@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
| 18 | 18 | // donc il faut l'inclure "en globals" |
| 19 | 19 | if ($f = find_in_path('mes_fonctions.php')) { |
| 20 | - global $dossier_squelettes; |
|
| 21 | - include_once(_ROOT_CWD . $f); |
|
| 20 | + global $dossier_squelettes; |
|
| 21 | + include_once(_ROOT_CWD . $f); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
| 25 | - // chargement optimise precompile |
|
| 26 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 25 | + // chargement optimise precompile |
|
| 26 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 27 | 27 | } |
| 28 | 28 | if (test_espace_prive ()) |
| 29 | - include_spip('inc/filtres_ecrire'); |
|
| 29 | + include_spip('inc/filtres_ecrire'); |
|
| 30 | 30 | |
| 31 | 31 | # Determine le squelette associe a une requete |
| 32 | 32 | # et l'applique sur le contexte, le nom du cache et le serveur |
@@ -43,158 +43,158 @@ discard block |
||
| 43 | 43 | |
| 44 | 44 | // http://doc.spip.org/@public_parametrer_dist |
| 45 | 45 | function public_parametrer_dist($fond, $contexte='', $cache='', $connect='') { |
| 46 | - static $composer,$styliser,$notes=null; |
|
| 47 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 48 | - if ($page) return $page; |
|
| 49 | - |
|
| 50 | - if (isset($contexte['lang'])) |
|
| 51 | - $lang = $contexte['lang']; |
|
| 52 | - elseif (!isset($lang)) |
|
| 53 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 54 | - |
|
| 55 | - $select = ((!isset($GLOBALS['forcer_lang']) OR !$GLOBALS['forcer_lang']) AND $lang <> $GLOBALS['spip_lang']); |
|
| 56 | - if ($select) $select = lang_select($lang); |
|
| 57 | - |
|
| 58 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 59 | - |
|
| 60 | - if (!$styliser) |
|
| 61 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 62 | - list($skel,$mime_type, $gram, $sourcefile) = |
|
| 63 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 64 | - |
|
| 65 | - if ($skel) { |
|
| 66 | - |
|
| 67 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 68 | - // (recursion possible a cause des modeles) |
|
| 69 | - if ($debug) { |
|
| 70 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 71 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // charger le squelette en specifiant les langages cibles et source |
|
| 75 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 76 | - |
|
| 77 | - if (!$composer) |
|
| 78 | - $composer = charger_fonction('composer', 'public'); |
|
| 79 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 80 | - } |
|
| 81 | - else |
|
| 82 | - $fonc = ''; |
|
| 83 | - |
|
| 84 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 85 | - $page = $fonc; |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - // Preparer l'appel de la fonction principale du squelette |
|
| 89 | - |
|
| 90 | - spip_timer($a = 'calcul page '.rand(0,1000)); |
|
| 91 | - |
|
| 92 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 93 | - // et on enregistre l'etat courant des globales de notes... |
|
| 94 | - if (is_null($notes)) |
|
| 95 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 96 | - if ($notes) |
|
| 97 | - $notes('','empiler'); |
|
| 98 | - |
|
| 99 | - // Rajouter d'office ces deux parametres |
|
| 100 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 101 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 102 | - if (!isset($contexte['date'])) { |
|
| 103 | - $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 104 | - $contexte['date_default'] = true; |
|
| 105 | - } else $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 106 | - |
|
| 107 | - if (!isset($contexte['date_redac'])) { |
|
| 108 | - $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 109 | - $contexte['date_redac_default'] = true; |
|
| 110 | - } else $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 111 | - |
|
| 112 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | - $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 114 | - |
|
| 115 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 116 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 117 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 118 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 119 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 120 | - if ($notes) |
|
| 121 | - $notes('','depiler'); |
|
| 122 | - |
|
| 123 | - // reinjecter en dynamique la pile des notes |
|
| 124 | - // si il y a des inclure dynamiques |
|
| 125 | - // si la pile n'est pas vide |
|
| 126 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 127 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 128 | - if ($notes) |
|
| 129 | - $page['notes'] = $notes('','sauver_etat'); |
|
| 130 | - |
|
| 131 | - // spip_log: un joli contexte |
|
| 132 | - $infos = array(); |
|
| 133 | - foreach (array_filter($contexte) as $var => $val) { |
|
| 134 | - if (is_array($val)) $val = serialize($val); |
|
| 135 | - if (strlen("$val") > 30) |
|
| 136 | - $val = substr("$val", 0,27).'..'; |
|
| 137 | - if (strstr($val,' ')) |
|
| 138 | - $val = "'$val'"; |
|
| 139 | - $infos[] = $var.'='.$val; |
|
| 140 | - } |
|
| 141 | - $profile = spip_timer($a); |
|
| 142 | - spip_log("calcul ($profile) [$skel] " |
|
| 143 | - . join(', ', $infos) |
|
| 144 | - .' ('.strlen($page['texte']).' octets)'); |
|
| 145 | - |
|
| 146 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 147 | - spip_log("calcul ($profile) [$skel] " |
|
| 148 | - . join(', ', $infos) |
|
| 149 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - if ($debug) { |
|
| 153 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | - $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 155 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 159 | - AND (_request('var_mode_objet') == $fonc) |
|
| 160 | - AND (_request('var_mode_affiche') == 'resultat')) { |
|
| 161 | - erreur_squelette(); |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 165 | - if (!isset($page['entetes']['X-Spip-Cache'])){ |
|
| 166 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 167 | - // si aucun #CACHE{} specifie |
|
| 168 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 169 | - // entre public et prive |
|
| 170 | - if (test_espace_prive() OR strncmp($fond,'modeles/',8)==0) |
|
| 171 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 172 | - else |
|
| 173 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais'])?$GLOBALS['delais']:36000; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $page['contexte'] = $contexte; |
|
| 46 | + static $composer,$styliser,$notes=null; |
|
| 47 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 48 | + if ($page) return $page; |
|
| 49 | + |
|
| 50 | + if (isset($contexte['lang'])) |
|
| 51 | + $lang = $contexte['lang']; |
|
| 52 | + elseif (!isset($lang)) |
|
| 53 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 54 | + |
|
| 55 | + $select = ((!isset($GLOBALS['forcer_lang']) OR !$GLOBALS['forcer_lang']) AND $lang <> $GLOBALS['spip_lang']); |
|
| 56 | + if ($select) $select = lang_select($lang); |
|
| 57 | + |
|
| 58 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 59 | + |
|
| 60 | + if (!$styliser) |
|
| 61 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 62 | + list($skel,$mime_type, $gram, $sourcefile) = |
|
| 63 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 64 | + |
|
| 65 | + if ($skel) { |
|
| 66 | + |
|
| 67 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 68 | + // (recursion possible a cause des modeles) |
|
| 69 | + if ($debug) { |
|
| 70 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 71 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // charger le squelette en specifiant les langages cibles et source |
|
| 75 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 76 | + |
|
| 77 | + if (!$composer) |
|
| 78 | + $composer = charger_fonction('composer', 'public'); |
|
| 79 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 80 | + } |
|
| 81 | + else |
|
| 82 | + $fonc = ''; |
|
| 83 | + |
|
| 84 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 85 | + $page = $fonc; |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + // Preparer l'appel de la fonction principale du squelette |
|
| 89 | + |
|
| 90 | + spip_timer($a = 'calcul page '.rand(0,1000)); |
|
| 91 | + |
|
| 92 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 93 | + // et on enregistre l'etat courant des globales de notes... |
|
| 94 | + if (is_null($notes)) |
|
| 95 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 96 | + if ($notes) |
|
| 97 | + $notes('','empiler'); |
|
| 98 | + |
|
| 99 | + // Rajouter d'office ces deux parametres |
|
| 100 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 101 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 102 | + if (!isset($contexte['date'])) { |
|
| 103 | + $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 104 | + $contexte['date_default'] = true; |
|
| 105 | + } else $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 106 | + |
|
| 107 | + if (!isset($contexte['date_redac'])) { |
|
| 108 | + $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 109 | + $contexte['date_redac_default'] = true; |
|
| 110 | + } else $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 111 | + |
|
| 112 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 113 | + $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 114 | + |
|
| 115 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 116 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 117 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 118 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 119 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 120 | + if ($notes) |
|
| 121 | + $notes('','depiler'); |
|
| 122 | + |
|
| 123 | + // reinjecter en dynamique la pile des notes |
|
| 124 | + // si il y a des inclure dynamiques |
|
| 125 | + // si la pile n'est pas vide |
|
| 126 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 127 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 128 | + if ($notes) |
|
| 129 | + $page['notes'] = $notes('','sauver_etat'); |
|
| 130 | + |
|
| 131 | + // spip_log: un joli contexte |
|
| 132 | + $infos = array(); |
|
| 133 | + foreach (array_filter($contexte) as $var => $val) { |
|
| 134 | + if (is_array($val)) $val = serialize($val); |
|
| 135 | + if (strlen("$val") > 30) |
|
| 136 | + $val = substr("$val", 0,27).'..'; |
|
| 137 | + if (strstr($val,' ')) |
|
| 138 | + $val = "'$val'"; |
|
| 139 | + $infos[] = $var.'='.$val; |
|
| 140 | + } |
|
| 141 | + $profile = spip_timer($a); |
|
| 142 | + spip_log("calcul ($profile) [$skel] " |
|
| 143 | + . join(', ', $infos) |
|
| 144 | + .' ('.strlen($page['texte']).' octets)'); |
|
| 145 | + |
|
| 146 | + if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 147 | + spip_log("calcul ($profile) [$skel] " |
|
| 148 | + . join(', ', $infos) |
|
| 149 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + if ($debug) { |
|
| 153 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 154 | + $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 155 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 156 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 157 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 158 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 159 | + AND (_request('var_mode_objet') == $fonc) |
|
| 160 | + AND (_request('var_mode_affiche') == 'resultat')) { |
|
| 161 | + erreur_squelette(); |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 165 | + if (!isset($page['entetes']['X-Spip-Cache'])){ |
|
| 166 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 167 | + // si aucun #CACHE{} specifie |
|
| 168 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 169 | + // entre public et prive |
|
| 170 | + if (test_espace_prive() OR strncmp($fond,'modeles/',8)==0) |
|
| 171 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 172 | + else |
|
| 173 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais'])?$GLOBALS['delais']:36000; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $page['contexte'] = $contexte; |
|
| 177 | 177 | |
| 178 | - // faire remonter le fichier source |
|
| 179 | - static $js_inclus = false; |
|
| 180 | - if (defined('_VAR_INCLURE') AND _VAR_INCLURE){ |
|
| 181 | - $page['sourcefile'] = $sourcefile; |
|
| 182 | - $page['texte'] = |
|
| 183 | - "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 184 | - . ($js_inclus?"":"<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 185 | - $js_inclus = true; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 189 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 190 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 191 | - unset($GLOBALS['cache_utilise_session']); |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ($select) lang_select(); |
|
| 196 | - |
|
| 197 | - return $page; |
|
| 178 | + // faire remonter le fichier source |
|
| 179 | + static $js_inclus = false; |
|
| 180 | + if (defined('_VAR_INCLURE') AND _VAR_INCLURE){ |
|
| 181 | + $page['sourcefile'] = $sourcefile; |
|
| 182 | + $page['texte'] = |
|
| 183 | + "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 184 | + . ($js_inclus?"":"<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 185 | + $js_inclus = true; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 189 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 190 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 191 | + unset($GLOBALS['cache_utilise_session']); |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ($select) lang_select(); |
|
| 196 | + |
|
| 197 | + return $page; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -212,36 +212,36 @@ discard block |
||
| 212 | 212 | */ |
| 213 | 213 | function tester_redirection($fond, $contexte, $connect) |
| 214 | 214 | { |
| 215 | - if ($fond == 'article' |
|
| 216 | - AND $id_article = intval($contexte['id_article'])) { |
|
| 217 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 218 | - $m = quete_virtuel($id_article, $connect); |
|
| 219 | - if (strlen($m)) { |
|
| 220 | - include_spip('inc/texte'); |
|
| 221 | - // les navigateurs pataugent si l'URL est vide |
|
| 222 | - if ($url = virtuel_redirige($m, true)){ |
|
| 223 | - // passer en url absolue car cette redirection pourra |
|
| 224 | - // etre utilisee dans un contexte d'url qui change |
|
| 225 | - // y compris url arbo |
|
| 226 | - $status = 302; |
|
| 227 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) |
|
| 228 | - $status=_STATUS_REDIRECTION_VIRTUEL; |
|
| 229 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 230 | - include_spip('inc/filtres_mini'); |
|
| 231 | - $url = url_absolue($url); |
|
| 232 | - } |
|
| 233 | - $url = str_replace('&', '&', $url); |
|
| 234 | - return array('texte' => "<" |
|
| 235 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 236 | - . texte_script($url) |
|
| 237 | - . "','',$status);" |
|
| 238 | - . "?" . ">", |
|
| 239 | - 'process_ins' => 'php', |
|
| 240 | - 'status' => $status); |
|
| 241 | - } |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - return false; |
|
| 215 | + if ($fond == 'article' |
|
| 216 | + AND $id_article = intval($contexte['id_article'])) { |
|
| 217 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 218 | + $m = quete_virtuel($id_article, $connect); |
|
| 219 | + if (strlen($m)) { |
|
| 220 | + include_spip('inc/texte'); |
|
| 221 | + // les navigateurs pataugent si l'URL est vide |
|
| 222 | + if ($url = virtuel_redirige($m, true)){ |
|
| 223 | + // passer en url absolue car cette redirection pourra |
|
| 224 | + // etre utilisee dans un contexte d'url qui change |
|
| 225 | + // y compris url arbo |
|
| 226 | + $status = 302; |
|
| 227 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) |
|
| 228 | + $status=_STATUS_REDIRECTION_VIRTUEL; |
|
| 229 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 230 | + include_spip('inc/filtres_mini'); |
|
| 231 | + $url = url_absolue($url); |
|
| 232 | + } |
|
| 233 | + $url = str_replace('&', '&', $url); |
|
| 234 | + return array('texte' => "<" |
|
| 235 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 236 | + . texte_script($url) |
|
| 237 | + . "','',$status);" |
|
| 238 | + . "?" . ">", |
|
| 239 | + 'process_ins' => 'php', |
|
| 240 | + 'status' => $status); |
|
| 241 | + } |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + return false; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | ?> |
@@ -21,54 +21,54 @@ |
||
| 21 | 21 | // Compatibilite : on utilise stripos/strripos() qui n'existent pas en php4 |
| 22 | 22 | if (!function_exists('strripos')) { |
| 23 | 23 | // http://doc.spip.org/@strripos |
| 24 | - function strripos($botte, $aiguille) { |
|
| 25 | - if (preg_match('@^(.*)' . preg_quote($aiguille, '@') . '@is', |
|
| 26 | - $botte, $regs)) { |
|
| 27 | - return strlen($regs[1]); |
|
| 28 | - } |
|
| 29 | - return false; |
|
| 30 | - } |
|
| 24 | + function strripos($botte, $aiguille) { |
|
| 25 | + if (preg_match('@^(.*)' . preg_quote($aiguille, '@') . '@is', |
|
| 26 | + $botte, $regs)) { |
|
| 27 | + return strlen($regs[1]); |
|
| 28 | + } |
|
| 29 | + return false; |
|
| 30 | + } |
|
| 31 | 31 | } |
| 32 | 32 | if (!function_exists('stripos')) { |
| 33 | 33 | // http://doc.spip.org/@stripos |
| 34 | - function stripos($botte, $aiguille) { |
|
| 35 | - if (preg_match('@^(.*)' . preg_quote($aiguille, '@') . '@isU', |
|
| 36 | - $botte, $regs)) { |
|
| 37 | - return strlen($regs[1]); |
|
| 38 | - } |
|
| 39 | - return false; |
|
| 40 | - } |
|
| 34 | + function stripos($botte, $aiguille) { |
|
| 35 | + if (preg_match('@^(.*)' . preg_quote($aiguille, '@') . '@isU', |
|
| 36 | + $botte, $regs)) { |
|
| 37 | + return strlen($regs[1]); |
|
| 38 | + } |
|
| 39 | + return false; |
|
| 40 | + } |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | // http://doc.spip.org/@affiche_boutons_admin |
| 44 | 44 | function affiche_boutons_admin($contenu) { |
| 45 | - include_spip('inc/filtres'); |
|
| 45 | + include_spip('inc/filtres'); |
|
| 46 | 46 | |
| 47 | - // Inserer le css d'admin |
|
| 48 | - $css = "<link rel='stylesheet' href='".url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 49 | - . "' type='text/css' />\n"; |
|
| 50 | - if ($f = find_in_path('spip_admin_perso.css')) |
|
| 51 | - $css .= "<link rel='stylesheet' href='" |
|
| 52 | - . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 47 | + // Inserer le css d'admin |
|
| 48 | + $css = "<link rel='stylesheet' href='".url_absolue(direction_css(find_in_path('spip_admin.css'))) |
|
| 49 | + . "' type='text/css' />\n"; |
|
| 50 | + if ($f = find_in_path('spip_admin_perso.css')) |
|
| 51 | + $css .= "<link rel='stylesheet' href='" |
|
| 52 | + . url_absolue(direction_css($f)) . "' type='text/css' />\n"; |
|
| 53 | 53 | |
| 54 | - ($pos = stripos($contenu, '</head>')) |
|
| 55 | - || ($pos = stripos($contenu, '<body>')) |
|
| 56 | - || ($pos = 0); |
|
| 57 | - $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 54 | + ($pos = stripos($contenu, '</head>')) |
|
| 55 | + || ($pos = stripos($contenu, '<body>')) |
|
| 56 | + || ($pos = 0); |
|
| 57 | + $contenu = substr_replace($contenu, $css, $pos, 0); |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 61 | - $boutons_admin = inclure_balise_dynamique( |
|
| 62 | - balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 63 | - false); |
|
| 60 | + // Inserer la balise #FORMULAIRE_ADMIN, en float |
|
| 61 | + $boutons_admin = inclure_balise_dynamique( |
|
| 62 | + balise_FORMULAIRE_ADMIN_dyn('spip-admin-float'), |
|
| 63 | + false); |
|
| 64 | 64 | |
| 65 | - ($pos = strripos($contenu, '</body>')) |
|
| 66 | - || ($pos = strripos($contenu, '</html>')) |
|
| 67 | - || ($pos = strlen($contenu)); |
|
| 68 | - $contenu = substr_replace($contenu, $boutons_admin, $pos, 0); |
|
| 65 | + ($pos = strripos($contenu, '</body>')) |
|
| 66 | + || ($pos = strripos($contenu, '</html>')) |
|
| 67 | + || ($pos = strlen($contenu)); |
|
| 68 | + $contenu = substr_replace($contenu, $boutons_admin, $pos, 0); |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - return $contenu; |
|
| 71 | + return $contenu; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | ?> |
@@ -64,136 +64,136 @@ discard block |
||
| 64 | 64 | * - string si $message à false. |
| 65 | 65 | **/ |
| 66 | 66 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()){ |
| 67 | - global $visiteur_session; |
|
| 68 | - global $debug_objets; |
|
| 69 | - static $tableau_des_erreurs = array(); |
|
| 70 | - |
|
| 71 | - // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | - if (isset($opt['erreurs'])) { |
|
| 73 | - if ($opt['erreurs'] == 'get') { |
|
| 74 | - return $tableau_des_erreurs; |
|
| 75 | - } |
|
| 76 | - if ($opt['erreurs'] == 'reset') { |
|
| 77 | - $tableau_des_erreurs = array(); |
|
| 78 | - return true; |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - // Erreur ou appel final ? |
|
| 83 | - if ($message){ |
|
| 84 | - $message = debusquer_compose_message($message); |
|
| 85 | - $tableau_des_erreurs[] = array($message, $lieu); |
|
| 86 | - set_request('var_mode', 'debug'); |
|
| 87 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 88 | - // Permettre a la compil de continuer |
|
| 89 | - if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
|
| 90 | - $lieu->code = "''"; |
|
| 91 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 92 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 93 | - if (!$urgence) return; |
|
| 94 | - } |
|
| 95 | - if (empty($debug_objets['principal'])) |
|
| 96 | - $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 97 | - |
|
| 98 | - include_spip('inc/autoriser'); |
|
| 99 | - if (!autoriser('debug')) return; |
|
| 100 | - include_spip('inc/headers'); |
|
| 101 | - include_spip('inc/filtres'); |
|
| 102 | - |
|
| 103 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 104 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 105 | - // - ca fait 2 headers ! |
|
| 106 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 107 | - // actif par exemple) |
|
| 108 | - if (ob_get_length() |
|
| 109 | - AND |
|
| 110 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 111 | - ){ |
|
| 112 | - ob_end_clean(); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - lang_select($visiteur_session['lang']); |
|
| 116 | - $fonc = _request('var_mode_objet'); |
|
| 117 | - $mode = _request('var_mode_affiche'); |
|
| 118 | - $self = str_replace("\\'", ''', self()); |
|
| 119 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 67 | + global $visiteur_session; |
|
| 68 | + global $debug_objets; |
|
| 69 | + static $tableau_des_erreurs = array(); |
|
| 70 | + |
|
| 71 | + // Pour des tests unitaires, pouvoir récupérer les erreurs générées |
|
| 72 | + if (isset($opt['erreurs'])) { |
|
| 73 | + if ($opt['erreurs'] == 'get') { |
|
| 74 | + return $tableau_des_erreurs; |
|
| 75 | + } |
|
| 76 | + if ($opt['erreurs'] == 'reset') { |
|
| 77 | + $tableau_des_erreurs = array(); |
|
| 78 | + return true; |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + // Erreur ou appel final ? |
|
| 83 | + if ($message){ |
|
| 84 | + $message = debusquer_compose_message($message); |
|
| 85 | + $tableau_des_erreurs[] = array($message, $lieu); |
|
| 86 | + set_request('var_mode', 'debug'); |
|
| 87 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 88 | + // Permettre a la compil de continuer |
|
| 89 | + if (is_object($lieu) AND (!isset($lieu->code) OR !$lieu->code)) |
|
| 90 | + $lieu->code = "''"; |
|
| 91 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 92 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS AND count($tableau_des_erreurs)>_DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 93 | + if (!$urgence) return; |
|
| 94 | + } |
|
| 95 | + if (empty($debug_objets['principal'])) |
|
| 96 | + $debug_objets['principal'] = $GLOBALS['fond']; |
|
| 97 | + |
|
| 98 | + include_spip('inc/autoriser'); |
|
| 99 | + if (!autoriser('debug')) return; |
|
| 100 | + include_spip('inc/headers'); |
|
| 101 | + include_spip('inc/filtres'); |
|
| 102 | + |
|
| 103 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 104 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 105 | + // - ca fait 2 headers ! |
|
| 106 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 107 | + // actif par exemple) |
|
| 108 | + if (ob_get_length() |
|
| 109 | + AND |
|
| 110 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 111 | + ){ |
|
| 112 | + ob_end_clean(); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + lang_select($visiteur_session['lang']); |
|
| 116 | + $fonc = _request('var_mode_objet'); |
|
| 117 | + $mode = _request('var_mode_affiche'); |
|
| 118 | + $self = str_replace("\\'", ''', self()); |
|
| 119 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 120 | 120 | |
| 121 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 122 | - . '<br />' |
|
| 123 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 124 | - |
|
| 125 | - if (!_DIR_RESTREINT OR headers_sent()) return $res; |
|
| 126 | - if ($tableau_des_erreurs) http_status(503); |
|
| 127 | - |
|
| 128 | - http_no_cache(); |
|
| 129 | - if (isset($_GET['var_profile'])){ |
|
| 130 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 131 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 132 | - } |
|
| 133 | - else { |
|
| 134 | - if (!$fonc) $fonc = $debug_objets['principal']; |
|
| 135 | - $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
|
| 136 | - } |
|
| 137 | - if ($message===false){ |
|
| 138 | - lang_select(); |
|
| 139 | - return debusquer_entete($titre, $res); |
|
| 140 | - } |
|
| 141 | - else |
|
| 142 | - echo debusquer_entete($titre, $res); |
|
| 143 | - exit; |
|
| 121 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 122 | + . '<br />' |
|
| 123 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 124 | + |
|
| 125 | + if (!_DIR_RESTREINT OR headers_sent()) return $res; |
|
| 126 | + if ($tableau_des_erreurs) http_status(503); |
|
| 127 | + |
|
| 128 | + http_no_cache(); |
|
| 129 | + if (isset($_GET['var_profile'])){ |
|
| 130 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 131 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 132 | + } |
|
| 133 | + else { |
|
| 134 | + if (!$fonc) $fonc = $debug_objets['principal']; |
|
| 135 | + $titre = !$mode ? $fonc : ($mode . ' ' . $debug_objets['sourcefile'][$fonc]); |
|
| 136 | + } |
|
| 137 | + if ($message===false){ |
|
| 138 | + lang_select(); |
|
| 139 | + return debusquer_entete($titre, $res); |
|
| 140 | + } |
|
| 141 | + else |
|
| 142 | + echo debusquer_entete($titre, $res); |
|
| 143 | + exit; |
|
| 144 | 144 | } |
| 145 | 145 | |
| 146 | 146 | function debusquer_compose_message($msg){ |
| 147 | - if (is_array($msg)){ |
|
| 148 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 149 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 150 | - if (!is_numeric($msg[0]) AND count($msg)==2) { |
|
| 151 | - // message avec argument: instancier |
|
| 152 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 153 | - } else { |
|
| 154 | - // message SQL: interpreter |
|
| 155 | - $msg = debusquer_requete($msg); |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 159 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 160 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 161 | - // une erreur critique sort $message en array |
|
| 162 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 163 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 164 | - return $msg; |
|
| 147 | + if (is_array($msg)){ |
|
| 148 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 149 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 150 | + if (!is_numeric($msg[0]) AND count($msg)==2) { |
|
| 151 | + // message avec argument: instancier |
|
| 152 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 153 | + } else { |
|
| 154 | + // message SQL: interpreter |
|
| 155 | + $msg = debusquer_requete($msg); |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 159 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 160 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 161 | + // une erreur critique sort $message en array |
|
| 162 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 163 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 164 | + return $msg; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | function debusquer_bandeau($erreurs){ |
| 168 | 168 | |
| 169 | - if (!empty($erreurs)){ |
|
| 170 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 171 | - return debusquer_navigation($erreurs, $n); |
|
| 172 | - } |
|
| 173 | - elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 174 | - include_spip('public/tracer'); |
|
| 175 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 176 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 177 | - } |
|
| 178 | - else |
|
| 179 | - return ''; |
|
| 169 | + if (!empty($erreurs)){ |
|
| 170 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 171 | + return debusquer_navigation($erreurs, $n); |
|
| 172 | + } |
|
| 173 | + elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 174 | + include_spip('public/tracer'); |
|
| 175 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 176 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 177 | + } |
|
| 178 | + else |
|
| 179 | + return ''; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | function debusquer_contexte($env){ |
| 183 | 183 | |
| 184 | - if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
|
| 184 | + if (is_array($env_tab = @unserialize($env))) $env = $env_tab; |
|
| 185 | 185 | |
| 186 | - if (!$env) return ''; |
|
| 187 | - $res = ""; |
|
| 188 | - foreach ($env as $nom => $valeur){ |
|
| 189 | - if (is_array($valeur)) |
|
| 190 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 191 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 192 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 193 | - . "</td></tr>\n"; |
|
| 194 | - } |
|
| 186 | + if (!$env) return ''; |
|
| 187 | + $res = ""; |
|
| 188 | + foreach ($env as $nom => $valeur){ |
|
| 189 | + if (is_array($valeur)) |
|
| 190 | + $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur) . ']'; |
|
| 191 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 192 | + . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 193 | + . "</td></tr>\n"; |
|
| 194 | + } |
|
| 195 | 195 | |
| 196 | - return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 196 | + return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 197 | 197 | } |
| 198 | 198 | |
| 199 | 199 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -201,65 +201,65 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav'){ |
| 203 | 203 | |
| 204 | - if (_request('exec')=='valider_xml') return ''; |
|
| 205 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 206 | - $res = ''; |
|
| 207 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 208 | - foreach ($tableau as $i => $err){ |
|
| 209 | - $boucle = $ligne = $skel = ''; |
|
| 210 | - list($msg, $lieu) = $err; |
|
| 211 | - if (is_object($lieu)){ |
|
| 212 | - $ligne = $lieu->ligne; |
|
| 213 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 214 | - if (isset($lieu->descr['nom'])){ |
|
| 215 | - $nom_code = $lieu->descr['nom']; |
|
| 216 | - $skel = $lieu->descr['sourcefile']; |
|
| 217 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 218 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 219 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 220 | - if ($boucle){ |
|
| 221 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 222 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - } |
|
| 226 | - |
|
| 227 | - $j = ($i+1); |
|
| 228 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 229 | - . $j |
|
| 230 | - . " </td><td style='text-align: left'>" |
|
| 231 | - . $msg |
|
| 232 | - . "</td><td style='text-align: left'>" |
|
| 233 | - . ($skel ? $skel : " / ") |
|
| 234 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 235 | - . ($boucle ? $boucle : " / ") |
|
| 236 | - . "</td><td style='text-align: right'>" |
|
| 237 | - . $ligne |
|
| 238 | - . "</td></tr>\n"; |
|
| 239 | - |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - return "\n<table id='$id'>" |
|
| 243 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 244 | - . $caption[0] |
|
| 204 | + if (_request('exec')=='valider_xml') return ''; |
|
| 205 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 206 | + $res = ''; |
|
| 207 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 208 | + foreach ($tableau as $i => $err){ |
|
| 209 | + $boucle = $ligne = $skel = ''; |
|
| 210 | + list($msg, $lieu) = $err; |
|
| 211 | + if (is_object($lieu)){ |
|
| 212 | + $ligne = $lieu->ligne; |
|
| 213 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 214 | + if (isset($lieu->descr['nom'])){ |
|
| 215 | + $nom_code = $lieu->descr['nom']; |
|
| 216 | + $skel = $lieu->descr['sourcefile']; |
|
| 217 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 218 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 219 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 220 | + if ($boucle){ |
|
| 221 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 222 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | + |
|
| 227 | + $j = ($i+1); |
|
| 228 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 229 | + . $j |
|
| 230 | + . " </td><td style='text-align: left'>" |
|
| 231 | + . $msg |
|
| 232 | + . "</td><td style='text-align: left'>" |
|
| 233 | + . ($skel ? $skel : " / ") |
|
| 234 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 235 | + . ($boucle ? $boucle : " / ") |
|
| 236 | + . "</td><td style='text-align: right'>" |
|
| 237 | + . $ligne |
|
| 238 | + . "</td></tr>\n"; |
|
| 239 | + |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + return "\n<table id='$id'>" |
|
| 243 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 244 | + . $caption[0] |
|
| 245 | 245 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 246 | 246 | # aide('erreur_compilation'), |
| 247 | - . "</caption>" |
|
| 248 | - // fausse caption du chrono (mais vraie nav) |
|
| 249 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 250 | - . "<tr><th>" |
|
| 251 | - . _T('numero') |
|
| 252 | - . "</th><th>" |
|
| 253 | - . _T('public:message') |
|
| 254 | - . "</th><th>" |
|
| 255 | - . _T('squelette') |
|
| 256 | - . "</th><th>" |
|
| 257 | - . _T('zbug_boucle') |
|
| 258 | - . "</th><th>" |
|
| 259 | - . _T('ligne') |
|
| 260 | - . "</th></tr>" |
|
| 261 | - . $res |
|
| 262 | - . "</table>"; |
|
| 247 | + . "</caption>" |
|
| 248 | + // fausse caption du chrono (mais vraie nav) |
|
| 249 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 250 | + . "<tr><th>" |
|
| 251 | + . _T('numero') |
|
| 252 | + . "</th><th>" |
|
| 253 | + . _T('public:message') |
|
| 254 | + . "</th><th>" |
|
| 255 | + . _T('squelette') |
|
| 256 | + . "</th><th>" |
|
| 257 | + . _T('zbug_boucle') |
|
| 258 | + . "</th><th>" |
|
| 259 | + . _T('ligne') |
|
| 260 | + . "</th></tr>" |
|
| 261 | + . $res |
|
| 262 | + . "</table>"; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -279,116 +279,116 @@ discard block |
||
| 279 | 279 | * ou un tableau si l'erreur est critique |
| 280 | 280 | **/ |
| 281 | 281 | function debusquer_requete($message){ |
| 282 | - list($errno, $msg, $query) = $message; |
|
| 283 | - |
|
| 284 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 285 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 286 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
|
| 287 | - $errno = $regs[2]; |
|
| 288 | - } |
|
| 289 | - elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 290 | - AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 291 | - ) { |
|
| 292 | - $errno = $regs[1]; |
|
| 293 | - } |
|
| 294 | - |
|
| 295 | - // Erreur systeme |
|
| 296 | - if (is_numeric($errno) and $errno>0 AND $errno<200){ |
|
| 297 | - $retour = "<tt><br /><br /><blink>" |
|
| 298 | - . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 299 | - . "</blink><br />\n<b>" |
|
| 300 | - . _T('info_erreur_systeme2', |
|
| 301 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 302 | - . '</b><br />'; |
|
| 303 | - spip_log("Erreur systeme $errno"); |
|
| 304 | - return array($retour, ''); |
|
| 305 | - } |
|
| 306 | - |
|
| 307 | - // Requete erronee |
|
| 308 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 309 | - . spip_htmlspecialchars($msg) |
|
| 310 | - . "\n<br /><span style='color: red'><b>" |
|
| 311 | - . spip_htmlspecialchars($query) |
|
| 312 | - . "</b></span></tt><br />"; |
|
| 313 | - //. aide('erreur_mysql'); |
|
| 314 | - |
|
| 315 | - return $err; |
|
| 282 | + list($errno, $msg, $query) = $message; |
|
| 283 | + |
|
| 284 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 285 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 286 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)){ |
|
| 287 | + $errno = $regs[2]; |
|
| 288 | + } |
|
| 289 | + elseif (is_numeric($errno) and ($errno==1030 OR $errno<=1026) |
|
| 290 | + AND preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 291 | + ) { |
|
| 292 | + $errno = $regs[1]; |
|
| 293 | + } |
|
| 294 | + |
|
| 295 | + // Erreur systeme |
|
| 296 | + if (is_numeric($errno) and $errno>0 AND $errno<200){ |
|
| 297 | + $retour = "<tt><br /><br /><blink>" |
|
| 298 | + . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 299 | + . "</blink><br />\n<b>" |
|
| 300 | + . _T('info_erreur_systeme2', |
|
| 301 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 302 | + . '</b><br />'; |
|
| 303 | + spip_log("Erreur systeme $errno"); |
|
| 304 | + return array($retour, ''); |
|
| 305 | + } |
|
| 306 | + |
|
| 307 | + // Requete erronee |
|
| 308 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 309 | + . spip_htmlspecialchars($msg) |
|
| 310 | + . "\n<br /><span style='color: red'><b>" |
|
| 311 | + . spip_htmlspecialchars($query) |
|
| 312 | + . "</b></span></tt><br />"; |
|
| 313 | + //. aide('erreur_mysql'); |
|
| 314 | + |
|
| 315 | + return $err; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | |
| 319 | 319 | |
| 320 | 320 | // http://doc.spip.org/@trouve_boucle_debug |
| 321 | 321 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = ""){ |
| 322 | - global $debug_objets; |
|
| 323 | - |
|
| 324 | - $id = $nom . $boucle; |
|
| 325 | - if (is_array($debug_objets['sequence'][$id])){ |
|
| 326 | - foreach ($debug_objets['sequence'][$id] as $v){ |
|
| 327 | - |
|
| 328 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
|
| 329 | - $y = substr_count($v[0], "\n"); |
|
| 330 | - else { |
|
| 331 | - if ($v[1][0]=='#') |
|
| 332 | - // balise dynamique |
|
| 333 | - $incl = $debug_objets['resultat'][$v[2]]; |
|
| 334 | - else |
|
| 335 | - // inclusion |
|
| 336 | - $incl = $debug_objets['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 337 | - $y = substr_count($incl, "\n") |
|
| 338 | - +substr_count($r[1], "\n") |
|
| 339 | - +substr_count($r[3], "\n"); |
|
| 340 | - } |
|
| 341 | - if ($n<=($y+$debut)){ |
|
| 342 | - if ($v[1][0]=='?') |
|
| 343 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 344 | - elseif ($v[1][0]=='!') { |
|
| 345 | - if ($incl = trouve_squelette_inclus($v[1])) |
|
| 346 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 347 | - } |
|
| 348 | - return array($nom, $boucle, $v[2]-1+$n-$debut); |
|
| 349 | - } |
|
| 350 | - $debut += $y; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - return array($nom, $boucle, $n-$debut); |
|
| 322 | + global $debug_objets; |
|
| 323 | + |
|
| 324 | + $id = $nom . $boucle; |
|
| 325 | + if (is_array($debug_objets['sequence'][$id])){ |
|
| 326 | + foreach ($debug_objets['sequence'][$id] as $v){ |
|
| 327 | + |
|
| 328 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) |
|
| 329 | + $y = substr_count($v[0], "\n"); |
|
| 330 | + else { |
|
| 331 | + if ($v[1][0]=='#') |
|
| 332 | + // balise dynamique |
|
| 333 | + $incl = $debug_objets['resultat'][$v[2]]; |
|
| 334 | + else |
|
| 335 | + // inclusion |
|
| 336 | + $incl = $debug_objets['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 337 | + $y = substr_count($incl, "\n") |
|
| 338 | + +substr_count($r[1], "\n") |
|
| 339 | + +substr_count($r[3], "\n"); |
|
| 340 | + } |
|
| 341 | + if ($n<=($y+$debut)){ |
|
| 342 | + if ($v[1][0]=='?') |
|
| 343 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 344 | + elseif ($v[1][0]=='!') { |
|
| 345 | + if ($incl = trouve_squelette_inclus($v[1])) |
|
| 346 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 347 | + } |
|
| 348 | + return array($nom, $boucle, $v[2]-1+$n-$debut); |
|
| 349 | + } |
|
| 350 | + $debut += $y; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + return array($nom, $boucle, $n-$debut); |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | // http://doc.spip.org/@trouve_squelette_inclus |
| 357 | 357 | function trouve_squelette_inclus($script){ |
| 358 | - global $debug_objets; |
|
| 359 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 360 | - // si le script X.php n'est pas ecrire/public.php |
|
| 361 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 362 | - if ($reg[1]=='ecrire/public') |
|
| 363 | - // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 364 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
|
| 365 | - // a defaut on cherche le param 'page' |
|
| 366 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
|
| 367 | - $reg[1] = "inconnu"; |
|
| 368 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 369 | - |
|
| 370 | - foreach ($debug_objets['sourcefile'] as $k => $v){ |
|
| 371 | - if (preg_match($incl, $v)) return $k; |
|
| 372 | - } |
|
| 373 | - return ""; |
|
| 358 | + global $debug_objets; |
|
| 359 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 360 | + // si le script X.php n'est pas ecrire/public.php |
|
| 361 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 362 | + if ($reg[1]=='ecrire/public') |
|
| 363 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 364 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) |
|
| 365 | + // a defaut on cherche le param 'page' |
|
| 366 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) |
|
| 367 | + $reg[1] = "inconnu"; |
|
| 368 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 369 | + |
|
| 370 | + foreach ($debug_objets['sourcefile'] as $k => $v){ |
|
| 371 | + if (preg_match($incl, $v)) return $k; |
|
| 372 | + } |
|
| 373 | + return ""; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | // http://doc.spip.org/@reference_boucle_debug |
| 377 | 377 | function reference_boucle_debug($n, $nom, $self){ |
| 378 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 379 | - |
|
| 380 | - if (!$boucle) |
|
| 381 | - return !$ligne ? "" : |
|
| 382 | - (" (" . |
|
| 383 | - (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
|
| 384 | - _T('squelette_ligne')) . |
|
| 385 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 386 | - else { |
|
| 387 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 388 | - |
|
| 389 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 390 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 391 | - } |
|
| 378 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 379 | + |
|
| 380 | + if (!$boucle) |
|
| 381 | + return !$ligne ? "" : |
|
| 382 | + (" (" . |
|
| 383 | + (($nom!=$skel) ? _T('squelette_inclus_ligne') : |
|
| 384 | + _T('squelette_ligne')) . |
|
| 385 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 386 | + else { |
|
| 387 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 388 | + |
|
| 389 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 390 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 391 | + } |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // affiche un texte avec numero de ligne et ancre. |
@@ -396,380 +396,380 @@ discard block |
||
| 396 | 396 | // http://doc.spip.org/@ancre_texte |
| 397 | 397 | function ancre_texte($texte, $fautifs = array(), $nocpt = false){ |
| 398 | 398 | |
| 399 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 400 | - if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
|
| 401 | - $res = ''; |
|
| 402 | - |
|
| 403 | - $s = highlight_string($texte, true); |
|
| 404 | - if (substr($s, 0, 6)=='<code>'){ |
|
| 405 | - $s = substr($s, 6); |
|
| 406 | - $res = '<code>'; |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 410 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 411 | - $s); |
|
| 412 | - |
|
| 413 | - |
|
| 414 | - $tableau = explode("<br />", $s); |
|
| 415 | - |
|
| 416 | - $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 417 | - |
|
| 418 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 419 | - $formaterr = "color: red;"; |
|
| 420 | - $i = 1; |
|
| 421 | - $flignes = array(); |
|
| 422 | - $loc = array(0, 0); |
|
| 423 | - foreach ($fautifs as $lc) |
|
| 424 | - if (is_array($lc)){ |
|
| 425 | - $l = array_shift($lc); |
|
| 426 | - $flignes[$l] = $lc; |
|
| 427 | - } else $flignes[$lc] = $loc; |
|
| 428 | - |
|
| 429 | - $ancre = md5($texte); |
|
| 430 | - foreach ($tableau as $ligne){ |
|
| 431 | - if (isset($flignes[$i])){ |
|
| 432 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 433 | - $indexmesg = $flignes[$i][1]; |
|
| 434 | - $err = textebrut($flignes[$i][2]); |
|
| 435 | - // tentative de pointer sur la colonne fautive; |
|
| 436 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 437 | - // $m = $flignes[$i][0]; |
|
| 438 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 439 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 440 | - $bg = $formaterr; |
|
| 441 | - } else { |
|
| 442 | - $indexmesg = $ancre; |
|
| 443 | - $err = $bg = ''; |
|
| 444 | - } |
|
| 445 | - $res .= sprintf((($i%10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 446 | - $i++; |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - return "<div id='T$ancre'>" |
|
| 450 | - . '<div onclick="' |
|
| 451 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 452 | - . '" title="' |
|
| 453 | - . _T('masquer_colonne') |
|
| 454 | - . '" style="cursor: pointer;">' |
|
| 455 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 456 | - . "</div> |
|
| 399 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 400 | + if ($var_mode_ligne) $fautifs[] = array($var_mode_ligne); |
|
| 401 | + $res = ''; |
|
| 402 | + |
|
| 403 | + $s = highlight_string($texte, true); |
|
| 404 | + if (substr($s, 0, 6)=='<code>'){ |
|
| 405 | + $s = substr($s, 6); |
|
| 406 | + $res = '<code>'; |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 410 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 411 | + $s); |
|
| 412 | + |
|
| 413 | + |
|
| 414 | + $tableau = explode("<br />", $s); |
|
| 415 | + |
|
| 416 | + $format = "<span style='float:left;display:block;width:50px;height:1px'><a id='L%d' style='background-color: white; visibility: " . ($nocpt ? 'hidden' : 'visible') . ";%s' href='#T%s' title=\"%s\">%0" . strval(@strlen(count($tableau))) . "d</a></span> %s<br />\n"; |
|
| 417 | + |
|
| 418 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 419 | + $formaterr = "color: red;"; |
|
| 420 | + $i = 1; |
|
| 421 | + $flignes = array(); |
|
| 422 | + $loc = array(0, 0); |
|
| 423 | + foreach ($fautifs as $lc) |
|
| 424 | + if (is_array($lc)){ |
|
| 425 | + $l = array_shift($lc); |
|
| 426 | + $flignes[$l] = $lc; |
|
| 427 | + } else $flignes[$lc] = $loc; |
|
| 428 | + |
|
| 429 | + $ancre = md5($texte); |
|
| 430 | + foreach ($tableau as $ligne){ |
|
| 431 | + if (isset($flignes[$i])){ |
|
| 432 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 433 | + $indexmesg = $flignes[$i][1]; |
|
| 434 | + $err = textebrut($flignes[$i][2]); |
|
| 435 | + // tentative de pointer sur la colonne fautive; |
|
| 436 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 437 | + // $m = $flignes[$i][0]; |
|
| 438 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 439 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 440 | + $bg = $formaterr; |
|
| 441 | + } else { |
|
| 442 | + $indexmesg = $ancre; |
|
| 443 | + $err = $bg = ''; |
|
| 444 | + } |
|
| 445 | + $res .= sprintf((($i%10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 446 | + $i++; |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + return "<div id='T$ancre'>" |
|
| 450 | + . '<div onclick="' |
|
| 451 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 452 | + . '" title="' |
|
| 453 | + . _T('masquer_colonne') |
|
| 454 | + . '" style="cursor: pointer;">' |
|
| 455 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 456 | + . "</div> |
|
| 457 | 457 | " . $res . "</div>\n"; |
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | // l'environnement graphique du debuggueur |
| 461 | 461 | |
| 462 | 462 | function debusquer_squelette($fonc, $mode, $self){ |
| 463 | - global $debug_objets; |
|
| 464 | - |
|
| 465 | - if ($mode!=='validation'){ |
|
| 466 | - if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']){ |
|
| 467 | - $res = "<div id='spip-boucles'>\n" |
|
| 468 | - . debusquer_navigation_squelettes($self) |
|
| 469 | - . "</div>"; |
|
| 470 | - } |
|
| 471 | - else |
|
| 472 | - $res = ''; |
|
| 473 | - if ($fonc){ |
|
| 474 | - $id = " id='$fonc'"; |
|
| 475 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
|
| 476 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 477 | - $texte .= $res2; |
|
| 478 | - } |
|
| 479 | - elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | - $legend = _T('zbug_' . $mode); |
|
| 481 | - $texte = $debug_objets[$mode][$fonc . 'tout']; |
|
| 482 | - $texte = ancre_texte($texte, array('', '')); |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - else |
|
| 486 | - return strlen(trim($res)) |
|
| 487 | - ? "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>" |
|
| 488 | - // cas de l'appel sur erreur: montre la page |
|
| 489 | - : $GLOBALS['debug_objets']['resultat']['tout']; |
|
| 490 | - } |
|
| 491 | - else { |
|
| 492 | - $valider = charger_fonction('valider', 'xml'); |
|
| 493 | - $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
|
| 494 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 495 | - $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
|
| 496 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 497 | - if ($err===false) |
|
| 498 | - $err = _T('impossible'); |
|
| 499 | - elseif ($err===true) |
|
| 500 | - $err = _T('correcte'); |
|
| 501 | - else |
|
| 502 | - $err = ": $err"; |
|
| 503 | - $legend = _T('validation') . ' ' . $err; |
|
| 504 | - $res = $id = ''; |
|
| 505 | - } |
|
| 506 | - return !trim($texte) ? '' : ( |
|
| 507 | - "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 508 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 509 | - . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 510 | - . ($legend ? $legend : $mode) |
|
| 511 | - . "</a></legend>" |
|
| 512 | - . $texte |
|
| 513 | - . "</fieldset></div>" |
|
| 514 | - . "</div>"); |
|
| 463 | + global $debug_objets; |
|
| 464 | + |
|
| 465 | + if ($mode!=='validation'){ |
|
| 466 | + if (isset($debug_objets['sourcefile']) and $debug_objets['sourcefile']){ |
|
| 467 | + $res = "<div id='spip-boucles'>\n" |
|
| 468 | + . debusquer_navigation_squelettes($self) |
|
| 469 | + . "</div>"; |
|
| 470 | + } |
|
| 471 | + else |
|
| 472 | + $res = ''; |
|
| 473 | + if ($fonc){ |
|
| 474 | + $id = " id='$fonc'"; |
|
| 475 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])){ |
|
| 476 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 477 | + $texte .= $res2; |
|
| 478 | + } |
|
| 479 | + elseif (!empty($debug_objets[$mode][$fonc . 'tout'])) { |
|
| 480 | + $legend = _T('zbug_' . $mode); |
|
| 481 | + $texte = $debug_objets[$mode][$fonc . 'tout']; |
|
| 482 | + $texte = ancre_texte($texte, array('', '')); |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + else |
|
| 486 | + return strlen(trim($res)) |
|
| 487 | + ? "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res</div>" |
|
| 488 | + // cas de l'appel sur erreur: montre la page |
|
| 489 | + : $GLOBALS['debug_objets']['resultat']['tout']; |
|
| 490 | + } |
|
| 491 | + else { |
|
| 492 | + $valider = charger_fonction('valider', 'xml'); |
|
| 493 | + $val = $valider($debug_objets['validation'][$fonc . 'tout']); |
|
| 494 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 495 | + $debug_objets['validation'] = $val->err ? count($val->err) : ''; |
|
| 496 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 497 | + if ($err===false) |
|
| 498 | + $err = _T('impossible'); |
|
| 499 | + elseif ($err===true) |
|
| 500 | + $err = _T('correcte'); |
|
| 501 | + else |
|
| 502 | + $err = ": $err"; |
|
| 503 | + $legend = _T('validation') . ' ' . $err; |
|
| 504 | + $res = $id = ''; |
|
| 505 | + } |
|
| 506 | + return !trim($texte) ? '' : ( |
|
| 507 | + "<img src='".chemin_image('compat-16.png')."' alt='afficher-masquer le debug' id='spip-debug-toggle' onclick=\"var x = document.getElementById('spip-debug'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\" /><div id='spip-debug'>$res" |
|
| 508 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 509 | + . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 510 | + . ($legend ? $legend : $mode) |
|
| 511 | + . "</a></legend>" |
|
| 512 | + . $texte |
|
| 513 | + . "</fieldset></div>" |
|
| 514 | + . "</div>"); |
|
| 515 | 515 | } |
| 516 | 516 | |
| 517 | 517 | |
| 518 | 518 | // http://doc.spip.org/@emboite_texte |
| 519 | 519 | function emboite_texte($res, $fonc = '', $self = ''){ |
| 520 | - $errs = $res->err; |
|
| 521 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 522 | - |
|
| 523 | - if (!$texte and !$errs) |
|
| 524 | - return array(ancre_texte('', array('', '')), false); |
|
| 525 | - if (!$errs) |
|
| 526 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 527 | - |
|
| 528 | - if (!isset($GLOBALS['debug_objets'])){ |
|
| 529 | - |
|
| 530 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 531 | - $encore = count_occ($errs); |
|
| 532 | - $encore2 = array(); |
|
| 533 | - $fautifs = array(); |
|
| 534 | - |
|
| 535 | - $err = '<tr><th>' |
|
| 536 | - . _T('numero') |
|
| 537 | - . "</th><th>" |
|
| 538 | - . _T('occurence') |
|
| 539 | - . "</th><th>" |
|
| 540 | - . _T('ligne') |
|
| 541 | - . "</th><th>" |
|
| 542 | - . _T('colonne') |
|
| 543 | - . "</th><th>" |
|
| 544 | - . _T('erreur') |
|
| 545 | - . "</th></tr>"; |
|
| 546 | - |
|
| 547 | - $i = 0; |
|
| 548 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 549 | - foreach ($errs as $r){ |
|
| 550 | - $i++; |
|
| 551 | - list($msg, $ligne, $col) = $r; |
|
| 552 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 553 | - if (isset($encore2[$msg])) |
|
| 554 | - $ref = ++$encore2[$msg]; |
|
| 555 | - else { |
|
| 556 | - $encore2[$msg] = $ref = 1; |
|
| 557 | - } |
|
| 558 | - $err .= "<tr style='background-color: " |
|
| 559 | - . $colors[$i%2] |
|
| 560 | - . "'><td $style><a href='#debut_err'>" |
|
| 561 | - . $i |
|
| 562 | - . "</a></td><td $style>" |
|
| 563 | - . "$ref/$encore[$msg]</td>" |
|
| 564 | - . "<td $style><a href='#L" |
|
| 565 | - . $ligne |
|
| 566 | - . "' id='T$i'>" |
|
| 567 | - . $ligne |
|
| 568 | - . "</a></td><td $style>" |
|
| 569 | - . $col |
|
| 570 | - . "</td><td>$msg</td></tr>\n"; |
|
| 571 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 572 | - } |
|
| 573 | - $err = "<h2 style='text-align: center'>" |
|
| 574 | - . $i |
|
| 575 | - . "<a href='#fin_err'>" |
|
| 576 | - . " " . _T('erreur_texte') |
|
| 577 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 578 | - . $err |
|
| 579 | - . " </table><a id='fin_err'></a>"; |
|
| 580 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 581 | - } |
|
| 582 | - else { |
|
| 583 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 584 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 585 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 586 | - $err = $msg . |
|
| 587 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 588 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 589 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 590 | - } |
|
| 520 | + $errs = $res->err; |
|
| 521 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 522 | + |
|
| 523 | + if (!$texte and !$errs) |
|
| 524 | + return array(ancre_texte('', array('', '')), false); |
|
| 525 | + if (!$errs) |
|
| 526 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 527 | + |
|
| 528 | + if (!isset($GLOBALS['debug_objets'])){ |
|
| 529 | + |
|
| 530 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 531 | + $encore = count_occ($errs); |
|
| 532 | + $encore2 = array(); |
|
| 533 | + $fautifs = array(); |
|
| 534 | + |
|
| 535 | + $err = '<tr><th>' |
|
| 536 | + . _T('numero') |
|
| 537 | + . "</th><th>" |
|
| 538 | + . _T('occurence') |
|
| 539 | + . "</th><th>" |
|
| 540 | + . _T('ligne') |
|
| 541 | + . "</th><th>" |
|
| 542 | + . _T('colonne') |
|
| 543 | + . "</th><th>" |
|
| 544 | + . _T('erreur') |
|
| 545 | + . "</th></tr>"; |
|
| 546 | + |
|
| 547 | + $i = 0; |
|
| 548 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 549 | + foreach ($errs as $r){ |
|
| 550 | + $i++; |
|
| 551 | + list($msg, $ligne, $col) = $r; |
|
| 552 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 553 | + if (isset($encore2[$msg])) |
|
| 554 | + $ref = ++$encore2[$msg]; |
|
| 555 | + else { |
|
| 556 | + $encore2[$msg] = $ref = 1; |
|
| 557 | + } |
|
| 558 | + $err .= "<tr style='background-color: " |
|
| 559 | + . $colors[$i%2] |
|
| 560 | + . "'><td $style><a href='#debut_err'>" |
|
| 561 | + . $i |
|
| 562 | + . "</a></td><td $style>" |
|
| 563 | + . "$ref/$encore[$msg]</td>" |
|
| 564 | + . "<td $style><a href='#L" |
|
| 565 | + . $ligne |
|
| 566 | + . "' id='T$i'>" |
|
| 567 | + . $ligne |
|
| 568 | + . "</a></td><td $style>" |
|
| 569 | + . $col |
|
| 570 | + . "</td><td>$msg</td></tr>\n"; |
|
| 571 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 572 | + } |
|
| 573 | + $err = "<h2 style='text-align: center'>" |
|
| 574 | + . $i |
|
| 575 | + . "<a href='#fin_err'>" |
|
| 576 | + . " " . _T('erreur_texte') |
|
| 577 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 578 | + . $err |
|
| 579 | + . " </table><a id='fin_err'></a>"; |
|
| 580 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 581 | + } |
|
| 582 | + else { |
|
| 583 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 584 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 585 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 586 | + $err = $msg . |
|
| 587 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 588 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 589 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | // http://doc.spip.org/@count_occ |
| 594 | 594 | function count_occ($regs){ |
| 595 | - $encore = array(); |
|
| 596 | - foreach ($regs as $r){ |
|
| 597 | - if (isset($encore[$r[0]])) |
|
| 598 | - $encore[$r[0]]++; |
|
| 599 | - else |
|
| 600 | - $encore[$r[0]] = 1; |
|
| 601 | - } |
|
| 602 | - return $encore; |
|
| 595 | + $encore = array(); |
|
| 596 | + foreach ($regs as $r){ |
|
| 597 | + if (isset($encore[$r[0]])) |
|
| 598 | + $encore[$r[0]]++; |
|
| 599 | + else |
|
| 600 | + $encore[$r[0]] = 1; |
|
| 601 | + } |
|
| 602 | + return $encore; |
|
| 603 | 603 | } |
| 604 | 604 | |
| 605 | 605 | function debusquer_navigation_squelettes($self){ |
| 606 | - global $debug_objets, $spip_lang_right; |
|
| 607 | - |
|
| 608 | - $res = ''; |
|
| 609 | - $boucles = !empty($debug_objets['boucle']) ? $debug_objets['boucle'] : ''; |
|
| 610 | - $contexte = $debug_objets['contexte']; |
|
| 611 | - $t_skel = _T('squelette'); |
|
| 612 | - foreach ($debug_objets['sourcefile'] as $nom => $sourcefile){ |
|
| 613 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 614 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 615 | - $temps = !isset($debug_objets['profile'][$sourcefile]) ? '' : _T('zbug_profile', array('time' => $debug_objets['profile'][$sourcefile])); |
|
| 616 | - |
|
| 617 | - $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 618 | - . $t_skel |
|
| 619 | - . ' ' |
|
| 620 | - . $sourcefile |
|
| 621 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 622 | - . $t_skel |
|
| 623 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 624 | - . _T('zbug_resultat') |
|
| 625 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 626 | - . _T('zbug_code') |
|
| 627 | - . "</a>\n<a href='" |
|
| 628 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 629 | - . "'>" |
|
| 630 | - . _T('zbug_calcul') |
|
| 631 | - . "</a></legend>" |
|
| 632 | - . (!$temps ? '' : ("\n<span style='display:block;float:$spip_lang_right'>$temps</span><br />")) |
|
| 633 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 634 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 635 | - . "</fieldset>\n"; |
|
| 636 | - } |
|
| 637 | - return $res; |
|
| 606 | + global $debug_objets, $spip_lang_right; |
|
| 607 | + |
|
| 608 | + $res = ''; |
|
| 609 | + $boucles = !empty($debug_objets['boucle']) ? $debug_objets['boucle'] : ''; |
|
| 610 | + $contexte = $debug_objets['contexte']; |
|
| 611 | + $t_skel = _T('squelette'); |
|
| 612 | + foreach ($debug_objets['sourcefile'] as $nom => $sourcefile){ |
|
| 613 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 614 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 615 | + $temps = !isset($debug_objets['profile'][$sourcefile]) ? '' : _T('zbug_profile', array('time' => $debug_objets['profile'][$sourcefile])); |
|
| 616 | + |
|
| 617 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 618 | + . $t_skel |
|
| 619 | + . ' ' |
|
| 620 | + . $sourcefile |
|
| 621 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 622 | + . $t_skel |
|
| 623 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 624 | + . _T('zbug_resultat') |
|
| 625 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 626 | + . _T('zbug_code') |
|
| 627 | + . "</a>\n<a href='" |
|
| 628 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 629 | + . "'>" |
|
| 630 | + . _T('zbug_calcul') |
|
| 631 | + . "</a></legend>" |
|
| 632 | + . (!$temps ? '' : ("\n<span style='display:block;float:$spip_lang_right'>$temps</span><br />")) |
|
| 633 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 634 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 635 | + . "</fieldset>\n"; |
|
| 636 | + } |
|
| 637 | + return $res; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source){ |
| 641 | - $i = 0; |
|
| 642 | - $res = ''; |
|
| 643 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 644 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 645 | - |
|
| 646 | - foreach ($boucles as $objet => $boucle){ |
|
| 647 | - if (substr($objet, 0, strlen($nom_skel))==$nom_skel){ |
|
| 648 | - $i++; |
|
| 649 | - $nom = $boucle->id_boucle; |
|
| 650 | - $req = $boucle->type_requete; |
|
| 651 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 652 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 653 | - |
|
| 654 | - $res .= "\n<tr style='background-color: " . |
|
| 655 | - ($i%2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 656 | - "'><td align='right'>$i</td><td>\n" . |
|
| 657 | - "<a class='debug_link_boucle' href='" . |
|
| 658 | - $self2 . |
|
| 659 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 660 | - _T('zbug_boucle') . |
|
| 661 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 662 | - $self2 . |
|
| 663 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 664 | - _T('zbug_resultat') . |
|
| 665 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 666 | - $self2 . |
|
| 667 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 668 | - _T('zbug_code') . |
|
| 669 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 670 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 671 | - "'>" . |
|
| 672 | - _T('zbug_calcul') . |
|
| 673 | - "</a></td><td>\n" . |
|
| 674 | - (($var_mode_objet==$objet) ? "<b>$nom</b>" : $nom) . |
|
| 675 | - "</td><td>\n" . |
|
| 676 | - $req . |
|
| 677 | - "</td><td>\n" . |
|
| 678 | - spip_htmlspecialchars($crit) . |
|
| 679 | - "</td></tr>"; |
|
| 680 | - } |
|
| 681 | - } |
|
| 682 | - return $res; |
|
| 641 | + $i = 0; |
|
| 642 | + $res = ''; |
|
| 643 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 644 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 645 | + |
|
| 646 | + foreach ($boucles as $objet => $boucle){ |
|
| 647 | + if (substr($objet, 0, strlen($nom_skel))==$nom_skel){ |
|
| 648 | + $i++; |
|
| 649 | + $nom = $boucle->id_boucle; |
|
| 650 | + $req = $boucle->type_requete; |
|
| 651 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 652 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 653 | + |
|
| 654 | + $res .= "\n<tr style='background-color: " . |
|
| 655 | + ($i%2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 656 | + "'><td align='right'>$i</td><td>\n" . |
|
| 657 | + "<a class='debug_link_boucle' href='" . |
|
| 658 | + $self2 . |
|
| 659 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 660 | + _T('zbug_boucle') . |
|
| 661 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 662 | + $self2 . |
|
| 663 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 664 | + _T('zbug_resultat') . |
|
| 665 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 666 | + $self2 . |
|
| 667 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 668 | + _T('zbug_code') . |
|
| 669 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 670 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 671 | + "'>" . |
|
| 672 | + _T('zbug_calcul') . |
|
| 673 | + "</a></td><td>\n" . |
|
| 674 | + (($var_mode_objet==$objet) ? "<b>$nom</b>" : $nom) . |
|
| 675 | + "</td><td>\n" . |
|
| 676 | + $req . |
|
| 677 | + "</td><td>\n" . |
|
| 678 | + spip_htmlspecialchars($crit) . |
|
| 679 | + "</td></tr>"; |
|
| 680 | + } |
|
| 681 | + } |
|
| 682 | + return $res; |
|
| 683 | 683 | } |
| 684 | 684 | |
| 685 | 685 | function debusquer_source($objet, $affiche){ |
| 686 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 687 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 688 | - $res2 = ""; |
|
| 689 | - |
|
| 690 | - if ($affiche=='resultat'){ |
|
| 691 | - $legend = $nom; |
|
| 692 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 693 | - if (function_exists('traite_query')){ |
|
| 694 | - $c = strtolower(_request('connect')); |
|
| 695 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 696 | - $req = traite_query($req, '', $c); |
|
| 697 | - } |
|
| 698 | - // permettre le copier/coller facile |
|
| 699 | - // $res = ancre_texte($req, array(), true); |
|
| 700 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 701 | - // formatage et affichage des resultats bruts de la requete |
|
| 702 | - $ress_req = spip_query($req); |
|
| 703 | - $brut_sql = ''; |
|
| 704 | - $num = 1; |
|
| 705 | - // eviter l'affichage de milliers de lignes |
|
| 706 | - // personnalisation possible dans mes_options |
|
| 707 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 708 | - while ($retours_sql = sql_fetch($ress_req)){ |
|
| 709 | - if ($num<=$max_aff){ |
|
| 710 | - $brut_sql .= "<h3>" . ($num==1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 711 | - $brut_sql .= "<p>"; |
|
| 712 | - foreach ($retours_sql as $key => $val){ |
|
| 713 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 714 | - } |
|
| 715 | - $brut_sql .= "</p>"; |
|
| 716 | - } |
|
| 717 | - $num++; |
|
| 718 | - } |
|
| 719 | - $res2 = interdire_scripts($brut_sql); |
|
| 720 | - foreach ($quoi as $view){ |
|
| 721 | - // ne pas afficher les $contexte_inclus |
|
| 722 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 723 | - if ($view){ |
|
| 724 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 725 | - } |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - } |
|
| 729 | - elseif ($affiche=='code'){ |
|
| 730 | - $legend = $nom; |
|
| 731 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 732 | - } |
|
| 733 | - elseif ($affiche=='boucle'){ |
|
| 734 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 735 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 736 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 737 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 738 | - } |
|
| 739 | - elseif ($affiche=='squelette'){ |
|
| 740 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 741 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 742 | - } |
|
| 743 | - |
|
| 744 | - return array($legend, $res, $res2); |
|
| 686 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 687 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 688 | + $res2 = ""; |
|
| 689 | + |
|
| 690 | + if ($affiche=='resultat'){ |
|
| 691 | + $legend = $nom; |
|
| 692 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 693 | + if (function_exists('traite_query')){ |
|
| 694 | + $c = strtolower(_request('connect')); |
|
| 695 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 696 | + $req = traite_query($req, '', $c); |
|
| 697 | + } |
|
| 698 | + // permettre le copier/coller facile |
|
| 699 | + // $res = ancre_texte($req, array(), true); |
|
| 700 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 701 | + // formatage et affichage des resultats bruts de la requete |
|
| 702 | + $ress_req = spip_query($req); |
|
| 703 | + $brut_sql = ''; |
|
| 704 | + $num = 1; |
|
| 705 | + // eviter l'affichage de milliers de lignes |
|
| 706 | + // personnalisation possible dans mes_options |
|
| 707 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 708 | + while ($retours_sql = sql_fetch($ress_req)){ |
|
| 709 | + if ($num<=$max_aff){ |
|
| 710 | + $brut_sql .= "<h3>" . ($num==1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 711 | + $brut_sql .= "<p>"; |
|
| 712 | + foreach ($retours_sql as $key => $val){ |
|
| 713 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 714 | + } |
|
| 715 | + $brut_sql .= "</p>"; |
|
| 716 | + } |
|
| 717 | + $num++; |
|
| 718 | + } |
|
| 719 | + $res2 = interdire_scripts($brut_sql); |
|
| 720 | + foreach ($quoi as $view){ |
|
| 721 | + // ne pas afficher les $contexte_inclus |
|
| 722 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 723 | + if ($view){ |
|
| 724 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 725 | + } |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + } |
|
| 729 | + elseif ($affiche=='code'){ |
|
| 730 | + $legend = $nom; |
|
| 731 | + $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 732 | + } |
|
| 733 | + elseif ($affiche=='boucle'){ |
|
| 734 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 735 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 736 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 737 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 738 | + } |
|
| 739 | + elseif ($affiche=='squelette'){ |
|
| 740 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 741 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 742 | + } |
|
| 743 | + |
|
| 744 | + return array($legend, $res, $res2); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | // http://doc.spip.org/@debusquer_entete |
| 748 | 748 | function debusquer_entete($titre, $corps){ |
| 749 | - global $debug_objets; |
|
| 750 | - include_spip('balise/formulaire_admin'); |
|
| 751 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 752 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 753 | - |
|
| 754 | - return _DOCTYPE_ECRIRE . |
|
| 755 | - html_lang_attributes() . |
|
| 756 | - "<head>\n<title>" . |
|
| 757 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 758 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 759 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 760 | - ")</title>\n" . |
|
| 761 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 762 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 763 | - "' />\n" . |
|
| 764 | - http_script('', 'jquery.js') |
|
| 765 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 766 | - . "' type='text/css' />" . |
|
| 767 | - "</head>\n" . |
|
| 768 | - "<body style='margin:0 10px;'>\n" . |
|
| 769 | - "<div id='spip-debug-header'>" . |
|
| 770 | - $corps . |
|
| 771 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false) . |
|
| 772 | - '</div></body></html>'; |
|
| 749 | + global $debug_objets; |
|
| 750 | + include_spip('balise/formulaire_admin'); |
|
| 751 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 752 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 753 | + |
|
| 754 | + return _DOCTYPE_ECRIRE . |
|
| 755 | + html_lang_attributes() . |
|
| 756 | + "<head>\n<title>" . |
|
| 757 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 758 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 759 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 760 | + ")</title>\n" . |
|
| 761 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 762 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 763 | + "' />\n" . |
|
| 764 | + http_script('', 'jquery.js') |
|
| 765 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 766 | + . "' type='text/css' />" . |
|
| 767 | + "</head>\n" . |
|
| 768 | + "<body style='margin:0 10px;'>\n" . |
|
| 769 | + "<div id='spip-debug-header'>" . |
|
| 770 | + $corps . |
|
| 771 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $debug_objets), false) . |
|
| 772 | + '</div></body></html>'; |
|
| 773 | 773 | } |
| 774 | 774 | |
| 775 | 775 | ?> |
@@ -13,127 +13,127 @@ discard block |
||
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) return; |
| 14 | 14 | |
| 15 | 15 | function securiser_redirect_action($redirect) { |
| 16 | - if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 17 | - and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 18 | - // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 19 | - // c'est encore le plus simple |
|
| 20 | - $base = $GLOBALS['meta']['adresse_site']."/"; |
|
| 21 | - if (strlen($base) AND strncmp($redirect,$base,strlen($base))==0) |
|
| 22 | - return $redirect; |
|
| 23 | - $base = url_de_base(); |
|
| 24 | - if (strlen($base) AND strncmp($redirect,$base,strlen($base))==0) |
|
| 25 | - return $redirect; |
|
| 26 | - return ""; |
|
| 27 | - } |
|
| 28 | - return $redirect; |
|
| 16 | + if ((tester_url_absolue($redirect) or preg_match(',^\w+:,',trim($redirect))) |
|
| 17 | + and !defined('_AUTORISER_ACTION_ABS_REDIRECT')) { |
|
| 18 | + // si l'url est une url du site, on la laisse passer sans rien faire |
|
| 19 | + // c'est encore le plus simple |
|
| 20 | + $base = $GLOBALS['meta']['adresse_site']."/"; |
|
| 21 | + if (strlen($base) AND strncmp($redirect,$base,strlen($base))==0) |
|
| 22 | + return $redirect; |
|
| 23 | + $base = url_de_base(); |
|
| 24 | + if (strlen($base) AND strncmp($redirect,$base,strlen($base))==0) |
|
| 25 | + return $redirect; |
|
| 26 | + return ""; |
|
| 27 | + } |
|
| 28 | + return $redirect; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | // http://doc.spip.org/@traiter_appels_actions |
| 32 | 32 | function traiter_appels_actions(){ |
| 33 | - // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 34 | - if ($action = _request('action')) { |
|
| 35 | - include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 36 | - include_spip('inc/autoriser'); |
|
| 37 | - include_spip('inc/headers'); |
|
| 38 | - include_spip('inc/actions'); |
|
| 39 | - // des actions peuvent appeler _T |
|
| 40 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 41 | - include_spip('inc/lang'); |
|
| 42 | - utiliser_langue_visiteur(); |
|
| 43 | - } |
|
| 44 | - // si l'action est provoque par un hit {ajax} |
|
| 45 | - // il faut transmettre l'env ajax au redirect |
|
| 46 | - // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 47 | - if (($v=_request('var_ajax')) |
|
| 48 | - AND ($v!=='form') |
|
| 49 | - AND ($args = _request('var_ajax_env')) |
|
| 50 | - AND ($url = _request('redirect'))){ |
|
| 51 | - $url = parametre_url($url,'var_ajax',$v,'&'); |
|
| 52 | - $url = parametre_url($url,'var_ajax_env',$args,'&'); |
|
| 53 | - set_request('redirect',$url); |
|
| 54 | - } |
|
| 55 | - else if(_request('redirect')){ |
|
| 56 | - set_request('redirect',securiser_redirect_action(_request('redirect'))); |
|
| 57 | - } |
|
| 58 | - $var_f = charger_fonction($action, 'action'); |
|
| 59 | - $var_f(); |
|
| 60 | - if (!isset($GLOBALS['redirect'])) { |
|
| 61 | - $GLOBALS['redirect'] = _request('redirect'); |
|
| 62 | - if ($_SERVER['REQUEST_METHOD'] == 'POST') |
|
| 63 | - $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 64 | - $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 65 | - } |
|
| 66 | - if ($url = $GLOBALS['redirect']) { |
|
| 67 | - // si l'action est provoque par un hit {ajax} |
|
| 68 | - // il faut transmettre l'env ajax au redirect |
|
| 69 | - // qui a pu etre defini par l'action |
|
| 70 | - if (($v=_request('var_ajax')) |
|
| 71 | - AND ($v!=='form') |
|
| 72 | - AND ($args = _request('var_ajax_env'))) { |
|
| 73 | - $url = parametre_url($url,'var_ajax',$v,'&'); |
|
| 74 | - $url = parametre_url($url,'var_ajax_env',$args,'&'); |
|
| 75 | - // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 76 | - $url = preg_replace(',#([^#&?]+)$,',"&var_ajax_ancre=\\1",$url); |
|
| 77 | - } |
|
| 78 | - $url = str_replace('&','&',$url); // les redirections se font en &, pas en en & |
|
| 79 | - redirige_par_entete($url); |
|
| 80 | - } |
|
| 81 | - if (!headers_sent() |
|
| 82 | - AND !ob_get_length()) |
|
| 83 | - http_status(204); // No Content |
|
| 84 | - return true; |
|
| 85 | - } |
|
| 86 | - return false; |
|
| 33 | + // cas de l'appel qui renvoie une redirection (302) ou rien (204) |
|
| 34 | + if ($action = _request('action')) { |
|
| 35 | + include_spip('base/abstract_sql'); // chargement systematique pour les actions |
|
| 36 | + include_spip('inc/autoriser'); |
|
| 37 | + include_spip('inc/headers'); |
|
| 38 | + include_spip('inc/actions'); |
|
| 39 | + // des actions peuvent appeler _T |
|
| 40 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 41 | + include_spip('inc/lang'); |
|
| 42 | + utiliser_langue_visiteur(); |
|
| 43 | + } |
|
| 44 | + // si l'action est provoque par un hit {ajax} |
|
| 45 | + // il faut transmettre l'env ajax au redirect |
|
| 46 | + // on le met avant dans la query string au cas ou l'action fait elle meme sa redirection |
|
| 47 | + if (($v=_request('var_ajax')) |
|
| 48 | + AND ($v!=='form') |
|
| 49 | + AND ($args = _request('var_ajax_env')) |
|
| 50 | + AND ($url = _request('redirect'))){ |
|
| 51 | + $url = parametre_url($url,'var_ajax',$v,'&'); |
|
| 52 | + $url = parametre_url($url,'var_ajax_env',$args,'&'); |
|
| 53 | + set_request('redirect',$url); |
|
| 54 | + } |
|
| 55 | + else if(_request('redirect')){ |
|
| 56 | + set_request('redirect',securiser_redirect_action(_request('redirect'))); |
|
| 57 | + } |
|
| 58 | + $var_f = charger_fonction($action, 'action'); |
|
| 59 | + $var_f(); |
|
| 60 | + if (!isset($GLOBALS['redirect'])) { |
|
| 61 | + $GLOBALS['redirect'] = _request('redirect'); |
|
| 62 | + if ($_SERVER['REQUEST_METHOD'] == 'POST') |
|
| 63 | + $GLOBALS['redirect'] = urldecode($GLOBALS['redirect']); |
|
| 64 | + $GLOBALS['redirect'] = securiser_redirect_action($GLOBALS['redirect']); |
|
| 65 | + } |
|
| 66 | + if ($url = $GLOBALS['redirect']) { |
|
| 67 | + // si l'action est provoque par un hit {ajax} |
|
| 68 | + // il faut transmettre l'env ajax au redirect |
|
| 69 | + // qui a pu etre defini par l'action |
|
| 70 | + if (($v=_request('var_ajax')) |
|
| 71 | + AND ($v!=='form') |
|
| 72 | + AND ($args = _request('var_ajax_env'))) { |
|
| 73 | + $url = parametre_url($url,'var_ajax',$v,'&'); |
|
| 74 | + $url = parametre_url($url,'var_ajax_env',$args,'&'); |
|
| 75 | + // passer l'ancre en variable pour pouvoir la gerer cote serveur |
|
| 76 | + $url = preg_replace(',#([^#&?]+)$,',"&var_ajax_ancre=\\1",$url); |
|
| 77 | + } |
|
| 78 | + $url = str_replace('&','&',$url); // les redirections se font en &, pas en en & |
|
| 79 | + redirige_par_entete($url); |
|
| 80 | + } |
|
| 81 | + if (!headers_sent() |
|
| 82 | + AND !ob_get_length()) |
|
| 83 | + http_status(204); // No Content |
|
| 84 | + return true; |
|
| 85 | + } |
|
| 86 | + return false; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | |
| 90 | 90 | // http://doc.spip.org/@refuser_traiter_formulaire_ajax |
| 91 | 91 | function refuser_traiter_formulaire_ajax(){ |
| 92 | - if ($v=_request('var_ajax') |
|
| 93 | - AND $v=='form' |
|
| 94 | - AND $form = _request('formulaire_action') |
|
| 95 | - AND $args = _request('formulaire_action_args') |
|
| 96 | - AND decoder_contexte_ajax($args,$form)!==false) { |
|
| 97 | - // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 98 | - // mais traiter ne veut pas |
|
| 99 | - // on le dit a la page qui va resumbit |
|
| 100 | - // sans ajax |
|
| 101 | - include_spip('inc/actions'); |
|
| 102 | - ajax_retour('noajax',false); |
|
| 103 | - exit; |
|
| 104 | - } |
|
| 92 | + if ($v=_request('var_ajax') |
|
| 93 | + AND $v=='form' |
|
| 94 | + AND $form = _request('formulaire_action') |
|
| 95 | + AND $args = _request('formulaire_action_args') |
|
| 96 | + AND decoder_contexte_ajax($args,$form)!==false) { |
|
| 97 | + // on est bien dans le contexte de traitement d'un formulaire en ajax |
|
| 98 | + // mais traiter ne veut pas |
|
| 99 | + // on le dit a la page qui va resumbit |
|
| 100 | + // sans ajax |
|
| 101 | + include_spip('inc/actions'); |
|
| 102 | + ajax_retour('noajax',false); |
|
| 103 | + exit; |
|
| 104 | + } |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | // http://doc.spip.org/@traiter_appels_inclusions_ajax |
| 108 | 108 | function traiter_appels_inclusions_ajax(){ |
| 109 | - // traiter les appels de bloc ajax (ex: pagination) |
|
| 110 | - if ($v = _request('var_ajax') |
|
| 111 | - AND $v !== 'form' |
|
| 112 | - AND $args = _request('var_ajax_env')) { |
|
| 113 | - include_spip('inc/filtres'); |
|
| 114 | - include_spip('inc/actions'); |
|
| 115 | - if ($args = decoder_contexte_ajax($args) |
|
| 116 | - AND $fond = $args['fond']) { |
|
| 117 | - include_spip('public/assembler'); |
|
| 118 | - $contexte = calculer_contexte(); |
|
| 119 | - $contexte = array_merge($args, $contexte); |
|
| 120 | - $page = recuperer_fond($fond,$contexte,array('trim'=>false)); |
|
| 121 | - $texte = $page; |
|
| 122 | - if ($ancre = _request('var_ajax_ancre')){ |
|
| 123 | - // pas n'importe quoi quand meme dans la variable ! |
|
| 124 | - $ancre = str_replace(array('<','"',"'"),array('<','"',''),$ancre); |
|
| 125 | - $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>".$texte; |
|
| 126 | - } |
|
| 127 | - } |
|
| 128 | - else { |
|
| 129 | - include_spip('inc/headers'); |
|
| 130 | - http_status(403); |
|
| 131 | - $texte = _L('signature ajax bloc incorrecte'); |
|
| 132 | - } |
|
| 133 | - ajax_retour($texte, false); |
|
| 134 | - return true; // on a fini le hit |
|
| 135 | - } |
|
| 136 | - return false; |
|
| 109 | + // traiter les appels de bloc ajax (ex: pagination) |
|
| 110 | + if ($v = _request('var_ajax') |
|
| 111 | + AND $v !== 'form' |
|
| 112 | + AND $args = _request('var_ajax_env')) { |
|
| 113 | + include_spip('inc/filtres'); |
|
| 114 | + include_spip('inc/actions'); |
|
| 115 | + if ($args = decoder_contexte_ajax($args) |
|
| 116 | + AND $fond = $args['fond']) { |
|
| 117 | + include_spip('public/assembler'); |
|
| 118 | + $contexte = calculer_contexte(); |
|
| 119 | + $contexte = array_merge($args, $contexte); |
|
| 120 | + $page = recuperer_fond($fond,$contexte,array('trim'=>false)); |
|
| 121 | + $texte = $page; |
|
| 122 | + if ($ancre = _request('var_ajax_ancre')){ |
|
| 123 | + // pas n'importe quoi quand meme dans la variable ! |
|
| 124 | + $ancre = str_replace(array('<','"',"'"),array('<','"',''),$ancre); |
|
| 125 | + $texte = "<a href='#$ancre' name='ajax_ancre' style='display:none;'>anchor</a>".$texte; |
|
| 126 | + } |
|
| 127 | + } |
|
| 128 | + else { |
|
| 129 | + include_spip('inc/headers'); |
|
| 130 | + http_status(403); |
|
| 131 | + $texte = _L('signature ajax bloc incorrecte'); |
|
| 132 | + } |
|
| 133 | + ajax_retour($texte, false); |
|
| 134 | + return true; // on a fini le hit |
|
| 135 | + } |
|
| 136 | + return false; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | // au 1er appel, traite les formulaires dynamiques charger/verifier/traiter |
@@ -142,119 +142,119 @@ discard block |
||
| 142 | 142 | |
| 143 | 143 | // http://doc.spip.org/@traiter_formulaires_dynamiques |
| 144 | 144 | function traiter_formulaires_dynamiques($get=false){ |
| 145 | - static $post = array(); |
|
| 146 | - static $done = false; |
|
| 145 | + static $post = array(); |
|
| 146 | + static $done = false; |
|
| 147 | 147 | |
| 148 | - if ($get) return $post; |
|
| 149 | - if ($done) return false; |
|
| 150 | - $done = true; |
|
| 148 | + if ($get) return $post; |
|
| 149 | + if ($done) return false; |
|
| 150 | + $done = true; |
|
| 151 | 151 | |
| 152 | - if (!($form = _request('formulaire_action') |
|
| 153 | - AND $args = _request('formulaire_action_args'))) |
|
| 154 | - return false; // le hit peut continuer normalement |
|
| 152 | + if (!($form = _request('formulaire_action') |
|
| 153 | + AND $args = _request('formulaire_action_args'))) |
|
| 154 | + return false; // le hit peut continuer normalement |
|
| 155 | 155 | |
| 156 | - include_spip('inc/filtres'); |
|
| 157 | - if (($args = decoder_contexte_ajax($args,$form))===false) { |
|
| 158 | - spip_log("signature ajax form incorrecte : $form"); |
|
| 159 | - return false; // continuons le hit comme si de rien etait |
|
| 160 | - } else { |
|
| 161 | - include_spip('inc/lang'); |
|
| 162 | - // sauvegarder la lang en cours |
|
| 163 | - $old_lang = $GLOBALS['spip_lang']; |
|
| 164 | - // changer la langue avec celle qui a cours dans le formulaire |
|
| 165 | - // on la depile de $args car c'est un argument implicite masque |
|
| 166 | - changer_langue(array_shift($args)); |
|
| 156 | + include_spip('inc/filtres'); |
|
| 157 | + if (($args = decoder_contexte_ajax($args,$form))===false) { |
|
| 158 | + spip_log("signature ajax form incorrecte : $form"); |
|
| 159 | + return false; // continuons le hit comme si de rien etait |
|
| 160 | + } else { |
|
| 161 | + include_spip('inc/lang'); |
|
| 162 | + // sauvegarder la lang en cours |
|
| 163 | + $old_lang = $GLOBALS['spip_lang']; |
|
| 164 | + // changer la langue avec celle qui a cours dans le formulaire |
|
| 165 | + // on la depile de $args car c'est un argument implicite masque |
|
| 166 | + changer_langue(array_shift($args)); |
|
| 167 | 167 | |
| 168 | 168 | |
| 169 | - // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 170 | - include_spip('public/parametrer'); |
|
| 171 | - $verifier = charger_fonction("verifier","formulaires/$form/",true); |
|
| 172 | - $post["erreurs_$form"] = pipeline( |
|
| 173 | - 'formulaire_verifier', |
|
| 174 | - array( |
|
| 175 | - 'args'=>array('form'=>$form,'args'=>$args), |
|
| 176 | - 'data'=>$verifier?call_user_func_array($verifier,$args):array()) |
|
| 177 | - ); |
|
| 178 | - // si on ne demandait qu'une verif json |
|
| 179 | - if (_request('formulaire_action_verifier_json')){ |
|
| 180 | - include_spip('inc/json'); |
|
| 181 | - include_spip('inc/actions'); |
|
| 182 | - ajax_retour(json_encode($post["erreurs_$form"]),'text/plain'); |
|
| 183 | - return true; // on a fini le hit |
|
| 184 | - } |
|
| 185 | - $retour = ""; |
|
| 186 | - if ((count($post["erreurs_$form"])==0)){ |
|
| 187 | - $rev = ""; |
|
| 188 | - if ($traiter = charger_fonction("traiter","formulaires/$form/",true)) |
|
| 189 | - $rev = call_user_func_array($traiter,$args); |
|
| 169 | + // inclure mes_fonctions et autres filtres avant verifier/traiter |
|
| 170 | + include_spip('public/parametrer'); |
|
| 171 | + $verifier = charger_fonction("verifier","formulaires/$form/",true); |
|
| 172 | + $post["erreurs_$form"] = pipeline( |
|
| 173 | + 'formulaire_verifier', |
|
| 174 | + array( |
|
| 175 | + 'args'=>array('form'=>$form,'args'=>$args), |
|
| 176 | + 'data'=>$verifier?call_user_func_array($verifier,$args):array()) |
|
| 177 | + ); |
|
| 178 | + // si on ne demandait qu'une verif json |
|
| 179 | + if (_request('formulaire_action_verifier_json')){ |
|
| 180 | + include_spip('inc/json'); |
|
| 181 | + include_spip('inc/actions'); |
|
| 182 | + ajax_retour(json_encode($post["erreurs_$form"]),'text/plain'); |
|
| 183 | + return true; // on a fini le hit |
|
| 184 | + } |
|
| 185 | + $retour = ""; |
|
| 186 | + if ((count($post["erreurs_$form"])==0)){ |
|
| 187 | + $rev = ""; |
|
| 188 | + if ($traiter = charger_fonction("traiter","formulaires/$form/",true)) |
|
| 189 | + $rev = call_user_func_array($traiter,$args); |
|
| 190 | 190 | |
| 191 | - $rev = pipeline( |
|
| 192 | - 'formulaire_traiter', |
|
| 193 | - array( |
|
| 194 | - 'args'=>array('form'=>$form,'args'=>$args), |
|
| 195 | - 'data'=>$rev) |
|
| 196 | - ); |
|
| 197 | - // le retour de traiter peut avoir 3 formats |
|
| 198 | - // - simple message texte |
|
| 199 | - // - tableau a deux entrees ($editable,$message) |
|
| 200 | - // - tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 201 | - // le dernier format est celui conseille car il permet le pipelinage, en particulier |
|
| 202 | - // en y passant l'id de l'objet cree/modifie |
|
| 203 | - // si message_erreur est present, on considere que le traitement a echoue |
|
| 204 | - // cas du message texte simple |
|
| 205 | - if (!is_array($rev)){ |
|
| 206 | - $post["message_ok_$form"] = $rev; |
|
| 207 | - } |
|
| 208 | - // cas du tableau deux valeurs simple (ancien format, deconseille) |
|
| 209 | - elseif (count($rev)==2 |
|
| 210 | - AND !array_key_exists('message_ok',$rev) |
|
| 211 | - AND !array_key_exists('message_erreur',$rev) |
|
| 212 | - AND !array_key_exists('redirect',$rev)) { |
|
| 213 | - $post["editable_$form"] = reset($rev); |
|
| 214 | - $post["message_ok_$form"] = end($rev); |
|
| 215 | - } |
|
| 216 | - // cas du tableau explicite (conseille) |
|
| 217 | - else { |
|
| 218 | - // verifier si traiter n'a pas echoue avec une erreur : |
|
| 219 | - if (isset($rev['message_erreur'])) { |
|
| 220 | - $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 191 | + $rev = pipeline( |
|
| 192 | + 'formulaire_traiter', |
|
| 193 | + array( |
|
| 194 | + 'args'=>array('form'=>$form,'args'=>$args), |
|
| 195 | + 'data'=>$rev) |
|
| 196 | + ); |
|
| 197 | + // le retour de traiter peut avoir 3 formats |
|
| 198 | + // - simple message texte |
|
| 199 | + // - tableau a deux entrees ($editable,$message) |
|
| 200 | + // - tableau explicite ('editable'=>$editable,'message_ok'=>$message,'redirect'=>$redirect,'id_xx'=>$id_xx) |
|
| 201 | + // le dernier format est celui conseille car il permet le pipelinage, en particulier |
|
| 202 | + // en y passant l'id de l'objet cree/modifie |
|
| 203 | + // si message_erreur est present, on considere que le traitement a echoue |
|
| 204 | + // cas du message texte simple |
|
| 205 | + if (!is_array($rev)){ |
|
| 206 | + $post["message_ok_$form"] = $rev; |
|
| 207 | + } |
|
| 208 | + // cas du tableau deux valeurs simple (ancien format, deconseille) |
|
| 209 | + elseif (count($rev)==2 |
|
| 210 | + AND !array_key_exists('message_ok',$rev) |
|
| 211 | + AND !array_key_exists('message_erreur',$rev) |
|
| 212 | + AND !array_key_exists('redirect',$rev)) { |
|
| 213 | + $post["editable_$form"] = reset($rev); |
|
| 214 | + $post["message_ok_$form"] = end($rev); |
|
| 215 | + } |
|
| 216 | + // cas du tableau explicite (conseille) |
|
| 217 | + else { |
|
| 218 | + // verifier si traiter n'a pas echoue avec une erreur : |
|
| 219 | + if (isset($rev['message_erreur'])) { |
|
| 220 | + $post["erreurs_$form"]["message_erreur"] = $rev['message_erreur']; |
|
| 221 | 221 | |
| 222 | - } |
|
| 223 | - else { |
|
| 224 | - // sinon faire ce qu'il faut : |
|
| 225 | - if (isset($rev['message_ok'])) |
|
| 226 | - $post["message_ok_$form"] = $rev['message_ok']; |
|
| 227 | - if (isset($rev['editable'])) |
|
| 228 | - $post["editable_$form"] = $rev['editable']; |
|
| 229 | - // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 230 | - // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 231 | - if (isset($rev['redirect']) AND $rev['redirect']){ |
|
| 232 | - include_spip('inc/headers'); |
|
| 233 | - list($masque,$message) = redirige_formulaire($rev['redirect'], '','ajaxform'); |
|
| 234 | - $post["message_ok_$form"] .= $message; |
|
| 235 | - $retour .= $masque; |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - } |
|
| 239 | - } |
|
| 240 | - // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 241 | - if (_request('var_ajax')){ |
|
| 242 | - if (find_in_path('formulaire_.php','balise/',true)) { |
|
| 243 | - include_spip('inc/actions'); |
|
| 244 | - include_spip('public/assembler'); |
|
| 245 | - array_unshift($args,$form); |
|
| 246 | - $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn',$args),false); |
|
| 247 | - // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 248 | - // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 249 | - $retour = "<br class='bugajaxie' style='display:none;'/>".$retour; |
|
| 250 | - ajax_retour($retour,false); |
|
| 251 | - return true; // on a fini le hit |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - // restaurer la lang en cours |
|
| 255 | - changer_langue($old_lang); |
|
| 256 | - } |
|
| 257 | - return false; // le hit peut continuer normalement |
|
| 222 | + } |
|
| 223 | + else { |
|
| 224 | + // sinon faire ce qu'il faut : |
|
| 225 | + if (isset($rev['message_ok'])) |
|
| 226 | + $post["message_ok_$form"] = $rev['message_ok']; |
|
| 227 | + if (isset($rev['editable'])) |
|
| 228 | + $post["editable_$form"] = $rev['editable']; |
|
| 229 | + // si une redirection est demandee, appeler redirigae_formulaire qui choisira |
|
| 230 | + // le bon mode de redirection (302 et on ne revient pas ici, ou javascript et on continue) |
|
| 231 | + if (isset($rev['redirect']) AND $rev['redirect']){ |
|
| 232 | + include_spip('inc/headers'); |
|
| 233 | + list($masque,$message) = redirige_formulaire($rev['redirect'], '','ajaxform'); |
|
| 234 | + $post["message_ok_$form"] .= $message; |
|
| 235 | + $retour .= $masque; |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + } |
|
| 239 | + } |
|
| 240 | + // si le formulaire a ete soumis en ajax, on le renvoie direct ! |
|
| 241 | + if (_request('var_ajax')){ |
|
| 242 | + if (find_in_path('formulaire_.php','balise/',true)) { |
|
| 243 | + include_spip('inc/actions'); |
|
| 244 | + include_spip('public/assembler'); |
|
| 245 | + array_unshift($args,$form); |
|
| 246 | + $retour .= inclure_balise_dynamique(call_user_func_array('balise_formulaire__dyn',$args),false); |
|
| 247 | + // on ajoute un br en display none en tete du retour ajax pour regler un bug dans IE6/7 |
|
| 248 | + // sans cela le formulaire n'est pas actif apres le hit ajax |
|
| 249 | + $retour = "<br class='bugajaxie' style='display:none;'/>".$retour; |
|
| 250 | + ajax_retour($retour,false); |
|
| 251 | + return true; // on a fini le hit |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + // restaurer la lang en cours |
|
| 255 | + changer_langue($old_lang); |
|
| 256 | + } |
|
| 257 | + return false; // le hit peut continuer normalement |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | ?> |
@@ -26,8 +26,8 @@ discard block |
||
| 26 | 26 | * @return string |
| 27 | 27 | */ |
| 28 | 28 | function sandbox_composer_texte($texte, &$p){ |
| 29 | - $code = "'".str_replace(array("\\","'"),array("\\\\","\\'"), $texte)."'"; |
|
| 30 | - return $code; |
|
| 29 | + $code = "'".str_replace(array("\\","'"),array("\\\\","\\'"), $texte)."'"; |
|
| 30 | + return $code; |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | |
@@ -41,33 +41,33 @@ discard block |
||
| 41 | 41 | * @return string |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p){ |
| 44 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 45 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 46 | - } |
|
| 47 | - |
|
| 48 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 49 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 50 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 51 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 52 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 53 | - if (strpbrk($f, ':')) { // Class::method |
|
| 54 | - $refl = new ReflectionMethod($f); |
|
| 55 | - } else { |
|
| 56 | - $refl = new ReflectionFunction($f); |
|
| 57 | - } |
|
| 58 | - $refs = $refl->getParameters(); |
|
| 59 | - if (isset($refs[0]) AND $refs[0]->name == 'Pile') { |
|
| 60 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 61 | - } |
|
| 62 | - else { |
|
| 63 | - $code = "$f($code$arglist)"; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - // le filtre n'existe pas, |
|
| 67 | - // on le notifie |
|
| 68 | - else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 69 | - |
|
| 70 | - return $code; |
|
| 44 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 45 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 46 | + } |
|
| 47 | + |
|
| 48 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 49 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 50 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 51 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 52 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 53 | + if (strpbrk($f, ':')) { // Class::method |
|
| 54 | + $refl = new ReflectionMethod($f); |
|
| 55 | + } else { |
|
| 56 | + $refl = new ReflectionFunction($f); |
|
| 57 | + } |
|
| 58 | + $refs = $refl->getParameters(); |
|
| 59 | + if (isset($refs[0]) AND $refs[0]->name == 'Pile') { |
|
| 60 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 61 | + } |
|
| 62 | + else { |
|
| 63 | + $code = "$f($code$arglist)"; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + // le filtre n'existe pas, |
|
| 67 | + // on le notifie |
|
| 68 | + else erreur_squelette(array('zbug_erreur_filtre', array('filtre'=> texte_script($fonc))), $p); |
|
| 69 | + |
|
| 70 | + return $code; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // Calculer un <INCLURE(xx.php)> |
@@ -90,13 +90,13 @@ discard block |
||
| 90 | 90 | * @return string |
| 91 | 91 | */ |
| 92 | 92 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte){ |
| 93 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 94 | - // si inexistant, on essaiera a l'execution |
|
| 95 | - if ($path = find_in_path($fichier)) |
|
| 96 | - $path = "\"$path\""; |
|
| 97 | - else $path = "find_in_path(\"$fichier\")"; |
|
| 93 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 94 | + // si inexistant, on essaiera a l'execution |
|
| 95 | + if ($path = find_in_path($fichier)) |
|
| 96 | + $path = "\"$path\""; |
|
| 97 | + else $path = "find_in_path(\"$fichier\")"; |
|
| 98 | 98 | |
| 99 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 99 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -107,17 +107,17 @@ discard block |
||
| 107 | 107 | * @return string |
| 108 | 108 | */ |
| 109 | 109 | function sandbox_composer_interdire_scripts($code, &$p){ |
| 110 | - // Securite |
|
| 111 | - if ($p->interdire_scripts |
|
| 112 | - AND $p->etoile != '**') { |
|
| 113 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) |
|
| 114 | - $code = "interdire_scripts($code)"; |
|
| 115 | - else { |
|
| 116 | - $code = interdire_scripts($r[2]); |
|
| 117 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - return $code; |
|
| 110 | + // Securite |
|
| 111 | + if ($p->interdire_scripts |
|
| 112 | + AND $p->etoile != '**') { |
|
| 113 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) |
|
| 114 | + $code = "interdire_scripts($code)"; |
|
| 115 | + else { |
|
| 116 | + $code = interdire_scripts($r[2]); |
|
| 117 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + return $code; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -133,45 +133,45 @@ discard block |
||
| 133 | 133 | * @return mixed|string |
| 134 | 134 | */ |
| 135 | 135 | function sandbox_filtrer_squelette($skel, $corps, $filtres){ |
| 136 | - $series_filtres = func_get_args(); |
|
| 137 | - array_shift($series_filtres);// skel |
|
| 138 | - array_shift($series_filtres);// corps |
|
| 139 | - |
|
| 140 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 141 | - if ($skel['process_ins'] == 'php') |
|
| 142 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 143 | - |
|
| 144 | - // recuperer les couples de remplacement |
|
| 145 | - $replace = echapper_php_callback(); |
|
| 146 | - |
|
| 147 | - foreach($series_filtres as $filtres){ |
|
| 148 | - if (count($filtres)) |
|
| 149 | - foreach ($filtres as $filtre) { |
|
| 150 | - if ($filtre AND $f = chercher_filtre($filtre)) |
|
| 151 | - $corps = $f($corps); |
|
| 152 | - } |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - // restaurer les echappements |
|
| 156 | - return str_replace($replace[0],$replace[1],$corps); |
|
| 136 | + $series_filtres = func_get_args(); |
|
| 137 | + array_shift($series_filtres);// skel |
|
| 138 | + array_shift($series_filtres);// corps |
|
| 139 | + |
|
| 140 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 141 | + if ($skel['process_ins'] == 'php') |
|
| 142 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS','echapper_php_callback', $corps); |
|
| 143 | + |
|
| 144 | + // recuperer les couples de remplacement |
|
| 145 | + $replace = echapper_php_callback(); |
|
| 146 | + |
|
| 147 | + foreach($series_filtres as $filtres){ |
|
| 148 | + if (count($filtres)) |
|
| 149 | + foreach ($filtres as $filtre) { |
|
| 150 | + if ($filtre AND $f = chercher_filtre($filtre)) |
|
| 151 | + $corps = $f($corps); |
|
| 152 | + } |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + // restaurer les echappements |
|
| 156 | + return str_replace($replace[0],$replace[1],$corps); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
| 160 | 160 | // http://doc.spip.org/@echapper_php_callback |
| 161 | 161 | function echapper_php_callback($r=null) { |
| 162 | - static $src = array(); |
|
| 163 | - static $dst = array(); |
|
| 164 | - |
|
| 165 | - // si on recoit un tableau, on est en mode echappement |
|
| 166 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 167 | - if (is_array($r)) { |
|
| 168 | - $dst[] = $r[0]; |
|
| 169 | - return $src[] = '___'.md5($r[0]).'___'; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 173 | - // et on RAZ les remplacements |
|
| 174 | - $r = array($src,$dst); |
|
| 175 | - $src = $dst = array(); |
|
| 176 | - return $r; |
|
| 162 | + static $src = array(); |
|
| 163 | + static $dst = array(); |
|
| 164 | + |
|
| 165 | + // si on recoit un tableau, on est en mode echappement |
|
| 166 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 167 | + if (is_array($r)) { |
|
| 168 | + $dst[] = $r[0]; |
|
| 169 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 173 | + // et on RAZ les remplacements |
|
| 174 | + $r = array($src,$dst); |
|
| 175 | + $src = $dst = array(); |
|
| 176 | + return $r; |
|
| 177 | 177 | } |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | // |
| 23 | 23 | // http://doc.spip.org/@boucle_DEFAUT_dist |
| 24 | 24 | function boucle_DEFAUT_dist($id_boucle, &$boucles) { |
| 25 | - return calculer_boucle($id_boucle, $boucles); |
|
| 25 | + return calculer_boucle($id_boucle, $boucles); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | // http://doc.spip.org/@boucle_BOUCLE_dist |
| 33 | 33 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { |
| 34 | 34 | |
| 35 | - return calculer_boucle($id_boucle, $boucles); |
|
| 35 | + return calculer_boucle($id_boucle, $boucles); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -41,30 +41,30 @@ discard block |
||
| 41 | 41 | // |
| 42 | 42 | // http://doc.spip.org/@boucle_HIERARCHIE_dist |
| 43 | 43 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 44 | - $boucle = &$boucles[$id_boucle]; |
|
| 45 | - $id_table = $boucle->id_table . ".id_rubrique"; |
|
| 46 | - |
|
| 47 | - // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 48 | - // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 49 | - // ou {id_article} qui positionne aussi le {tout} |
|
| 50 | - |
|
| 51 | - $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 52 | - . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 53 | - . ")))\n\t\treturn '';\n\t" |
|
| 54 | - . "include_spip('inc/rubriques');\n\t" |
|
| 55 | - . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 56 | - . (isset($boucle->modificateur['tout']) ? 'true':'false') |
|
| 57 | - . ");\n\t" |
|
| 58 | - . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 59 | - |
|
| 60 | - $boucle->where[]= array("'IN'", "'$id_table'", '"($hierarchie)"'); |
|
| 61 | - |
|
| 62 | - $order = "FIELD($id_table, \$hierarchie)"; |
|
| 63 | - if (!isset($boucle->default_order[0]) OR $boucle->default_order[0] != " DESC") |
|
| 64 | - $boucle->default_order[] = "\"$order\""; |
|
| 65 | - else |
|
| 66 | - $boucle->default_order[0] = "\"$order DESC\""; |
|
| 67 | - return calculer_boucle($id_boucle, $boucles); |
|
| 44 | + $boucle = &$boucles[$id_boucle]; |
|
| 45 | + $id_table = $boucle->id_table . ".id_rubrique"; |
|
| 46 | + |
|
| 47 | + // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 48 | + // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 49 | + // ou {id_article} qui positionne aussi le {tout} |
|
| 50 | + |
|
| 51 | + $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 52 | + . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 53 | + . ")))\n\t\treturn '';\n\t" |
|
| 54 | + . "include_spip('inc/rubriques');\n\t" |
|
| 55 | + . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 56 | + . (isset($boucle->modificateur['tout']) ? 'true':'false') |
|
| 57 | + . ");\n\t" |
|
| 58 | + . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 59 | + |
|
| 60 | + $boucle->where[]= array("'IN'", "'$id_table'", '"($hierarchie)"'); |
|
| 61 | + |
|
| 62 | + $order = "FIELD($id_table, \$hierarchie)"; |
|
| 63 | + if (!isset($boucle->default_order[0]) OR $boucle->default_order[0] != " DESC") |
|
| 64 | + $boucle->default_order[] = "\"$order\""; |
|
| 65 | + else |
|
| 66 | + $boucle->default_order[0] = "\"$order DESC\""; |
|
| 67 | + return calculer_boucle($id_boucle, $boucles); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -45,15 +45,15 @@ discard block |
||
| 45 | 45 | * AST complété de la gestion du critère |
| 46 | 46 | **/ |
| 47 | 47 | function critere_racine_dist($idb, &$boucles, $crit){ |
| 48 | - global $exceptions_des_tables; |
|
| 49 | - $not = $crit->not; |
|
| 50 | - $boucle = &$boucles[$idb]; |
|
| 51 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 52 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 53 | - 'id_parent'; |
|
| 54 | - |
|
| 55 | - $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 56 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 48 | + global $exceptions_des_tables; |
|
| 49 | + $not = $crit->not; |
|
| 50 | + $boucle = &$boucles[$idb]; |
|
| 51 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 52 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 53 | + 'id_parent'; |
|
| 54 | + |
|
| 55 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 56 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -74,14 +74,14 @@ discard block |
||
| 74 | 74 | * AST complété de la gestion du critère |
| 75 | 75 | **/ |
| 76 | 76 | function critere_exclus_dist($idb, &$boucles, $crit){ |
| 77 | - $not = $crit->not; |
|
| 78 | - $boucle = &$boucles[$idb]; |
|
| 79 | - $id = $boucle->primary; |
|
| 80 | - |
|
| 81 | - if ($not OR !$id) |
|
| 82 | - return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 83 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 84 | - $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 77 | + $not = $crit->not; |
|
| 78 | + $boucle = &$boucles[$idb]; |
|
| 79 | + $id = $boucle->primary; |
|
| 80 | + |
|
| 81 | + if ($not OR !$id) |
|
| 82 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 83 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 84 | + $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | |
@@ -105,72 +105,72 @@ discard block |
||
| 105 | 105 | * AST complété de la gestion du critère |
| 106 | 106 | **/ |
| 107 | 107 | function critere_doublons_dist($idb, &$boucles, $crit){ |
| 108 | - $boucle = &$boucles[$idb]; |
|
| 109 | - $primary = $boucle->primary; |
|
| 110 | - |
|
| 111 | - // la table nécessite une clé primaire, non composée |
|
| 112 | - if (!$primary OR strpos($primary, ',')){ |
|
| 113 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 117 | - |
|
| 118 | - // le doublon s'applique sur un type de boucle (article) |
|
| 119 | - $nom = "'" . $boucle->type_requete. "'"; |
|
| 120 | - |
|
| 121 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 122 | - // on obtient $nom = "'article' . 'nom'" |
|
| 123 | - if (isset($crit->param[0])) { |
|
| 124 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 128 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 129 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 130 | - |
|
| 131 | - // on crée un sql_in avec la clé primaire de la table |
|
| 132 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 133 | - // $doublons et son index, ici $nom |
|
| 134 | - |
|
| 135 | - // debut du code "sql_in('articles.id_article', " |
|
| 136 | - $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 137 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 138 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 139 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 140 | - |
|
| 141 | - // le debut complet du code des doublons |
|
| 142 | - $debut_doub = $debut_in . $debut_doub; |
|
| 143 | - |
|
| 144 | - // nom du doublon "('article' . 'nom')]" |
|
| 145 | - $fin_doub = "($nom)]"; |
|
| 146 | - |
|
| 147 | - // si on trouve un autre critère doublon, |
|
| 148 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 149 | - foreach ($boucle->where as $k => $w) { |
|
| 150 | - if (strpos($w[0], $debut_doub)===0) { |
|
| 151 | - // fusionner le sql_in (du where) |
|
| 152 | - $boucle->where[$k][0] = $debut_doub . $fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 153 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 154 | - $x = strpos($boucle->hash, $init_comment); |
|
| 155 | - $len = strlen($init_comment); |
|
| 156 | - $boucle->hash = |
|
| 157 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 163 | - $boucle->where[] = array($debut_doub . $fin_doub.", '".$not."')"); |
|
| 164 | - |
|
| 165 | - // déclarer le doublon s'il n'existe pas encore |
|
| 166 | - $boucle->hash .= $init_comment . $init_code; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 170 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 171 | - # {!doublons A}{doublons B} |
|
| 172 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 173 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 108 | + $boucle = &$boucles[$idb]; |
|
| 109 | + $primary = $boucle->primary; |
|
| 110 | + |
|
| 111 | + // la table nécessite une clé primaire, non composée |
|
| 112 | + if (!$primary OR strpos($primary, ',')){ |
|
| 113 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 117 | + |
|
| 118 | + // le doublon s'applique sur un type de boucle (article) |
|
| 119 | + $nom = "'" . $boucle->type_requete. "'"; |
|
| 120 | + |
|
| 121 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 122 | + // on obtient $nom = "'article' . 'nom'" |
|
| 123 | + if (isset($crit->param[0])) { |
|
| 124 | + $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 128 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 129 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 130 | + |
|
| 131 | + // on crée un sql_in avec la clé primaire de la table |
|
| 132 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 133 | + // $doublons et son index, ici $nom |
|
| 134 | + |
|
| 135 | + // debut du code "sql_in('articles.id_article', " |
|
| 136 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 137 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 138 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 139 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 140 | + |
|
| 141 | + // le debut complet du code des doublons |
|
| 142 | + $debut_doub = $debut_in . $debut_doub; |
|
| 143 | + |
|
| 144 | + // nom du doublon "('article' . 'nom')]" |
|
| 145 | + $fin_doub = "($nom)]"; |
|
| 146 | + |
|
| 147 | + // si on trouve un autre critère doublon, |
|
| 148 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 149 | + foreach ($boucle->where as $k => $w) { |
|
| 150 | + if (strpos($w[0], $debut_doub)===0) { |
|
| 151 | + // fusionner le sql_in (du where) |
|
| 152 | + $boucle->where[$k][0] = $debut_doub . $fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 153 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 154 | + $x = strpos($boucle->hash, $init_comment); |
|
| 155 | + $len = strlen($init_comment); |
|
| 156 | + $boucle->hash = |
|
| 157 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 163 | + $boucle->where[] = array($debut_doub . $fin_doub.", '".$not."')"); |
|
| 164 | + |
|
| 165 | + // déclarer le doublon s'il n'existe pas encore |
|
| 166 | + $boucle->hash .= $init_comment . $init_code; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 170 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 171 | + # {!doublons A}{doublons B} |
|
| 172 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 173 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | |
@@ -195,26 +195,26 @@ discard block |
||
| 195 | 195 | * AST complété de la gestion du critère |
| 196 | 196 | **/ |
| 197 | 197 | function critere_lang_select_dist($idb, &$boucles, $crit){ |
| 198 | - if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
|
| 199 | - if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 200 | - $boucle = &$boucles[$idb]; |
|
| 201 | - $boucle->lang_select = $param; |
|
| 198 | + if (!isset($crit->param[1][0]) OR !($param = $crit->param[1][0]->texte)) $param = 'oui'; |
|
| 199 | + if ($crit->not) $param = ($param=='oui') ? 'non' : 'oui'; |
|
| 200 | + $boucle = &$boucles[$idb]; |
|
| 201 | + $boucle->lang_select = $param; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | // {debut_xxx} |
| 205 | 205 | // http://www.spip.net/@debut_ |
| 206 | 206 | // http://doc.spip.org/@critere_debut_dist |
| 207 | 207 | function critere_debut_dist($idb, &$boucles, $crit){ |
| 208 | - list($un, $deux) = $crit->param; |
|
| 209 | - $un = $un[0]->texte; |
|
| 210 | - $deux = $deux[0]->texte; |
|
| 211 | - if ($deux){ |
|
| 212 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 213 | - $un. |
|
| 214 | - '"]) . ",'. |
|
| 215 | - $deux. |
|
| 216 | - '"'; |
|
| 217 | - } else calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 208 | + list($un, $deux) = $crit->param; |
|
| 209 | + $un = $un[0]->texte; |
|
| 210 | + $deux = $deux[0]->texte; |
|
| 211 | + if ($deux){ |
|
| 212 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 213 | + $un. |
|
| 214 | + '"]) . ",'. |
|
| 215 | + $deux. |
|
| 216 | + '"'; |
|
| 217 | + } else calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | // {pagination} |
@@ -225,46 +225,46 @@ discard block |
||
| 225 | 225 | // http://doc.spip.org/@critere_pagination_dist |
| 226 | 226 | function critere_pagination_dist($idb, &$boucles, $crit){ |
| 227 | 227 | |
| 228 | - $boucle = &$boucles[$idb]; |
|
| 229 | - // definition de la taille de la page |
|
| 230 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 231 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 232 | - |
|
| 233 | - if (!preg_match(_CODE_QUOTE, $pas, $r)){ |
|
| 234 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 235 | - } else { |
|
| 236 | - $r = intval($r[2]); |
|
| 237 | - $pas = strval($r ? $r : 10); |
|
| 238 | - } |
|
| 239 | - $type = !isset($crit->param[0][1]) ? "'$idb'" |
|
| 240 | - : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 241 | - $debut = ($type[0]!=="'") ? "'debut'.$type" |
|
| 242 | - : ("'debut".substr($type, 1)); |
|
| 243 | - |
|
| 244 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 245 | - $partie = |
|
| 246 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 247 | - 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 248 | - ."\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 249 | - ."\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 250 | - ."\t\t".'$iter->seek(0);'."\n" |
|
| 251 | - ."\t}\n" |
|
| 252 | - ."\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 253 | - |
|
| 254 | - $boucle->hash .= ' |
|
| 228 | + $boucle = &$boucles[$idb]; |
|
| 229 | + // definition de la taille de la page |
|
| 230 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 231 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 232 | + |
|
| 233 | + if (!preg_match(_CODE_QUOTE, $pas, $r)){ |
|
| 234 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 235 | + } else { |
|
| 236 | + $r = intval($r[2]); |
|
| 237 | + $pas = strval($r ? $r : 10); |
|
| 238 | + } |
|
| 239 | + $type = !isset($crit->param[0][1]) ? "'$idb'" |
|
| 240 | + : calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 241 | + $debut = ($type[0]!=="'") ? "'debut'.$type" |
|
| 242 | + : ("'debut".substr($type, 1)); |
|
| 243 | + |
|
| 244 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 245 | + $partie = |
|
| 246 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 247 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 248 | + ."\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 249 | + ."\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 250 | + ."\t\t".'$iter->seek(0);'."\n" |
|
| 251 | + ."\t}\n" |
|
| 252 | + ."\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 253 | + |
|
| 254 | + $boucle->hash .= ' |
|
| 255 | 255 | $command[\'pagination\'] = array((isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : null), ' . $pas . ');'; |
| 256 | 256 | |
| 257 | - $boucle->total_parties = $pas; |
|
| 258 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 259 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 260 | - // sauf si pas de primaire, ou si primaire composee |
|
| 261 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 262 | - $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 263 | - if ($boucle->primary |
|
| 264 | - AND !preg_match('/[,\s]/', $boucle->primary) |
|
| 265 | - AND !in_array($t, $boucle->select) |
|
| 266 | - ) |
|
| 267 | - $boucle->select[] = $t; |
|
| 257 | + $boucle->total_parties = $pas; |
|
| 258 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 259 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 260 | + // sauf si pas de primaire, ou si primaire composee |
|
| 261 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 262 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 263 | + if ($boucle->primary |
|
| 264 | + AND !preg_match('/[,\s]/', $boucle->primary) |
|
| 265 | + AND !in_array($t, $boucle->select) |
|
| 266 | + ) |
|
| 267 | + $boucle->select[] = $t; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | |
@@ -273,22 +273,22 @@ discard block |
||
| 273 | 273 | // http://doc.spip.org/@critere_recherche_dist |
| 274 | 274 | function critere_recherche_dist($idb, &$boucles, $crit){ |
| 275 | 275 | |
| 276 | - $boucle = &$boucles[$idb]; |
|
| 276 | + $boucle = &$boucles[$idb]; |
|
| 277 | 277 | |
| 278 | - if (!$boucle->primary OR strpos($boucle->primary, ',')){ |
|
| 279 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire',array('critere'=>'recherche')), $boucle); |
|
| 280 | - return; |
|
| 281 | - } |
|
| 278 | + if (!$boucle->primary OR strpos($boucle->primary, ',')){ |
|
| 279 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire',array('critere'=>'recherche')), $boucle); |
|
| 280 | + return; |
|
| 281 | + } |
|
| 282 | 282 | |
| 283 | - if (isset($crit->param[0])) |
|
| 284 | - $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 285 | - else |
|
| 286 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 283 | + if (isset($crit->param[0])) |
|
| 284 | + $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 285 | + else |
|
| 286 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 287 | 287 | |
| 288 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 289 | - $boucle->hash .= ' |
|
| 288 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 289 | + $boucle->hash .= ' |
|
| 290 | 290 | // RECHERCHE' |
| 291 | - .($crit->cond ? ' |
|
| 291 | + .($crit->cond ? ' |
|
| 292 | 292 | if (!strlen('.$quoi.')){ |
| 293 | 293 | list($rech_select, $rech_where) = array("0 as points",""); |
| 294 | 294 | } else' : '').' |
@@ -299,20 +299,20 @@ discard block |
||
| 299 | 299 | '; |
| 300 | 300 | |
| 301 | 301 | |
| 302 | - $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 304 | - $boucle->select[] = $t; # pour postgres, neuneu ici |
|
| 305 | - // jointure uniquement sur le serveur principal |
|
| 306 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 307 | - if (!$boucle->sql_serveur){ |
|
| 308 | - $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 309 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 310 | - } |
|
| 311 | - $boucle->select[] = '$rech_select'; |
|
| 312 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 313 | - |
|
| 314 | - // et la recherche trouve |
|
| 315 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 303 | + if (!in_array($t, $boucles[$idb]->select)) |
|
| 304 | + $boucle->select[] = $t; # pour postgres, neuneu ici |
|
| 305 | + // jointure uniquement sur le serveur principal |
|
| 306 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 307 | + if (!$boucle->sql_serveur){ |
|
| 308 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 309 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 310 | + } |
|
| 311 | + $boucle->select[] = '$rech_select'; |
|
| 312 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 313 | + |
|
| 314 | + // et la recherche trouve |
|
| 315 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | // {traduction} |
@@ -321,22 +321,22 @@ discard block |
||
| 321 | 321 | // OR id_article=id_article(precedent) |
| 322 | 322 | // http://doc.spip.org/@critere_traduction_dist |
| 323 | 323 | function critere_traduction_dist($idb, &$boucles, $crit){ |
| 324 | - $boucle = &$boucles[$idb]; |
|
| 325 | - $prim = $boucle->primary; |
|
| 326 | - $table = $boucle->id_table; |
|
| 327 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 328 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 329 | - $boucle->where[] = |
|
| 330 | - array("'OR'", |
|
| 331 | - array("'AND'", |
|
| 332 | - array("'='", "'$table.id_trad'", 0), |
|
| 333 | - array("'='", "'$table.$prim'", $dprim) |
|
| 334 | - ), |
|
| 335 | - array("'AND'", |
|
| 336 | - array("'>'", "'$table.id_trad'", 0), |
|
| 337 | - array("'='", "'$table.id_trad'", $arg) |
|
| 338 | - ) |
|
| 339 | - ); |
|
| 324 | + $boucle = &$boucles[$idb]; |
|
| 325 | + $prim = $boucle->primary; |
|
| 326 | + $table = $boucle->id_table; |
|
| 327 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 328 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 329 | + $boucle->where[] = |
|
| 330 | + array("'OR'", |
|
| 331 | + array("'AND'", |
|
| 332 | + array("'='", "'$table.id_trad'", 0), |
|
| 333 | + array("'='", "'$table.$prim'", $dprim) |
|
| 334 | + ), |
|
| 335 | + array("'AND'", |
|
| 336 | + array("'>'", "'$table.id_trad'", 0), |
|
| 337 | + array("'='", "'$table.id_trad'", $arg) |
|
| 338 | + ) |
|
| 339 | + ); |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // {origine_traduction} |
@@ -344,38 +344,38 @@ discard block |
||
| 344 | 344 | // http://www.spip.net/@origine_traduction |
| 345 | 345 | // http://doc.spip.org/@critere_origine_traduction_dist |
| 346 | 346 | function critere_origine_traduction_dist($idb, &$boucles, $crit){ |
| 347 | - $boucle = &$boucles[$idb]; |
|
| 348 | - $prim = $boucle->primary; |
|
| 349 | - $table = $boucle->id_table; |
|
| 350 | - |
|
| 351 | - $c = |
|
| 352 | - array("'OR'", |
|
| 353 | - array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 354 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 355 | - ); |
|
| 356 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 347 | + $boucle = &$boucles[$idb]; |
|
| 348 | + $prim = $boucle->primary; |
|
| 349 | + $table = $boucle->id_table; |
|
| 350 | + |
|
| 351 | + $c = |
|
| 352 | + array("'OR'", |
|
| 353 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 354 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 355 | + ); |
|
| 356 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | // {meme_parent} |
| 360 | 360 | // http://www.spip.net/@meme_parent |
| 361 | 361 | // http://doc.spip.org/@critere_meme_parent_dist |
| 362 | 362 | function critere_meme_parent_dist($idb, &$boucles, $crit){ |
| 363 | - global $exceptions_des_tables; |
|
| 364 | - $boucle = &$boucles[$idb]; |
|
| 365 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 366 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 367 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 368 | - 'id_parent'; |
|
| 369 | - $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 370 | - |
|
| 371 | - if ($boucle->type_requete=='rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])){ |
|
| 372 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 373 | - |
|
| 374 | - } |
|
| 375 | - // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 376 | - else { |
|
| 377 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 378 | - } |
|
| 363 | + global $exceptions_des_tables; |
|
| 364 | + $boucle = &$boucles[$idb]; |
|
| 365 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 366 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 367 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 368 | + 'id_parent'; |
|
| 369 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 370 | + |
|
| 371 | + if ($boucle->type_requete=='rubriques' OR isset($exceptions_des_tables[$boucle->id_table]['id_parent'])){ |
|
| 372 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 373 | + |
|
| 374 | + } |
|
| 375 | + // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 376 | + else { |
|
| 377 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | |
@@ -400,249 +400,249 @@ discard block |
||
| 400 | 400 | **/ |
| 401 | 401 | function critere_branche_dist($idb, &$boucles, $crit){ |
| 402 | 402 | |
| 403 | - $not = $crit->not; |
|
| 404 | - $boucle = &$boucles[$idb]; |
|
| 405 | - $arg = calculer_argument_precedent($idb, 'id_rubrique', $boucles); |
|
| 406 | - |
|
| 407 | - //Trouver une jointure |
|
| 408 | - $champ = "id_rubrique"; |
|
| 409 | - $desc = $boucle->show; |
|
| 410 | - //Seulement si necessaire |
|
| 411 | - if (!array_key_exists($champ, $desc['field'])){ |
|
| 412 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 413 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 414 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 415 | - if (count(trouver_champs_decomposes($champ, $desc))>1){ |
|
| 416 | - $decompose = decompose_champ_id_objet($champ); |
|
| 417 | - $champ = array_shift($decompose); |
|
| 418 | - $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - else $cle = $boucle->id_table; |
|
| 422 | - |
|
| 423 | - $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 424 | - .($not ? ", 'NOT'" : '').")"; |
|
| 425 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 426 | - ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 403 | + $not = $crit->not; |
|
| 404 | + $boucle = &$boucles[$idb]; |
|
| 405 | + $arg = calculer_argument_precedent($idb, 'id_rubrique', $boucles); |
|
| 406 | + |
|
| 407 | + //Trouver une jointure |
|
| 408 | + $champ = "id_rubrique"; |
|
| 409 | + $desc = $boucle->show; |
|
| 410 | + //Seulement si necessaire |
|
| 411 | + if (!array_key_exists($champ, $desc['field'])){ |
|
| 412 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 413 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 414 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 415 | + if (count(trouver_champs_decomposes($champ, $desc))>1){ |
|
| 416 | + $decompose = decompose_champ_id_objet($champ); |
|
| 417 | + $champ = array_shift($decompose); |
|
| 418 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + else $cle = $boucle->id_table; |
|
| 422 | + |
|
| 423 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 424 | + .($not ? ", 'NOT'" : '').")"; |
|
| 425 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 426 | + ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 427 | 427 | } |
| 428 | 428 | |
| 429 | 429 | // {logo} liste les objets qui ont un logo |
| 430 | 430 | // http://doc.spip.org/@critere_logo_dist |
| 431 | 431 | function critere_logo_dist($idb, &$boucles, $crit){ |
| 432 | 432 | |
| 433 | - $not = $crit->not; |
|
| 434 | - $boucle = &$boucles[$idb]; |
|
| 433 | + $not = $crit->not; |
|
| 434 | + $boucle = &$boucles[$idb]; |
|
| 435 | 435 | |
| 436 | - $c = "sql_in('". |
|
| 437 | - $boucle->id_table.'.'.$boucle->primary |
|
| 438 | - ."', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 436 | + $c = "sql_in('". |
|
| 437 | + $boucle->id_table.'.'.$boucle->primary |
|
| 438 | + ."', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 439 | 439 | |
| 440 | - if ($crit->cond) $c = "($arg ? $c : 1)"; |
|
| 440 | + if ($crit->cond) $c = "($arg ? $c : 1)"; |
|
| 441 | 441 | |
| 442 | - if ($not) |
|
| 443 | - $boucle->where[] = array("'NOT'", $c); |
|
| 444 | - else |
|
| 445 | - $boucle->where[] = $c; |
|
| 442 | + if ($not) |
|
| 443 | + $boucle->where[] = array("'NOT'", $c); |
|
| 444 | + else |
|
| 445 | + $boucle->where[] = $c; |
|
| 446 | 446 | } |
| 447 | 447 | |
| 448 | 448 | // c'est la commande SQL "GROUP BY" |
| 449 | 449 | // par exemple <boucle(articles){fusion lang}> |
| 450 | 450 | // http://doc.spip.org/@critere_fusion_dist |
| 451 | 451 | function critere_fusion_dist($idb, &$boucles, $crit){ |
| 452 | - if ($t = isset($crit->param[0])){ |
|
| 453 | - $t = $crit->param[0]; |
|
| 454 | - if ($t[0]->type=='texte'){ |
|
| 455 | - $t = $t[0]->texte; |
|
| 456 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
|
| 457 | - $t = table_objet_sql($r[1]); |
|
| 458 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 459 | - if ($t) $t .= '.'.$r[2]; |
|
| 460 | - } |
|
| 461 | - } else { |
|
| 462 | - $t = '".' |
|
| 463 | - .calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 464 | - .'."'; |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - if ($t){ |
|
| 468 | - $boucles[$idb]->group[] = $t; |
|
| 469 | - if (!in_array($t, $boucles[$idb]->select)) |
|
| 470 | - $boucles[$idb]->select[] = $t; |
|
| 471 | - } else |
|
| 472 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 452 | + if ($t = isset($crit->param[0])){ |
|
| 453 | + $t = $crit->param[0]; |
|
| 454 | + if ($t[0]->type=='texte'){ |
|
| 455 | + $t = $t[0]->texte; |
|
| 456 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)){ |
|
| 457 | + $t = table_objet_sql($r[1]); |
|
| 458 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 459 | + if ($t) $t .= '.'.$r[2]; |
|
| 460 | + } |
|
| 461 | + } else { |
|
| 462 | + $t = '".' |
|
| 463 | + .calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 464 | + .'."'; |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + if ($t){ |
|
| 468 | + $boucles[$idb]->group[] = $t; |
|
| 469 | + if (!in_array($t, $boucles[$idb]->select)) |
|
| 470 | + $boucles[$idb]->select[] = $t; |
|
| 471 | + } else |
|
| 472 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | // c'est la commande SQL "COLLATE" |
| 476 | 476 | // qui peut etre appliquee sur les order by, group by, where like ... |
| 477 | 477 | // http://doc.spip.org/@critere_collecte_dist |
| 478 | 478 | function critere_collecte_dist($idb, &$boucles, $crit){ |
| 479 | - if (isset($crit->param[0])){ |
|
| 480 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 481 | - $boucle = $boucles[$idb]; |
|
| 482 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 483 | - $n = count($boucle->order); |
|
| 484 | - if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | - $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | - } else |
|
| 487 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 479 | + if (isset($crit->param[0])){ |
|
| 480 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 481 | + $boucle = $boucles[$idb]; |
|
| 482 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 483 | + $n = count($boucle->order); |
|
| 484 | + if ($n && (strpos($boucle->order[$n-1], 'COLLATE')===false)) |
|
| 485 | + $boucle->order[$n-1] .= " . ".$boucle->modificateur['collate']; |
|
| 486 | + } else |
|
| 487 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 488 | 488 | } |
| 489 | 489 | |
| 490 | 490 | // http://doc.spip.org/@calculer_critere_arg_dynamique |
| 491 | 491 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = ''){ |
| 492 | - $boucle = $boucles[$idb]; |
|
| 493 | - $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 494 | - $var = '$champs_'.$idb; |
|
| 495 | - $desc = (strpos($boucle->in, "static $var =")!==false); |
|
| 496 | - if (!$desc){ |
|
| 497 | - $desc = $boucle->show['field']; |
|
| 498 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 499 | - $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 500 | - } |
|
| 501 | - if ($desc) $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 502 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 503 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 492 | + $boucle = $boucles[$idb]; |
|
| 493 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 494 | + $var = '$champs_'.$idb; |
|
| 495 | + $desc = (strpos($boucle->in, "static $var =")!==false); |
|
| 496 | + if (!$desc){ |
|
| 497 | + $desc = $boucle->show['field']; |
|
| 498 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 499 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 500 | + } |
|
| 501 | + if ($desc) $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 502 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 503 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | // Tri : {par xxxx} |
| 507 | 507 | // http://www.spip.net/@par |
| 508 | 508 | // http://doc.spip.org/@critere_par_dist |
| 509 | 509 | function critere_par_dist($idb, &$boucles, $crit){ |
| 510 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 510 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 511 | 511 | } |
| 512 | 512 | |
| 513 | 513 | // http://doc.spip.org/@critere_parinverse |
| 514 | 514 | function critere_parinverse($idb, &$boucles, $crit, $sens = ''){ |
| 515 | - global $exceptions_des_jointures; |
|
| 516 | - $boucle = &$boucles[$idb]; |
|
| 517 | - if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
|
| 518 | - $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
|
| 519 | - |
|
| 520 | - foreach ($crit->param as $tri){ |
|
| 521 | - |
|
| 522 | - $order = $fct = ""; // en cas de fonction SQL |
|
| 523 | - // tris specifies dynamiquement |
|
| 524 | - if ($tri[0]->type!='texte'){ |
|
| 525 | - // calculer le order dynamique qui verifie les champs |
|
| 526 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 527 | - // et si ce n'est fait, ajouter un champ 'hasard' |
|
| 528 | - // pour supporter 'hasard' comme tri dynamique |
|
| 529 | - $par = "rand()"; |
|
| 530 | - $parha = $par." AS hasard"; |
|
| 531 | - if (!in_array($parha, $boucle->select)) |
|
| 532 | - $boucle->select[] = $parha; |
|
| 533 | - } else { |
|
| 534 | - $par = array_shift($tri); |
|
| 535 | - $par = $par->texte; |
|
| 536 | - // par multi champ |
|
| 537 | - if (preg_match(",^multi[\s]*(.*)$,", $par, $m)){ |
|
| 538 | - $champ = trim($m[1]); |
|
| 539 | - // par multi L1.champ |
|
| 540 | - if (strpos($champ, '.')) { |
|
| 541 | - $cle = ''; |
|
| 542 | - // par multi champ (champ sur une autre table) |
|
| 543 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 544 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 545 | - // par multi champ (champ dans la table en cours) |
|
| 546 | - } else { |
|
| 547 | - $cle = $boucle->id_table; |
|
| 548 | - } |
|
| 549 | - if ($cle) { $cle .= '.'; } |
|
| 550 | - $texte = $cle.$champ; |
|
| 551 | - $boucle->select[] = "\".sql_multi('".$texte."', \$GLOBALS['spip_lang']).\""; |
|
| 552 | - $order = "'multi'"; |
|
| 553 | - // par num champ(, suite) |
|
| 554 | - } else if (preg_match(",^num (.*)$,m", $par, $m)) { |
|
| 555 | - $champ = trim($m[1]); |
|
| 556 | - // par num L1.champ |
|
| 557 | - if (strpos($champ, '.')) { |
|
| 558 | - $cle = ''; |
|
| 559 | - // par num champ (champ sur une autre table) |
|
| 560 | - } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 561 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 562 | - // par num champ (champ dans la table en cours) |
|
| 563 | - } else { |
|
| 564 | - $cle = $boucle->id_table; |
|
| 565 | - } |
|
| 566 | - if ($cle) { $cle .= '.'; } |
|
| 567 | - $texte = '0+'. $cle . $champ; |
|
| 568 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 569 | - if ($suite!=="''") |
|
| 570 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 571 | - $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 572 | - $boucle->select[] = $texte." AS $as"; |
|
| 573 | - $order = "'$as'"; |
|
| 574 | - } else { |
|
| 575 | - if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)){ |
|
| 576 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 577 | - } else { |
|
| 578 | - if (count($match)>2){ |
|
| 579 | - $par = substr($match[2], 1, -1); |
|
| 580 | - $fct = $match[1]; |
|
| 581 | - } |
|
| 582 | - // par hasard |
|
| 583 | - if ($par=='hasard'){ |
|
| 584 | - $par = "rand()"; |
|
| 585 | - $boucle->select[] = $par." AS alea"; |
|
| 586 | - $order = "'alea'"; |
|
| 587 | - } |
|
| 588 | - // par titre_mot ou type_mot voire d'autres |
|
| 589 | - else if (isset($exceptions_des_jointures[$par])){ |
|
| 590 | - list($table, $champ) = $exceptions_des_jointures[$par]; |
|
| 591 | - $order = critere_par_joint($table, $champ, $boucle, $idb); |
|
| 592 | - if (!$order) |
|
| 593 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 594 | - } |
|
| 595 | - else if ($par=='date' |
|
| 596 | - AND $desc = $boucle->show |
|
| 597 | - AND $desc['date'] |
|
| 598 | - ){ |
|
| 599 | - $m = $desc['date']; |
|
| 600 | - $order = "'".$boucle->id_table.".".$m."'"; |
|
| 601 | - } |
|
| 602 | - // par champ. Verifier qu'ils sont presents. |
|
| 603 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 604 | - // cas du tri sur champ de jointure explicite |
|
| 605 | - $t = array_search($r[1], $boucle->from); |
|
| 606 | - if (!$t){ |
|
| 607 | - $t = trouver_jointure_champ($r[2], $boucle, array($r[1])); |
|
| 608 | - } |
|
| 609 | - if (!$t){ |
|
| 610 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 611 | - } else $order = "'".$t.'.'.$r[2]."'"; |
|
| 612 | - } else { |
|
| 613 | - $desc = $boucle->show; |
|
| 614 | - if ($desc['field'][$par]) |
|
| 615 | - $par = $boucle->id_table.".".$par; |
|
| 616 | - // sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 617 | - $order = "'$par'"; |
|
| 618 | - } |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)){ |
|
| 623 | - $t = $m[1]; |
|
| 624 | - if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
|
| 625 | - $boucle->select[] = $t; |
|
| 626 | - } |
|
| 627 | - } else $sens = ''; |
|
| 628 | - |
|
| 629 | - if ($fct){ |
|
| 630 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
|
| 631 | - $order = "'$fct(".$r[1].")'"; |
|
| 632 | - else $order = "'$fct(' . $order . ')'"; |
|
| 633 | - } |
|
| 634 | - $t = $order.$collecte.$sens; |
|
| 635 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 636 | - $t = $r[1].$r[2]; |
|
| 637 | - $boucle->order[] = $t; |
|
| 638 | - } |
|
| 515 | + global $exceptions_des_jointures; |
|
| 516 | + $boucle = &$boucles[$idb]; |
|
| 517 | + if ($crit->not) $sens = $sens ? "" : " . ' DESC'"; |
|
| 518 | + $collecte = (isset($boucle->modificateur['collecte'])) ? " . ".$boucle->modificateur['collecte'] : ""; |
|
| 519 | + |
|
| 520 | + foreach ($crit->param as $tri){ |
|
| 521 | + |
|
| 522 | + $order = $fct = ""; // en cas de fonction SQL |
|
| 523 | + // tris specifies dynamiquement |
|
| 524 | + if ($tri[0]->type!='texte'){ |
|
| 525 | + // calculer le order dynamique qui verifie les champs |
|
| 526 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 527 | + // et si ce n'est fait, ajouter un champ 'hasard' |
|
| 528 | + // pour supporter 'hasard' comme tri dynamique |
|
| 529 | + $par = "rand()"; |
|
| 530 | + $parha = $par." AS hasard"; |
|
| 531 | + if (!in_array($parha, $boucle->select)) |
|
| 532 | + $boucle->select[] = $parha; |
|
| 533 | + } else { |
|
| 534 | + $par = array_shift($tri); |
|
| 535 | + $par = $par->texte; |
|
| 536 | + // par multi champ |
|
| 537 | + if (preg_match(",^multi[\s]*(.*)$,", $par, $m)){ |
|
| 538 | + $champ = trim($m[1]); |
|
| 539 | + // par multi L1.champ |
|
| 540 | + if (strpos($champ, '.')) { |
|
| 541 | + $cle = ''; |
|
| 542 | + // par multi champ (champ sur une autre table) |
|
| 543 | + } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 544 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 545 | + // par multi champ (champ dans la table en cours) |
|
| 546 | + } else { |
|
| 547 | + $cle = $boucle->id_table; |
|
| 548 | + } |
|
| 549 | + if ($cle) { $cle .= '.'; } |
|
| 550 | + $texte = $cle.$champ; |
|
| 551 | + $boucle->select[] = "\".sql_multi('".$texte."', \$GLOBALS['spip_lang']).\""; |
|
| 552 | + $order = "'multi'"; |
|
| 553 | + // par num champ(, suite) |
|
| 554 | + } else if (preg_match(",^num (.*)$,m", $par, $m)) { |
|
| 555 | + $champ = trim($m[1]); |
|
| 556 | + // par num L1.champ |
|
| 557 | + if (strpos($champ, '.')) { |
|
| 558 | + $cle = ''; |
|
| 559 | + // par num champ (champ sur une autre table) |
|
| 560 | + } elseif (!array_key_exists($champ, $boucle->show['field'])){ |
|
| 561 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 562 | + // par num champ (champ dans la table en cours) |
|
| 563 | + } else { |
|
| 564 | + $cle = $boucle->id_table; |
|
| 565 | + } |
|
| 566 | + if ($cle) { $cle .= '.'; } |
|
| 567 | + $texte = '0+'. $cle . $champ; |
|
| 568 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 569 | + if ($suite!=="''") |
|
| 570 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 571 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 572 | + $boucle->select[] = $texte." AS $as"; |
|
| 573 | + $order = "'$as'"; |
|
| 574 | + } else { |
|
| 575 | + if (!preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)){ |
|
| 576 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 577 | + } else { |
|
| 578 | + if (count($match)>2){ |
|
| 579 | + $par = substr($match[2], 1, -1); |
|
| 580 | + $fct = $match[1]; |
|
| 581 | + } |
|
| 582 | + // par hasard |
|
| 583 | + if ($par=='hasard'){ |
|
| 584 | + $par = "rand()"; |
|
| 585 | + $boucle->select[] = $par." AS alea"; |
|
| 586 | + $order = "'alea'"; |
|
| 587 | + } |
|
| 588 | + // par titre_mot ou type_mot voire d'autres |
|
| 589 | + else if (isset($exceptions_des_jointures[$par])){ |
|
| 590 | + list($table, $champ) = $exceptions_des_jointures[$par]; |
|
| 591 | + $order = critere_par_joint($table, $champ, $boucle, $idb); |
|
| 592 | + if (!$order) |
|
| 593 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 594 | + } |
|
| 595 | + else if ($par=='date' |
|
| 596 | + AND $desc = $boucle->show |
|
| 597 | + AND $desc['date'] |
|
| 598 | + ){ |
|
| 599 | + $m = $desc['date']; |
|
| 600 | + $order = "'".$boucle->id_table.".".$m."'"; |
|
| 601 | + } |
|
| 602 | + // par champ. Verifier qu'ils sont presents. |
|
| 603 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 604 | + // cas du tri sur champ de jointure explicite |
|
| 605 | + $t = array_search($r[1], $boucle->from); |
|
| 606 | + if (!$t){ |
|
| 607 | + $t = trouver_jointure_champ($r[2], $boucle, array($r[1])); |
|
| 608 | + } |
|
| 609 | + if (!$t){ |
|
| 610 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." $par"))); |
|
| 611 | + } else $order = "'".$t.'.'.$r[2]."'"; |
|
| 612 | + } else { |
|
| 613 | + $desc = $boucle->show; |
|
| 614 | + if ($desc['field'][$par]) |
|
| 615 | + $par = $boucle->id_table.".".$par; |
|
| 616 | + // sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 617 | + $order = "'$par'"; |
|
| 618 | + } |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)){ |
|
| 623 | + $t = $m[1]; |
|
| 624 | + if (strpos($t, '.') AND !in_array($t, $boucle->select)){ |
|
| 625 | + $boucle->select[] = $t; |
|
| 626 | + } |
|
| 627 | + } else $sens = ''; |
|
| 628 | + |
|
| 629 | + if ($fct){ |
|
| 630 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) |
|
| 631 | + $order = "'$fct(".$r[1].")'"; |
|
| 632 | + else $order = "'$fct(' . $order . ')'"; |
|
| 633 | + } |
|
| 634 | + $t = $order.$collecte.$sens; |
|
| 635 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 636 | + $t = $r[1].$r[2]; |
|
| 637 | + $boucle->order[] = $t; |
|
| 638 | + } |
|
| 639 | 639 | } |
| 640 | 640 | |
| 641 | 641 | // http://doc.spip.org/@critere_par_joint |
| 642 | 642 | function critere_par_joint($table, $champ, &$boucle, $idb){ |
| 643 | - $t = array_search($table, $boucle->from); |
|
| 644 | - if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
|
| 645 | - return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 643 | + $t = array_search($table, $boucle->from); |
|
| 644 | + if (!$t) $t = trouver_jointure_champ($champ, $boucle); |
|
| 645 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | // {inverse} |
@@ -651,137 +651,137 @@ discard block |
||
| 651 | 651 | // http://doc.spip.org/@critere_inverse_dist |
| 652 | 652 | function critere_inverse_dist($idb, &$boucles, $crit){ |
| 653 | 653 | |
| 654 | - $boucle = &$boucles[$idb]; |
|
| 655 | - // Classement par ordre inverse |
|
| 656 | - if ($crit->not) |
|
| 657 | - critere_parinverse($idb, $boucles, $crit); |
|
| 658 | - else |
|
| 659 | - { |
|
| 660 | - $order = "' DESC'"; |
|
| 661 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 662 | - if (isset($crit->param[0])){ |
|
| 663 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 664 | - $order = "(($critere)?' DESC':'')"; |
|
| 665 | - } |
|
| 666 | - |
|
| 667 | - $n = count($boucle->order); |
|
| 668 | - if (!$n){ |
|
| 669 | - if (isset($boucle->default_order[0])) |
|
| 670 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 671 | - else |
|
| 672 | - $boucle->default_order[] = ' DESC'; |
|
| 673 | - } else { |
|
| 674 | - $t = $boucle->order[$n-1]." . $order"; |
|
| 675 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 676 | - $t = $r[1].$r[2]; |
|
| 677 | - $boucle->order[$n-1] = $t; |
|
| 678 | - } |
|
| 679 | - } |
|
| 654 | + $boucle = &$boucles[$idb]; |
|
| 655 | + // Classement par ordre inverse |
|
| 656 | + if ($crit->not) |
|
| 657 | + critere_parinverse($idb, $boucles, $crit); |
|
| 658 | + else |
|
| 659 | + { |
|
| 660 | + $order = "' DESC'"; |
|
| 661 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 662 | + if (isset($crit->param[0])){ |
|
| 663 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 664 | + $order = "(($critere)?' DESC':'')"; |
|
| 665 | + } |
|
| 666 | + |
|
| 667 | + $n = count($boucle->order); |
|
| 668 | + if (!$n){ |
|
| 669 | + if (isset($boucle->default_order[0])) |
|
| 670 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 671 | + else |
|
| 672 | + $boucle->default_order[] = ' DESC'; |
|
| 673 | + } else { |
|
| 674 | + $t = $boucle->order[$n-1]." . $order"; |
|
| 675 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) |
|
| 676 | + $t = $r[1].$r[2]; |
|
| 677 | + $boucle->order[$n-1] = $t; |
|
| 678 | + } |
|
| 679 | + } |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | // http://doc.spip.org/@critere_agenda_dist |
| 683 | 683 | function critere_agenda_dist($idb, &$boucles, $crit){ |
| 684 | - $params = $crit->param; |
|
| 685 | - |
|
| 686 | - if (count($params)<1) |
|
| 687 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 688 | - |
|
| 689 | - $parent = $boucles[$idb]->id_parent; |
|
| 690 | - |
|
| 691 | - // les valeurs $date et $type doivent etre connus a la compilation |
|
| 692 | - // autrement dit ne pas etre des champs |
|
| 693 | - |
|
| 694 | - $date = array_shift($params); |
|
| 695 | - $date = $date[0]->texte; |
|
| 696 | - |
|
| 697 | - $type = array_shift($params); |
|
| 698 | - $type = $type[0]->texte; |
|
| 699 | - |
|
| 700 | - $annee = $params ? array_shift($params) : ""; |
|
| 701 | - $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 702 | - calculer_liste($annee, array(), $boucles, $parent). |
|
| 703 | - ') ? $x : date("Y"))'; |
|
| 704 | - |
|
| 705 | - $mois = $params ? array_shift($params) : ""; |
|
| 706 | - $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 707 | - calculer_liste($mois, array(), $boucles, $parent). |
|
| 708 | - ') ? $x : date("m"))'; |
|
| 709 | - |
|
| 710 | - $jour = $params ? array_shift($params) : ""; |
|
| 711 | - $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 712 | - calculer_liste($jour, array(), $boucles, $parent). |
|
| 713 | - ') ? $x : date("d"))'; |
|
| 714 | - |
|
| 715 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 716 | - $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 717 | - calculer_liste($annee2, array(), $boucles, $parent). |
|
| 718 | - ') ? $x : date("Y"))'; |
|
| 719 | - |
|
| 720 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 721 | - $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 722 | - calculer_liste($mois2, array(), $boucles, $parent). |
|
| 723 | - ') ? $x : date("m"))'; |
|
| 724 | - |
|
| 725 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 726 | - $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 727 | - calculer_liste($jour2, array(), $boucles, $parent). |
|
| 728 | - ') ? $x : date("d"))'; |
|
| 729 | - |
|
| 730 | - $boucle = &$boucles[$idb]; |
|
| 731 | - $date = $boucle->id_table.".$date"; |
|
| 732 | - |
|
| 733 | - $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 734 | - if ($type=='jour') |
|
| 735 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 736 | - ("sql_quote($annee . $mois . $jour$quote_end)")); |
|
| 737 | - elseif ($type=='mois') |
|
| 738 | - $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 739 | - ("sql_quote($annee . $mois$quote_end)")); |
|
| 740 | - elseif ($type=='semaine') |
|
| 741 | - $boucle->where[] = array("'AND'", |
|
| 742 | - array("'>='", |
|
| 743 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 744 | - ("date_debut_semaine($annee, $mois, $jour)")), |
|
| 745 | - array("'<='", |
|
| 746 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 747 | - ("date_fin_semaine($annee, $mois, $jour)"))); |
|
| 748 | - elseif (count($crit->param)>2) |
|
| 749 | - $boucle->where[] = array("'AND'", |
|
| 750 | - array("'>='", |
|
| 751 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 752 | - ("sql_quote($annee . $mois . $jour$quote_end)")), |
|
| 753 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)"))); |
|
| 754 | - // sinon on prend tout |
|
| 684 | + $params = $crit->param; |
|
| 685 | + |
|
| 686 | + if (count($params)<1) |
|
| 687 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 688 | + |
|
| 689 | + $parent = $boucles[$idb]->id_parent; |
|
| 690 | + |
|
| 691 | + // les valeurs $date et $type doivent etre connus a la compilation |
|
| 692 | + // autrement dit ne pas etre des champs |
|
| 693 | + |
|
| 694 | + $date = array_shift($params); |
|
| 695 | + $date = $date[0]->texte; |
|
| 696 | + |
|
| 697 | + $type = array_shift($params); |
|
| 698 | + $type = $type[0]->texte; |
|
| 699 | + |
|
| 700 | + $annee = $params ? array_shift($params) : ""; |
|
| 701 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 702 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 703 | + ') ? $x : date("Y"))'; |
|
| 704 | + |
|
| 705 | + $mois = $params ? array_shift($params) : ""; |
|
| 706 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 707 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 708 | + ') ? $x : date("m"))'; |
|
| 709 | + |
|
| 710 | + $jour = $params ? array_shift($params) : ""; |
|
| 711 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 712 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 713 | + ') ? $x : date("d"))'; |
|
| 714 | + |
|
| 715 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 716 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 717 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 718 | + ') ? $x : date("Y"))'; |
|
| 719 | + |
|
| 720 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 721 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 722 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 723 | + ') ? $x : date("m"))'; |
|
| 724 | + |
|
| 725 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 726 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 727 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 728 | + ') ? $x : date("d"))'; |
|
| 729 | + |
|
| 730 | + $boucle = &$boucles[$idb]; |
|
| 731 | + $date = $boucle->id_table.".$date"; |
|
| 732 | + |
|
| 733 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 734 | + if ($type=='jour') |
|
| 735 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 736 | + ("sql_quote($annee . $mois . $jour$quote_end)")); |
|
| 737 | + elseif ($type=='mois') |
|
| 738 | + $boucle->where[] = array("'='", "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 739 | + ("sql_quote($annee . $mois$quote_end)")); |
|
| 740 | + elseif ($type=='semaine') |
|
| 741 | + $boucle->where[] = array("'AND'", |
|
| 742 | + array("'>='", |
|
| 743 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 744 | + ("date_debut_semaine($annee, $mois, $jour)")), |
|
| 745 | + array("'<='", |
|
| 746 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 747 | + ("date_fin_semaine($annee, $mois, $jour)"))); |
|
| 748 | + elseif (count($crit->param)>2) |
|
| 749 | + $boucle->where[] = array("'AND'", |
|
| 750 | + array("'>='", |
|
| 751 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 752 | + ("sql_quote($annee . $mois . $jour$quote_end)")), |
|
| 753 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)"))); |
|
| 754 | + // sinon on prend tout |
|
| 755 | 755 | } |
| 756 | 756 | |
| 757 | 757 | // http://doc.spip.org/@calculer_critere_parties |
| 758 | 758 | function calculer_critere_parties($idb, &$boucles, $crit){ |
| 759 | - $boucle = &$boucles[$idb]; |
|
| 760 | - $a1 = $crit->param[0]; |
|
| 761 | - $a2 = $crit->param[1]; |
|
| 762 | - $op = $crit->op; |
|
| 763 | - |
|
| 764 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 765 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 766 | - |
|
| 767 | - if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
|
| 768 | - $boucle->limit = $a11.','.$a21; |
|
| 769 | - } |
|
| 770 | - else { |
|
| 771 | - $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
|
| 772 | - $partie = ($a11!='n') ? $a11 : $a12; |
|
| 773 | - $mode = (($op=='/') ? '/' : |
|
| 774 | - (($a11=='n') ? '-' : '+').(($a21=='n') ? '-' : '+')); |
|
| 775 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 776 | - if ($a11!=='n' AND $a21!=='n' AND $mode=="++" AND $op==','){ |
|
| 777 | - $boucle->limit = |
|
| 778 | - (is_numeric($a11)?"'$a11'":$a11) |
|
| 779 | - .".','." |
|
| 780 | - .(is_numeric($a21)?"'$a21'":$a21); |
|
| 781 | - } |
|
| 782 | - else |
|
| 783 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 784 | - } |
|
| 759 | + $boucle = &$boucles[$idb]; |
|
| 760 | + $a1 = $crit->param[0]; |
|
| 761 | + $a2 = $crit->param[1]; |
|
| 762 | + $op = $crit->op; |
|
| 763 | + |
|
| 764 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 765 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 766 | + |
|
| 767 | + if (($op==',') && (is_numeric($a11) && (is_numeric($a21)))){ |
|
| 768 | + $boucle->limit = $a11.','.$a21; |
|
| 769 | + } |
|
| 770 | + else { |
|
| 771 | + $boucle->total_parties = ($a21!='n') ? $a21 : $a22; |
|
| 772 | + $partie = ($a11!='n') ? $a11 : $a12; |
|
| 773 | + $mode = (($op=='/') ? '/' : |
|
| 774 | + (($a11=='n') ? '-' : '+').(($a21=='n') ? '-' : '+')); |
|
| 775 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 776 | + if ($a11!=='n' AND $a21!=='n' AND $mode=="++" AND $op==','){ |
|
| 777 | + $boucle->limit = |
|
| 778 | + (is_numeric($a11)?"'$a11'":$a11) |
|
| 779 | + .".','." |
|
| 780 | + .(is_numeric($a21)?"'$a21'":$a21); |
|
| 781 | + } |
|
| 782 | + else |
|
| 783 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 784 | + } |
|
| 785 | 785 | } |
| 786 | 786 | |
| 787 | 787 | // |
@@ -789,77 +789,77 @@ discard block |
||
| 789 | 789 | // |
| 790 | 790 | |
| 791 | 791 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode){ |
| 792 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 793 | - |
|
| 794 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 795 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 796 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 797 | - // {1/3} |
|
| 798 | - if ($op1=='/'){ |
|
| 799 | - $pmoins1 = is_numeric($debut) ? ($debut-1) : "($debut-1)"; |
|
| 800 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 801 | - "($total_parties ? $total_parties : 1)"; |
|
| 802 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 803 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 804 | - } else { |
|
| 805 | - // cas {n-1,x} |
|
| 806 | - if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 807 | - |
|
| 808 | - // cas {x,n-1} |
|
| 809 | - if ($op2=='-'){ |
|
| 810 | - $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 811 | - .(is_numeric($total_parties) ? ($total_parties+1) : |
|
| 812 | - ($total_parties.' - 1')); |
|
| 813 | - } else { |
|
| 814 | - // {x,1} ou {pagination} |
|
| 815 | - $fin = '$debut_boucle' |
|
| 816 | - .(is_numeric($total_parties) ? |
|
| 817 | - (($total_parties==1) ? "" : (' + '.($total_parties-1))) : |
|
| 818 | - ('+'.$total_parties.' - 1')); |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 822 | - if ($op1=='p'){ |
|
| 823 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 824 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 825 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - |
|
| 829 | - // Notes : |
|
| 830 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 831 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 832 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 833 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 834 | - |
|
| 835 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 836 | - .'$debut_boucle = '.$debut.";\n " |
|
| 837 | - .'$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 838 | - .'$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 839 | - .'$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 840 | - ."\n\tif (\$debut_boucle>0 AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total'] AND \$iter->seek(\$debut_boucle,'continue'))\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 841 | - |
|
| 842 | - $boucles[$id_boucle]->partie = " |
|
| 792 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 793 | + |
|
| 794 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 795 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 796 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 797 | + // {1/3} |
|
| 798 | + if ($op1=='/'){ |
|
| 799 | + $pmoins1 = is_numeric($debut) ? ($debut-1) : "($debut-1)"; |
|
| 800 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 801 | + "($total_parties ? $total_parties : 1)"; |
|
| 802 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 803 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 804 | + } else { |
|
| 805 | + // cas {n-1,x} |
|
| 806 | + if ($op1=='-') $debut = "$nombre_boucle - $debut;"; |
|
| 807 | + |
|
| 808 | + // cas {x,n-1} |
|
| 809 | + if ($op2=='-'){ |
|
| 810 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 811 | + .(is_numeric($total_parties) ? ($total_parties+1) : |
|
| 812 | + ($total_parties.' - 1')); |
|
| 813 | + } else { |
|
| 814 | + // {x,1} ou {pagination} |
|
| 815 | + $fin = '$debut_boucle' |
|
| 816 | + .(is_numeric($total_parties) ? |
|
| 817 | + (($total_parties==1) ? "" : (' + '.($total_parties-1))) : |
|
| 818 | + ('+'.$total_parties.' - 1')); |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 822 | + if ($op1=='p'){ |
|
| 823 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 824 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 825 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + |
|
| 829 | + // Notes : |
|
| 830 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 831 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 832 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 833 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 834 | + |
|
| 835 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 836 | + .'$debut_boucle = '.$debut.";\n " |
|
| 837 | + .'$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 838 | + .'$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 839 | + .'$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 840 | + ."\n\tif (\$debut_boucle>0 AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total'] AND \$iter->seek(\$debut_boucle,'continue'))\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 841 | + |
|
| 842 | + $boucles[$id_boucle]->partie = " |
|
| 843 | 843 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 844 | 844 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | // http://doc.spip.org/@calculer_critere_parties_aux |
| 848 | 848 | function calculer_critere_parties_aux($idb, &$boucles, $param){ |
| 849 | - if ($param[0]->type!='texte'){ |
|
| 850 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 851 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 852 | - return array("intval($a1)", ($m[2] ? $m[2] : 0)); |
|
| 853 | - } else { |
|
| 854 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 855 | - $a1 = $m[1]; |
|
| 856 | - if (!@$m[3]) |
|
| 857 | - return array($a1, 0); |
|
| 858 | - elseif ($m[4]) |
|
| 859 | - return array($a1, $m[4]); |
|
| 860 | - else return array($a1, |
|
| 861 | - calculer_liste(array($param[1]), array(), $boucles[$idb]->id_parent, $boucles)); |
|
| 862 | - } |
|
| 849 | + if ($param[0]->type!='texte'){ |
|
| 850 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 851 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 852 | + return array("intval($a1)", ($m[2] ? $m[2] : 0)); |
|
| 853 | + } else { |
|
| 854 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 855 | + $a1 = $m[1]; |
|
| 856 | + if (!@$m[3]) |
|
| 857 | + return array($a1, 0); |
|
| 858 | + elseif ($m[4]) |
|
| 859 | + return array($a1, $m[4]); |
|
| 860 | + else return array($a1, |
|
| 861 | + calculer_liste(array($param[1]), array(), $boucles[$idb]->id_parent, $boucles)); |
|
| 862 | + } |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | |
@@ -886,44 +886,44 @@ discard block |
||
| 886 | 886 | * array : Erreur sur un des critères |
| 887 | 887 | **/ |
| 888 | 888 | function calculer_criteres($idb, &$boucles){ |
| 889 | - $msg = ''; |
|
| 890 | - $boucle = $boucles[$idb]; |
|
| 891 | - $table = strtoupper($boucle->type_requete); |
|
| 892 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 893 | - |
|
| 894 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 895 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 896 | - if (!is_array($boucle->criteres)) return array(); |
|
| 897 | - |
|
| 898 | - foreach ($boucle->criteres as $crit){ |
|
| 899 | - $critere = $crit->op; |
|
| 900 | - // critere personnalise ? |
|
| 901 | - if ( |
|
| 902 | - (!$serveur OR |
|
| 903 | - ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 904 | - AND (!function_exists($f = $f."_dist")) |
|
| 905 | - AND (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 906 | - AND (!function_exists($f = $f."_dist")) |
|
| 907 | - ) |
|
| 908 | - ) |
|
| 909 | - AND (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 910 | - AND (!function_exists($f = $f."_dist")) |
|
| 911 | - AND (!function_exists($f = "critere_".$critere)) |
|
| 912 | - AND (!function_exists($f = $f."_dist")) |
|
| 913 | - ){ |
|
| 914 | - // fonction critere standard |
|
| 915 | - $f = $defaut; |
|
| 916 | - } |
|
| 917 | - // compile le critere |
|
| 918 | - $res = $f($idb, $boucles, $crit); |
|
| 919 | - |
|
| 920 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 921 | - if (is_array($res)){ |
|
| 922 | - $msg = $res; |
|
| 923 | - erreur_squelette($msg, $boucle); |
|
| 924 | - } |
|
| 925 | - } |
|
| 926 | - return $msg; |
|
| 889 | + $msg = ''; |
|
| 890 | + $boucle = $boucles[$idb]; |
|
| 891 | + $table = strtoupper($boucle->type_requete); |
|
| 892 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 893 | + |
|
| 894 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 895 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 896 | + if (!is_array($boucle->criteres)) return array(); |
|
| 897 | + |
|
| 898 | + foreach ($boucle->criteres as $crit){ |
|
| 899 | + $critere = $crit->op; |
|
| 900 | + // critere personnalise ? |
|
| 901 | + if ( |
|
| 902 | + (!$serveur OR |
|
| 903 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 904 | + AND (!function_exists($f = $f."_dist")) |
|
| 905 | + AND (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 906 | + AND (!function_exists($f = $f."_dist")) |
|
| 907 | + ) |
|
| 908 | + ) |
|
| 909 | + AND (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 910 | + AND (!function_exists($f = $f."_dist")) |
|
| 911 | + AND (!function_exists($f = "critere_".$critere)) |
|
| 912 | + AND (!function_exists($f = $f."_dist")) |
|
| 913 | + ){ |
|
| 914 | + // fonction critere standard |
|
| 915 | + $f = $defaut; |
|
| 916 | + } |
|
| 917 | + // compile le critere |
|
| 918 | + $res = $f($idb, $boucles, $crit); |
|
| 919 | + |
|
| 920 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 921 | + if (is_array($res)){ |
|
| 922 | + $msg = $res; |
|
| 923 | + erreur_squelette($msg, $boucle); |
|
| 924 | + } |
|
| 925 | + } |
|
| 926 | + return $msg; |
|
| 927 | 927 | } |
| 928 | 928 | |
| 929 | 929 | /** |
@@ -938,80 +938,80 @@ discard block |
||
| 938 | 938 | * @return string |
| 939 | 939 | */ |
| 940 | 940 | function kwote($lisp, $serveur='', $type=''){ |
| 941 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) |
|
| 942 | - return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 943 | - else |
|
| 944 | - return "sql_quote($lisp)"; |
|
| 941 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) |
|
| 942 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]),$serveur,$type)."\""; |
|
| 943 | + else |
|
| 944 | + return "sql_quote($lisp)"; |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | // Si on a une liste de valeurs dans #ENV{x}, utiliser la double etoile |
| 948 | 948 | // pour faire par exemple {id_article IN #ENV**{liste_articles}} |
| 949 | 949 | // http://doc.spip.org/@critere_IN_dist |
| 950 | 950 | function critere_IN_dist($idb, &$boucles, $crit){ |
| 951 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 952 | - if (!$r){ |
|
| 953 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 954 | - } |
|
| 955 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 956 | - |
|
| 957 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 958 | - |
|
| 959 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 960 | - $where = $in; |
|
| 961 | - if ($crit->cond){ |
|
| 962 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 963 | - $where = array("'?'", $pred, $where, "''"); |
|
| 964 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 965 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 966 | - } |
|
| 967 | - if ($crit->exclus) |
|
| 968 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 969 | - $where = array("'NOT'", $where); |
|
| 970 | - else |
|
| 971 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 972 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 973 | - $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 974 | - |
|
| 975 | - $boucles[$idb]->where[] = $where; |
|
| 976 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 977 | - $boucles[$idb]->where[] = $where_complement; |
|
| 951 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 952 | + if (!$r){ |
|
| 953 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 954 | + } |
|
| 955 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 956 | + |
|
| 957 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 958 | + |
|
| 959 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 960 | + $where = $in; |
|
| 961 | + if ($crit->cond){ |
|
| 962 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 963 | + $where = array("'?'", $pred, $where, "''"); |
|
| 964 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 965 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 966 | + } |
|
| 967 | + if ($crit->exclus) |
|
| 968 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 969 | + $where = array("'NOT'", $where); |
|
| 970 | + else |
|
| 971 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 972 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 973 | + $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 974 | + |
|
| 975 | + $boucles[$idb]->where[] = $where; |
|
| 976 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 977 | + $boucles[$idb]->where[] = $where_complement; |
|
| 978 | 978 | } |
| 979 | 979 | |
| 980 | 980 | // http://doc.spip.org/@critere_IN_cas |
| 981 | 981 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col){ |
| 982 | - static $num = array(); |
|
| 983 | - $descr = $boucles[$idb]->descr; |
|
| 984 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 985 | - |
|
| 986 | - $var = '$in'.$cpt++; |
|
| 987 | - $x = "\n\t$var = array();"; |
|
| 988 | - foreach ($val as $k => $v){ |
|
| 989 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
|
| 990 | - // optimiser le traitement des constantes |
|
| 991 | - if (is_numeric($r[2])) |
|
| 992 | - $x .= "\n\t$var"."[]= $r[2];"; |
|
| 993 | - else |
|
| 994 | - $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 995 | - } else { |
|
| 996 | - // Pour permettre de passer des tableaux de valeurs |
|
| 997 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 998 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 999 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1000 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - $boucles[$idb]->in .= $x; |
|
| 1005 | - |
|
| 1006 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1007 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un rexgexp) |
|
| 1008 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1009 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1010 | - if (!$crit2){ |
|
| 1011 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1012 | - } |
|
| 1013 | - |
|
| 1014 | - return "sql_in('$arg',sql_quote($var)".($crit2=='NOT' ? ",'NOT'" : "").")"; |
|
| 982 | + static $num = array(); |
|
| 983 | + $descr = $boucles[$idb]->descr; |
|
| 984 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 985 | + |
|
| 986 | + $var = '$in'.$cpt++; |
|
| 987 | + $x = "\n\t$var = array();"; |
|
| 988 | + foreach ($val as $k => $v){ |
|
| 989 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)){ |
|
| 990 | + // optimiser le traitement des constantes |
|
| 991 | + if (is_numeric($r[2])) |
|
| 992 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 993 | + else |
|
| 994 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 995 | + } else { |
|
| 996 | + // Pour permettre de passer des tableaux de valeurs |
|
| 997 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 998 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 999 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1000 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + $boucles[$idb]->in .= $x; |
|
| 1005 | + |
|
| 1006 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1007 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un rexgexp) |
|
| 1008 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1009 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1010 | + if (!$crit2){ |
|
| 1011 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1012 | + } |
|
| 1013 | + |
|
| 1014 | + return "sql_in('$arg',sql_quote($var)".($crit2=='NOT' ? ",'NOT'" : "").")"; |
|
| 1015 | 1015 | } |
| 1016 | 1016 | |
| 1017 | 1017 | /** |
@@ -1023,19 +1023,19 @@ discard block |
||
| 1023 | 1023 | * @param <type> $crit |
| 1024 | 1024 | */ |
| 1025 | 1025 | function critere_where_dist($idb, &$boucles, $crit){ |
| 1026 | - $boucle = &$boucles[$idb]; |
|
| 1027 | - if (isset($crit->param[0])) |
|
| 1028 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1029 | - else |
|
| 1030 | - $_where = '@$Pile[0]["where"]'; |
|
| 1026 | + $boucle = &$boucles[$idb]; |
|
| 1027 | + if (isset($crit->param[0])) |
|
| 1028 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1029 | + else |
|
| 1030 | + $_where = '@$Pile[0]["where"]'; |
|
| 1031 | 1031 | |
| 1032 | - if ($crit->cond) |
|
| 1033 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1032 | + if ($crit->cond) |
|
| 1033 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1034 | 1034 | |
| 1035 | - if ($crit->not) |
|
| 1036 | - $_where = "array('NOT',$_where)"; |
|
| 1035 | + if ($crit->not) |
|
| 1036 | + $_where = "array('NOT',$_where)"; |
|
| 1037 | 1037 | |
| 1038 | - $boucle->where[] = $_where; |
|
| 1038 | + $boucle->where[] = $_where; |
|
| 1039 | 1039 | } |
| 1040 | 1040 | |
| 1041 | 1041 | |
@@ -1085,27 +1085,27 @@ discard block |
||
| 1085 | 1085 | * @param unknown_type $crit |
| 1086 | 1086 | */ |
| 1087 | 1087 | function critere_tri_dist($idb, &$boucles, $crit){ |
| 1088 | - $boucle = &$boucles[$idb]; |
|
| 1089 | - |
|
| 1090 | - // definition du champ par defaut |
|
| 1091 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1092 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1093 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1094 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1095 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1096 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1097 | - |
|
| 1098 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:$_champ_defaut)?tri_protege_champ(\$t):'')"; |
|
| 1099 | - |
|
| 1100 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1101 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:$_sens_defaut)==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1102 | - |
|
| 1103 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1104 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1105 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1106 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1107 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1108 | - $boucle->hash .= " |
|
| 1088 | + $boucle = &$boucles[$idb]; |
|
| 1089 | + |
|
| 1090 | + // definition du champ par defaut |
|
| 1091 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1092 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1093 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1094 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1095 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1096 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1097 | + |
|
| 1098 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:$_champ_defaut)?tri_protege_champ(\$t):'')"; |
|
| 1099 | + |
|
| 1100 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1101 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:$_sens_defaut)==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1102 | + |
|
| 1103 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1104 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1105 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1106 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1107 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1108 | + $boucle->hash .= " |
|
| 1109 | 1109 | \$senstri = ''; |
| 1110 | 1110 | \$tri = $_tri; |
| 1111 | 1111 | if (\$tri){ |
@@ -1113,264 +1113,264 @@ discard block |
||
| 1113 | 1113 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1114 | 1114 | }; |
| 1115 | 1115 | "; |
| 1116 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1117 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1116 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1117 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | # Criteres de comparaison |
| 1121 | 1121 | |
| 1122 | 1122 | // http://doc.spip.org/@calculer_critere_DEFAUT |
| 1123 | 1123 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit){ |
| 1124 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1125 | - if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1126 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1127 | - |
|
| 1128 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1129 | - if (!$r){ |
|
| 1130 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1131 | - # if (!$crit->cond) { |
|
| 1132 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1133 | - # } |
|
| 1134 | - } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1124 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1125 | + if (($crit->op==",") OR ($crit->op=='/')) |
|
| 1126 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1127 | + |
|
| 1128 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1129 | + if (!$r){ |
|
| 1130 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1131 | + # if (!$crit->cond) { |
|
| 1132 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1133 | + # } |
|
| 1134 | + } else calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1135 | 1135 | } |
| 1136 | 1136 | |
| 1137 | 1137 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args){ |
| 1138 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1139 | - |
|
| 1140 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1141 | - |
|
| 1142 | - // inserer la negation (cf !...) |
|
| 1143 | - |
|
| 1144 | - if ($crit->not) $where = array("'NOT'", $where); |
|
| 1145 | - if ($crit->exclus) |
|
| 1146 | - if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1147 | - $where = array("'NOT'", $where); |
|
| 1148 | - else |
|
| 1149 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1150 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1151 | - $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 1152 | - |
|
| 1153 | - // inserer la condition (cf {lang?}) |
|
| 1154 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1155 | - if ($crit->cond){ |
|
| 1156 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1157 | - if ($col=="date" OR $col=="date_redac"){ |
|
| 1158 | - if ($pred=="\$Pile[0]['".$col."']"){ |
|
| 1159 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1160 | - } |
|
| 1161 | - } |
|
| 1162 | - |
|
| 1163 | - if ($op=='=' AND !$crit->not) |
|
| 1164 | - $where = array("'?'", "(is_array($pred))", |
|
| 1165 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1166 | - $where); |
|
| 1167 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1168 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1169 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - $boucles[$idb]->where[] = $where; |
|
| 1173 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1174 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1138 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1139 | + |
|
| 1140 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1141 | + |
|
| 1142 | + // inserer la negation (cf !...) |
|
| 1143 | + |
|
| 1144 | + if ($crit->not) $where = array("'NOT'", $where); |
|
| 1145 | + if ($crit->exclus) |
|
| 1146 | + if (!preg_match(",^L[0-9]+[.],", $arg)) |
|
| 1147 | + $where = array("'NOT'", $where); |
|
| 1148 | + else |
|
| 1149 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1150 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1151 | + $where = array("'NOT'", array("'IN'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where))); |
|
| 1152 | + |
|
| 1153 | + // inserer la condition (cf {lang?}) |
|
| 1154 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1155 | + if ($crit->cond){ |
|
| 1156 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1157 | + if ($col=="date" OR $col=="date_redac"){ |
|
| 1158 | + if ($pred=="\$Pile[0]['".$col."']"){ |
|
| 1159 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1160 | + } |
|
| 1161 | + } |
|
| 1162 | + |
|
| 1163 | + if ($op=='=' AND !$crit->not) |
|
| 1164 | + $where = array("'?'", "(is_array($pred))", |
|
| 1165 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1166 | + $where); |
|
| 1167 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1168 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1169 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + $boucles[$idb]->where[] = $where; |
|
| 1173 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1174 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1175 | 1175 | } |
| 1176 | 1176 | |
| 1177 | 1177 | // http://doc.spip.org/@calculer_critere_infixe |
| 1178 | 1178 | function calculer_critere_infixe($idb, &$boucles, $crit){ |
| 1179 | 1179 | |
| 1180 | - global $table_criteres_infixes; |
|
| 1181 | - global $exceptions_des_jointures, $exceptions_des_tables; |
|
| 1182 | - |
|
| 1183 | - $boucle = &$boucles[$idb]; |
|
| 1184 | - $type = $boucle->type_requete; |
|
| 1185 | - $table = $boucle->id_table; |
|
| 1186 | - $desc = $boucle->show; |
|
| 1187 | - $col_vraie = null; |
|
| 1188 | - |
|
| 1189 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1190 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1191 | - |
|
| 1192 | - $col_alias = $col; |
|
| 1193 | - $where_complement = false; |
|
| 1194 | - |
|
| 1195 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1196 | - if ($col=='id_enfant') |
|
| 1197 | - $col = $boucle->primary; |
|
| 1198 | - |
|
| 1199 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1200 | - if (in_array($col,array('id_parent','id_secteur')) |
|
| 1201 | - AND isset($exceptions_des_tables[$table][$col])) |
|
| 1202 | - $col = $exceptions_des_tables[$table][$col]; |
|
| 1203 | - |
|
| 1204 | - // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1205 | - else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
|
| 1206 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1207 | - } |
|
| 1208 | - |
|
| 1209 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1210 | - // sauf si exception declaree : sauter cette etape |
|
| 1211 | - else if ( |
|
| 1212 | - !isset($exceptions_des_jointures[table_objet_sql($table)][$col]) |
|
| 1213 | - AND !isset($exceptions_des_jointures[$col]) |
|
| 1214 | - AND count(trouver_champs_decomposes($col, $desc))>1 |
|
| 1215 | - ){ |
|
| 1216 | - $e = decompose_champ_id_objet($col); |
|
| 1217 | - $col = array_shift($e); |
|
| 1218 | - $where_complement = primary_doublee($e, $table); |
|
| 1219 | - } |
|
| 1220 | - // Cas particulier : expressions de date |
|
| 1221 | - else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
|
| 1222 | - list($col,$col_vraie) = $c; |
|
| 1223 | - $table = ''; |
|
| 1224 | - } |
|
| 1225 | - else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1226 | - list(, $table, $col) = $r; |
|
| 1227 | - $col_alias = $col; |
|
| 1228 | - |
|
| 1229 | - $trouver_table = charger_fonction('trouver_table','base'); |
|
| 1230 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1231 | - AND isset($desc['field'][$col]) |
|
| 1232 | - AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1233 | - $table = $cle; |
|
| 1234 | - else { |
|
| 1235 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
|
| 1236 | - } |
|
| 1237 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1238 | - if (!$table) return ''; |
|
| 1239 | - } |
|
| 1240 | - elseif (@!array_key_exists($col, $desc['field']) |
|
| 1241 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1242 | - AND @!array_key_exists('*', $desc['field']) |
|
| 1243 | - ) { |
|
| 1244 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1245 | - if (!$r) return ''; |
|
| 1246 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1247 | - } |
|
| 1248 | - |
|
| 1249 | - $col_vraie = ($col_vraie?$col_vraie:$col); |
|
| 1250 | - // Dans tous les cas, |
|
| 1251 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) et passer dans sql_quote avec le type si connu |
|
| 1252 | - // et int sinon si la valeur est numerique |
|
| 1253 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1254 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1255 | - if ($op=='=' OR in_array($op, $table_criteres_infixes)){ |
|
| 1256 | - |
|
| 1257 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1258 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1259 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
|
| 1260 | - $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1261 | - |
|
| 1262 | - // sinon expliciter les |
|
| 1263 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1264 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1265 | - // sans toucher aux |
|
| 1266 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1267 | - // sql_quote(truc,'','varchar') |
|
| 1268 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1269 | - // si pas deja un type |
|
| 1270 | - AND (!isset($r[3]) OR !$r[3])) { |
|
| 1271 | - $r = $r[1] |
|
| 1272 | - .((isset($r[2]) AND $r[2]) ? $r[2] : ",''") |
|
| 1273 | - .",'".(isset($desc['field'][$col_vraie])?addslashes($desc['field'][$col_vraie]):'int NOT NULL')."'"; |
|
| 1274 | - $val[0] = "sql_quote($r)"; |
|
| 1275 | - } |
|
| 1276 | - } |
|
| 1277 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1278 | - // leurs requetes par defaut, notamment le champ statut |
|
| 1279 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 1280 | - if ($table===$boucle->id_table){ |
|
| 1281 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1282 | - if ($col_alias!=$col_vraie) |
|
| 1283 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1284 | - } |
|
| 1285 | - |
|
| 1286 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1287 | - // il faut alors interdire a la fonction de boucle |
|
| 1288 | - // de mettre ses propres criteres de statut |
|
| 1289 | - // http://www.spip.net/@statut (a documenter) |
|
| 1290 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1291 | - if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1292 | - |
|
| 1293 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 1294 | - if ($table){ |
|
| 1295 | - if ($col[0]=="`") |
|
| 1296 | - $arg = "$table.".substr($col, 1, -1); |
|
| 1297 | - else $arg = "$table.$col"; |
|
| 1298 | - } else $arg = $col; |
|
| 1299 | - |
|
| 1300 | - // inserer la fonction SQL |
|
| 1301 | - if ($fct) $arg = "$fct($arg$args_sql)"; |
|
| 1302 | - |
|
| 1303 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1180 | + global $table_criteres_infixes; |
|
| 1181 | + global $exceptions_des_jointures, $exceptions_des_tables; |
|
| 1182 | + |
|
| 1183 | + $boucle = &$boucles[$idb]; |
|
| 1184 | + $type = $boucle->type_requete; |
|
| 1185 | + $table = $boucle->id_table; |
|
| 1186 | + $desc = $boucle->show; |
|
| 1187 | + $col_vraie = null; |
|
| 1188 | + |
|
| 1189 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1190 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1191 | + |
|
| 1192 | + $col_alias = $col; |
|
| 1193 | + $where_complement = false; |
|
| 1194 | + |
|
| 1195 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1196 | + if ($col=='id_enfant') |
|
| 1197 | + $col = $boucle->primary; |
|
| 1198 | + |
|
| 1199 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1200 | + if (in_array($col,array('id_parent','id_secteur')) |
|
| 1201 | + AND isset($exceptions_des_tables[$table][$col])) |
|
| 1202 | + $col = $exceptions_des_tables[$table][$col]; |
|
| 1203 | + |
|
| 1204 | + // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1205 | + else if (($col=='id_secteur') AND ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))){ |
|
| 1206 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1207 | + } |
|
| 1208 | + |
|
| 1209 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1210 | + // sauf si exception declaree : sauter cette etape |
|
| 1211 | + else if ( |
|
| 1212 | + !isset($exceptions_des_jointures[table_objet_sql($table)][$col]) |
|
| 1213 | + AND !isset($exceptions_des_jointures[$col]) |
|
| 1214 | + AND count(trouver_champs_decomposes($col, $desc))>1 |
|
| 1215 | + ){ |
|
| 1216 | + $e = decompose_champ_id_objet($col); |
|
| 1217 | + $col = array_shift($e); |
|
| 1218 | + $where_complement = primary_doublee($e, $table); |
|
| 1219 | + } |
|
| 1220 | + // Cas particulier : expressions de date |
|
| 1221 | + else if ($c = calculer_critere_infixe_date($idb, $boucles, $col)){ |
|
| 1222 | + list($col,$col_vraie) = $c; |
|
| 1223 | + $table = ''; |
|
| 1224 | + } |
|
| 1225 | + else if (preg_match('/^(.*)\.(.*)$/', $col, $r)){ |
|
| 1226 | + list(, $table, $col) = $r; |
|
| 1227 | + $col_alias = $col; |
|
| 1228 | + |
|
| 1229 | + $trouver_table = charger_fonction('trouver_table','base'); |
|
| 1230 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1231 | + AND isset($desc['field'][$col]) |
|
| 1232 | + AND $cle = array_search($desc['table'],$boucle->from)) |
|
| 1233 | + $table = $cle; |
|
| 1234 | + else { |
|
| 1235 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond OR $op!='=')); |
|
| 1236 | + } |
|
| 1237 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1238 | + if (!$table) return ''; |
|
| 1239 | + } |
|
| 1240 | + elseif (@!array_key_exists($col, $desc['field']) |
|
| 1241 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1242 | + AND @!array_key_exists('*', $desc['field']) |
|
| 1243 | + ) { |
|
| 1244 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1245 | + if (!$r) return ''; |
|
| 1246 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1247 | + } |
|
| 1248 | + |
|
| 1249 | + $col_vraie = ($col_vraie?$col_vraie:$col); |
|
| 1250 | + // Dans tous les cas, |
|
| 1251 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) et passer dans sql_quote avec le type si connu |
|
| 1252 | + // et int sinon si la valeur est numerique |
|
| 1253 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1254 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1255 | + if ($op=='=' OR in_array($op, $table_criteres_infixes)){ |
|
| 1256 | + |
|
| 1257 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1258 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1259 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) |
|
| 1260 | + $val[0] = $r[1].'"'.sql_quote($r[2],$boucle->sql_serveur,(isset($desc['field'][$col_vraie])?$desc['field'][$col_vraie]:'int NOT NULL')).'"'; |
|
| 1261 | + |
|
| 1262 | + // sinon expliciter les |
|
| 1263 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1264 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1265 | + // sans toucher aux |
|
| 1266 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1267 | + // sql_quote(truc,'','varchar') |
|
| 1268 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1269 | + // si pas deja un type |
|
| 1270 | + AND (!isset($r[3]) OR !$r[3])) { |
|
| 1271 | + $r = $r[1] |
|
| 1272 | + .((isset($r[2]) AND $r[2]) ? $r[2] : ",''") |
|
| 1273 | + .",'".(isset($desc['field'][$col_vraie])?addslashes($desc['field'][$col_vraie]):'int NOT NULL')."'"; |
|
| 1274 | + $val[0] = "sql_quote($r)"; |
|
| 1275 | + } |
|
| 1276 | + } |
|
| 1277 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1278 | + // leurs requetes par defaut, notamment le champ statut |
|
| 1279 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 1280 | + if ($table===$boucle->id_table){ |
|
| 1281 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1282 | + if ($col_alias!=$col_vraie) |
|
| 1283 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1284 | + } |
|
| 1285 | + |
|
| 1286 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1287 | + // il faut alors interdire a la fonction de boucle |
|
| 1288 | + // de mettre ses propres criteres de statut |
|
| 1289 | + // http://www.spip.net/@statut (a documenter) |
|
| 1290 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1291 | + if ($col=='statut') $boucles[$idb]->statut = true; |
|
| 1292 | + |
|
| 1293 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 1294 | + if ($table){ |
|
| 1295 | + if ($col[0]=="`") |
|
| 1296 | + $arg = "$table.".substr($col, 1, -1); |
|
| 1297 | + else $arg = "$table.$col"; |
|
| 1298 | + } else $arg = $col; |
|
| 1299 | + |
|
| 1300 | + // inserer la fonction SQL |
|
| 1301 | + if ($fct) $arg = "$fct($arg$args_sql)"; |
|
| 1302 | + |
|
| 1303 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1304 | 1304 | } |
| 1305 | 1305 | |
| 1306 | 1306 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table){ |
| 1307 | - global $exceptions_des_jointures; |
|
| 1308 | - $where = ''; |
|
| 1309 | - |
|
| 1310 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 1311 | - // gestion par les plugins des jointures tordues |
|
| 1312 | - // pas automatiques mais necessaires |
|
| 1313 | - $table_sql = table_objet_sql($table); |
|
| 1314 | - if (isset($exceptions_des_jointures[$table_sql]) |
|
| 1315 | - AND is_array($exceptions_des_jointures[$table_sql]) |
|
| 1316 | - AND |
|
| 1317 | - ( |
|
| 1318 | - isset($exceptions_des_jointures[$table_sql][$col]) |
|
| 1319 | - OR |
|
| 1320 | - isset($exceptions_des_jointures[$table_sql]['']) |
|
| 1321 | - ) |
|
| 1322 | - ){ |
|
| 1323 | - $t = $exceptions_des_jointures[$table_sql]; |
|
| 1324 | - $index = isset($t[$col]) |
|
| 1325 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 1326 | - |
|
| 1327 | - if (count($index)==3) |
|
| 1328 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 1329 | - elseif (count($index)==2) { |
|
| 1330 | - list($t, $col) = $t[$col]; |
|
| 1331 | - } |
|
| 1332 | - elseif (count($index)==1) { |
|
| 1333 | - list($calculer_critere_externe) = $index; |
|
| 1334 | - $t = $table; |
|
| 1335 | - } |
|
| 1336 | - else |
|
| 1337 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1338 | - } |
|
| 1339 | - elseif (isset($exceptions_des_jointures[$col])) |
|
| 1340 | - list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1341 | - else |
|
| 1342 | - $t = ''; // jointure non declaree. La trouver. |
|
| 1343 | - |
|
| 1344 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 1345 | - |
|
| 1346 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 1347 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 1348 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 1349 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 1350 | - $table = ""; |
|
| 1351 | - if ($boucle->jointures_explicites){ |
|
| 1352 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 1353 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 1357 | - if (!$table) { |
|
| 1358 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1359 | - } |
|
| 1360 | - |
|
| 1361 | - if (!$table) return ''; |
|
| 1362 | - |
|
| 1363 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 1364 | - list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 1365 | - |
|
| 1366 | - if (count(trouver_champs_decomposes($col, $desc))>1){ |
|
| 1367 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 1368 | - $e = decompose_champ_id_objet($col); |
|
| 1369 | - $col = array_shift($e); |
|
| 1370 | - $where = primary_doublee($e, $table); |
|
| 1371 | - } |
|
| 1372 | - |
|
| 1373 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 1307 | + global $exceptions_des_jointures; |
|
| 1308 | + $where = ''; |
|
| 1309 | + |
|
| 1310 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 1311 | + // gestion par les plugins des jointures tordues |
|
| 1312 | + // pas automatiques mais necessaires |
|
| 1313 | + $table_sql = table_objet_sql($table); |
|
| 1314 | + if (isset($exceptions_des_jointures[$table_sql]) |
|
| 1315 | + AND is_array($exceptions_des_jointures[$table_sql]) |
|
| 1316 | + AND |
|
| 1317 | + ( |
|
| 1318 | + isset($exceptions_des_jointures[$table_sql][$col]) |
|
| 1319 | + OR |
|
| 1320 | + isset($exceptions_des_jointures[$table_sql]['']) |
|
| 1321 | + ) |
|
| 1322 | + ){ |
|
| 1323 | + $t = $exceptions_des_jointures[$table_sql]; |
|
| 1324 | + $index = isset($t[$col]) |
|
| 1325 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 1326 | + |
|
| 1327 | + if (count($index)==3) |
|
| 1328 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 1329 | + elseif (count($index)==2) { |
|
| 1330 | + list($t, $col) = $t[$col]; |
|
| 1331 | + } |
|
| 1332 | + elseif (count($index)==1) { |
|
| 1333 | + list($calculer_critere_externe) = $index; |
|
| 1334 | + $t = $table; |
|
| 1335 | + } |
|
| 1336 | + else |
|
| 1337 | + $t = ''; // jointure non declaree. La trouver. |
|
| 1338 | + } |
|
| 1339 | + elseif (isset($exceptions_des_jointures[$col])) |
|
| 1340 | + list($t, $col) = $exceptions_des_jointures[$col]; |
|
| 1341 | + else |
|
| 1342 | + $t = ''; // jointure non declaree. La trouver. |
|
| 1343 | + |
|
| 1344 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 1345 | + |
|
| 1346 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 1347 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 1348 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 1349 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 1350 | + $table = ""; |
|
| 1351 | + if ($boucle->jointures_explicites){ |
|
| 1352 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 1353 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 1357 | + if (!$table) { |
|
| 1358 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond OR $op!='='), $t); |
|
| 1359 | + } |
|
| 1360 | + |
|
| 1361 | + if (!$table) return ''; |
|
| 1362 | + |
|
| 1363 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 1364 | + list($nom, $desc) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 1365 | + |
|
| 1366 | + if (count(trouver_champs_decomposes($col, $desc))>1){ |
|
| 1367 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 1368 | + $e = decompose_champ_id_objet($col); |
|
| 1369 | + $col = array_shift($e); |
|
| 1370 | + $where = primary_doublee($e, $table); |
|
| 1371 | + } |
|
| 1372 | + |
|
| 1373 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | // Ne pas appliquer sql_quote lors de la compilation, |
@@ -1378,9 +1378,9 @@ discard block |
||
| 1378 | 1378 | |
| 1379 | 1379 | // http://doc.spip.org/@primary_doublee |
| 1380 | 1380 | function primary_doublee($decompose, $table){ |
| 1381 | - $e1 = reset($decompose); |
|
| 1382 | - $e2 = "sql_quote('".end($decompose)."')"; |
|
| 1383 | - return array("'='", "'$table.".$e1."'", $e2); |
|
| 1381 | + $e1 = reset($decompose); |
|
| 1382 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 1383 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 1384 | 1384 | } |
| 1385 | 1385 | |
| 1386 | 1386 | /** |
@@ -1403,43 +1403,43 @@ discard block |
||
| 1403 | 1403 | * @return mixed|string |
| 1404 | 1404 | */ |
| 1405 | 1405 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
| 1406 | - // si on demande un truc du genre spip_mots |
|
| 1407 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 1408 | - // et qu'on est la |
|
| 1409 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 1410 | - if ($checkarrivee |
|
| 1411 | - AND is_string($checkarrivee) |
|
| 1412 | - AND $a = table_objet($checkarrivee) |
|
| 1413 | - AND in_array($a.'_liens', $joints) |
|
| 1414 | - ){ |
|
| 1415 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 1416 | - return $res; |
|
| 1417 | - } |
|
| 1418 | - } |
|
| 1419 | - foreach ($joints as $joint){ |
|
| 1420 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)){ |
|
| 1421 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 1422 | - // transformer eventuellement id_xx en (id_objet,objet) |
|
| 1423 | - $cols = trouver_champs_decomposes($col, $arrivee[1]); |
|
| 1424 | - if ($t){ |
|
| 1425 | - $joindre = false; |
|
| 1426 | - foreach ($cols as $col){ |
|
| 1427 | - $c = '/\b'.$t.".$col".'\b/'; |
|
| 1428 | - if (trouver_champ($c, $boucle->where)) $joindre = true; |
|
| 1429 | - else { |
|
| 1430 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 1431 | - $c = "/FIELD.$t".".$col,/"; |
|
| 1432 | - if (trouver_champ($c, $boucle->select)) $joindre = true; |
|
| 1433 | - } |
|
| 1434 | - } |
|
| 1435 | - if (!$joindre) return $t; |
|
| 1436 | - } |
|
| 1437 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 1438 | - return $res; |
|
| 1439 | - } |
|
| 1440 | - } |
|
| 1441 | - } |
|
| 1442 | - return ''; |
|
| 1406 | + // si on demande un truc du genre spip_mots |
|
| 1407 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 1408 | + // et qu'on est la |
|
| 1409 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 1410 | + if ($checkarrivee |
|
| 1411 | + AND is_string($checkarrivee) |
|
| 1412 | + AND $a = table_objet($checkarrivee) |
|
| 1413 | + AND in_array($a.'_liens', $joints) |
|
| 1414 | + ){ |
|
| 1415 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 1416 | + return $res; |
|
| 1417 | + } |
|
| 1418 | + } |
|
| 1419 | + foreach ($joints as $joint){ |
|
| 1420 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)){ |
|
| 1421 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 1422 | + // transformer eventuellement id_xx en (id_objet,objet) |
|
| 1423 | + $cols = trouver_champs_decomposes($col, $arrivee[1]); |
|
| 1424 | + if ($t){ |
|
| 1425 | + $joindre = false; |
|
| 1426 | + foreach ($cols as $col){ |
|
| 1427 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 1428 | + if (trouver_champ($c, $boucle->where)) $joindre = true; |
|
| 1429 | + else { |
|
| 1430 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 1431 | + $c = "/FIELD.$t".".$col,/"; |
|
| 1432 | + if (trouver_champ($c, $boucle->select)) $joindre = true; |
|
| 1433 | + } |
|
| 1434 | + } |
|
| 1435 | + if (!$joindre) return $t; |
|
| 1436 | + } |
|
| 1437 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 1438 | + return $res; |
|
| 1439 | + } |
|
| 1440 | + } |
|
| 1441 | + } |
|
| 1442 | + return ''; |
|
| 1443 | 1443 | |
| 1444 | 1444 | } |
| 1445 | 1445 | |
@@ -1455,33 +1455,33 @@ discard block |
||
| 1455 | 1455 | * @return string |
| 1456 | 1456 | */ |
| 1457 | 1457 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false){ |
| 1458 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 1458 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 1459 | 1459 | |
| 1460 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 1461 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 1460 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 1461 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 1462 | 1462 | |
| 1463 | - if (!$intermediaire OR !$arrivee) return ''; |
|
| 1463 | + if (!$intermediaire OR !$arrivee) return ''; |
|
| 1464 | 1464 | |
| 1465 | - $res = fabrique_jointures($boucle, |
|
| 1466 | - array( |
|
| 1467 | - array($boucle->id_table, $intermediaire, array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type'])), |
|
| 1468 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 1469 | - ) |
|
| 1470 | - , $cond, $desc, $boucle->id_table, array($col)); |
|
| 1471 | - return $res; |
|
| 1465 | + $res = fabrique_jointures($boucle, |
|
| 1466 | + array( |
|
| 1467 | + array($boucle->id_table, $intermediaire, array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type'])), |
|
| 1468 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 1469 | + ) |
|
| 1470 | + , $cond, $desc, $boucle->id_table, array($col)); |
|
| 1471 | + return $res; |
|
| 1472 | 1472 | } |
| 1473 | 1473 | |
| 1474 | 1474 | |
| 1475 | 1475 | // http://doc.spip.org/@trouver_champ |
| 1476 | 1476 | function trouver_champ($champ, $where){ |
| 1477 | - if (!is_array($where)) |
|
| 1478 | - return preg_match($champ, $where); |
|
| 1479 | - else { |
|
| 1480 | - foreach ($where as $clause){ |
|
| 1481 | - if (trouver_champ($champ, $clause)) return true; |
|
| 1482 | - } |
|
| 1483 | - return false; |
|
| 1484 | - } |
|
| 1477 | + if (!is_array($where)) |
|
| 1478 | + return preg_match($champ, $where); |
|
| 1479 | + else { |
|
| 1480 | + foreach ($where as $clause){ |
|
| 1481 | + if (trouver_champ($champ, $clause)) return true; |
|
| 1482 | + } |
|
| 1483 | + return false; |
|
| 1484 | + } |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | |
@@ -1489,227 +1489,227 @@ discard block |
||
| 1489 | 1489 | |
| 1490 | 1490 | // http://doc.spip.org/@calculer_critere_infixe_ops |
| 1491 | 1491 | function calculer_critere_infixe_ops($idb, &$boucles, $crit){ |
| 1492 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 1493 | - if (count($crit->param)==0){ |
|
| 1494 | - $op = '='; |
|
| 1495 | - $col = $val = $crit->op; |
|
| 1496 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
|
| 1497 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 1498 | - if ($val=='lang') |
|
| 1499 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1500 | - else { |
|
| 1501 | - $defaut = null; |
|
| 1502 | - if ($val=='id_parent') { |
|
| 1503 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 1504 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 1505 | - // pour eviter l'erreur SQL |
|
| 1506 | - $val = $boucles[$idb]->primary; |
|
| 1507 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 1508 | - $defaut = "\$Pile[0]['id_parent']"; |
|
| 1509 | - } |
|
| 1510 | - elseif ($val=='id_enfant'){ |
|
| 1511 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 1512 | - // de la boucle superieure |
|
| 1513 | - $val = 'id_parent'; |
|
| 1514 | - } |
|
| 1515 | - elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1516 | - // un critere conditionnel sur date est traite a part |
|
| 1517 | - // car la date est mise d'office par SPIP, |
|
| 1518 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 1519 | - } |
|
| 1520 | - |
|
| 1521 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 1522 | - $val = array(kwote($val)); |
|
| 1523 | - } |
|
| 1524 | - } else { |
|
| 1525 | - // comparaison explicite |
|
| 1526 | - // le phraseur impose que le premier param soit du texte |
|
| 1527 | - $params = $crit->param; |
|
| 1528 | - $op = $crit->op; |
|
| 1529 | - if ($op=='==') $op = 'REGEXP'; |
|
| 1530 | - $col = array_shift($params); |
|
| 1531 | - $col = $col[0]->texte; |
|
| 1532 | - |
|
| 1533 | - $val = array(); |
|
| 1534 | - $desc = array('id_mere' => $idb); |
|
| 1535 | - $parent = $boucles[$idb]->id_parent; |
|
| 1536 | - |
|
| 1537 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 1538 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 1539 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 1540 | - if (count($params)==1 |
|
| 1541 | - AND count($params[0]==3) |
|
| 1542 | - AND $params[0][0]->type=='texte' |
|
| 1543 | - AND @$params[0][2]->type=='texte' |
|
| 1544 | - AND ($p = $params[0][0]->texte)==$params[0][2]->texte |
|
| 1545 | - AND (($p=="'") OR ($p=='"')) |
|
| 1546 | - AND $params[0][1]->type=='champ' |
|
| 1547 | - ){ |
|
| 1548 | - $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 1549 | - } else |
|
| 1550 | - foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1551 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 1552 | - if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1553 | - else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
|
| 1554 | - } |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - $fct = $args_sql = ''; |
|
| 1558 | - // fonction SQL ? |
|
| 1559 | - if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)){ |
|
| 1560 | - $fct = $m[1]; |
|
| 1561 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 1562 | - $col = $a[1]; |
|
| 1563 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)){ |
|
| 1564 | - $col = $m[1]; |
|
| 1565 | - $args_sql = $m[2]; |
|
| 1566 | - } |
|
| 1567 | - $args_sql .= $a[2]; |
|
| 1568 | - ; |
|
| 1569 | - } |
|
| 1570 | - |
|
| 1571 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 1492 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 1493 | + if (count($crit->param)==0){ |
|
| 1494 | + $op = '='; |
|
| 1495 | + $col = $val = $crit->op; |
|
| 1496 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) $val = $r[2]; |
|
| 1497 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 1498 | + if ($val=='lang') |
|
| 1499 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 1500 | + else { |
|
| 1501 | + $defaut = null; |
|
| 1502 | + if ($val=='id_parent') { |
|
| 1503 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 1504 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 1505 | + // pour eviter l'erreur SQL |
|
| 1506 | + $val = $boucles[$idb]->primary; |
|
| 1507 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 1508 | + $defaut = "\$Pile[0]['id_parent']"; |
|
| 1509 | + } |
|
| 1510 | + elseif ($val=='id_enfant'){ |
|
| 1511 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 1512 | + // de la boucle superieure |
|
| 1513 | + $val = 'id_parent'; |
|
| 1514 | + } |
|
| 1515 | + elseif ($crit->cond AND ($col=="date" OR $col=="date_redac")){ |
|
| 1516 | + // un critere conditionnel sur date est traite a part |
|
| 1517 | + // car la date est mise d'office par SPIP, |
|
| 1518 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 1519 | + } |
|
| 1520 | + |
|
| 1521 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 1522 | + $val = array(kwote($val)); |
|
| 1523 | + } |
|
| 1524 | + } else { |
|
| 1525 | + // comparaison explicite |
|
| 1526 | + // le phraseur impose que le premier param soit du texte |
|
| 1527 | + $params = $crit->param; |
|
| 1528 | + $op = $crit->op; |
|
| 1529 | + if ($op=='==') $op = 'REGEXP'; |
|
| 1530 | + $col = array_shift($params); |
|
| 1531 | + $col = $col[0]->texte; |
|
| 1532 | + |
|
| 1533 | + $val = array(); |
|
| 1534 | + $desc = array('id_mere' => $idb); |
|
| 1535 | + $parent = $boucles[$idb]->id_parent; |
|
| 1536 | + |
|
| 1537 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 1538 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 1539 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 1540 | + if (count($params)==1 |
|
| 1541 | + AND count($params[0]==3) |
|
| 1542 | + AND $params[0][0]->type=='texte' |
|
| 1543 | + AND @$params[0][2]->type=='texte' |
|
| 1544 | + AND ($p = $params[0][0]->texte)==$params[0][2]->texte |
|
| 1545 | + AND (($p=="'") OR ($p=='"')) |
|
| 1546 | + AND $params[0][1]->type=='champ' |
|
| 1547 | + ){ |
|
| 1548 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 1549 | + } else |
|
| 1550 | + foreach ((($op!='IN') ? $params : calculer_vieux_in($params)) as $p){ |
|
| 1551 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 1552 | + if (strcasecmp($op,'IN')==0) $val[] = $a; |
|
| 1553 | + else $val[] = kwote($a, $boucles[$idb]->sql_serveur, 'char'); // toujours quoter en char ici |
|
| 1554 | + } |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + $fct = $args_sql = ''; |
|
| 1558 | + // fonction SQL ? |
|
| 1559 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)){ |
|
| 1560 | + $fct = $m[1]; |
|
| 1561 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 1562 | + $col = $a[1]; |
|
| 1563 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)){ |
|
| 1564 | + $col = $m[1]; |
|
| 1565 | + $args_sql = $m[2]; |
|
| 1566 | + } |
|
| 1567 | + $args_sql .= $a[2]; |
|
| 1568 | + ; |
|
| 1569 | + } |
|
| 1570 | + |
|
| 1571 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 1572 | 1572 | } |
| 1573 | 1573 | |
| 1574 | 1574 | // compatibilite ancienne version |
| 1575 | 1575 | |
| 1576 | 1576 | // http://doc.spip.org/@calculer_vieux_in |
| 1577 | 1577 | function calculer_vieux_in($params){ |
| 1578 | - $deb = $params[0][0]; |
|
| 1579 | - $k = count($params)-1; |
|
| 1580 | - $last = $params[$k]; |
|
| 1581 | - $j = count($last)-1; |
|
| 1582 | - $last = $last[$j]; |
|
| 1583 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 1584 | - |
|
| 1585 | - if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
|
| 1586 | - && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1587 | - return $params; |
|
| 1588 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 1589 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 1590 | - $last = $params[$k][$j]; |
|
| 1591 | - $n = strlen($last->texte); |
|
| 1592 | - $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
|
| 1593 | - $newp = array(); |
|
| 1594 | - foreach ($params as $v){ |
|
| 1595 | - if ($v[0]->type!='texte') |
|
| 1596 | - $newp[] = $v; |
|
| 1597 | - else { |
|
| 1598 | - foreach (explode(',', $v[0]->texte) as $x){ |
|
| 1599 | - $t = new Texte; |
|
| 1600 | - $t->texte = $x; |
|
| 1601 | - $newp[] = array($t); |
|
| 1602 | - } |
|
| 1603 | - } |
|
| 1604 | - } |
|
| 1605 | - return $newp; |
|
| 1578 | + $deb = $params[0][0]; |
|
| 1579 | + $k = count($params)-1; |
|
| 1580 | + $last = $params[$k]; |
|
| 1581 | + $j = count($last)-1; |
|
| 1582 | + $last = $last[$j]; |
|
| 1583 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 1584 | + |
|
| 1585 | + if (!((isset($deb->texte[0]) AND $deb->texte[0]=='(') |
|
| 1586 | + && (isset($last->texte[$n-1]) AND $last->texte[$n-1]==')'))) |
|
| 1587 | + return $params; |
|
| 1588 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 1589 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 1590 | + $last = $params[$k][$j]; |
|
| 1591 | + $n = strlen($last->texte); |
|
| 1592 | + $params[$k][$j]->texte = substr($last->texte, 0, $n-1); |
|
| 1593 | + $newp = array(); |
|
| 1594 | + foreach ($params as $v){ |
|
| 1595 | + if ($v[0]->type!='texte') |
|
| 1596 | + $newp[] = $v; |
|
| 1597 | + else { |
|
| 1598 | + foreach (explode(',', $v[0]->texte) as $x){ |
|
| 1599 | + $t = new Texte; |
|
| 1600 | + $t->texte = $x; |
|
| 1601 | + $newp[] = array($t); |
|
| 1602 | + } |
|
| 1603 | + } |
|
| 1604 | + } |
|
| 1605 | + return $newp; |
|
| 1606 | 1606 | } |
| 1607 | 1607 | |
| 1608 | 1608 | // http://doc.spip.org/@calculer_critere_infixe_date |
| 1609 | 1609 | function calculer_critere_infixe_date($idb, &$boucles, $col){ |
| 1610 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
|
| 1611 | - $boucle = $boucles[$idb]; |
|
| 1612 | - $table = $boucle->show; |
|
| 1613 | - // si c'est une colonne de la table, ne rien faire |
|
| 1614 | - if(isset($table['field'][$col])) return ''; |
|
| 1615 | - |
|
| 1616 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
|
| 1617 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1618 | - $col = $regs[1]; |
|
| 1619 | - if (isset($regs[3]) AND $suite = $regs[3]){ |
|
| 1620 | - # Recherche de l'existence du champ date_xxxx, |
|
| 1621 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 1622 | - |
|
| 1623 | - if (isset($table['field']["date$suite"])) |
|
| 1624 | - $date_orig = 'date'.$suite; |
|
| 1625 | - else |
|
| 1626 | - $date_orig = substr($suite, 1); |
|
| 1627 | - $pred = $date_orig; |
|
| 1628 | - } |
|
| 1629 | - else |
|
| 1630 | - if (isset($regs[2]) AND $rel = $regs[2]) $pred = 'date'; |
|
| 1631 | - |
|
| 1632 | - $date_compare = "\"' . normaliser_date(". |
|
| 1633 | - calculer_argument_precedent($idb, $pred, $boucles). |
|
| 1634 | - ") . '\""; |
|
| 1635 | - |
|
| 1636 | - $col_vraie = $date_orig; |
|
| 1637 | - $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 1638 | - |
|
| 1639 | - switch ($col) { |
|
| 1640 | - case 'date': |
|
| 1641 | - $col = $date_orig; |
|
| 1642 | - break; |
|
| 1643 | - case 'jour': |
|
| 1644 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 1645 | - break; |
|
| 1646 | - case 'mois': |
|
| 1647 | - $col = "MONTH($date_orig)"; |
|
| 1648 | - break; |
|
| 1649 | - case 'annee': |
|
| 1650 | - $col = "YEAR($date_orig)"; |
|
| 1651 | - break; |
|
| 1652 | - case 'heure': |
|
| 1653 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 1654 | - break; |
|
| 1655 | - case 'age': |
|
| 1656 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 1657 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1658 | - break; |
|
| 1659 | - case 'age_relatif': |
|
| 1660 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 1661 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1662 | - break; |
|
| 1663 | - case 'jour_relatif': |
|
| 1664 | - $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 1665 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1666 | - break; |
|
| 1667 | - case 'mois_relatif': |
|
| 1668 | - $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 1669 | - $date_orig.")+12*(YEAR(".$date_compare. |
|
| 1670 | - ")-YEAR(".$date_orig."))"; |
|
| 1671 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1672 | - break; |
|
| 1673 | - case 'annee_relatif': |
|
| 1674 | - $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 1675 | - $date_orig.")"; |
|
| 1676 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 1677 | - break; |
|
| 1678 | - } |
|
| 1679 | - return array($col,$col_vraie); |
|
| 1610 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) return ''; |
|
| 1611 | + $boucle = $boucles[$idb]; |
|
| 1612 | + $table = $boucle->show; |
|
| 1613 | + // si c'est une colonne de la table, ne rien faire |
|
| 1614 | + if(isset($table['field'][$col])) return ''; |
|
| 1615 | + |
|
| 1616 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) return ''; |
|
| 1617 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']])? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 1618 | + $col = $regs[1]; |
|
| 1619 | + if (isset($regs[3]) AND $suite = $regs[3]){ |
|
| 1620 | + # Recherche de l'existence du champ date_xxxx, |
|
| 1621 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 1622 | + |
|
| 1623 | + if (isset($table['field']["date$suite"])) |
|
| 1624 | + $date_orig = 'date'.$suite; |
|
| 1625 | + else |
|
| 1626 | + $date_orig = substr($suite, 1); |
|
| 1627 | + $pred = $date_orig; |
|
| 1628 | + } |
|
| 1629 | + else |
|
| 1630 | + if (isset($regs[2]) AND $rel = $regs[2]) $pred = 'date'; |
|
| 1631 | + |
|
| 1632 | + $date_compare = "\"' . normaliser_date(". |
|
| 1633 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 1634 | + ") . '\""; |
|
| 1635 | + |
|
| 1636 | + $col_vraie = $date_orig; |
|
| 1637 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 1638 | + |
|
| 1639 | + switch ($col) { |
|
| 1640 | + case 'date': |
|
| 1641 | + $col = $date_orig; |
|
| 1642 | + break; |
|
| 1643 | + case 'jour': |
|
| 1644 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 1645 | + break; |
|
| 1646 | + case 'mois': |
|
| 1647 | + $col = "MONTH($date_orig)"; |
|
| 1648 | + break; |
|
| 1649 | + case 'annee': |
|
| 1650 | + $col = "YEAR($date_orig)"; |
|
| 1651 | + break; |
|
| 1652 | + case 'heure': |
|
| 1653 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 1654 | + break; |
|
| 1655 | + case 'age': |
|
| 1656 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 1657 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1658 | + break; |
|
| 1659 | + case 'age_relatif': |
|
| 1660 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 1661 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1662 | + break; |
|
| 1663 | + case 'jour_relatif': |
|
| 1664 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 1665 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1666 | + break; |
|
| 1667 | + case 'mois_relatif': |
|
| 1668 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 1669 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 1670 | + ")-YEAR(".$date_orig."))"; |
|
| 1671 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1672 | + break; |
|
| 1673 | + case 'annee_relatif': |
|
| 1674 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 1675 | + $date_orig.")"; |
|
| 1676 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 1677 | + break; |
|
| 1678 | + } |
|
| 1679 | + return array($col,$col_vraie); |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | // http://doc.spip.org/@calculer_param_date |
| 1683 | 1683 | function calculer_param_date($date_compare, $date_orig){ |
| 1684 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
|
| 1685 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 1686 | - $date_compare = '\'$x\''; |
|
| 1687 | - } |
|
| 1688 | - else |
|
| 1689 | - $init = $date_compare; |
|
| 1690 | - |
|
| 1691 | - return |
|
| 1692 | - "LEAST((UNIX_TIMESTAMP(". |
|
| 1693 | - $init. |
|
| 1694 | - ")-UNIX_TIMESTAMP(". |
|
| 1695 | - $date_orig. |
|
| 1696 | - "))/86400,\n\tTO_DAYS(". |
|
| 1697 | - $date_compare. |
|
| 1698 | - ")-TO_DAYS(". |
|
| 1699 | - $date_orig. |
|
| 1700 | - "),\n\tDAYOFMONTH(". |
|
| 1701 | - $date_compare. |
|
| 1702 | - ")-DAYOFMONTH(". |
|
| 1703 | - $date_orig. |
|
| 1704 | - ")+30.4368*(MONTH(". |
|
| 1705 | - $date_compare. |
|
| 1706 | - ")-MONTH(". |
|
| 1707 | - $date_orig. |
|
| 1708 | - "))+365.2422*(YEAR(". |
|
| 1709 | - $date_compare. |
|
| 1710 | - ")-YEAR(". |
|
| 1711 | - $date_orig. |
|
| 1712 | - ")))"; |
|
| 1684 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)){ |
|
| 1685 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 1686 | + $date_compare = '\'$x\''; |
|
| 1687 | + } |
|
| 1688 | + else |
|
| 1689 | + $init = $date_compare; |
|
| 1690 | + |
|
| 1691 | + return |
|
| 1692 | + "LEAST((UNIX_TIMESTAMP(". |
|
| 1693 | + $init. |
|
| 1694 | + ")-UNIX_TIMESTAMP(". |
|
| 1695 | + $date_orig. |
|
| 1696 | + "))/86400,\n\tTO_DAYS(". |
|
| 1697 | + $date_compare. |
|
| 1698 | + ")-TO_DAYS(". |
|
| 1699 | + $date_orig. |
|
| 1700 | + "),\n\tDAYOFMONTH(". |
|
| 1701 | + $date_compare. |
|
| 1702 | + ")-DAYOFMONTH(". |
|
| 1703 | + $date_orig. |
|
| 1704 | + ")+30.4368*(MONTH(". |
|
| 1705 | + $date_compare. |
|
| 1706 | + ")-MONTH(". |
|
| 1707 | + $date_orig. |
|
| 1708 | + "))+365.2422*(YEAR(". |
|
| 1709 | + $date_compare. |
|
| 1710 | + ")-YEAR(". |
|
| 1711 | + $date_orig. |
|
| 1712 | + ")))"; |
|
| 1713 | 1713 | } |
| 1714 | 1714 | |
| 1715 | 1715 | /** |
@@ -1719,17 +1719,17 @@ discard block |
||
| 1719 | 1719 | * @param object $crit |
| 1720 | 1720 | */ |
| 1721 | 1721 | function critere_DATA_source_dist($idb, &$boucles, $crit){ |
| 1722 | - $boucle = &$boucles[$idb]; |
|
| 1722 | + $boucle = &$boucles[$idb]; |
|
| 1723 | 1723 | |
| 1724 | - $args = array(); |
|
| 1725 | - foreach ($crit->param as &$param) |
|
| 1726 | - array_push($args, |
|
| 1727 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1724 | + $args = array(); |
|
| 1725 | + foreach ($crit->param as &$param) |
|
| 1726 | + array_push($args, |
|
| 1727 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1728 | 1728 | |
| 1729 | - $boucle->hash .= ' |
|
| 1729 | + $boucle->hash .= ' |
|
| 1730 | 1730 | $command[\'sourcemode\'] = '.array_shift($args).";\n"; |
| 1731 | 1731 | |
| 1732 | - $boucle->hash .= ' |
|
| 1732 | + $boucle->hash .= ' |
|
| 1733 | 1733 | $command[\'source\'] = array('.join(', ', $args).");\n"; |
| 1734 | 1734 | } |
| 1735 | 1735 | |
@@ -1741,8 +1741,8 @@ discard block |
||
| 1741 | 1741 | * @param object $crit |
| 1742 | 1742 | */ |
| 1743 | 1743 | function critere_DATA_datasource_dist($idb, &$boucles, $crit){ |
| 1744 | - $boucle = &$boucles[$idb]; |
|
| 1745 | - $boucle->hash .= ' |
|
| 1744 | + $boucle = &$boucles[$idb]; |
|
| 1745 | + $boucle->hash .= ' |
|
| 1746 | 1746 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
| 1747 | 1747 | $command[\'sourcemode\'] = '.calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1748 | 1748 | } |
@@ -1755,8 +1755,8 @@ discard block |
||
| 1755 | 1755 | * @param object $crit |
| 1756 | 1756 | */ |
| 1757 | 1757 | function critere_DATA_datacache_dist($idb, &$boucles, $crit){ |
| 1758 | - $boucle = &$boucles[$idb]; |
|
| 1759 | - $boucle->hash .= ' |
|
| 1758 | + $boucle = &$boucles[$idb]; |
|
| 1759 | + $boucle->hash .= ' |
|
| 1760 | 1760 | $command[\'datacache\'] = '.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1761 | 1761 | } |
| 1762 | 1762 | |
@@ -1770,12 +1770,12 @@ discard block |
||
| 1770 | 1770 | * @param object $crit |
| 1771 | 1771 | */ |
| 1772 | 1772 | function critere_php_args_dist($idb, &$boucles, $crit){ |
| 1773 | - $boucle = &$boucles[$idb]; |
|
| 1774 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 1775 | - foreach ($crit->param as $param){ |
|
| 1776 | - $boucle->hash .= ' |
|
| 1773 | + $boucle = &$boucles[$idb]; |
|
| 1774 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 1775 | + foreach ($crit->param as $param){ |
|
| 1776 | + $boucle->hash .= ' |
|
| 1777 | 1777 | $command[\'args\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1778 | - } |
|
| 1778 | + } |
|
| 1779 | 1779 | } |
| 1780 | 1780 | |
| 1781 | 1781 | /** |
@@ -1787,11 +1787,11 @@ discard block |
||
| 1787 | 1787 | * @param object $crit |
| 1788 | 1788 | */ |
| 1789 | 1789 | function critere_DATA_liste_dist($idb, &$boucles, $crit){ |
| 1790 | - $boucle = &$boucles[$idb]; |
|
| 1791 | - $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 1792 | - foreach ($crit->param as $param){ |
|
| 1793 | - $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1794 | - } |
|
| 1790 | + $boucle = &$boucles[$idb]; |
|
| 1791 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 1792 | + foreach ($crit->param as $param){ |
|
| 1793 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1794 | + } |
|
| 1795 | 1795 | } |
| 1796 | 1796 | |
| 1797 | 1797 | /** |
@@ -1803,11 +1803,11 @@ discard block |
||
| 1803 | 1803 | * @param object $crit |
| 1804 | 1804 | */ |
| 1805 | 1805 | function critere_DATA_enum_dist($idb, &$boucles, $crit){ |
| 1806 | - $boucle = &$boucles[$idb]; |
|
| 1807 | - $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 1808 | - foreach ($crit->param as $param){ |
|
| 1809 | - $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1810 | - } |
|
| 1806 | + $boucle = &$boucles[$idb]; |
|
| 1807 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 1808 | + foreach ($crit->param as $param){ |
|
| 1809 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 1810 | + } |
|
| 1811 | 1811 | } |
| 1812 | 1812 | |
| 1813 | 1813 | /** |
@@ -1819,11 +1819,11 @@ discard block |
||
| 1819 | 1819 | * @param object $crit |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_DATA_datapath_dist($idb, &$boucles, $crit){ |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - foreach ($crit->param as $param){ |
|
| 1824 | - $boucle->hash .= ' |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + foreach ($crit->param as $param){ |
|
| 1824 | + $boucle->hash .= ' |
|
| 1825 | 1825 | $command[\'datapath\'][] = '.calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
| 1826 | - } |
|
| 1826 | + } |
|
| 1827 | 1827 | } |
| 1828 | 1828 | |
| 1829 | 1829 | |
@@ -1835,20 +1835,20 @@ discard block |
||
| 1835 | 1835 | * @param object $crit |
| 1836 | 1836 | */ |
| 1837 | 1837 | function critere_si_dist($idb, &$boucles, $crit){ |
| 1838 | - $boucle = &$boucles[$idb]; |
|
| 1839 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 1840 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 1841 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 1842 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 1843 | - if ($crit->param){ |
|
| 1844 | - foreach ($crit->param as $param){ |
|
| 1845 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 1846 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 1847 | - } |
|
| 1848 | - // interdire {si 0} aussi ! |
|
| 1849 | - } else { |
|
| 1850 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 1851 | - } |
|
| 1838 | + $boucle = &$boucles[$idb]; |
|
| 1839 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 1840 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 1841 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 1842 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 1843 | + if ($crit->param){ |
|
| 1844 | + foreach ($crit->param as $param){ |
|
| 1845 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 1846 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 1847 | + } |
|
| 1848 | + // interdire {si 0} aussi ! |
|
| 1849 | + } else { |
|
| 1850 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 1851 | + } |
|
| 1852 | 1852 | } |
| 1853 | 1853 | |
| 1854 | 1854 | /** |
@@ -1860,8 +1860,8 @@ discard block |
||
| 1860 | 1860 | * @param object $crit |
| 1861 | 1861 | */ |
| 1862 | 1862 | function critere_POUR_tableau_dist($idb, &$boucles, $crit){ |
| 1863 | - $boucle = &$boucles[$idb]; |
|
| 1864 | - $boucle->hash .= ' |
|
| 1863 | + $boucle = &$boucles[$idb]; |
|
| 1864 | + $boucle->hash .= ' |
|
| 1865 | 1865 | $command[\'source\'] = array('.calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
| 1866 | 1866 | $command[\'sourcemode\'] = \'table\';'; |
| 1867 | 1867 | } |
@@ -1878,28 +1878,28 @@ discard block |
||
| 1878 | 1878 | * @param Object $crit |
| 1879 | 1879 | */ |
| 1880 | 1880 | function critere_noeud_dist($idb, &$boucles, $crit){ |
| 1881 | - global $exceptions_des_tables; |
|
| 1882 | - $not = $crit->not; |
|
| 1883 | - $boucle = &$boucles[$idb]; |
|
| 1884 | - $primary = $boucle->primary; |
|
| 1885 | - |
|
| 1886 | - if (!$primary OR strpos($primary, ',')){ |
|
| 1887 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 1888 | - return; |
|
| 1889 | - } |
|
| 1890 | - $table = $boucle->type_requete; |
|
| 1891 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 1892 | - |
|
| 1893 | - $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 1894 | - $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 1895 | - 'id_parent'; |
|
| 1896 | - |
|
| 1897 | - $in = "IN"; |
|
| 1898 | - $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 1899 | - if ($not) |
|
| 1900 | - $where = array("'NOT'", $where); |
|
| 1901 | - |
|
| 1902 | - $boucle->where[] = $where; |
|
| 1881 | + global $exceptions_des_tables; |
|
| 1882 | + $not = $crit->not; |
|
| 1883 | + $boucle = &$boucles[$idb]; |
|
| 1884 | + $primary = $boucle->primary; |
|
| 1885 | + |
|
| 1886 | + if (!$primary OR strpos($primary, ',')){ |
|
| 1887 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 1888 | + return; |
|
| 1889 | + } |
|
| 1890 | + $table = $boucle->type_requete; |
|
| 1891 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 1892 | + |
|
| 1893 | + $id_parent = isset($exceptions_des_tables[$boucle->id_table]['id_parent']) ? |
|
| 1894 | + $exceptions_des_tables[$boucle->id_table]['id_parent'] : |
|
| 1895 | + 'id_parent'; |
|
| 1896 | + |
|
| 1897 | + $in = "IN"; |
|
| 1898 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 1899 | + if ($not) |
|
| 1900 | + $where = array("'NOT'", $where); |
|
| 1901 | + |
|
| 1902 | + $boucle->where[] = $where; |
|
| 1903 | 1903 | } |
| 1904 | 1904 | |
| 1905 | 1905 | /** |
@@ -1913,10 +1913,10 @@ discard block |
||
| 1913 | 1913 | * @param Object $crit |
| 1914 | 1914 | */ |
| 1915 | 1915 | function critere_feuille_dist($idb, &$boucles, $crit){ |
| 1916 | - $not = $crit->not; |
|
| 1917 | - $crit->not = $not ? false : true; |
|
| 1918 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 1919 | - $crit->not = $not; |
|
| 1916 | + $not = $crit->not; |
|
| 1917 | + $crit->not = $not ? false : true; |
|
| 1918 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 1919 | + $crit->not = $not; |
|
| 1920 | 1920 | } |
| 1921 | 1921 | |
| 1922 | 1922 | ?> |
@@ -41,77 +41,77 @@ discard block |
||
| 41 | 41 | // http://doc.spip.org/@phraser_inclure |
| 42 | 42 | function phraser_inclure($texte, $ligne, $result){ |
| 43 | 43 | |
| 44 | - while (preg_match(BALISE_INCLURE, $texte, $match)){ |
|
| 45 | - $p = strpos($texte, $match[0]); |
|
| 46 | - $debut = substr($texte, 0, $p); |
|
| 47 | - if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
|
| 48 | - $ligne += substr_count($debut, "\n"); |
|
| 49 | - $champ = new Inclure; |
|
| 50 | - $champ->ligne = $ligne; |
|
| 51 | - $ligne += substr_count($match[0], "\n"); |
|
| 52 | - $fichier = @$match[2]; |
|
| 53 | - # assurer ici la migration .php3 => .php |
|
| 54 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 55 | - if (preg_match(',^(.*[.]php)3$,', $fichier, $r)){ |
|
| 56 | - $fichier = $r[1]; |
|
| 57 | - } |
|
| 58 | - $champ->texte = ($fichier!=='page.php') ? $fichier : ''; |
|
| 59 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 60 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 61 | - phraser_args($texte, "/>", "", $result, $champ); |
|
| 62 | - if (!$champ->texte OR count($champ->param)>1){ |
|
| 63 | - if (!function_exists('normaliser_inclure')) |
|
| 64 | - include_spip('public/normaliser'); |
|
| 65 | - normaliser_inclure($champ); |
|
| 66 | - } |
|
| 67 | - $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
|
| 68 | - $champ->apres = ""; |
|
| 69 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 70 | - $result[] = $champ; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 44 | + while (preg_match(BALISE_INCLURE, $texte, $match)){ |
|
| 45 | + $p = strpos($texte, $match[0]); |
|
| 46 | + $debut = substr($texte, 0, $p); |
|
| 47 | + if ($p) $result = phraser_idiomes($debut, $ligne, $result); |
|
| 48 | + $ligne += substr_count($debut, "\n"); |
|
| 49 | + $champ = new Inclure; |
|
| 50 | + $champ->ligne = $ligne; |
|
| 51 | + $ligne += substr_count($match[0], "\n"); |
|
| 52 | + $fichier = @$match[2]; |
|
| 53 | + # assurer ici la migration .php3 => .php |
|
| 54 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 55 | + if (preg_match(',^(.*[.]php)3$,', $fichier, $r)){ |
|
| 56 | + $fichier = $r[1]; |
|
| 57 | + } |
|
| 58 | + $champ->texte = ($fichier!=='page.php') ? $fichier : ''; |
|
| 59 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 60 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 61 | + phraser_args($texte, "/>", "", $result, $champ); |
|
| 62 | + if (!$champ->texte OR count($champ->param)>1){ |
|
| 63 | + if (!function_exists('normaliser_inclure')) |
|
| 64 | + include_spip('public/normaliser'); |
|
| 65 | + normaliser_inclure($champ); |
|
| 66 | + } |
|
| 67 | + $texte = substr($champ->apres, strpos($champ->apres, '>')+1); |
|
| 68 | + $champ->apres = ""; |
|
| 69 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 70 | + $result[] = $champ; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return (($texte==="") ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // http://doc.spip.org/@phraser_polyglotte |
| 77 | 77 | function phraser_polyglotte($texte, $ligne, $result){ |
| 78 | 78 | |
| 79 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
|
| 80 | - foreach ($m as $match){ |
|
| 81 | - $p = strpos($texte, $match[0]); |
|
| 82 | - $debut = substr($texte, 0, $p); |
|
| 83 | - if ($p){ |
|
| 84 | - $champ = new Texte; |
|
| 85 | - $champ->texte = $debut; |
|
| 86 | - $champ->ligne = $ligne; |
|
| 87 | - $result[] = $champ; |
|
| 88 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champ = new Polyglotte; |
|
| 92 | - $champ->ligne = $ligne; |
|
| 93 | - $ligne += substr_count($match[0], "\n"); |
|
| 94 | - $lang = ''; |
|
| 95 | - $bloc = $match[1]; |
|
| 96 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 97 | - while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
|
| 98 | - $trad = $regs[1]; |
|
| 99 | - if ($trad OR $lang) |
|
| 100 | - $champ->traductions[$lang] = $trad; |
|
| 101 | - $lang = $regs[2]; |
|
| 102 | - $bloc = $regs[3]; |
|
| 103 | - } |
|
| 104 | - $champ->traductions[$lang] = $bloc; |
|
| 105 | - $result[] = $champ; |
|
| 106 | - } |
|
| 107 | - if ($texte!==""){ |
|
| 108 | - $champ = new Texte; |
|
| 109 | - $champ->texte = $texte; |
|
| 110 | - $champ->ligne = $ligne; |
|
| 111 | - $result[] = $champ; |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - return $result; |
|
| 79 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) |
|
| 80 | + foreach ($m as $match){ |
|
| 81 | + $p = strpos($texte, $match[0]); |
|
| 82 | + $debut = substr($texte, 0, $p); |
|
| 83 | + if ($p){ |
|
| 84 | + $champ = new Texte; |
|
| 85 | + $champ->texte = $debut; |
|
| 86 | + $champ->ligne = $ligne; |
|
| 87 | + $result[] = $champ; |
|
| 88 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champ = new Polyglotte; |
|
| 92 | + $champ->ligne = $ligne; |
|
| 93 | + $ligne += substr_count($match[0], "\n"); |
|
| 94 | + $lang = ''; |
|
| 95 | + $bloc = $match[1]; |
|
| 96 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 97 | + while (preg_match("/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si", $bloc, $regs)){ |
|
| 98 | + $trad = $regs[1]; |
|
| 99 | + if ($trad OR $lang) |
|
| 100 | + $champ->traductions[$lang] = $trad; |
|
| 101 | + $lang = $regs[2]; |
|
| 102 | + $bloc = $regs[3]; |
|
| 103 | + } |
|
| 104 | + $champ->traductions[$lang] = $bloc; |
|
| 105 | + $result[] = $champ; |
|
| 106 | + } |
|
| 107 | + if ($texte!==""){ |
|
| 108 | + $champ = new Texte; |
|
| 109 | + $champ->texte = $texte; |
|
| 110 | + $champ->ligne = $ligne; |
|
| 111 | + $result[] = $champ; |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + return $result; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -121,77 +121,77 @@ discard block |
||
| 121 | 121 | // sinon ce n'est pas un idiome |
| 122 | 122 | // http://doc.spip.org/@phraser_idiomes |
| 123 | 123 | function phraser_idiomes($texte, $ligne, $result){ |
| 124 | - while (preg_match(BALISE_IDIOMES, $texte, $match)){ |
|
| 125 | - $p = strpos($texte, $match[0]); |
|
| 126 | - $ko = (!$match[3] && ($match[5][0]!=='=')); |
|
| 127 | - $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
|
| 128 | - if ($debut) $result = phraser_champs($debut, $ligne, $result); |
|
| 129 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 130 | - $ligne += substr_count($debut, "\n"); |
|
| 131 | - if ($ko) continue; // faux idiome |
|
| 132 | - $champ = new Idiome; |
|
| 133 | - $champ->ligne = $ligne; |
|
| 134 | - $ligne += substr_count($match[0], "\n"); |
|
| 135 | - // Stocker les arguments de la balise de traduction |
|
| 136 | - $args = array(); |
|
| 137 | - $largs = $match[5]; |
|
| 138 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)){ |
|
| 139 | - $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 140 | - $largs = substr($largs, strlen($r[0])); |
|
| 141 | - } |
|
| 142 | - $champ->arg = $args; |
|
| 143 | - $champ->nom_champ = strtolower($match[3]); |
|
| 144 | - $champ->module = $match[2]; |
|
| 145 | - // pas d'imbrication pour les filtres sur langue |
|
| 146 | - phraser_args(@$match[7], ":", '', array(), $champ); |
|
| 147 | - $result[] = $champ; |
|
| 148 | - } |
|
| 149 | - if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 150 | - |
|
| 151 | - return $result; |
|
| 124 | + while (preg_match(BALISE_IDIOMES, $texte, $match)){ |
|
| 125 | + $p = strpos($texte, $match[0]); |
|
| 126 | + $ko = (!$match[3] && ($match[5][0]!=='=')); |
|
| 127 | + $debut = substr($texte, 0, $p+($ko ? strlen($match[0]) : 0)); |
|
| 128 | + if ($debut) $result = phraser_champs($debut, $ligne, $result); |
|
| 129 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 130 | + $ligne += substr_count($debut, "\n"); |
|
| 131 | + if ($ko) continue; // faux idiome |
|
| 132 | + $champ = new Idiome; |
|
| 133 | + $champ->ligne = $ligne; |
|
| 134 | + $ligne += substr_count($match[0], "\n"); |
|
| 135 | + // Stocker les arguments de la balise de traduction |
|
| 136 | + $args = array(); |
|
| 137 | + $largs = $match[5]; |
|
| 138 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)){ |
|
| 139 | + $args[$r[1]] = phraser_champs($r[2], 0, array()); |
|
| 140 | + $largs = substr($largs, strlen($r[0])); |
|
| 141 | + } |
|
| 142 | + $champ->arg = $args; |
|
| 143 | + $champ->nom_champ = strtolower($match[3]); |
|
| 144 | + $champ->module = $match[2]; |
|
| 145 | + // pas d'imbrication pour les filtres sur langue |
|
| 146 | + phraser_args(@$match[7], ":", '', array(), $champ); |
|
| 147 | + $result[] = $champ; |
|
| 148 | + } |
|
| 149 | + if ($texte!=="") $result = phraser_champs($texte, $ligne, $result); |
|
| 150 | + |
|
| 151 | + return $result; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | // http://doc.spip.org/@phraser_champs |
| 155 | 155 | function phraser_champs($texte, $ligne, $result){ |
| 156 | - while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)){ |
|
| 157 | - $p = strpos($texte, $match[0]); |
|
| 158 | - $suite = substr($texte, $p+strlen($match[0])); |
|
| 159 | - if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
|
| 160 | - $debut = substr($texte, 0, $p); |
|
| 161 | - if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 162 | - $ligne += substr_count($debut, "\n"); |
|
| 163 | - $champ = new Champ; |
|
| 164 | - $champ->ligne = $ligne; |
|
| 165 | - $ligne += substr_count($match[0], "\n"); |
|
| 166 | - $champ->nom_boucle = $match[2]; |
|
| 167 | - $champ->nom_champ = $match[3]; |
|
| 168 | - $champ->etoile = $match[5]; |
|
| 169 | - |
|
| 170 | - if ($suite[0]=='{'){ |
|
| 171 | - phraser_arg($suite, '', array(), $champ); |
|
| 172 | - // ce ltrim est une ereur de conception |
|
| 173 | - // mais on le conserve par souci de compatibilite |
|
| 174 | - $texte = ltrim($suite); |
|
| 175 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 176 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 177 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 156 | + while (preg_match("/" . NOM_DE_CHAMP . "/S", $texte, $match)){ |
|
| 157 | + $p = strpos($texte, $match[0]); |
|
| 158 | + $suite = substr($texte, $p+strlen($match[0])); |
|
| 159 | + if ($match[5] || (strpos($suite[0], "[0-9]")===false)){ |
|
| 160 | + $debut = substr($texte, 0, $p); |
|
| 161 | + if ($p) $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 162 | + $ligne += substr_count($debut, "\n"); |
|
| 163 | + $champ = new Champ; |
|
| 164 | + $champ->ligne = $ligne; |
|
| 165 | + $ligne += substr_count($match[0], "\n"); |
|
| 166 | + $champ->nom_boucle = $match[2]; |
|
| 167 | + $champ->nom_champ = $match[3]; |
|
| 168 | + $champ->etoile = $match[5]; |
|
| 169 | + |
|
| 170 | + if ($suite[0]=='{'){ |
|
| 171 | + phraser_arg($suite, '', array(), $champ); |
|
| 172 | + // ce ltrim est une ereur de conception |
|
| 173 | + // mais on le conserve par souci de compatibilite |
|
| 174 | + $texte = ltrim($suite); |
|
| 175 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 176 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 177 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 178 | 178 | if ($n = (strlen($suite) - strlen($texte))) { |
| 179 | 179 | $champ->apres = array(new Texte); |
| 180 | 180 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 181 | 181 | } |
| 182 | 182 | */ |
| 183 | - } else $texte = $suite; |
|
| 184 | - phraser_vieux($champ); |
|
| 185 | - $result[] = $champ; |
|
| 186 | - } else { |
|
| 187 | - // faux champ |
|
| 188 | - $result = phraser_polyglotte(substr($texte, 0, $p+1), $ligne, $result); |
|
| 189 | - $texte = (substr($texte, $p+1)); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 193 | - |
|
| 194 | - return $result; |
|
| 183 | + } else $texte = $suite; |
|
| 184 | + phraser_vieux($champ); |
|
| 185 | + $result[] = $champ; |
|
| 186 | + } else { |
|
| 187 | + // faux champ |
|
| 188 | + $result = phraser_polyglotte(substr($texte, 0, $p+1), $ligne, $result); |
|
| 189 | + $texte = (substr($texte, $p+1)); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + if ($texte!=="") $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 193 | + |
|
| 194 | + return $result; |
|
| 195 | 195 | } |
| 196 | 196 | |
| 197 | 197 | // Gestion des imbrications: |
@@ -201,12 +201,12 @@ discard block |
||
| 201 | 201 | |
| 202 | 202 | // http://doc.spip.org/@phraser_champs_etendus |
| 203 | 203 | function phraser_champs_etendus($texte, $ligne, $result){ |
| 204 | - if ($texte==="") return $result; |
|
| 205 | - $sep = '##'; |
|
| 206 | - while (strpos($texte, $sep)!==false) |
|
| 207 | - $sep .= '#'; |
|
| 204 | + if ($texte==="") return $result; |
|
| 205 | + $sep = '##'; |
|
| 206 | + while (strpos($texte, $sep)!==false) |
|
| 207 | + $sep .= '#'; |
|
| 208 | 208 | |
| 209 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 209 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, array())); |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | // Analyse les filtres d'un champ etendu et affecte le resultat |
@@ -217,248 +217,248 @@ discard block |
||
| 217 | 217 | |
| 218 | 218 | // http://doc.spip.org/@phraser_args |
| 219 | 219 | function phraser_args($texte, $fin, $sep, $result, &$pointeur_champ){ |
| 220 | - $texte = ltrim($texte); |
|
| 221 | - while (($texte!=="") && strpos($fin, $texte[0])===false){ |
|
| 222 | - $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 223 | - $texte = ltrim($texte); |
|
| 224 | - } |
|
| 220 | + $texte = ltrim($texte); |
|
| 221 | + while (($texte!=="") && strpos($fin, $texte[0])===false){ |
|
| 222 | + $result = phraser_arg($texte, $sep, $result, $pointeur_champ); |
|
| 223 | + $texte = ltrim($texte); |
|
| 224 | + } |
|
| 225 | 225 | # mettre ici la suite du texte, |
| 226 | 226 | # notamment pour que l'appelant vire le caractere fermant si besoin |
| 227 | - $pointeur_champ->apres = $texte; |
|
| 227 | + $pointeur_champ->apres = $texte; |
|
| 228 | 228 | |
| 229 | - return $result; |
|
| 229 | + return $result; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // http://doc.spip.org/@phraser_arg |
| 233 | 233 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ){ |
| 234 | - preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 235 | - $suite = ltrim($match[2]); |
|
| 236 | - $fonc = trim($match[1]); |
|
| 237 | - if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 238 | - $res = array($fonc); |
|
| 239 | - $err_f = ''; |
|
| 240 | - // cas du filtre sans argument ou du critere / |
|
| 241 | - if (($suite && ($suite[0]!='{')) || ($fonc && $fonc[0]=='/')){ |
|
| 242 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 243 | - if (!$match[1]){ |
|
| 244 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 245 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 246 | - $texte = ''; |
|
| 247 | - } else $texte = $suite; |
|
| 248 | - if ($err_f) $pointeur_champ->param = false; |
|
| 249 | - elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 250 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 251 | - $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 252 | - |
|
| 253 | - return $result; |
|
| 254 | - } |
|
| 255 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 256 | - $collecte = array(); |
|
| 257 | - while ($args && $args[0]!='}'){ |
|
| 258 | - if ($args[0]=='"') |
|
| 259 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 260 | - else if ($args[0]=="'") |
|
| 261 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 262 | - else { |
|
| 263 | - preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 264 | - if (!strlen($regs[2])){ |
|
| 265 | - $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 266 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 267 | - $champ = new Texte; |
|
| 268 | - $champ->apres = $champ->avant = $args = ""; |
|
| 269 | - break; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $arg = $regs[2]; |
|
| 273 | - if (trim($regs[1])){ |
|
| 274 | - $champ = new Texte; |
|
| 275 | - $champ->texte = $arg; |
|
| 276 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 277 | - $result[] = $champ; |
|
| 278 | - $collecte[] = $champ; |
|
| 279 | - $args = ltrim($regs[count($regs)-1]); |
|
| 280 | - } else { |
|
| 281 | - if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)){ |
|
| 282 | - // 0 est un aveu d'impuissance. A completer |
|
| 283 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 284 | - |
|
| 285 | - $args = ltrim($regs[count($regs)-1]); |
|
| 286 | - $collecte = array_merge($collecte, $arg); |
|
| 287 | - $result = array_merge($result, $arg); |
|
| 288 | - } else { |
|
| 289 | - $n = strpos($args, $r[0]); |
|
| 290 | - $pred = substr($args, 0, $n); |
|
| 291 | - $par = ',}'; |
|
| 292 | - if (preg_match('/^(.*)\($/', $pred, $m)){ |
|
| 293 | - $pred = $m[1]; |
|
| 294 | - $par = ')'; |
|
| 295 | - } |
|
| 296 | - if ($pred){ |
|
| 297 | - $champ = new Texte; |
|
| 298 | - $champ->texte = $pred; |
|
| 299 | - $champ->apres = $champ->avant = ""; |
|
| 300 | - $result[] = $champ; |
|
| 301 | - $collecte[] = $champ; |
|
| 302 | - } |
|
| 303 | - $rec = substr($args, $n+strlen($r[0])-1); |
|
| 304 | - $champ = new Champ; |
|
| 305 | - $champ->nom_boucle = $r[2]; |
|
| 306 | - $champ->nom_champ = $r[3]; |
|
| 307 | - $champ->etoile = $r[5]; |
|
| 308 | - $next = $r[6]; |
|
| 309 | - while ($next=='{'){ |
|
| 310 | - phraser_arg($rec, $sep, array(), $champ); |
|
| 311 | - $args = ltrim($rec); |
|
| 312 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 313 | - } |
|
| 314 | - while ($next=='|'){ |
|
| 315 | - phraser_args($rec, $par, $sep, array(), $champ); |
|
| 316 | - $args = $champ->apres; |
|
| 317 | - $champ->apres = ''; |
|
| 318 | - $next = isset($args[0]) ? $args[0] : ''; |
|
| 319 | - } |
|
| 320 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 321 | - if ($champ->param===false) |
|
| 322 | - $err_f = true; |
|
| 323 | - else phraser_vieux($champ); |
|
| 324 | - if ($par==')') $args = substr($args, 1); |
|
| 325 | - $collecte[] = $champ; |
|
| 326 | - $result[] = $champ; |
|
| 327 | - } |
|
| 328 | - } |
|
| 329 | - if (isset($args[0]) AND $args[0]==','){ |
|
| 330 | - $args = ltrim(substr($args, 1)); |
|
| 331 | - if ($collecte){ |
|
| 332 | - $res[] = $collecte; |
|
| 333 | - $collecte = array(); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - if ($collecte){ |
|
| 338 | - $res[] = $collecte; |
|
| 339 | - $collecte = array(); |
|
| 340 | - } |
|
| 341 | - $texte = substr($args, 1); |
|
| 342 | - $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
|
| 343 | - // propager les erreurs, et ignorer les param vides |
|
| 344 | - if ($pointeur_champ->param!==false){ |
|
| 345 | - if ($err_f) |
|
| 346 | - $pointeur_champ->param = false; |
|
| 347 | - elseif ($fonc!=='' || count($res)>1) |
|
| 348 | - $pointeur_champ->param[] = $res; |
|
| 349 | - } |
|
| 350 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 351 | - $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 352 | - |
|
| 353 | - return $result; |
|
| 234 | + preg_match(",^(\|?[^}{)|]*)(.*)$,ms", $texte, $match); |
|
| 235 | + $suite = ltrim($match[2]); |
|
| 236 | + $fonc = trim($match[1]); |
|
| 237 | + if ($fonc && $fonc[0]=="|") $fonc = ltrim(substr($fonc, 1)); |
|
| 238 | + $res = array($fonc); |
|
| 239 | + $err_f = ''; |
|
| 240 | + // cas du filtre sans argument ou du critere / |
|
| 241 | + if (($suite && ($suite[0]!='{')) || ($fonc && $fonc[0]=='/')){ |
|
| 242 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 243 | + if (!$match[1]){ |
|
| 244 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $texte)); |
|
| 245 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 246 | + $texte = ''; |
|
| 247 | + } else $texte = $suite; |
|
| 248 | + if ($err_f) $pointeur_champ->param = false; |
|
| 249 | + elseif ($fonc!=='') $pointeur_champ->param[] = $res; |
|
| 250 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 251 | + $pointeur_champ->fonctions[] = array($fonc, ''); |
|
| 252 | + |
|
| 253 | + return $result; |
|
| 254 | + } |
|
| 255 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 256 | + $collecte = array(); |
|
| 257 | + while ($args && $args[0]!='}'){ |
|
| 258 | + if ($args[0]=='"') |
|
| 259 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 260 | + else if ($args[0]=="'") |
|
| 261 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 262 | + else { |
|
| 263 | + preg_match("/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms", $args, $regs); |
|
| 264 | + if (!strlen($regs[2])){ |
|
| 265 | + $err_f = array('zbug_erreur_filtre', array('filtre' => $args)); |
|
| 266 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 267 | + $champ = new Texte; |
|
| 268 | + $champ->apres = $champ->avant = $args = ""; |
|
| 269 | + break; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $arg = $regs[2]; |
|
| 273 | + if (trim($regs[1])){ |
|
| 274 | + $champ = new Texte; |
|
| 275 | + $champ->texte = $arg; |
|
| 276 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 277 | + $result[] = $champ; |
|
| 278 | + $collecte[] = $champ; |
|
| 279 | + $args = ltrim($regs[count($regs)-1]); |
|
| 280 | + } else { |
|
| 281 | + if (!preg_match("/" . NOM_DE_CHAMP . "([{|])/", $arg, $r)){ |
|
| 282 | + // 0 est un aveu d'impuissance. A completer |
|
| 283 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 284 | + |
|
| 285 | + $args = ltrim($regs[count($regs)-1]); |
|
| 286 | + $collecte = array_merge($collecte, $arg); |
|
| 287 | + $result = array_merge($result, $arg); |
|
| 288 | + } else { |
|
| 289 | + $n = strpos($args, $r[0]); |
|
| 290 | + $pred = substr($args, 0, $n); |
|
| 291 | + $par = ',}'; |
|
| 292 | + if (preg_match('/^(.*)\($/', $pred, $m)){ |
|
| 293 | + $pred = $m[1]; |
|
| 294 | + $par = ')'; |
|
| 295 | + } |
|
| 296 | + if ($pred){ |
|
| 297 | + $champ = new Texte; |
|
| 298 | + $champ->texte = $pred; |
|
| 299 | + $champ->apres = $champ->avant = ""; |
|
| 300 | + $result[] = $champ; |
|
| 301 | + $collecte[] = $champ; |
|
| 302 | + } |
|
| 303 | + $rec = substr($args, $n+strlen($r[0])-1); |
|
| 304 | + $champ = new Champ; |
|
| 305 | + $champ->nom_boucle = $r[2]; |
|
| 306 | + $champ->nom_champ = $r[3]; |
|
| 307 | + $champ->etoile = $r[5]; |
|
| 308 | + $next = $r[6]; |
|
| 309 | + while ($next=='{'){ |
|
| 310 | + phraser_arg($rec, $sep, array(), $champ); |
|
| 311 | + $args = ltrim($rec); |
|
| 312 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 313 | + } |
|
| 314 | + while ($next=='|'){ |
|
| 315 | + phraser_args($rec, $par, $sep, array(), $champ); |
|
| 316 | + $args = $champ->apres; |
|
| 317 | + $champ->apres = ''; |
|
| 318 | + $next = isset($args[0]) ? $args[0] : ''; |
|
| 319 | + } |
|
| 320 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 321 | + if ($champ->param===false) |
|
| 322 | + $err_f = true; |
|
| 323 | + else phraser_vieux($champ); |
|
| 324 | + if ($par==')') $args = substr($args, 1); |
|
| 325 | + $collecte[] = $champ; |
|
| 326 | + $result[] = $champ; |
|
| 327 | + } |
|
| 328 | + } |
|
| 329 | + if (isset($args[0]) AND $args[0]==','){ |
|
| 330 | + $args = ltrim(substr($args, 1)); |
|
| 331 | + if ($collecte){ |
|
| 332 | + $res[] = $collecte; |
|
| 333 | + $collecte = array(); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + if ($collecte){ |
|
| 338 | + $res[] = $collecte; |
|
| 339 | + $collecte = array(); |
|
| 340 | + } |
|
| 341 | + $texte = substr($args, 1); |
|
| 342 | + $source = substr($suite, 0, strlen($suite)-strlen($texte)); |
|
| 343 | + // propager les erreurs, et ignorer les param vides |
|
| 344 | + if ($pointeur_champ->param!==false){ |
|
| 345 | + if ($err_f) |
|
| 346 | + $pointeur_champ->param = false; |
|
| 347 | + elseif ($fonc!=='' || count($res)>1) |
|
| 348 | + $pointeur_champ->param[] = $res; |
|
| 349 | + } |
|
| 350 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 351 | + $pointeur_champ->fonctions[] = array($fonc, $source); |
|
| 352 | + |
|
| 353 | + return $result; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | |
| 357 | 357 | // http://doc.spip.org/@phraser_champs_exterieurs |
| 358 | 358 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested){ |
| 359 | - $res = array(); |
|
| 360 | - while (($p = strpos($texte, "%$sep"))!==false){ |
|
| 361 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | - break; |
|
| 363 | - $debut = substr($texte, 0, $p); |
|
| 364 | - $texte = substr($texte, $p+strlen($m[0])); |
|
| 365 | - if ($p) |
|
| 366 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 367 | - $ligne += substr_count($debut, "\n"); |
|
| 368 | - $res[] = $nested[$m[1]]; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - return (($texte==='') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 359 | + $res = array(); |
|
| 360 | + while (($p = strpos($texte, "%$sep"))!==false){ |
|
| 361 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) |
|
| 362 | + break; |
|
| 363 | + $debut = substr($texte, 0, $p); |
|
| 364 | + $texte = substr($texte, $p+strlen($m[0])); |
|
| 365 | + if ($p) |
|
| 366 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 367 | + $ligne += substr_count($debut, "\n"); |
|
| 368 | + $res[] = $nested[$m[1]]; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + return (($texte==='') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | // http://doc.spip.org/@phraser_champs_interieurs |
| 375 | 375 | function phraser_champs_interieurs($texte, $ligne, $sep, $result){ |
| 376 | - $i = 0; // en fait count($result) |
|
| 377 | - $x = ""; |
|
| 378 | - |
|
| 379 | - while (true){ |
|
| 380 | - $j = $i; |
|
| 381 | - $n = $ligne; |
|
| 382 | - while (preg_match(CHAMP_ETENDU, $texte, $match)){ |
|
| 383 | - $p = strpos($texte, $match[0]); |
|
| 384 | - $debut = substr($texte, 0, $p); |
|
| 385 | - if ($p){ |
|
| 386 | - $result[$i] = $debut; |
|
| 387 | - $i++; |
|
| 388 | - } |
|
| 389 | - $nom = $match[4]; |
|
| 390 | - $champ = new Champ; |
|
| 391 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 392 | - $champ->ligne = $x ? 0 : ($n+substr_count($debut, "\n")); |
|
| 393 | - $champ->nom_boucle = $match[3]; |
|
| 394 | - $champ->nom_champ = $nom; |
|
| 395 | - $champ->etoile = $match[6]; |
|
| 396 | - // phraser_args indiquera ou commence apres |
|
| 397 | - $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 398 | - phraser_vieux($champ); |
|
| 399 | - $champ->avant = |
|
| 400 | - phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 401 | - $debut = substr($champ->apres, 1); |
|
| 402 | - if (!empty($debut)){ |
|
| 403 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 404 | - } |
|
| 405 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 406 | - |
|
| 407 | - $result[$i] = $champ; |
|
| 408 | - $i++; |
|
| 409 | - $texte = substr($texte, $p+strlen($match[0])); |
|
| 410 | - } |
|
| 411 | - if ($texte!==""){ |
|
| 412 | - $result[$i] = $texte; |
|
| 413 | - $i++; |
|
| 414 | - } |
|
| 415 | - $x = ''; |
|
| 416 | - |
|
| 417 | - while ($j<$i){ |
|
| 418 | - $z = $result[$j]; |
|
| 419 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 420 | - if (is_object($z)) |
|
| 421 | - $x .= "%$sep$j@"; |
|
| 422 | - else |
|
| 423 | - $x .= $z; |
|
| 424 | - $j++; |
|
| 425 | - } |
|
| 426 | - if (preg_match(CHAMP_ETENDU, $x)) |
|
| 427 | - $texte = $x; |
|
| 428 | - else |
|
| 429 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 430 | - } |
|
| 376 | + $i = 0; // en fait count($result) |
|
| 377 | + $x = ""; |
|
| 378 | + |
|
| 379 | + while (true){ |
|
| 380 | + $j = $i; |
|
| 381 | + $n = $ligne; |
|
| 382 | + while (preg_match(CHAMP_ETENDU, $texte, $match)){ |
|
| 383 | + $p = strpos($texte, $match[0]); |
|
| 384 | + $debut = substr($texte, 0, $p); |
|
| 385 | + if ($p){ |
|
| 386 | + $result[$i] = $debut; |
|
| 387 | + $i++; |
|
| 388 | + } |
|
| 389 | + $nom = $match[4]; |
|
| 390 | + $champ = new Champ; |
|
| 391 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 392 | + $champ->ligne = $x ? 0 : ($n+substr_count($debut, "\n")); |
|
| 393 | + $champ->nom_boucle = $match[3]; |
|
| 394 | + $champ->nom_champ = $nom; |
|
| 395 | + $champ->etoile = $match[6]; |
|
| 396 | + // phraser_args indiquera ou commence apres |
|
| 397 | + $result = phraser_args($match[7], ")", $sep, $result, $champ); |
|
| 398 | + phraser_vieux($champ); |
|
| 399 | + $champ->avant = |
|
| 400 | + phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 401 | + $debut = substr($champ->apres, 1); |
|
| 402 | + if (!empty($debut)){ |
|
| 403 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 404 | + } |
|
| 405 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 406 | + |
|
| 407 | + $result[$i] = $champ; |
|
| 408 | + $i++; |
|
| 409 | + $texte = substr($texte, $p+strlen($match[0])); |
|
| 410 | + } |
|
| 411 | + if ($texte!==""){ |
|
| 412 | + $result[$i] = $texte; |
|
| 413 | + $i++; |
|
| 414 | + } |
|
| 415 | + $x = ''; |
|
| 416 | + |
|
| 417 | + while ($j<$i){ |
|
| 418 | + $z = $result[$j]; |
|
| 419 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 420 | + if (is_object($z)) |
|
| 421 | + $x .= "%$sep$j@"; |
|
| 422 | + else |
|
| 423 | + $x .= $z; |
|
| 424 | + $j++; |
|
| 425 | + } |
|
| 426 | + if (preg_match(CHAMP_ETENDU, $x)) |
|
| 427 | + $texte = $x; |
|
| 428 | + else |
|
| 429 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 430 | + } |
|
| 431 | 431 | } |
| 432 | 432 | |
| 433 | 433 | function phraser_vieux(&$champ){ |
| 434 | - $nom = $champ->nom_champ; |
|
| 435 | - if ($nom=='EMBED_DOCUMENT'){ |
|
| 436 | - if (!function_exists('phraser_vieux_emb')) |
|
| 437 | - include_spip('public/normaliser'); |
|
| 438 | - phraser_vieux_emb($champ); |
|
| 439 | - } elseif ($nom=='EXPOSER') { |
|
| 440 | - if (!function_exists('phraser_vieux_exposer')) |
|
| 441 | - include_spip('public/normaliser'); |
|
| 442 | - phraser_vieux_exposer($champ); |
|
| 443 | - } elseif ($champ->param) { |
|
| 444 | - if ($nom=='FORMULAIRE_RECHERCHE'){ |
|
| 445 | - if (!function_exists('phraser_vieux_recherche')) |
|
| 446 | - include_spip('public/normaliser'); |
|
| 447 | - phraser_vieux_recherche($champ); |
|
| 448 | - } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 449 | - if (!function_exists('phraser_vieux_logos')) |
|
| 450 | - include_spip('public/normaliser'); |
|
| 451 | - phraser_vieux_logos($champ); |
|
| 452 | - } elseif ($nom=='MODELE') { |
|
| 453 | - if (!function_exists('phraser_vieux_modele')) |
|
| 454 | - include_spip('public/normaliser'); |
|
| 455 | - phraser_vieux_modele($champ); |
|
| 456 | - } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
|
| 457 | - if (!function_exists('phraser_vieux_inclu')) |
|
| 458 | - include_spip('public/normaliser'); |
|
| 459 | - phraser_vieux_inclu($champ); |
|
| 460 | - } |
|
| 461 | - } |
|
| 434 | + $nom = $champ->nom_champ; |
|
| 435 | + if ($nom=='EMBED_DOCUMENT'){ |
|
| 436 | + if (!function_exists('phraser_vieux_emb')) |
|
| 437 | + include_spip('public/normaliser'); |
|
| 438 | + phraser_vieux_emb($champ); |
|
| 439 | + } elseif ($nom=='EXPOSER') { |
|
| 440 | + if (!function_exists('phraser_vieux_exposer')) |
|
| 441 | + include_spip('public/normaliser'); |
|
| 442 | + phraser_vieux_exposer($champ); |
|
| 443 | + } elseif ($champ->param) { |
|
| 444 | + if ($nom=='FORMULAIRE_RECHERCHE'){ |
|
| 445 | + if (!function_exists('phraser_vieux_recherche')) |
|
| 446 | + include_spip('public/normaliser'); |
|
| 447 | + phraser_vieux_recherche($champ); |
|
| 448 | + } elseif (preg_match(",^LOGO_[A-Z]+,", $nom)) { |
|
| 449 | + if (!function_exists('phraser_vieux_logos')) |
|
| 450 | + include_spip('public/normaliser'); |
|
| 451 | + phraser_vieux_logos($champ); |
|
| 452 | + } elseif ($nom=='MODELE') { |
|
| 453 | + if (!function_exists('phraser_vieux_modele')) |
|
| 454 | + include_spip('public/normaliser'); |
|
| 455 | + phraser_vieux_modele($champ); |
|
| 456 | + } elseif ($nom=='INCLURE' OR $nom=='INCLUDE') { |
|
| 457 | + if (!function_exists('phraser_vieux_inclu')) |
|
| 458 | + include_spip('public/normaliser'); |
|
| 459 | + phraser_vieux_inclu($champ); |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | |
@@ -486,340 +486,340 @@ discard block |
||
| 486 | 486 | **/ |
| 487 | 487 | function phraser_criteres($params, &$result){ |
| 488 | 488 | |
| 489 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 490 | - $args = array(); |
|
| 491 | - $type = $result->type_requete; |
|
| 492 | - $doublons = array(); |
|
| 493 | - foreach ($params as $v){ |
|
| 494 | - $var = $v[1][0]; |
|
| 495 | - $param = ($var->type!='texte') ? "" : $var->texte; |
|
| 496 | - if ((count($v)>2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))){ |
|
| 489 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 490 | + $args = array(); |
|
| 491 | + $type = $result->type_requete; |
|
| 492 | + $doublons = array(); |
|
| 493 | + foreach ($params as $v){ |
|
| 494 | + $var = $v[1][0]; |
|
| 495 | + $param = ($var->type!='texte') ? "" : $var->texte; |
|
| 496 | + if ((count($v)>2) && (!preg_match(",[^A-Za-z]IN[^A-Za-z],i", $param))){ |
|
| 497 | 497 | // plus d'un argument et pas le critere IN: |
| 498 | 498 | // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
| 499 | 499 | |
| 500 | - if ($var->type!='texte' |
|
| 501 | - OR preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 502 | - ){ |
|
| 503 | - $op = ','; |
|
| 504 | - $not = ""; |
|
| 505 | - } else { |
|
| 506 | - // Le debut du premier argument est l'operateur |
|
| 507 | - preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 508 | - $op = $m[2]; |
|
| 509 | - $not = $m[1]; |
|
| 510 | - $cond = $m[3]; |
|
| 511 | - // virer le premier argument, |
|
| 512 | - // et mettre son reliquat eventuel |
|
| 513 | - // Recopier pour ne pas alterer le texte source |
|
| 514 | - // utile au debusqueur |
|
| 515 | - if ($m[4]){ |
|
| 516 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 517 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
|
| 518 | - $c = null; |
|
| 519 | - eval ('$c = ' . $m[4] . ';'); |
|
| 520 | - if (isset($c)) |
|
| 521 | - $m[4] = $c; |
|
| 522 | - } |
|
| 523 | - $texte = new Texte; |
|
| 524 | - $texte->texte = $m[4]; |
|
| 525 | - $v[1][0] = $texte; |
|
| 526 | - } else array_shift($v[1]); |
|
| 527 | - } |
|
| 528 | - array_shift($v); // $v[O] est vide |
|
| 529 | - $crit = new Critere; |
|
| 530 | - $crit->op = $op; |
|
| 531 | - $crit->not = $not; |
|
| 532 | - $crit->cond = $cond; |
|
| 533 | - $crit->exclus = ""; |
|
| 534 | - $crit->param = $v; |
|
| 535 | - $args[] = $crit; |
|
| 536 | - } else { |
|
| 537 | - if ($var->type!='texte'){ |
|
| 538 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 539 | - // erreur ou critere infixe "/" |
|
| 540 | - if (($v[1][1]->type!='texte') || (trim($v[1][1]->texte)!='/')){ |
|
| 541 | - $err_ci = array('zbug_critere_inconnu', |
|
| 542 | - array('critere' => $var->nom_champ)); |
|
| 543 | - erreur_squelette($err_ci, $result); |
|
| 544 | - } else { |
|
| 545 | - $crit = new Critere; |
|
| 546 | - $crit->op = '/'; |
|
| 547 | - $crit->not = ""; |
|
| 548 | - $crit->exclus = ""; |
|
| 549 | - $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 550 | - $args[] = $crit; |
|
| 551 | - } |
|
| 552 | - } else { |
|
| 553 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 554 | - // les separateurs |
|
| 555 | - if ($var->apres) |
|
| 556 | - $result->separateur[] = $param; |
|
| 557 | - elseif (($param=='tout') OR ($param=='tous')) |
|
| 558 | - $result->modificateur['tout'] = true; |
|
| 559 | - elseif ($param=='plat') |
|
| 560 | - $result->modificateur['plat'] = true; |
|
| 561 | - |
|
| 562 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 563 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 564 | - // ceux-ci pour avoir la rubrique mere... |
|
| 565 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 566 | - // traités normalement. |
|
| 567 | - elseif (strcasecmp($type, 'hierarchie')==0 |
|
| 568 | - AND !preg_match(",^id_rubrique\b,", $param) |
|
| 569 | - AND preg_match(",^id_\w+\s*$,", $param) |
|
| 570 | - ) { |
|
| 571 | - $result->modificateur['tout'] = true; |
|
| 572 | - } elseif (strcasecmp($type, 'hierarchie')==0 AND $param=="id_rubrique") { |
|
| 573 | - // rien a faire sur {id_rubrique} tout seul |
|
| 574 | - } else { |
|
| 575 | - // pas d'emplacement statique, faut un dynamique |
|
| 576 | - /// mais il y a 2 cas qui ont les 2 ! |
|
| 577 | - if (($param=='unique') || (preg_match(',^!?doublons *,', $param))){ |
|
| 578 | - // cette variable sera inseree dans le code |
|
| 579 | - // et son nom sert d'indicateur des maintenant |
|
| 580 | - $result->doublons = '$doublons_index'; |
|
| 581 | - if ($param=='unique') $param = 'doublons'; |
|
| 582 | - } elseif ($param=='recherche') |
|
| 583 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 584 | - $result->hash = ' '; |
|
| 585 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
|
| 586 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 587 | - } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 588 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 589 | - $a2 = trim($m[8]); |
|
| 590 | - if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 591 | - $a2 = substr($a2, 1, -1); |
|
| 592 | - $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 593 | - (($m[2]=='lang_select') ? $m[2] : $m[7]), |
|
| 594 | - $m[6], $m[5]); |
|
| 595 | - $crit->exclus = $m[1]; |
|
| 596 | - } elseif (preg_match("/^([!]?)\s*(" . |
|
| 597 | - CHAMP_SQL_PLUS_FONC . |
|
| 598 | - ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 599 | - // contient aussi les comparaisons implicites ! |
|
| 600 | - // Comme ci-dessus: |
|
| 601 | - // le premier arg contient l'operateur |
|
| 602 | - array_shift($v); |
|
| 603 | - if ($m[6]){ |
|
| 604 | - $v[0][0] = new Texte; |
|
| 605 | - $v[0][0]->texte = $m[6]; |
|
| 606 | - } else { |
|
| 607 | - array_shift($v[0]); |
|
| 608 | - if (!$v[0]) array_shift($v); |
|
| 609 | - } |
|
| 610 | - $crit = new Critere; |
|
| 611 | - $crit->op = $m[2]; |
|
| 612 | - $crit->param = $v; |
|
| 613 | - $crit->not = $m[1]; |
|
| 614 | - $crit->cond = $m[5]; |
|
| 615 | - } else { |
|
| 616 | - $err_ci = array('zbug_critere_inconnu', |
|
| 617 | - array('critere' => $param)); |
|
| 618 | - erreur_squelette($err_ci, $result); |
|
| 619 | - } |
|
| 620 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) |
|
| 621 | - $args[] = $crit; |
|
| 622 | - else |
|
| 623 | - $doublons[] = $crit; |
|
| 624 | - } |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - // les doublons non nies doivent etre le dernier critere |
|
| 629 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 630 | - // cf critere_doublon |
|
| 631 | - if ($doublons) $args = array_merge($args, $doublons); |
|
| 632 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 633 | - if (!$err_ci) $result->criteres = $args; |
|
| 500 | + if ($var->type!='texte' |
|
| 501 | + OR preg_match("/^(n|n-|(n-)?\d+)$/S", $param) |
|
| 502 | + ){ |
|
| 503 | + $op = ','; |
|
| 504 | + $not = ""; |
|
| 505 | + } else { |
|
| 506 | + // Le debut du premier argument est l'operateur |
|
| 507 | + preg_match("/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms", $param, $m); |
|
| 508 | + $op = $m[2]; |
|
| 509 | + $not = $m[1]; |
|
| 510 | + $cond = $m[3]; |
|
| 511 | + // virer le premier argument, |
|
| 512 | + // et mettre son reliquat eventuel |
|
| 513 | + // Recopier pour ne pas alterer le texte source |
|
| 514 | + // utile au debusqueur |
|
| 515 | + if ($m[4]){ |
|
| 516 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 517 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])){ |
|
| 518 | + $c = null; |
|
| 519 | + eval ('$c = ' . $m[4] . ';'); |
|
| 520 | + if (isset($c)) |
|
| 521 | + $m[4] = $c; |
|
| 522 | + } |
|
| 523 | + $texte = new Texte; |
|
| 524 | + $texte->texte = $m[4]; |
|
| 525 | + $v[1][0] = $texte; |
|
| 526 | + } else array_shift($v[1]); |
|
| 527 | + } |
|
| 528 | + array_shift($v); // $v[O] est vide |
|
| 529 | + $crit = new Critere; |
|
| 530 | + $crit->op = $op; |
|
| 531 | + $crit->not = $not; |
|
| 532 | + $crit->cond = $cond; |
|
| 533 | + $crit->exclus = ""; |
|
| 534 | + $crit->param = $v; |
|
| 535 | + $args[] = $crit; |
|
| 536 | + } else { |
|
| 537 | + if ($var->type!='texte'){ |
|
| 538 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 539 | + // erreur ou critere infixe "/" |
|
| 540 | + if (($v[1][1]->type!='texte') || (trim($v[1][1]->texte)!='/')){ |
|
| 541 | + $err_ci = array('zbug_critere_inconnu', |
|
| 542 | + array('critere' => $var->nom_champ)); |
|
| 543 | + erreur_squelette($err_ci, $result); |
|
| 544 | + } else { |
|
| 545 | + $crit = new Critere; |
|
| 546 | + $crit->op = '/'; |
|
| 547 | + $crit->not = ""; |
|
| 548 | + $crit->exclus = ""; |
|
| 549 | + $crit->param = array(array($v[1][0]), array($v[1][2])); |
|
| 550 | + $args[] = $crit; |
|
| 551 | + } |
|
| 552 | + } else { |
|
| 553 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 554 | + // les separateurs |
|
| 555 | + if ($var->apres) |
|
| 556 | + $result->separateur[] = $param; |
|
| 557 | + elseif (($param=='tout') OR ($param=='tous')) |
|
| 558 | + $result->modificateur['tout'] = true; |
|
| 559 | + elseif ($param=='plat') |
|
| 560 | + $result->modificateur['plat'] = true; |
|
| 561 | + |
|
| 562 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 563 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 564 | + // ceux-ci pour avoir la rubrique mere... |
|
| 565 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 566 | + // traités normalement. |
|
| 567 | + elseif (strcasecmp($type, 'hierarchie')==0 |
|
| 568 | + AND !preg_match(",^id_rubrique\b,", $param) |
|
| 569 | + AND preg_match(",^id_\w+\s*$,", $param) |
|
| 570 | + ) { |
|
| 571 | + $result->modificateur['tout'] = true; |
|
| 572 | + } elseif (strcasecmp($type, 'hierarchie')==0 AND $param=="id_rubrique") { |
|
| 573 | + // rien a faire sur {id_rubrique} tout seul |
|
| 574 | + } else { |
|
| 575 | + // pas d'emplacement statique, faut un dynamique |
|
| 576 | + /// mais il y a 2 cas qui ont les 2 ! |
|
| 577 | + if (($param=='unique') || (preg_match(',^!?doublons *,', $param))){ |
|
| 578 | + // cette variable sera inseree dans le code |
|
| 579 | + // et son nom sert d'indicateur des maintenant |
|
| 580 | + $result->doublons = '$doublons_index'; |
|
| 581 | + if ($param=='unique') $param = 'doublons'; |
|
| 582 | + } elseif ($param=='recherche') |
|
| 583 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 584 | + $result->hash = ' '; |
|
| 585 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)){ |
|
| 586 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 587 | + } elseif (preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 588 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m)) { |
|
| 589 | + $a2 = trim($m[8]); |
|
| 590 | + if ($a2 AND ($a2[0]=="'" OR $a2[0]=='"') AND ($a2[0]==substr($a2, -1))) |
|
| 591 | + $a2 = substr($a2, 1, -1); |
|
| 592 | + $crit = phraser_critere_infixe($m[2], $a2, $v, |
|
| 593 | + (($m[2]=='lang_select') ? $m[2] : $m[7]), |
|
| 594 | + $m[6], $m[5]); |
|
| 595 | + $crit->exclus = $m[1]; |
|
| 596 | + } elseif (preg_match("/^([!]?)\s*(" . |
|
| 597 | + CHAMP_SQL_PLUS_FONC . |
|
| 598 | + ")\s*(\??)(.*)$/is", $param, $m)) { |
|
| 599 | + // contient aussi les comparaisons implicites ! |
|
| 600 | + // Comme ci-dessus: |
|
| 601 | + // le premier arg contient l'operateur |
|
| 602 | + array_shift($v); |
|
| 603 | + if ($m[6]){ |
|
| 604 | + $v[0][0] = new Texte; |
|
| 605 | + $v[0][0]->texte = $m[6]; |
|
| 606 | + } else { |
|
| 607 | + array_shift($v[0]); |
|
| 608 | + if (!$v[0]) array_shift($v); |
|
| 609 | + } |
|
| 610 | + $crit = new Critere; |
|
| 611 | + $crit->op = $m[2]; |
|
| 612 | + $crit->param = $v; |
|
| 613 | + $crit->not = $m[1]; |
|
| 614 | + $crit->cond = $m[5]; |
|
| 615 | + } else { |
|
| 616 | + $err_ci = array('zbug_critere_inconnu', |
|
| 617 | + array('critere' => $param)); |
|
| 618 | + erreur_squelette($err_ci, $result); |
|
| 619 | + } |
|
| 620 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) |
|
| 621 | + $args[] = $crit; |
|
| 622 | + else |
|
| 623 | + $doublons[] = $crit; |
|
| 624 | + } |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + // les doublons non nies doivent etre le dernier critere |
|
| 629 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 630 | + // cf critere_doublon |
|
| 631 | + if ($doublons) $args = array_merge($args, $doublons); |
|
| 632 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 633 | + if (!$err_ci) $result->criteres = $args; |
|
| 634 | 634 | } |
| 635 | 635 | |
| 636 | 636 | // http://doc.spip.org/@phraser_critere_infixe |
| 637 | 637 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond){ |
| 638 | - $args[0] = new Texte; |
|
| 639 | - $args[0]->texte = $arg1; |
|
| 640 | - $args[0] = array($args[0]); |
|
| 641 | - $args[1][0] = new Texte; |
|
| 642 | - $args[1][0]->texte = $arg2; |
|
| 643 | - $crit = new Critere; |
|
| 644 | - $crit->op = $op; |
|
| 645 | - $crit->not = $not; |
|
| 646 | - $crit->cond = $cond; |
|
| 647 | - $crit->param = $args; |
|
| 648 | - |
|
| 649 | - return $crit; |
|
| 638 | + $args[0] = new Texte; |
|
| 639 | + $args[0]->texte = $arg1; |
|
| 640 | + $args[0] = array($args[0]); |
|
| 641 | + $args[1][0] = new Texte; |
|
| 642 | + $args[1][0]->texte = $arg2; |
|
| 643 | + $crit = new Critere; |
|
| 644 | + $crit->op = $op; |
|
| 645 | + $crit->not = $not; |
|
| 646 | + $crit->cond = $cond; |
|
| 647 | + $crit->param = $args; |
|
| 648 | + |
|
| 649 | + return $crit; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne = 1){ |
| 653 | 653 | |
| 654 | - $all_res = array(); |
|
| 654 | + $all_res = array(); |
|
| 655 | 655 | |
| 656 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE))!==false){ |
|
| 656 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE))!==false){ |
|
| 657 | 657 | |
| 658 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 659 | - $result = new Boucle; |
|
| 660 | - $result->id_parent = $id_parent; |
|
| 661 | - $result->descr = $descr; |
|
| 658 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 659 | + $result = new Boucle; |
|
| 660 | + $result->id_parent = $id_parent; |
|
| 661 | + $result->descr = $descr; |
|
| 662 | 662 | # attention: reperer la premiere des 2 balises: pre_boucle ou boucle |
| 663 | 663 | |
| 664 | - if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 665 | - OR ($n = strpos($texte, $r[0]))===false |
|
| 666 | - OR ($n>$pos_boucle) |
|
| 667 | - ){ |
|
| 668 | - $debut = substr($texte, 0, $pos_boucle); |
|
| 669 | - $milieu = substr($texte, $pos_boucle); |
|
| 670 | - $k = strpos($milieu, '('); |
|
| 671 | - $id_boucle = trim(substr($milieu, |
|
| 672 | - strlen(BALISE_BOUCLE), |
|
| 673 | - $k-strlen(BALISE_BOUCLE))); |
|
| 674 | - $milieu = substr($milieu, $k); |
|
| 675 | - |
|
| 676 | - } else { |
|
| 677 | - $debut = substr($texte, 0, $n); |
|
| 678 | - $milieu = substr($texte, $n); |
|
| 679 | - $k = strpos($milieu, '>'); |
|
| 680 | - $id_boucle = substr($milieu, |
|
| 681 | - strlen(BALISE_PRE_BOUCLE), |
|
| 682 | - $k-strlen(BALISE_PRE_BOUCLE)); |
|
| 683 | - |
|
| 684 | - if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)){ |
|
| 685 | - $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 686 | - erreur_squelette($err_b, $result); |
|
| 687 | - $texte = substr($texte, $n+1); |
|
| 688 | - continue; |
|
| 689 | - } else { |
|
| 690 | - $pos_boucle = $n; |
|
| 691 | - $n = strpos($milieu, $r[0]); |
|
| 692 | - $result->avant = substr($milieu, $k+1, $n-$k-1); |
|
| 693 | - $milieu = substr($milieu, $n+strlen($id_boucle)+strlen(BALISE_BOUCLE)); |
|
| 694 | - } |
|
| 695 | - } |
|
| 696 | - $result->id_boucle = $id_boucle; |
|
| 697 | - |
|
| 698 | - preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 699 | - $result->type_requete = $match[0]; |
|
| 700 | - $milieu = substr($milieu, strlen($match[0])); |
|
| 701 | - $type = $match[1]; |
|
| 702 | - $jointures = trim($match[2]); |
|
| 703 | - $table_optionnelle = ($match[3]); |
|
| 704 | - if ($jointures){ |
|
| 705 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 706 | - // ou elles seront completees des jointures declarees |
|
| 707 | - $result->jointures_explicites = $jointures; |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - if ($table_optionnelle){ |
|
| 711 | - $result->table_optionnelle = $type; |
|
| 712 | - } |
|
| 713 | - |
|
| 714 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 715 | - // Resultat mis dans result->param |
|
| 716 | - phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 717 | - |
|
| 718 | - // En 2e passe result->criteres contiendra un tableau |
|
| 719 | - // pour l'instant on met le source (chaine) : |
|
| 720 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 721 | - $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 722 | - $milieu = $result->apres; |
|
| 723 | - $result->apres = ""; |
|
| 724 | - |
|
| 725 | - // |
|
| 726 | - // Recuperer la fin : |
|
| 727 | - // |
|
| 728 | - if ($milieu[0]==='/'){ |
|
| 729 | - $suite = substr($milieu, 2); |
|
| 730 | - $milieu = ''; |
|
| 731 | - } else { |
|
| 732 | - $milieu = substr($milieu, 1); |
|
| 733 | - $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 734 | - $p = strpos($milieu, $s); |
|
| 735 | - if ($p===false){ |
|
| 736 | - $err_b = array('zbug_erreur_boucle_fermant', |
|
| 737 | - array('id' => $id_boucle)); |
|
| 738 | - erreur_squelette($err_b, $result); |
|
| 739 | - } |
|
| 740 | - |
|
| 741 | - $suite = substr($milieu, $p+strlen($s)); |
|
| 742 | - $milieu = substr($milieu, 0, $p); |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - $result->milieu = $milieu; |
|
| 746 | - |
|
| 747 | - // |
|
| 748 | - // 1. Recuperer la partie conditionnelle apres |
|
| 749 | - // |
|
| 750 | - $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 751 | - $p = strpos($suite, $s); |
|
| 752 | - if ($p!==false){ |
|
| 753 | - $result->apres = substr($suite, 0, $p); |
|
| 754 | - $suite = substr($suite, $p+strlen($s)); |
|
| 755 | - } |
|
| 756 | - |
|
| 757 | - // |
|
| 758 | - // 2. Recuperer la partie alternative |
|
| 759 | - // |
|
| 760 | - $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 761 | - $p = strpos($suite, $s); |
|
| 762 | - if ($p!==false){ |
|
| 763 | - $result->altern = substr($suite, 0, $p); |
|
| 764 | - $suite = substr($suite, $p+strlen($s)); |
|
| 765 | - } |
|
| 766 | - $result->ligne = $ligne+substr_count($debut, "\n"); |
|
| 767 | - $m = substr_count($milieu, "\n"); |
|
| 768 | - $b = substr_count($result->avant, "\n"); |
|
| 769 | - $a = substr_count($result->apres, "\n"); |
|
| 770 | - |
|
| 771 | - if ($p = strpos($type, ':')){ |
|
| 772 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 773 | - $type = substr($type, $p+1); |
|
| 774 | - } |
|
| 775 | - $soustype = strtolower($type); |
|
| 776 | - |
|
| 777 | - if (!isset($GLOBALS["table_des_tables"][$soustype])) |
|
| 778 | - $soustype = $type; |
|
| 779 | - |
|
| 780 | - $result->type_requete = $soustype; |
|
| 781 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 782 | - if (!is_array($result->param)) |
|
| 783 | - $err_b = true; |
|
| 784 | - else { |
|
| 785 | - phraser_criteres($result->param, $result); |
|
| 786 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
|
| 787 | - $result->type_requete = TYPE_RECURSIF; |
|
| 788 | - $args = $result->param; |
|
| 789 | - array_unshift($args, |
|
| 790 | - substr($type, strlen(TYPE_RECURSIF))); |
|
| 791 | - $result->param = $args; |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - |
|
| 795 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 796 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne+$b+$m); |
|
| 797 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne+$a+$m+$b); |
|
| 798 | - $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
|
| 799 | - |
|
| 800 | - // Prevenir le generateur de code que le squelette est faux |
|
| 801 | - if ($err_b) $result->type_requete = false; |
|
| 802 | - |
|
| 803 | - // Verifier qu'il n'y a pas double definition |
|
| 804 | - // apres analyse des sous-parties (pas avant). |
|
| 805 | - |
|
| 806 | - if (isset($boucles[$id_boucle])){ |
|
| 807 | - $err_b_d = array('zbug_erreur_boucle_double', |
|
| 808 | - array('id' => $id_boucle)); |
|
| 809 | - erreur_squelette($err_b_d, $result); |
|
| 810 | - // Prevenir le generateur de code que le squelette est faux |
|
| 811 | - $boucles[$id_boucle]->type_requete = false; |
|
| 812 | - } else |
|
| 813 | - $boucles[$id_boucle] = $result; |
|
| 814 | - $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 815 | - $all_res[] = &$boucles[$id_boucle]; |
|
| 816 | - if (!empty($suite)){ |
|
| 817 | - $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 818 | - } |
|
| 819 | - $texte = $suite; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 664 | + if (!preg_match("," . BALISE_PRE_BOUCLE . '[0-9_],', $texte, $r) |
|
| 665 | + OR ($n = strpos($texte, $r[0]))===false |
|
| 666 | + OR ($n>$pos_boucle) |
|
| 667 | + ){ |
|
| 668 | + $debut = substr($texte, 0, $pos_boucle); |
|
| 669 | + $milieu = substr($texte, $pos_boucle); |
|
| 670 | + $k = strpos($milieu, '('); |
|
| 671 | + $id_boucle = trim(substr($milieu, |
|
| 672 | + strlen(BALISE_BOUCLE), |
|
| 673 | + $k-strlen(BALISE_BOUCLE))); |
|
| 674 | + $milieu = substr($milieu, $k); |
|
| 675 | + |
|
| 676 | + } else { |
|
| 677 | + $debut = substr($texte, 0, $n); |
|
| 678 | + $milieu = substr($texte, $n); |
|
| 679 | + $k = strpos($milieu, '>'); |
|
| 680 | + $id_boucle = substr($milieu, |
|
| 681 | + strlen(BALISE_PRE_BOUCLE), |
|
| 682 | + $k-strlen(BALISE_PRE_BOUCLE)); |
|
| 683 | + |
|
| 684 | + if (!preg_match("," . BALISE_BOUCLE . $id_boucle . "[[:space:]]*\(,", $milieu, $r)){ |
|
| 685 | + $err_b = array('zbug_erreur_boucle_syntaxe', array('id' => $id_boucle)); |
|
| 686 | + erreur_squelette($err_b, $result); |
|
| 687 | + $texte = substr($texte, $n+1); |
|
| 688 | + continue; |
|
| 689 | + } else { |
|
| 690 | + $pos_boucle = $n; |
|
| 691 | + $n = strpos($milieu, $r[0]); |
|
| 692 | + $result->avant = substr($milieu, $k+1, $n-$k-1); |
|
| 693 | + $milieu = substr($milieu, $n+strlen($id_boucle)+strlen(BALISE_BOUCLE)); |
|
| 694 | + } |
|
| 695 | + } |
|
| 696 | + $result->id_boucle = $id_boucle; |
|
| 697 | + |
|
| 698 | + preg_match(SPEC_BOUCLE, $milieu, $match); |
|
| 699 | + $result->type_requete = $match[0]; |
|
| 700 | + $milieu = substr($milieu, strlen($match[0])); |
|
| 701 | + $type = $match[1]; |
|
| 702 | + $jointures = trim($match[2]); |
|
| 703 | + $table_optionnelle = ($match[3]); |
|
| 704 | + if ($jointures){ |
|
| 705 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 706 | + // ou elles seront completees des jointures declarees |
|
| 707 | + $result->jointures_explicites = $jointures; |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + if ($table_optionnelle){ |
|
| 711 | + $result->table_optionnelle = $type; |
|
| 712 | + } |
|
| 713 | + |
|
| 714 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 715 | + // Resultat mis dans result->param |
|
| 716 | + phraser_args($milieu, "/>", "", $all_res, $result); |
|
| 717 | + |
|
| 718 | + // En 2e passe result->criteres contiendra un tableau |
|
| 719 | + // pour l'instant on met le source (chaine) : |
|
| 720 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 721 | + $result->criteres = substr($milieu, 0, @strpos($milieu, $result->apres)); |
|
| 722 | + $milieu = $result->apres; |
|
| 723 | + $result->apres = ""; |
|
| 724 | + |
|
| 725 | + // |
|
| 726 | + // Recuperer la fin : |
|
| 727 | + // |
|
| 728 | + if ($milieu[0]==='/'){ |
|
| 729 | + $suite = substr($milieu, 2); |
|
| 730 | + $milieu = ''; |
|
| 731 | + } else { |
|
| 732 | + $milieu = substr($milieu, 1); |
|
| 733 | + $s = BALISE_FIN_BOUCLE . $id_boucle . ">"; |
|
| 734 | + $p = strpos($milieu, $s); |
|
| 735 | + if ($p===false){ |
|
| 736 | + $err_b = array('zbug_erreur_boucle_fermant', |
|
| 737 | + array('id' => $id_boucle)); |
|
| 738 | + erreur_squelette($err_b, $result); |
|
| 739 | + } |
|
| 740 | + |
|
| 741 | + $suite = substr($milieu, $p+strlen($s)); |
|
| 742 | + $milieu = substr($milieu, 0, $p); |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + $result->milieu = $milieu; |
|
| 746 | + |
|
| 747 | + // |
|
| 748 | + // 1. Recuperer la partie conditionnelle apres |
|
| 749 | + // |
|
| 750 | + $s = BALISE_POST_BOUCLE . $id_boucle . ">"; |
|
| 751 | + $p = strpos($suite, $s); |
|
| 752 | + if ($p!==false){ |
|
| 753 | + $result->apres = substr($suite, 0, $p); |
|
| 754 | + $suite = substr($suite, $p+strlen($s)); |
|
| 755 | + } |
|
| 756 | + |
|
| 757 | + // |
|
| 758 | + // 2. Recuperer la partie alternative |
|
| 759 | + // |
|
| 760 | + $s = BALISE_ALT_BOUCLE . $id_boucle . ">"; |
|
| 761 | + $p = strpos($suite, $s); |
|
| 762 | + if ($p!==false){ |
|
| 763 | + $result->altern = substr($suite, 0, $p); |
|
| 764 | + $suite = substr($suite, $p+strlen($s)); |
|
| 765 | + } |
|
| 766 | + $result->ligne = $ligne+substr_count($debut, "\n"); |
|
| 767 | + $m = substr_count($milieu, "\n"); |
|
| 768 | + $b = substr_count($result->avant, "\n"); |
|
| 769 | + $a = substr_count($result->apres, "\n"); |
|
| 770 | + |
|
| 771 | + if ($p = strpos($type, ':')){ |
|
| 772 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 773 | + $type = substr($type, $p+1); |
|
| 774 | + } |
|
| 775 | + $soustype = strtolower($type); |
|
| 776 | + |
|
| 777 | + if (!isset($GLOBALS["table_des_tables"][$soustype])) |
|
| 778 | + $soustype = $type; |
|
| 779 | + |
|
| 780 | + $result->type_requete = $soustype; |
|
| 781 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 782 | + if (!is_array($result->param)) |
|
| 783 | + $err_b = true; |
|
| 784 | + else { |
|
| 785 | + phraser_criteres($result->param, $result); |
|
| 786 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF))==0){ |
|
| 787 | + $result->type_requete = TYPE_RECURSIF; |
|
| 788 | + $args = $result->param; |
|
| 789 | + array_unshift($args, |
|
| 790 | + substr($type, strlen(TYPE_RECURSIF))); |
|
| 791 | + $result->param = $args; |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + |
|
| 795 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $result->ligne); |
|
| 796 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $result->ligne+$b+$m); |
|
| 797 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $result->ligne+$a+$m+$b); |
|
| 798 | + $result->milieu = public_phraser_html_dist($milieu, $id_boucle, $boucles, $descr, $result->ligne+$b); |
|
| 799 | + |
|
| 800 | + // Prevenir le generateur de code que le squelette est faux |
|
| 801 | + if ($err_b) $result->type_requete = false; |
|
| 802 | + |
|
| 803 | + // Verifier qu'il n'y a pas double definition |
|
| 804 | + // apres analyse des sous-parties (pas avant). |
|
| 805 | + |
|
| 806 | + if (isset($boucles[$id_boucle])){ |
|
| 807 | + $err_b_d = array('zbug_erreur_boucle_double', |
|
| 808 | + array('id' => $id_boucle)); |
|
| 809 | + erreur_squelette($err_b_d, $result); |
|
| 810 | + // Prevenir le generateur de code que le squelette est faux |
|
| 811 | + $boucles[$id_boucle]->type_requete = false; |
|
| 812 | + } else |
|
| 813 | + $boucles[$id_boucle] = $result; |
|
| 814 | + $all_res = phraser_champs_etendus($debut, $ligne, $all_res); |
|
| 815 | + $all_res[] = &$boucles[$id_boucle]; |
|
| 816 | + if (!empty($suite)){ |
|
| 817 | + $ligne += substr_count(substr($texte, 0, strpos($texte, $suite)), "\n"); |
|
| 818 | + } |
|
| 819 | + $texte = $suite; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + return phraser_champs_etendus($texte, $ligne, $all_res); |
|
| 823 | 823 | } |
| 824 | 824 | |
| 825 | 825 | ?> |
@@ -22,132 +22,132 @@ discard block |
||
| 22 | 22 | // http://doc.spip.org/@assembler |
| 23 | 23 | function assembler($fond, $connect='') { |
| 24 | 24 | |
| 25 | - // flag_preserver est modifie ici, et utilise en globale |
|
| 26 | - // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 27 | - // contexte est utilise en globale dans le formulaire d'admin |
|
| 28 | - global $flag_preserver, $use_cache, $contexte; |
|
| 29 | - |
|
| 30 | - $contexte = calculer_contexte(); |
|
| 31 | - $page = array('contexte_implicite'=>calculer_contexte_implicite()); |
|
| 32 | - $page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '', preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI'])); |
|
| 33 | - // Cette fonction est utilisee deux fois |
|
| 34 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 35 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 36 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 37 | - if ($cacher) |
|
| 38 | - $res = $cacher($GLOBALS['contexte'], $use_cache, $chemin_cache, $page, $lastmodified); |
|
| 39 | - else |
|
| 40 | - $use_cache = -1; |
|
| 41 | - // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 42 | - if ($res) {return array('texte' => $res);} |
|
| 43 | - |
|
| 44 | - if (!$chemin_cache || !$lastmodified) $lastmodified = time(); |
|
| 45 | - |
|
| 46 | - $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 47 | - $calculer_page = true; |
|
| 48 | - |
|
| 49 | - // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 50 | - // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 51 | - // pages sont dynamiques) |
|
| 52 | - if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 53 | - AND (!defined('_VAR_MODE') OR !_VAR_MODE) |
|
| 54 | - AND $chemin_cache |
|
| 55 | - AND isset($page['entetes']) |
|
| 56 | - AND isset($page['entetes']['Cache-Control']) |
|
| 57 | - AND strstr($page['entetes']['Cache-Control'],'max-age=') |
|
| 58 | - AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/') |
|
| 59 | - ) { |
|
| 60 | - $since = preg_replace('/;.*/', '', |
|
| 61 | - $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|
| 62 | - $since = str_replace('GMT', '', $since); |
|
| 63 | - if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) { |
|
| 64 | - $page['status'] = 304; |
|
| 65 | - $headers_only = true; |
|
| 66 | - $calculer_page = false; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 71 | - // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 72 | - if (!$calculer_page) { |
|
| 73 | - $page['texte'] = ""; |
|
| 74 | - } else { |
|
| 75 | - // si la page est prise dans le cache |
|
| 76 | - if (!$use_cache) { |
|
| 77 | - // Informer les boutons d'admin du contexte |
|
| 78 | - // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 79 | - $contexte = $page['contexte']; |
|
| 80 | - |
|
| 81 | - // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 82 | - // d'inversion url => objet |
|
| 83 | - // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 84 | - #unset($_SERVER['REDIRECT_url_propre']); |
|
| 85 | - #unset($_ENV['url_propre']); |
|
| 86 | - } |
|
| 87 | - else { |
|
| 88 | - // Compat ascendante : |
|
| 89 | - // 1. $contexte est global |
|
| 90 | - // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 91 | - // et calculer la page |
|
| 92 | - if (!test_espace_prive()) { |
|
| 93 | - include_spip('inc/urls'); |
|
| 94 | - list($fond,$contexte,$url_redirect) = urls_decoder_url(nettoyer_uri(),$fond,$contexte,true); |
|
| 95 | - } |
|
| 96 | - // squelette par defaut |
|
| 97 | - if (!strlen($fond)) |
|
| 98 | - $fond = 'sommaire'; |
|
| 99 | - |
|
| 100 | - // produire la page : peut mettre a jour $lastmodified |
|
| 101 | - $produire_page = charger_fonction('produire_page','public'); |
|
| 102 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, NULL, $page, $lastmodified, $connect); |
|
| 103 | - if ($page === '') { |
|
| 104 | - $erreur = _T('info_erreur_squelette2', |
|
| 105 | - array('fichier'=>spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES)); |
|
| 106 | - erreur_squelette($erreur); |
|
| 107 | - // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 108 | - $page = array('texte' => '', 'erreur' => $erreur); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - if ($page AND $chemin_cache) $page['cache'] = $chemin_cache; |
|
| 113 | - |
|
| 114 | - auto_content_type($page); |
|
| 115 | - |
|
| 116 | - $flag_preserver |= headers_sent(); |
|
| 117 | - |
|
| 118 | - // Definir les entetes si ce n'est fait |
|
| 119 | - if (!$flag_preserver) { |
|
| 120 | - if ($GLOBALS['flag_ob']) { |
|
| 121 | - // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 122 | - if (trim($page['texte']) === '' |
|
| 123 | - AND _VAR_MODE != 'debug' |
|
| 124 | - AND !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 125 | - ) { |
|
| 126 | - $contexte['fond_erreur'] = $fond; |
|
| 127 | - $page = message_page_indisponible($page, $contexte); |
|
| 128 | - } |
|
| 129 | - // pas de cache client en mode 'observation' |
|
| 130 | - if (defined('_VAR_MODE') AND _VAR_MODE) { |
|
| 131 | - $page['entetes']["Cache-Control"]= "no-cache,must-revalidate"; |
|
| 132 | - $page['entetes']["Pragma"] = "no-cache"; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Entete Last-Modified: |
|
| 139 | - // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 140 | - // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 141 | - if ($lastmodified |
|
| 142 | - AND !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 143 | - AND !isset($page['entetes']["Last-Modified"])) |
|
| 144 | - $page['entetes']["Last-Modified"]=gmdate("D, d M Y H:i:s", $lastmodified)." GMT"; |
|
| 145 | - |
|
| 146 | - // fermer la connexion apres les headers si requete HEAD |
|
| 147 | - if ($headers_only) |
|
| 148 | - $page['entetes']["Connection"] = "close"; |
|
| 149 | - |
|
| 150 | - return $page; |
|
| 25 | + // flag_preserver est modifie ici, et utilise en globale |
|
| 26 | + // use_cache sert a informer le bouton d'admin pr savoir s'il met un * |
|
| 27 | + // contexte est utilise en globale dans le formulaire d'admin |
|
| 28 | + global $flag_preserver, $use_cache, $contexte; |
|
| 29 | + |
|
| 30 | + $contexte = calculer_contexte(); |
|
| 31 | + $page = array('contexte_implicite'=>calculer_contexte_implicite()); |
|
| 32 | + $page['contexte_implicite']['cache'] = $fond . preg_replace(',\.[a-zA-Z0-9]*$,', '', preg_replace('/[?].*$/', '', $GLOBALS['REQUEST_URI'])); |
|
| 33 | + // Cette fonction est utilisee deux fois |
|
| 34 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 35 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 36 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 37 | + if ($cacher) |
|
| 38 | + $res = $cacher($GLOBALS['contexte'], $use_cache, $chemin_cache, $page, $lastmodified); |
|
| 39 | + else |
|
| 40 | + $use_cache = -1; |
|
| 41 | + // Si un resultat est retourne, c'est un message d'impossibilite |
|
| 42 | + if ($res) {return array('texte' => $res);} |
|
| 43 | + |
|
| 44 | + if (!$chemin_cache || !$lastmodified) $lastmodified = time(); |
|
| 45 | + |
|
| 46 | + $headers_only = ($_SERVER['REQUEST_METHOD'] == 'HEAD'); |
|
| 47 | + $calculer_page = true; |
|
| 48 | + |
|
| 49 | + // Pour les pages non-dynamiques (indiquees par #CACHE{duree,cache-client}) |
|
| 50 | + // une perennite valide a meme reponse qu'une requete HEAD (par defaut les |
|
| 51 | + // pages sont dynamiques) |
|
| 52 | + if (isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 53 | + AND (!defined('_VAR_MODE') OR !_VAR_MODE) |
|
| 54 | + AND $chemin_cache |
|
| 55 | + AND isset($page['entetes']) |
|
| 56 | + AND isset($page['entetes']['Cache-Control']) |
|
| 57 | + AND strstr($page['entetes']['Cache-Control'],'max-age=') |
|
| 58 | + AND !strstr($_SERVER['SERVER_SOFTWARE'],'IIS/') |
|
| 59 | + ) { |
|
| 60 | + $since = preg_replace('/;.*/', '', |
|
| 61 | + $_SERVER['HTTP_IF_MODIFIED_SINCE']); |
|
| 62 | + $since = str_replace('GMT', '', $since); |
|
| 63 | + if (trim($since) == gmdate("D, d M Y H:i:s", $lastmodified)) { |
|
| 64 | + $page['status'] = 304; |
|
| 65 | + $headers_only = true; |
|
| 66 | + $calculer_page = false; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + // Si requete HEAD ou Last-modified compatible, ignorer le texte |
|
| 71 | + // et pas de content-type (pour contrer le bouton admin de inc-public) |
|
| 72 | + if (!$calculer_page) { |
|
| 73 | + $page['texte'] = ""; |
|
| 74 | + } else { |
|
| 75 | + // si la page est prise dans le cache |
|
| 76 | + if (!$use_cache) { |
|
| 77 | + // Informer les boutons d'admin du contexte |
|
| 78 | + // (fourni par urls_decoder_url ci-dessous lors de la mise en cache) |
|
| 79 | + $contexte = $page['contexte']; |
|
| 80 | + |
|
| 81 | + // vider les globales url propres qui ne doivent plus etre utilisees en cas |
|
| 82 | + // d'inversion url => objet |
|
| 83 | + // plus necessaire si on utilise bien la fonction urls_decoder_url |
|
| 84 | + #unset($_SERVER['REDIRECT_url_propre']); |
|
| 85 | + #unset($_ENV['url_propre']); |
|
| 86 | + } |
|
| 87 | + else { |
|
| 88 | + // Compat ascendante : |
|
| 89 | + // 1. $contexte est global |
|
| 90 | + // (a evacuer car urls_decoder_url gere ce probleme ?) |
|
| 91 | + // et calculer la page |
|
| 92 | + if (!test_espace_prive()) { |
|
| 93 | + include_spip('inc/urls'); |
|
| 94 | + list($fond,$contexte,$url_redirect) = urls_decoder_url(nettoyer_uri(),$fond,$contexte,true); |
|
| 95 | + } |
|
| 96 | + // squelette par defaut |
|
| 97 | + if (!strlen($fond)) |
|
| 98 | + $fond = 'sommaire'; |
|
| 99 | + |
|
| 100 | + // produire la page : peut mettre a jour $lastmodified |
|
| 101 | + $produire_page = charger_fonction('produire_page','public'); |
|
| 102 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, NULL, $page, $lastmodified, $connect); |
|
| 103 | + if ($page === '') { |
|
| 104 | + $erreur = _T('info_erreur_squelette2', |
|
| 105 | + array('fichier'=>spip_htmlspecialchars($fond).'.'._EXTENSION_SQUELETTES)); |
|
| 106 | + erreur_squelette($erreur); |
|
| 107 | + // eviter des erreurs strictes ensuite sur $page['cle'] en PHP >= 5.4 |
|
| 108 | + $page = array('texte' => '', 'erreur' => $erreur); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + if ($page AND $chemin_cache) $page['cache'] = $chemin_cache; |
|
| 113 | + |
|
| 114 | + auto_content_type($page); |
|
| 115 | + |
|
| 116 | + $flag_preserver |= headers_sent(); |
|
| 117 | + |
|
| 118 | + // Definir les entetes si ce n'est fait |
|
| 119 | + if (!$flag_preserver) { |
|
| 120 | + if ($GLOBALS['flag_ob']) { |
|
| 121 | + // Si la page est vide, produire l'erreur 404 ou message d'erreur pour les inclusions |
|
| 122 | + if (trim($page['texte']) === '' |
|
| 123 | + AND _VAR_MODE != 'debug' |
|
| 124 | + AND !isset($page['entetes']['Location']) // cette page realise une redirection, donc pas d'erreur |
|
| 125 | + ) { |
|
| 126 | + $contexte['fond_erreur'] = $fond; |
|
| 127 | + $page = message_page_indisponible($page, $contexte); |
|
| 128 | + } |
|
| 129 | + // pas de cache client en mode 'observation' |
|
| 130 | + if (defined('_VAR_MODE') AND _VAR_MODE) { |
|
| 131 | + $page['entetes']["Cache-Control"]= "no-cache,must-revalidate"; |
|
| 132 | + $page['entetes']["Pragma"] = "no-cache"; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Entete Last-Modified: |
|
| 139 | + // eviter d'etre incoherent en envoyant un lastmodified identique |
|
| 140 | + // a celui qu'on a refuse d'honorer plus haut (cf. #655) |
|
| 141 | + if ($lastmodified |
|
| 142 | + AND !isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) |
|
| 143 | + AND !isset($page['entetes']["Last-Modified"])) |
|
| 144 | + $page['entetes']["Last-Modified"]=gmdate("D, d M Y H:i:s", $lastmodified)." GMT"; |
|
| 145 | + |
|
| 146 | + // fermer la connexion apres les headers si requete HEAD |
|
| 147 | + if ($headers_only) |
|
| 148 | + $page['entetes']["Connection"] = "close"; |
|
| 149 | + |
|
| 150 | + return $page; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | // |
@@ -160,17 +160,17 @@ discard block |
||
| 160 | 160 | // http://doc.spip.org/@calculer_contexte |
| 161 | 161 | function calculer_contexte() { |
| 162 | 162 | |
| 163 | - $contexte = array(); |
|
| 164 | - foreach($_GET as $var => $val) { |
|
| 165 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES,$var)) |
|
| 166 | - $contexte[$var] = $val; |
|
| 167 | - } |
|
| 168 | - foreach($_POST as $var => $val) { |
|
| 169 | - if (!preg_match(_CONTEXTE_IGNORE_VARIABLES,$var)) |
|
| 170 | - $contexte[$var] = $val; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - return $contexte; |
|
| 163 | + $contexte = array(); |
|
| 164 | + foreach($_GET as $var => $val) { |
|
| 165 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES,$var)) |
|
| 166 | + $contexte[$var] = $val; |
|
| 167 | + } |
|
| 168 | + foreach($_POST as $var => $val) { |
|
| 169 | + if (!preg_match(_CONTEXTE_IGNORE_VARIABLES,$var)) |
|
| 170 | + $contexte[$var] = $val; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + return $contexte; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -181,20 +181,20 @@ discard block |
||
| 181 | 181 | * @return array |
| 182 | 182 | */ |
| 183 | 183 | function calculer_contexte_implicite(){ |
| 184 | - static $notes = null; |
|
| 185 | - if (is_null($notes)) |
|
| 186 | - $notes = charger_fonction('notes','inc',true); |
|
| 187 | - $contexte_implicite = array( |
|
| 188 | - 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 189 | - 'host' => $_SERVER['HTTP_HOST'], |
|
| 190 | - 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 191 | - 'espace' => test_espace_prive(), |
|
| 192 | - 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 193 | - 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 194 | - 'notes' => $notes?$notes('','contexter_cache'):'', |
|
| 195 | - 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 196 | - ); |
|
| 197 | - return $contexte_implicite; |
|
| 184 | + static $notes = null; |
|
| 185 | + if (is_null($notes)) |
|
| 186 | + $notes = charger_fonction('notes','inc',true); |
|
| 187 | + $contexte_implicite = array( |
|
| 188 | + 'squelettes' => $GLOBALS['dossier_squelettes'], // devrait etre 'chemin' => $GLOBALS['path_sig'], ? |
|
| 189 | + 'host' => $_SERVER['HTTP_HOST'], |
|
| 190 | + 'https' => (isset($_SERVER['HTTPS']) ? $_SERVER['HTTPS'] : ''), |
|
| 191 | + 'espace' => test_espace_prive(), |
|
| 192 | + 'marqueur' => (isset($GLOBALS['marqueur']) ? $GLOBALS['marqueur'] : ''), |
|
| 193 | + 'marqueur_skel' => (isset($GLOBALS['marqueur_skel']) ? $GLOBALS['marqueur_skel'] : ''), |
|
| 194 | + 'notes' => $notes?$notes('','contexter_cache'):'', |
|
| 195 | + 'spip_version_code' => $GLOBALS['spip_version_code'], |
|
| 196 | + ); |
|
| 197 | + return $contexte_implicite; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | // |
@@ -204,47 +204,47 @@ discard block |
||
| 204 | 204 | // http://doc.spip.org/@auto_content_type |
| 205 | 205 | function auto_content_type($page) |
| 206 | 206 | { |
| 207 | - global $flag_preserver; |
|
| 208 | - if (!isset($flag_preserver)) |
|
| 209 | - { |
|
| 210 | - $flag_preserver = ($page && preg_match("/header\s*\(\s*.content\-type:/isx",$page['texte']) || (isset($page['entetes']['Content-Type']))); |
|
| 211 | - } |
|
| 207 | + global $flag_preserver; |
|
| 208 | + if (!isset($flag_preserver)) |
|
| 209 | + { |
|
| 210 | + $flag_preserver = ($page && preg_match("/header\s*\(\s*.content\-type:/isx",$page['texte']) || (isset($page['entetes']['Content-Type']))); |
|
| 211 | + } |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | // http://doc.spip.org/@inclure_page |
| 215 | 215 | function inclure_page($fond, $contexte, $connect='') { |
| 216 | - static $cacher, $produire_page; |
|
| 217 | - global $lastmodified; |
|
| 218 | - |
|
| 219 | - // enlever le fond de contexte inclus car sinon il prend la main |
|
| 220 | - // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 221 | - // (cette precaution n'est probablement plus utile) |
|
| 222 | - unset($contexte['fond']); |
|
| 223 | - $page = array('contexte_implicite'=>calculer_contexte_implicite()); |
|
| 224 | - $page['contexte_implicite']['cache'] = $fond; |
|
| 225 | - if (is_null($cacher)) |
|
| 226 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 227 | - // Les quatre derniers parametres sont modifies par la fonction: |
|
| 228 | - // emplacement, validite, et, s'il est valide, contenu & age |
|
| 229 | - if ($cacher) |
|
| 230 | - $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 231 | - else |
|
| 232 | - $use_cache = -1; |
|
| 233 | - // $res = message d'erreur : on sort de la |
|
| 234 | - if ($res) {return array('texte' => $res);} |
|
| 235 | - |
|
| 236 | - // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 237 | - // produire la page : peut mettre a jour $lastinclude |
|
| 238 | - // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 239 | - if ($use_cache) { |
|
| 240 | - if (is_null($produire_page)) |
|
| 241 | - $produire_page = charger_fonction('produire_page','public'); |
|
| 242 | - $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 243 | - } |
|
| 244 | - // dans tous les cas, mettre a jour $lastmodified |
|
| 245 | - $lastmodified = max($lastmodified, $lastinclude); |
|
| 246 | - |
|
| 247 | - return $page; |
|
| 216 | + static $cacher, $produire_page; |
|
| 217 | + global $lastmodified; |
|
| 218 | + |
|
| 219 | + // enlever le fond de contexte inclus car sinon il prend la main |
|
| 220 | + // dans les sous inclusions -> boucle infinie d'inclusion identique |
|
| 221 | + // (cette precaution n'est probablement plus utile) |
|
| 222 | + unset($contexte['fond']); |
|
| 223 | + $page = array('contexte_implicite'=>calculer_contexte_implicite()); |
|
| 224 | + $page['contexte_implicite']['cache'] = $fond; |
|
| 225 | + if (is_null($cacher)) |
|
| 226 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 227 | + // Les quatre derniers parametres sont modifies par la fonction: |
|
| 228 | + // emplacement, validite, et, s'il est valide, contenu & age |
|
| 229 | + if ($cacher) |
|
| 230 | + $res = $cacher($contexte, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 231 | + else |
|
| 232 | + $use_cache = -1; |
|
| 233 | + // $res = message d'erreur : on sort de la |
|
| 234 | + if ($res) {return array('texte' => $res);} |
|
| 235 | + |
|
| 236 | + // Si use_cache ne vaut pas 0, la page doit etre calculee |
|
| 237 | + // produire la page : peut mettre a jour $lastinclude |
|
| 238 | + // le contexte_cache envoye a cacher() a ete conserve et est passe a produire |
|
| 239 | + if ($use_cache) { |
|
| 240 | + if (is_null($produire_page)) |
|
| 241 | + $produire_page = charger_fonction('produire_page','public'); |
|
| 242 | + $page = $produire_page($fond, $contexte, $use_cache, $chemin_cache, $contexte, $page, $lastinclude, $connect); |
|
| 243 | + } |
|
| 244 | + // dans tous les cas, mettre a jour $lastmodified |
|
| 245 | + $lastmodified = max($lastmodified, $lastinclude); |
|
| 246 | + |
|
| 247 | + return $page; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -262,25 +262,25 @@ discard block |
||
| 262 | 262 | * @return array |
| 263 | 263 | */ |
| 264 | 264 | function public_produire_page_dist($fond, $contexte, $use_cache, $chemin_cache, $contexte_cache, &$page, &$lastinclude, $connect=''){ |
| 265 | - static $parametrer,$cacher; |
|
| 266 | - if (!$parametrer) |
|
| 267 | - $parametrer = charger_fonction('parametrer', 'public'); |
|
| 268 | - $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 269 | - // et on l'enregistre sur le disque |
|
| 270 | - if ($chemin_cache |
|
| 271 | - AND $use_cache>-1 |
|
| 272 | - AND is_array($page) |
|
| 273 | - AND count($page) |
|
| 274 | - AND $page['entetes']['X-Spip-Cache'] > 0){ |
|
| 275 | - if (is_null($cacher)) |
|
| 276 | - $cacher = charger_fonction('cacher', 'public', true); |
|
| 277 | - $lastinclude = time(); |
|
| 278 | - if ($cacher) |
|
| 279 | - $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 280 | - else |
|
| 281 | - $use_cache = -1; |
|
| 282 | - } |
|
| 283 | - return $page; |
|
| 265 | + static $parametrer,$cacher; |
|
| 266 | + if (!$parametrer) |
|
| 267 | + $parametrer = charger_fonction('parametrer', 'public'); |
|
| 268 | + $page = $parametrer($fond, $contexte, $chemin_cache, $connect); |
|
| 269 | + // et on l'enregistre sur le disque |
|
| 270 | + if ($chemin_cache |
|
| 271 | + AND $use_cache>-1 |
|
| 272 | + AND is_array($page) |
|
| 273 | + AND count($page) |
|
| 274 | + AND $page['entetes']['X-Spip-Cache'] > 0){ |
|
| 275 | + if (is_null($cacher)) |
|
| 276 | + $cacher = charger_fonction('cacher', 'public', true); |
|
| 277 | + $lastinclude = time(); |
|
| 278 | + if ($cacher) |
|
| 279 | + $cacher($contexte_cache, $use_cache, $chemin_cache, $page, $lastinclude); |
|
| 280 | + else |
|
| 281 | + $use_cache = -1; |
|
| 282 | + } |
|
| 283 | + return $page; |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -296,11 +296,11 @@ discard block |
||
| 296 | 296 | |
| 297 | 297 | function inserer_balise_dynamique($contexte_exec, $contexte_compil) |
| 298 | 298 | { |
| 299 | - if (!is_array($contexte_exec)) |
|
| 300 | - echo $contexte_exec; // message d'erreur etc |
|
| 301 | - else { |
|
| 302 | - inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 303 | - } |
|
| 299 | + if (!is_array($contexte_exec)) |
|
| 300 | + echo $contexte_exec; // message d'erreur etc |
|
| 301 | + else { |
|
| 302 | + inclure_balise_dynamique($contexte_exec, true, $contexte_compil); |
|
| 303 | + } |
|
| 304 | 304 | } |
| 305 | 305 | |
| 306 | 306 | // Attention, un appel explicite a cette fonction suppose certains include |
@@ -309,204 +309,204 @@ discard block |
||
| 309 | 309 | // http://doc.spip.org/@inclure_balise_dynamique |
| 310 | 310 | function inclure_balise_dynamique($texte, $echo=true, $contexte_compil=array()) |
| 311 | 311 | { |
| 312 | - if (is_array($texte)) { |
|
| 313 | - |
|
| 314 | - list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 315 | - |
|
| 316 | - // delais a l'ancienne, c'est pratiquement mort |
|
| 317 | - $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : NULL; |
|
| 318 | - $GLOBALS['delais'] = $delainc; |
|
| 319 | - |
|
| 320 | - $page = recuperer_fond($fond,$contexte_inclus,array('trim'=>false, 'raw' => true, 'compil' => $contexte_compil)); |
|
| 321 | - |
|
| 322 | - $texte = $page['texte']; |
|
| 323 | - |
|
| 324 | - $GLOBALS['delais'] = $d; |
|
| 325 | - // Faire remonter les entetes |
|
| 326 | - if (is_array($page['entetes'])) { |
|
| 327 | - // mais pas toutes |
|
| 328 | - unset($page['entetes']['X-Spip-Cache']); |
|
| 329 | - unset($page['entetes']['Content-Type']); |
|
| 330 | - if (isset($GLOBALS['page']) AND is_array($GLOBALS['page'])) { |
|
| 331 | - if (!is_array($GLOBALS['page']['entetes'])) |
|
| 332 | - $GLOBALS['page']['entetes'] = array(); |
|
| 333 | - $GLOBALS['page']['entetes'] = |
|
| 334 | - array_merge($GLOBALS['page']['entetes'],$page['entetes']); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 338 | - if (isset($page['contexte']['_pipelines']) |
|
| 339 | - AND is_array($page['contexte']['_pipelines']) |
|
| 340 | - AND count($page['contexte']['_pipelines'])) { |
|
| 341 | - foreach($page['contexte']['_pipelines'] as $pipe=>$args){ |
|
| 342 | - $args['contexte'] = $page['contexte']; |
|
| 343 | - unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 344 | - $texte = pipeline( |
|
| 345 | - $pipe, |
|
| 346 | - array( |
|
| 347 | - 'data'=>$texte, |
|
| 348 | - 'args'=>$args |
|
| 349 | - ), |
|
| 350 | - false |
|
| 351 | - ); |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 357 | - // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 358 | - $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 359 | - $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 360 | - } |
|
| 361 | - if ($echo) |
|
| 362 | - echo $texte; |
|
| 363 | - else |
|
| 364 | - return $texte; |
|
| 312 | + if (is_array($texte)) { |
|
| 313 | + |
|
| 314 | + list($fond, $delainc, $contexte_inclus) = $texte; |
|
| 315 | + |
|
| 316 | + // delais a l'ancienne, c'est pratiquement mort |
|
| 317 | + $d = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : NULL; |
|
| 318 | + $GLOBALS['delais'] = $delainc; |
|
| 319 | + |
|
| 320 | + $page = recuperer_fond($fond,$contexte_inclus,array('trim'=>false, 'raw' => true, 'compil' => $contexte_compil)); |
|
| 321 | + |
|
| 322 | + $texte = $page['texte']; |
|
| 323 | + |
|
| 324 | + $GLOBALS['delais'] = $d; |
|
| 325 | + // Faire remonter les entetes |
|
| 326 | + if (is_array($page['entetes'])) { |
|
| 327 | + // mais pas toutes |
|
| 328 | + unset($page['entetes']['X-Spip-Cache']); |
|
| 329 | + unset($page['entetes']['Content-Type']); |
|
| 330 | + if (isset($GLOBALS['page']) AND is_array($GLOBALS['page'])) { |
|
| 331 | + if (!is_array($GLOBALS['page']['entetes'])) |
|
| 332 | + $GLOBALS['page']['entetes'] = array(); |
|
| 333 | + $GLOBALS['page']['entetes'] = |
|
| 334 | + array_merge($GLOBALS['page']['entetes'],$page['entetes']); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + // _pipelines au pluriel array('nom_pipeline' => $args...) avec une syntaxe permettant plusieurs pipelines |
|
| 338 | + if (isset($page['contexte']['_pipelines']) |
|
| 339 | + AND is_array($page['contexte']['_pipelines']) |
|
| 340 | + AND count($page['contexte']['_pipelines'])) { |
|
| 341 | + foreach($page['contexte']['_pipelines'] as $pipe=>$args){ |
|
| 342 | + $args['contexte'] = $page['contexte']; |
|
| 343 | + unset($args['contexte']['_pipelines']); // par precaution, meme si le risque de boucle infinie est a priori nul |
|
| 344 | + $texte = pipeline( |
|
| 345 | + $pipe, |
|
| 346 | + array( |
|
| 347 | + 'data'=>$texte, |
|
| 348 | + 'args'=>$args |
|
| 349 | + ), |
|
| 350 | + false |
|
| 351 | + ); |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if (defined('_VAR_MODE') AND _VAR_MODE == 'debug') { |
|
| 357 | + // compatibilite : avant on donnait le numero de ligne ou rien. |
|
| 358 | + $ligne = intval(isset($contexte_compil[3]) ? $contexte_compil[3] : $contexte_compil); |
|
| 359 | + $GLOBALS['debug_objets']['resultat'][$ligne] = $texte; |
|
| 360 | + } |
|
| 361 | + if ($echo) |
|
| 362 | + echo $texte; |
|
| 363 | + else |
|
| 364 | + return $texte; |
|
| 365 | 365 | |
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | // http://doc.spip.org/@message_page_indisponible |
| 369 | 369 | function message_page_indisponible ($page, $contexte) { |
| 370 | - static $deja = false; |
|
| 371 | - if ($deja) return "erreur"; |
|
| 372 | - $codes = array( |
|
| 373 | - '404' => '404 Not Found', |
|
| 374 | - '503' => '503 Service Unavailable', |
|
| 375 | - ); |
|
| 376 | - |
|
| 377 | - $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 378 | - $contexte['code'] = $codes[$contexte['status']]; |
|
| 379 | - $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 380 | - if (!isset($contexte['lang'])) |
|
| 381 | - $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 382 | - |
|
| 383 | - $deja = true; |
|
| 384 | - // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 385 | - // ex restriction d'acces => 401 |
|
| 386 | - $contexte = pipeline('page_indisponible',$contexte); |
|
| 387 | - |
|
| 388 | - // produire la page d'erreur |
|
| 389 | - $page = inclure_page($contexte['fond'], $contexte); |
|
| 390 | - if (!$page) |
|
| 391 | - $page = inclure_page('404', $contexte); |
|
| 392 | - $page['status'] = $contexte['status']; |
|
| 393 | - |
|
| 394 | - return $page; |
|
| 370 | + static $deja = false; |
|
| 371 | + if ($deja) return "erreur"; |
|
| 372 | + $codes = array( |
|
| 373 | + '404' => '404 Not Found', |
|
| 374 | + '503' => '503 Service Unavailable', |
|
| 375 | + ); |
|
| 376 | + |
|
| 377 | + $contexte['status'] = ($page !== false) ? '404' : '503'; |
|
| 378 | + $contexte['code'] = $codes[$contexte['status']]; |
|
| 379 | + $contexte['fond'] = '404'; // gere les 2 erreurs |
|
| 380 | + if (!isset($contexte['lang'])) |
|
| 381 | + $contexte['lang'] = $GLOBALS['spip_lang']; |
|
| 382 | + |
|
| 383 | + $deja = true; |
|
| 384 | + // passer aux plugins qui peuvent decider d'une page d'erreur plus pertinent |
|
| 385 | + // ex restriction d'acces => 401 |
|
| 386 | + $contexte = pipeline('page_indisponible',$contexte); |
|
| 387 | + |
|
| 388 | + // produire la page d'erreur |
|
| 389 | + $page = inclure_page($contexte['fond'], $contexte); |
|
| 390 | + if (!$page) |
|
| 391 | + $page = inclure_page('404', $contexte); |
|
| 392 | + $page['status'] = $contexte['status']; |
|
| 393 | + |
|
| 394 | + return $page; |
|
| 395 | 395 | } |
| 396 | 396 | |
| 397 | 397 | // temporairement ici : a mettre dans le futur inc/modeles |
| 398 | 398 | // creer_contexte_de_modele('left', 'autostart=true', ...) renvoie un array() |
| 399 | 399 | // http://doc.spip.org/@creer_contexte_de_modele |
| 400 | 400 | function creer_contexte_de_modele($args) { |
| 401 | - $contexte = array(); |
|
| 402 | - foreach ($args as $var=>$val) { |
|
| 403 | - if (is_int($var)){ // argument pas formate |
|
| 404 | - if (in_array($val, array('left', 'right', 'center'))) { |
|
| 405 | - $var = 'align'; |
|
| 406 | - $contexte[$var] = $val; |
|
| 407 | - } else { |
|
| 408 | - $args = explode('=', $val); |
|
| 409 | - if (count($args)>=2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 410 | - $contexte[trim($args[0])] = substr($val,strlen($args[0])+1); |
|
| 411 | - else // notation abregee |
|
| 412 | - $contexte[trim($val)] = trim($val); |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - else |
|
| 416 | - $contexte[$var] = $val; |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - return $contexte; |
|
| 401 | + $contexte = array(); |
|
| 402 | + foreach ($args as $var=>$val) { |
|
| 403 | + if (is_int($var)){ // argument pas formate |
|
| 404 | + if (in_array($val, array('left', 'right', 'center'))) { |
|
| 405 | + $var = 'align'; |
|
| 406 | + $contexte[$var] = $val; |
|
| 407 | + } else { |
|
| 408 | + $args = explode('=', $val); |
|
| 409 | + if (count($args)>=2) // Flashvars=arg1=machin&arg2=truc genere plus de deux args |
|
| 410 | + $contexte[trim($args[0])] = substr($val,strlen($args[0])+1); |
|
| 411 | + else // notation abregee |
|
| 412 | + $contexte[trim($val)] = trim($val); |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + else |
|
| 416 | + $contexte[$var] = $val; |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + return $contexte; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // Calcule le modele et retourne la mini-page ainsi calculee |
| 423 | 423 | // http://doc.spip.org/@inclure_modele |
| 424 | 424 | function inclure_modele($type, $id, $params, $lien, $connect='', $env=array()) { |
| 425 | 425 | |
| 426 | - static $compteur; |
|
| 427 | - if (++$compteur>10) return ''; # ne pas boucler indefiniment |
|
| 428 | - |
|
| 429 | - $type = strtolower($type); |
|
| 430 | - |
|
| 431 | - $fond = $class = ''; |
|
| 432 | - |
|
| 433 | - $params = array_filter(explode('|', $params)); |
|
| 434 | - if ($params) { |
|
| 435 | - list(,$soustype) = each($params); |
|
| 436 | - $soustype = strtolower(trim($soustype)); |
|
| 437 | - if (in_array($soustype, |
|
| 438 | - array('left', 'right', 'center', 'ajax'))) { |
|
| 439 | - list(,$soustype) = each($params); |
|
| 440 | - $soustype = strtolower($soustype); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 444 | - if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 445 | - $fond = ''; |
|
| 446 | - $class = $soustype; |
|
| 447 | - } |
|
| 448 | - // enlever le sous type des params |
|
| 449 | - $params = array_diff($params,array($soustype)); |
|
| 450 | - } |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 454 | - if (!$fond AND !trouve_modele($fond = $type)){ |
|
| 455 | - spip_log("Modele $type introuvable",_LOG_INFO_IMPORTANTE); |
|
| 456 | - return false; |
|
| 457 | - } |
|
| 458 | - $fond = 'modeles/'.$fond; |
|
| 459 | - // Creer le contexte |
|
| 460 | - $contexte = $env; |
|
| 461 | - $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 |
|
| 462 | - |
|
| 463 | - // Le numero du modele est mis dans l'environnement |
|
| 464 | - // d'une part sous l'identifiant "id" |
|
| 465 | - // et d'autre part sous l'identifiant de la cle primaire |
|
| 466 | - // par la fonction id_table_objet, |
|
| 467 | - // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 468 | - $_id = id_table_objet($type); |
|
| 469 | - $contexte['id'] = $contexte[$_id] = $id; |
|
| 470 | - |
|
| 471 | - if (isset($class)) |
|
| 472 | - $contexte['class'] = $class; |
|
| 473 | - |
|
| 474 | - // Si un lien a ete passe en parametre, ex: [<modele1>->url] |
|
| 475 | - if ($lien) { |
|
| 476 | - # un eventuel guillemet (") sera reechappe par #ENV |
|
| 477 | - $contexte['lien'] = str_replace(""",'"', $lien['href']); |
|
| 478 | - $contexte['lien_class'] = $lien['class']; |
|
| 479 | - $contexte['lien_mime'] = $lien['mime']; |
|
| 480 | - $contexte['lien_title'] = $lien['title']; |
|
| 481 | - $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // Traiter les parametres |
|
| 485 | - // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 486 | - $arg_list = creer_contexte_de_modele($params); |
|
| 487 | - $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 488 | - $contexte = array_merge($contexte,$arg_list); |
|
| 489 | - |
|
| 490 | - |
|
| 491 | - // Appliquer le modele avec le contexte |
|
| 492 | - $retour = recuperer_fond($fond, $contexte, array(), $connect); |
|
| 493 | - |
|
| 494 | - |
|
| 495 | - // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 496 | - // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 497 | - // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 498 | - if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')).' ', |
|
| 499 | - 'spip_lien_ok')) { |
|
| 500 | - $retour = inserer_attribut($retour, 'class', |
|
| 501 | - trim(str_replace(' spip_lien_ok ', ' ', " $classes "))); |
|
| 502 | - } else if ($lien) |
|
| 503 | - $retour = "<a href='".$lien['href']."' class='".$lien['class']."'>".$retour."</a>"; |
|
| 504 | - |
|
| 505 | - $compteur--; |
|
| 506 | - |
|
| 507 | - return (isset($arg_list['ajax'])AND $arg_list['ajax']=='ajax') |
|
| 508 | - ? encoder_contexte_ajax($contexte,'',$retour) |
|
| 509 | - : $retour; |
|
| 426 | + static $compteur; |
|
| 427 | + if (++$compteur>10) return ''; # ne pas boucler indefiniment |
|
| 428 | + |
|
| 429 | + $type = strtolower($type); |
|
| 430 | + |
|
| 431 | + $fond = $class = ''; |
|
| 432 | + |
|
| 433 | + $params = array_filter(explode('|', $params)); |
|
| 434 | + if ($params) { |
|
| 435 | + list(,$soustype) = each($params); |
|
| 436 | + $soustype = strtolower(trim($soustype)); |
|
| 437 | + if (in_array($soustype, |
|
| 438 | + array('left', 'right', 'center', 'ajax'))) { |
|
| 439 | + list(,$soustype) = each($params); |
|
| 440 | + $soustype = strtolower($soustype); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (preg_match(',^[a-z0-9_]+$,', $soustype)) { |
|
| 444 | + if (!trouve_modele($fond = ($type.'_'.$soustype))) { |
|
| 445 | + $fond = ''; |
|
| 446 | + $class = $soustype; |
|
| 447 | + } |
|
| 448 | + // enlever le sous type des params |
|
| 449 | + $params = array_diff($params,array($soustype)); |
|
| 450 | + } |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // Si ca marche pas en precisant le sous-type, prendre le type |
|
| 454 | + if (!$fond AND !trouve_modele($fond = $type)){ |
|
| 455 | + spip_log("Modele $type introuvable",_LOG_INFO_IMPORTANTE); |
|
| 456 | + return false; |
|
| 457 | + } |
|
| 458 | + $fond = 'modeles/'.$fond; |
|
| 459 | + // Creer le contexte |
|
| 460 | + $contexte = $env; |
|
| 461 | + $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 |
|
| 462 | + |
|
| 463 | + // Le numero du modele est mis dans l'environnement |
|
| 464 | + // d'une part sous l'identifiant "id" |
|
| 465 | + // et d'autre part sous l'identifiant de la cle primaire |
|
| 466 | + // par la fonction id_table_objet, |
|
| 467 | + // (<article1> =>> article =>> id_article =>> id_article=1) |
|
| 468 | + $_id = id_table_objet($type); |
|
| 469 | + $contexte['id'] = $contexte[$_id] = $id; |
|
| 470 | + |
|
| 471 | + if (isset($class)) |
|
| 472 | + $contexte['class'] = $class; |
|
| 473 | + |
|
| 474 | + // Si un lien a ete passe en parametre, ex: [<modele1>->url] |
|
| 475 | + if ($lien) { |
|
| 476 | + # un eventuel guillemet (") sera reechappe par #ENV |
|
| 477 | + $contexte['lien'] = str_replace(""",'"', $lien['href']); |
|
| 478 | + $contexte['lien_class'] = $lien['class']; |
|
| 479 | + $contexte['lien_mime'] = $lien['mime']; |
|
| 480 | + $contexte['lien_title'] = $lien['title']; |
|
| 481 | + $contexte['lien_hreflang'] = $lien['hreflang']; |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // Traiter les parametres |
|
| 485 | + // par exemple : <img1|center>, <emb12|autostart=true> ou <doc1|lang=en> |
|
| 486 | + $arg_list = creer_contexte_de_modele($params); |
|
| 487 | + $contexte['args'] = $arg_list; // on passe la liste des arguments du modeles dans une variable args |
|
| 488 | + $contexte = array_merge($contexte,$arg_list); |
|
| 489 | + |
|
| 490 | + |
|
| 491 | + // Appliquer le modele avec le contexte |
|
| 492 | + $retour = recuperer_fond($fond, $contexte, array(), $connect); |
|
| 493 | + |
|
| 494 | + |
|
| 495 | + // Regarder si le modele tient compte des liens (il *doit* alors indiquer |
|
| 496 | + // spip_lien_ok dans les classes de son conteneur de premier niveau ; |
|
| 497 | + // sinon, s'il y a un lien, on l'ajoute classiquement |
|
| 498 | + if (strstr(' ' . ($classes = extraire_attribut($retour, 'class')).' ', |
|
| 499 | + 'spip_lien_ok')) { |
|
| 500 | + $retour = inserer_attribut($retour, 'class', |
|
| 501 | + trim(str_replace(' spip_lien_ok ', ' ', " $classes "))); |
|
| 502 | + } else if ($lien) |
|
| 503 | + $retour = "<a href='".$lien['href']."' class='".$lien['class']."'>".$retour."</a>"; |
|
| 504 | + |
|
| 505 | + $compteur--; |
|
| 506 | + |
|
| 507 | + return (isset($arg_list['ajax'])AND $arg_list['ajax']=='ajax') |
|
| 508 | + ? encoder_contexte_ajax($contexte,'',$retour) |
|
| 509 | + : $retour; |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | // Un inclure_page qui marche aussi pour l'espace prive |
@@ -516,77 +516,77 @@ discard block |
||
| 516 | 516 | // http://doc.spip.org/@evaluer_fond |
| 517 | 517 | function evaluer_fond ($fond, $contexte=array(), $connect=null) { |
| 518 | 518 | |
| 519 | - $page = inclure_page($fond, $contexte, $connect); |
|
| 519 | + $page = inclure_page($fond, $contexte, $connect); |
|
| 520 | 520 | |
| 521 | - if (!$page) return $page; |
|
| 522 | - // eval $page et affecte $res |
|
| 523 | - include _ROOT_RESTREINT."public/evaluer_page.php"; |
|
| 521 | + if (!$page) return $page; |
|
| 522 | + // eval $page et affecte $res |
|
| 523 | + include _ROOT_RESTREINT."public/evaluer_page.php"; |
|
| 524 | 524 | |
| 525 | - // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 526 | - // a destination de public/parametrer |
|
| 527 | - // pour remonter vers les inclusions appelantes |
|
| 528 | - // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 529 | - // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 530 | - if (isset($page['invalideurs']) |
|
| 531 | - AND isset($page['invalideurs']['session'])) |
|
| 532 | - $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 533 | - |
|
| 534 | - return $page; |
|
| 525 | + // Lever un drapeau (global) si le fond utilise #SESSION |
|
| 526 | + // a destination de public/parametrer |
|
| 527 | + // pour remonter vers les inclusions appelantes |
|
| 528 | + // il faut bien lever ce drapeau apres avoir evalue le fond |
|
| 529 | + // pour ne pas faire descendre le flag vers les inclusions appelees |
|
| 530 | + if (isset($page['invalideurs']) |
|
| 531 | + AND isset($page['invalideurs']['session'])) |
|
| 532 | + $GLOBALS['cache_utilise_session'] = $page['invalideurs']['session']; |
|
| 533 | + |
|
| 534 | + return $page; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
| 538 | 538 | // http://doc.spip.org/@page_base_href |
| 539 | 539 | function page_base_href(&$texte){ |
| 540 | - static $set_html_base = null; |
|
| 541 | - if (is_null($set_html_base)){ |
|
| 542 | - if (!defined('_SET_HTML_BASE')) |
|
| 543 | - // si la profondeur est superieure a 1 |
|
| 544 | - // est que ce n'est pas une url page ni une url action |
|
| 545 | - // activer par defaut |
|
| 546 | - $set_html_base = (( |
|
| 547 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT?1:2) |
|
| 548 | - AND _request(_SPIP_PAGE) !== 'login' |
|
| 549 | - AND !_request('action'))?true:false); |
|
| 550 | - else |
|
| 551 | - $set_html_base = _SET_HTML_BASE; |
|
| 552 | - } |
|
| 553 | - |
|
| 554 | - if ($set_html_base |
|
| 555 | - AND isset($GLOBALS['html']) AND $GLOBALS['html'] |
|
| 556 | - AND $GLOBALS['profondeur_url']>0 |
|
| 557 | - AND ($poshead = strpos($texte,'</head>'))!==FALSE){ |
|
| 558 | - $head = substr($texte,0,$poshead); |
|
| 559 | - $insert = false; |
|
| 560 | - if (strpos($head, '<base')===false) |
|
| 561 | - $insert = true; |
|
| 562 | - else { |
|
| 563 | - // si aucun <base ...> n'a de href c'est bon quand meme ! |
|
| 564 | - $insert = true; |
|
| 565 | - include_spip('inc/filtres'); |
|
| 566 | - $bases = extraire_balises($head,'base'); |
|
| 567 | - foreach ($bases as $base) |
|
| 568 | - if (extraire_attribut($base,'href')) |
|
| 569 | - $insert = false; |
|
| 570 | - } |
|
| 571 | - if ($insert) { |
|
| 572 | - include_spip('inc/filtres_mini'); |
|
| 573 | - // ajouter un base qui reglera tous les liens relatifs |
|
| 574 | - $base = url_absolue('./'); |
|
| 575 | - $bbase = "\n<base href=\"$base\" />"; |
|
| 576 | - if (($pos = strpos($head, '<head>')) !== false) |
|
| 577 | - $head = substr_replace($head, $bbase, $pos+6, 0); |
|
| 578 | - elseif(preg_match(",<head[^>]*>,i",$head,$r)){ |
|
| 579 | - $head = str_replace($r[0], $r[0].$bbase, $head); |
|
| 580 | - } |
|
| 581 | - $texte = $head . substr($texte,$poshead); |
|
| 582 | - // gerer les ancres |
|
| 583 | - $base = $_SERVER['REQUEST_URI']; |
|
| 584 | - if (strpos($texte,"href='#")!==false) |
|
| 585 | - $texte = str_replace("href='#","href='$base#",$texte); |
|
| 586 | - if (strpos($texte, "href=\"#")!==false) |
|
| 587 | - $texte = str_replace("href=\"#","href=\"$base#",$texte); |
|
| 588 | - } |
|
| 589 | - } |
|
| 540 | + static $set_html_base = null; |
|
| 541 | + if (is_null($set_html_base)){ |
|
| 542 | + if (!defined('_SET_HTML_BASE')) |
|
| 543 | + // si la profondeur est superieure a 1 |
|
| 544 | + // est que ce n'est pas une url page ni une url action |
|
| 545 | + // activer par defaut |
|
| 546 | + $set_html_base = (( |
|
| 547 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT?1:2) |
|
| 548 | + AND _request(_SPIP_PAGE) !== 'login' |
|
| 549 | + AND !_request('action'))?true:false); |
|
| 550 | + else |
|
| 551 | + $set_html_base = _SET_HTML_BASE; |
|
| 552 | + } |
|
| 553 | + |
|
| 554 | + if ($set_html_base |
|
| 555 | + AND isset($GLOBALS['html']) AND $GLOBALS['html'] |
|
| 556 | + AND $GLOBALS['profondeur_url']>0 |
|
| 557 | + AND ($poshead = strpos($texte,'</head>'))!==FALSE){ |
|
| 558 | + $head = substr($texte,0,$poshead); |
|
| 559 | + $insert = false; |
|
| 560 | + if (strpos($head, '<base')===false) |
|
| 561 | + $insert = true; |
|
| 562 | + else { |
|
| 563 | + // si aucun <base ...> n'a de href c'est bon quand meme ! |
|
| 564 | + $insert = true; |
|
| 565 | + include_spip('inc/filtres'); |
|
| 566 | + $bases = extraire_balises($head,'base'); |
|
| 567 | + foreach ($bases as $base) |
|
| 568 | + if (extraire_attribut($base,'href')) |
|
| 569 | + $insert = false; |
|
| 570 | + } |
|
| 571 | + if ($insert) { |
|
| 572 | + include_spip('inc/filtres_mini'); |
|
| 573 | + // ajouter un base qui reglera tous les liens relatifs |
|
| 574 | + $base = url_absolue('./'); |
|
| 575 | + $bbase = "\n<base href=\"$base\" />"; |
|
| 576 | + if (($pos = strpos($head, '<head>')) !== false) |
|
| 577 | + $head = substr_replace($head, $bbase, $pos+6, 0); |
|
| 578 | + elseif(preg_match(",<head[^>]*>,i",$head,$r)){ |
|
| 579 | + $head = str_replace($r[0], $r[0].$bbase, $head); |
|
| 580 | + } |
|
| 581 | + $texte = $head . substr($texte,$poshead); |
|
| 582 | + // gerer les ancres |
|
| 583 | + $base = $_SERVER['REQUEST_URI']; |
|
| 584 | + if (strpos($texte,"href='#")!==false) |
|
| 585 | + $texte = str_replace("href='#","href='$base#",$texte); |
|
| 586 | + if (strpos($texte, "href=\"#")!==false) |
|
| 587 | + $texte = str_replace("href=\"#","href=\"$base#",$texte); |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -594,9 +594,9 @@ discard block |
||
| 594 | 594 | // et demarrent par X-Spip-... |
| 595 | 595 | // http://doc.spip.org/@envoyer_entetes |
| 596 | 596 | function envoyer_entetes($entetes) { |
| 597 | - foreach ($entetes as $k => $v) |
|
| 598 | - # if (strncmp($k, 'X-Spip-', 7)) |
|
| 599 | - @header(strlen($v)?"$k: $v":$k); |
|
| 597 | + foreach ($entetes as $k => $v) |
|
| 598 | + # if (strncmp($k, 'X-Spip-', 7)) |
|
| 599 | + @header(strlen($v)?"$k: $v":$k); |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | ?> |