@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -46,33 +46,33 @@ discard block |
||
| 46 | 46 | * Environnement du formulaire |
| 47 | 47 | **/ |
| 48 | 48 | function formulaires_editer_article_charger_dist( |
| 49 | - $id_article = 'new', |
|
| 50 | - $id_rubrique = 0, |
|
| 51 | - $retour = '', |
|
| 52 | - $lier_trad = 0, |
|
| 53 | - $config_fonc = 'articles_edit_config', |
|
| 54 | - $row = array(), |
|
| 55 | - $hidden = '' |
|
| 49 | + $id_article = 'new', |
|
| 50 | + $id_rubrique = 0, |
|
| 51 | + $retour = '', |
|
| 52 | + $lier_trad = 0, |
|
| 53 | + $config_fonc = 'articles_edit_config', |
|
| 54 | + $row = array(), |
|
| 55 | + $hidden = '' |
|
| 56 | 56 | ) { |
| 57 | - $valeurs = formulaires_editer_objet_charger( |
|
| 58 | - 'article', |
|
| 59 | - $id_article, |
|
| 60 | - $id_rubrique, |
|
| 61 | - $lier_trad, |
|
| 62 | - $retour, |
|
| 63 | - $config_fonc, |
|
| 64 | - $row, |
|
| 65 | - $hidden |
|
| 66 | - ); |
|
| 67 | - |
|
| 68 | - if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | - $valeurs['editable'] = ''; |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | - // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | - // et sera perdue si elle est supposee saisie |
|
| 75 | - return $valeurs; |
|
| 57 | + $valeurs = formulaires_editer_objet_charger( |
|
| 58 | + 'article', |
|
| 59 | + $id_article, |
|
| 60 | + $id_rubrique, |
|
| 61 | + $lier_trad, |
|
| 62 | + $retour, |
|
| 63 | + $config_fonc, |
|
| 64 | + $row, |
|
| 65 | + $hidden |
|
| 66 | + ); |
|
| 67 | + |
|
| 68 | + if (intval($id_article) and !autoriser('modifier', 'article', intval($id_article))) { |
|
| 69 | + $valeurs['editable'] = ''; |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + // il faut enlever l'id_rubrique car la saisie se fait sur id_parent |
|
| 73 | + // et id_rubrique peut etre passe dans l'url comme rubrique parent initiale |
|
| 74 | + // et sera perdue si elle est supposee saisie |
|
| 75 | + return $valeurs; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -97,15 +97,15 @@ discard block |
||
| 97 | 97 | * Hash du formulaire |
| 98 | 98 | */ |
| 99 | 99 | function formulaires_editer_article_identifier_dist( |
| 100 | - $id_article = 'new', |
|
| 101 | - $id_rubrique = 0, |
|
| 102 | - $retour = '', |
|
| 103 | - $lier_trad = 0, |
|
| 104 | - $config_fonc = 'articles_edit_config', |
|
| 105 | - $row = array(), |
|
| 106 | - $hidden = '' |
|
| 100 | + $id_article = 'new', |
|
| 101 | + $id_rubrique = 0, |
|
| 102 | + $retour = '', |
|
| 103 | + $lier_trad = 0, |
|
| 104 | + $config_fonc = 'articles_edit_config', |
|
| 105 | + $row = array(), |
|
| 106 | + $hidden = '' |
|
| 107 | 107 | ) { |
| 108 | - return serialize(array(intval($id_article), $lier_trad)); |
|
| 108 | + return serialize(array(intval($id_article), $lier_trad)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * Configuration pour le formulaire |
| 118 | 118 | */ |
| 119 | 119 | function articles_edit_config($row) { |
| 120 | - global $spip_lang; |
|
| 120 | + global $spip_lang; |
|
| 121 | 121 | |
| 122 | - $config = $GLOBALS['meta']; |
|
| 123 | - $config['lignes'] = 8; |
|
| 124 | - $config['langue'] = $spip_lang; |
|
| 122 | + $config = $GLOBALS['meta']; |
|
| 123 | + $config['lignes'] = 8; |
|
| 124 | + $config['langue'] = $spip_lang; |
|
| 125 | 125 | |
| 126 | - $config['restreint'] = ($row['statut'] == 'publie'); |
|
| 126 | + $config['restreint'] = ($row['statut'] == 'publie'); |
|
| 127 | 127 | |
| 128 | - return $config; |
|
| 128 | + return $config; |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -151,29 +151,29 @@ discard block |
||
| 151 | 151 | * Erreurs du formulaire |
| 152 | 152 | **/ |
| 153 | 153 | function formulaires_editer_article_verifier_dist( |
| 154 | - $id_article = 'new', |
|
| 155 | - $id_rubrique = 0, |
|
| 156 | - $retour = '', |
|
| 157 | - $lier_trad = 0, |
|
| 158 | - $config_fonc = 'articles_edit_config', |
|
| 159 | - $row = array(), |
|
| 160 | - $hidden = '' |
|
| 154 | + $id_article = 'new', |
|
| 155 | + $id_rubrique = 0, |
|
| 156 | + $retour = '', |
|
| 157 | + $lier_trad = 0, |
|
| 158 | + $config_fonc = 'articles_edit_config', |
|
| 159 | + $row = array(), |
|
| 160 | + $hidden = '' |
|
| 161 | 161 | ) { |
| 162 | - // auto-renseigner le titre si il n'existe pas |
|
| 163 | - titre_automatique('titre', array('descriptif', 'chapo', 'texte')); |
|
| 164 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 165 | - $erreurs = formulaires_editer_objet_verifier('article', $id_article, array('id_parent')); |
|
| 166 | - // si on utilise le formulaire dans le public |
|
| 167 | - if (!function_exists('autoriser')) { |
|
| 168 | - include_spip('inc/autoriser'); |
|
| 169 | - } |
|
| 170 | - if (!isset($erreurs['id_parent']) |
|
| 171 | - and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 172 | - ) { |
|
| 173 | - $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return $erreurs; |
|
| 162 | + // auto-renseigner le titre si il n'existe pas |
|
| 163 | + titre_automatique('titre', array('descriptif', 'chapo', 'texte')); |
|
| 164 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_article si vide |
|
| 165 | + $erreurs = formulaires_editer_objet_verifier('article', $id_article, array('id_parent')); |
|
| 166 | + // si on utilise le formulaire dans le public |
|
| 167 | + if (!function_exists('autoriser')) { |
|
| 168 | + include_spip('inc/autoriser'); |
|
| 169 | + } |
|
| 170 | + if (!isset($erreurs['id_parent']) |
|
| 171 | + and !autoriser('creerarticledans', 'rubrique', _request('id_parent')) |
|
| 172 | + ) { |
|
| 173 | + $erreurs['id_parent'] = _T('info_creerdansrubrique_non_autorise'); |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return $erreurs; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -199,27 +199,27 @@ discard block |
||
| 199 | 199 | * Retours des traitements |
| 200 | 200 | **/ |
| 201 | 201 | function formulaires_editer_article_traiter_dist( |
| 202 | - $id_article = 'new', |
|
| 203 | - $id_rubrique = 0, |
|
| 204 | - $retour = '', |
|
| 205 | - $lier_trad = 0, |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = array(), |
|
| 208 | - $hidden = '' |
|
| 202 | + $id_article = 'new', |
|
| 203 | + $id_rubrique = 0, |
|
| 204 | + $retour = '', |
|
| 205 | + $lier_trad = 0, |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = array(), |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | - // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 211 | - // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 212 | - // en fonction de la config du site et de la rubrique choisie |
|
| 213 | - set_request('changer_lang'); |
|
| 214 | - |
|
| 215 | - return formulaires_editer_objet_traiter( |
|
| 216 | - 'article', |
|
| 217 | - $id_article, |
|
| 218 | - $id_rubrique, |
|
| 219 | - $lier_trad, |
|
| 220 | - $retour, |
|
| 221 | - $config_fonc, |
|
| 222 | - $row, |
|
| 223 | - $hidden |
|
| 224 | - ); |
|
| 210 | + // ici on ignore changer_lang qui est poste en cas de trad, |
|
| 211 | + // car l'heuristique du choix de la langue est pris en charge par article_inserer |
|
| 212 | + // en fonction de la config du site et de la rubrique choisie |
|
| 213 | + set_request('changer_lang'); |
|
| 214 | + |
|
| 215 | + return formulaires_editer_objet_traiter( |
|
| 216 | + 'article', |
|
| 217 | + $id_article, |
|
| 218 | + $id_rubrique, |
|
| 219 | + $lier_trad, |
|
| 220 | + $retour, |
|
| 221 | + $config_fonc, |
|
| 222 | + $row, |
|
| 223 | + $hidden |
|
| 224 | + ); |
|
| 225 | 225 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/actions'); |
@@ -47,30 +47,30 @@ discard block |
||
| 47 | 47 | * Environnement du formulaire |
| 48 | 48 | **/ |
| 49 | 49 | function formulaires_editer_rubrique_charger_dist( |
| 50 | - $id_rubrique = 'new', |
|
| 51 | - $id_parent = 0, |
|
| 52 | - $retour = '', |
|
| 53 | - $lier_trad = 0, |
|
| 54 | - $config_fonc = 'rubriques_edit_config', |
|
| 55 | - $row = array(), |
|
| 56 | - $hidden = '' |
|
| 50 | + $id_rubrique = 'new', |
|
| 51 | + $id_parent = 0, |
|
| 52 | + $retour = '', |
|
| 53 | + $lier_trad = 0, |
|
| 54 | + $config_fonc = 'rubriques_edit_config', |
|
| 55 | + $row = array(), |
|
| 56 | + $hidden = '' |
|
| 57 | 57 | ) { |
| 58 | - $valeurs = formulaires_editer_objet_charger( |
|
| 59 | - 'rubrique', |
|
| 60 | - $id_rubrique, |
|
| 61 | - $id_parent, |
|
| 62 | - $lier_trad, |
|
| 63 | - $retour, |
|
| 64 | - $config_fonc, |
|
| 65 | - $row, |
|
| 66 | - $hidden |
|
| 67 | - ); |
|
| 68 | - |
|
| 69 | - if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | - $valeurs['editable'] = ''; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return $valeurs; |
|
| 58 | + $valeurs = formulaires_editer_objet_charger( |
|
| 59 | + 'rubrique', |
|
| 60 | + $id_rubrique, |
|
| 61 | + $id_parent, |
|
| 62 | + $lier_trad, |
|
| 63 | + $retour, |
|
| 64 | + $config_fonc, |
|
| 65 | + $row, |
|
| 66 | + $hidden |
|
| 67 | + ); |
|
| 68 | + |
|
| 69 | + if (intval($id_rubrique) and !autoriser('modifier', 'rubrique', intval($id_rubrique))) { |
|
| 70 | + $valeurs['editable'] = ''; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return $valeurs; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -82,15 +82,15 @@ discard block |
||
| 82 | 82 | * Configuration pour le formulaire |
| 83 | 83 | */ |
| 84 | 84 | function rubriques_edit_config($row) { |
| 85 | - global $spip_lang; |
|
| 85 | + global $spip_lang; |
|
| 86 | 86 | |
| 87 | - $config = $GLOBALS['meta']; |
|
| 88 | - $config['lignes'] = 8; |
|
| 89 | - $config['langue'] = $spip_lang; |
|
| 87 | + $config = $GLOBALS['meta']; |
|
| 88 | + $config['lignes'] = 8; |
|
| 89 | + $config['langue'] = $spip_lang; |
|
| 90 | 90 | |
| 91 | - $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 91 | + $config['restreint'] = (!$GLOBALS['connect_toutes_rubriques']); |
|
| 92 | 92 | |
| 93 | - return $config; |
|
| 93 | + return $config; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -115,15 +115,15 @@ discard block |
||
| 115 | 115 | * Hash du formulaire |
| 116 | 116 | */ |
| 117 | 117 | function formulaires_editer_rubrique_identifier_dist( |
| 118 | - $id_rubrique = 'new', |
|
| 119 | - $id_parent = 0, |
|
| 120 | - $retour = '', |
|
| 121 | - $lier_trad = 0, |
|
| 122 | - $config_fonc = 'rubriques_edit_config', |
|
| 123 | - $row = array(), |
|
| 124 | - $hidden = '' |
|
| 118 | + $id_rubrique = 'new', |
|
| 119 | + $id_parent = 0, |
|
| 120 | + $retour = '', |
|
| 121 | + $lier_trad = 0, |
|
| 122 | + $config_fonc = 'rubriques_edit_config', |
|
| 123 | + $row = array(), |
|
| 124 | + $hidden = '' |
|
| 125 | 125 | ) { |
| 126 | - return serialize(array(intval($id_rubrique), $lier_trad)); |
|
| 126 | + return serialize(array(intval($id_rubrique), $lier_trad)); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | /** |
@@ -149,20 +149,20 @@ discard block |
||
| 149 | 149 | * Erreurs du formulaire |
| 150 | 150 | **/ |
| 151 | 151 | function formulaires_editer_rubrique_verifier_dist( |
| 152 | - $id_rubrique = 'new', |
|
| 153 | - $id_parent = 0, |
|
| 154 | - $retour = '', |
|
| 155 | - $lier_trad = 0, |
|
| 156 | - $config_fonc = 'rubriques_edit_config', |
|
| 157 | - $row = array(), |
|
| 158 | - $hidden = '' |
|
| 152 | + $id_rubrique = 'new', |
|
| 153 | + $id_parent = 0, |
|
| 154 | + $retour = '', |
|
| 155 | + $lier_trad = 0, |
|
| 156 | + $config_fonc = 'rubriques_edit_config', |
|
| 157 | + $row = array(), |
|
| 158 | + $hidden = '' |
|
| 159 | 159 | ) { |
| 160 | - // auto-renseigner le titre si il n'existe pas |
|
| 161 | - titre_automatique('titre', array('descriptif', 'texte')); |
|
| 162 | - // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 163 | - $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, array()); |
|
| 160 | + // auto-renseigner le titre si il n'existe pas |
|
| 161 | + titre_automatique('titre', array('descriptif', 'texte')); |
|
| 162 | + // on ne demande pas le titre obligatoire : il sera rempli a la volee dans editer_rubrique si vide |
|
| 163 | + $erreurs = formulaires_editer_objet_verifier('rubrique', $id_rubrique, array()); |
|
| 164 | 164 | |
| 165 | - return $erreurs; |
|
| 165 | + return $erreurs; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -188,22 +188,22 @@ discard block |
||
| 188 | 188 | * Retour des traitements |
| 189 | 189 | **/ |
| 190 | 190 | function formulaires_editer_rubrique_traiter_dist( |
| 191 | - $id_rubrique = 'new', |
|
| 192 | - $id_parent = 0, |
|
| 193 | - $retour = '', |
|
| 194 | - $lier_trad = 0, |
|
| 195 | - $config_fonc = 'rubriques_edit_config', |
|
| 196 | - $row = array(), |
|
| 197 | - $hidden = '' |
|
| 191 | + $id_rubrique = 'new', |
|
| 192 | + $id_parent = 0, |
|
| 193 | + $retour = '', |
|
| 194 | + $lier_trad = 0, |
|
| 195 | + $config_fonc = 'rubriques_edit_config', |
|
| 196 | + $row = array(), |
|
| 197 | + $hidden = '' |
|
| 198 | 198 | ) { |
| 199 | - return formulaires_editer_objet_traiter( |
|
| 200 | - 'rubrique', |
|
| 201 | - $id_rubrique, |
|
| 202 | - $id_parent, |
|
| 203 | - $lier_trad, |
|
| 204 | - $retour, |
|
| 205 | - $config_fonc, |
|
| 206 | - $row, |
|
| 207 | - $hidden |
|
| 208 | - ); |
|
| 199 | + return formulaires_editer_objet_traiter( |
|
| 200 | + 'rubrique', |
|
| 201 | + $id_rubrique, |
|
| 202 | + $id_parent, |
|
| 203 | + $lier_trad, |
|
| 204 | + $retour, |
|
| 205 | + $config_fonc, |
|
| 206 | + $row, |
|
| 207 | + $hidden |
|
| 208 | + ); |
|
| 209 | 209 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -43,239 +43,239 @@ discard block |
||
| 43 | 43 | // https://code.spip.net/@public_composer_dist |
| 44 | 44 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 45 | 45 | |
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - // @todo : a remplacer quand _PHP_MIN >= 7 |
|
| 96 | - // eval("return true; $f ;"); |
|
| 97 | - // PHP 5.x compat |
|
| 98 | - if ($ok = @eval("return true; $f ;") === false) { |
|
| 99 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 100 | - $msg = _T('zbug_erreur_compilation'); |
|
| 101 | - erreur_squelette($msg, $boucle); |
|
| 102 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 103 | - // mais prevenir que c'est mort |
|
| 104 | - $nom = ''; |
|
| 105 | - } |
|
| 106 | - } catch (\ParseError $e) { |
|
| 107 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 108 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 109 | - erreur_squelette($msg, $boucle); |
|
| 110 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 111 | - // mais prevenir que c'est mort |
|
| 112 | - $nom = ''; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Contexte de compil inutile a present |
|
| 116 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 117 | - $skel_code[$id] = $f; |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - $code = ''; |
|
| 121 | - if ($nom) { |
|
| 122 | - // Si le code est bon, concatener et mettre en cache |
|
| 123 | - if (function_exists($nom)) { |
|
| 124 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 125 | - } else { |
|
| 126 | - // code semantiquement faux: bug du compilateur |
|
| 127 | - // $boucle est en fait ici la fct principale du squelette |
|
| 128 | - $msg = _T('zbug_erreur_compilation'); |
|
| 129 | - erreur_squelette($msg, $boucle); |
|
| 130 | - $nom = ''; |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 135 | - |
|
| 136 | - // Tracer ce qui vient d'etre compile |
|
| 137 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 138 | - |
|
| 139 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 140 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 141 | - and (_request('var_mode_objet') == $nom) |
|
| 142 | - and (_request('var_mode_affiche') == 'code') |
|
| 143 | - ) { |
|
| 144 | - erreur_squelette(); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - return $nom ? $nom : false; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + // @todo : a remplacer quand _PHP_MIN >= 7 |
|
| 96 | + // eval("return true; $f ;"); |
|
| 97 | + // PHP 5.x compat |
|
| 98 | + if ($ok = @eval("return true; $f ;") === false) { |
|
| 99 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 100 | + $msg = _T('zbug_erreur_compilation'); |
|
| 101 | + erreur_squelette($msg, $boucle); |
|
| 102 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 103 | + // mais prevenir que c'est mort |
|
| 104 | + $nom = ''; |
|
| 105 | + } |
|
| 106 | + } catch (\ParseError $e) { |
|
| 107 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 108 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 109 | + erreur_squelette($msg, $boucle); |
|
| 110 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 111 | + // mais prevenir que c'est mort |
|
| 112 | + $nom = ''; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Contexte de compil inutile a present |
|
| 116 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 117 | + $skel_code[$id] = $f; |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + $code = ''; |
|
| 121 | + if ($nom) { |
|
| 122 | + // Si le code est bon, concatener et mettre en cache |
|
| 123 | + if (function_exists($nom)) { |
|
| 124 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 125 | + } else { |
|
| 126 | + // code semantiquement faux: bug du compilateur |
|
| 127 | + // $boucle est en fait ici la fct principale du squelette |
|
| 128 | + $msg = _T('zbug_erreur_compilation'); |
|
| 129 | + erreur_squelette($msg, $boucle); |
|
| 130 | + $nom = ''; |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 135 | + |
|
| 136 | + // Tracer ce qui vient d'etre compile |
|
| 137 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 138 | + |
|
| 139 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 140 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 141 | + and (_request('var_mode_objet') == $nom) |
|
| 142 | + and (_request('var_mode_affiche') == 'code') |
|
| 143 | + ) { |
|
| 144 | + erreur_squelette(); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + return $nom ? $nom : false; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 152 | 152 | |
| 153 | - // Le dernier index est '' (fonction principale) |
|
| 154 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 155 | - if (CODE_COMMENTE) { |
|
| 156 | - $code = " |
|
| 153 | + // Le dernier index est '' (fonction principale) |
|
| 154 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 155 | + if (CODE_COMMENTE) { |
|
| 156 | + $code = " |
|
| 157 | 157 | /* |
| 158 | 158 | * Squelette : $sourcefile |
| 159 | 159 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 160 | 160 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 161 | 161 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 162 | 162 | */ "; |
| 163 | - } |
|
| 163 | + } |
|
| 164 | 164 | |
| 165 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 166 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 167 | - ecrire_fichier($phpfile, $code); |
|
| 168 | - } |
|
| 165 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 166 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 167 | + ecrire_fichier($phpfile, $code); |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - return $code; |
|
| 170 | + return $code; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // Le squelette compile est-il trop vieux ? |
| 174 | 174 | // https://code.spip.net/@squelette_obsolete |
| 175 | 175 | function squelette_obsolete($skel, $squelette) { |
| 176 | - static $date_change = null; |
|
| 177 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 178 | - // par hit |
|
| 179 | - if (is_null($date_change)) { |
|
| 180 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 181 | - $date_change = @filemtime($fonc); |
|
| 182 | - } # compatibilite |
|
| 183 | - if (defined('_FILE_OPTIONS')) { |
|
| 184 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 185 | - } |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return ( |
|
| 189 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 190 | - or !@file_exists($skel) |
|
| 191 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 192 | - > ($date = @filemtime($skel))) |
|
| 193 | - or ($date_change > $date) |
|
| 194 | - ); |
|
| 176 | + static $date_change = null; |
|
| 177 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 178 | + // par hit |
|
| 179 | + if (is_null($date_change)) { |
|
| 180 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 181 | + $date_change = @filemtime($fonc); |
|
| 182 | + } # compatibilite |
|
| 183 | + if (defined('_FILE_OPTIONS')) { |
|
| 184 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 185 | + } |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return ( |
|
| 189 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 190 | + or !@file_exists($skel) |
|
| 191 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 192 | + > ($date = @filemtime($skel))) |
|
| 193 | + or ($date_change > $date) |
|
| 194 | + ); |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Activer l'invalideur de session |
| 198 | 198 | // https://code.spip.net/@invalideur_session |
| 199 | 199 | function invalideur_session(&$Cache, $code = null) { |
| 200 | - $Cache['session'] = spip_session(); |
|
| 200 | + $Cache['session'] = spip_session(); |
|
| 201 | 201 | |
| 202 | - return $code; |
|
| 202 | + return $code; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | // https://code.spip.net/@analyse_resultat_skel |
| 207 | 207 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 208 | - static $filtres = array(); |
|
| 209 | - $headers = array(); |
|
| 210 | - |
|
| 211 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 212 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 213 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 214 | - if (stripos($corps, 'header') !== false |
|
| 215 | - and preg_match_all( |
|
| 216 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 217 | - $corps, $regs, PREG_SET_ORDER) |
|
| 218 | - ) { |
|
| 219 | - foreach ($regs as $r) { |
|
| 220 | - $corps = str_replace($r[0], '', $corps); |
|
| 221 | - # $j = Content-Type, et pas content-TYPE. |
|
| 222 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 223 | - |
|
| 224 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 225 | - $headers[$j] .= "|" . $r[3]; |
|
| 226 | - } else { |
|
| 227 | - $headers[$j] = $r[3]; |
|
| 228 | - } |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 232 | - $process_ins = ( |
|
| 233 | - strpos($corps, '<' . '?') === false |
|
| 234 | - or |
|
| 235 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 236 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 237 | - ) |
|
| 238 | - ? 'html' |
|
| 239 | - : 'php'; |
|
| 240 | - |
|
| 241 | - $skel = array( |
|
| 242 | - 'squelette' => $nom, |
|
| 243 | - 'source' => $source, |
|
| 244 | - 'process_ins' => $process_ins, |
|
| 245 | - 'invalideurs' => $cache, |
|
| 246 | - 'entetes' => $headers, |
|
| 247 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 248 | - ); |
|
| 249 | - |
|
| 250 | - // traiter #FILTRE{} et filtres |
|
| 251 | - if (!isset($filtres[$nom])) { |
|
| 252 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 253 | - } |
|
| 254 | - $filtres_headers = array(); |
|
| 255 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 256 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 257 | - unset($headers['X-Spip-Filtre']); |
|
| 258 | - } |
|
| 259 | - if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 260 | - include_spip('public/sandbox'); |
|
| 261 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 262 | - |
|
| 263 | - if ($process_ins == 'html') { |
|
| 264 | - $skel['process_ins'] = ( |
|
| 265 | - strpos($corps, '<' . '?') === false |
|
| 266 | - or |
|
| 267 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 268 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 269 | - ) |
|
| 270 | - ? 'html' |
|
| 271 | - : 'php'; |
|
| 272 | - } |
|
| 273 | - } |
|
| 274 | - |
|
| 275 | - $skel['entetes'] = $headers; |
|
| 276 | - $skel['texte'] = $corps; |
|
| 277 | - |
|
| 278 | - return $skel; |
|
| 208 | + static $filtres = array(); |
|
| 209 | + $headers = array(); |
|
| 210 | + |
|
| 211 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 212 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 213 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 214 | + if (stripos($corps, 'header') !== false |
|
| 215 | + and preg_match_all( |
|
| 216 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 217 | + $corps, $regs, PREG_SET_ORDER) |
|
| 218 | + ) { |
|
| 219 | + foreach ($regs as $r) { |
|
| 220 | + $corps = str_replace($r[0], '', $corps); |
|
| 221 | + # $j = Content-Type, et pas content-TYPE. |
|
| 222 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 223 | + |
|
| 224 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 225 | + $headers[$j] .= "|" . $r[3]; |
|
| 226 | + } else { |
|
| 227 | + $headers[$j] = $r[3]; |
|
| 228 | + } |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 232 | + $process_ins = ( |
|
| 233 | + strpos($corps, '<' . '?') === false |
|
| 234 | + or |
|
| 235 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 236 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 237 | + ) |
|
| 238 | + ? 'html' |
|
| 239 | + : 'php'; |
|
| 240 | + |
|
| 241 | + $skel = array( |
|
| 242 | + 'squelette' => $nom, |
|
| 243 | + 'source' => $source, |
|
| 244 | + 'process_ins' => $process_ins, |
|
| 245 | + 'invalideurs' => $cache, |
|
| 246 | + 'entetes' => $headers, |
|
| 247 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 248 | + ); |
|
| 249 | + |
|
| 250 | + // traiter #FILTRE{} et filtres |
|
| 251 | + if (!isset($filtres[$nom])) { |
|
| 252 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 253 | + } |
|
| 254 | + $filtres_headers = array(); |
|
| 255 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 256 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 257 | + unset($headers['X-Spip-Filtre']); |
|
| 258 | + } |
|
| 259 | + if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 260 | + include_spip('public/sandbox'); |
|
| 261 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 262 | + |
|
| 263 | + if ($process_ins == 'html') { |
|
| 264 | + $skel['process_ins'] = ( |
|
| 265 | + strpos($corps, '<' . '?') === false |
|
| 266 | + or |
|
| 267 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 268 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 269 | + ) |
|
| 270 | + ? 'html' |
|
| 271 | + : 'php'; |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | + |
|
| 275 | + $skel['entetes'] = $headers; |
|
| 276 | + $skel['texte'] = $corps; |
|
| 277 | + |
|
| 278 | + return $skel; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | // |
@@ -289,7 +289,7 @@ discard block |
||
| 289 | 289 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 290 | 290 | if ($lang_select) lang_select(); |
| 291 | 291 | ?' |
| 292 | - . '>'); |
|
| 292 | + . '>'); |
|
| 293 | 293 | |
| 294 | 294 | /** |
| 295 | 295 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -309,29 +309,29 @@ discard block |
||
| 309 | 309 | * Code PHP pour inclure le squelette de la balise dynamique |
| 310 | 310 | **/ |
| 311 | 311 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 312 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 313 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - $lang = $context_compil[4]; |
|
| 317 | - if (preg_match(",\W,", $lang)) { |
|
| 318 | - $lang = ''; |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - $args = array_map('argumenter_squelette', $args); |
|
| 322 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 323 | - $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 324 | - } |
|
| 325 | - $args = join(', ', $args); |
|
| 326 | - |
|
| 327 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 328 | - $file, |
|
| 329 | - $lang, |
|
| 330 | - $nom, |
|
| 331 | - $args, |
|
| 332 | - join(', ', array_map('_q', $context_compil))); |
|
| 333 | - |
|
| 334 | - return $r; |
|
| 312 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 313 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + $lang = $context_compil[4]; |
|
| 317 | + if (preg_match(",\W,", $lang)) { |
|
| 318 | + $lang = ''; |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + $args = array_map('argumenter_squelette', $args); |
|
| 322 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 323 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 324 | + } |
|
| 325 | + $args = join(', ', $args); |
|
| 326 | + |
|
| 327 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 328 | + $file, |
|
| 329 | + $lang, |
|
| 330 | + $nom, |
|
| 331 | + $args, |
|
| 332 | + join(', ', array_map('_q', $context_compil))); |
|
| 333 | + |
|
| 334 | + return $r; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -349,21 +349,21 @@ discard block |
||
| 349 | 349 | **/ |
| 350 | 350 | function argumenter_squelette($v) { |
| 351 | 351 | |
| 352 | - if (is_object($v)) { |
|
| 353 | - if (PHP_VERSION_ID < 73000 and $v instanceof \stdClass) { |
|
| 354 | - return "(object) " . var_export((array) $v, true); |
|
| 355 | - } |
|
| 356 | - return var_export($v, true); |
|
| 357 | - } elseif (!is_array($v)) { |
|
| 358 | - return "'" . texte_script($v) . "'"; |
|
| 359 | - } else { |
|
| 360 | - $out = array(); |
|
| 361 | - foreach ($v as $k => $val) { |
|
| 362 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 363 | - } |
|
| 364 | - |
|
| 365 | - return 'array(' . join(", ", $out) . ')'; |
|
| 366 | - } |
|
| 352 | + if (is_object($v)) { |
|
| 353 | + if (PHP_VERSION_ID < 73000 and $v instanceof \stdClass) { |
|
| 354 | + return "(object) " . var_export((array) $v, true); |
|
| 355 | + } |
|
| 356 | + return var_export($v, true); |
|
| 357 | + } elseif (!is_array($v)) { |
|
| 358 | + return "'" . texte_script($v) . "'"; |
|
| 359 | + } else { |
|
| 360 | + $out = array(); |
|
| 361 | + foreach ($v as $k => $val) { |
|
| 362 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 363 | + } |
|
| 364 | + |
|
| 365 | + return 'array(' . join(", ", $out) . ')'; |
|
| 366 | + } |
|
| 367 | 367 | } |
| 368 | 368 | |
| 369 | 369 | |
@@ -394,82 +394,82 @@ discard block |
||
| 394 | 394 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 395 | 395 | **/ |
| 396 | 396 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 397 | - $nomfonction = $nom; |
|
| 398 | - $nomfonction_generique = ""; |
|
| 399 | - |
|
| 400 | - $appel_php_depuis_modele = false; |
|
| 401 | - if (is_array($context_compil) |
|
| 402 | - and !is_numeric($context_compil[3]) |
|
| 403 | - and empty($context_compil[0]) |
|
| 404 | - and empty($context_compil[1]) |
|
| 405 | - and empty($context_compil[2]) |
|
| 406 | - and empty($context_compil[3])) { |
|
| 407 | - $appel_php_depuis_modele = true; |
|
| 408 | - } |
|
| 409 | - |
|
| 410 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 411 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 412 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 413 | - } |
|
| 414 | - |
|
| 415 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 416 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 417 | - // et injecter en premier arg le nom de la balise |
|
| 418 | - array_unshift($args, $nom); |
|
| 419 | - $nomfonction = $nomfonction_generique; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!$fonction_balise) { |
|
| 424 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 425 | - erreur_squelette($msg, $context_compil); |
|
| 426 | - |
|
| 427 | - return ''; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // retrouver le fichier qui a déclaré la fonction |
|
| 431 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 441 | - |
|
| 442 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | - |
|
| 444 | - if (!is_array($r)) { |
|
| 445 | - return $r; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // verifier que la fonction dyn est la, |
|
| 449 | - // sinon se replier sur la generique si elle existe |
|
| 450 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 451 | - if ($nomfonction_generique |
|
| 452 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 453 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 454 | - ) { |
|
| 455 | - // et lui injecter en premier arg le nom de la balise |
|
| 456 | - array_unshift($r, $nom); |
|
| 457 | - $nomfonction = $nomfonction_generique; |
|
| 458 | - if (!_DIR_RESTREINT) { |
|
| 459 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 460 | - } |
|
| 461 | - } else { |
|
| 462 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 463 | - erreur_squelette($msg, $context_compil); |
|
| 464 | - |
|
| 465 | - return ''; |
|
| 466 | - } |
|
| 467 | - } |
|
| 468 | - |
|
| 469 | - if ($appel_php_depuis_modele) { |
|
| 470 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 471 | - } |
|
| 472 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 397 | + $nomfonction = $nom; |
|
| 398 | + $nomfonction_generique = ""; |
|
| 399 | + |
|
| 400 | + $appel_php_depuis_modele = false; |
|
| 401 | + if (is_array($context_compil) |
|
| 402 | + and !is_numeric($context_compil[3]) |
|
| 403 | + and empty($context_compil[0]) |
|
| 404 | + and empty($context_compil[1]) |
|
| 405 | + and empty($context_compil[2]) |
|
| 406 | + and empty($context_compil[3])) { |
|
| 407 | + $appel_php_depuis_modele = true; |
|
| 408 | + } |
|
| 409 | + |
|
| 410 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 411 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 412 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 413 | + } |
|
| 414 | + |
|
| 415 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 416 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 417 | + // et injecter en premier arg le nom de la balise |
|
| 418 | + array_unshift($args, $nom); |
|
| 419 | + $nomfonction = $nomfonction_generique; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!$fonction_balise) { |
|
| 424 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 425 | + erreur_squelette($msg, $context_compil); |
|
| 426 | + |
|
| 427 | + return ''; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // retrouver le fichier qui a déclaré la fonction |
|
| 431 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 441 | + |
|
| 442 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | + |
|
| 444 | + if (!is_array($r)) { |
|
| 445 | + return $r; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // verifier que la fonction dyn est la, |
|
| 449 | + // sinon se replier sur la generique si elle existe |
|
| 450 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 451 | + if ($nomfonction_generique |
|
| 452 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 453 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 454 | + ) { |
|
| 455 | + // et lui injecter en premier arg le nom de la balise |
|
| 456 | + array_unshift($r, $nom); |
|
| 457 | + $nomfonction = $nomfonction_generique; |
|
| 458 | + if (!_DIR_RESTREINT) { |
|
| 459 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 460 | + } |
|
| 461 | + } else { |
|
| 462 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 463 | + erreur_squelette($msg, $context_compil); |
|
| 464 | + |
|
| 465 | + return ''; |
|
| 466 | + } |
|
| 467 | + } |
|
| 468 | + |
|
| 469 | + if ($appel_php_depuis_modele) { |
|
| 470 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 471 | + } |
|
| 472 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 473 | 473 | |
| 474 | 474 | } |
| 475 | 475 | |
@@ -494,27 +494,27 @@ discard block |
||
| 494 | 494 | * @return null; |
| 495 | 495 | **/ |
| 496 | 496 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 497 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 498 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 499 | - and $lang_select !== 'oui' |
|
| 500 | - ) { |
|
| 501 | - $lang = $GLOBALS['spip_lang']; |
|
| 502 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 503 | - elseif (!strlen($lang)) { |
|
| 504 | - $lang = $GLOBALS['spip_lang']; |
|
| 505 | - } // Cas 3. l'objet est multilingue ! |
|
| 506 | - elseif ($lang_select !== 'oui' |
|
| 507 | - and strlen($titre) > 10 |
|
| 508 | - and strpos($titre, '<multi>') !== false |
|
| 509 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 510 | - ) { |
|
| 511 | - $lang = $GLOBALS['spip_lang']; |
|
| 512 | - } |
|
| 513 | - |
|
| 514 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 515 | - lang_select($lang); |
|
| 516 | - |
|
| 517 | - return; |
|
| 497 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 498 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 499 | + and $lang_select !== 'oui' |
|
| 500 | + ) { |
|
| 501 | + $lang = $GLOBALS['spip_lang']; |
|
| 502 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 503 | + elseif (!strlen($lang)) { |
|
| 504 | + $lang = $GLOBALS['spip_lang']; |
|
| 505 | + } // Cas 3. l'objet est multilingue ! |
|
| 506 | + elseif ($lang_select !== 'oui' |
|
| 507 | + and strlen($titre) > 10 |
|
| 508 | + and strpos($titre, '<multi>') !== false |
|
| 509 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 510 | + ) { |
|
| 511 | + $lang = $GLOBALS['spip_lang']; |
|
| 512 | + } |
|
| 513 | + |
|
| 514 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 515 | + lang_select($lang); |
|
| 516 | + |
|
| 517 | + return; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | |
@@ -522,21 +522,21 @@ discard block |
||
| 522 | 522 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 523 | 523 | // https://code.spip.net/@nettoyer_env_doublons |
| 524 | 524 | function nettoyer_env_doublons($envd) { |
| 525 | - foreach ($envd as $table => $liste) { |
|
| 526 | - $n = ''; |
|
| 527 | - foreach (explode(',', $liste) as $val) { |
|
| 528 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 529 | - $n .= ',' . $val; |
|
| 530 | - } |
|
| 531 | - } |
|
| 532 | - if (strlen($n)) { |
|
| 533 | - $envd[$table] = $n; |
|
| 534 | - } else { |
|
| 535 | - unset($envd[$table]); |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - return $envd; |
|
| 525 | + foreach ($envd as $table => $liste) { |
|
| 526 | + $n = ''; |
|
| 527 | + foreach (explode(',', $liste) as $val) { |
|
| 528 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 529 | + $n .= ',' . $val; |
|
| 530 | + } |
|
| 531 | + } |
|
| 532 | + if (strlen($n)) { |
|
| 533 | + $envd[$table] = $n; |
|
| 534 | + } else { |
|
| 535 | + unset($envd[$table]); |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + return $envd; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -555,21 +555,21 @@ discard block |
||
| 555 | 555 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 556 | 556 | **/ |
| 557 | 557 | function match_self($w) { |
| 558 | - if (is_string($w)) { |
|
| 559 | - return false; |
|
| 560 | - } |
|
| 561 | - if (is_array($w)) { |
|
| 562 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 563 | - return $w; |
|
| 564 | - } |
|
| 565 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 566 | - if ($m = match_self($sw)) { |
|
| 567 | - return $m; |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return false; |
|
| 558 | + if (is_string($w)) { |
|
| 559 | + return false; |
|
| 560 | + } |
|
| 561 | + if (is_array($w)) { |
|
| 562 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 563 | + return $w; |
|
| 564 | + } |
|
| 565 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 566 | + if ($m = match_self($sw)) { |
|
| 567 | + return $m; |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return false; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -585,16 +585,16 @@ discard block |
||
| 585 | 585 | * est remplacée par son code. |
| 586 | 586 | **/ |
| 587 | 587 | function remplace_sous_requete($w, $sousrequete) { |
| 588 | - if (is_array($w)) { |
|
| 589 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 590 | - return $sousrequete; |
|
| 591 | - } |
|
| 592 | - foreach ($w as $k => $sw) { |
|
| 593 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 594 | - } |
|
| 595 | - } |
|
| 596 | - |
|
| 597 | - return $w; |
|
| 588 | + if (is_array($w)) { |
|
| 589 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 590 | + return $sousrequete; |
|
| 591 | + } |
|
| 592 | + foreach ($w as $k => $sw) { |
|
| 593 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 594 | + } |
|
| 595 | + } |
|
| 596 | + |
|
| 597 | + return $w; |
|
| 598 | 598 | } |
| 599 | 599 | |
| 600 | 600 | /** |
@@ -608,17 +608,17 @@ discard block |
||
| 608 | 608 | * - Conditions avec des sous requêtes |
| 609 | 609 | **/ |
| 610 | 610 | function trouver_sous_requetes($where) { |
| 611 | - $where_simples = array(); |
|
| 612 | - $where_sous = array(); |
|
| 613 | - foreach ($where as $k => $w) { |
|
| 614 | - if (match_self($w)) { |
|
| 615 | - $where_sous[$k] = $w; |
|
| 616 | - } else { |
|
| 617 | - $where_simples[$k] = $w; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - return array($where_simples, $where_sous); |
|
| 611 | + $where_simples = array(); |
|
| 612 | + $where_sous = array(); |
|
| 613 | + foreach ($where as $k => $w) { |
|
| 614 | + if (match_self($w)) { |
|
| 615 | + $where_sous[$k] = $w; |
|
| 616 | + } else { |
|
| 617 | + $where_simples[$k] = $w; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + return array($where_simples, $where_sous); |
|
| 622 | 622 | } |
| 623 | 623 | |
| 624 | 624 | |
@@ -644,258 +644,258 @@ discard block |
||
| 644 | 644 | * @return resource |
| 645 | 645 | */ |
| 646 | 646 | function calculer_select( |
| 647 | - $select = array(), |
|
| 648 | - $from = array(), |
|
| 649 | - $from_type = array(), |
|
| 650 | - $where = array(), |
|
| 651 | - $join = array(), |
|
| 652 | - $groupby = array(), |
|
| 653 | - $orderby = array(), |
|
| 654 | - $limit = '', |
|
| 655 | - $having = array(), |
|
| 656 | - $table = '', |
|
| 657 | - $id = '', |
|
| 658 | - $serveur = '', |
|
| 659 | - $requeter = true |
|
| 647 | + $select = array(), |
|
| 648 | + $from = array(), |
|
| 649 | + $from_type = array(), |
|
| 650 | + $where = array(), |
|
| 651 | + $join = array(), |
|
| 652 | + $groupby = array(), |
|
| 653 | + $orderby = array(), |
|
| 654 | + $limit = '', |
|
| 655 | + $having = array(), |
|
| 656 | + $table = '', |
|
| 657 | + $id = '', |
|
| 658 | + $serveur = '', |
|
| 659 | + $requeter = true |
|
| 660 | 660 | ) { |
| 661 | 661 | |
| 662 | - // retirer les criteres vides: |
|
| 663 | - // {X ?} avec X absent de l'URL |
|
| 664 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 665 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 666 | - $menage = false; |
|
| 667 | - foreach ($where as $k => $v) { |
|
| 668 | - if (is_array($v)) { |
|
| 669 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 670 | - $op = false; |
|
| 671 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 672 | - $op = false; |
|
| 673 | - } else { |
|
| 674 | - $op = $v[0] ? $v[0] : $v; |
|
| 675 | - } |
|
| 676 | - } else { |
|
| 677 | - $op = $v; |
|
| 678 | - } |
|
| 679 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 680 | - unset($where[$k]); |
|
| 681 | - $menage = true; |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 686 | - $groupby = array_diff($groupby, array('')); |
|
| 687 | - |
|
| 688 | - // remplacer les sous requetes recursives au calcul |
|
| 689 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 690 | - foreach ($where_sous as $k => $w) { |
|
| 691 | - $menage = true; |
|
| 692 | - // on recupere la sous requete |
|
| 693 | - $sous = match_self($w); |
|
| 694 | - if ($sous[0] == 'SELF') { |
|
| 695 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 696 | - array_push($where_simples, $sous[2]); |
|
| 697 | - $wheresub = array( |
|
| 698 | - $sous[2], |
|
| 699 | - '0=0' |
|
| 700 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 701 | - $jsub = $join; |
|
| 702 | - // trouver les jointures utiles a |
|
| 703 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 704 | - // ie L1.objet='article' |
|
| 705 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 706 | - $i = 0; |
|
| 707 | - do { |
|
| 708 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 709 | - array($sous[1] . " AS id"), |
|
| 710 | - $from, |
|
| 711 | - $from_type, |
|
| 712 | - $wheresub, |
|
| 713 | - $jsub, |
|
| 714 | - array(), array(), '', |
|
| 715 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 716 | - if (!$i) { |
|
| 717 | - $i = 1; |
|
| 718 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 719 | - foreach ($join as $cle => $wj) { |
|
| 720 | - if (count($wj) == 4 |
|
| 721 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 722 | - ) { |
|
| 723 | - $i = 0; |
|
| 724 | - $wheresub[] = $wj[3]; |
|
| 725 | - unset($jsub[$cle][3]); |
|
| 726 | - } |
|
| 727 | - } |
|
| 728 | - } |
|
| 729 | - } while ($i++ < 1); |
|
| 730 | - } |
|
| 731 | - if ($sous[0] == 'SUBSELECT') { |
|
| 732 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 733 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 734 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 735 | - $sous[1], # select |
|
| 736 | - $sous[2], #from |
|
| 737 | - array(), #from_type |
|
| 738 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 739 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 740 | - array(), #join |
|
| 741 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 742 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 743 | - $sous[6], #limit |
|
| 744 | - $sous[7] ? $sous[7] : array(), #having |
|
| 745 | - $table, $id, $serveur, false |
|
| 746 | - ) . ")"); |
|
| 747 | - } |
|
| 748 | - array_pop($where_simples); |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - foreach ($having as $k => $v) { |
|
| 752 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 753 | - unset($having[$k]); |
|
| 754 | - } |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - // Installer les jointures. |
|
| 758 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 759 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 760 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 761 | - |
|
| 762 | - $afrom = array(); |
|
| 763 | - $equiv = array(); |
|
| 764 | - $k = count($join); |
|
| 765 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 766 | - $cle = $cledef; |
|
| 767 | - // le format de join est : |
|
| 768 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 769 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 770 | - if (count($join[$cle]) == 2) { |
|
| 771 | - $join[$cle][] = $join[$cle][1]; |
|
| 772 | - } |
|
| 773 | - if (count($join[$cle]) == 3) { |
|
| 774 | - $join[$cle][] = ''; |
|
| 775 | - } |
|
| 776 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 777 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 778 | - // pour compat avec ancienne convention |
|
| 779 | - if (is_numeric($cle)) { |
|
| 780 | - $cle = "L$k"; |
|
| 781 | - } |
|
| 782 | - if (!$menage |
|
| 783 | - or isset($afrom[$cle]) |
|
| 784 | - or calculer_jointnul($cle, $select) |
|
| 785 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 786 | - or calculer_jointnul($cle, $having) |
|
| 787 | - or calculer_jointnul($cle, $where_simples) |
|
| 788 | - ) { |
|
| 789 | - // corriger les references non explicites dans select |
|
| 790 | - // ou groupby |
|
| 791 | - foreach ($select as $i => $s) { |
|
| 792 | - if ($s == $c) { |
|
| 793 | - $select[$i] = "$cle.$c AS $c"; |
|
| 794 | - break; |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - foreach ($groupby as $i => $g) { |
|
| 798 | - if ($g == $c) { |
|
| 799 | - $groupby[$i] = "$cle.$c"; |
|
| 800 | - break; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 804 | - // sans recours a preg_match |
|
| 805 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 806 | - $afrom[$t][$cle] = array( |
|
| 807 | - "\n" . |
|
| 808 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 809 | - $from[$cle], |
|
| 810 | - "AS $cle", |
|
| 811 | - "ON (", |
|
| 812 | - "$cle.$c", |
|
| 813 | - "=", |
|
| 814 | - "$t.$carr", |
|
| 815 | - ($and ? "AND " . $and : "") . |
|
| 816 | - ")" |
|
| 817 | - ); |
|
| 818 | - if (isset($afrom[$cle])) { |
|
| 819 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 820 | - unset($afrom[$cle]); |
|
| 821 | - } |
|
| 822 | - $equiv[] = $carr; |
|
| 823 | - } else { |
|
| 824 | - unset($join[$cledef]); |
|
| 825 | - } |
|
| 826 | - unset($from[$cle]); |
|
| 827 | - $k--; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - if (count($afrom)) { |
|
| 831 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 832 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 833 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 834 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 835 | - // ou dans |
|
| 836 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 837 | - // qui comporte plusieurs jointures |
|
| 838 | - // ou dans |
|
| 839 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 840 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 841 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 842 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 843 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 844 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 845 | - |
|
| 846 | - $t = key($from); |
|
| 847 | - $c = current($from); |
|
| 848 | - reset($from); |
|
| 849 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 850 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 851 | - calculer_jointnul($t, $select, $e) or |
|
| 852 | - calculer_jointnul($t, $join, $e) or |
|
| 853 | - calculer_jointnul($t, $where, $e) or |
|
| 854 | - calculer_jointnul($t, $orderby, $e) or |
|
| 855 | - calculer_jointnul($t, $groupby, $e) or |
|
| 856 | - calculer_jointnul($t, $having, $e)) |
|
| 857 | - && count($afrom[$t]) |
|
| 858 | - ) { |
|
| 859 | - $nfrom = reset($afrom[$t]); |
|
| 860 | - $nt = key($afrom[$t]); |
|
| 861 | - unset($from[$t]); |
|
| 862 | - $from[$nt] = $nfrom[1]; |
|
| 863 | - unset($afrom[$t][$nt]); |
|
| 864 | - $afrom[$nt] = $afrom[$t]; |
|
| 865 | - unset($afrom[$t]); |
|
| 866 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 867 | - $t = $nfrom[4]; |
|
| 868 | - $alias = ""; |
|
| 869 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 870 | - $oldcle = explode('.', $nfrom[6]); |
|
| 871 | - $oldcle = end($oldcle); |
|
| 872 | - $newcle = explode('.', $nfrom[4]); |
|
| 873 | - $newcle = end($newcle); |
|
| 874 | - if ($newcle != $oldcle) { |
|
| 875 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 876 | - // reprendre simplement ce AS |
|
| 877 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 878 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 879 | - $alias = ""; |
|
| 880 | - } else { |
|
| 881 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 882 | - } |
|
| 883 | - } |
|
| 884 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 885 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 886 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 887 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 888 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 889 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 890 | - } |
|
| 891 | - $from = reinjecte_joint($afrom, $from); |
|
| 892 | - } |
|
| 893 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 894 | - $r = sql_select($select, $from, $where, |
|
| 895 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 896 | - unset($GLOBALS['debug']['aucasou']); |
|
| 897 | - |
|
| 898 | - return $r; |
|
| 662 | + // retirer les criteres vides: |
|
| 663 | + // {X ?} avec X absent de l'URL |
|
| 664 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 665 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 666 | + $menage = false; |
|
| 667 | + foreach ($where as $k => $v) { |
|
| 668 | + if (is_array($v)) { |
|
| 669 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 670 | + $op = false; |
|
| 671 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 672 | + $op = false; |
|
| 673 | + } else { |
|
| 674 | + $op = $v[0] ? $v[0] : $v; |
|
| 675 | + } |
|
| 676 | + } else { |
|
| 677 | + $op = $v; |
|
| 678 | + } |
|
| 679 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 680 | + unset($where[$k]); |
|
| 681 | + $menage = true; |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 686 | + $groupby = array_diff($groupby, array('')); |
|
| 687 | + |
|
| 688 | + // remplacer les sous requetes recursives au calcul |
|
| 689 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 690 | + foreach ($where_sous as $k => $w) { |
|
| 691 | + $menage = true; |
|
| 692 | + // on recupere la sous requete |
|
| 693 | + $sous = match_self($w); |
|
| 694 | + if ($sous[0] == 'SELF') { |
|
| 695 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 696 | + array_push($where_simples, $sous[2]); |
|
| 697 | + $wheresub = array( |
|
| 698 | + $sous[2], |
|
| 699 | + '0=0' |
|
| 700 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 701 | + $jsub = $join; |
|
| 702 | + // trouver les jointures utiles a |
|
| 703 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 704 | + // ie L1.objet='article' |
|
| 705 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 706 | + $i = 0; |
|
| 707 | + do { |
|
| 708 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 709 | + array($sous[1] . " AS id"), |
|
| 710 | + $from, |
|
| 711 | + $from_type, |
|
| 712 | + $wheresub, |
|
| 713 | + $jsub, |
|
| 714 | + array(), array(), '', |
|
| 715 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 716 | + if (!$i) { |
|
| 717 | + $i = 1; |
|
| 718 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 719 | + foreach ($join as $cle => $wj) { |
|
| 720 | + if (count($wj) == 4 |
|
| 721 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 722 | + ) { |
|
| 723 | + $i = 0; |
|
| 724 | + $wheresub[] = $wj[3]; |
|
| 725 | + unset($jsub[$cle][3]); |
|
| 726 | + } |
|
| 727 | + } |
|
| 728 | + } |
|
| 729 | + } while ($i++ < 1); |
|
| 730 | + } |
|
| 731 | + if ($sous[0] == 'SUBSELECT') { |
|
| 732 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 733 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 734 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 735 | + $sous[1], # select |
|
| 736 | + $sous[2], #from |
|
| 737 | + array(), #from_type |
|
| 738 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 739 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 740 | + array(), #join |
|
| 741 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 742 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 743 | + $sous[6], #limit |
|
| 744 | + $sous[7] ? $sous[7] : array(), #having |
|
| 745 | + $table, $id, $serveur, false |
|
| 746 | + ) . ")"); |
|
| 747 | + } |
|
| 748 | + array_pop($where_simples); |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + foreach ($having as $k => $v) { |
|
| 752 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 753 | + unset($having[$k]); |
|
| 754 | + } |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + // Installer les jointures. |
|
| 758 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 759 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 760 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 761 | + |
|
| 762 | + $afrom = array(); |
|
| 763 | + $equiv = array(); |
|
| 764 | + $k = count($join); |
|
| 765 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 766 | + $cle = $cledef; |
|
| 767 | + // le format de join est : |
|
| 768 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 769 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 770 | + if (count($join[$cle]) == 2) { |
|
| 771 | + $join[$cle][] = $join[$cle][1]; |
|
| 772 | + } |
|
| 773 | + if (count($join[$cle]) == 3) { |
|
| 774 | + $join[$cle][] = ''; |
|
| 775 | + } |
|
| 776 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 777 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 778 | + // pour compat avec ancienne convention |
|
| 779 | + if (is_numeric($cle)) { |
|
| 780 | + $cle = "L$k"; |
|
| 781 | + } |
|
| 782 | + if (!$menage |
|
| 783 | + or isset($afrom[$cle]) |
|
| 784 | + or calculer_jointnul($cle, $select) |
|
| 785 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 786 | + or calculer_jointnul($cle, $having) |
|
| 787 | + or calculer_jointnul($cle, $where_simples) |
|
| 788 | + ) { |
|
| 789 | + // corriger les references non explicites dans select |
|
| 790 | + // ou groupby |
|
| 791 | + foreach ($select as $i => $s) { |
|
| 792 | + if ($s == $c) { |
|
| 793 | + $select[$i] = "$cle.$c AS $c"; |
|
| 794 | + break; |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + foreach ($groupby as $i => $g) { |
|
| 798 | + if ($g == $c) { |
|
| 799 | + $groupby[$i] = "$cle.$c"; |
|
| 800 | + break; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 804 | + // sans recours a preg_match |
|
| 805 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 806 | + $afrom[$t][$cle] = array( |
|
| 807 | + "\n" . |
|
| 808 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 809 | + $from[$cle], |
|
| 810 | + "AS $cle", |
|
| 811 | + "ON (", |
|
| 812 | + "$cle.$c", |
|
| 813 | + "=", |
|
| 814 | + "$t.$carr", |
|
| 815 | + ($and ? "AND " . $and : "") . |
|
| 816 | + ")" |
|
| 817 | + ); |
|
| 818 | + if (isset($afrom[$cle])) { |
|
| 819 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 820 | + unset($afrom[$cle]); |
|
| 821 | + } |
|
| 822 | + $equiv[] = $carr; |
|
| 823 | + } else { |
|
| 824 | + unset($join[$cledef]); |
|
| 825 | + } |
|
| 826 | + unset($from[$cle]); |
|
| 827 | + $k--; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + if (count($afrom)) { |
|
| 831 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 832 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 833 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 834 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 835 | + // ou dans |
|
| 836 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 837 | + // qui comporte plusieurs jointures |
|
| 838 | + // ou dans |
|
| 839 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 840 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 841 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 842 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 843 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 844 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 845 | + |
|
| 846 | + $t = key($from); |
|
| 847 | + $c = current($from); |
|
| 848 | + reset($from); |
|
| 849 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 850 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 851 | + calculer_jointnul($t, $select, $e) or |
|
| 852 | + calculer_jointnul($t, $join, $e) or |
|
| 853 | + calculer_jointnul($t, $where, $e) or |
|
| 854 | + calculer_jointnul($t, $orderby, $e) or |
|
| 855 | + calculer_jointnul($t, $groupby, $e) or |
|
| 856 | + calculer_jointnul($t, $having, $e)) |
|
| 857 | + && count($afrom[$t]) |
|
| 858 | + ) { |
|
| 859 | + $nfrom = reset($afrom[$t]); |
|
| 860 | + $nt = key($afrom[$t]); |
|
| 861 | + unset($from[$t]); |
|
| 862 | + $from[$nt] = $nfrom[1]; |
|
| 863 | + unset($afrom[$t][$nt]); |
|
| 864 | + $afrom[$nt] = $afrom[$t]; |
|
| 865 | + unset($afrom[$t]); |
|
| 866 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 867 | + $t = $nfrom[4]; |
|
| 868 | + $alias = ""; |
|
| 869 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 870 | + $oldcle = explode('.', $nfrom[6]); |
|
| 871 | + $oldcle = end($oldcle); |
|
| 872 | + $newcle = explode('.', $nfrom[4]); |
|
| 873 | + $newcle = end($newcle); |
|
| 874 | + if ($newcle != $oldcle) { |
|
| 875 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 876 | + // reprendre simplement ce AS |
|
| 877 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 878 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 879 | + $alias = ""; |
|
| 880 | + } else { |
|
| 881 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 882 | + } |
|
| 883 | + } |
|
| 884 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 885 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 886 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 887 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 888 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 889 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 890 | + } |
|
| 891 | + $from = reinjecte_joint($afrom, $from); |
|
| 892 | + } |
|
| 893 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 894 | + $r = sql_select($select, $from, $where, |
|
| 895 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 896 | + unset($GLOBALS['debug']['aucasou']); |
|
| 897 | + |
|
| 898 | + return $r; |
|
| 899 | 899 | } |
| 900 | 900 | |
| 901 | 901 | /** |
@@ -906,20 +906,20 @@ discard block |
||
| 906 | 906 | * @return string |
| 907 | 907 | */ |
| 908 | 908 | function calculer_where_to_string($v, $join = 'AND') { |
| 909 | - if (empty($v)) { |
|
| 910 | - return ''; |
|
| 911 | - } |
|
| 912 | - |
|
| 913 | - if (!is_array($v)) { |
|
| 914 | - return $v; |
|
| 915 | - } else { |
|
| 916 | - $exp = ""; |
|
| 917 | - if (strtoupper($join) === 'AND') { |
|
| 918 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 919 | - } else { |
|
| 920 | - return $exp . join($join, $v); |
|
| 921 | - } |
|
| 922 | - } |
|
| 909 | + if (empty($v)) { |
|
| 910 | + return ''; |
|
| 911 | + } |
|
| 912 | + |
|
| 913 | + if (!is_array($v)) { |
|
| 914 | + return $v; |
|
| 915 | + } else { |
|
| 916 | + $exp = ""; |
|
| 917 | + if (strtoupper($join) === 'AND') { |
|
| 918 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 919 | + } else { |
|
| 920 | + return $exp . join($join, $v); |
|
| 921 | + } |
|
| 922 | + } |
|
| 923 | 923 | } |
| 924 | 924 | |
| 925 | 925 | |
@@ -927,62 +927,62 @@ discard block |
||
| 927 | 927 | |
| 928 | 928 | // https://code.spip.net/@calculer_jointnul |
| 929 | 929 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 930 | - if (!is_array($exp)) { |
|
| 931 | - if ($equiv) { |
|
| 932 | - $exp = preg_replace($equiv, '', $exp); |
|
| 933 | - } |
|
| 934 | - |
|
| 935 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 936 | - } else { |
|
| 937 | - foreach ($exp as $v) { |
|
| 938 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 939 | - return true; |
|
| 940 | - } |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 930 | + if (!is_array($exp)) { |
|
| 931 | + if ($equiv) { |
|
| 932 | + $exp = preg_replace($equiv, '', $exp); |
|
| 933 | + } |
|
| 934 | + |
|
| 935 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 936 | + } else { |
|
| 937 | + foreach ($exp as $v) { |
|
| 938 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 939 | + return true; |
|
| 940 | + } |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | // https://code.spip.net/@reinjecte_joint |
| 948 | 948 | function reinjecte_joint($afrom, $from) { |
| 949 | - $from_synth = array(); |
|
| 950 | - foreach ($from as $k => $v) { |
|
| 951 | - $from_synth[$k] = $from[$k]; |
|
| 952 | - if (isset($afrom[$k])) { |
|
| 953 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 954 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 955 | - } |
|
| 956 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 957 | - unset($afrom[$k]); |
|
| 958 | - } |
|
| 959 | - } |
|
| 960 | - |
|
| 961 | - return $from_synth; |
|
| 949 | + $from_synth = array(); |
|
| 950 | + foreach ($from as $k => $v) { |
|
| 951 | + $from_synth[$k] = $from[$k]; |
|
| 952 | + if (isset($afrom[$k])) { |
|
| 953 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 954 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 955 | + } |
|
| 956 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 957 | + unset($afrom[$k]); |
|
| 958 | + } |
|
| 959 | + } |
|
| 960 | + |
|
| 961 | + return $from_synth; |
|
| 962 | 962 | } |
| 963 | 963 | |
| 964 | 964 | // https://code.spip.net/@remplacer_jointnul |
| 965 | 965 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 966 | - if (!is_array($exp)) { |
|
| 967 | - return preg_replace($equiv, $cle, $exp); |
|
| 968 | - } else { |
|
| 969 | - foreach ($exp as $k => $v) { |
|
| 970 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 971 | - } |
|
| 972 | - |
|
| 973 | - return $exp; |
|
| 974 | - } |
|
| 966 | + if (!is_array($exp)) { |
|
| 967 | + return preg_replace($equiv, $cle, $exp); |
|
| 968 | + } else { |
|
| 969 | + foreach ($exp as $k => $v) { |
|
| 970 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 971 | + } |
|
| 972 | + |
|
| 973 | + return $exp; |
|
| 974 | + } |
|
| 975 | 975 | } |
| 976 | 976 | |
| 977 | 977 | // calcul du nom du squelette |
| 978 | 978 | // https://code.spip.net/@calculer_nom_fonction_squel |
| 979 | 979 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 980 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 981 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 982 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 983 | - } |
|
| 984 | - |
|
| 985 | - return $mime_type |
|
| 986 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 987 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 980 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 981 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 982 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 983 | + } |
|
| 984 | + |
|
| 985 | + return $mime_type |
|
| 986 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 987 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 988 | 988 | } |
@@ -20,155 +20,155 @@ discard block |
||
| 20 | 20 | **/ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | // En cas de modification, il faut aussi actualiser la regexp de nettoyer_uri_var() dans inc/utils.php |
| 27 | 27 | if (!defined('_CONTEXTE_IGNORE_VARIABLES')) { |
| 28 | - define('_CONTEXTE_IGNORE_VARIABLES', "/(^var_|^PHPSESSID$|^fbclid$|^utm_)/"); |
|
| 28 | + define('_CONTEXTE_IGNORE_VARIABLES', "/(^var_|^PHPSESSID$|^fbclid$|^utm_)/"); |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // https://code.spip.net/@assembler |
| 32 | 32 | function assembler($fond, $connect = '') { |
| 33 | 33 | |
| 34 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | - |
|
| 38 | - $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | - $page = array('contexte_implicite' => calculer_contexte_implicite()); |
|
| 40 | - $page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '', |
|
| 41 | - preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI'])); |
|
| 42 | - // Cette fonction est utilisee deux fois |
|
| 43 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 44 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 45 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 46 | - if ($cacher) { |
|
| 47 | - $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 48 | - } else { |
|
| 49 | - $GLOBALS['use_cache'] = -1; |
|
| 50 | - } |
|
| 51 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 52 | - if ($res) { |
|
| 53 | - return array('texte' => $res); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - if (!$chemin_cache || !$lastmodified) { |
|
| 57 | - $lastmodified = time(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 61 | - $calculer_page = true; |
|
| 62 | - |
|
| 63 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 64 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 65 | - // pages sont dynamiques) |
|
| 66 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 67 | - and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 68 | - and $chemin_cache |
|
| 69 | - and isset($page['entetes']) |
|
| 70 | - and isset($page['entetes']['Cache-Control']) |
|
| 71 | - and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 72 | - and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 73 | - ) { |
|
| 74 | - $since = preg_replace('/;.*/', '', |
|
| 75 | - $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|
| 76 | - $since = str_replace('GMT', '', $since); |
|
| 77 | - if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) { |
|
| 78 | - $page['status'] = 304; |
|
| 79 | - $headers_only = true; |
|
| 80 | - $calculer_page = false; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - |
|
| 84 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 85 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 86 | - if (!$calculer_page) { |
|
| 87 | - $page['texte'] = ""; |
|
| 88 | - } else { |
|
| 89 | - // si la page est prise dans le cache |
|
| 90 | - if (!$GLOBALS['use_cache']) { |
|
| 91 | - // Informer les boutons d'admin du contexte |
|
| 92 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 93 | - $GLOBALS['contexte'] = $page['contexte']; |
|
| 94 | - |
|
| 95 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 96 | - // d'inversion url => objet |
|
| 97 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 98 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 99 | - #unset($_ENV['url_propre']); |
|
| 100 | - } else { |
|
| 101 | - // Compat ascendante : |
|
| 102 | - // 1. $contexte est global |
|
| 103 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 104 | - // et calculer la page |
|
| 105 | - if (!test_espace_prive()) { |
|
| 106 | - include_spip('inc/urls'); |
|
| 107 | - list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url(nettoyer_uri(), $fond, $GLOBALS['contexte'], |
|
| 108 | - true); |
|
| 109 | - } |
|
| 110 | - // squelette par defaut |
|
| 111 | - if (!strlen($fond)) { |
|
| 112 | - $fond = 'sommaire'; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // produire la page : peut mettre a jour $lastmodified |
|
| 116 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 117 | - $page = $produire_page($fond, $GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, null, $page, |
|
| 118 | - $lastmodified, $connect); |
|
| 119 | - if ($page === '') { |
|
| 120 | - $erreur = _T('info_erreur_squelette2', |
|
| 121 | - array('fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES)); |
|
| 122 | - erreur_squelette($erreur); |
|
| 123 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 124 | - $page = array('texte' => '', 'erreur' => $erreur); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - if ($page and $chemin_cache) { |
|
| 129 | - $page['cache'] = $chemin_cache; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - auto_content_type($page); |
|
| 133 | - |
|
| 134 | - $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 135 | - |
|
| 136 | - // Definir les entetes si ce n'est fait |
|
| 137 | - if (!$GLOBALS['flag_preserver']) { |
|
| 138 | - if ($GLOBALS['flag_ob']) { |
|
| 139 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 140 | - if (trim($page['texte']) === '' |
|
| 141 | - and _VAR_MODE != 'debug' |
|
| 142 | - and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 143 | - ) { |
|
| 144 | - $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 145 | - $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 146 | - } |
|
| 147 | - // pas de cache client en mode 'observation' |
|
| 148 | - if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 149 | - $page['entetes']["Cache-Control"] = "no-cache,must-revalidate"; |
|
| 150 | - $page['entetes']["Pragma"] = "no-cache"; |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - // Entete Last-Modified: |
|
| 157 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 158 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 159 | - if ($lastmodified |
|
| 160 | - and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 161 | - and !isset($page['entetes']["Last-Modified"]) |
|
| 162 | - ) { |
|
| 163 | - $page['entetes']["Last-Modified"] = gmdate("D, d M Y H:i:s", $lastmodified) . " GMT"; |
|
| 164 | - } |
|
| 165 | - |
|
| 166 | - // fermer la connexion apres les headers si requete HEAD |
|
| 167 | - if ($headers_only) { |
|
| 168 | - $page['entetes']["Connection"] = "close"; |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - return $page; |
|
| 34 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 35 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 36 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 37 | + |
|
| 38 | + $GLOBALS['contexte'] = calculer_contexte(); |
|
| 39 | + $page = array('contexte_implicite' => calculer_contexte_implicite()); |
|
| 40 | + $page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '', |
|
| 41 | + preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI'])); |
|
| 42 | + // Cette fonction est utilisee deux fois |
|
| 43 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 44 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 45 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 46 | + if ($cacher) { |
|
| 47 | + $res = $cacher($GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, $page, $lastmodified); |
|
| 48 | + } else { |
|
| 49 | + $GLOBALS['use_cache'] = -1; |
|
| 50 | + } |
|
| 51 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 52 | + if ($res) { |
|
| 53 | + return array('texte' => $res); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + if (!$chemin_cache || !$lastmodified) { |
|
| 57 | + $lastmodified = time(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 61 | + $calculer_page = true; |
|
| 62 | + |
|
| 63 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 64 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 65 | + // pages sont dynamiques) |
|
| 66 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 67 | + and (!defined('_VAR_MODE') or !_VAR_MODE) |
|
| 68 | + and $chemin_cache |
|
| 69 | + and isset($page['entetes']) |
|
| 70 | + and isset($page['entetes']['Cache-Control']) |
|
| 71 | + and strstr($page['entetes']['Cache-Control'], 'max-age=') |
|
| 72 | + and !strstr($_SERVER['SERVER_SOFTWARE'], 'IIS/') |
|
| 73 | + ) { |
|
| 74 | + $since = preg_replace('/;.*/', '', |
|
| 75 | + $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|
| 76 | + $since = str_replace('GMT', '', $since); |
|
| 77 | + if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) { |
|
| 78 | + $page['status'] = 304; |
|
| 79 | + $headers_only = true; |
|
| 80 | + $calculer_page = false; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + |
|
| 84 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 85 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 86 | + if (!$calculer_page) { |
|
| 87 | + $page['texte'] = ""; |
|
| 88 | + } else { |
|
| 89 | + // si la page est prise dans le cache |
|
| 90 | + if (!$GLOBALS['use_cache']) { |
|
| 91 | + // Informer les boutons d'admin du contexte |
|
| 92 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 93 | + $GLOBALS['contexte'] = $page['contexte']; |
|
| 94 | + |
|
| 95 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 96 | + // d'inversion url => objet |
|
| 97 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 98 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 99 | + #unset($_ENV['url_propre']); |
|
| 100 | + } else { |
|
| 101 | + // Compat ascendante : |
|
| 102 | + // 1. $contexte est global |
|
| 103 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 104 | + // et calculer la page |
|
| 105 | + if (!test_espace_prive()) { |
|
| 106 | + include_spip('inc/urls'); |
|
| 107 | + list($fond, $GLOBALS['contexte'], $url_redirect) = urls_decoder_url(nettoyer_uri(), $fond, $GLOBALS['contexte'], |
|
| 108 | + true); |
|
| 109 | + } |
|
| 110 | + // squelette par defaut |
|
| 111 | + if (!strlen($fond)) { |
|
| 112 | + $fond = 'sommaire'; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // produire la page : peut mettre a jour $lastmodified |
|
| 116 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 117 | + $page = $produire_page($fond, $GLOBALS['contexte'], $GLOBALS['use_cache'], $chemin_cache, null, $page, |
|
| 118 | + $lastmodified, $connect); |
|
| 119 | + if ($page === '') { |
|
| 120 | + $erreur = _T('info_erreur_squelette2', |
|
| 121 | + array('fichier' => spip_htmlspecialchars($fond) . '.' . _EXTENSION_SQUELETTES)); |
|
| 122 | + erreur_squelette($erreur); |
|
| 123 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 124 | + $page = array('texte' => '', 'erreur' => $erreur); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + if ($page and $chemin_cache) { |
|
| 129 | + $page['cache'] = $chemin_cache; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + auto_content_type($page); |
|
| 133 | + |
|
| 134 | + $GLOBALS['flag_preserver'] |= headers_sent(); |
|
| 135 | + |
|
| 136 | + // Definir les entetes si ce n'est fait |
|
| 137 | + if (!$GLOBALS['flag_preserver']) { |
|
| 138 | + if ($GLOBALS['flag_ob']) { |
|
| 139 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 140 | + if (trim($page['texte']) === '' |
|
| 141 | + and _VAR_MODE != 'debug' |
|
| 142 | + and !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 143 | + ) { |
|
| 144 | + $GLOBALS['contexte']['fond_erreur'] = $fond; |
|
| 145 | + $page = message_page_indisponible($page, $GLOBALS['contexte']); |
|
| 146 | + } |
|
| 147 | + // pas de cache client en mode 'observation' |
|
| 148 | + if (defined('_VAR_MODE') and _VAR_MODE) { |
|
| 149 | + $page['entetes']["Cache-Control"] = "no-cache,must-revalidate"; |
|
| 150 | + $page['entetes']["Pragma"] = "no-cache"; |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + // Entete Last-Modified: |
|
| 157 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 158 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 159 | + if ($lastmodified |
|
| 160 | + and !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 161 | + and !isset($page['entetes']["Last-Modified"]) |
|
| 162 | + ) { |
|
| 163 | + $page['entetes']["Last-Modified"] = gmdate("D, d M Y H:i:s", $lastmodified) . " GMT"; |
|
| 164 | + } |
|
| 165 | + |
|
| 166 | + // fermer la connexion apres les headers si requete HEAD |
|
| 167 | + if ($headers_only) { |
|
| 168 | + $page['entetes']["Connection"] = "close"; |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + return $page; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -187,19 +187,19 @@ discard block |
||
| 187 | 187 | */ |
| 188 | 188 | function calculer_contexte() { |
| 189 | 189 | |
| 190 | - $contexte = array(); |
|
| 191 | - foreach ($_GET as $var => $val) { |
|
| 192 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 193 | - $contexte[$var] = $val; |
|
| 194 | - } |
|
| 195 | - } |
|
| 196 | - foreach ($_POST as $var => $val) { |
|
| 197 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 198 | - $contexte[$var] = $val; |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - return $contexte; |
|
| 190 | + $contexte = array(); |
|
| 191 | + foreach ($_GET as $var => $val) { |
|
| 192 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 193 | + $contexte[$var] = $val; |
|
| 194 | + } |
|
| 195 | + } |
|
| 196 | + foreach ($_POST as $var => $val) { |
|
| 197 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES, $var)) { |
|
| 198 | + $contexte[$var] = $val; |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + return $contexte; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | /** |
@@ -210,25 +210,25 @@ discard block |
||
| 210 | 210 | * @return array |
| 211 | 211 | */ |
| 212 | 212 | function calculer_contexte_implicite() { |
| 213 | - static $notes = null; |
|
| 214 | - if (is_null($notes)) { |
|
| 215 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 216 | - } |
|
| 217 | - $contexte_implicite = array( |
|
| 218 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 219 | - 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 220 | - 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 221 | - 'espace' => test_espace_prive(), |
|
| 222 | - 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 223 | - 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 224 | - 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 225 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 226 | - ); |
|
| 227 | - if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 228 | - $contexte_implicite['host'] .= "|" . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - return $contexte_implicite; |
|
| 213 | + static $notes = null; |
|
| 214 | + if (is_null($notes)) { |
|
| 215 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 216 | + } |
|
| 217 | + $contexte_implicite = array( |
|
| 218 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 219 | + 'host' => (isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : null), |
|
| 220 | + 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 221 | + 'espace' => test_espace_prive(), |
|
| 222 | + 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 223 | + 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 224 | + 'notes' => $notes ? $notes('', 'contexter_cache') : '', |
|
| 225 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 226 | + ); |
|
| 227 | + if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) { |
|
| 228 | + $contexte_implicite['host'] .= "|" . $_SERVER['HTTP_X_FORWARDED_HOST']; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + return $contexte_implicite; |
|
| 232 | 232 | } |
| 233 | 233 | |
| 234 | 234 | // |
@@ -238,50 +238,50 @@ discard block |
||
| 238 | 238 | // https://code.spip.net/@auto_content_type |
| 239 | 239 | function auto_content_type($page) { |
| 240 | 240 | |
| 241 | - if (!isset($GLOBALS['flag_preserver'])) { |
|
| 242 | - $GLOBALS['flag_preserver'] = ($page && preg_match("/header\s*\(\s*.content\-type:/isx", |
|
| 243 | - $page['texte']) || (isset($page['entetes']['Content-Type']))); |
|
| 244 | - } |
|
| 241 | + if (!isset($GLOBALS['flag_preserver'])) { |
|
| 242 | + $GLOBALS['flag_preserver'] = ($page && preg_match("/header\s*\(\s*.content\-type:/isx", |
|
| 243 | + $page['texte']) || (isset($page['entetes']['Content-Type']))); |
|
| 244 | + } |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | // https://code.spip.net/@inclure_page |
| 248 | 248 | function inclure_page($fond, $contexte, $connect = '') { |
| 249 | - static $cacher, $produire_page; |
|
| 250 | - |
|
| 251 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 252 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 253 | - // (cette precaution n'est probablement plus utile) |
|
| 254 | - unset($contexte['fond']); |
|
| 255 | - $page = array('contexte_implicite' => calculer_contexte_implicite()); |
|
| 256 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 257 | - if (is_null($cacher)) { |
|
| 258 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 259 | - } |
|
| 260 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 261 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 262 | - if ($cacher) { |
|
| 263 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 264 | - } else { |
|
| 265 | - $use_cache = -1; |
|
| 266 | - } |
|
| 267 | - // $res = message d'erreur : on sort de la |
|
| 268 | - if ($res) { |
|
| 269 | - return array('texte' => $res); |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 273 | - // produire la page : peut mettre a jour $lastinclude |
|
| 274 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 275 | - if ($use_cache) { |
|
| 276 | - if (is_null($produire_page)) { |
|
| 277 | - $produire_page = charger_fonction('produire_page', 'public'); |
|
| 278 | - } |
|
| 279 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 280 | - } |
|
| 281 | - // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 282 | - $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 283 | - |
|
| 284 | - return $page; |
|
| 249 | + static $cacher, $produire_page; |
|
| 250 | + |
|
| 251 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 252 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 253 | + // (cette precaution n'est probablement plus utile) |
|
| 254 | + unset($contexte['fond']); |
|
| 255 | + $page = array('contexte_implicite' => calculer_contexte_implicite()); |
|
| 256 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 257 | + if (is_null($cacher)) { |
|
| 258 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 259 | + } |
|
| 260 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 261 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 262 | + if ($cacher) { |
|
| 263 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 264 | + } else { |
|
| 265 | + $use_cache = -1; |
|
| 266 | + } |
|
| 267 | + // $res = message d'erreur : on sort de la |
|
| 268 | + if ($res) { |
|
| 269 | + return array('texte' => $res); |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 273 | + // produire la page : peut mettre a jour $lastinclude |
|
| 274 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 275 | + if ($use_cache) { |
|
| 276 | + if (is_null($produire_page)) { |
|
| 277 | + $produire_page = charger_fonction('produire_page', 'public'); |
|
| 278 | + } |
|
| 279 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 280 | + } |
|
| 281 | + // dans tous les cas, mettre a jour $GLOBALS['lastmodified'] |
|
| 282 | + $GLOBALS['lastmodified'] = max((isset($GLOBALS['lastmodified']) ? $GLOBALS['lastmodified'] : 0), $lastinclude); |
|
| 283 | + |
|
| 284 | + return $page; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -299,40 +299,40 @@ discard block |
||
| 299 | 299 | * @return array |
| 300 | 300 | */ |
| 301 | 301 | function public_produire_page_dist( |
| 302 | - $fond, |
|
| 303 | - $contexte, |
|
| 304 | - $use_cache, |
|
| 305 | - $chemin_cache, |
|
| 306 | - $contexte_cache, |
|
| 307 | - &$page, |
|
| 308 | - &$lastinclude, |
|
| 309 | - $connect = '' |
|
| 302 | + $fond, |
|
| 303 | + $contexte, |
|
| 304 | + $use_cache, |
|
| 305 | + $chemin_cache, |
|
| 306 | + $contexte_cache, |
|
| 307 | + &$page, |
|
| 308 | + &$lastinclude, |
|
| 309 | + $connect = '' |
|
| 310 | 310 | ) { |
| 311 | - static $parametrer, $cacher; |
|
| 312 | - if (!$parametrer) { |
|
| 313 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 314 | - } |
|
| 315 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 316 | - // et on l'enregistre sur le disque |
|
| 317 | - if ($chemin_cache |
|
| 318 | - and $use_cache > -1 |
|
| 319 | - and is_array($page) |
|
| 320 | - and count($page) |
|
| 321 | - and isset($page['entetes']['X-Spip-Cache']) |
|
| 322 | - and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 323 | - ) { |
|
| 324 | - if (is_null($cacher)) { |
|
| 325 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 326 | - } |
|
| 327 | - $lastinclude = time(); |
|
| 328 | - if ($cacher) { |
|
| 329 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 330 | - } else { |
|
| 331 | - $use_cache = -1; |
|
| 332 | - } |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - return $page; |
|
| 311 | + static $parametrer, $cacher; |
|
| 312 | + if (!$parametrer) { |
|
| 313 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 314 | + } |
|
| 315 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 316 | + // et on l'enregistre sur le disque |
|
| 317 | + if ($chemin_cache |
|
| 318 | + and $use_cache > -1 |
|
| 319 | + and is_array($page) |
|
| 320 | + and count($page) |
|
| 321 | + and isset($page['entetes']['X-Spip-Cache']) |
|
| 322 | + and $page['entetes']['X-Spip-Cache'] > 0 |
|
| 323 | + ) { |
|
| 324 | + if (is_null($cacher)) { |
|
| 325 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 326 | + } |
|
| 327 | + $lastinclude = time(); |
|
| 328 | + if ($cacher) { |
|
| 329 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 330 | + } else { |
|
| 331 | + $use_cache = -1; |
|
| 332 | + } |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + return $page; |
|
| 336 | 336 | } |
| 337 | 337 | |
| 338 | 338 | // Fonction inseree par le compilateur dans le code compile. |
@@ -346,14 +346,14 @@ discard block |
||
| 346 | 346 | // 4: langue |
| 347 | 347 | |
| 348 | 348 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) { |
| 349 | - arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 350 | - |
|
| 351 | - if (!is_array($contexte_exec)) { |
|
| 352 | - echo $contexte_exec; |
|
| 353 | - } // message d'erreur etc |
|
| 354 | - else { |
|
| 355 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 356 | - } |
|
| 349 | + arguments_balise_dyn_depuis_modele(null, 'reset'); |
|
| 350 | + |
|
| 351 | + if (!is_array($contexte_exec)) { |
|
| 352 | + echo $contexte_exec; |
|
| 353 | + } // message d'erreur etc |
|
| 354 | + else { |
|
| 355 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -368,97 +368,97 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function inclure_balise_dynamique($texte, $echo = true, $contexte_compil = array()) { |
| 371 | - if (is_array($texte)) { |
|
| 372 | - |
|
| 373 | - list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 374 | - |
|
| 375 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 376 | - $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 377 | - $GLOBALS['delais'] = $delainc; |
|
| 378 | - |
|
| 379 | - $page = recuperer_fond($fond, $contexte_inclus, |
|
| 380 | - array('trim' => false, 'raw' => true, 'compil' => $contexte_compil)); |
|
| 381 | - |
|
| 382 | - $texte = $page['texte']; |
|
| 383 | - |
|
| 384 | - $GLOBALS['delais'] = $d; |
|
| 385 | - // Faire remonter les entetes |
|
| 386 | - if (is_array($page['entetes'])) { |
|
| 387 | - // mais pas toutes |
|
| 388 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 389 | - unset($page['entetes']['Content-Type']); |
|
| 390 | - if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 391 | - if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 392 | - $GLOBALS['page']['entetes'] = array(); |
|
| 393 | - } |
|
| 394 | - $GLOBALS['page']['entetes'] = |
|
| 395 | - array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 399 | - if (isset($page['contexte']['_pipelines']) |
|
| 400 | - and is_array($page['contexte']['_pipelines']) |
|
| 401 | - and count($page['contexte']['_pipelines']) |
|
| 402 | - ) { |
|
| 403 | - foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 404 | - $args['contexte'] = $page['contexte']; |
|
| 405 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 406 | - $texte = pipeline( |
|
| 407 | - $pipe, |
|
| 408 | - array( |
|
| 409 | - 'data' => $texte, |
|
| 410 | - 'args' => $args |
|
| 411 | - ), |
|
| 412 | - false |
|
| 413 | - ); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - |
|
| 418 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 419 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 420 | - $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 421 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 422 | - } |
|
| 423 | - if ($echo) { |
|
| 424 | - echo $texte; |
|
| 425 | - } else { |
|
| 426 | - return $texte; |
|
| 427 | - } |
|
| 371 | + if (is_array($texte)) { |
|
| 372 | + |
|
| 373 | + list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 374 | + |
|
| 375 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 376 | + $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : null; |
|
| 377 | + $GLOBALS['delais'] = $delainc; |
|
| 378 | + |
|
| 379 | + $page = recuperer_fond($fond, $contexte_inclus, |
|
| 380 | + array('trim' => false, 'raw' => true, 'compil' => $contexte_compil)); |
|
| 381 | + |
|
| 382 | + $texte = $page['texte']; |
|
| 383 | + |
|
| 384 | + $GLOBALS['delais'] = $d; |
|
| 385 | + // Faire remonter les entetes |
|
| 386 | + if (is_array($page['entetes'])) { |
|
| 387 | + // mais pas toutes |
|
| 388 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 389 | + unset($page['entetes']['Content-Type']); |
|
| 390 | + if (isset($GLOBALS['page']) and is_array($GLOBALS['page'])) { |
|
| 391 | + if (!is_array($GLOBALS['page']['entetes'])) { |
|
| 392 | + $GLOBALS['page']['entetes'] = array(); |
|
| 393 | + } |
|
| 394 | + $GLOBALS['page']['entetes'] = |
|
| 395 | + array_merge($GLOBALS['page']['entetes'], $page['entetes']); |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 399 | + if (isset($page['contexte']['_pipelines']) |
|
| 400 | + and is_array($page['contexte']['_pipelines']) |
|
| 401 | + and count($page['contexte']['_pipelines']) |
|
| 402 | + ) { |
|
| 403 | + foreach ($page['contexte']['_pipelines'] as $pipe => $args) { |
|
| 404 | + $args['contexte'] = $page['contexte']; |
|
| 405 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 406 | + $texte = pipeline( |
|
| 407 | + $pipe, |
|
| 408 | + array( |
|
| 409 | + 'data' => $texte, |
|
| 410 | + 'args' => $args |
|
| 411 | + ), |
|
| 412 | + false |
|
| 413 | + ); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + |
|
| 418 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 419 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 420 | + $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 421 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 422 | + } |
|
| 423 | + if ($echo) { |
|
| 424 | + echo $texte; |
|
| 425 | + } else { |
|
| 426 | + return $texte; |
|
| 427 | + } |
|
| 428 | 428 | } |
| 429 | 429 | |
| 430 | 430 | // https://code.spip.net/@message_page_indisponible |
| 431 | 431 | function message_page_indisponible($page, $contexte) { |
| 432 | - static $deja = false; |
|
| 433 | - if ($deja) { |
|
| 434 | - return "erreur"; |
|
| 435 | - } |
|
| 436 | - $codes = array( |
|
| 437 | - '404' => '404 Not Found', |
|
| 438 | - '503' => '503 Service Unavailable', |
|
| 439 | - ); |
|
| 440 | - |
|
| 441 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 442 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 443 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 444 | - if (!isset($contexte['lang'])) { |
|
| 445 | - include_spip('inc/lang'); |
|
| 446 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $deja = true; |
|
| 450 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 451 | - // ex restriction d'acces => 401 |
|
| 452 | - $contexte = pipeline('page_indisponible', $contexte); |
|
| 453 | - |
|
| 454 | - // produire la page d'erreur |
|
| 455 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 456 | - if (!$page) { |
|
| 457 | - $page = inclure_page('404', $contexte); |
|
| 458 | - } |
|
| 459 | - $page['status'] = $contexte['status']; |
|
| 460 | - |
|
| 461 | - return $page; |
|
| 432 | + static $deja = false; |
|
| 433 | + if ($deja) { |
|
| 434 | + return "erreur"; |
|
| 435 | + } |
|
| 436 | + $codes = array( |
|
| 437 | + '404' => '404 Not Found', |
|
| 438 | + '503' => '503 Service Unavailable', |
|
| 439 | + ); |
|
| 440 | + |
|
| 441 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 442 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 443 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 444 | + if (!isset($contexte['lang'])) { |
|
| 445 | + include_spip('inc/lang'); |
|
| 446 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $deja = true; |
|
| 450 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 451 | + // ex restriction d'acces => 401 |
|
| 452 | + $contexte = pipeline('page_indisponible', $contexte); |
|
| 453 | + |
|
| 454 | + // produire la page d'erreur |
|
| 455 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 456 | + if (!$page) { |
|
| 457 | + $page = inclure_page('404', $contexte); |
|
| 458 | + } |
|
| 459 | + $page['status'] = $contexte['status']; |
|
| 460 | + |
|
| 461 | + return $page; |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -470,46 +470,46 @@ discard block |
||
| 470 | 470 | * @return mixed |
| 471 | 471 | */ |
| 472 | 472 | function arguments_balise_dyn_depuis_modele($arg, $operation = 'set') { |
| 473 | - static $balise_dyn_appellee_par_modele = null; |
|
| 474 | - switch ($operation) { |
|
| 475 | - case 'read': |
|
| 476 | - return $balise_dyn_appellee_par_modele; |
|
| 477 | - case 'reset': |
|
| 478 | - $balise_dyn_appellee_par_modele = null; |
|
| 479 | - return null; |
|
| 480 | - case 'set': |
|
| 481 | - default: |
|
| 482 | - $balise_dyn_appellee_par_modele = $arg; |
|
| 483 | - return $arg; |
|
| 484 | - } |
|
| 473 | + static $balise_dyn_appellee_par_modele = null; |
|
| 474 | + switch ($operation) { |
|
| 475 | + case 'read': |
|
| 476 | + return $balise_dyn_appellee_par_modele; |
|
| 477 | + case 'reset': |
|
| 478 | + $balise_dyn_appellee_par_modele = null; |
|
| 479 | + return null; |
|
| 480 | + case 'set': |
|
| 481 | + default: |
|
| 482 | + $balise_dyn_appellee_par_modele = $arg; |
|
| 483 | + return $arg; |
|
| 484 | + } |
|
| 485 | 485 | } |
| 486 | 486 | |
| 487 | 487 | // temporairement ici : a mettre dans le futur inc/modeles |
| 488 | 488 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 489 | 489 | // https://code.spip.net/@creer_contexte_de_modele |
| 490 | 490 | function creer_contexte_de_modele($args) { |
| 491 | - $contexte = array(); |
|
| 492 | - foreach ($args as $var => $val) { |
|
| 493 | - if (is_int($var)) { // argument pas formate |
|
| 494 | - if (in_array($val, array('left', 'right', 'center'))) { |
|
| 495 | - $var = 'align'; |
|
| 496 | - $contexte[$var] = $val; |
|
| 497 | - } else { |
|
| 498 | - $args = explode('=', $val); |
|
| 499 | - if (count($args) >= 2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 500 | - { |
|
| 501 | - $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 502 | - } else // notation abregee |
|
| 503 | - { |
|
| 504 | - $contexte[trim($val)] = trim($val); |
|
| 505 | - } |
|
| 506 | - } |
|
| 507 | - } else { |
|
| 508 | - $contexte[$var] = $val; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - |
|
| 512 | - return $contexte; |
|
| 491 | + $contexte = array(); |
|
| 492 | + foreach ($args as $var => $val) { |
|
| 493 | + if (is_int($var)) { // argument pas formate |
|
| 494 | + if (in_array($val, array('left', 'right', 'center'))) { |
|
| 495 | + $var = 'align'; |
|
| 496 | + $contexte[$var] = $val; |
|
| 497 | + } else { |
|
| 498 | + $args = explode('=', $val); |
|
| 499 | + if (count($args) >= 2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 500 | + { |
|
| 501 | + $contexte[trim($args[0])] = substr($val, strlen($args[0]) + 1); |
|
| 502 | + } else // notation abregee |
|
| 503 | + { |
|
| 504 | + $contexte[trim($val)] = trim($val); |
|
| 505 | + } |
|
| 506 | + } |
|
| 507 | + } else { |
|
| 508 | + $contexte[$var] = $val; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + |
|
| 512 | + return $contexte; |
|
| 513 | 513 | } |
| 514 | 514 | |
| 515 | 515 | /** |
@@ -524,40 +524,40 @@ discard block |
||
| 524 | 524 | * @return string |
| 525 | 525 | */ |
| 526 | 526 | function styliser_modele($modele, $id, $contexte=null) { |
| 527 | - static $styliseurs = null; |
|
| 528 | - if (is_null($styliseurs)) { |
|
| 529 | - $tables_objet = lister_tables_objets_sql(); |
|
| 530 | - foreach ($tables_objet as $table => $desc) { |
|
| 531 | - if (isset($desc['modeles']) and $desc['modeles'] |
|
| 532 | - and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 533 | - and function_exists($desc['modeles_styliser'])) { |
|
| 534 | - $primary = id_table_objet($table); |
|
| 535 | - foreach ($desc['modeles'] as $m) { |
|
| 536 | - $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - if (isset($styliseurs[$modele])) { |
|
| 543 | - $styliseur = $styliseurs[$modele]['callback']; |
|
| 544 | - if (is_null($id) and $contexte) { |
|
| 545 | - if (isset($contexte['id'])) { |
|
| 546 | - $id = $contexte['id']; |
|
| 547 | - } elseif (isset($contexte[$primary])) { |
|
| 548 | - $id = $contexte[$primary]; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - if (is_null($id)) { |
|
| 552 | - $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', array('param' => "id/$primary")); |
|
| 553 | - erreur_squelette($msg); |
|
| 554 | - // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 555 | - $id = 0; |
|
| 556 | - } |
|
| 557 | - $modele = $styliseur($modele, $id); |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - return $modele; |
|
| 527 | + static $styliseurs = null; |
|
| 528 | + if (is_null($styliseurs)) { |
|
| 529 | + $tables_objet = lister_tables_objets_sql(); |
|
| 530 | + foreach ($tables_objet as $table => $desc) { |
|
| 531 | + if (isset($desc['modeles']) and $desc['modeles'] |
|
| 532 | + and isset($desc['modeles_styliser']) and $desc['modeles_styliser'] |
|
| 533 | + and function_exists($desc['modeles_styliser'])) { |
|
| 534 | + $primary = id_table_objet($table); |
|
| 535 | + foreach ($desc['modeles'] as $m) { |
|
| 536 | + $styliseurs[$m] = ['primary' => $primary, 'callback' => $desc['modeles_styliser']]; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + if (isset($styliseurs[$modele])) { |
|
| 543 | + $styliseur = $styliseurs[$modele]['callback']; |
|
| 544 | + if (is_null($id) and $contexte) { |
|
| 545 | + if (isset($contexte['id'])) { |
|
| 546 | + $id = $contexte['id']; |
|
| 547 | + } elseif (isset($contexte[$primary])) { |
|
| 548 | + $id = $contexte[$primary]; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + if (is_null($id)) { |
|
| 552 | + $msg = "modeles/$modele : " . _T('zbug_parametres_inclus_incorrects', array('param' => "id/$primary")); |
|
| 553 | + erreur_squelette($msg); |
|
| 554 | + // on passe id=0 au routeur pour tomber sur le modele par defaut et eviter une seconde erreur sur un modele inexistant |
|
| 555 | + $id = 0; |
|
| 556 | + } |
|
| 557 | + $modele = $styliseur($modele, $id); |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + return $modele; |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -576,95 +576,95 @@ discard block |
||
| 576 | 576 | */ |
| 577 | 577 | function inclure_modele($type, $id, $params, $lien, $connect = '', $env = array()) { |
| 578 | 578 | |
| 579 | - static $compteur; |
|
| 580 | - if (++$compteur > 10) { |
|
| 581 | - return ''; |
|
| 582 | - } # ne pas boucler indefiniment |
|
| 583 | - |
|
| 584 | - $type = strtolower($type); |
|
| 585 | - $type = styliser_modele($type, $id); |
|
| 586 | - |
|
| 587 | - $fond = $class = ''; |
|
| 588 | - |
|
| 589 | - $params = array_filter(explode('|', $params)); |
|
| 590 | - if ($params) { |
|
| 591 | - $soustype = current($params); |
|
| 592 | - $soustype = strtolower(trim($soustype)); |
|
| 593 | - if (in_array($soustype, array('left', 'right', 'center', 'ajax'))) { |
|
| 594 | - $soustype = next($params); |
|
| 595 | - $soustype = strtolower($soustype); |
|
| 596 | - } |
|
| 597 | - |
|
| 598 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 599 | - if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 600 | - $fond = ''; |
|
| 601 | - $class = $soustype; |
|
| 602 | - } |
|
| 603 | - // enlever le sous type des params |
|
| 604 | - $params = array_diff($params, array($soustype)); |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - |
|
| 608 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 609 | - if (!$fond and !trouve_modele($fond = $type)) { |
|
| 610 | - spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 611 | - |
|
| 612 | - return false; |
|
| 613 | - } |
|
| 614 | - $fond = 'modeles/' . $fond; |
|
| 615 | - // Creer le contexte |
|
| 616 | - $contexte = $env; |
|
| 617 | - $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 618 | - |
|
| 619 | - // Le numero du modele est mis dans l'environnement |
|
| 620 | - // d'une part sous l'identifiant "id" |
|
| 621 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 622 | - // par la fonction id_table_objet, |
|
| 623 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 624 | - $_id = id_table_objet($type); |
|
| 625 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 626 | - |
|
| 627 | - if (isset($class)) { |
|
| 628 | - $contexte['class'] = $class; |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 632 | - if ($lien) { |
|
| 633 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 634 | - $contexte['lien'] = str_replace(""", '"', $lien['href']); |
|
| 635 | - $contexte['lien_class'] = $lien['class']; |
|
| 636 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 637 | - $contexte['lien_title'] = $lien['title']; |
|
| 638 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - // Traiter les parametres |
|
| 642 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 643 | - $arg_list = creer_contexte_de_modele($params); |
|
| 644 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 645 | - $contexte = array_merge($contexte, $arg_list); |
|
| 646 | - |
|
| 647 | - // Appliquer le modele avec le contexte |
|
| 648 | - $retour = recuperer_fond($fond, $contexte, array(), $connect); |
|
| 649 | - |
|
| 650 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 651 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 652 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 653 | - if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 654 | - 'spip_lien_ok')) { |
|
| 655 | - $retour = inserer_attribut($retour, 'class', |
|
| 656 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes "))); |
|
| 657 | - } else { |
|
| 658 | - if ($lien) { |
|
| 659 | - $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . "</a>"; |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $compteur--; |
|
| 664 | - |
|
| 665 | - return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 666 | - ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 667 | - : $retour; |
|
| 579 | + static $compteur; |
|
| 580 | + if (++$compteur > 10) { |
|
| 581 | + return ''; |
|
| 582 | + } # ne pas boucler indefiniment |
|
| 583 | + |
|
| 584 | + $type = strtolower($type); |
|
| 585 | + $type = styliser_modele($type, $id); |
|
| 586 | + |
|
| 587 | + $fond = $class = ''; |
|
| 588 | + |
|
| 589 | + $params = array_filter(explode('|', $params)); |
|
| 590 | + if ($params) { |
|
| 591 | + $soustype = current($params); |
|
| 592 | + $soustype = strtolower(trim($soustype)); |
|
| 593 | + if (in_array($soustype, array('left', 'right', 'center', 'ajax'))) { |
|
| 594 | + $soustype = next($params); |
|
| 595 | + $soustype = strtolower($soustype); |
|
| 596 | + } |
|
| 597 | + |
|
| 598 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 599 | + if (!trouve_modele($fond = ($type . '_' . $soustype))) { |
|
| 600 | + $fond = ''; |
|
| 601 | + $class = $soustype; |
|
| 602 | + } |
|
| 603 | + // enlever le sous type des params |
|
| 604 | + $params = array_diff($params, array($soustype)); |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + |
|
| 608 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 609 | + if (!$fond and !trouve_modele($fond = $type)) { |
|
| 610 | + spip_log("Modele $type introuvable", _LOG_INFO_IMPORTANTE); |
|
| 611 | + |
|
| 612 | + return false; |
|
| 613 | + } |
|
| 614 | + $fond = 'modeles/' . $fond; |
|
| 615 | + // Creer le contexte |
|
| 616 | + $contexte = $env; |
|
| 617 | + $contexte['dir_racine'] = _DIR_RACINE; # eviter de mixer un cache racine et un cache ecrire (meme si pour l'instant les modeles ne sont pas caches, le resultat etant different il faut que le contexte en tienne compte |
|
| 618 | + |
|
| 619 | + // Le numero du modele est mis dans l'environnement |
|
| 620 | + // d'une part sous l'identifiant "id" |
|
| 621 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 622 | + // par la fonction id_table_objet, |
|
| 623 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 624 | + $_id = id_table_objet($type); |
|
| 625 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 626 | + |
|
| 627 | + if (isset($class)) { |
|
| 628 | + $contexte['class'] = $class; |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] ou [<modele1|title_du_lien{hreflang}->url] |
|
| 632 | + if ($lien) { |
|
| 633 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 634 | + $contexte['lien'] = str_replace(""", '"', $lien['href']); |
|
| 635 | + $contexte['lien_class'] = $lien['class']; |
|
| 636 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 637 | + $contexte['lien_title'] = $lien['title']; |
|
| 638 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + // Traiter les parametres |
|
| 642 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 643 | + $arg_list = creer_contexte_de_modele($params); |
|
| 644 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 645 | + $contexte = array_merge($contexte, $arg_list); |
|
| 646 | + |
|
| 647 | + // Appliquer le modele avec le contexte |
|
| 648 | + $retour = recuperer_fond($fond, $contexte, array(), $connect); |
|
| 649 | + |
|
| 650 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 651 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 652 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 653 | + if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')) . ' ', |
|
| 654 | + 'spip_lien_ok')) { |
|
| 655 | + $retour = inserer_attribut($retour, 'class', |
|
| 656 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes "))); |
|
| 657 | + } else { |
|
| 658 | + if ($lien) { |
|
| 659 | + $retour = "<a href='" . $lien['href'] . "' class='" . $lien['class'] . "'>" . $retour . "</a>"; |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $compteur--; |
|
| 664 | + |
|
| 665 | + return (isset($arg_list['ajax']) and $arg_list['ajax'] == 'ajax') |
|
| 666 | + ? encoder_contexte_ajax($contexte, '', $retour) |
|
| 667 | + : $retour; |
|
| 668 | 668 | } |
| 669 | 669 | |
| 670 | 670 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -674,92 +674,92 @@ discard block |
||
| 674 | 674 | // https://code.spip.net/@evaluer_fond |
| 675 | 675 | function evaluer_fond($fond, $contexte = array(), $connect = null) { |
| 676 | 676 | |
| 677 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 678 | - |
|
| 679 | - if (!$page) { |
|
| 680 | - return $page; |
|
| 681 | - } |
|
| 682 | - // eval $page et affecte $res |
|
| 683 | - include _ROOT_RESTREINT . "public/evaluer_page.php"; |
|
| 684 | - |
|
| 685 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 686 | - // a destination de public/parametrer |
|
| 687 | - // pour remonter vers les inclusions appelantes |
|
| 688 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 689 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 690 | - if (isset($page['invalideurs']) |
|
| 691 | - and isset($page['invalideurs']['session']) |
|
| 692 | - ) { |
|
| 693 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $page; |
|
| 677 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 678 | + |
|
| 679 | + if (!$page) { |
|
| 680 | + return $page; |
|
| 681 | + } |
|
| 682 | + // eval $page et affecte $res |
|
| 683 | + include _ROOT_RESTREINT . "public/evaluer_page.php"; |
|
| 684 | + |
|
| 685 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 686 | + // a destination de public/parametrer |
|
| 687 | + // pour remonter vers les inclusions appelantes |
|
| 688 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 689 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 690 | + if (isset($page['invalideurs']) |
|
| 691 | + and isset($page['invalideurs']['session']) |
|
| 692 | + ) { |
|
| 693 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $page; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
| 700 | 700 | // https://code.spip.net/@page_base_href |
| 701 | 701 | function page_base_href(&$texte) { |
| 702 | - static $set_html_base = null; |
|
| 703 | - if (is_null($set_html_base)) { |
|
| 704 | - if (!defined('_SET_HTML_BASE')) |
|
| 705 | - // si la profondeur est superieure a 1 |
|
| 706 | - // est que ce n'est pas une url page ni une url action |
|
| 707 | - // activer par defaut |
|
| 708 | - { |
|
| 709 | - $set_html_base = (( |
|
| 710 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 711 | - and _request(_SPIP_PAGE) !== 'login' |
|
| 712 | - and !_request('action')) ? true : false); |
|
| 713 | - } else { |
|
| 714 | - $set_html_base = _SET_HTML_BASE; |
|
| 715 | - } |
|
| 716 | - } |
|
| 717 | - |
|
| 718 | - if ($set_html_base |
|
| 719 | - and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 720 | - and $GLOBALS['profondeur_url'] > 0 |
|
| 721 | - and ($poshead = strpos($texte, '</head>')) !== false |
|
| 722 | - ) { |
|
| 723 | - $head = substr($texte, 0, $poshead); |
|
| 724 | - $insert = false; |
|
| 725 | - if (strpos($head, '<base') === false) { |
|
| 726 | - $insert = true; |
|
| 727 | - } else { |
|
| 728 | - // si aucun <base ...> n'a de href c'est bon quand meme ! |
|
| 729 | - $insert = true; |
|
| 730 | - include_spip('inc/filtres'); |
|
| 731 | - $bases = extraire_balises($head, 'base'); |
|
| 732 | - foreach ($bases as $base) { |
|
| 733 | - if (extraire_attribut($base, 'href')) { |
|
| 734 | - $insert = false; |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - if ($insert) { |
|
| 739 | - include_spip('inc/filtres_mini'); |
|
| 740 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 741 | - $base = url_absolue('./'); |
|
| 742 | - $bbase = "\n<base href=\"$base\" />"; |
|
| 743 | - if (($pos = strpos($head, '<head>')) !== false) { |
|
| 744 | - $head = substr_replace($head, $bbase, $pos + 6, 0); |
|
| 745 | - } elseif (preg_match(",<head[^>]*>,i", $head, $r)) { |
|
| 746 | - $head = str_replace($r[0], $r[0] . $bbase, $head); |
|
| 747 | - } |
|
| 748 | - $texte = $head . substr($texte, $poshead); |
|
| 749 | - // gerer les ancres |
|
| 750 | - $base = $_SERVER['REQUEST_URI']; |
|
| 751 | - // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 752 | - if (strpos($base,"'") or strpos($base,'"') or strpos($base,'<')) { |
|
| 753 | - $base = str_replace(array("'",'"','<'),array("%27",'%22','%3C'), $base); |
|
| 754 | - } |
|
| 755 | - if (strpos($texte, "href='#") !== false) { |
|
| 756 | - $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 757 | - } |
|
| 758 | - if (strpos($texte, "href=\"#") !== false) { |
|
| 759 | - $texte = str_replace("href=\"#", "href=\"$base#", $texte); |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 702 | + static $set_html_base = null; |
|
| 703 | + if (is_null($set_html_base)) { |
|
| 704 | + if (!defined('_SET_HTML_BASE')) |
|
| 705 | + // si la profondeur est superieure a 1 |
|
| 706 | + // est que ce n'est pas une url page ni une url action |
|
| 707 | + // activer par defaut |
|
| 708 | + { |
|
| 709 | + $set_html_base = (( |
|
| 710 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 711 | + and _request(_SPIP_PAGE) !== 'login' |
|
| 712 | + and !_request('action')) ? true : false); |
|
| 713 | + } else { |
|
| 714 | + $set_html_base = _SET_HTML_BASE; |
|
| 715 | + } |
|
| 716 | + } |
|
| 717 | + |
|
| 718 | + if ($set_html_base |
|
| 719 | + and isset($GLOBALS['html']) and $GLOBALS['html'] |
|
| 720 | + and $GLOBALS['profondeur_url'] > 0 |
|
| 721 | + and ($poshead = strpos($texte, '</head>')) !== false |
|
| 722 | + ) { |
|
| 723 | + $head = substr($texte, 0, $poshead); |
|
| 724 | + $insert = false; |
|
| 725 | + if (strpos($head, '<base') === false) { |
|
| 726 | + $insert = true; |
|
| 727 | + } else { |
|
| 728 | + // si aucun <base ...> n'a de href c'est bon quand meme ! |
|
| 729 | + $insert = true; |
|
| 730 | + include_spip('inc/filtres'); |
|
| 731 | + $bases = extraire_balises($head, 'base'); |
|
| 732 | + foreach ($bases as $base) { |
|
| 733 | + if (extraire_attribut($base, 'href')) { |
|
| 734 | + $insert = false; |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + if ($insert) { |
|
| 739 | + include_spip('inc/filtres_mini'); |
|
| 740 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 741 | + $base = url_absolue('./'); |
|
| 742 | + $bbase = "\n<base href=\"$base\" />"; |
|
| 743 | + if (($pos = strpos($head, '<head>')) !== false) { |
|
| 744 | + $head = substr_replace($head, $bbase, $pos + 6, 0); |
|
| 745 | + } elseif (preg_match(",<head[^>]*>,i", $head, $r)) { |
|
| 746 | + $head = str_replace($r[0], $r[0] . $bbase, $head); |
|
| 747 | + } |
|
| 748 | + $texte = $head . substr($texte, $poshead); |
|
| 749 | + // gerer les ancres |
|
| 750 | + $base = $_SERVER['REQUEST_URI']; |
|
| 751 | + // pas de guillemets ni < dans l'URL qu'on insere dans le HTML |
|
| 752 | + if (strpos($base,"'") or strpos($base,'"') or strpos($base,'<')) { |
|
| 753 | + $base = str_replace(array("'",'"','<'),array("%27",'%22','%3C'), $base); |
|
| 754 | + } |
|
| 755 | + if (strpos($texte, "href='#") !== false) { |
|
| 756 | + $texte = str_replace("href='#", "href='$base#", $texte); |
|
| 757 | + } |
|
| 758 | + if (strpos($texte, "href=\"#") !== false) { |
|
| 759 | + $texte = str_replace("href=\"#", "href=\"$base#", $texte); |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | 763 | } |
| 764 | 764 | |
| 765 | 765 | |
@@ -767,8 +767,8 @@ discard block |
||
| 767 | 767 | // et demarrent par X-Spip-... |
| 768 | 768 | // https://code.spip.net/@envoyer_entetes |
| 769 | 769 | function envoyer_entetes($entetes) { |
| 770 | - foreach ($entetes as $k => $v) # if (strncmp($k, 'X-Spip-', 7)) |
|
| 771 | - { |
|
| 772 | - @header(strlen($v) ? "$k: $v" : $k); |
|
| 773 | - } |
|
| 770 | + foreach ($entetes as $k => $v) # if (strncmp($k, 'X-Spip-', 7)) |
|
| 771 | + { |
|
| 772 | + @header(strlen($v) ? "$k: $v" : $k); |
|
| 773 | + } |
|
| 774 | 774 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | include_spip('base/abstract_sql'); |
| 23 | 23 | |
@@ -59,56 +59,56 @@ discard block |
||
| 59 | 59 | * Retour des traitements. |
| 60 | 60 | **/ |
| 61 | 61 | function formulaires_editer_objet_traiter( |
| 62 | - $type, |
|
| 63 | - $id = 'new', |
|
| 64 | - $id_parent = 0, |
|
| 65 | - $lier_trad = 0, |
|
| 66 | - $retour = '', |
|
| 67 | - $config_fonc = 'articles_edit_config', |
|
| 68 | - $row = array(), |
|
| 69 | - $hidden = '' |
|
| 62 | + $type, |
|
| 63 | + $id = 'new', |
|
| 64 | + $id_parent = 0, |
|
| 65 | + $lier_trad = 0, |
|
| 66 | + $retour = '', |
|
| 67 | + $config_fonc = 'articles_edit_config', |
|
| 68 | + $row = array(), |
|
| 69 | + $hidden = '' |
|
| 70 | 70 | ) { |
| 71 | 71 | |
| 72 | - $res = array(); |
|
| 73 | - // eviter la redirection forcee par l'action... |
|
| 74 | - set_request('redirect'); |
|
| 75 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | - list($id, $err) = $action_editer($id); |
|
| 77 | - } else { |
|
| 78 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | - list($id, $err) = $action_editer($id, $type); |
|
| 80 | - } |
|
| 81 | - $id_table_objet = id_table_objet($type); |
|
| 82 | - $res[$id_table_objet] = $id; |
|
| 83 | - if ($err or !$id) { |
|
| 84 | - $res['message_erreur'] = ($err ? $err : _T('erreur')); |
|
| 85 | - } else { |
|
| 86 | - // Un lien de trad a prendre en compte |
|
| 87 | - if ($lier_trad) { |
|
| 88 | - // referencer la traduction |
|
| 89 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | - if ($err) { |
|
| 95 | - $res['message_erreur'] = $err; |
|
| 96 | - return $res; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | - if ($retour) { |
|
| 102 | - if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | - $res['editable'] = true; |
|
| 105 | - } else { |
|
| 106 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $res; |
|
| 72 | + $res = array(); |
|
| 73 | + // eviter la redirection forcee par l'action... |
|
| 74 | + set_request('redirect'); |
|
| 75 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 76 | + list($id, $err) = $action_editer($id); |
|
| 77 | + } else { |
|
| 78 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 79 | + list($id, $err) = $action_editer($id, $type); |
|
| 80 | + } |
|
| 81 | + $id_table_objet = id_table_objet($type); |
|
| 82 | + $res[$id_table_objet] = $id; |
|
| 83 | + if ($err or !$id) { |
|
| 84 | + $res['message_erreur'] = ($err ? $err : _T('erreur')); |
|
| 85 | + } else { |
|
| 86 | + // Un lien de trad a prendre en compte |
|
| 87 | + if ($lier_trad) { |
|
| 88 | + // referencer la traduction |
|
| 89 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 90 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 91 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 92 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 93 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 94 | + if ($err) { |
|
| 95 | + $res['message_erreur'] = $err; |
|
| 96 | + return $res; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 101 | + if ($retour) { |
|
| 102 | + if (strncmp($retour, 'javascript:', 11) == 0) { |
|
| 103 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 104 | + $res['editable'] = true; |
|
| 105 | + } else { |
|
| 106 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $res; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -132,29 +132,29 @@ discard block |
||
| 132 | 132 | * Tableau des erreurs |
| 133 | 133 | **/ |
| 134 | 134 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = array()) { |
| 135 | - $erreurs = array(); |
|
| 136 | - if (intval($id)) { |
|
| 137 | - $conflits = controler_contenu($type, $id); |
|
| 138 | - if ($conflits and count($conflits)) { |
|
| 139 | - foreach ($conflits as $champ => $conflit) { |
|
| 140 | - if (!isset($erreurs[$champ])) { |
|
| 141 | - $erreurs[$champ] = ''; |
|
| 142 | - } |
|
| 143 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - foreach ($oblis as $obli) { |
|
| 148 | - $value = _request($obli); |
|
| 149 | - if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | - if (!isset($erreurs[$obli])) { |
|
| 151 | - $erreurs[$obli] = ''; |
|
| 152 | - } |
|
| 153 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - return $erreurs; |
|
| 135 | + $erreurs = array(); |
|
| 136 | + if (intval($id)) { |
|
| 137 | + $conflits = controler_contenu($type, $id); |
|
| 138 | + if ($conflits and count($conflits)) { |
|
| 139 | + foreach ($conflits as $champ => $conflit) { |
|
| 140 | + if (!isset($erreurs[$champ])) { |
|
| 141 | + $erreurs[$champ] = ''; |
|
| 142 | + } |
|
| 143 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + foreach ($oblis as $obli) { |
|
| 148 | + $value = _request($obli); |
|
| 149 | + if (is_null($value) or !(is_array($value) ? count($value) : strlen($value))) { |
|
| 150 | + if (!isset($erreurs[$obli])) { |
|
| 151 | + $erreurs[$obli] = ''; |
|
| 152 | + } |
|
| 153 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + return $erreurs; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | /** |
@@ -198,127 +198,127 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = array(), |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = array(), |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | 210 | |
| 211 | - $table_objet = table_objet($type); |
|
| 212 | - $table_objet_sql = table_objet_sql($type); |
|
| 213 | - $id_table_objet = id_table_objet($type); |
|
| 214 | - |
|
| 215 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 216 | - if ($config_fonc |
|
| 217 | - and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 218 | - and $config_fonc !== $table_objet . '_edit_config') { |
|
| 219 | - if ($args = test_formulaire_inclus_par_modele() |
|
| 220 | - and in_array($config_fonc, $args)) { |
|
| 221 | - $config_fonc = ''; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $new = !is_numeric($id); |
|
| 226 | - // Appel direct dans un squelette |
|
| 227 | - if (!$row) { |
|
| 228 | - if (!$new or $lier_trad) { |
|
| 229 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 230 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 231 | - } else { |
|
| 232 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 233 | - } |
|
| 234 | - if (!$new) { |
|
| 235 | - $md5 = controles_md5($row); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - if (!$row) { |
|
| 239 | - $row = array(); |
|
| 240 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 241 | - if ($desc = $trouver_table($table_objet)) { |
|
| 242 | - foreach ($desc['field'] as $k => $v) { |
|
| 243 | - $row[$k] = ''; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - } |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 250 | - // (et donc: pas de lien de traduction) |
|
| 251 | - $id = ($new or $lier_trad) |
|
| 252 | - ? 'oui' |
|
| 253 | - : $row[$id_table_objet]; |
|
| 254 | - $row[$id_table_objet] = $id; |
|
| 255 | - |
|
| 256 | - $contexte = $row; |
|
| 257 | - if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 258 | - if (!isset($contexte['id_parent'])) { |
|
| 259 | - unset($contexte['id_rubrique']); |
|
| 260 | - } |
|
| 261 | - $contexte['id_parent'] = $id_parent; |
|
| 262 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 263 | - // id_rubrique dans id_parent si possible |
|
| 264 | - if (isset($contexte['id_rubrique'])) { |
|
| 265 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 266 | - unset($contexte['id_rubrique']); |
|
| 267 | - } else { |
|
| 268 | - $contexte['id_parent'] = ''; |
|
| 269 | - } |
|
| 270 | - if (!$contexte['id_parent'] |
|
| 271 | - and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 272 | - ) { |
|
| 273 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 274 | - } |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - $config = array(); |
|
| 278 | - if ($config_fonc) { |
|
| 279 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 280 | - } |
|
| 281 | - $config = $config + array( |
|
| 282 | - 'lignes' => 0, |
|
| 283 | - 'langue' => '', |
|
| 284 | - ); |
|
| 285 | - |
|
| 286 | - $att_text = " class='textarea' " |
|
| 287 | - . " rows='" |
|
| 288 | - . ($config['lignes'] + 15) |
|
| 289 | - . "' cols='40'"; |
|
| 290 | - if (isset($contexte['texte'])) { |
|
| 291 | - list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // on veut conserver la langue de l'interface ; |
|
| 295 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 296 | - // voudrait l'exploiter |
|
| 297 | - if (isset($contexte['lang'])) { |
|
| 298 | - $contexte['langue'] = $contexte['lang']; |
|
| 299 | - unset($contexte['lang']); |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 303 | - (!$lier_trad ? '' : |
|
| 304 | - ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 305 | - $lier_trad . |
|
| 306 | - "' />" . |
|
| 307 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 308 | - $config['langue'] . |
|
| 309 | - "' />")) |
|
| 310 | - . $hidden |
|
| 311 | - . (isset($md5) ? $md5 : ''); |
|
| 312 | - |
|
| 313 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 314 | - $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id)); |
|
| 315 | - |
|
| 316 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 317 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 318 | - // on le garde pour compat |
|
| 319 | - $contexte['_action'] = array("editer_$type", $id); |
|
| 320 | - |
|
| 321 | - return $contexte; |
|
| 211 | + $table_objet = table_objet($type); |
|
| 212 | + $table_objet_sql = table_objet_sql($type); |
|
| 213 | + $id_table_objet = id_table_objet($type); |
|
| 214 | + |
|
| 215 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 216 | + if ($config_fonc |
|
| 217 | + and !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 218 | + and $config_fonc !== $table_objet . '_edit_config') { |
|
| 219 | + if ($args = test_formulaire_inclus_par_modele() |
|
| 220 | + and in_array($config_fonc, $args)) { |
|
| 221 | + $config_fonc = ''; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $new = !is_numeric($id); |
|
| 226 | + // Appel direct dans un squelette |
|
| 227 | + if (!$row) { |
|
| 228 | + if (!$new or $lier_trad) { |
|
| 229 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 230 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 231 | + } else { |
|
| 232 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . intval($id)); |
|
| 233 | + } |
|
| 234 | + if (!$new) { |
|
| 235 | + $md5 = controles_md5($row); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + if (!$row) { |
|
| 239 | + $row = array(); |
|
| 240 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 241 | + if ($desc = $trouver_table($table_objet)) { |
|
| 242 | + foreach ($desc['field'] as $k => $v) { |
|
| 243 | + $row[$k] = ''; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + } |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 250 | + // (et donc: pas de lien de traduction) |
|
| 251 | + $id = ($new or $lier_trad) |
|
| 252 | + ? 'oui' |
|
| 253 | + : $row[$id_table_objet]; |
|
| 254 | + $row[$id_table_objet] = $id; |
|
| 255 | + |
|
| 256 | + $contexte = $row; |
|
| 257 | + if (strlen($id_parent) && is_numeric($id_parent) && (!isset($contexte['id_parent']) or $new)) { |
|
| 258 | + if (!isset($contexte['id_parent'])) { |
|
| 259 | + unset($contexte['id_rubrique']); |
|
| 260 | + } |
|
| 261 | + $contexte['id_parent'] = $id_parent; |
|
| 262 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 263 | + // id_rubrique dans id_parent si possible |
|
| 264 | + if (isset($contexte['id_rubrique'])) { |
|
| 265 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 266 | + unset($contexte['id_rubrique']); |
|
| 267 | + } else { |
|
| 268 | + $contexte['id_parent'] = ''; |
|
| 269 | + } |
|
| 270 | + if (!$contexte['id_parent'] |
|
| 271 | + and $preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true) |
|
| 272 | + ) { |
|
| 273 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 274 | + } |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + $config = array(); |
|
| 278 | + if ($config_fonc) { |
|
| 279 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 280 | + } |
|
| 281 | + $config = $config + array( |
|
| 282 | + 'lignes' => 0, |
|
| 283 | + 'langue' => '', |
|
| 284 | + ); |
|
| 285 | + |
|
| 286 | + $att_text = " class='textarea' " |
|
| 287 | + . " rows='" |
|
| 288 | + . ($config['lignes'] + 15) |
|
| 289 | + . "' cols='40'"; |
|
| 290 | + if (isset($contexte['texte'])) { |
|
| 291 | + list($contexte['texte'], $contexte['_texte_trop_long']) = editer_texte_recolle($contexte['texte'], $att_text); |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // on veut conserver la langue de l'interface ; |
|
| 295 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 296 | + // voudrait l'exploiter |
|
| 297 | + if (isset($contexte['lang'])) { |
|
| 298 | + $contexte['langue'] = $contexte['lang']; |
|
| 299 | + unset($contexte['lang']); |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 303 | + (!$lier_trad ? '' : |
|
| 304 | + ("\n<input type='hidden' name='lier_trad' value='" . |
|
| 305 | + $lier_trad . |
|
| 306 | + "' />" . |
|
| 307 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 308 | + $config['langue'] . |
|
| 309 | + "' />")) |
|
| 310 | + . $hidden |
|
| 311 | + . (isset($md5) ? $md5 : ''); |
|
| 312 | + |
|
| 313 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 314 | + $contexte['_pipeline'] = array('editer_contenu_objet', array('type' => $type, 'id' => $id)); |
|
| 315 | + |
|
| 316 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 317 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 318 | + // on le garde pour compat |
|
| 319 | + $contexte['_action'] = array("editer_$type", $id); |
|
| 320 | + |
|
| 321 | + return $contexte; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | /** |
@@ -329,29 +329,29 @@ discard block |
||
| 329 | 329 | * @return array |
| 330 | 330 | */ |
| 331 | 331 | function coupe_trop_long($texte) { |
| 332 | - $aider = charger_fonction('aider', 'inc'); |
|
| 333 | - if (strlen($texte) > 28 * 1024) { |
|
| 334 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 335 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 336 | - if ($pos > 0 and $pos < 32 * 1024) { |
|
| 337 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 338 | - $suite = substr($texte, $pos + 2); |
|
| 339 | - } else { |
|
| 340 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 341 | - if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 342 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 343 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 344 | - } else { |
|
| 345 | - $decalage = 1; |
|
| 346 | - } |
|
| 347 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 348 | - $suite = substr($texte, $pos + $decalage); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - return (array($debut, $suite)); |
|
| 352 | - } else { |
|
| 353 | - return (array($texte, '')); |
|
| 354 | - } |
|
| 332 | + $aider = charger_fonction('aider', 'inc'); |
|
| 333 | + if (strlen($texte) > 28 * 1024) { |
|
| 334 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 335 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 336 | + if ($pos > 0 and $pos < 32 * 1024) { |
|
| 337 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 338 | + $suite = substr($texte, $pos + 2); |
|
| 339 | + } else { |
|
| 340 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 341 | + if (!($pos > 0 and $pos < 32 * 1024)) { |
|
| 342 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 343 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 344 | + } else { |
|
| 345 | + $decalage = 1; |
|
| 346 | + } |
|
| 347 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 348 | + $suite = substr($texte, $pos + $decalage); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + return (array($debut, $suite)); |
|
| 352 | + } else { |
|
| 353 | + return (array($texte, '')); |
|
| 354 | + } |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -362,24 +362,24 @@ discard block |
||
| 362 | 362 | * @return array |
| 363 | 363 | */ |
| 364 | 364 | function editer_texte_recolle($texte, $att_text) { |
| 365 | - if ((strlen($texte) < 29 * 1024) |
|
| 366 | - or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 367 | - ) { |
|
| 368 | - return array($texte, ''); |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - include_spip('inc/barre'); |
|
| 372 | - $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 373 | - $nombre = 0; |
|
| 374 | - |
|
| 375 | - while (strlen($texte) > 29 * 1024) { |
|
| 376 | - $nombre++; |
|
| 377 | - list($texte1, $texte) = coupe_trop_long($texte); |
|
| 378 | - $textes_supplement .= '<br />' . |
|
| 379 | - "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - return array($texte, $textes_supplement); |
|
| 365 | + if ((strlen($texte) < 29 * 1024) |
|
| 366 | + or (include_spip('inc/layer') and ($GLOBALS['browser_name'] != 'MSIE')) |
|
| 367 | + ) { |
|
| 368 | + return array($texte, ''); |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + include_spip('inc/barre'); |
|
| 372 | + $textes_supplement = "<br /><span style='color: red'>" . _T('info_texte_long') . "</span>\n"; |
|
| 373 | + $nombre = 0; |
|
| 374 | + |
|
| 375 | + while (strlen($texte) > 29 * 1024) { |
|
| 376 | + $nombre++; |
|
| 377 | + list($texte1, $texte) = coupe_trop_long($texte); |
|
| 378 | + $textes_supplement .= '<br />' . |
|
| 379 | + "<textarea id='texte$nombre' name='texte_plus[$nombre]'$att_text>$texte1</textarea>\n"; |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + return array($texte, $textes_supplement); |
|
| 383 | 383 | } |
| 384 | 384 | |
| 385 | 385 | /** |
@@ -390,17 +390,17 @@ discard block |
||
| 390 | 390 | * @param int $longueur |
| 391 | 391 | */ |
| 392 | 392 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 393 | - if (!_request($champ_titre)) { |
|
| 394 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 395 | - if (!is_null($longueur)) { |
|
| 396 | - $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 397 | - } else { |
|
| 398 | - $t = $titrer_contenu($champs_contenu); |
|
| 399 | - } |
|
| 400 | - if ($t) { |
|
| 401 | - set_request($champ_titre, $t); |
|
| 402 | - } |
|
| 403 | - } |
|
| 393 | + if (!_request($champ_titre)) { |
|
| 394 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 395 | + if (!is_null($longueur)) { |
|
| 396 | + $t = $titrer_contenu($champs_contenu, null, $longueur); |
|
| 397 | + } else { |
|
| 398 | + $t = $titrer_contenu($champs_contenu); |
|
| 399 | + } |
|
| 400 | + if ($t) { |
|
| 401 | + set_request($champ_titre, $t); |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -420,20 +420,20 @@ discard block |
||
| 420 | 420 | * @return string |
| 421 | 421 | */ |
| 422 | 422 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 423 | - // trouver un champ texte non vide |
|
| 424 | - $t = ''; |
|
| 425 | - foreach ($champs_contenu as $champ) { |
|
| 426 | - if ($t = _request($champ, $c)) { |
|
| 427 | - break; |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if ($t) { |
|
| 432 | - include_spip('inc/texte_mini'); |
|
| 433 | - $t = couper($t, $longueur, '...'); |
|
| 434 | - } |
|
| 435 | - |
|
| 436 | - return $t; |
|
| 423 | + // trouver un champ texte non vide |
|
| 424 | + $t = ''; |
|
| 425 | + foreach ($champs_contenu as $champ) { |
|
| 426 | + if ($t = _request($champ, $c)) { |
|
| 427 | + break; |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if ($t) { |
|
| 432 | + include_spip('inc/texte_mini'); |
|
| 433 | + $t = couper($t, $longueur, '...'); |
|
| 434 | + } |
|
| 435 | + |
|
| 436 | + return $t; |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | /** |
@@ -456,30 +456,30 @@ discard block |
||
| 456 | 456 | * - array sinon couples ('$prefixe$colonne => md5) |
| 457 | 457 | **/ |
| 458 | 458 | function controles_md5($data, $prefixe = 'ctr_', $format = 'html') { |
| 459 | - if (!is_array($data)) { |
|
| 460 | - return false; |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - $ctr = array(); |
|
| 464 | - foreach ($data as $key => $val) { |
|
| 465 | - $m = md5($val); |
|
| 466 | - $k = $prefixe . $key; |
|
| 467 | - |
|
| 468 | - switch ($format) { |
|
| 469 | - case 'html': |
|
| 470 | - $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 471 | - break; |
|
| 472 | - default: |
|
| 473 | - $ctr[$k] = $m; |
|
| 474 | - break; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - if ($format == 'html') { |
|
| 479 | - return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 480 | - } else { |
|
| 481 | - return $ctr; |
|
| 482 | - } |
|
| 459 | + if (!is_array($data)) { |
|
| 460 | + return false; |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + $ctr = array(); |
|
| 464 | + foreach ($data as $key => $val) { |
|
| 465 | + $m = md5($val); |
|
| 466 | + $k = $prefixe . $key; |
|
| 467 | + |
|
| 468 | + switch ($format) { |
|
| 469 | + case 'html': |
|
| 470 | + $ctr[$k] = "<input type='hidden' value='$m' name='$k' />"; |
|
| 471 | + break; |
|
| 472 | + default: |
|
| 473 | + $ctr[$k] = $m; |
|
| 474 | + break; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + if ($format == 'html') { |
|
| 479 | + return "\n\n<!-- controles md5 -->\n" . join("\n", $ctr) . "\n\n"; |
|
| 480 | + } else { |
|
| 481 | + return $ctr; |
|
| 482 | + } |
|
| 483 | 483 | } |
| 484 | 484 | |
| 485 | 485 | /** |
@@ -518,79 +518,79 @@ discard block |
||
| 518 | 518 | * - post : le contenu posté |
| 519 | 519 | **/ |
| 520 | 520 | function controler_contenu($type, $id, $options = array(), $c = false, $serveur = '') { |
| 521 | - include_spip('inc/filtres'); |
|
| 522 | - |
|
| 523 | - $table_objet = table_objet($type); |
|
| 524 | - $spip_table_objet = table_objet_sql($type); |
|
| 525 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 526 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 527 | - |
|
| 528 | - // Appels incomplets (sans $c) |
|
| 529 | - if (!is_array($c)) { |
|
| 530 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 531 | - if (_request($champ)) { |
|
| 532 | - $c[$champ] = _request($champ); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 538 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 539 | - // il faut passer par instituer_XX() |
|
| 540 | - // TODO: faut-il passer ces variables interdites |
|
| 541 | - // dans un fichier de description separe ? |
|
| 542 | - unset($c['statut']); |
|
| 543 | - unset($c['id_parent']); |
|
| 544 | - unset($c['id_rubrique']); |
|
| 545 | - unset($c['id_secteur']); |
|
| 546 | - |
|
| 547 | - // Gerer les champs non vides |
|
| 548 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 549 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 550 | - if ($c[$champ] === '') { |
|
| 551 | - $c[$champ] = $sinon; |
|
| 552 | - } |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - |
|
| 556 | - // N'accepter que les champs qui existent |
|
| 557 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 558 | - $champs = array(); |
|
| 559 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 560 | - if (isset($c[$champ])) { |
|
| 561 | - $champs[$champ] = $c[$champ]; |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - // Nettoyer les valeurs |
|
| 566 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 567 | - |
|
| 568 | - // Envoyer aux plugins |
|
| 569 | - $champs = pipeline( |
|
| 570 | - 'pre_edition', |
|
| 571 | - array( |
|
| 572 | - 'args' => array( |
|
| 573 | - 'table' => $spip_table_objet, // compatibilite |
|
| 574 | - 'table_objet' => $table_objet, |
|
| 575 | - 'spip_table_objet' => $spip_table_objet, |
|
| 576 | - 'type' => $type, |
|
| 577 | - 'id_objet' => $id, |
|
| 578 | - 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 579 | - 'action' => 'controler', |
|
| 580 | - 'serveur' => $serveur, |
|
| 581 | - ), |
|
| 582 | - 'data' => $champs |
|
| 583 | - ) |
|
| 584 | - ); |
|
| 585 | - |
|
| 586 | - if (!$champs) { |
|
| 587 | - return false; |
|
| 588 | - } |
|
| 589 | - |
|
| 590 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 591 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_'); |
|
| 592 | - |
|
| 593 | - return $conflits; |
|
| 521 | + include_spip('inc/filtres'); |
|
| 522 | + |
|
| 523 | + $table_objet = table_objet($type); |
|
| 524 | + $spip_table_objet = table_objet_sql($type); |
|
| 525 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 526 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 527 | + |
|
| 528 | + // Appels incomplets (sans $c) |
|
| 529 | + if (!is_array($c)) { |
|
| 530 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 531 | + if (_request($champ)) { |
|
| 532 | + $c[$champ] = _request($champ); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 538 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 539 | + // il faut passer par instituer_XX() |
|
| 540 | + // TODO: faut-il passer ces variables interdites |
|
| 541 | + // dans un fichier de description separe ? |
|
| 542 | + unset($c['statut']); |
|
| 543 | + unset($c['id_parent']); |
|
| 544 | + unset($c['id_rubrique']); |
|
| 545 | + unset($c['id_secteur']); |
|
| 546 | + |
|
| 547 | + // Gerer les champs non vides |
|
| 548 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 549 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 550 | + if ($c[$champ] === '') { |
|
| 551 | + $c[$champ] = $sinon; |
|
| 552 | + } |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + |
|
| 556 | + // N'accepter que les champs qui existent |
|
| 557 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 558 | + $champs = array(); |
|
| 559 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 560 | + if (isset($c[$champ])) { |
|
| 561 | + $champs[$champ] = $c[$champ]; |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + // Nettoyer les valeurs |
|
| 566 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 567 | + |
|
| 568 | + // Envoyer aux plugins |
|
| 569 | + $champs = pipeline( |
|
| 570 | + 'pre_edition', |
|
| 571 | + array( |
|
| 572 | + 'args' => array( |
|
| 573 | + 'table' => $spip_table_objet, // compatibilite |
|
| 574 | + 'table_objet' => $table_objet, |
|
| 575 | + 'spip_table_objet' => $spip_table_objet, |
|
| 576 | + 'type' => $type, |
|
| 577 | + 'id_objet' => $id, |
|
| 578 | + 'champs' => isset($options['champs']) ? $options['champs'] : array(), // [doc] c'est quoi ? |
|
| 579 | + 'action' => 'controler', |
|
| 580 | + 'serveur' => $serveur, |
|
| 581 | + ), |
|
| 582 | + 'data' => $champs |
|
| 583 | + ) |
|
| 584 | + ); |
|
| 585 | + |
|
| 586 | + if (!$champs) { |
|
| 587 | + return false; |
|
| 588 | + } |
|
| 589 | + |
|
| 590 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 591 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, isset($options['prefix']) ? $options['prefix'] : 'ctr_'); |
|
| 592 | + |
|
| 593 | + return $conflits; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | |
@@ -620,63 +620,63 @@ discard block |
||
| 620 | 620 | * - post : le contenu posté |
| 621 | 621 | **/ |
| 622 | 622 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 623 | - $spip_table_objet = table_objet_sql($type); |
|
| 624 | - $id_table_objet = id_table_objet($type); |
|
| 625 | - |
|
| 626 | - // Controle des MD5 envoyes |
|
| 627 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 628 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 629 | - foreach ($champs as $key => $val) { |
|
| 630 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 631 | - if (is_scalar($val) and $m == md5($val)) { |
|
| 632 | - unset($champs[$key]); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - if (!$champs) { |
|
| 637 | - return; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - // On veut savoir si notre modif va avoir un impact |
|
| 641 | - // par rapport aux donnees contenues dans la base |
|
| 642 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 643 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 644 | - $intact = true; |
|
| 645 | - foreach ($champs as $ch => $val) { |
|
| 646 | - $intact &= ($s[$ch] == $val); |
|
| 647 | - } |
|
| 648 | - if ($intact) { |
|
| 649 | - return; |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - // Detection de conflits : |
|
| 653 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 654 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 655 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 656 | - // de conflit. |
|
| 657 | - $ctrh = $ctrq = $conflits = array(); |
|
| 658 | - foreach (array_keys($champs) as $key) { |
|
| 659 | - if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 660 | - $ctrh[$key] = $m; |
|
| 661 | - $ctrq[] = $key; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - if ($ctrq) { |
|
| 665 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 666 | - foreach ($ctrh as $key => $m) { |
|
| 667 | - if ($m != md5($ctrq[$key]) |
|
| 668 | - and $champs[$key] !== $ctrq[$key] |
|
| 669 | - ) { |
|
| 670 | - $conflits[$key] = array( |
|
| 671 | - 'base' => $ctrq[$key], |
|
| 672 | - 'post' => $champs[$key] |
|
| 673 | - ); |
|
| 674 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return $conflits; |
|
| 623 | + $spip_table_objet = table_objet_sql($type); |
|
| 624 | + $id_table_objet = id_table_objet($type); |
|
| 625 | + |
|
| 626 | + // Controle des MD5 envoyes |
|
| 627 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 628 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 629 | + foreach ($champs as $key => $val) { |
|
| 630 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 631 | + if (is_scalar($val) and $m == md5($val)) { |
|
| 632 | + unset($champs[$key]); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + if (!$champs) { |
|
| 637 | + return; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + // On veut savoir si notre modif va avoir un impact |
|
| 641 | + // par rapport aux donnees contenues dans la base |
|
| 642 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 643 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 644 | + $intact = true; |
|
| 645 | + foreach ($champs as $ch => $val) { |
|
| 646 | + $intact &= ($s[$ch] == $val); |
|
| 647 | + } |
|
| 648 | + if ($intact) { |
|
| 649 | + return; |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + // Detection de conflits : |
|
| 653 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 654 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 655 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 656 | + // de conflit. |
|
| 657 | + $ctrh = $ctrq = $conflits = array(); |
|
| 658 | + foreach (array_keys($champs) as $key) { |
|
| 659 | + if (isset($ctr[$prefix . $key]) and $m = $ctr[$prefix . $key]) { |
|
| 660 | + $ctrh[$key] = $m; |
|
| 661 | + $ctrq[] = $key; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + if ($ctrq) { |
|
| 665 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 666 | + foreach ($ctrh as $key => $m) { |
|
| 667 | + if ($m != md5($ctrq[$key]) |
|
| 668 | + and $champs[$key] !== $ctrq[$key] |
|
| 669 | + ) { |
|
| 670 | + $conflits[$key] = array( |
|
| 671 | + 'base' => $ctrq[$key], |
|
| 672 | + 'post' => $champs[$key] |
|
| 673 | + ); |
|
| 674 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return $conflits; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -688,11 +688,11 @@ discard block |
||
| 688 | 688 | * @return string |
| 689 | 689 | */ |
| 690 | 690 | function display_conflit_champ($x) { |
| 691 | - if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 692 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 693 | - } else { |
|
| 694 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 695 | - } |
|
| 691 | + if (strstr($x, "\n") or strlen($x) > 80) { |
|
| 692 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 693 | + } else { |
|
| 694 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 695 | + } |
|
| 696 | 696 | } |
| 697 | 697 | |
| 698 | 698 | /** |
@@ -710,57 +710,57 @@ discard block |
||
| 710 | 710 | * @return string |
| 711 | 711 | */ |
| 712 | 712 | function signaler_conflits_edition($conflits, $redirect = '') { |
| 713 | - include_spip('inc/minipres'); |
|
| 714 | - include_spip('inc/revisions'); |
|
| 715 | - include_spip('afficher_diff/champ'); |
|
| 716 | - include_spip('inc/suivi_versions'); |
|
| 717 | - include_spip('inc/diff'); |
|
| 718 | - $diffs = array(); |
|
| 719 | - foreach ($conflits as $champ => $a) { |
|
| 720 | - // probleme de stockage ou conflit d'edition ? |
|
| 721 | - $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 722 | - |
|
| 723 | - $diff = new Diff(new DiffTexte); |
|
| 724 | - $n = preparer_diff($a['post']); |
|
| 725 | - $o = preparer_diff($base); |
|
| 726 | - $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 727 | - |
|
| 728 | - $titre = isset($a['save']) ? _L( |
|
| 729 | - 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 730 | - array('champ' => $champ) |
|
| 731 | - ) : $champ; |
|
| 732 | - |
|
| 733 | - $diffs[] = "<h2>$titre</h2>\n" |
|
| 734 | - . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 735 | - . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 736 | - . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 737 | - . display_conflit_champ($a['post']) |
|
| 738 | - . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 739 | - . display_conflit_champ($base); |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - if ($redirect) { |
|
| 743 | - $id = uniqid(rand()); |
|
| 744 | - $redirect = "<form action='$redirect' method='get' |
|
| 713 | + include_spip('inc/minipres'); |
|
| 714 | + include_spip('inc/revisions'); |
|
| 715 | + include_spip('afficher_diff/champ'); |
|
| 716 | + include_spip('inc/suivi_versions'); |
|
| 717 | + include_spip('inc/diff'); |
|
| 718 | + $diffs = array(); |
|
| 719 | + foreach ($conflits as $champ => $a) { |
|
| 720 | + // probleme de stockage ou conflit d'edition ? |
|
| 721 | + $base = isset($a['save']) ? $a['save'] : $a['base']; |
|
| 722 | + |
|
| 723 | + $diff = new Diff(new DiffTexte); |
|
| 724 | + $n = preparer_diff($a['post']); |
|
| 725 | + $o = preparer_diff($base); |
|
| 726 | + $d = propre_diff(afficher_para_modifies(afficher_diff($diff->comparer($n, $o)))); |
|
| 727 | + |
|
| 728 | + $titre = isset($a['save']) ? _L( |
|
| 729 | + 'Echec lors de l\'enregistrement du champ @champ@', |
|
| 730 | + array('champ' => $champ) |
|
| 731 | + ) : $champ; |
|
| 732 | + |
|
| 733 | + $diffs[] = "<h2>$titre</h2>\n" |
|
| 734 | + . '<h3>' . _T('info_conflit_edition_differences') . "</h3>\n" |
|
| 735 | + . "<div style='max-height:8em; overflow: auto; width:99%;'>" . $d . "</div>\n" |
|
| 736 | + . '<h4>' . _T('info_conflit_edition_votre_version') . '</h4>' |
|
| 737 | + . display_conflit_champ($a['post']) |
|
| 738 | + . '<h4>' . _T('info_conflit_edition_version_enregistree') . '</h4>' |
|
| 739 | + . display_conflit_champ($base); |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + if ($redirect) { |
|
| 743 | + $id = uniqid(rand()); |
|
| 744 | + $redirect = "<form action='$redirect' method='get' |
|
| 745 | 745 | id='$id' |
| 746 | 746 | style='float:" . $GLOBALS['spip_lang_right'] . "; margin-top:2em;'>\n" |
| 747 | - . form_hidden($redirect) |
|
| 748 | - . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 747 | + . form_hidden($redirect) |
|
| 748 | + . "<input type='submit' value='" . _T('icone_retour') . "' /> |
|
| 749 | 749 | </form>\n"; |
| 750 | 750 | |
| 751 | - // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 752 | - if (_AJAX) { |
|
| 753 | - $redirect .= '<script type="text/javascript">' |
|
| 754 | - . 'setTimeout(function(){$("#' . $id . '") |
|
| 751 | + // pour les documents, on est probablement en ajax : il faut ajaxer |
|
| 752 | + if (_AJAX) { |
|
| 753 | + $redirect .= '<script type="text/javascript">' |
|
| 754 | + . 'setTimeout(function(){$("#' . $id . '") |
|
| 755 | 755 | .ajaxForm({target:$("#' . $id . '").parent()}); |
| 756 | 756 | }, 200);' |
| 757 | - . "</script>\n"; |
|
| 758 | - } |
|
| 759 | - } |
|
| 757 | + . "</script>\n"; |
|
| 758 | + } |
|
| 759 | + } |
|
| 760 | 760 | |
| 761 | - echo minipres( |
|
| 762 | - _T('titre_conflit_edition'), |
|
| 763 | - '<style> |
|
| 761 | + echo minipres( |
|
| 762 | + _T('titre_conflit_edition'), |
|
| 763 | + '<style> |
|
| 764 | 764 | .diff-para-deplace { background: #e8e8ff; } |
| 765 | 765 | .diff-para-ajoute { background: #d0ffc0; color: #000; } |
| 766 | 766 | .diff-para-supprime { background: #ffd0c0; color: #904040; text-decoration: line-through; } |
@@ -771,12 +771,12 @@ discard block |
||
| 771 | 771 | .diff-para-deplace .diff-supprime { background: #ffb8b8; border: 1px solid #808080; } |
| 772 | 772 | .diff-para-deplace .diff-deplace { background: #b8b8ff; border: 1px solid #808080; } |
| 773 | 773 | </style>' |
| 774 | - . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 775 | - . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 776 | - . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 777 | - . join("\n", $diffs) |
|
| 778 | - . "</div>\n" |
|
| 779 | - |
|
| 780 | - . $redirect |
|
| 781 | - ); |
|
| 774 | + . '<p>' . _T('info_conflit_edition_avis_non_sauvegarde') . '</p>' |
|
| 775 | + . '<p>' . _T('texte_conflit_edition_correction') . '</p>' |
|
| 776 | + . "<div style='text-align:" . $GLOBALS['spip_lang_left'] . ";'>" |
|
| 777 | + . join("\n", $diffs) |
|
| 778 | + . "</div>\n" |
|
| 779 | + |
|
| 780 | + . $redirect |
|
| 781 | + ); |
|
| 782 | 782 | } |
@@ -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,24 +34,24 @@ discard block |
||
| 34 | 34 | * Saisie protégée |
| 35 | 35 | **/ |
| 36 | 36 | function protege_champ($texte) { |
| 37 | - if (is_array($texte)) { |
|
| 38 | - $texte = array_map('protege_champ', $texte); |
|
| 39 | - } else { |
|
| 40 | - // ne pas corrompre une valeur serialize |
|
| 41 | - if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) { |
|
| 42 | - return $texte; |
|
| 43 | - } |
|
| 44 | - if (is_string($texte) |
|
| 45 | - and $texte |
|
| 46 | - and strpbrk($texte, "&\"'<>") !== false |
|
| 47 | - ) { |
|
| 48 | - $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 49 | - } elseif (is_bool($texte)) { |
|
| 50 | - $texte = ($texte ? '1' : ''); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $texte; |
|
| 37 | + if (is_array($texte)) { |
|
| 38 | + $texte = array_map('protege_champ', $texte); |
|
| 39 | + } else { |
|
| 40 | + // ne pas corrompre une valeur serialize |
|
| 41 | + if ((preg_match(",^[abis]:\d+[:;],", $texte) and @unserialize($texte) != false) or is_null($texte)) { |
|
| 42 | + return $texte; |
|
| 43 | + } |
|
| 44 | + if (is_string($texte) |
|
| 45 | + and $texte |
|
| 46 | + and strpbrk($texte, "&\"'<>") !== false |
|
| 47 | + ) { |
|
| 48 | + $texte = spip_htmlspecialchars($texte, ENT_QUOTES); |
|
| 49 | + } elseif (is_bool($texte)) { |
|
| 50 | + $texte = ($texte ? '1' : ''); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $texte; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -65,17 +65,17 @@ discard block |
||
| 65 | 65 | * - false : pas de squelette trouvé |
| 66 | 66 | **/ |
| 67 | 67 | function existe_formulaire($form) { |
| 68 | - if (substr($form, 0, 11) == "FORMULAIRE_") { |
|
| 69 | - $form = strtolower(substr($form, 11)); |
|
| 70 | - } else { |
|
| 71 | - $form = strtolower($form); |
|
| 72 | - } |
|
| 68 | + if (substr($form, 0, 11) == "FORMULAIRE_") { |
|
| 69 | + $form = strtolower(substr($form, 11)); |
|
| 70 | + } else { |
|
| 71 | + $form = strtolower($form); |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | - if (!$form) { |
|
| 75 | - return ''; |
|
| 76 | - } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 74 | + if (!$form) { |
|
| 75 | + return ''; |
|
| 76 | + } // on ne sait pas, le nom du formulaire n'est pas fourni ici |
|
| 77 | 77 | |
| 78 | - return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 78 | + return trouver_fond($form, 'formulaires/') ? $form : false; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -84,29 +84,29 @@ discard block |
||
| 84 | 84 | * @return false|array |
| 85 | 85 | */ |
| 86 | 86 | function test_formulaire_inclus_par_modele() { |
| 87 | - $trace = debug_backtrace(null, 20); |
|
| 88 | - $trace_fonctions = array_column($trace, 'function'); |
|
| 89 | - $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 90 | - |
|
| 91 | - // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 92 | - if (function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | - and $form = arguments_balise_dyn_depuis_modele(null, 'read')) { |
|
| 94 | - if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 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 | - |
|
| 102 | - // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 103 | - // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 104 | - if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 105 | - $k = array_search('inclure_modele', $trace_fonctions); |
|
| 106 | - // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 107 | - return $trace[$k-1]['args'][1]['args']; |
|
| 108 | - } |
|
| 109 | - return false; |
|
| 87 | + $trace = debug_backtrace(null, 20); |
|
| 88 | + $trace_fonctions = array_column($trace, 'function'); |
|
| 89 | + $trace_fonctions = array_map('strtolower', $trace_fonctions); |
|
| 90 | + |
|
| 91 | + // regarder si un flag a ete leve juste avant l'appel de balise_FORMULAIRE_dyn |
|
| 92 | + if (function_exists('arguments_balise_dyn_depuis_modele') |
|
| 93 | + and $form = arguments_balise_dyn_depuis_modele(null, 'read')) { |
|
| 94 | + if (in_array('balise_formulaire__dyn', $trace_fonctions)) { |
|
| 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 | + |
|
| 102 | + // fallback qui ne repose pas sur le flag lie a l'analyse de contexte_compil, |
|
| 103 | + // mais ne marche pas si executer_balise_dynamique est appelee via du php dans le squelette |
|
| 104 | + if (in_array('eval', $trace_fonctions) and in_array('inclure_modele', $trace_fonctions)) { |
|
| 105 | + $k = array_search('inclure_modele', $trace_fonctions); |
|
| 106 | + // les arguments de recuperer_fond() passes par inclure_modele() |
|
| 107 | + return $trace[$k-1]['args'][1]['args']; |
|
| 108 | + } |
|
| 109 | + return false; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -121,17 +121,17 @@ discard block |
||
| 121 | 121 | **/ |
| 122 | 122 | function balise_FORMULAIRE__dist($p) { |
| 123 | 123 | |
| 124 | - // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 125 | - // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 126 | - if (existe_formulaire($p->nom_champ) === false) { |
|
| 127 | - $p->code = "''"; |
|
| 128 | - $p->interdire_scripts = false; |
|
| 124 | + // Cas d'un #FORMULAIRE_TOTO inexistant : renvoyer la chaine vide. |
|
| 125 | + // mais si #FORMULAIRE_{toto} on ne peut pas savoir a la compilation, continuer |
|
| 126 | + if (existe_formulaire($p->nom_champ) === false) { |
|
| 127 | + $p->code = "''"; |
|
| 128 | + $p->interdire_scripts = false; |
|
| 129 | 129 | |
| 130 | - return $p; |
|
| 131 | - } |
|
| 130 | + return $p; |
|
| 131 | + } |
|
| 132 | 132 | |
| 133 | - // sinon renvoyer un code php dynamique |
|
| 134 | - return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 133 | + // sinon renvoyer un code php dynamique |
|
| 134 | + return calculer_balise_dynamique($p, $p->nom_champ, array()); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -144,27 +144,27 @@ discard block |
||
| 144 | 144 | * - string : texte à afficher directement |
| 145 | 145 | */ |
| 146 | 146 | function balise_FORMULAIRE__dyn($form) { |
| 147 | - $form = existe_formulaire($form); |
|
| 148 | - if (!$form) { |
|
| 149 | - return ''; |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // deux moyen d'arriver ici : |
|
| 153 | - // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 154 | - // soit #FORMULAIRE_{xx} |
|
| 155 | - |
|
| 156 | - // recuperer les arguments passes a la balise |
|
| 157 | - // on enleve le premier qui est le nom de la balise |
|
| 158 | - // deja recupere ci-dessus |
|
| 159 | - |
|
| 160 | - $args = func_get_args(); |
|
| 161 | - array_shift($args); |
|
| 162 | - $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | - if (!is_array($contexte)) { |
|
| 164 | - return $contexte; |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - return array("formulaires/$form", 3600, $contexte); |
|
| 147 | + $form = existe_formulaire($form); |
|
| 148 | + if (!$form) { |
|
| 149 | + return ''; |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // deux moyen d'arriver ici : |
|
| 153 | + // soit #FORMULAIRE_XX reroute avec 'FORMULAIRE_XX' ajoute en premier arg |
|
| 154 | + // soit #FORMULAIRE_{xx} |
|
| 155 | + |
|
| 156 | + // recuperer les arguments passes a la balise |
|
| 157 | + // on enleve le premier qui est le nom de la balise |
|
| 158 | + // deja recupere ci-dessus |
|
| 159 | + |
|
| 160 | + $args = func_get_args(); |
|
| 161 | + array_shift($args); |
|
| 162 | + $contexte = balise_FORMULAIRE__contexte($form, $args); |
|
| 163 | + if (!is_array($contexte)) { |
|
| 164 | + return $contexte; |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + return array("formulaires/$form", 3600, $contexte); |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -178,120 +178,120 @@ discard block |
||
| 178 | 178 | * Contexte d'environnement à envoyer au squelette |
| 179 | 179 | **/ |
| 180 | 180 | function balise_FORMULAIRE__contexte($form, $args) { |
| 181 | - // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 182 | - // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 183 | - // si poste, on recupere les erreurs |
|
| 184 | - |
|
| 185 | - $je_suis_poste = false; |
|
| 186 | - if ($post_form = _request('formulaire_action') |
|
| 187 | - and $post_form == $form |
|
| 188 | - and $p = _request('formulaire_action_args') |
|
| 189 | - and 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 = array(); |
|
| 200 | - if ($je_suis_poste) { |
|
| 201 | - $post = traiter_formulaires_dynamiques(true); |
|
| 202 | - $e = "erreurs_$form"; |
|
| 203 | - $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 204 | - $editable = "editable_$form"; |
|
| 205 | - $editable = (!isset($post[$e])) |
|
| 206 | - || count($erreurs) |
|
| 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 = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 222 | - // bug IEx : si action finit par / |
|
| 223 | - // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | - if (substr($action, -1) == '/') { |
|
| 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 | - if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) { |
|
| 235 | - if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 236 | - $valeurs[$champ] = $v; |
|
| 237 | - } |
|
| 238 | - // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | - if ($action) { |
|
| 240 | - $action = parametre_url($action, $champ, ''); |
|
| 241 | - } |
|
| 242 | - // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | - $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - if ($action) { |
|
| 248 | - // nettoyer l'url |
|
| 249 | - $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | - $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | - } |
|
| 252 | - |
|
| 253 | - if (isset($valeurs['_action'])) { |
|
| 254 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 255 | - $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
|
| 256 | - $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') . |
|
| 257 | - "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />" |
|
| 258 | - . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />"; |
|
| 259 | - } |
|
| 260 | - |
|
| 261 | - // empiler la lang en tant que premier argument implicite du CVT |
|
| 262 | - // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 263 | - array_unshift($args, $GLOBALS['spip_lang']); |
|
| 264 | - |
|
| 265 | - $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 266 | - $valeurs['erreurs'] = $erreurs; |
|
| 267 | - $valeurs['action'] = $action; |
|
| 268 | - $valeurs['form'] = $form; |
|
| 269 | - |
|
| 270 | - if (!isset($valeurs['id'])) { |
|
| 271 | - $valeurs['id'] = 'new'; |
|
| 272 | - } |
|
| 273 | - // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | - if (!isset($valeurs['editable'])) { |
|
| 275 | - $valeurs['editable'] = $editable; |
|
| 276 | - } |
|
| 277 | - // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | - $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | - |
|
| 280 | - if ($je_suis_poste) { |
|
| 281 | - $valeurs['message_erreur'] = ""; |
|
| 282 | - if (isset($erreurs['message_erreur'])) { |
|
| 283 | - $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - $valeurs['message_ok'] = ""; |
|
| 287 | - if (isset($post["message_ok_$form"])) { |
|
| 288 | - $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | - } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | - $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - return $valeurs; |
|
| 181 | + // tester si ce formulaire vient d'etre poste (memes arguments) |
|
| 182 | + // pour ne pas confondre 2 #FORMULAIRES_XX identiques sur une meme page |
|
| 183 | + // si poste, on recupere les erreurs |
|
| 184 | + |
|
| 185 | + $je_suis_poste = false; |
|
| 186 | + if ($post_form = _request('formulaire_action') |
|
| 187 | + and $post_form == $form |
|
| 188 | + and $p = _request('formulaire_action_args') |
|
| 189 | + and 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 = array(); |
|
| 200 | + if ($je_suis_poste) { |
|
| 201 | + $post = traiter_formulaires_dynamiques(true); |
|
| 202 | + $e = "erreurs_$form"; |
|
| 203 | + $erreurs = isset($post[$e]) ? $post[$e] : array(); |
|
| 204 | + $editable = "editable_$form"; |
|
| 205 | + $editable = (!isset($post[$e])) |
|
| 206 | + || count($erreurs) |
|
| 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 = (isset($valeurs['action'])) ? $valeurs['action'] : self('&', true); |
|
| 222 | + // bug IEx : si action finit par / |
|
| 223 | + // IE croit que le <form ... action=../ > est autoferme |
|
| 224 | + if (substr($action, -1) == '/') { |
|
| 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 | + if ($champ[0] !== '_' and !in_array($champ, array('message_ok', 'message_erreur', 'editable'))) { |
|
| 235 | + if ($dispo and (($v = _request($champ)) !== null)) { |
|
| 236 | + $valeurs[$champ] = $v; |
|
| 237 | + } |
|
| 238 | + // nettoyer l'url des champs qui vont etre saisis |
|
| 239 | + if ($action) { |
|
| 240 | + $action = parametre_url($action, $champ, ''); |
|
| 241 | + } |
|
| 242 | + // proteger les ' et les " dans les champs que l'on va injecter |
|
| 243 | + $valeurs[$champ] = protege_champ($valeurs[$champ]); |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + if ($action) { |
|
| 248 | + // nettoyer l'url |
|
| 249 | + $action = parametre_url($action, 'formulaire_action', ''); |
|
| 250 | + $action = parametre_url($action, 'formulaire_action_args', ''); |
|
| 251 | + } |
|
| 252 | + |
|
| 253 | + if (isset($valeurs['_action'])) { |
|
| 254 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 255 | + $secu = $securiser_action(reset($valeurs['_action']), end($valeurs['_action']), '', -1); |
|
| 256 | + $valeurs['_hidden'] = (isset($valeurs['_hidden']) ? $valeurs['_hidden'] : '') . |
|
| 257 | + "<input type='hidden' name='arg' value='" . $secu['arg'] . "' />" |
|
| 258 | + . "<input type='hidden' name='hash' value='" . $secu['hash'] . "' />"; |
|
| 259 | + } |
|
| 260 | + |
|
| 261 | + // empiler la lang en tant que premier argument implicite du CVT |
|
| 262 | + // pour permettre de la restaurer au moment du Verifier et du Traiter |
|
| 263 | + array_unshift($args, $GLOBALS['spip_lang']); |
|
| 264 | + |
|
| 265 | + $valeurs['formulaire_args'] = encoder_contexte_ajax($args, $form); |
|
| 266 | + $valeurs['erreurs'] = $erreurs; |
|
| 267 | + $valeurs['action'] = $action; |
|
| 268 | + $valeurs['form'] = $form; |
|
| 269 | + |
|
| 270 | + if (!isset($valeurs['id'])) { |
|
| 271 | + $valeurs['id'] = 'new'; |
|
| 272 | + } |
|
| 273 | + // editable peut venir de charger() ou de traiter() sinon |
|
| 274 | + if (!isset($valeurs['editable'])) { |
|
| 275 | + $valeurs['editable'] = $editable; |
|
| 276 | + } |
|
| 277 | + // dans tous les cas, renvoyer un espace ou vide (et pas un booleen) |
|
| 278 | + $valeurs['editable'] = ($valeurs['editable'] ? ' ' : ''); |
|
| 279 | + |
|
| 280 | + if ($je_suis_poste) { |
|
| 281 | + $valeurs['message_erreur'] = ""; |
|
| 282 | + if (isset($erreurs['message_erreur'])) { |
|
| 283 | + $valeurs['message_erreur'] = $erreurs['message_erreur']; |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + $valeurs['message_ok'] = ""; |
|
| 287 | + if (isset($post["message_ok_$form"])) { |
|
| 288 | + $valeurs['message_ok'] = $post["message_ok_$form"]; |
|
| 289 | + } elseif (isset($erreurs['message_ok'])) { |
|
| 290 | + $valeurs['message_ok'] = $erreurs["message_ok"]; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + return $valeurs; |
|
| 295 | 295 | } |
| 296 | 296 | |
| 297 | 297 | /** |
@@ -303,51 +303,51 @@ discard block |
||
| 303 | 303 | * @return array |
| 304 | 304 | */ |
| 305 | 305 | function formulaire__charger($form, $args, $poste) { |
| 306 | - if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) { |
|
| 307 | - $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 308 | - } else { |
|
| 309 | - $valeurs = array(); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $valeurs = pipeline( |
|
| 313 | - 'formulaire_charger', |
|
| 314 | - array( |
|
| 315 | - 'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 316 | - 'data' => $valeurs |
|
| 317 | - ) |
|
| 318 | - ); |
|
| 319 | - |
|
| 320 | - // prise en charge CVT multi etape |
|
| 321 | - if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 322 | - include_spip('inc/cvt_multietapes'); |
|
| 323 | - $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 324 | - array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 325 | - $valeurs |
|
| 326 | - ); |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 330 | - if (is_array($valeurs)) { |
|
| 331 | - if (!isset($valeurs['_pipelines'])) { |
|
| 332 | - $valeurs['_pipelines'] = array(); |
|
| 333 | - } |
|
| 334 | - // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 335 | - // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 336 | - if (isset($valeurs['_pipeline'])) { |
|
| 337 | - $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 338 | - $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array(); |
|
| 339 | - |
|
| 340 | - $pipelines = array($pipe => $args); |
|
| 341 | - $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 342 | - } |
|
| 343 | - |
|
| 344 | - // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 345 | - // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 346 | - // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 347 | - $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste); |
|
| 348 | - } |
|
| 349 | - |
|
| 350 | - return $valeurs; |
|
| 306 | + if ($charger_valeurs = charger_fonction("charger", "formulaires/$form", true)) { |
|
| 307 | + $valeurs = call_user_func_array($charger_valeurs, $args); |
|
| 308 | + } else { |
|
| 309 | + $valeurs = array(); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $valeurs = pipeline( |
|
| 313 | + 'formulaire_charger', |
|
| 314 | + array( |
|
| 315 | + 'args' => array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 316 | + 'data' => $valeurs |
|
| 317 | + ) |
|
| 318 | + ); |
|
| 319 | + |
|
| 320 | + // prise en charge CVT multi etape |
|
| 321 | + if (is_array($valeurs) and isset($valeurs['_etapes'])) { |
|
| 322 | + include_spip('inc/cvt_multietapes'); |
|
| 323 | + $valeurs = cvtmulti_formulaire_charger_etapes( |
|
| 324 | + array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste), |
|
| 325 | + $valeurs |
|
| 326 | + ); |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // si $valeurs et false ou une chaine, pas de formulaire, donc pas de pipeline ! |
|
| 330 | + if (is_array($valeurs)) { |
|
| 331 | + if (!isset($valeurs['_pipelines'])) { |
|
| 332 | + $valeurs['_pipelines'] = array(); |
|
| 333 | + } |
|
| 334 | + // l'ancien argument _pipeline devient maintenant _pipelines |
|
| 335 | + // reinjectons le vieux _pipeline au debut de _pipelines |
|
| 336 | + if (isset($valeurs['_pipeline'])) { |
|
| 337 | + $pipe = is_array($valeurs['_pipeline']) ? reset($valeurs['_pipeline']) : $valeurs['_pipeline']; |
|
| 338 | + $args = is_array($valeurs['_pipeline']) ? end($valeurs['_pipeline']) : array(); |
|
| 339 | + |
|
| 340 | + $pipelines = array($pipe => $args); |
|
| 341 | + $valeurs['_pipelines'] = array_merge($pipelines, $valeurs['_pipelines']); |
|
| 342 | + } |
|
| 343 | + |
|
| 344 | + // et enfin, ajoutons systematiquement un pipeline sur le squelette du formulaire |
|
| 345 | + // qui constitue le cas le plus courant d'utilisation du pipeline recuperer_fond |
|
| 346 | + // (performance, cela evite de s'injecter dans recuperer_fond utilise pour *tous* les squelettes) |
|
| 347 | + $valeurs['_pipelines']['formulaire_fond'] = array('form' => $form, 'args' => $args, 'je_suis_poste' => $poste); |
|
| 348 | + } |
|
| 349 | + |
|
| 350 | + return $valeurs; |
|
| 351 | 351 | } |
| 352 | 352 | |
| 353 | 353 | /** |
@@ -366,9 +366,9 @@ discard block |
||
| 366 | 366 | * @return bool |
| 367 | 367 | */ |
| 368 | 368 | function formulaire__identifier($form, $args, $p) { |
| 369 | - if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) { |
|
| 370 | - return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p); |
|
| 371 | - } |
|
| 369 | + if ($identifier_args = charger_fonction("identifier", "formulaires/$form", true)) { |
|
| 370 | + return call_user_func_array($identifier_args, $args) === call_user_func_array($identifier_args, $p); |
|
| 371 | + } |
|
| 372 | 372 | |
| 373 | - return $args === $p; |
|
| 373 | + return $args === $p; |
|
| 374 | 374 | } |