@@ -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 | ?> |
@@ -24,65 +24,65 @@ discard block |
||
| 24 | 24 | |
| 25 | 25 | function phraser_vieux_logos(&$p) |
| 26 | 26 | { |
| 27 | - if ($p->param[0][0]) |
|
| 28 | - $args = array(''); |
|
| 29 | - else { |
|
| 30 | - $args = array_shift($p->param); |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - foreach($p->param as $couple) { |
|
| 34 | - $nom = trim($couple[0]); |
|
| 35 | - if ($nom == '') {array_shift($p->param); break;} |
|
| 36 | - $r = phraser_logo_faux_filtres($nom); |
|
| 37 | - if ($r === 0) { |
|
| 38 | - $c = new Texte; |
|
| 39 | - $c->texte = $nom; |
|
| 40 | - $args[] = array($c); |
|
| 41 | - array_shift($p->param); |
|
| 42 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 43 | - } elseif ($r === 2) { |
|
| 44 | - $p->etoile = '**'; |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 1) { |
|
| 48 | - array_shift($p->param); |
|
| 49 | - $p->etoile = '*'; |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - |
|
| 52 | - } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 53 | - $champ = new Champ(); |
|
| 54 | - $champ->nom_boucle = $m[2]; |
|
| 55 | - $champ->nom_champ = $m[3]; |
|
| 56 | - $champ->etoile = $m[5]; |
|
| 57 | - $champ = array($champ); |
|
| 58 | - if ($m[6]) { |
|
| 59 | - $r = new Texte; |
|
| 60 | - $r->texte = $m[6]; |
|
| 61 | - $champ[]= $r; |
|
| 62 | - } |
|
| 63 | - $args[]= $champ; |
|
| 64 | - array_shift($p->param); |
|
| 65 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 66 | - |
|
| 67 | - } // le cas else est la seule incompatibilite |
|
| 68 | - |
|
| 69 | - } |
|
| 70 | - array_unshift($p->param, $args); |
|
| 27 | + if ($p->param[0][0]) |
|
| 28 | + $args = array(''); |
|
| 29 | + else { |
|
| 30 | + $args = array_shift($p->param); |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + foreach($p->param as $couple) { |
|
| 34 | + $nom = trim($couple[0]); |
|
| 35 | + if ($nom == '') {array_shift($p->param); break;} |
|
| 36 | + $r = phraser_logo_faux_filtres($nom); |
|
| 37 | + if ($r === 0) { |
|
| 38 | + $c = new Texte; |
|
| 39 | + $c->texte = $nom; |
|
| 40 | + $args[] = array($c); |
|
| 41 | + array_shift($p->param); |
|
| 42 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 43 | + } elseif ($r === 2) { |
|
| 44 | + $p->etoile = '**'; |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 1) { |
|
| 48 | + array_shift($p->param); |
|
| 49 | + $p->etoile = '*'; |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + |
|
| 52 | + } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 53 | + $champ = new Champ(); |
|
| 54 | + $champ->nom_boucle = $m[2]; |
|
| 55 | + $champ->nom_champ = $m[3]; |
|
| 56 | + $champ->etoile = $m[5]; |
|
| 57 | + $champ = array($champ); |
|
| 58 | + if ($m[6]) { |
|
| 59 | + $r = new Texte; |
|
| 60 | + $r->texte = $m[6]; |
|
| 61 | + $champ[]= $r; |
|
| 62 | + } |
|
| 63 | + $args[]= $champ; |
|
| 64 | + array_shift($p->param); |
|
| 65 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 66 | + |
|
| 67 | + } // le cas else est la seule incompatibilite |
|
| 68 | + |
|
| 69 | + } |
|
| 70 | + array_unshift($p->param, $args); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | function phraser_logo_faux_filtres($nom) |
| 75 | 75 | { |
| 76 | - switch($nom) { |
|
| 77 | - case 'top': |
|
| 78 | - case 'left': |
|
| 79 | - case 'right': |
|
| 80 | - case 'center': |
|
| 81 | - case 'bottom': return 0; |
|
| 82 | - case 'lien': return 1; |
|
| 83 | - case 'fichier': return 2; |
|
| 84 | - default: return $nom; |
|
| 85 | - } |
|
| 76 | + switch($nom) { |
|
| 77 | + case 'top': |
|
| 78 | + case 'left': |
|
| 79 | + case 'right': |
|
| 80 | + case 'center': |
|
| 81 | + case 'bottom': return 0; |
|
| 82 | + case 'lien': return 1; |
|
| 83 | + case 'fichier': return 2; |
|
| 84 | + default: return $nom; |
|
| 85 | + } |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -90,64 +90,64 @@ discard block |
||
| 90 | 90 | |
| 91 | 91 | function phraser_vieux_emb(&$p) |
| 92 | 92 | { |
| 93 | - if (!is_array($p->param)) |
|
| 94 | - $p->param=array(); |
|
| 95 | - |
|
| 96 | - // Produire le premier argument {emb} |
|
| 97 | - $texte = new Texte; |
|
| 98 | - $texte->texte='emb'; |
|
| 99 | - $param = array('', array($texte)); |
|
| 100 | - |
|
| 101 | - // Transformer les filtres en arguments |
|
| 102 | - for ($i=0; $i<count($p->param); $i++) { |
|
| 103 | - if ($p->param[$i][0]) { |
|
| 104 | - if (!strstr($p->param[$i][0], '=')) |
|
| 105 | - break;# on a rencontre un vrai filtre, c'est fini |
|
| 106 | - $texte = new Texte; |
|
| 107 | - $texte->texte=$p->param[$i][0]; |
|
| 108 | - $param[] = array($texte); |
|
| 109 | - } |
|
| 110 | - array_shift($p->param); |
|
| 111 | - } |
|
| 112 | - array_unshift($p->param, $param); |
|
| 113 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 114 | - $p->nom_champ = 'MODELE'; |
|
| 93 | + if (!is_array($p->param)) |
|
| 94 | + $p->param=array(); |
|
| 95 | + |
|
| 96 | + // Produire le premier argument {emb} |
|
| 97 | + $texte = new Texte; |
|
| 98 | + $texte->texte='emb'; |
|
| 99 | + $param = array('', array($texte)); |
|
| 100 | + |
|
| 101 | + // Transformer les filtres en arguments |
|
| 102 | + for ($i=0; $i<count($p->param); $i++) { |
|
| 103 | + if ($p->param[$i][0]) { |
|
| 104 | + if (!strstr($p->param[$i][0], '=')) |
|
| 105 | + break;# on a rencontre un vrai filtre, c'est fini |
|
| 106 | + $texte = new Texte; |
|
| 107 | + $texte->texte=$p->param[$i][0]; |
|
| 108 | + $param[] = array($texte); |
|
| 109 | + } |
|
| 110 | + array_shift($p->param); |
|
| 111 | + } |
|
| 112 | + array_unshift($p->param, $param); |
|
| 113 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 114 | + $p->nom_champ = 'MODELE'; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | // Vieux formulaire de recherch |
| 118 | 118 | |
| 119 | 119 | function phraser_vieux_recherche($p) |
| 120 | 120 | { |
| 121 | - if ($p->param[0][0]) { |
|
| 122 | - $c = new Texte; |
|
| 123 | - $c->texte = $p->param[0][0]; |
|
| 124 | - $p->param[0][1] = array($c); |
|
| 125 | - $p->param[0][0] = ''; |
|
| 126 | - $p->fonctions = array(); |
|
| 127 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 128 | - } |
|
| 121 | + if ($p->param[0][0]) { |
|
| 122 | + $c = new Texte; |
|
| 123 | + $c->texte = $p->param[0][0]; |
|
| 124 | + $p->param[0][1] = array($c); |
|
| 125 | + $p->param[0][0] = ''; |
|
| 126 | + $p->fonctions = array(); |
|
| 127 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 128 | + } |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | // Gerer la notation [(#EXPOSER|on,off)] |
| 132 | 132 | function phraser_vieux_exposer($p) |
| 133 | 133 | { |
| 134 | - if ($a = $p->fonctions) { |
|
| 135 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 136 | - $args = array(); |
|
| 137 | - if ($regs[1]) { |
|
| 138 | - $a = new Texte; |
|
| 139 | - $a->texte = $regs[1]; |
|
| 140 | - $args = array('', array($a)); |
|
| 141 | - if ($regs[3]) { |
|
| 142 | - $a = new Texte; |
|
| 143 | - $a->texte = $regs[3]; |
|
| 144 | - $args[] = array($a); |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $p->param[0] = $args; |
|
| 148 | - $p->fonctions = array(); |
|
| 149 | - $p->nom_champ = 'EXPOSE'; |
|
| 150 | - } |
|
| 134 | + if ($a = $p->fonctions) { |
|
| 135 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 136 | + $args = array(); |
|
| 137 | + if ($regs[1]) { |
|
| 138 | + $a = new Texte; |
|
| 139 | + $a->texte = $regs[1]; |
|
| 140 | + $args = array('', array($a)); |
|
| 141 | + if ($regs[3]) { |
|
| 142 | + $a = new Texte; |
|
| 143 | + $a->texte = $regs[3]; |
|
| 144 | + $args[] = array($a); |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $p->param[0] = $args; |
|
| 148 | + $p->fonctions = array(); |
|
| 149 | + $p->nom_champ = 'EXPOSE'; |
|
| 150 | + } |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | function phraser_vieux_modele($p) {normaliser_args_inclumodel($p);} |
@@ -155,46 +155,46 @@ discard block |
||
| 155 | 155 | |
| 156 | 156 | function normaliser_args_inclumodel($p) |
| 157 | 157 | { |
| 158 | - $params = $p->param; |
|
| 159 | - if (!$params) return; |
|
| 160 | - $args = $params[0]; |
|
| 161 | - if ($args[0]) return; // filtre immediat |
|
| 162 | - array_shift($p->param); |
|
| 163 | - foreach ($p->param as $l) { |
|
| 164 | - if (!array_shift($l)) { |
|
| 165 | - $args = array_merge($args, $l); |
|
| 166 | - array_shift($p->param); |
|
| 167 | - } else break; // filtre |
|
| 168 | - } |
|
| 169 | - array_unshift($p->param, $args); |
|
| 158 | + $params = $p->param; |
|
| 159 | + if (!$params) return; |
|
| 160 | + $args = $params[0]; |
|
| 161 | + if ($args[0]) return; // filtre immediat |
|
| 162 | + array_shift($p->param); |
|
| 163 | + foreach ($p->param as $l) { |
|
| 164 | + if (!array_shift($l)) { |
|
| 165 | + $args = array_merge($args, $l); |
|
| 166 | + array_shift($p->param); |
|
| 167 | + } else break; // filtre |
|
| 168 | + } |
|
| 169 | + array_unshift($p->param, $args); |
|
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | function normaliser_inclure($champ) |
| 173 | 173 | { |
| 174 | - normaliser_args_inclumodel($champ); |
|
| 175 | - $l = $champ->param[0]; |
|
| 176 | - if (is_array($l) AND !$l[0]) { |
|
| 177 | - foreach ($l as $k => $p) { |
|
| 178 | - if ($p AND $p[0]->type == 'texte' AND !strpos($p[0]->texte,'=')) { |
|
| 179 | - $p[0]->texte = trim($p[0]->texte); |
|
| 180 | - } |
|
| 181 | - } |
|
| 182 | - foreach ($l as $k => $p) { |
|
| 183 | - if (!$p OR $p[0]->type != 'texte' OR |
|
| 184 | - !preg_match('/^fond\s*=\s*(.*)$/',$p[0]->texte, $r)) |
|
| 185 | - continue; |
|
| 186 | - |
|
| 187 | - if ($r[1]) |
|
| 188 | - $p[0]->texte = $r[1]; |
|
| 189 | - else unset($p[0]); |
|
| 190 | - $champ->texte = $p; |
|
| 191 | - unset($champ->param[0][$k]); |
|
| 192 | - if (count($champ->param[0]) ==1) |
|
| 193 | - array_shift($champ->param); |
|
| 194 | - return; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - spip_log("inclure sans fond ni fichier"); |
|
| 174 | + normaliser_args_inclumodel($champ); |
|
| 175 | + $l = $champ->param[0]; |
|
| 176 | + if (is_array($l) AND !$l[0]) { |
|
| 177 | + foreach ($l as $k => $p) { |
|
| 178 | + if ($p AND $p[0]->type == 'texte' AND !strpos($p[0]->texte,'=')) { |
|
| 179 | + $p[0]->texte = trim($p[0]->texte); |
|
| 180 | + } |
|
| 181 | + } |
|
| 182 | + foreach ($l as $k => $p) { |
|
| 183 | + if (!$p OR $p[0]->type != 'texte' OR |
|
| 184 | + !preg_match('/^fond\s*=\s*(.*)$/',$p[0]->texte, $r)) |
|
| 185 | + continue; |
|
| 186 | + |
|
| 187 | + if ($r[1]) |
|
| 188 | + $p[0]->texte = $r[1]; |
|
| 189 | + else unset($p[0]); |
|
| 190 | + $champ->texte = $p; |
|
| 191 | + unset($champ->param[0][$k]); |
|
| 192 | + if (count($champ->param[0]) ==1) |
|
| 193 | + array_shift($champ->param); |
|
| 194 | + return; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + spip_log("inclure sans fond ni fichier"); |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | ?> |
@@ -32,43 +32,43 @@ discard block |
||
| 32 | 32 | * @package SPIP\Compilateur\AST |
| 33 | 33 | */ |
| 34 | 34 | class Contexte { |
| 35 | - /** |
|
| 36 | - * Description du squelette |
|
| 37 | - * |
|
| 38 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 39 | - * |
|
| 40 | - * Peut contenir les index : |
|
| 41 | - * - nom : Nom du fichier de cache |
|
| 42 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 43 | - * - sourcefile : Chemin du squelette |
|
| 44 | - * - squelette : Code du squelette |
|
| 45 | - * - id_mere : Identifiant de la boucle parente |
|
| 46 | - * - documents : Pour embed et img dans les textes |
|
| 47 | - * - session : Pour un cache sessionné par auteur |
|
| 48 | - * - niv : Niveau de tabulation |
|
| 49 | - * |
|
| 50 | - * @var array */ |
|
| 51 | - public $descr = array(); |
|
| 52 | - |
|
| 53 | - /** |
|
| 54 | - * Identifiant de la boucle |
|
| 55 | - * @var string */ |
|
| 56 | - public $id_boucle = ''; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Numéro de ligne dans le code source du squelette |
|
| 60 | - * @var int */ |
|
| 61 | - public $ligne = 0; |
|
| 62 | - |
|
| 63 | - /** |
|
| 64 | - * Langue d'exécution |
|
| 65 | - * @var string */ |
|
| 66 | - public $lang = ''; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Résultat de la compilation: toujours une expression PHP |
|
| 70 | - * @var string */ |
|
| 71 | - public $code = ''; |
|
| 35 | + /** |
|
| 36 | + * Description du squelette |
|
| 37 | + * |
|
| 38 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 39 | + * |
|
| 40 | + * Peut contenir les index : |
|
| 41 | + * - nom : Nom du fichier de cache |
|
| 42 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 43 | + * - sourcefile : Chemin du squelette |
|
| 44 | + * - squelette : Code du squelette |
|
| 45 | + * - id_mere : Identifiant de la boucle parente |
|
| 46 | + * - documents : Pour embed et img dans les textes |
|
| 47 | + * - session : Pour un cache sessionné par auteur |
|
| 48 | + * - niv : Niveau de tabulation |
|
| 49 | + * |
|
| 50 | + * @var array */ |
|
| 51 | + public $descr = array(); |
|
| 52 | + |
|
| 53 | + /** |
|
| 54 | + * Identifiant de la boucle |
|
| 55 | + * @var string */ |
|
| 56 | + public $id_boucle = ''; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Numéro de ligne dans le code source du squelette |
|
| 60 | + * @var int */ |
|
| 61 | + public $ligne = 0; |
|
| 62 | + |
|
| 63 | + /** |
|
| 64 | + * Langue d'exécution |
|
| 65 | + * @var string */ |
|
| 66 | + public $lang = ''; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Résultat de la compilation: toujours une expression PHP |
|
| 70 | + * @var string */ |
|
| 71 | + public $code = ''; |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | |
@@ -78,34 +78,34 @@ discard block |
||
| 78 | 78 | * @package SPIP\Compilateur\AST |
| 79 | 79 | **/ |
| 80 | 80 | class Texte { |
| 81 | - /** |
|
| 82 | - * Type de noeud |
|
| 83 | - * @var string */ |
|
| 84 | - public $type = 'texte'; |
|
| 85 | - |
|
| 86 | - /** |
|
| 87 | - * Le texte |
|
| 88 | - * @var string */ |
|
| 89 | - public $texte; |
|
| 90 | - |
|
| 91 | - /** |
|
| 92 | - * Contenu avant le texte. |
|
| 93 | - * |
|
| 94 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 95 | - * @var string|array */ |
|
| 96 | - public $avant = ""; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Contenu après le texte. |
|
| 100 | - * |
|
| 101 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 102 | - * @var string|array */ |
|
| 103 | - public $apres = ""; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Numéro de ligne dans le code source du squelette |
|
| 107 | - * @var int */ |
|
| 108 | - public $ligne = 0; |
|
| 81 | + /** |
|
| 82 | + * Type de noeud |
|
| 83 | + * @var string */ |
|
| 84 | + public $type = 'texte'; |
|
| 85 | + |
|
| 86 | + /** |
|
| 87 | + * Le texte |
|
| 88 | + * @var string */ |
|
| 89 | + public $texte; |
|
| 90 | + |
|
| 91 | + /** |
|
| 92 | + * Contenu avant le texte. |
|
| 93 | + * |
|
| 94 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 95 | + * @var string|array */ |
|
| 96 | + public $avant = ""; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Contenu après le texte. |
|
| 100 | + * |
|
| 101 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 102 | + * @var string|array */ |
|
| 103 | + public $apres = ""; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Numéro de ligne dans le code source du squelette |
|
| 107 | + * @var int */ |
|
| 108 | + public $ligne = 0; |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -114,38 +114,38 @@ discard block |
||
| 114 | 114 | * @package SPIP\Compilateur\AST |
| 115 | 115 | **/ |
| 116 | 116 | class Inclure { |
| 117 | - /** |
|
| 118 | - * Type de noeud |
|
| 119 | - * @var string */ |
|
| 120 | - public $type = 'include'; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Nom d'un fichier inclu |
|
| 124 | - * |
|
| 125 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 126 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 127 | - * @var string|Texte */ |
|
| 128 | - public $texte; |
|
| 129 | - |
|
| 130 | - /** |
|
| 131 | - * Inutilisé, propriété générique de l'AST |
|
| 132 | - * @var string|array */ |
|
| 133 | - public $avant = ''; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Inutilisé, propriété générique de l'AST |
|
| 137 | - * @var string|array */ |
|
| 138 | - public $apres = ''; |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Numéro de ligne dans le code source du squelette |
|
| 142 | - * @var int */ |
|
| 143 | - public $ligne = 0; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Valeurs des paramètres |
|
| 147 | - * @var array */ |
|
| 148 | - public $param = array(); |
|
| 117 | + /** |
|
| 118 | + * Type de noeud |
|
| 119 | + * @var string */ |
|
| 120 | + public $type = 'include'; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Nom d'un fichier inclu |
|
| 124 | + * |
|
| 125 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 126 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 127 | + * @var string|Texte */ |
|
| 128 | + public $texte; |
|
| 129 | + |
|
| 130 | + /** |
|
| 131 | + * Inutilisé, propriété générique de l'AST |
|
| 132 | + * @var string|array */ |
|
| 133 | + public $avant = ''; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Inutilisé, propriété générique de l'AST |
|
| 137 | + * @var string|array */ |
|
| 138 | + public $apres = ''; |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Numéro de ligne dans le code source du squelette |
|
| 142 | + * @var int */ |
|
| 143 | + public $ligne = 0; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Valeurs des paramètres |
|
| 147 | + * @var array */ |
|
| 148 | + public $param = array(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | |
@@ -155,164 +155,164 @@ discard block |
||
| 155 | 155 | * @package SPIP\Compilateur\AST |
| 156 | 156 | **/ |
| 157 | 157 | class Boucle { |
| 158 | - /** |
|
| 159 | - * Type de noeud |
|
| 160 | - * @var string */ |
|
| 161 | - public $type = 'boucle'; |
|
| 162 | - |
|
| 163 | - /** |
|
| 164 | - * Identifiant de la boucle |
|
| 165 | - * @var string */ |
|
| 166 | - public $id_boucle; |
|
| 167 | - |
|
| 168 | - /** |
|
| 169 | - * Identifiant de la boucle parente |
|
| 170 | - * @var string */ |
|
| 171 | - public $id_parent =''; |
|
| 172 | - |
|
| 173 | - /** |
|
| 174 | - * Partie optionnelle avant |
|
| 175 | - * @var string|array */ |
|
| 176 | - public $avant = ''; |
|
| 177 | - |
|
| 178 | - /** |
|
| 179 | - * Pour chaque élément |
|
| 180 | - * @var string|array */ |
|
| 181 | - public $milieu = ''; |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Partie optionnelle après |
|
| 185 | - * @var string|array */ |
|
| 186 | - public $apres = ''; |
|
| 187 | - |
|
| 188 | - /** |
|
| 189 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 190 | - * @var string|array */ |
|
| 191 | - public $altern = ''; |
|
| 192 | - |
|
| 193 | - /** |
|
| 194 | - * La boucle doit-elle sélectionner la langue ? |
|
| 195 | - * @var string|null */ |
|
| 196 | - public $lang_select; |
|
| 197 | - |
|
| 198 | - /** |
|
| 199 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 200 | - * @var string|null */ |
|
| 201 | - public $type_requete; |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * La table est elle optionnelle ? |
|
| 205 | - * |
|
| 206 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 207 | - * @var bool */ |
|
| 208 | - public $table_optionnelle = false; |
|
| 209 | - |
|
| 210 | - /** |
|
| 211 | - * Nom du fichier de connexion |
|
| 212 | - * @var string */ |
|
| 213 | - public $sql_serveur = ''; |
|
| 214 | - |
|
| 215 | - /** |
|
| 216 | - * Paramètres de la boucle |
|
| 217 | - * |
|
| 218 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 219 | - * au calcul des critères |
|
| 220 | - * |
|
| 221 | - * @var array */ |
|
| 222 | - public $param = array(); |
|
| 223 | - |
|
| 224 | - /** |
|
| 225 | - * Critères de la boucle |
|
| 226 | - * @var Critere[] */ |
|
| 227 | - public $criteres = array(); |
|
| 228 | - |
|
| 229 | - /** |
|
| 230 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 231 | - * @var string[] */ |
|
| 232 | - public $separateur = array(); |
|
| 233 | - |
|
| 234 | - /** |
|
| 235 | - * Liste des jointures possibles avec cette table |
|
| 236 | - * |
|
| 237 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 238 | - * des jointures déclarées explicitement sur la boucle |
|
| 239 | - * @see base_trouver_table_dist() |
|
| 240 | - * @var array */ |
|
| 241 | - public $jointures = array(); |
|
| 242 | - |
|
| 243 | - /** |
|
| 244 | - * Jointures explicites avec cette table |
|
| 245 | - * |
|
| 246 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 247 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 248 | - * à la boucle. |
|
| 249 | - * @var string|bool */ |
|
| 250 | - public $jointures_explicites = false; |
|
| 251 | - |
|
| 252 | - /** |
|
| 253 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 254 | - * @var string|null */ |
|
| 255 | - public $doublons; |
|
| 256 | - |
|
| 257 | - var $partie, $total_parties,$mode_partie=''; |
|
| 258 | - var $externe = ''; # appel a partir d'une autre boucle (recursion) |
|
| 259 | - // champs pour la construction de la requete SQL |
|
| 260 | - var $select = array(); |
|
| 261 | - var $from = array(); |
|
| 262 | - var $from_type = array(); |
|
| 263 | - var $where = array(); |
|
| 264 | - var $join = array(); |
|
| 265 | - var $having = array(); |
|
| 266 | - var $limit; |
|
| 267 | - var $group = array(); |
|
| 268 | - var $order = array(); |
|
| 269 | - var $default_order = array(); |
|
| 270 | - var $date = 'date' ; |
|
| 271 | - var $hash = "" ; |
|
| 272 | - var $in = "" ; |
|
| 273 | - var $sous_requete = false; |
|
| 274 | - var $hierarchie = ''; |
|
| 275 | - var $statut = false; # definition/surcharge du statut des elements retournes |
|
| 276 | - // champs pour la construction du corps PHP |
|
| 277 | - var $show = array(); |
|
| 278 | - var $id_table; |
|
| 279 | - var $primary; |
|
| 280 | - var $return; |
|
| 281 | - var $numrows = false; |
|
| 282 | - var $cptrows = false; |
|
| 283 | - |
|
| 284 | - /** |
|
| 285 | - * Description du squelette |
|
| 286 | - * |
|
| 287 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 288 | - * |
|
| 289 | - * Peut contenir les index : |
|
| 290 | - * - nom : Nom du fichier de cache |
|
| 291 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 292 | - * - sourcefile : Chemin du squelette |
|
| 293 | - * - squelette : Code du squelette |
|
| 294 | - * - id_mere : Identifiant de la boucle parente |
|
| 295 | - * - documents : Pour embed et img dans les textes |
|
| 296 | - * - session : Pour un cache sessionné par auteur |
|
| 297 | - * - niv : Niveau de tabulation |
|
| 298 | - * |
|
| 299 | - * @var array */ |
|
| 300 | - public $descr = array(); |
|
| 301 | - |
|
| 302 | - /** |
|
| 303 | - * Numéro de ligne dans le code source du squelette |
|
| 304 | - * @var int */ |
|
| 305 | - public $ligne = 0; |
|
| 306 | - |
|
| 307 | - |
|
| 308 | - var $modificateur = array(); // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 309 | - |
|
| 310 | - var $iterateur = ''; // type d'iterateur |
|
| 311 | - |
|
| 312 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 313 | - var $tout = false; |
|
| 314 | - var $plat = false; |
|
| 315 | - var $lien = false; |
|
| 158 | + /** |
|
| 159 | + * Type de noeud |
|
| 160 | + * @var string */ |
|
| 161 | + public $type = 'boucle'; |
|
| 162 | + |
|
| 163 | + /** |
|
| 164 | + * Identifiant de la boucle |
|
| 165 | + * @var string */ |
|
| 166 | + public $id_boucle; |
|
| 167 | + |
|
| 168 | + /** |
|
| 169 | + * Identifiant de la boucle parente |
|
| 170 | + * @var string */ |
|
| 171 | + public $id_parent =''; |
|
| 172 | + |
|
| 173 | + /** |
|
| 174 | + * Partie optionnelle avant |
|
| 175 | + * @var string|array */ |
|
| 176 | + public $avant = ''; |
|
| 177 | + |
|
| 178 | + /** |
|
| 179 | + * Pour chaque élément |
|
| 180 | + * @var string|array */ |
|
| 181 | + public $milieu = ''; |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Partie optionnelle après |
|
| 185 | + * @var string|array */ |
|
| 186 | + public $apres = ''; |
|
| 187 | + |
|
| 188 | + /** |
|
| 189 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 190 | + * @var string|array */ |
|
| 191 | + public $altern = ''; |
|
| 192 | + |
|
| 193 | + /** |
|
| 194 | + * La boucle doit-elle sélectionner la langue ? |
|
| 195 | + * @var string|null */ |
|
| 196 | + public $lang_select; |
|
| 197 | + |
|
| 198 | + /** |
|
| 199 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 200 | + * @var string|null */ |
|
| 201 | + public $type_requete; |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * La table est elle optionnelle ? |
|
| 205 | + * |
|
| 206 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 207 | + * @var bool */ |
|
| 208 | + public $table_optionnelle = false; |
|
| 209 | + |
|
| 210 | + /** |
|
| 211 | + * Nom du fichier de connexion |
|
| 212 | + * @var string */ |
|
| 213 | + public $sql_serveur = ''; |
|
| 214 | + |
|
| 215 | + /** |
|
| 216 | + * Paramètres de la boucle |
|
| 217 | + * |
|
| 218 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 219 | + * au calcul des critères |
|
| 220 | + * |
|
| 221 | + * @var array */ |
|
| 222 | + public $param = array(); |
|
| 223 | + |
|
| 224 | + /** |
|
| 225 | + * Critères de la boucle |
|
| 226 | + * @var Critere[] */ |
|
| 227 | + public $criteres = array(); |
|
| 228 | + |
|
| 229 | + /** |
|
| 230 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 231 | + * @var string[] */ |
|
| 232 | + public $separateur = array(); |
|
| 233 | + |
|
| 234 | + /** |
|
| 235 | + * Liste des jointures possibles avec cette table |
|
| 236 | + * |
|
| 237 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 238 | + * des jointures déclarées explicitement sur la boucle |
|
| 239 | + * @see base_trouver_table_dist() |
|
| 240 | + * @var array */ |
|
| 241 | + public $jointures = array(); |
|
| 242 | + |
|
| 243 | + /** |
|
| 244 | + * Jointures explicites avec cette table |
|
| 245 | + * |
|
| 246 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 247 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 248 | + * à la boucle. |
|
| 249 | + * @var string|bool */ |
|
| 250 | + public $jointures_explicites = false; |
|
| 251 | + |
|
| 252 | + /** |
|
| 253 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 254 | + * @var string|null */ |
|
| 255 | + public $doublons; |
|
| 256 | + |
|
| 257 | + var $partie, $total_parties,$mode_partie=''; |
|
| 258 | + var $externe = ''; # appel a partir d'une autre boucle (recursion) |
|
| 259 | + // champs pour la construction de la requete SQL |
|
| 260 | + var $select = array(); |
|
| 261 | + var $from = array(); |
|
| 262 | + var $from_type = array(); |
|
| 263 | + var $where = array(); |
|
| 264 | + var $join = array(); |
|
| 265 | + var $having = array(); |
|
| 266 | + var $limit; |
|
| 267 | + var $group = array(); |
|
| 268 | + var $order = array(); |
|
| 269 | + var $default_order = array(); |
|
| 270 | + var $date = 'date' ; |
|
| 271 | + var $hash = "" ; |
|
| 272 | + var $in = "" ; |
|
| 273 | + var $sous_requete = false; |
|
| 274 | + var $hierarchie = ''; |
|
| 275 | + var $statut = false; # definition/surcharge du statut des elements retournes |
|
| 276 | + // champs pour la construction du corps PHP |
|
| 277 | + var $show = array(); |
|
| 278 | + var $id_table; |
|
| 279 | + var $primary; |
|
| 280 | + var $return; |
|
| 281 | + var $numrows = false; |
|
| 282 | + var $cptrows = false; |
|
| 283 | + |
|
| 284 | + /** |
|
| 285 | + * Description du squelette |
|
| 286 | + * |
|
| 287 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 288 | + * |
|
| 289 | + * Peut contenir les index : |
|
| 290 | + * - nom : Nom du fichier de cache |
|
| 291 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 292 | + * - sourcefile : Chemin du squelette |
|
| 293 | + * - squelette : Code du squelette |
|
| 294 | + * - id_mere : Identifiant de la boucle parente |
|
| 295 | + * - documents : Pour embed et img dans les textes |
|
| 296 | + * - session : Pour un cache sessionné par auteur |
|
| 297 | + * - niv : Niveau de tabulation |
|
| 298 | + * |
|
| 299 | + * @var array */ |
|
| 300 | + public $descr = array(); |
|
| 301 | + |
|
| 302 | + /** |
|
| 303 | + * Numéro de ligne dans le code source du squelette |
|
| 304 | + * @var int */ |
|
| 305 | + public $ligne = 0; |
|
| 306 | + |
|
| 307 | + |
|
| 308 | + var $modificateur = array(); // table pour stocker les modificateurs de boucle tels que tout, plat ..., utilisable par les plugins egalement |
|
| 309 | + |
|
| 310 | + var $iterateur = ''; // type d'iterateur |
|
| 311 | + |
|
| 312 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 313 | + var $tout = false; |
|
| 314 | + var $plat = false; |
|
| 315 | + var $lien = false; |
|
| 316 | 316 | } |
| 317 | 317 | |
| 318 | 318 | /** |
@@ -323,37 +323,37 @@ discard block |
||
| 323 | 323 | * @package SPIP\Compilateur\AST |
| 324 | 324 | **/ |
| 325 | 325 | class Critere { |
| 326 | - /** |
|
| 327 | - * Type de noeud |
|
| 328 | - * @var string */ |
|
| 329 | - public $type = 'critere'; |
|
| 330 | - |
|
| 331 | - /** |
|
| 332 | - * Opérateur (>, <, >=, IN, ...) |
|
| 333 | - * @var null|string */ |
|
| 334 | - public $op; |
|
| 335 | - |
|
| 336 | - /** |
|
| 337 | - * Présence d'une négation (truc !op valeur) |
|
| 338 | - * @var null|string */ |
|
| 339 | - public $not; |
|
| 340 | - |
|
| 341 | - /** |
|
| 342 | - * Présence d'une exclusion (!truc op valeur) |
|
| 343 | - * @var null|string */ |
|
| 344 | - public $exclus; |
|
| 345 | - |
|
| 346 | - /** |
|
| 347 | - * Paramètres du critère |
|
| 348 | - * - $param[0] : élément avant l'opérateur |
|
| 349 | - * - $param[1..n] : éléments après l'opérateur |
|
| 350 | - * @var array */ |
|
| 351 | - var $param = array(); |
|
| 352 | - |
|
| 353 | - /** |
|
| 354 | - * Numéro de ligne dans le code source du squelette |
|
| 355 | - * @var int */ |
|
| 356 | - public $ligne = 0; |
|
| 326 | + /** |
|
| 327 | + * Type de noeud |
|
| 328 | + * @var string */ |
|
| 329 | + public $type = 'critere'; |
|
| 330 | + |
|
| 331 | + /** |
|
| 332 | + * Opérateur (>, <, >=, IN, ...) |
|
| 333 | + * @var null|string */ |
|
| 334 | + public $op; |
|
| 335 | + |
|
| 336 | + /** |
|
| 337 | + * Présence d'une négation (truc !op valeur) |
|
| 338 | + * @var null|string */ |
|
| 339 | + public $not; |
|
| 340 | + |
|
| 341 | + /** |
|
| 342 | + * Présence d'une exclusion (!truc op valeur) |
|
| 343 | + * @var null|string */ |
|
| 344 | + public $exclus; |
|
| 345 | + |
|
| 346 | + /** |
|
| 347 | + * Paramètres du critère |
|
| 348 | + * - $param[0] : élément avant l'opérateur |
|
| 349 | + * - $param[1..n] : éléments après l'opérateur |
|
| 350 | + * @var array */ |
|
| 351 | + var $param = array(); |
|
| 352 | + |
|
| 353 | + /** |
|
| 354 | + * Numéro de ligne dans le code source du squelette |
|
| 355 | + * @var int */ |
|
| 356 | + public $ligne = 0; |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -362,106 +362,106 @@ discard block |
||
| 362 | 362 | * @package SPIP\Compilateur\AST |
| 363 | 363 | **/ |
| 364 | 364 | class Champ { |
| 365 | - /** |
|
| 366 | - * Type de noeud |
|
| 367 | - * @var string */ |
|
| 368 | - public $type = 'champ'; |
|
| 369 | - |
|
| 370 | - /** |
|
| 371 | - * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 372 | - * @var string|null */ |
|
| 373 | - public $nom_champ; |
|
| 374 | - |
|
| 375 | - /** |
|
| 376 | - * Identifiant de la boucle parente si explicité |
|
| 377 | - * @var string|null */ |
|
| 378 | - public $nom_boucle= ''; |
|
| 379 | - |
|
| 380 | - /** |
|
| 381 | - * Partie optionnelle avant |
|
| 382 | - * @var null|string|array */ |
|
| 383 | - public $avant; |
|
| 384 | - |
|
| 385 | - /** |
|
| 386 | - * Partie optionnelle après |
|
| 387 | - * @var null|string|array */ |
|
| 388 | - public $apres; |
|
| 389 | - |
|
| 390 | - /** |
|
| 391 | - * Étoiles : annuler des automatismes |
|
| 392 | - * |
|
| 393 | - * - '*' annule les filtres automatiques |
|
| 394 | - * - '**' annule en plus les protections de scripts |
|
| 395 | - * @var null|string */ |
|
| 396 | - public $etoile; |
|
| 397 | - |
|
| 398 | - /** |
|
| 399 | - * Arguments et filtres explicites sur la balise |
|
| 400 | - * - $param[0] contient les arguments de la balise |
|
| 401 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 402 | - * @var array */ |
|
| 403 | - public $param = array(); |
|
| 404 | - |
|
| 405 | - /** |
|
| 406 | - * Source des filtres (compatibilité) (?) |
|
| 407 | - * @var array|null */ |
|
| 408 | - public $fonctions = array(); |
|
| 409 | - |
|
| 410 | - /** |
|
| 411 | - * Identifiant de la boucle |
|
| 412 | - * @var string */ |
|
| 413 | - public $id_boucle = ''; |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * AST du squelette, liste de toutes les boucles |
|
| 417 | - * @var Boucles[] */ |
|
| 418 | - public $boucles; |
|
| 419 | - |
|
| 420 | - /** |
|
| 421 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 422 | - * @var string|null */ |
|
| 423 | - public $type_requete; |
|
| 424 | - |
|
| 425 | - /** |
|
| 426 | - * Résultat de la compilation: toujours une expression PHP |
|
| 427 | - * @var string */ |
|
| 428 | - public $code = ''; |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * Interdire les scripts |
|
| 432 | - * |
|
| 433 | - * false si on est sûr de cette balise |
|
| 434 | - * @see interdire_scripts() |
|
| 435 | - * @var bool */ |
|
| 436 | - public $interdire_scripts = true; |
|
| 437 | - |
|
| 438 | - /** |
|
| 439 | - * Description du squelette |
|
| 440 | - * |
|
| 441 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 442 | - * |
|
| 443 | - * Peut contenir les index : |
|
| 444 | - * - nom : Nom du fichier de cache |
|
| 445 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 446 | - * - sourcefile : Chemin du squelette |
|
| 447 | - * - squelette : Code du squelette |
|
| 448 | - * - id_mere : Identifiant de la boucle parente |
|
| 449 | - * - documents : Pour embed et img dans les textes |
|
| 450 | - * - session : Pour un cache sessionné par auteur |
|
| 451 | - * - niv : Niveau de tabulation |
|
| 452 | - * |
|
| 453 | - * @var array */ |
|
| 454 | - public $descr = array(); |
|
| 455 | - |
|
| 456 | - /** |
|
| 457 | - * Numéro de ligne dans le code source du squelette |
|
| 458 | - * @var int */ |
|
| 459 | - public $ligne = 0; |
|
| 460 | - |
|
| 461 | - /** |
|
| 462 | - * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 463 | - * @var bool */ |
|
| 464 | - public $balise_calculee = false; |
|
| 365 | + /** |
|
| 366 | + * Type de noeud |
|
| 367 | + * @var string */ |
|
| 368 | + public $type = 'champ'; |
|
| 369 | + |
|
| 370 | + /** |
|
| 371 | + * Nom du champ demandé. Exemple 'ID_ARTICLE' |
|
| 372 | + * @var string|null */ |
|
| 373 | + public $nom_champ; |
|
| 374 | + |
|
| 375 | + /** |
|
| 376 | + * Identifiant de la boucle parente si explicité |
|
| 377 | + * @var string|null */ |
|
| 378 | + public $nom_boucle= ''; |
|
| 379 | + |
|
| 380 | + /** |
|
| 381 | + * Partie optionnelle avant |
|
| 382 | + * @var null|string|array */ |
|
| 383 | + public $avant; |
|
| 384 | + |
|
| 385 | + /** |
|
| 386 | + * Partie optionnelle après |
|
| 387 | + * @var null|string|array */ |
|
| 388 | + public $apres; |
|
| 389 | + |
|
| 390 | + /** |
|
| 391 | + * Étoiles : annuler des automatismes |
|
| 392 | + * |
|
| 393 | + * - '*' annule les filtres automatiques |
|
| 394 | + * - '**' annule en plus les protections de scripts |
|
| 395 | + * @var null|string */ |
|
| 396 | + public $etoile; |
|
| 397 | + |
|
| 398 | + /** |
|
| 399 | + * Arguments et filtres explicites sur la balise |
|
| 400 | + * - $param[0] contient les arguments de la balise |
|
| 401 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 402 | + * @var array */ |
|
| 403 | + public $param = array(); |
|
| 404 | + |
|
| 405 | + /** |
|
| 406 | + * Source des filtres (compatibilité) (?) |
|
| 407 | + * @var array|null */ |
|
| 408 | + public $fonctions = array(); |
|
| 409 | + |
|
| 410 | + /** |
|
| 411 | + * Identifiant de la boucle |
|
| 412 | + * @var string */ |
|
| 413 | + public $id_boucle = ''; |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * AST du squelette, liste de toutes les boucles |
|
| 417 | + * @var Boucles[] */ |
|
| 418 | + public $boucles; |
|
| 419 | + |
|
| 420 | + /** |
|
| 421 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 422 | + * @var string|null */ |
|
| 423 | + public $type_requete; |
|
| 424 | + |
|
| 425 | + /** |
|
| 426 | + * Résultat de la compilation: toujours une expression PHP |
|
| 427 | + * @var string */ |
|
| 428 | + public $code = ''; |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * Interdire les scripts |
|
| 432 | + * |
|
| 433 | + * false si on est sûr de cette balise |
|
| 434 | + * @see interdire_scripts() |
|
| 435 | + * @var bool */ |
|
| 436 | + public $interdire_scripts = true; |
|
| 437 | + |
|
| 438 | + /** |
|
| 439 | + * Description du squelette |
|
| 440 | + * |
|
| 441 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 442 | + * |
|
| 443 | + * Peut contenir les index : |
|
| 444 | + * - nom : Nom du fichier de cache |
|
| 445 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 446 | + * - sourcefile : Chemin du squelette |
|
| 447 | + * - squelette : Code du squelette |
|
| 448 | + * - id_mere : Identifiant de la boucle parente |
|
| 449 | + * - documents : Pour embed et img dans les textes |
|
| 450 | + * - session : Pour un cache sessionné par auteur |
|
| 451 | + * - niv : Niveau de tabulation |
|
| 452 | + * |
|
| 453 | + * @var array */ |
|
| 454 | + public $descr = array(); |
|
| 455 | + |
|
| 456 | + /** |
|
| 457 | + * Numéro de ligne dans le code source du squelette |
|
| 458 | + * @var int */ |
|
| 459 | + public $ligne = 0; |
|
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * Drapeau pour reperer les balises calculées par une fonction explicite |
|
| 463 | + * @var bool */ |
|
| 464 | + public $balise_calculee = false; |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | |
@@ -469,94 +469,94 @@ discard block |
||
| 469 | 469 | * Description d'une chaîne de langue |
| 470 | 470 | **/ |
| 471 | 471 | class Idiome { |
| 472 | - /** |
|
| 473 | - * Type de noeud |
|
| 474 | - * @var string */ |
|
| 475 | - public $type = 'idiome'; |
|
| 476 | - |
|
| 477 | - /** |
|
| 478 | - * Clé de traduction demandée. Exemple 'item_oui' |
|
| 479 | - * @var string */ |
|
| 480 | - public $nom_champ = ""; |
|
| 481 | - |
|
| 482 | - /** |
|
| 483 | - * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 484 | - * @var string */ |
|
| 485 | - public $module = ""; |
|
| 486 | - |
|
| 487 | - /** |
|
| 488 | - * Arguments à passer à la chaîne |
|
| 489 | - * @var array */ |
|
| 490 | - public $arg = array(); |
|
| 491 | - |
|
| 492 | - /** |
|
| 493 | - * Filtres à appliquer au résultat |
|
| 494 | - * @var array */ |
|
| 495 | - public $param = array(); |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Source des filtres (compatibilité) (?) |
|
| 499 | - * @var array|null */ |
|
| 500 | - public $fonctions = array(); |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Inutilisé, propriété générique de l'AST |
|
| 504 | - * @var string|array */ |
|
| 505 | - public $avant = ''; |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * Inutilisé, propriété générique de l'AST |
|
| 509 | - * @var string|array */ |
|
| 510 | - public $apres = ''; |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Identifiant de la boucle |
|
| 514 | - * @var string */ |
|
| 515 | - public $id_boucle = ''; |
|
| 516 | - |
|
| 517 | - /** |
|
| 518 | - * AST du squelette, liste de toutes les boucles |
|
| 519 | - * @var Boucles[] */ |
|
| 520 | - public $boucles; |
|
| 521 | - |
|
| 522 | - /** |
|
| 523 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 524 | - * @var string|null */ |
|
| 525 | - public $type_requete; |
|
| 526 | - |
|
| 527 | - /** |
|
| 528 | - * Résultat de la compilation: toujours une expression PHP |
|
| 529 | - * @var string */ |
|
| 530 | - public $code = ''; |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Interdire les scripts |
|
| 534 | - * @see interdire_scripts() |
|
| 535 | - * @var bool */ |
|
| 536 | - public $interdire_scripts = false; |
|
| 537 | - |
|
| 538 | - /** |
|
| 539 | - * Description du squelette |
|
| 540 | - * |
|
| 541 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 542 | - * |
|
| 543 | - * Peut contenir les index : |
|
| 544 | - * - nom : Nom du fichier de cache |
|
| 545 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 546 | - * - sourcefile : Chemin du squelette |
|
| 547 | - * - squelette : Code du squelette |
|
| 548 | - * - id_mere : Identifiant de la boucle parente |
|
| 549 | - * - documents : Pour embed et img dans les textes |
|
| 550 | - * - session : Pour un cache sessionné par auteur |
|
| 551 | - * - niv : Niveau de tabulation |
|
| 552 | - * |
|
| 553 | - * @var array */ |
|
| 554 | - public $descr = array(); |
|
| 555 | - |
|
| 556 | - /** |
|
| 557 | - * Numéro de ligne dans le code source du squelette |
|
| 558 | - * @var int */ |
|
| 559 | - public $ligne = 0; |
|
| 472 | + /** |
|
| 473 | + * Type de noeud |
|
| 474 | + * @var string */ |
|
| 475 | + public $type = 'idiome'; |
|
| 476 | + |
|
| 477 | + /** |
|
| 478 | + * Clé de traduction demandée. Exemple 'item_oui' |
|
| 479 | + * @var string */ |
|
| 480 | + public $nom_champ = ""; |
|
| 481 | + |
|
| 482 | + /** |
|
| 483 | + * Module de langue où chercher la clé de traduction. Exemple 'medias' |
|
| 484 | + * @var string */ |
|
| 485 | + public $module = ""; |
|
| 486 | + |
|
| 487 | + /** |
|
| 488 | + * Arguments à passer à la chaîne |
|
| 489 | + * @var array */ |
|
| 490 | + public $arg = array(); |
|
| 491 | + |
|
| 492 | + /** |
|
| 493 | + * Filtres à appliquer au résultat |
|
| 494 | + * @var array */ |
|
| 495 | + public $param = array(); |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Source des filtres (compatibilité) (?) |
|
| 499 | + * @var array|null */ |
|
| 500 | + public $fonctions = array(); |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Inutilisé, propriété générique de l'AST |
|
| 504 | + * @var string|array */ |
|
| 505 | + public $avant = ''; |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * Inutilisé, propriété générique de l'AST |
|
| 509 | + * @var string|array */ |
|
| 510 | + public $apres = ''; |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Identifiant de la boucle |
|
| 514 | + * @var string */ |
|
| 515 | + public $id_boucle = ''; |
|
| 516 | + |
|
| 517 | + /** |
|
| 518 | + * AST du squelette, liste de toutes les boucles |
|
| 519 | + * @var Boucles[] */ |
|
| 520 | + public $boucles; |
|
| 521 | + |
|
| 522 | + /** |
|
| 523 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 524 | + * @var string|null */ |
|
| 525 | + public $type_requete; |
|
| 526 | + |
|
| 527 | + /** |
|
| 528 | + * Résultat de la compilation: toujours une expression PHP |
|
| 529 | + * @var string */ |
|
| 530 | + public $code = ''; |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Interdire les scripts |
|
| 534 | + * @see interdire_scripts() |
|
| 535 | + * @var bool */ |
|
| 536 | + public $interdire_scripts = false; |
|
| 537 | + |
|
| 538 | + /** |
|
| 539 | + * Description du squelette |
|
| 540 | + * |
|
| 541 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 542 | + * |
|
| 543 | + * Peut contenir les index : |
|
| 544 | + * - nom : Nom du fichier de cache |
|
| 545 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 546 | + * - sourcefile : Chemin du squelette |
|
| 547 | + * - squelette : Code du squelette |
|
| 548 | + * - id_mere : Identifiant de la boucle parente |
|
| 549 | + * - documents : Pour embed et img dans les textes |
|
| 550 | + * - session : Pour un cache sessionné par auteur |
|
| 551 | + * - niv : Niveau de tabulation |
|
| 552 | + * |
|
| 553 | + * @var array */ |
|
| 554 | + public $descr = array(); |
|
| 555 | + |
|
| 556 | + /** |
|
| 557 | + * Numéro de ligne dans le code source du squelette |
|
| 558 | + * @var int */ |
|
| 559 | + public $ligne = 0; |
|
| 560 | 560 | } |
| 561 | 561 | |
| 562 | 562 | /** |
@@ -565,22 +565,22 @@ discard block |
||
| 565 | 565 | * @package SPIP\Compilateur\AST |
| 566 | 566 | **/ |
| 567 | 567 | class Polyglotte { |
| 568 | - /** |
|
| 569 | - * Type de noeud |
|
| 570 | - * @var string */ |
|
| 571 | - public $type = 'polyglotte'; |
|
| 572 | - |
|
| 573 | - /** |
|
| 574 | - * Tableau des traductions possibles classées par langue |
|
| 575 | - * |
|
| 576 | - * Tableau code de langue => texte |
|
| 577 | - * @var array */ |
|
| 578 | - var $traductions = array(); |
|
| 579 | - |
|
| 580 | - /** |
|
| 581 | - * Numéro de ligne dans le code source du squelette |
|
| 582 | - * @var int */ |
|
| 583 | - public $ligne = 0; |
|
| 568 | + /** |
|
| 569 | + * Type de noeud |
|
| 570 | + * @var string */ |
|
| 571 | + public $type = 'polyglotte'; |
|
| 572 | + |
|
| 573 | + /** |
|
| 574 | + * Tableau des traductions possibles classées par langue |
|
| 575 | + * |
|
| 576 | + * Tableau code de langue => texte |
|
| 577 | + * @var array */ |
|
| 578 | + var $traductions = array(); |
|
| 579 | + |
|
| 580 | + /** |
|
| 581 | + * Numéro de ligne dans le code source du squelette |
|
| 582 | + * @var int */ |
|
| 583 | + public $ligne = 0; |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | |
@@ -606,87 +606,87 @@ discard block |
||
| 606 | 606 | * @return void |
| 607 | 607 | */ |
| 608 | 608 | function declarer_interfaces(){ |
| 609 | - global $exceptions_des_tables, $table_des_tables, $table_date, $table_titre, $table_statut; |
|
| 610 | - |
|
| 611 | - $table_des_tables['articles']='articles'; |
|
| 612 | - $table_des_tables['auteurs']='auteurs'; |
|
| 613 | - $table_des_tables['rubriques']='rubriques'; |
|
| 614 | - $table_des_tables['hierarchie']='rubriques'; |
|
| 615 | - |
|
| 616 | - // definition des statuts de publication |
|
| 617 | - global $tables_statut; |
|
| 618 | - $table_statut = array(); |
|
| 619 | - |
|
| 620 | - // |
|
| 621 | - // tableau des tables de jointures |
|
| 622 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 623 | - global $tables_jointures; |
|
| 624 | - $tables_jointures = array(); |
|
| 625 | - $tables_jointures['spip_jobs'][] = 'jobs_liens'; |
|
| 626 | - |
|
| 627 | - global $exceptions_des_jointures; |
|
| 628 | - #$exceptions_des_jointures['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 629 | - $exceptions_des_jointures['profondeur'] = array('spip_rubriques', 'profondeur'); |
|
| 630 | - |
|
| 631 | - global $table_des_traitements; |
|
| 632 | - |
|
| 633 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 634 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 635 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'typo(supprimer_numero(%s), "TYPO", $connect, $Pile[0])'); |
|
| 636 | - |
|
| 637 | - $table_des_traitements['BIO'][]= _TRAITEMENT_RACCOURCIS; |
|
| 638 | - $table_des_traitements['CHAPO'][]= _TRAITEMENT_RACCOURCIS; |
|
| 639 | - $table_des_traitements['DATE'][]= 'normaliser_date(%s)'; |
|
| 640 | - $table_des_traitements['DATE_REDAC'][]= 'normaliser_date(%s)'; |
|
| 641 | - $table_des_traitements['DATE_MODIF'][]= 'normaliser_date(%s)'; |
|
| 642 | - $table_des_traitements['DATE_NOUVEAUTES'][]= 'normaliser_date(%s)'; |
|
| 643 | - $table_des_traitements['DESCRIPTIF'][]= _TRAITEMENT_RACCOURCIS; |
|
| 644 | - $table_des_traitements['INTRODUCTION'][]= 'PtoBR('. _TRAITEMENT_RACCOURCIS .')'; |
|
| 645 | - $table_des_traitements['NOM_SITE_SPIP'][]= _TRAITEMENT_TYPO; |
|
| 646 | - $table_des_traitements['NOM'][]= _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 647 | - $table_des_traitements['AUTEUR'][]= _TRAITEMENT_TYPO; |
|
| 648 | - $table_des_traitements['PS'][]= _TRAITEMENT_RACCOURCIS; |
|
| 649 | - $table_des_traitements['SOURCE'][]= _TRAITEMENT_TYPO; |
|
| 650 | - $table_des_traitements['SOUSTITRE'][]= _TRAITEMENT_TYPO; |
|
| 651 | - $table_des_traitements['SURTITRE'][]= _TRAITEMENT_TYPO; |
|
| 652 | - $table_des_traitements['TAGS'][]= '%s'; |
|
| 653 | - $table_des_traitements['TEXTE'][]= _TRAITEMENT_RACCOURCIS; |
|
| 654 | - $table_des_traitements['TITRE'][]= _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 655 | - $table_des_traitements['TYPE'][]= _TRAITEMENT_TYPO; |
|
| 656 | - $table_des_traitements['DESCRIPTIF_SITE_SPIP'][]= _TRAITEMENT_RACCOURCIS; |
|
| 657 | - $table_des_traitements['SLOGAN_SITE_SPIP'][]= _TRAITEMENT_TYPO; |
|
| 658 | - $table_des_traitements['ENV'][]= 'entites_html(%s,true)'; |
|
| 659 | - |
|
| 660 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 661 | - $table_des_traitements['*'][]= false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 662 | - // toujours securiser les DATA |
|
| 663 | - $table_des_traitements['*']['DATA']= 'safehtml(%s)'; |
|
| 664 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 665 | - $table_des_traitements['VALEUR']['DATA']= 'safehtml(%s)'; |
|
| 666 | - |
|
| 667 | - |
|
| 668 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 669 | - $interfaces = pipeline('declarer_tables_interfaces', |
|
| 670 | - array( |
|
| 671 | - 'table_des_tables'=>$table_des_tables, |
|
| 672 | - 'exceptions_des_tables'=>$exceptions_des_tables, |
|
| 673 | - 'table_date'=>$table_date, |
|
| 674 | - 'table_titre'=>$table_titre, |
|
| 675 | - 'tables_jointures'=>$tables_jointures, |
|
| 676 | - 'exceptions_des_jointures'=>$exceptions_des_jointures, |
|
| 677 | - 'table_des_traitements'=>$table_des_traitements, |
|
| 678 | - 'table_statut'=>$table_statut, |
|
| 679 | - )); |
|
| 680 | - if ($interfaces){ |
|
| 681 | - $table_des_tables = $interfaces['table_des_tables']; |
|
| 682 | - $exceptions_des_tables = $interfaces['exceptions_des_tables']; |
|
| 683 | - $table_date = $interfaces['table_date']; |
|
| 684 | - $table_titre = $interfaces['table_titre']; |
|
| 685 | - $tables_jointures = $interfaces['tables_jointures']; |
|
| 686 | - $exceptions_des_jointures = $interfaces['exceptions_des_jointures']; |
|
| 687 | - $table_des_traitements = $interfaces['table_des_traitements']; |
|
| 688 | - $table_statut = $interfaces['table_statut']; |
|
| 689 | - } |
|
| 609 | + global $exceptions_des_tables, $table_des_tables, $table_date, $table_titre, $table_statut; |
|
| 610 | + |
|
| 611 | + $table_des_tables['articles']='articles'; |
|
| 612 | + $table_des_tables['auteurs']='auteurs'; |
|
| 613 | + $table_des_tables['rubriques']='rubriques'; |
|
| 614 | + $table_des_tables['hierarchie']='rubriques'; |
|
| 615 | + |
|
| 616 | + // definition des statuts de publication |
|
| 617 | + global $tables_statut; |
|
| 618 | + $table_statut = array(); |
|
| 619 | + |
|
| 620 | + // |
|
| 621 | + // tableau des tables de jointures |
|
| 622 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 623 | + global $tables_jointures; |
|
| 624 | + $tables_jointures = array(); |
|
| 625 | + $tables_jointures['spip_jobs'][] = 'jobs_liens'; |
|
| 626 | + |
|
| 627 | + global $exceptions_des_jointures; |
|
| 628 | + #$exceptions_des_jointures['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 629 | + $exceptions_des_jointures['profondeur'] = array('spip_rubriques', 'profondeur'); |
|
| 630 | + |
|
| 631 | + global $table_des_traitements; |
|
| 632 | + |
|
| 633 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 634 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 635 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'typo(supprimer_numero(%s), "TYPO", $connect, $Pile[0])'); |
|
| 636 | + |
|
| 637 | + $table_des_traitements['BIO'][]= _TRAITEMENT_RACCOURCIS; |
|
| 638 | + $table_des_traitements['CHAPO'][]= _TRAITEMENT_RACCOURCIS; |
|
| 639 | + $table_des_traitements['DATE'][]= 'normaliser_date(%s)'; |
|
| 640 | + $table_des_traitements['DATE_REDAC'][]= 'normaliser_date(%s)'; |
|
| 641 | + $table_des_traitements['DATE_MODIF'][]= 'normaliser_date(%s)'; |
|
| 642 | + $table_des_traitements['DATE_NOUVEAUTES'][]= 'normaliser_date(%s)'; |
|
| 643 | + $table_des_traitements['DESCRIPTIF'][]= _TRAITEMENT_RACCOURCIS; |
|
| 644 | + $table_des_traitements['INTRODUCTION'][]= 'PtoBR('. _TRAITEMENT_RACCOURCIS .')'; |
|
| 645 | + $table_des_traitements['NOM_SITE_SPIP'][]= _TRAITEMENT_TYPO; |
|
| 646 | + $table_des_traitements['NOM'][]= _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 647 | + $table_des_traitements['AUTEUR'][]= _TRAITEMENT_TYPO; |
|
| 648 | + $table_des_traitements['PS'][]= _TRAITEMENT_RACCOURCIS; |
|
| 649 | + $table_des_traitements['SOURCE'][]= _TRAITEMENT_TYPO; |
|
| 650 | + $table_des_traitements['SOUSTITRE'][]= _TRAITEMENT_TYPO; |
|
| 651 | + $table_des_traitements['SURTITRE'][]= _TRAITEMENT_TYPO; |
|
| 652 | + $table_des_traitements['TAGS'][]= '%s'; |
|
| 653 | + $table_des_traitements['TEXTE'][]= _TRAITEMENT_RACCOURCIS; |
|
| 654 | + $table_des_traitements['TITRE'][]= _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 655 | + $table_des_traitements['TYPE'][]= _TRAITEMENT_TYPO; |
|
| 656 | + $table_des_traitements['DESCRIPTIF_SITE_SPIP'][]= _TRAITEMENT_RACCOURCIS; |
|
| 657 | + $table_des_traitements['SLOGAN_SITE_SPIP'][]= _TRAITEMENT_TYPO; |
|
| 658 | + $table_des_traitements['ENV'][]= 'entites_html(%s,true)'; |
|
| 659 | + |
|
| 660 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 661 | + $table_des_traitements['*'][]= false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 662 | + // toujours securiser les DATA |
|
| 663 | + $table_des_traitements['*']['DATA']= 'safehtml(%s)'; |
|
| 664 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 665 | + $table_des_traitements['VALEUR']['DATA']= 'safehtml(%s)'; |
|
| 666 | + |
|
| 667 | + |
|
| 668 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 669 | + $interfaces = pipeline('declarer_tables_interfaces', |
|
| 670 | + array( |
|
| 671 | + 'table_des_tables'=>$table_des_tables, |
|
| 672 | + 'exceptions_des_tables'=>$exceptions_des_tables, |
|
| 673 | + 'table_date'=>$table_date, |
|
| 674 | + 'table_titre'=>$table_titre, |
|
| 675 | + 'tables_jointures'=>$tables_jointures, |
|
| 676 | + 'exceptions_des_jointures'=>$exceptions_des_jointures, |
|
| 677 | + 'table_des_traitements'=>$table_des_traitements, |
|
| 678 | + 'table_statut'=>$table_statut, |
|
| 679 | + )); |
|
| 680 | + if ($interfaces){ |
|
| 681 | + $table_des_tables = $interfaces['table_des_tables']; |
|
| 682 | + $exceptions_des_tables = $interfaces['exceptions_des_tables']; |
|
| 683 | + $table_date = $interfaces['table_date']; |
|
| 684 | + $table_titre = $interfaces['table_titre']; |
|
| 685 | + $tables_jointures = $interfaces['tables_jointures']; |
|
| 686 | + $exceptions_des_jointures = $interfaces['exceptions_des_jointures']; |
|
| 687 | + $table_des_traitements = $interfaces['table_des_traitements']; |
|
| 688 | + $table_statut = $interfaces['table_statut']; |
|
| 689 | + } |
|
| 690 | 690 | } |
| 691 | 691 | |
| 692 | 692 | declarer_interfaces(); |