@@ -133,6 +133,10 @@ discard block |
||
| 133 | 133 | return $nom ? $nom : false; |
| 134 | 134 | } |
| 135 | 135 | |
| 136 | +/** |
|
| 137 | + * @param string $squelette |
|
| 138 | + * @param string $phpfile |
|
| 139 | + */ |
|
| 136 | 140 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 137 | 141 | |
| 138 | 142 | // Le dernier index est '' (fonction principale) |
@@ -157,6 +161,9 @@ discard block |
||
| 157 | 161 | |
| 158 | 162 | // Le squelette compile est-il trop vieux ? |
| 159 | 163 | // http://code.spip.net/@squelette_obsolete |
| 164 | +/** |
|
| 165 | + * @param string $skel |
|
| 166 | + */ |
|
| 160 | 167 | function squelette_obsolete($skel, $squelette) { |
| 161 | 168 | static $date_change = null; |
| 162 | 169 | // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('inc/texte'); |
@@ -42,224 +42,224 @@ discard block |
||
| 42 | 42 | // http://code.spip.net/@public_composer_dist |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 44 | 44 | |
| 45 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | - |
|
| 47 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | - if (function_exists($nom)) { |
|
| 49 | - return $nom; |
|
| 50 | - } |
|
| 51 | - |
|
| 52 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | - |
|
| 58 | - // si squelette est deja compile et perenne, le charger |
|
| 59 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | - include_once $phpfile; |
|
| 61 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | - ## eval('?'.'>'.$skel_code); |
|
| 65 | - # spip_log($skel_code, 'comp') |
|
| 66 | - #} |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | - include_once $lib; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | - |
|
| 75 | - if (function_exists($nom)) { |
|
| 76 | - return $nom; |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // charger le source, si possible, et compiler |
|
| 80 | - if (lire_fichier($source, $skel)) { |
|
| 81 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 82 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 83 | - } |
|
| 84 | - else |
|
| 85 | - $skel_code=''; |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - if (@eval("return true; $f ;") === false) { |
|
| 95 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 96 | - $msg = _T('zbug_erreur_compilation'); |
|
| 97 | - erreur_squelette($msg, $boucle); |
|
| 98 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 99 | - // mais prevenir que c'est mort |
|
| 100 | - $nom = ''; |
|
| 101 | - } |
|
| 102 | - // Contexte de compil inutile a present |
|
| 103 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 104 | - $skel_code[$id] = $f; |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - $code = ''; |
|
| 108 | - if ($nom) { |
|
| 109 | - // Si le code est bon, concatener et mettre en cache |
|
| 110 | - if (function_exists($nom)) { |
|
| 111 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 112 | - } else { |
|
| 113 | - // code semantiquement faux: bug du compilateur |
|
| 114 | - // $boucle est en fait ici la fct principale du squelette |
|
| 115 | - $msg = _T('zbug_erreur_compilation'); |
|
| 116 | - erreur_squelette($msg, $boucle); |
|
| 117 | - $nom = ''; |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 122 | - |
|
| 123 | - // Tracer ce qui vient d'etre compile |
|
| 124 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 125 | - |
|
| 126 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 127 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 128 | - and (_request('var_mode_objet') == $nom) |
|
| 129 | - and (_request('var_mode_affiche') == 'code') |
|
| 130 | - ) { |
|
| 131 | - erreur_squelette(); |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return $nom ? $nom : false; |
|
| 45 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 46 | + |
|
| 47 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 48 | + if (function_exists($nom)) { |
|
| 49 | + return $nom; |
|
| 50 | + } |
|
| 51 | + |
|
| 52 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 53 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + |
|
| 58 | + // si squelette est deja compile et perenne, le charger |
|
| 59 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 60 | + include_once $phpfile; |
|
| 61 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 62 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 63 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 64 | + ## eval('?'.'>'.$skel_code); |
|
| 65 | + # spip_log($skel_code, 'comp') |
|
| 66 | + #} |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + include_once $lib; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 74 | + |
|
| 75 | + if (function_exists($nom)) { |
|
| 76 | + return $nom; |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // charger le source, si possible, et compiler |
|
| 80 | + if (lire_fichier($source, $skel)) { |
|
| 81 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 82 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 83 | + } |
|
| 84 | + else |
|
| 85 | + $skel_code=''; |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + if (@eval("return true; $f ;") === false) { |
|
| 95 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 96 | + $msg = _T('zbug_erreur_compilation'); |
|
| 97 | + erreur_squelette($msg, $boucle); |
|
| 98 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 99 | + // mais prevenir que c'est mort |
|
| 100 | + $nom = ''; |
|
| 101 | + } |
|
| 102 | + // Contexte de compil inutile a present |
|
| 103 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 104 | + $skel_code[$id] = $f; |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + $code = ''; |
|
| 108 | + if ($nom) { |
|
| 109 | + // Si le code est bon, concatener et mettre en cache |
|
| 110 | + if (function_exists($nom)) { |
|
| 111 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 112 | + } else { |
|
| 113 | + // code semantiquement faux: bug du compilateur |
|
| 114 | + // $boucle est en fait ici la fct principale du squelette |
|
| 115 | + $msg = _T('zbug_erreur_compilation'); |
|
| 116 | + erreur_squelette($msg, $boucle); |
|
| 117 | + $nom = ''; |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 122 | + |
|
| 123 | + // Tracer ce qui vient d'etre compile |
|
| 124 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 125 | + |
|
| 126 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 127 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 128 | + and (_request('var_mode_objet') == $nom) |
|
| 129 | + and (_request('var_mode_affiche') == 'code') |
|
| 130 | + ) { |
|
| 131 | + erreur_squelette(); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return $nom ? $nom : false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 139 | 139 | |
| 140 | - // Le dernier index est '' (fonction principale) |
|
| 141 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 142 | - if (CODE_COMMENTE) { |
|
| 143 | - $code = " |
|
| 140 | + // Le dernier index est '' (fonction principale) |
|
| 141 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 142 | + if (CODE_COMMENTE) { |
|
| 143 | + $code = " |
|
| 144 | 144 | /* |
| 145 | 145 | * Squelette : $sourcefile |
| 146 | 146 | * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
| 147 | 147 | * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
| 148 | 148 | * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
| 149 | 149 | */ "; |
| 150 | - } |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 153 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 154 | - ecrire_fichier($phpfile, $code); |
|
| 155 | - } |
|
| 152 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 153 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 154 | + ecrire_fichier($phpfile, $code); |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - return $code; |
|
| 157 | + return $code; |
|
| 158 | 158 | } |
| 159 | 159 | |
| 160 | 160 | // Le squelette compile est-il trop vieux ? |
| 161 | 161 | // http://code.spip.net/@squelette_obsolete |
| 162 | 162 | function squelette_obsolete($skel, $squelette) { |
| 163 | - static $date_change = null; |
|
| 164 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 165 | - // par hit |
|
| 166 | - if (is_null($date_change)) { |
|
| 167 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 168 | - $date_change = @filemtime($fonc); |
|
| 169 | - } # compatibilite |
|
| 170 | - if (defined('_FILE_OPTIONS')) { |
|
| 171 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - return ( |
|
| 176 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 177 | - or !@file_exists($skel) |
|
| 178 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 179 | - > ($date = @filemtime($skel))) |
|
| 180 | - or ($date_change > $date) |
|
| 181 | - ); |
|
| 163 | + static $date_change = null; |
|
| 164 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 165 | + // par hit |
|
| 166 | + if (is_null($date_change)) { |
|
| 167 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 168 | + $date_change = @filemtime($fonc); |
|
| 169 | + } # compatibilite |
|
| 170 | + if (defined('_FILE_OPTIONS')) { |
|
| 171 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + return ( |
|
| 176 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, array('recalcul', 'preview', 'debug'))) |
|
| 177 | + or !@file_exists($skel) |
|
| 178 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 179 | + > ($date = @filemtime($skel))) |
|
| 180 | + or ($date_change > $date) |
|
| 181 | + ); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | // Activer l'invalideur de session |
| 185 | 185 | // http://code.spip.net/@invalideur_session |
| 186 | 186 | function invalideur_session(&$Cache, $code = null) { |
| 187 | - $Cache['session'] = spip_session(); |
|
| 187 | + $Cache['session'] = spip_session(); |
|
| 188 | 188 | |
| 189 | - return $code; |
|
| 189 | + return $code; |
|
| 190 | 190 | } |
| 191 | 191 | |
| 192 | 192 | |
| 193 | 193 | // http://code.spip.net/@analyse_resultat_skel |
| 194 | 194 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 195 | - static $filtres = array(); |
|
| 196 | - $headers = array(); |
|
| 197 | - |
|
| 198 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 199 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 200 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 201 | - if (stripos($corps, 'header') !== false |
|
| 202 | - and preg_match_all( |
|
| 203 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 204 | - $corps, $regs, PREG_SET_ORDER) |
|
| 205 | - ) { |
|
| 206 | - foreach ($regs as $r) { |
|
| 207 | - $corps = str_replace($r[0], '', $corps); |
|
| 208 | - # $j = Content-Type, et pas content-TYPE. |
|
| 209 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 210 | - |
|
| 211 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 212 | - $headers[$j] .= "|" . $r[3]; |
|
| 213 | - } else { |
|
| 214 | - $headers[$j] = $r[3]; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - } |
|
| 218 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 219 | - $process_ins = ( |
|
| 220 | - strpos($corps, '<' . '?') === false |
|
| 221 | - or |
|
| 222 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 223 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 224 | - ) |
|
| 225 | - ? 'html' |
|
| 226 | - : 'php'; |
|
| 227 | - |
|
| 228 | - $skel = array( |
|
| 229 | - 'squelette' => $nom, |
|
| 230 | - 'source' => $source, |
|
| 231 | - 'process_ins' => $process_ins, |
|
| 232 | - 'invalideurs' => $cache, |
|
| 233 | - 'entetes' => $headers, |
|
| 234 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 235 | - ); |
|
| 236 | - |
|
| 237 | - // traiter #FILTRE{} et filtres |
|
| 238 | - if (!isset($filtres[$nom])) { |
|
| 239 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 240 | - } |
|
| 241 | - if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 242 | - include_spip('public/sandbox'); |
|
| 243 | - $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 244 | - strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 245 | - unset($headers['X-Spip-Filtre']); |
|
| 246 | - |
|
| 247 | - if ($process_ins == 'html') { |
|
| 248 | - $skel['process_ins'] = ( |
|
| 249 | - strpos($corps, '<' . '?') === false |
|
| 250 | - or |
|
| 251 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 252 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 253 | - ) |
|
| 254 | - ? 'html' |
|
| 255 | - : 'php'; |
|
| 256 | - } |
|
| 257 | - } |
|
| 258 | - |
|
| 259 | - $skel['entetes'] = $headers; |
|
| 260 | - $skel['texte'] = $corps; |
|
| 261 | - |
|
| 262 | - return $skel; |
|
| 195 | + static $filtres = array(); |
|
| 196 | + $headers = array(); |
|
| 197 | + |
|
| 198 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 199 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 200 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 201 | + if (stripos($corps, 'header') !== false |
|
| 202 | + and preg_match_all( |
|
| 203 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 204 | + $corps, $regs, PREG_SET_ORDER) |
|
| 205 | + ) { |
|
| 206 | + foreach ($regs as $r) { |
|
| 207 | + $corps = str_replace($r[0], '', $corps); |
|
| 208 | + # $j = Content-Type, et pas content-TYPE. |
|
| 209 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 210 | + |
|
| 211 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 212 | + $headers[$j] .= "|" . $r[3]; |
|
| 213 | + } else { |
|
| 214 | + $headers[$j] = $r[3]; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + } |
|
| 218 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 219 | + $process_ins = ( |
|
| 220 | + strpos($corps, '<' . '?') === false |
|
| 221 | + or |
|
| 222 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 223 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 224 | + ) |
|
| 225 | + ? 'html' |
|
| 226 | + : 'php'; |
|
| 227 | + |
|
| 228 | + $skel = array( |
|
| 229 | + 'squelette' => $nom, |
|
| 230 | + 'source' => $source, |
|
| 231 | + 'process_ins' => $process_ins, |
|
| 232 | + 'invalideurs' => $cache, |
|
| 233 | + 'entetes' => $headers, |
|
| 234 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 235 | + ); |
|
| 236 | + |
|
| 237 | + // traiter #FILTRE{} et filtres |
|
| 238 | + if (!isset($filtres[$nom])) { |
|
| 239 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', array('args' => $skel, 'data' => array())); |
|
| 240 | + } |
|
| 241 | + if (count($filtres[$nom]) or (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre']))) { |
|
| 242 | + include_spip('public/sandbox'); |
|
| 243 | + $corps = sandbox_filtrer_squelette($skel, $corps, |
|
| 244 | + strlen($headers['X-Spip-Filtre']) ? explode('|', $headers['X-Spip-Filtre']) : array(), $filtres[$nom]); |
|
| 245 | + unset($headers['X-Spip-Filtre']); |
|
| 246 | + |
|
| 247 | + if ($process_ins == 'html') { |
|
| 248 | + $skel['process_ins'] = ( |
|
| 249 | + strpos($corps, '<' . '?') === false |
|
| 250 | + or |
|
| 251 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 252 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 253 | + ) |
|
| 254 | + ? 'html' |
|
| 255 | + : 'php'; |
|
| 256 | + } |
|
| 257 | + } |
|
| 258 | + |
|
| 259 | + $skel['entetes'] = $headers; |
|
| 260 | + $skel['texte'] = $corps; |
|
| 261 | + |
|
| 262 | + return $skel; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | // |
@@ -296,75 +296,75 @@ discard block |
||
| 296 | 296 | * Introduction calculée |
| 297 | 297 | **/ |
| 298 | 298 | function filtre_introduction_dist($descriptif, $texte, $longueur, $connect, $suite = null) { |
| 299 | - // Si un descriptif est envoye, on l'utilise directement |
|
| 300 | - if (strlen($descriptif)) { |
|
| 301 | - return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // De preference ce qui est marque <intro>...</intro> |
|
| 305 | - $intro = ''; |
|
| 306 | - $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 307 | - while ($fin = strpos($texte, "</intro>")) { |
|
| 308 | - $zone = substr($texte, 0, $fin); |
|
| 309 | - $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 310 | - if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 311 | - $zone = substr($zone, $deb + 7); |
|
| 312 | - } |
|
| 313 | - $intro .= $zone; |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 317 | - // qui inclus raccourcis et modeles |
|
| 318 | - // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 319 | - // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 320 | - // des surcharges et enrichissement de propre |
|
| 321 | - // couper doit se faire apres propre |
|
| 322 | - //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 323 | - |
|
| 324 | - // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 325 | - // large et en se mefiant des tableaux #1323 |
|
| 326 | - |
|
| 327 | - if (strlen($intro)) { |
|
| 328 | - $texte = $intro; |
|
| 329 | - } else { |
|
| 330 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 331 | - and strlen($texte) > 2.5 * $longueur |
|
| 332 | - ) { |
|
| 333 | - if (strpos($texte, "<multi") !== false) { |
|
| 334 | - $texte = extraire_multi($texte); |
|
| 335 | - } |
|
| 336 | - $texte = couper($texte, 2 * $longueur); |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - // ne pas tenir compte des notes |
|
| 341 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 342 | - $notes('', 'empiler'); |
|
| 343 | - } |
|
| 344 | - // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 345 | - // dans l'introduction. |
|
| 346 | - $texte = supprime_img($texte, ''); |
|
| 347 | - $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 348 | - |
|
| 349 | - if ($notes) { |
|
| 350 | - $notes('', 'depiler'); |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 354 | - $suite = _INTRODUCTION_SUITE; |
|
| 355 | - } |
|
| 356 | - $texte = couper($texte, $longueur, $suite); |
|
| 357 | - // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 358 | - $texte = typo($texte, true, $connect, array()); |
|
| 359 | - |
|
| 360 | - // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 361 | - // une introduction a tojours un <p> |
|
| 362 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 363 | - { |
|
| 364 | - $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 365 | - } |
|
| 366 | - |
|
| 367 | - return $texte; |
|
| 299 | + // Si un descriptif est envoye, on l'utilise directement |
|
| 300 | + if (strlen($descriptif)) { |
|
| 301 | + return appliquer_traitement_champ($descriptif, 'introduction', '', array(), $connect); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // De preference ce qui est marque <intro>...</intro> |
|
| 305 | + $intro = ''; |
|
| 306 | + $texte = preg_replace(",(</?)intro>,i", "\\1intro>", $texte); // minuscules |
|
| 307 | + while ($fin = strpos($texte, "</intro>")) { |
|
| 308 | + $zone = substr($texte, 0, $fin); |
|
| 309 | + $texte = substr($texte, $fin + strlen("</intro>")); |
|
| 310 | + if ($deb = strpos($zone, "<intro>") or substr($zone, 0, 7) == "<intro>") { |
|
| 311 | + $zone = substr($zone, $deb + 7); |
|
| 312 | + } |
|
| 313 | + $intro .= $zone; |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + // [12025] On ne *PEUT* pas couper simplement ici car c'est du texte brut, |
|
| 317 | + // qui inclus raccourcis et modeles |
|
| 318 | + // un simple <articlexx> peut etre ensuite transforme en 1000 lignes ... |
|
| 319 | + // par ailleurs le nettoyage des raccourcis ne tient pas compte |
|
| 320 | + // des surcharges et enrichissement de propre |
|
| 321 | + // couper doit se faire apres propre |
|
| 322 | + //$texte = nettoyer_raccourcis_typo($intro ? $intro : $texte, $connect); |
|
| 323 | + |
|
| 324 | + // Cependant pour des questions de perfs on coupe quand meme, en prenant |
|
| 325 | + // large et en se mefiant des tableaux #1323 |
|
| 326 | + |
|
| 327 | + if (strlen($intro)) { |
|
| 328 | + $texte = $intro; |
|
| 329 | + } else { |
|
| 330 | + if (strpos("\n" . $texte, "\n|") === false |
|
| 331 | + and strlen($texte) > 2.5 * $longueur |
|
| 332 | + ) { |
|
| 333 | + if (strpos($texte, "<multi") !== false) { |
|
| 334 | + $texte = extraire_multi($texte); |
|
| 335 | + } |
|
| 336 | + $texte = couper($texte, 2 * $longueur); |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + // ne pas tenir compte des notes |
|
| 341 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 342 | + $notes('', 'empiler'); |
|
| 343 | + } |
|
| 344 | + // Supprimer les modèles avant le propre afin d'éviter qu'ils n'ajoutent du texte indésirable |
|
| 345 | + // dans l'introduction. |
|
| 346 | + $texte = supprime_img($texte, ''); |
|
| 347 | + $texte = appliquer_traitement_champ($texte, 'introduction', '', array(), $connect); |
|
| 348 | + |
|
| 349 | + if ($notes) { |
|
| 350 | + $notes('', 'depiler'); |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (is_null($suite) and defined('_INTRODUCTION_SUITE')) { |
|
| 354 | + $suite = _INTRODUCTION_SUITE; |
|
| 355 | + } |
|
| 356 | + $texte = couper($texte, $longueur, $suite); |
|
| 357 | + // comme on a coupe il faut repasser la typo (on a perdu les insecables) |
|
| 358 | + $texte = typo($texte, true, $connect, array()); |
|
| 359 | + |
|
| 360 | + // et reparagrapher si necessaire (coherence avec le cas descriptif) |
|
| 361 | + // une introduction a tojours un <p> |
|
| 362 | + if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 363 | + { |
|
| 364 | + $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
|
| 365 | + } |
|
| 366 | + |
|
| 367 | + return $texte; |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | // |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 379 | 379 | if ($lang_select) lang_select(); |
| 380 | 380 | ?' |
| 381 | - . '>'); |
|
| 381 | + . '>'); |
|
| 382 | 382 | |
| 383 | 383 | /** |
| 384 | 384 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -398,17 +398,17 @@ discard block |
||
| 398 | 398 | * Code PHP pour inclure le squelette de la balise dynamique |
| 399 | 399 | **/ |
| 400 | 400 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 401 | - if (strncmp($file, "/", 1) !== 0) { |
|
| 402 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 403 | - } |
|
| 404 | - $r = sprintf(CODE_INCLURE_BALISE, |
|
| 405 | - $file, |
|
| 406 | - $context_compil[4] ? $context_compil[4] : '', |
|
| 407 | - $nom, |
|
| 408 | - join(', ', array_map('argumenter_squelette', $args)), |
|
| 409 | - join(', ', array_map('_q', $context_compil))); |
|
| 410 | - |
|
| 411 | - return $r; |
|
| 401 | + if (strncmp($file, "/", 1) !== 0) { |
|
| 402 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 403 | + } |
|
| 404 | + $r = sprintf(CODE_INCLURE_BALISE, |
|
| 405 | + $file, |
|
| 406 | + $context_compil[4] ? $context_compil[4] : '', |
|
| 407 | + $nom, |
|
| 408 | + join(', ', array_map('argumenter_squelette', $args)), |
|
| 409 | + join(', ', array_map('_q', $context_compil))); |
|
| 410 | + |
|
| 411 | + return $r; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -426,16 +426,16 @@ discard block |
||
| 426 | 426 | **/ |
| 427 | 427 | function argumenter_squelette($v) { |
| 428 | 428 | |
| 429 | - if (!is_array($v)) { |
|
| 430 | - return "'" . texte_script($v) . "'"; |
|
| 431 | - } else { |
|
| 432 | - $out = array(); |
|
| 433 | - foreach ($v as $k => $val) { |
|
| 434 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 435 | - } |
|
| 429 | + if (!is_array($v)) { |
|
| 430 | + return "'" . texte_script($v) . "'"; |
|
| 431 | + } else { |
|
| 432 | + $out = array(); |
|
| 433 | + foreach ($v as $k => $val) { |
|
| 434 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 435 | + } |
|
| 436 | 436 | |
| 437 | - return 'array(' . join(", ", $out) . ')'; |
|
| 438 | - } |
|
| 437 | + return 'array(' . join(", ", $out) . ')'; |
|
| 438 | + } |
|
| 439 | 439 | } |
| 440 | 440 | |
| 441 | 441 | |
@@ -466,69 +466,69 @@ discard block |
||
| 466 | 466 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 467 | 467 | **/ |
| 468 | 468 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 469 | - $nomfonction = $nom; |
|
| 470 | - $nomfonction_generique = ""; |
|
| 471 | - |
|
| 472 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 473 | - if (false !== ($p = strpos($nom, "_"))) { |
|
| 474 | - $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 475 | - } |
|
| 476 | - |
|
| 477 | - if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 478 | - if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 479 | - // et injecter en premier arg le nom de la balise |
|
| 480 | - array_unshift($args, $nom); |
|
| 481 | - $nomfonction = $nomfonction_generique; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if (!$fonction_balise) { |
|
| 486 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 487 | - erreur_squelette($msg, $context_compil); |
|
| 488 | - |
|
| 489 | - return ''; |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - // retrouver le fichier qui a déclaré la fonction |
|
| 493 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 494 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 495 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 496 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 497 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 498 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 502 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 503 | - |
|
| 504 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 505 | - |
|
| 506 | - if (!is_array($r)) { |
|
| 507 | - return $r; |
|
| 508 | - } |
|
| 509 | - |
|
| 510 | - // verifier que la fonction dyn est la, |
|
| 511 | - // sinon se replier sur la generique si elle existe |
|
| 512 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 513 | - if ($nomfonction_generique |
|
| 514 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 515 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 516 | - ) { |
|
| 517 | - // et lui injecter en premier arg le nom de la balise |
|
| 518 | - array_unshift($r, $nom); |
|
| 519 | - $nomfonction = $nomfonction_generique; |
|
| 520 | - if (!_DIR_RESTREINT) { |
|
| 521 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 522 | - } |
|
| 523 | - } else { |
|
| 524 | - $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 525 | - erreur_squelette($msg, $context_compil); |
|
| 526 | - |
|
| 527 | - return ''; |
|
| 528 | - } |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 469 | + $nomfonction = $nom; |
|
| 470 | + $nomfonction_generique = ""; |
|
| 471 | + |
|
| 472 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 473 | + if (false !== ($p = strpos($nom, "_"))) { |
|
| 474 | + $nomfonction_generique = substr($nom, 0, $p + 1); |
|
| 475 | + } |
|
| 476 | + |
|
| 477 | + if (!$fonction_balise = charger_fonction($nomfonction, 'balise', true)) { |
|
| 478 | + if ($nomfonction_generique and $fonction_balise = charger_fonction($nomfonction_generique, 'balise', true)) { |
|
| 479 | + // et injecter en premier arg le nom de la balise |
|
| 480 | + array_unshift($args, $nom); |
|
| 481 | + $nomfonction = $nomfonction_generique; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if (!$fonction_balise) { |
|
| 486 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 487 | + erreur_squelette($msg, $context_compil); |
|
| 488 | + |
|
| 489 | + return ''; |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + // retrouver le fichier qui a déclaré la fonction |
|
| 493 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 494 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 495 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 496 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 497 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 498 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 502 | + $f = 'balise_' . $nomfonction . '_stat'; |
|
| 503 | + |
|
| 504 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 505 | + |
|
| 506 | + if (!is_array($r)) { |
|
| 507 | + return $r; |
|
| 508 | + } |
|
| 509 | + |
|
| 510 | + // verifier que la fonction dyn est la, |
|
| 511 | + // sinon se replier sur la generique si elle existe |
|
| 512 | + if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 513 | + if ($nomfonction_generique |
|
| 514 | + and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 515 | + and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 516 | + ) { |
|
| 517 | + // et lui injecter en premier arg le nom de la balise |
|
| 518 | + array_unshift($r, $nom); |
|
| 519 | + $nomfonction = $nomfonction_generique; |
|
| 520 | + if (!_DIR_RESTREINT) { |
|
| 521 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 522 | + } |
|
| 523 | + } else { |
|
| 524 | + $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
|
| 525 | + erreur_squelette($msg, $context_compil); |
|
| 526 | + |
|
| 527 | + return ''; |
|
| 528 | + } |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + return synthetiser_balise_dynamique($nomfonction, $r, $file, $context_compil); |
|
| 532 | 532 | |
| 533 | 533 | } |
| 534 | 534 | |
@@ -544,24 +544,24 @@ discard block |
||
| 544 | 544 | **/ |
| 545 | 545 | function lister_objets_avec_logos($type) { |
| 546 | 546 | |
| 547 | - $logos = array(); |
|
| 548 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 549 | - $type = '/' |
|
| 550 | - . type_du_logo($type) |
|
| 551 | - . "on(\d+)\.(" |
|
| 552 | - . join('|', $GLOBALS['formats_logos']) |
|
| 553 | - . ")$/"; |
|
| 554 | - |
|
| 555 | - if ($d = opendir(_DIR_LOGOS)) { |
|
| 556 | - while (($f = readdir($d)) !== false) { |
|
| 557 | - if (preg_match($type, $f, $r)) { |
|
| 558 | - $logos[] = $r[1]; |
|
| 559 | - } |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - @closedir($d); |
|
| 563 | - |
|
| 564 | - return join(',', $logos); |
|
| 547 | + $logos = array(); |
|
| 548 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 549 | + $type = '/' |
|
| 550 | + . type_du_logo($type) |
|
| 551 | + . "on(\d+)\.(" |
|
| 552 | + . join('|', $GLOBALS['formats_logos']) |
|
| 553 | + . ")$/"; |
|
| 554 | + |
|
| 555 | + if ($d = opendir(_DIR_LOGOS)) { |
|
| 556 | + while (($f = readdir($d)) !== false) { |
|
| 557 | + if (preg_match($type, $f, $r)) { |
|
| 558 | + $logos[] = $r[1]; |
|
| 559 | + } |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + @closedir($d); |
|
| 563 | + |
|
| 564 | + return join(',', $logos); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -577,14 +577,14 @@ discard block |
||
| 577 | 577 | * Code HTML des notes |
| 578 | 578 | **/ |
| 579 | 579 | function calculer_notes() { |
| 580 | - $r = ''; |
|
| 581 | - if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 582 | - $r = $notes(array()); |
|
| 583 | - $notes('', 'depiler'); |
|
| 584 | - $notes('', 'empiler'); |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - return $r; |
|
| 580 | + $r = ''; |
|
| 581 | + if ($notes = charger_fonction('notes', 'inc', true)) { |
|
| 582 | + $r = $notes(array()); |
|
| 583 | + $notes('', 'depiler'); |
|
| 584 | + $notes('', 'empiler'); |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + return $r; |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -607,27 +607,27 @@ discard block |
||
| 607 | 607 | * @return null; |
| 608 | 608 | **/ |
| 609 | 609 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 610 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 611 | - if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 612 | - and $lang_select !== 'oui' |
|
| 613 | - ) { |
|
| 614 | - $lang = $GLOBALS['spip_lang']; |
|
| 615 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 616 | - elseif (!strlen($lang)) { |
|
| 617 | - $lang = $GLOBALS['spip_lang']; |
|
| 618 | - } // Cas 3. l'objet est multilingue ! |
|
| 619 | - elseif ($lang_select !== 'oui' |
|
| 620 | - and strlen($titre) > 10 |
|
| 621 | - and strpos($titre, '<multi>') !== false |
|
| 622 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 623 | - ) { |
|
| 624 | - $lang = $GLOBALS['spip_lang']; |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 628 | - lang_select($lang); |
|
| 629 | - |
|
| 630 | - return; |
|
| 610 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 611 | + if (isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 612 | + and $lang_select !== 'oui' |
|
| 613 | + ) { |
|
| 614 | + $lang = $GLOBALS['spip_lang']; |
|
| 615 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 616 | + elseif (!strlen($lang)) { |
|
| 617 | + $lang = $GLOBALS['spip_lang']; |
|
| 618 | + } // Cas 3. l'objet est multilingue ! |
|
| 619 | + elseif ($lang_select !== 'oui' |
|
| 620 | + and strlen($titre) > 10 |
|
| 621 | + and strpos($titre, '<multi>') !== false |
|
| 622 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 623 | + ) { |
|
| 624 | + $lang = $GLOBALS['spip_lang']; |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 628 | + lang_select($lang); |
|
| 629 | + |
|
| 630 | + return; |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | |
@@ -635,21 +635,21 @@ discard block |
||
| 635 | 635 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 636 | 636 | // http://code.spip.net/@nettoyer_env_doublons |
| 637 | 637 | function nettoyer_env_doublons($envd) { |
| 638 | - foreach ($envd as $table => $liste) { |
|
| 639 | - $n = ''; |
|
| 640 | - foreach (explode(',', $liste) as $val) { |
|
| 641 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 642 | - $n .= ',' . $val; |
|
| 643 | - } |
|
| 644 | - } |
|
| 645 | - if (strlen($n)) { |
|
| 646 | - $envd[$table] = $n; |
|
| 647 | - } else { |
|
| 648 | - unset($envd[$table]); |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - return $envd; |
|
| 638 | + foreach ($envd as $table => $liste) { |
|
| 639 | + $n = ''; |
|
| 640 | + foreach (explode(',', $liste) as $val) { |
|
| 641 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 642 | + $n .= ',' . $val; |
|
| 643 | + } |
|
| 644 | + } |
|
| 645 | + if (strlen($n)) { |
|
| 646 | + $envd[$table] = $n; |
|
| 647 | + } else { |
|
| 648 | + unset($envd[$table]); |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + return $envd; |
|
| 653 | 653 | } |
| 654 | 654 | |
| 655 | 655 | /** |
@@ -668,21 +668,21 @@ discard block |
||
| 668 | 668 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 669 | 669 | **/ |
| 670 | 670 | function match_self($w) { |
| 671 | - if (is_string($w)) { |
|
| 672 | - return false; |
|
| 673 | - } |
|
| 674 | - if (is_array($w)) { |
|
| 675 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 676 | - return $w; |
|
| 677 | - } |
|
| 678 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 679 | - if ($m = match_self($sw)) { |
|
| 680 | - return $m; |
|
| 681 | - } |
|
| 682 | - } |
|
| 683 | - } |
|
| 684 | - |
|
| 685 | - return false; |
|
| 671 | + if (is_string($w)) { |
|
| 672 | + return false; |
|
| 673 | + } |
|
| 674 | + if (is_array($w)) { |
|
| 675 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 676 | + return $w; |
|
| 677 | + } |
|
| 678 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 679 | + if ($m = match_self($sw)) { |
|
| 680 | + return $m; |
|
| 681 | + } |
|
| 682 | + } |
|
| 683 | + } |
|
| 684 | + |
|
| 685 | + return false; |
|
| 686 | 686 | } |
| 687 | 687 | |
| 688 | 688 | /** |
@@ -698,16 +698,16 @@ discard block |
||
| 698 | 698 | * est remplacée par son code. |
| 699 | 699 | **/ |
| 700 | 700 | function remplace_sous_requete($w, $sousrequete) { |
| 701 | - if (is_array($w)) { |
|
| 702 | - if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 703 | - return $sousrequete; |
|
| 704 | - } |
|
| 705 | - foreach ($w as $k => $sw) { |
|
| 706 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 707 | - } |
|
| 708 | - } |
|
| 709 | - |
|
| 710 | - return $w; |
|
| 701 | + if (is_array($w)) { |
|
| 702 | + if (in_array(reset($w), array("SELF", "SUBSELECT"))) { |
|
| 703 | + return $sousrequete; |
|
| 704 | + } |
|
| 705 | + foreach ($w as $k => $sw) { |
|
| 706 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 707 | + } |
|
| 708 | + } |
|
| 709 | + |
|
| 710 | + return $w; |
|
| 711 | 711 | } |
| 712 | 712 | |
| 713 | 713 | /** |
@@ -721,17 +721,17 @@ discard block |
||
| 721 | 721 | * - Conditions avec des sous requêtes |
| 722 | 722 | **/ |
| 723 | 723 | function trouver_sous_requetes($where) { |
| 724 | - $where_simples = array(); |
|
| 725 | - $where_sous = array(); |
|
| 726 | - foreach ($where as $k => $w) { |
|
| 727 | - if (match_self($w)) { |
|
| 728 | - $where_sous[$k] = $w; |
|
| 729 | - } else { |
|
| 730 | - $where_simples[$k] = $w; |
|
| 731 | - } |
|
| 732 | - } |
|
| 733 | - |
|
| 734 | - return array($where_simples, $where_sous); |
|
| 724 | + $where_simples = array(); |
|
| 725 | + $where_sous = array(); |
|
| 726 | + foreach ($where as $k => $w) { |
|
| 727 | + if (match_self($w)) { |
|
| 728 | + $where_sous[$k] = $w; |
|
| 729 | + } else { |
|
| 730 | + $where_simples[$k] = $w; |
|
| 731 | + } |
|
| 732 | + } |
|
| 733 | + |
|
| 734 | + return array($where_simples, $where_sous); |
|
| 735 | 735 | } |
| 736 | 736 | |
| 737 | 737 | |
@@ -757,258 +757,258 @@ discard block |
||
| 757 | 757 | * @return resource |
| 758 | 758 | */ |
| 759 | 759 | function calculer_select( |
| 760 | - $select = array(), |
|
| 761 | - $from = array(), |
|
| 762 | - $from_type = array(), |
|
| 763 | - $where = array(), |
|
| 764 | - $join = array(), |
|
| 765 | - $groupby = array(), |
|
| 766 | - $orderby = array(), |
|
| 767 | - $limit = '', |
|
| 768 | - $having = array(), |
|
| 769 | - $table = '', |
|
| 770 | - $id = '', |
|
| 771 | - $serveur = '', |
|
| 772 | - $requeter = true |
|
| 760 | + $select = array(), |
|
| 761 | + $from = array(), |
|
| 762 | + $from_type = array(), |
|
| 763 | + $where = array(), |
|
| 764 | + $join = array(), |
|
| 765 | + $groupby = array(), |
|
| 766 | + $orderby = array(), |
|
| 767 | + $limit = '', |
|
| 768 | + $having = array(), |
|
| 769 | + $table = '', |
|
| 770 | + $id = '', |
|
| 771 | + $serveur = '', |
|
| 772 | + $requeter = true |
|
| 773 | 773 | ) { |
| 774 | 774 | |
| 775 | - // retirer les criteres vides: |
|
| 776 | - // {X ?} avec X absent de l'URL |
|
| 777 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 778 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 779 | - $menage = false; |
|
| 780 | - foreach ($where as $k => $v) { |
|
| 781 | - if (is_array($v)) { |
|
| 782 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 783 | - $op = false; |
|
| 784 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 785 | - $op = false; |
|
| 786 | - } else { |
|
| 787 | - $op = $v[0] ? $v[0] : $v; |
|
| 788 | - } |
|
| 789 | - } else { |
|
| 790 | - $op = $v; |
|
| 791 | - } |
|
| 792 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 793 | - unset($where[$k]); |
|
| 794 | - $menage = true; |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 799 | - $groupby = array_diff($groupby, array('')); |
|
| 800 | - |
|
| 801 | - // remplacer les sous requetes recursives au calcul |
|
| 802 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 803 | - foreach ($where_sous as $k => $w) { |
|
| 804 | - $menage = true; |
|
| 805 | - // on recupere la sous requete |
|
| 806 | - $sous = match_self($w); |
|
| 807 | - if ($sous[0] == 'SELF') { |
|
| 808 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 809 | - array_push($where_simples, $sous[2]); |
|
| 810 | - $wheresub = array( |
|
| 811 | - $sous[2], |
|
| 812 | - '0=0' |
|
| 813 | - ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 814 | - $jsub = $join; |
|
| 815 | - // trouver les jointures utiles a |
|
| 816 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 817 | - // ie L1.objet='article' |
|
| 818 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 819 | - $i = 0; |
|
| 820 | - do { |
|
| 821 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 822 | - array($sous[1] . " AS id"), |
|
| 823 | - $from, |
|
| 824 | - $from_type, |
|
| 825 | - $wheresub, |
|
| 826 | - $jsub, |
|
| 827 | - array(), array(), '', |
|
| 828 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 829 | - if (!$i) { |
|
| 830 | - $i = 1; |
|
| 831 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 832 | - foreach ($join as $cle => $wj) { |
|
| 833 | - if (count($wj) == 4 |
|
| 834 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 835 | - ) { |
|
| 836 | - $i = 0; |
|
| 837 | - $wheresub[] = $wj[3]; |
|
| 838 | - unset($jsub[$cle][3]); |
|
| 839 | - } |
|
| 840 | - } |
|
| 841 | - } |
|
| 842 | - } while ($i++ < 1); |
|
| 843 | - } |
|
| 844 | - if ($sous[0] == 'SUBSELECT') { |
|
| 845 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 846 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 847 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 848 | - $sous[1], # select |
|
| 849 | - $sous[2], #from |
|
| 850 | - array(), #from_type |
|
| 851 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 852 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 853 | - array(), #join |
|
| 854 | - $sous[4] ? $sous[4] : array(), #groupby |
|
| 855 | - $sous[5] ? $sous[5] : array(), #orderby |
|
| 856 | - $sous[6], #limit |
|
| 857 | - $sous[7] ? $sous[7] : array(), #having |
|
| 858 | - $table, $id, $serveur, false |
|
| 859 | - ) . ")"); |
|
| 860 | - } |
|
| 861 | - array_pop($where_simples); |
|
| 862 | - } |
|
| 863 | - |
|
| 864 | - foreach ($having as $k => $v) { |
|
| 865 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 866 | - unset($having[$k]); |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - |
|
| 870 | - // Installer les jointures. |
|
| 871 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 872 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 873 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 874 | - |
|
| 875 | - $afrom = array(); |
|
| 876 | - $equiv = array(); |
|
| 877 | - $k = count($join); |
|
| 878 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 879 | - $cle = $cledef; |
|
| 880 | - // le format de join est : |
|
| 881 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 882 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 883 | - if (count($join[$cle]) == 2) { |
|
| 884 | - $join[$cle][] = $join[$cle][1]; |
|
| 885 | - } |
|
| 886 | - if (count($join[$cle]) == 3) { |
|
| 887 | - $join[$cle][] = ''; |
|
| 888 | - } |
|
| 889 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 890 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 891 | - // pour compat avec ancienne convention |
|
| 892 | - if (is_numeric($cle)) { |
|
| 893 | - $cle = "L$k"; |
|
| 894 | - } |
|
| 895 | - if (!$menage |
|
| 896 | - or isset($afrom[$cle]) |
|
| 897 | - or calculer_jointnul($cle, $select) |
|
| 898 | - or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 899 | - or calculer_jointnul($cle, $having) |
|
| 900 | - or calculer_jointnul($cle, $where_simples) |
|
| 901 | - ) { |
|
| 902 | - // corriger les references non explicites dans select |
|
| 903 | - // ou groupby |
|
| 904 | - foreach ($select as $i => $s) { |
|
| 905 | - if ($s == $c) { |
|
| 906 | - $select[$i] = "$cle.$c AS $c"; |
|
| 907 | - break; |
|
| 908 | - } |
|
| 909 | - } |
|
| 910 | - foreach ($groupby as $i => $g) { |
|
| 911 | - if ($g == $c) { |
|
| 912 | - $groupby[$i] = "$cle.$c"; |
|
| 913 | - break; |
|
| 914 | - } |
|
| 915 | - } |
|
| 916 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 917 | - // sans recours a preg_match |
|
| 918 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 919 | - $afrom[$t][$cle] = array( |
|
| 920 | - "\n" . |
|
| 921 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 922 | - $from[$cle], |
|
| 923 | - "AS $cle", |
|
| 924 | - "ON (", |
|
| 925 | - "$cle.$c", |
|
| 926 | - "=", |
|
| 927 | - "$t.$carr", |
|
| 928 | - ($and ? "AND " . $and : "") . |
|
| 929 | - ")" |
|
| 930 | - ); |
|
| 931 | - if (isset($afrom[$cle])) { |
|
| 932 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 933 | - unset($afrom[$cle]); |
|
| 934 | - } |
|
| 935 | - $equiv[] = $carr; |
|
| 936 | - } else { |
|
| 937 | - unset($join[$cledef]); |
|
| 938 | - } |
|
| 939 | - unset($from[$cle]); |
|
| 940 | - $k--; |
|
| 941 | - } |
|
| 942 | - |
|
| 943 | - if (count($afrom)) { |
|
| 944 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 945 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 946 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 947 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 948 | - // ou dans |
|
| 949 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 950 | - // qui comporte plusieurs jointures |
|
| 951 | - // ou dans |
|
| 952 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 953 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 954 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 955 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 956 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 957 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 958 | - |
|
| 959 | - $t = key($from); |
|
| 960 | - $c = current($from); |
|
| 961 | - reset($from); |
|
| 962 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 963 | - if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 964 | - calculer_jointnul($t, $select, $e) or |
|
| 965 | - calculer_jointnul($t, $join, $e) or |
|
| 966 | - calculer_jointnul($t, $where, $e) or |
|
| 967 | - calculer_jointnul($t, $orderby, $e) or |
|
| 968 | - calculer_jointnul($t, $groupby, $e) or |
|
| 969 | - calculer_jointnul($t, $having, $e)) |
|
| 970 | - && count($afrom[$t]) |
|
| 971 | - ) { |
|
| 972 | - $nfrom = reset($afrom[$t]); |
|
| 973 | - $nt = key($afrom[$t]); |
|
| 974 | - unset($from[$t]); |
|
| 975 | - $from[$nt] = $nfrom[1]; |
|
| 976 | - unset($afrom[$t][$nt]); |
|
| 977 | - $afrom[$nt] = $afrom[$t]; |
|
| 978 | - unset($afrom[$t]); |
|
| 979 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 980 | - $t = $nfrom[4]; |
|
| 981 | - $alias = ""; |
|
| 982 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 983 | - $oldcle = explode('.', $nfrom[6]); |
|
| 984 | - $oldcle = end($oldcle); |
|
| 985 | - $newcle = explode('.', $nfrom[4]); |
|
| 986 | - $newcle = end($newcle); |
|
| 987 | - if ($newcle != $oldcle) { |
|
| 988 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 989 | - // reprendre simplement ce AS |
|
| 990 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 991 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 992 | - $alias = ""; |
|
| 993 | - } else { |
|
| 994 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 998 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 999 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 1000 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 1001 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 1002 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 1003 | - } |
|
| 1004 | - $from = reinjecte_joint($afrom, $from); |
|
| 1005 | - } |
|
| 1006 | - $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 1007 | - $r = sql_select($select, $from, $where, |
|
| 1008 | - $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 1009 | - unset($GLOBALS['debug']['aucasou']); |
|
| 1010 | - |
|
| 1011 | - return $r; |
|
| 775 | + // retirer les criteres vides: |
|
| 776 | + // {X ?} avec X absent de l'URL |
|
| 777 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 778 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 779 | + $menage = false; |
|
| 780 | + foreach ($where as $k => $v) { |
|
| 781 | + if (is_array($v)) { |
|
| 782 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 783 | + $op = false; |
|
| 784 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 785 | + $op = false; |
|
| 786 | + } else { |
|
| 787 | + $op = $v[0] ? $v[0] : $v; |
|
| 788 | + } |
|
| 789 | + } else { |
|
| 790 | + $op = $v; |
|
| 791 | + } |
|
| 792 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 793 | + unset($where[$k]); |
|
| 794 | + $menage = true; |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 799 | + $groupby = array_diff($groupby, array('')); |
|
| 800 | + |
|
| 801 | + // remplacer les sous requetes recursives au calcul |
|
| 802 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 803 | + foreach ($where_sous as $k => $w) { |
|
| 804 | + $menage = true; |
|
| 805 | + // on recupere la sous requete |
|
| 806 | + $sous = match_self($w); |
|
| 807 | + if ($sous[0] == 'SELF') { |
|
| 808 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 809 | + array_push($where_simples, $sous[2]); |
|
| 810 | + $wheresub = array( |
|
| 811 | + $sous[2], |
|
| 812 | + '0=0' |
|
| 813 | + ); // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 814 | + $jsub = $join; |
|
| 815 | + // trouver les jointures utiles a |
|
| 816 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 817 | + // ie L1.objet='article' |
|
| 818 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 819 | + $i = 0; |
|
| 820 | + do { |
|
| 821 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 822 | + array($sous[1] . " AS id"), |
|
| 823 | + $from, |
|
| 824 | + $from_type, |
|
| 825 | + $wheresub, |
|
| 826 | + $jsub, |
|
| 827 | + array(), array(), '', |
|
| 828 | + $having, $table, $id, $serveur, false) . ")"); |
|
| 829 | + if (!$i) { |
|
| 830 | + $i = 1; |
|
| 831 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 832 | + foreach ($join as $cle => $wj) { |
|
| 833 | + if (count($wj) == 4 |
|
| 834 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 835 | + ) { |
|
| 836 | + $i = 0; |
|
| 837 | + $wheresub[] = $wj[3]; |
|
| 838 | + unset($jsub[$cle][3]); |
|
| 839 | + } |
|
| 840 | + } |
|
| 841 | + } |
|
| 842 | + } while ($i++ < 1); |
|
| 843 | + } |
|
| 844 | + if ($sous[0] == 'SUBSELECT') { |
|
| 845 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 846 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 847 | + $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 848 | + $sous[1], # select |
|
| 849 | + $sous[2], #from |
|
| 850 | + array(), #from_type |
|
| 851 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : array($sous[3])) : array(), |
|
| 852 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 853 | + array(), #join |
|
| 854 | + $sous[4] ? $sous[4] : array(), #groupby |
|
| 855 | + $sous[5] ? $sous[5] : array(), #orderby |
|
| 856 | + $sous[6], #limit |
|
| 857 | + $sous[7] ? $sous[7] : array(), #having |
|
| 858 | + $table, $id, $serveur, false |
|
| 859 | + ) . ")"); |
|
| 860 | + } |
|
| 861 | + array_pop($where_simples); |
|
| 862 | + } |
|
| 863 | + |
|
| 864 | + foreach ($having as $k => $v) { |
|
| 865 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 866 | + unset($having[$k]); |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + |
|
| 870 | + // Installer les jointures. |
|
| 871 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 872 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 873 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 874 | + |
|
| 875 | + $afrom = array(); |
|
| 876 | + $equiv = array(); |
|
| 877 | + $k = count($join); |
|
| 878 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 879 | + $cle = $cledef; |
|
| 880 | + // le format de join est : |
|
| 881 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 882 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 883 | + if (count($join[$cle]) == 2) { |
|
| 884 | + $join[$cle][] = $join[$cle][1]; |
|
| 885 | + } |
|
| 886 | + if (count($join[$cle]) == 3) { |
|
| 887 | + $join[$cle][] = ''; |
|
| 888 | + } |
|
| 889 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 890 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 891 | + // pour compat avec ancienne convention |
|
| 892 | + if (is_numeric($cle)) { |
|
| 893 | + $cle = "L$k"; |
|
| 894 | + } |
|
| 895 | + if (!$menage |
|
| 896 | + or isset($afrom[$cle]) |
|
| 897 | + or calculer_jointnul($cle, $select) |
|
| 898 | + or calculer_jointnul($cle, array_diff_key($join, array($cle => $join[$cle]))) |
|
| 899 | + or calculer_jointnul($cle, $having) |
|
| 900 | + or calculer_jointnul($cle, $where_simples) |
|
| 901 | + ) { |
|
| 902 | + // corriger les references non explicites dans select |
|
| 903 | + // ou groupby |
|
| 904 | + foreach ($select as $i => $s) { |
|
| 905 | + if ($s == $c) { |
|
| 906 | + $select[$i] = "$cle.$c AS $c"; |
|
| 907 | + break; |
|
| 908 | + } |
|
| 909 | + } |
|
| 910 | + foreach ($groupby as $i => $g) { |
|
| 911 | + if ($g == $c) { |
|
| 912 | + $groupby[$i] = "$cle.$c"; |
|
| 913 | + break; |
|
| 914 | + } |
|
| 915 | + } |
|
| 916 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 917 | + // sans recours a preg_match |
|
| 918 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 919 | + $afrom[$t][$cle] = array( |
|
| 920 | + "\n" . |
|
| 921 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 922 | + $from[$cle], |
|
| 923 | + "AS $cle", |
|
| 924 | + "ON (", |
|
| 925 | + "$cle.$c", |
|
| 926 | + "=", |
|
| 927 | + "$t.$carr", |
|
| 928 | + ($and ? "AND " . $and : "") . |
|
| 929 | + ")" |
|
| 930 | + ); |
|
| 931 | + if (isset($afrom[$cle])) { |
|
| 932 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 933 | + unset($afrom[$cle]); |
|
| 934 | + } |
|
| 935 | + $equiv[] = $carr; |
|
| 936 | + } else { |
|
| 937 | + unset($join[$cledef]); |
|
| 938 | + } |
|
| 939 | + unset($from[$cle]); |
|
| 940 | + $k--; |
|
| 941 | + } |
|
| 942 | + |
|
| 943 | + if (count($afrom)) { |
|
| 944 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 945 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 946 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 947 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 948 | + // ou dans |
|
| 949 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 950 | + // qui comporte plusieurs jointures |
|
| 951 | + // ou dans |
|
| 952 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 953 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 954 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 955 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 956 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 957 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 958 | + |
|
| 959 | + $t = key($from); |
|
| 960 | + $c = current($from); |
|
| 961 | + reset($from); |
|
| 962 | + $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 963 | + if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 964 | + calculer_jointnul($t, $select, $e) or |
|
| 965 | + calculer_jointnul($t, $join, $e) or |
|
| 966 | + calculer_jointnul($t, $where, $e) or |
|
| 967 | + calculer_jointnul($t, $orderby, $e) or |
|
| 968 | + calculer_jointnul($t, $groupby, $e) or |
|
| 969 | + calculer_jointnul($t, $having, $e)) |
|
| 970 | + && count($afrom[$t]) |
|
| 971 | + ) { |
|
| 972 | + $nfrom = reset($afrom[$t]); |
|
| 973 | + $nt = key($afrom[$t]); |
|
| 974 | + unset($from[$t]); |
|
| 975 | + $from[$nt] = $nfrom[1]; |
|
| 976 | + unset($afrom[$t][$nt]); |
|
| 977 | + $afrom[$nt] = $afrom[$t]; |
|
| 978 | + unset($afrom[$t]); |
|
| 979 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 980 | + $t = $nfrom[4]; |
|
| 981 | + $alias = ""; |
|
| 982 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 983 | + $oldcle = explode('.', $nfrom[6]); |
|
| 984 | + $oldcle = end($oldcle); |
|
| 985 | + $newcle = explode('.', $nfrom[4]); |
|
| 986 | + $newcle = end($newcle); |
|
| 987 | + if ($newcle != $oldcle) { |
|
| 988 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 989 | + // reprendre simplement ce AS |
|
| 990 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 991 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 992 | + $alias = ""; |
|
| 993 | + } else { |
|
| 994 | + $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 998 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 999 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 1000 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 1001 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 1002 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 1003 | + } |
|
| 1004 | + $from = reinjecte_joint($afrom, $from); |
|
| 1005 | + } |
|
| 1006 | + $GLOBALS['debug']['aucasou'] = array($table, $id, $serveur, $requeter); |
|
| 1007 | + $r = sql_select($select, $from, $where, |
|
| 1008 | + $groupby, array_filter($orderby), $limit, $having, $serveur, $requeter); |
|
| 1009 | + unset($GLOBALS['debug']['aucasou']); |
|
| 1010 | + |
|
| 1011 | + return $r; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1019,20 +1019,20 @@ discard block |
||
| 1019 | 1019 | * @return string |
| 1020 | 1020 | */ |
| 1021 | 1021 | function calculer_where_to_string($v, $join = 'AND') { |
| 1022 | - if (empty($v)) { |
|
| 1023 | - return ''; |
|
| 1024 | - } |
|
| 1025 | - |
|
| 1026 | - if (!is_array($v)) { |
|
| 1027 | - return $v; |
|
| 1028 | - } else { |
|
| 1029 | - $exp = ""; |
|
| 1030 | - if (strtoupper($join) === 'AND') { |
|
| 1031 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1032 | - } else { |
|
| 1033 | - return $exp . join($join, $v); |
|
| 1034 | - } |
|
| 1035 | - } |
|
| 1022 | + if (empty($v)) { |
|
| 1023 | + return ''; |
|
| 1024 | + } |
|
| 1025 | + |
|
| 1026 | + if (!is_array($v)) { |
|
| 1027 | + return $v; |
|
| 1028 | + } else { |
|
| 1029 | + $exp = ""; |
|
| 1030 | + if (strtoupper($join) === 'AND') { |
|
| 1031 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1032 | + } else { |
|
| 1033 | + return $exp . join($join, $v); |
|
| 1034 | + } |
|
| 1035 | + } |
|
| 1036 | 1036 | } |
| 1037 | 1037 | |
| 1038 | 1038 | |
@@ -1040,62 +1040,62 @@ discard block |
||
| 1040 | 1040 | |
| 1041 | 1041 | // http://code.spip.net/@calculer_jointnul |
| 1042 | 1042 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1043 | - if (!is_array($exp)) { |
|
| 1044 | - if ($equiv) { |
|
| 1045 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1049 | - } else { |
|
| 1050 | - foreach ($exp as $v) { |
|
| 1051 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1052 | - return true; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - |
|
| 1056 | - return false; |
|
| 1057 | - } |
|
| 1043 | + if (!is_array($exp)) { |
|
| 1044 | + if ($equiv) { |
|
| 1045 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1049 | + } else { |
|
| 1050 | + foreach ($exp as $v) { |
|
| 1051 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1052 | + return true; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + |
|
| 1056 | + return false; |
|
| 1057 | + } |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | // http://code.spip.net/@reinjecte_joint |
| 1061 | 1061 | function reinjecte_joint($afrom, $from) { |
| 1062 | - $from_synth = array(); |
|
| 1063 | - foreach ($from as $k => $v) { |
|
| 1064 | - $from_synth[$k] = $from[$k]; |
|
| 1065 | - if (isset($afrom[$k])) { |
|
| 1066 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1067 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1068 | - } |
|
| 1069 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1070 | - unset($afrom[$k]); |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - return $from_synth; |
|
| 1062 | + $from_synth = array(); |
|
| 1063 | + foreach ($from as $k => $v) { |
|
| 1064 | + $from_synth[$k] = $from[$k]; |
|
| 1065 | + if (isset($afrom[$k])) { |
|
| 1066 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1067 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1068 | + } |
|
| 1069 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1070 | + unset($afrom[$k]); |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + return $from_synth; |
|
| 1075 | 1075 | } |
| 1076 | 1076 | |
| 1077 | 1077 | // http://code.spip.net/@remplacer_jointnul |
| 1078 | 1078 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1079 | - if (!is_array($exp)) { |
|
| 1080 | - return preg_replace($equiv, $cle, $exp); |
|
| 1081 | - } else { |
|
| 1082 | - foreach ($exp as $k => $v) { |
|
| 1083 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1084 | - } |
|
| 1085 | - |
|
| 1086 | - return $exp; |
|
| 1087 | - } |
|
| 1079 | + if (!is_array($exp)) { |
|
| 1080 | + return preg_replace($equiv, $cle, $exp); |
|
| 1081 | + } else { |
|
| 1082 | + foreach ($exp as $k => $v) { |
|
| 1083 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1084 | + } |
|
| 1085 | + |
|
| 1086 | + return $exp; |
|
| 1087 | + } |
|
| 1088 | 1088 | } |
| 1089 | 1089 | |
| 1090 | 1090 | // calcul du nom du squelette |
| 1091 | 1091 | // http://code.spip.net/@calculer_nom_fonction_squel |
| 1092 | 1092 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1093 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1094 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1095 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1096 | - } |
|
| 1097 | - |
|
| 1098 | - return $mime_type |
|
| 1099 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1100 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1093 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1094 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1095 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1096 | + } |
|
| 1097 | + |
|
| 1098 | + return $mime_type |
|
| 1099 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1100 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1101 | 1101 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 54 | 54 | } |
| 55 | 55 | |
| 56 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 56 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 57 | 57 | |
| 58 | 58 | // si squelette est deja compile et perenne, le charger |
| 59 | 59 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | #} |
| 67 | 67 | } |
| 68 | 68 | |
| 69 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 69 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 70 | 70 | include_once $lib; |
| 71 | 71 | } |
| 72 | 72 | |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
| 83 | 83 | } |
| 84 | 84 | else |
| 85 | - $skel_code=''; |
|
| 85 | + $skel_code = ''; |
|
| 86 | 86 | |
| 87 | 87 | // Ne plus rien faire si le compilateur n'a pas pu operer. |
| 88 | 88 | if (!$skel_code) { |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 122 | 122 | |
| 123 | 123 | // Tracer ce qui vient d'etre compile |
| 124 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 124 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 125 | 125 | |
| 126 | 126 | // si c'est ce que demande le debusqueur, lui passer la main |
| 127 | 127 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -143,13 +143,13 @@ discard block |
||
| 143 | 143 | $code = " |
| 144 | 144 | /* |
| 145 | 145 | * Squelette : $sourcefile |
| 146 | - * Date : " . gmdate("D, d M Y H:i:s", @filemtime($sourcefile)) . " GMT |
|
| 147 | - * Compile : " . gmdate("D, d M Y H:i:s", time()) . " GMT |
|
| 148 | - * " . (!$boucles ? "Pas de boucle" : ("Boucles : " . $noms)) . " |
|
| 146 | + * Date : ".gmdate("D, d M Y H:i:s", @filemtime($sourcefile))." GMT |
|
| 147 | + * Compile : " . gmdate("D, d M Y H:i:s", time())." GMT |
|
| 148 | + * " . (!$boucles ? "Pas de boucle" : ("Boucles : ".$noms))." |
|
| 149 | 149 | */ "; |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 152 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 153 | 153 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 154 | 154 | ecrire_fichier($phpfile, $code); |
| 155 | 155 | } |
@@ -209,7 +209,7 @@ discard block |
||
| 209 | 209 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 210 | 210 | |
| 211 | 211 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 212 | - $headers[$j] .= "|" . $r[3]; |
|
| 212 | + $headers[$j] .= "|".$r[3]; |
|
| 213 | 213 | } else { |
| 214 | 214 | $headers[$j] = $r[3]; |
| 215 | 215 | } |
@@ -217,10 +217,10 @@ discard block |
||
| 217 | 217 | } |
| 218 | 218 | // S'agit-il d'un resultat constant ou contenant du code php |
| 219 | 219 | $process_ins = ( |
| 220 | - strpos($corps, '<' . '?') === false |
|
| 220 | + strpos($corps, '<'.'?') === false |
|
| 221 | 221 | or |
| 222 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 223 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 222 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 223 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 224 | 224 | ) |
| 225 | 225 | ? 'html' |
| 226 | 226 | : 'php'; |
@@ -246,10 +246,10 @@ discard block |
||
| 246 | 246 | |
| 247 | 247 | if ($process_ins == 'html') { |
| 248 | 248 | $skel['process_ins'] = ( |
| 249 | - strpos($corps, '<' . '?') === false |
|
| 249 | + strpos($corps, '<'.'?') === false |
|
| 250 | 250 | or |
| 251 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 252 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 251 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 252 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 253 | 253 | ) |
| 254 | 254 | ? 'html' |
| 255 | 255 | : 'php'; |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | if (strlen($intro)) { |
| 328 | 328 | $texte = $intro; |
| 329 | 329 | } else { |
| 330 | - if (strpos("\n" . $texte, "\n|") === false |
|
| 330 | + if (strpos("\n".$texte, "\n|") === false |
|
| 331 | 331 | and strlen($texte) > 2.5 * $longueur |
| 332 | 332 | ) { |
| 333 | 333 | if (strpos($texte, "<multi") !== false) { |
@@ -372,7 +372,7 @@ discard block |
||
| 372 | 372 | // |
| 373 | 373 | |
| 374 | 374 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 375 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 375 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 376 | 376 | include_once("%s"); |
| 377 | 377 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 378 | 378 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -399,7 +399,7 @@ discard block |
||
| 399 | 399 | **/ |
| 400 | 400 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 401 | 401 | if (strncmp($file, "/", 1) !== 0) { |
| 402 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 402 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 403 | 403 | } |
| 404 | 404 | $r = sprintf(CODE_INCLURE_BALISE, |
| 405 | 405 | $file, |
@@ -427,14 +427,14 @@ discard block |
||
| 427 | 427 | function argumenter_squelette($v) { |
| 428 | 428 | |
| 429 | 429 | if (!is_array($v)) { |
| 430 | - return "'" . texte_script($v) . "'"; |
|
| 430 | + return "'".texte_script($v)."'"; |
|
| 431 | 431 | } else { |
| 432 | 432 | $out = array(); |
| 433 | 433 | foreach ($v as $k => $val) { |
| 434 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 434 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 435 | 435 | } |
| 436 | 436 | |
| 437 | - return 'array(' . join(", ", $out) . ')'; |
|
| 437 | + return 'array('.join(", ", $out).')'; |
|
| 438 | 438 | } |
| 439 | 439 | } |
| 440 | 440 | |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | // Y a-t-il une fonction de traitement des arguments ? |
| 502 | - $f = 'balise_' . $nomfonction . '_stat'; |
|
| 502 | + $f = 'balise_'.$nomfonction.'_stat'; |
|
| 503 | 503 | |
| 504 | 504 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 505 | 505 | |
@@ -509,16 +509,16 @@ discard block |
||
| 509 | 509 | |
| 510 | 510 | // verifier que la fonction dyn est la, |
| 511 | 511 | // sinon se replier sur la generique si elle existe |
| 512 | - if (!function_exists('balise_' . $nomfonction . '_dyn')) { |
|
| 512 | + if (!function_exists('balise_'.$nomfonction.'_dyn')) { |
|
| 513 | 513 | if ($nomfonction_generique |
| 514 | - and $file = include_spip("balise/" . strtolower($nomfonction_generique)) |
|
| 515 | - and function_exists('balise_' . $nomfonction_generique . '_dyn') |
|
| 514 | + and $file = include_spip("balise/".strtolower($nomfonction_generique)) |
|
| 515 | + and function_exists('balise_'.$nomfonction_generique.'_dyn') |
|
| 516 | 516 | ) { |
| 517 | 517 | // et lui injecter en premier arg le nom de la balise |
| 518 | 518 | array_unshift($r, $nom); |
| 519 | 519 | $nomfonction = $nomfonction_generique; |
| 520 | 520 | if (!_DIR_RESTREINT) { |
| 521 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 521 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 522 | 522 | } |
| 523 | 523 | } else { |
| 524 | 524 | $msg = array('zbug_balise_inexistante', array('from' => 'CVT', 'balise' => $nom)); |
@@ -639,7 +639,7 @@ discard block |
||
| 639 | 639 | $n = ''; |
| 640 | 640 | foreach (explode(',', $liste) as $val) { |
| 641 | 641 | if ($a = intval($val) and $val === strval($a)) { |
| 642 | - $n .= ',' . $val; |
|
| 642 | + $n .= ','.$val; |
|
| 643 | 643 | } |
| 644 | 644 | } |
| 645 | 645 | if (strlen($n)) { |
@@ -818,14 +818,14 @@ discard block |
||
| 818 | 818 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 819 | 819 | $i = 0; |
| 820 | 820 | do { |
| 821 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 822 | - array($sous[1] . " AS id"), |
|
| 821 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 822 | + array($sous[1]." AS id"), |
|
| 823 | 823 | $from, |
| 824 | 824 | $from_type, |
| 825 | 825 | $wheresub, |
| 826 | 826 | $jsub, |
| 827 | 827 | array(), array(), '', |
| 828 | - $having, $table, $id, $serveur, false) . ")"); |
|
| 828 | + $having, $table, $id, $serveur, false).")"); |
|
| 829 | 829 | if (!$i) { |
| 830 | 830 | $i = 1; |
| 831 | 831 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -844,7 +844,7 @@ discard block |
||
| 844 | 844 | if ($sous[0] == 'SUBSELECT') { |
| 845 | 845 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 846 | 846 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 847 | - $where[$k] = remplace_sous_requete($w, "(" . calculer_select( |
|
| 847 | + $where[$k] = remplace_sous_requete($w, "(".calculer_select( |
|
| 848 | 848 | $sous[1], # select |
| 849 | 849 | $sous[2], #from |
| 850 | 850 | array(), #from_type |
@@ -856,7 +856,7 @@ discard block |
||
| 856 | 856 | $sous[6], #limit |
| 857 | 857 | $sous[7] ? $sous[7] : array(), #having |
| 858 | 858 | $table, $id, $serveur, false |
| 859 | - ) . ")"); |
|
| 859 | + ).")"); |
|
| 860 | 860 | } |
| 861 | 861 | array_pop($where_simples); |
| 862 | 862 | } |
@@ -917,15 +917,15 @@ discard block |
||
| 917 | 917 | // sans recours a preg_match |
| 918 | 918 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 919 | 919 | $afrom[$t][$cle] = array( |
| 920 | - "\n" . |
|
| 921 | - (isset($from_type[$cle]) ? $from_type[$cle] : "INNER") . " JOIN", |
|
| 920 | + "\n". |
|
| 921 | + (isset($from_type[$cle]) ? $from_type[$cle] : "INNER")." JOIN", |
|
| 922 | 922 | $from[$cle], |
| 923 | 923 | "AS $cle", |
| 924 | 924 | "ON (", |
| 925 | 925 | "$cle.$c", |
| 926 | 926 | "=", |
| 927 | 927 | "$t.$carr", |
| 928 | - ($and ? "AND " . $and : "") . |
|
| 928 | + ($and ? "AND ".$and : ""). |
|
| 929 | 929 | ")" |
| 930 | 930 | ); |
| 931 | 931 | if (isset($afrom[$cle])) { |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | $t = key($from); |
| 960 | 960 | $c = current($from); |
| 961 | 961 | reset($from); |
| 962 | - $e = '/\b(' . "$t\\." . join("|" . $t . '\.', $equiv) . ')\b/'; |
|
| 962 | + $e = '/\b('."$t\\.".join("|".$t.'\.', $equiv).')\b/'; |
|
| 963 | 963 | if (!(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 964 | 964 | calculer_jointnul($t, $select, $e) or |
| 965 | 965 | calculer_jointnul($t, $join, $e) or |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | unset($afrom[$t][$nt]); |
| 977 | 977 | $afrom[$nt] = $afrom[$t]; |
| 978 | 978 | unset($afrom[$t]); |
| 979 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 979 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 980 | 980 | $t = $nfrom[4]; |
| 981 | 981 | $alias = ""; |
| 982 | 982 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -987,14 +987,14 @@ discard block |
||
| 987 | 987 | if ($newcle != $oldcle) { |
| 988 | 988 | // si l'ancienne cle etait deja dans le select avec un AS |
| 989 | 989 | // reprendre simplement ce AS |
| 990 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 990 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 991 | 991 | if (preg_match($as, implode(',', $select), $m)) { |
| 992 | 992 | $alias = ""; |
| 993 | 993 | } else { |
| 994 | - $alias = ", " . $nfrom[4] . " AS $oldcle"; |
|
| 994 | + $alias = ", ".$nfrom[4]." AS $oldcle"; |
|
| 995 | 995 | } |
| 996 | 996 | } |
| 997 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 997 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 998 | 998 | $join = remplacer_jointnul($t, $join, $e); |
| 999 | 999 | $where = remplacer_jointnul($t, $where, $e); |
| 1000 | 1000 | $having = remplacer_jointnul($t, $having, $e); |
@@ -1028,9 +1028,9 @@ discard block |
||
| 1028 | 1028 | } else { |
| 1029 | 1029 | $exp = ""; |
| 1030 | 1030 | if (strtoupper($join) === 'AND') { |
| 1031 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1031 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1032 | 1032 | } else { |
| 1033 | - return $exp . join($join, $v); |
|
| 1033 | + return $exp.join($join, $v); |
|
| 1034 | 1034 | } |
| 1035 | 1035 | } |
| 1036 | 1036 | } |
@@ -1096,6 +1096,6 @@ discard block |
||
| 1096 | 1096 | } |
| 1097 | 1097 | |
| 1098 | 1098 | return $mime_type |
| 1099 | - . (!$connect ? '' : preg_replace('/\W/', "_", $connect)) . '_' |
|
| 1100 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1099 | + . (!$connect ? '' : preg_replace('/\W/', "_", $connect)).'_' |
|
| 1100 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1101 | 1101 | } |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | if (lire_fichier($source, $skel)) { |
| 81 | 81 | $compiler = charger_fonction('compiler', 'public'); |
| 82 | 82 | $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
| 83 | + } else { |
|
| 84 | + $skel_code=''; |
|
| 83 | 85 | } |
| 84 | - else |
|
| 85 | - $skel_code=''; |
|
| 86 | 86 | |
| 87 | 87 | // Ne plus rien faire si le compilateur n'a pas pu operer. |
| 88 | 88 | if (!$skel_code) { |
@@ -359,10 +359,12 @@ discard block |
||
| 359 | 359 | |
| 360 | 360 | // et reparagrapher si necessaire (coherence avec le cas descriptif) |
| 361 | 361 | // une introduction a tojours un <p> |
| 362 | - if ($GLOBALS['toujours_paragrapher']) // Fermer les paragraphes |
|
| 362 | + if ($GLOBALS['toujours_paragrapher']) { |
|
| 363 | + // Fermer les paragraphes |
|
| 363 | 364 | { |
| 364 | 365 | $texte = paragrapher($texte, $GLOBALS['toujours_paragrapher']); |
| 365 | 366 | } |
| 367 | + } |
|
| 366 | 368 | |
| 367 | 369 | return $texte; |
| 368 | 370 | } |
@@ -661,6 +661,11 @@ discard block |
||
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | +/** |
|
| 665 | + * @param string $idb |
|
| 666 | + * |
|
| 667 | + * @return string |
|
| 668 | + */ |
|
| 664 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | 670 | $boucle = $boucles[$idb]; |
| 666 | 671 | $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
@@ -1509,6 +1514,10 @@ discard block |
||
| 1509 | 1514 | } |
| 1510 | 1515 | |
| 1511 | 1516 | // http://code.spip.net/@critere_IN_cas |
| 1517 | +/** |
|
| 1518 | + * @param string $idb |
|
| 1519 | + * @param string $crit2 |
|
| 1520 | + */ |
|
| 1512 | 1521 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1513 | 1522 | static $num = array(); |
| 1514 | 1523 | $descr = $boucles[$idb]->descr; |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | + 'id_parent'; |
|
| 51 | 51 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 52 | + $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 53 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
@@ -67,15 +67,15 @@ discard block |
||
| 67 | 67 | * @return void |
| 68 | 68 | **/ |
| 69 | 69 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 70 | - $not = $crit->not; |
|
| 71 | - $boucle = &$boucles[$idb]; |
|
| 72 | - $id = $boucle->primary; |
|
| 73 | - |
|
| 74 | - if ($not or !$id) { |
|
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | - } |
|
| 77 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 70 | + $not = $crit->not; |
|
| 71 | + $boucle = &$boucles[$idb]; |
|
| 72 | + $id = $boucle->primary; |
|
| 73 | + |
|
| 74 | + if ($not or !$id) { |
|
| 75 | + return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 76 | + } |
|
| 77 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 78 | + $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -95,73 +95,73 @@ discard block |
||
| 95 | 95 | * @return void |
| 96 | 96 | **/ |
| 97 | 97 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 98 | - $boucle = &$boucles[$idb]; |
|
| 99 | - $primary = $boucle->primary; |
|
| 100 | - |
|
| 101 | - // la table nécessite une clé primaire, non composée |
|
| 102 | - if (!$primary or strpos($primary, ',')) { |
|
| 103 | - return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | - |
|
| 108 | - // le doublon s'applique sur un type de boucle (article) |
|
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | - |
|
| 111 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | - // on obtient $nom = "'article' . 'nom'" |
|
| 113 | - if (isset($crit->param[0])) { |
|
| 114 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | - |
|
| 121 | - // on crée un sql_in avec la clé primaire de la table |
|
| 122 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | - // $doublons et son index, ici $nom |
|
| 124 | - |
|
| 125 | - // debut du code "sql_in('articles.id_article', " |
|
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | - |
|
| 131 | - // le debut complet du code des doublons |
|
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 133 | - |
|
| 134 | - // nom du doublon "('article' . 'nom')]" |
|
| 135 | - $fin_doub = "($nom)]"; |
|
| 136 | - |
|
| 137 | - // si on trouve un autre critère doublon, |
|
| 138 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | - foreach ($boucle->where as $k => $w) { |
|
| 140 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | - // fusionner le sql_in (du where) |
|
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | - $x = strpos($boucle->hash, $init_comment); |
|
| 145 | - $len = strlen($init_comment); |
|
| 146 | - $boucle->hash = |
|
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | - |
|
| 149 | - return; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | - |
|
| 156 | - // déclarer le doublon s'il n'existe pas encore |
|
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 158 | - |
|
| 159 | - |
|
| 160 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | - # {!doublons A}{doublons B} |
|
| 163 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 98 | + $boucle = &$boucles[$idb]; |
|
| 99 | + $primary = $boucle->primary; |
|
| 100 | + |
|
| 101 | + // la table nécessite une clé primaire, non composée |
|
| 102 | + if (!$primary or strpos($primary, ',')) { |
|
| 103 | + return (array('zbug_doublon_sur_table_sans_cle_primaire')); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 107 | + |
|
| 108 | + // le doublon s'applique sur un type de boucle (article) |
|
| 109 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 110 | + |
|
| 111 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 112 | + // on obtient $nom = "'article' . 'nom'" |
|
| 113 | + if (isset($crit->param[0])) { |
|
| 114 | + $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 118 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 119 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 120 | + |
|
| 121 | + // on crée un sql_in avec la clé primaire de la table |
|
| 122 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 123 | + // $doublons et son index, ici $nom |
|
| 124 | + |
|
| 125 | + // debut du code "sql_in('articles.id_article', " |
|
| 126 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 127 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 128 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 129 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 130 | + |
|
| 131 | + // le debut complet du code des doublons |
|
| 132 | + $debut_doub = $debut_in . $debut_doub; |
|
| 133 | + |
|
| 134 | + // nom du doublon "('article' . 'nom')]" |
|
| 135 | + $fin_doub = "($nom)]"; |
|
| 136 | + |
|
| 137 | + // si on trouve un autre critère doublon, |
|
| 138 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 139 | + foreach ($boucle->where as $k => $w) { |
|
| 140 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 141 | + // fusionner le sql_in (du where) |
|
| 142 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 143 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 144 | + $x = strpos($boucle->hash, $init_comment); |
|
| 145 | + $len = strlen($init_comment); |
|
| 146 | + $boucle->hash = |
|
| 147 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 148 | + |
|
| 149 | + return; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 154 | + $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 155 | + |
|
| 156 | + // déclarer le doublon s'il n'existe pas encore |
|
| 157 | + $boucle->hash .= $init_comment . $init_code; |
|
| 158 | + |
|
| 159 | + |
|
| 160 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 161 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 162 | + # {!doublons A}{doublons B} |
|
| 163 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 164 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | |
@@ -182,14 +182,14 @@ discard block |
||
| 182 | 182 | * @return void |
| 183 | 183 | **/ |
| 184 | 184 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 185 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | - $param = 'oui'; |
|
| 187 | - } |
|
| 188 | - if ($crit->not) { |
|
| 189 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | - } |
|
| 191 | - $boucle = &$boucles[$idb]; |
|
| 192 | - $boucle->lang_select = $param; |
|
| 185 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 186 | + $param = 'oui'; |
|
| 187 | + } |
|
| 188 | + if ($crit->not) { |
|
| 189 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 190 | + } |
|
| 191 | + $boucle = &$boucles[$idb]; |
|
| 192 | + $boucle->lang_select = $param; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
@@ -211,18 +211,18 @@ discard block |
||
| 211 | 211 | * @return void |
| 212 | 212 | **/ |
| 213 | 213 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 214 | - list($un, $deux) = $crit->param; |
|
| 215 | - $un = $un[0]->texte; |
|
| 216 | - $deux = $deux[0]->texte; |
|
| 217 | - if ($deux) { |
|
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 222 | - '"'; |
|
| 223 | - } else { |
|
| 224 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | - } |
|
| 214 | + list($un, $deux) = $crit->param; |
|
| 215 | + $un = $un[0]->texte; |
|
| 216 | + $deux = $deux[0]->texte; |
|
| 217 | + if ($deux) { |
|
| 218 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | + $un . |
|
| 220 | + '"]) . ",' . |
|
| 221 | + $deux . |
|
| 222 | + '"'; |
|
| 223 | + } else { |
|
| 224 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 225 | + } |
|
| 226 | 226 | } |
| 227 | 227 | |
| 228 | 228 | |
@@ -256,57 +256,57 @@ discard block |
||
| 256 | 256 | **/ |
| 257 | 257 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 258 | 258 | |
| 259 | - $boucle = &$boucles[$idb]; |
|
| 260 | - // definition de la taille de la page |
|
| 261 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 263 | - |
|
| 264 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | - } else { |
|
| 267 | - $r = intval($r[2]); |
|
| 268 | - $pas = strval($r ? $r : 10); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - // Calcul du nommage de la pagination si il existe. |
|
| 272 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | - $type = "'$idb'"; |
|
| 275 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | - // Syntaxe {pagination 20, nom} |
|
| 277 | - if (isset($crit->param[0][1])) { |
|
| 278 | - $type = calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 279 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | - elseif (isset($crit->param[1][0])) { |
|
| 281 | - $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | - $partie = |
|
| 287 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | - . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | - . "\t}\n" |
|
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | - |
|
| 295 | - $boucle->hash .= ' |
|
| 259 | + $boucle = &$boucles[$idb]; |
|
| 260 | + // definition de la taille de la page |
|
| 261 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 262 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 263 | + |
|
| 264 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 265 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 266 | + } else { |
|
| 267 | + $r = intval($r[2]); |
|
| 268 | + $pas = strval($r ? $r : 10); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + // Calcul du nommage de la pagination si il existe. |
|
| 272 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 273 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 274 | + $type = "'$idb'"; |
|
| 275 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 276 | + // Syntaxe {pagination 20, nom} |
|
| 277 | + if (isset($crit->param[0][1])) { |
|
| 278 | + $type = calculer_liste(array($crit->param[0][1]), array(), $boucles, $boucle->id_parent); |
|
| 279 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 280 | + elseif (isset($crit->param[1][0])) { |
|
| 281 | + $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 285 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 286 | + $partie = |
|
| 287 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 288 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 289 | + . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
|
| 290 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 292 | + . "\t}\n" |
|
| 293 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 294 | + |
|
| 295 | + $boucle->hash .= ' |
|
| 296 | 296 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 297 | 297 | |
| 298 | - $boucle->total_parties = $pas; |
|
| 299 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | - // sauf si pas de primaire, ou si primaire composee |
|
| 302 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | - if ($boucle->primary |
|
| 305 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | - and !in_array($t, $boucle->select) |
|
| 307 | - ) { |
|
| 308 | - $boucle->select[] = $t; |
|
| 309 | - } |
|
| 298 | + $boucle->total_parties = $pas; |
|
| 299 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 300 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 301 | + // sauf si pas de primaire, ou si primaire composee |
|
| 302 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 303 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 304 | + if ($boucle->primary |
|
| 305 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 306 | + and !in_array($t, $boucle->select) |
|
| 307 | + ) { |
|
| 308 | + $boucle->select[] = $t; |
|
| 309 | + } |
|
| 310 | 310 | } |
| 311 | 311 | |
| 312 | 312 | |
@@ -328,24 +328,24 @@ discard block |
||
| 328 | 328 | **/ |
| 329 | 329 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 330 | 330 | |
| 331 | - $boucle = &$boucles[$idb]; |
|
| 331 | + $boucle = &$boucles[$idb]; |
|
| 332 | 332 | |
| 333 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 333 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 334 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', array('critere' => 'recherche')), $boucle); |
|
| 335 | 335 | |
| 336 | - return; |
|
| 337 | - } |
|
| 336 | + return; |
|
| 337 | + } |
|
| 338 | 338 | |
| 339 | - if (isset($crit->param[0])) { |
|
| 340 | - $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 341 | - } else { |
|
| 342 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | - } |
|
| 339 | + if (isset($crit->param[0])) { |
|
| 340 | + $quoi = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 341 | + } else { |
|
| 342 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 343 | + } |
|
| 344 | 344 | |
| 345 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | - $boucle->hash .= ' |
|
| 345 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 346 | + $boucle->hash .= ' |
|
| 347 | 347 | // RECHERCHE' |
| 348 | - . ($crit->cond ? ' |
|
| 348 | + . ($crit->cond ? ' |
|
| 349 | 349 | if (!strlen(' . $quoi . ')){ |
| 350 | 350 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | 351 | } else' : '') . ' |
@@ -356,21 +356,21 @@ discard block |
||
| 356 | 356 | '; |
| 357 | 357 | |
| 358 | 358 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | - $boucle->select[] = $t; |
|
| 362 | - } # pour postgres, neuneu ici |
|
| 363 | - // jointure uniquement sur le serveur principal |
|
| 364 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | - if (!$boucle->sql_serveur) { |
|
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | - } |
|
| 369 | - $boucle->select[] = '$rech_select'; |
|
| 370 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | - |
|
| 372 | - // et la recherche trouve |
|
| 373 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 359 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 360 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 361 | + $boucle->select[] = $t; |
|
| 362 | + } # pour postgres, neuneu ici |
|
| 363 | + // jointure uniquement sur le serveur principal |
|
| 364 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 365 | + if (!$boucle->sql_serveur) { |
|
| 366 | + $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 367 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 368 | + } |
|
| 369 | + $boucle->select[] = '$rech_select'; |
|
| 370 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 371 | + |
|
| 372 | + // et la recherche trouve |
|
| 373 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -387,25 +387,25 @@ discard block |
||
| 387 | 387 | * @return void |
| 388 | 388 | **/ |
| 389 | 389 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 390 | - $boucle = &$boucles[$idb]; |
|
| 391 | - $prim = $boucle->primary; |
|
| 392 | - $table = $boucle->id_table; |
|
| 393 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | - $boucle->where[] = |
|
| 396 | - array( |
|
| 397 | - "'OR'", |
|
| 398 | - array( |
|
| 399 | - "'AND'", |
|
| 400 | - array("'='", "'$table.id_trad'", 0), |
|
| 401 | - array("'='", "'$table.$prim'", $dprim) |
|
| 402 | - ), |
|
| 403 | - array( |
|
| 404 | - "'AND'", |
|
| 405 | - array("'>'", "'$table.id_trad'", 0), |
|
| 406 | - array("'='", "'$table.id_trad'", $arg) |
|
| 407 | - ) |
|
| 408 | - ); |
|
| 390 | + $boucle = &$boucles[$idb]; |
|
| 391 | + $prim = $boucle->primary; |
|
| 392 | + $table = $boucle->id_table; |
|
| 393 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 394 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 395 | + $boucle->where[] = |
|
| 396 | + array( |
|
| 397 | + "'OR'", |
|
| 398 | + array( |
|
| 399 | + "'AND'", |
|
| 400 | + array("'='", "'$table.id_trad'", 0), |
|
| 401 | + array("'='", "'$table.$prim'", $dprim) |
|
| 402 | + ), |
|
| 403 | + array( |
|
| 404 | + "'AND'", |
|
| 405 | + array("'>'", "'$table.id_trad'", 0), |
|
| 406 | + array("'='", "'$table.id_trad'", $arg) |
|
| 407 | + ) |
|
| 408 | + ); |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return void |
| 424 | 424 | **/ |
| 425 | 425 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 426 | - $boucle = &$boucles[$idb]; |
|
| 427 | - $prim = $boucle->primary; |
|
| 428 | - $table = $boucle->id_table; |
|
| 429 | - |
|
| 430 | - $c = |
|
| 431 | - array( |
|
| 432 | - "'OR'", |
|
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | - array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | - ); |
|
| 436 | - $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 426 | + $boucle = &$boucles[$idb]; |
|
| 427 | + $prim = $boucle->primary; |
|
| 428 | + $table = $boucle->id_table; |
|
| 429 | + |
|
| 430 | + $c = |
|
| 431 | + array( |
|
| 432 | + "'OR'", |
|
| 433 | + array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 434 | + array("'='", "'$table.id_trad'", "'0'") |
|
| 435 | + ); |
|
| 436 | + $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
|
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | |
@@ -450,20 +450,20 @@ discard block |
||
| 450 | 450 | **/ |
| 451 | 451 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 452 | 452 | |
| 453 | - $boucle = &$boucles[$idb]; |
|
| 454 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + $boucle = &$boucles[$idb]; |
|
| 454 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 455 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 456 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | + 'id_parent'; |
|
| 458 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 459 | 459 | |
| 460 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | - $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 460 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 461 | + $boucle->where[] = array("'='", "'$mparent'", $arg); |
|
| 462 | 462 | |
| 463 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | - else { |
|
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | - } |
|
| 463 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 464 | + else { |
|
| 465 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -494,37 +494,37 @@ discard block |
||
| 494 | 494 | **/ |
| 495 | 495 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 496 | 496 | |
| 497 | - $not = $crit->not; |
|
| 498 | - $boucle = &$boucles[$idb]; |
|
| 499 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | - if (isset($crit->param[0])) { |
|
| 501 | - $arg = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 502 | - // sinon on le prend chez une boucle parente |
|
| 503 | - } else { |
|
| 504 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - //Trouver une jointure |
|
| 508 | - $champ = "id_rubrique"; |
|
| 509 | - $desc = $boucle->show; |
|
| 510 | - //Seulement si necessaire |
|
| 511 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | - $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | - $decompose = decompose_champ_id_objet($champ); |
|
| 517 | - $champ = array_shift($decompose); |
|
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | - } |
|
| 520 | - } else { |
|
| 521 | - $cle = $boucle->id_table; |
|
| 522 | - } |
|
| 523 | - |
|
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 497 | + $not = $crit->not; |
|
| 498 | + $boucle = &$boucles[$idb]; |
|
| 499 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 500 | + if (isset($crit->param[0])) { |
|
| 501 | + $arg = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 502 | + // sinon on le prend chez une boucle parente |
|
| 503 | + } else { |
|
| 504 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + //Trouver une jointure |
|
| 508 | + $champ = "id_rubrique"; |
|
| 509 | + $desc = $boucle->show; |
|
| 510 | + //Seulement si necessaire |
|
| 511 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 512 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 513 | + $trouver_table = charger_fonction("trouver_table", "base"); |
|
| 514 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 515 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 516 | + $decompose = decompose_champ_id_objet($champ); |
|
| 517 | + $champ = array_shift($decompose); |
|
| 518 | + $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 519 | + } |
|
| 520 | + } else { |
|
| 521 | + $cle = $boucle->id_table; |
|
| 522 | + } |
|
| 523 | + |
|
| 524 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | + . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -540,22 +540,22 @@ discard block |
||
| 540 | 540 | **/ |
| 541 | 541 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 542 | 542 | |
| 543 | - $not = $crit->not; |
|
| 544 | - $boucle = &$boucles[$idb]; |
|
| 543 | + $not = $crit->not; |
|
| 544 | + $boucle = &$boucles[$idb]; |
|
| 545 | 545 | |
| 546 | - $c = "sql_in('" . |
|
| 547 | - $boucle->id_table . '.' . $boucle->primary |
|
| 548 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 546 | + $c = "sql_in('" . |
|
| 547 | + $boucle->id_table . '.' . $boucle->primary |
|
| 548 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 549 | 549 | |
| 550 | - if ($crit->cond) { |
|
| 551 | - $c = "($arg ? $c : 1)"; |
|
| 552 | - } |
|
| 550 | + if ($crit->cond) { |
|
| 551 | + $c = "($arg ? $c : 1)"; |
|
| 552 | + } |
|
| 553 | 553 | |
| 554 | - if ($not) { |
|
| 555 | - $boucle->where[] = array("'NOT'", $c); |
|
| 556 | - } else { |
|
| 557 | - $boucle->where[] = $c; |
|
| 558 | - } |
|
| 554 | + if ($not) { |
|
| 555 | + $boucle->where[] = array("'NOT'", $c); |
|
| 556 | + } else { |
|
| 557 | + $boucle->where[] = $c; |
|
| 558 | + } |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | |
@@ -577,31 +577,31 @@ discard block |
||
| 577 | 577 | * @return void |
| 578 | 578 | **/ |
| 579 | 579 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 580 | - if ($t = isset($crit->param[0])) { |
|
| 581 | - $t = $crit->param[0]; |
|
| 582 | - if ($t[0]->type == 'texte') { |
|
| 583 | - $t = $t[0]->texte; |
|
| 584 | - if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 585 | - $t = table_objet_sql($r[1]); |
|
| 586 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 587 | - if ($t) { |
|
| 588 | - $t .= '.' . $r[2]; |
|
| 589 | - } |
|
| 590 | - } |
|
| 591 | - } else { |
|
| 592 | - $t = '".' |
|
| 593 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 594 | - . '."'; |
|
| 595 | - } |
|
| 596 | - } |
|
| 597 | - if ($t) { |
|
| 598 | - $boucles[$idb]->group[] = $t; |
|
| 599 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 600 | - $boucles[$idb]->select[] = $t; |
|
| 601 | - } |
|
| 602 | - } else { |
|
| 603 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 604 | - } |
|
| 580 | + if ($t = isset($crit->param[0])) { |
|
| 581 | + $t = $crit->param[0]; |
|
| 582 | + if ($t[0]->type == 'texte') { |
|
| 583 | + $t = $t[0]->texte; |
|
| 584 | + if (preg_match("/^(.*)\.(.*)$/", $t, $r)) { |
|
| 585 | + $t = table_objet_sql($r[1]); |
|
| 586 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 587 | + if ($t) { |
|
| 588 | + $t .= '.' . $r[2]; |
|
| 589 | + } |
|
| 590 | + } |
|
| 591 | + } else { |
|
| 592 | + $t = '".' |
|
| 593 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 594 | + . '."'; |
|
| 595 | + } |
|
| 596 | + } |
|
| 597 | + if ($t) { |
|
| 598 | + $boucles[$idb]->group[] = $t; |
|
| 599 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 600 | + $boucles[$idb]->select[] = $t; |
|
| 601 | + } |
|
| 602 | + } else { |
|
| 603 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 604 | + } |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -638,45 +638,45 @@ discard block |
||
| 638 | 638 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 639 | 639 | */ |
| 640 | 640 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 641 | - if (isset($crit->param[0])) { |
|
| 642 | - $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 643 | - $boucle = $boucles[$idb]; |
|
| 644 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 645 | - $n = count($boucle->order); |
|
| 646 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 647 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 648 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 649 | - if ( |
|
| 650 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 651 | - OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 652 | - ) { |
|
| 653 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 654 | - } else { |
|
| 655 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 656 | - } |
|
| 657 | - } |
|
| 658 | - } else { |
|
| 659 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 660 | - } |
|
| 641 | + if (isset($crit->param[0])) { |
|
| 642 | + $_coll = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 643 | + $boucle = $boucles[$idb]; |
|
| 644 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 645 | + $n = count($boucle->order); |
|
| 646 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 647 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 648 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 649 | + if ( |
|
| 650 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 651 | + OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 652 | + ) { |
|
| 653 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 654 | + } else { |
|
| 655 | + $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 656 | + } |
|
| 657 | + } |
|
| 658 | + } else { |
|
| 659 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 660 | + } |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | 664 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | - $boucle = $boucles[$idb]; |
|
| 666 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | - $var = '$champs_' . $idb; |
|
| 668 | - $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 669 | - if (!$desc) { |
|
| 670 | - $desc = $boucle->show['field']; |
|
| 671 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 672 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 673 | - } |
|
| 674 | - if ($desc) { |
|
| 675 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 676 | - } |
|
| 677 | - $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 678 | - |
|
| 679 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 665 | + $boucle = $boucles[$idb]; |
|
| 666 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | + $var = '$champs_' . $idb; |
|
| 668 | + $desc = (strpos($boucle->in, "static $var =") !== false); |
|
| 669 | + if (!$desc) { |
|
| 670 | + $desc = $boucle->show['field']; |
|
| 671 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 672 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 673 | + } |
|
| 674 | + if ($desc) { |
|
| 675 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 676 | + } |
|
| 677 | + $arg = calculer_liste($crit, array(), $boucles, $boucle->id_parent); |
|
| 678 | + |
|
| 679 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | /** |
@@ -715,7 +715,7 @@ discard block |
||
| 715 | 715 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 716 | 716 | */ |
| 717 | 717 | function critere_par_dist($idb, &$boucles, $crit) { |
| 718 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 718 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -737,93 +737,93 @@ discard block |
||
| 737 | 737 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 738 | 738 | */ |
| 739 | 739 | function critere_parinverse($idb, &$boucles, $crit) { |
| 740 | - $boucle = &$boucles[$idb]; |
|
| 741 | - |
|
| 742 | - $sens = $collecte = ''; |
|
| 743 | - if ($crit->not) { |
|
| 744 | - $sens = " . ' DESC'"; |
|
| 745 | - } |
|
| 746 | - if (isset($boucle->modificateur['collate'])) { |
|
| 747 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - // Pour chaque paramètre du critère |
|
| 751 | - foreach ($crit->param as $tri) { |
|
| 752 | - $order = $fct = ''; |
|
| 753 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 754 | - if ($tri[0]->type != 'texte') { |
|
| 755 | - // calculer le order dynamique qui verifie les champs |
|
| 756 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 757 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 758 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 759 | - } |
|
| 760 | - // tris textuels {par titre} |
|
| 761 | - else { |
|
| 762 | - $par = array_shift($tri); |
|
| 763 | - $par = $par->texte; |
|
| 764 | - |
|
| 765 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 766 | - if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 767 | - $expression = trim($m[1]); |
|
| 768 | - $champ = trim($m[2]); |
|
| 769 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 770 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 771 | - } else { |
|
| 772 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 773 | - } |
|
| 774 | - |
|
| 775 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 776 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 777 | - // {par FONCTION(champ)} |
|
| 778 | - if (count($match) > 2) { |
|
| 779 | - $par = substr($match[2], 1, -1); |
|
| 780 | - $fct = $match[1]; |
|
| 781 | - } |
|
| 782 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 783 | - if ($par == 'hasard') { |
|
| 784 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 785 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 786 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 787 | - } else { |
|
| 788 | - // cas général {par champ}, {par table.champ}, ... |
|
| 789 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 790 | - } |
|
| 791 | - } |
|
| 792 | - |
|
| 793 | - // on ne sait pas traiter… |
|
| 794 | - else { |
|
| 795 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 799 | - if (is_array($order)) { |
|
| 800 | - return $order; |
|
| 801 | - } |
|
| 802 | - } |
|
| 803 | - |
|
| 804 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 805 | - $t = $m[1]; |
|
| 806 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 807 | - $boucle->select[] = $t; |
|
| 808 | - } |
|
| 809 | - } else { |
|
| 810 | - $sens = ''; |
|
| 811 | - } |
|
| 812 | - |
|
| 813 | - if ($fct) { |
|
| 814 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 815 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 816 | - } else { |
|
| 817 | - $order = "'$fct(' . $order . ')'"; |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - $t = $order . $collecte . $sens; |
|
| 821 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 822 | - $t = $r[1] . $r[2]; |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - $boucle->order[] = $t; |
|
| 826 | - } |
|
| 740 | + $boucle = &$boucles[$idb]; |
|
| 741 | + |
|
| 742 | + $sens = $collecte = ''; |
|
| 743 | + if ($crit->not) { |
|
| 744 | + $sens = " . ' DESC'"; |
|
| 745 | + } |
|
| 746 | + if (isset($boucle->modificateur['collate'])) { |
|
| 747 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + // Pour chaque paramètre du critère |
|
| 751 | + foreach ($crit->param as $tri) { |
|
| 752 | + $order = $fct = ''; |
|
| 753 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 754 | + if ($tri[0]->type != 'texte') { |
|
| 755 | + // calculer le order dynamique qui verifie les champs |
|
| 756 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 757 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 758 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 759 | + } |
|
| 760 | + // tris textuels {par titre} |
|
| 761 | + else { |
|
| 762 | + $par = array_shift($tri); |
|
| 763 | + $par = $par->texte; |
|
| 764 | + |
|
| 765 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 766 | + if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
|
| 767 | + $expression = trim($m[1]); |
|
| 768 | + $champ = trim($m[2]); |
|
| 769 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 770 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 771 | + } else { |
|
| 772 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 773 | + } |
|
| 774 | + |
|
| 775 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 776 | + } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 777 | + // {par FONCTION(champ)} |
|
| 778 | + if (count($match) > 2) { |
|
| 779 | + $par = substr($match[2], 1, -1); |
|
| 780 | + $fct = $match[1]; |
|
| 781 | + } |
|
| 782 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 783 | + if ($par == 'hasard') { |
|
| 784 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 785 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 786 | + $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 787 | + } else { |
|
| 788 | + // cas général {par champ}, {par table.champ}, ... |
|
| 789 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 790 | + } |
|
| 791 | + } |
|
| 792 | + |
|
| 793 | + // on ne sait pas traiter… |
|
| 794 | + else { |
|
| 795 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 799 | + if (is_array($order)) { |
|
| 800 | + return $order; |
|
| 801 | + } |
|
| 802 | + } |
|
| 803 | + |
|
| 804 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 805 | + $t = $m[1]; |
|
| 806 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 807 | + $boucle->select[] = $t; |
|
| 808 | + } |
|
| 809 | + } else { |
|
| 810 | + $sens = ''; |
|
| 811 | + } |
|
| 812 | + |
|
| 813 | + if ($fct) { |
|
| 814 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 815 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 816 | + } else { |
|
| 817 | + $order = "'$fct(' . $order . ')'"; |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + $t = $order . $collecte . $sens; |
|
| 821 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 822 | + $t = $r[1] . $r[2]; |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + $boucle->order[] = $t; |
|
| 826 | + } |
|
| 827 | 827 | } |
| 828 | 828 | |
| 829 | 829 | /** |
@@ -837,13 +837,13 @@ discard block |
||
| 837 | 837 | * @return string Clause pour le Order by |
| 838 | 838 | */ |
| 839 | 839 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 840 | - $boucle = &$boucles[$idb]; |
|
| 841 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 842 | - $parha = "rand() AS hasard"; |
|
| 843 | - if (!in_array($parha, $boucle->select)) { |
|
| 844 | - $boucle->select[] = $parha; |
|
| 845 | - } |
|
| 846 | - return "'hasard'"; |
|
| 840 | + $boucle = &$boucles[$idb]; |
|
| 841 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 842 | + $parha = "rand() AS hasard"; |
|
| 843 | + if (!in_array($parha, $boucle->select)) { |
|
| 844 | + $boucle->select[] = $parha; |
|
| 845 | + } |
|
| 846 | + return "'hasard'"; |
|
| 847 | 847 | } |
| 848 | 848 | |
| 849 | 849 | /** |
@@ -867,20 +867,20 @@ discard block |
||
| 867 | 867 | * @return string Clause pour le Order by |
| 868 | 868 | */ |
| 869 | 869 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 870 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 871 | - if (is_array($_champ)) { |
|
| 872 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 873 | - } |
|
| 874 | - $boucle = &$boucles[$idb]; |
|
| 875 | - $texte = '0+' . $_champ; |
|
| 876 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 877 | - if ($suite !== "''") { |
|
| 878 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 879 | - } |
|
| 880 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | - $boucle->select[] = $texte . " AS $as"; |
|
| 882 | - $order = "'$as'"; |
|
| 883 | - return $order; |
|
| 870 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 871 | + if (is_array($_champ)) { |
|
| 872 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 873 | + } |
|
| 874 | + $boucle = &$boucles[$idb]; |
|
| 875 | + $texte = '0+' . $_champ; |
|
| 876 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 877 | + if ($suite !== "''") { |
|
| 878 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 879 | + } |
|
| 880 | + $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | + $boucle->select[] = $texte . " AS $as"; |
|
| 882 | + $order = "'$as'"; |
|
| 883 | + return $order; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | /** |
@@ -901,20 +901,20 @@ discard block |
||
| 901 | 901 | * @return string Clause pour le Order by |
| 902 | 902 | */ |
| 903 | 903 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 904 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 905 | - if (is_array($_champ)) { |
|
| 906 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 907 | - } |
|
| 908 | - $boucle = &$boucles[$idb]; |
|
| 909 | - $texte = '0+' . $_champ; |
|
| 910 | - $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 911 | - if ($suite !== "''") { |
|
| 912 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 913 | - } |
|
| 914 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 916 | - $order = "'$as'"; |
|
| 917 | - return $order; |
|
| 904 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 905 | + if (is_array($_champ)) { |
|
| 906 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 907 | + } |
|
| 908 | + $boucle = &$boucles[$idb]; |
|
| 909 | + $texte = '0+' . $_champ; |
|
| 910 | + $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
|
| 911 | + if ($suite !== "''") { |
|
| 912 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 913 | + } |
|
| 914 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | + $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 916 | + $order = "'$as'"; |
|
| 917 | + return $order; |
|
| 918 | 918 | } |
| 919 | 919 | |
| 920 | 920 | |
@@ -934,14 +934,14 @@ discard block |
||
| 934 | 934 | * @return string Clause pour le Order by |
| 935 | 935 | */ |
| 936 | 936 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 937 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 938 | - if (is_array($_champ)) { |
|
| 939 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 940 | - } |
|
| 941 | - $boucle = &$boucles[$idb]; |
|
| 942 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 943 | - $order = "'multi'"; |
|
| 944 | - return $order; |
|
| 937 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 938 | + if (is_array($_champ)) { |
|
| 939 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 940 | + } |
|
| 941 | + $boucle = &$boucles[$idb]; |
|
| 942 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 943 | + $order = "'multi'"; |
|
| 944 | + return $order; |
|
| 945 | 945 | } |
| 946 | 946 | |
| 947 | 947 | /** |
@@ -960,55 +960,55 @@ discard block |
||
| 960 | 960 | * @return array|string |
| 961 | 961 | */ |
| 962 | 962 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 963 | - $boucle = &$boucles[$idb]; |
|
| 964 | - |
|
| 965 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 966 | - if (isset($desc['field'][$par])) { |
|
| 967 | - $par = $boucle->id_table . "." . $par; |
|
| 968 | - } |
|
| 969 | - // le champ est peut être une jointure |
|
| 970 | - else { |
|
| 971 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 972 | - $champ = $par; |
|
| 973 | - |
|
| 974 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 975 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 976 | - list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 977 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 978 | - elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 979 | - list(, $table, $champ) = $r; |
|
| 980 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 981 | - $table = table_objet_sql($table); |
|
| 982 | - } |
|
| 983 | - |
|
| 984 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 985 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 986 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 987 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 988 | - $par = $infos['alias'] . "." . $champ; |
|
| 989 | - } elseif ( |
|
| 990 | - $boucle->jointures_explicites |
|
| 991 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 992 | - ) { |
|
| 993 | - $par = $alias . "." . $champ; |
|
| 994 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 995 | - $par = $alias . "." . $champ; |
|
| 996 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 997 | - } elseif ( |
|
| 998 | - $table_alias |
|
| 999 | - and isset($boucle->from[$table_alias]) |
|
| 1000 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1001 | - ) { |
|
| 1002 | - $par = $infos['alias'] . "." . $champ; |
|
| 1003 | - } elseif ($table) { |
|
| 1004 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1005 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1006 | - } else { |
|
| 1007 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return $raw ? $par : "'$par'"; |
|
| 963 | + $boucle = &$boucles[$idb]; |
|
| 964 | + |
|
| 965 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 966 | + if (isset($desc['field'][$par])) { |
|
| 967 | + $par = $boucle->id_table . "." . $par; |
|
| 968 | + } |
|
| 969 | + // le champ est peut être une jointure |
|
| 970 | + else { |
|
| 971 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 972 | + $champ = $par; |
|
| 973 | + |
|
| 974 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 975 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 976 | + list($table, $champ) = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 977 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 978 | + elseif (preg_match("/^([^,]*)\.(.*)$/", $par, $r)) { |
|
| 979 | + list(, $table, $champ) = $r; |
|
| 980 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 981 | + $table = table_objet_sql($table); |
|
| 982 | + } |
|
| 983 | + |
|
| 984 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 985 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 986 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 987 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 988 | + $par = $infos['alias'] . "." . $champ; |
|
| 989 | + } elseif ( |
|
| 990 | + $boucle->jointures_explicites |
|
| 991 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 992 | + ) { |
|
| 993 | + $par = $alias . "." . $champ; |
|
| 994 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 995 | + $par = $alias . "." . $champ; |
|
| 996 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 997 | + } elseif ( |
|
| 998 | + $table_alias |
|
| 999 | + and isset($boucle->from[$table_alias]) |
|
| 1000 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1001 | + ) { |
|
| 1002 | + $par = $infos['alias'] . "." . $champ; |
|
| 1003 | + } elseif ($table) { |
|
| 1004 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1005 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1006 | + } else { |
|
| 1007 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return $raw ? $par : "'$par'"; |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | /** |
@@ -1022,11 +1022,11 @@ discard block |
||
| 1022 | 1022 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1023 | 1023 | */ |
| 1024 | 1024 | function critere_par_joint($table, $champ, &$boucle) { |
| 1025 | - $t = array_search($table, $boucle->from); |
|
| 1026 | - if (!$t) { |
|
| 1027 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1028 | - } |
|
| 1029 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1025 | + $t = array_search($table, $boucle->from); |
|
| 1026 | + if (!$t) { |
|
| 1027 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1028 | + } |
|
| 1029 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | /** |
@@ -1051,143 +1051,143 @@ discard block |
||
| 1051 | 1051 | */ |
| 1052 | 1052 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1053 | 1053 | |
| 1054 | - $boucle = &$boucles[$idb]; |
|
| 1055 | - // Classement par ordre inverse |
|
| 1056 | - if ($crit->not) { |
|
| 1057 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1058 | - } else { |
|
| 1059 | - $order = "' DESC'"; |
|
| 1060 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1061 | - if (isset($crit->param[0])) { |
|
| 1062 | - $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1063 | - $order = "(($critere)?' DESC':'')"; |
|
| 1064 | - } |
|
| 1065 | - |
|
| 1066 | - $n = count($boucle->order); |
|
| 1067 | - if (!$n) { |
|
| 1068 | - if (isset($boucle->default_order[0])) { |
|
| 1069 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1070 | - } else { |
|
| 1071 | - $boucle->default_order[] = ' DESC'; |
|
| 1072 | - } |
|
| 1073 | - } else { |
|
| 1074 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1075 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1076 | - $t = $r[1] . $r[2]; |
|
| 1077 | - } |
|
| 1078 | - $boucle->order[$n - 1] = $t; |
|
| 1079 | - } |
|
| 1080 | - } |
|
| 1054 | + $boucle = &$boucles[$idb]; |
|
| 1055 | + // Classement par ordre inverse |
|
| 1056 | + if ($crit->not) { |
|
| 1057 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1058 | + } else { |
|
| 1059 | + $order = "' DESC'"; |
|
| 1060 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1061 | + if (isset($crit->param[0])) { |
|
| 1062 | + $critere = calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 1063 | + $order = "(($critere)?' DESC':'')"; |
|
| 1064 | + } |
|
| 1065 | + |
|
| 1066 | + $n = count($boucle->order); |
|
| 1067 | + if (!$n) { |
|
| 1068 | + if (isset($boucle->default_order[0])) { |
|
| 1069 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1070 | + } else { |
|
| 1071 | + $boucle->default_order[] = ' DESC'; |
|
| 1072 | + } |
|
| 1073 | + } else { |
|
| 1074 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1075 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1076 | + $t = $r[1] . $r[2]; |
|
| 1077 | + } |
|
| 1078 | + $boucle->order[$n - 1] = $t; |
|
| 1079 | + } |
|
| 1080 | + } |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | // http://code.spip.net/@critere_agenda_dist |
| 1084 | 1084 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1085 | - $params = $crit->param; |
|
| 1086 | - |
|
| 1087 | - if (count($params) < 1) { |
|
| 1088 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $boucle = &$boucles[$idb]; |
|
| 1092 | - $parent = $boucle->id_parent; |
|
| 1093 | - $fields = $boucle->show['field']; |
|
| 1094 | - |
|
| 1095 | - $date = array_shift($params); |
|
| 1096 | - $type = array_shift($params); |
|
| 1097 | - |
|
| 1098 | - // la valeur $type doit etre connue a la compilation |
|
| 1099 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1100 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1101 | - |
|
| 1102 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1103 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1104 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1105 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1106 | - if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1107 | - $date = $date[0]->texte; |
|
| 1108 | - if (!isset($fields[$date])) { |
|
| 1109 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1110 | - } |
|
| 1111 | - } else { |
|
| 1112 | - $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1113 | - $noms = array_keys($fields); |
|
| 1114 | - $defaut = $noms[0]; |
|
| 1115 | - $noms = join(" ", $noms); |
|
| 1116 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1117 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1118 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1119 | - } |
|
| 1120 | - $annee = $params ? array_shift($params) : ""; |
|
| 1121 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1122 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1123 | - ') ? $x : date("Y"))'; |
|
| 1124 | - |
|
| 1125 | - $mois = $params ? array_shift($params) : ""; |
|
| 1126 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1127 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1128 | - ') ? $x : date("m"))'; |
|
| 1129 | - |
|
| 1130 | - $jour = $params ? array_shift($params) : ""; |
|
| 1131 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1132 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1133 | - ') ? $x : date("d"))'; |
|
| 1134 | - |
|
| 1135 | - $annee2 = $params ? array_shift($params) : ""; |
|
| 1136 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1137 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1138 | - ') ? $x : date("Y"))'; |
|
| 1139 | - |
|
| 1140 | - $mois2 = $params ? array_shift($params) : ""; |
|
| 1141 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1142 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1143 | - ') ? $x : date("m"))'; |
|
| 1144 | - |
|
| 1145 | - $jour2 = $params ? array_shift($params) : ""; |
|
| 1146 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1147 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1148 | - ') ? $x : date("d"))'; |
|
| 1149 | - |
|
| 1150 | - $date = $boucle->id_table . ".$date"; |
|
| 1151 | - |
|
| 1152 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1153 | - if ($type == 'jour') { |
|
| 1154 | - $boucle->where[] = array( |
|
| 1155 | - "'='", |
|
| 1156 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1157 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1158 | - ); |
|
| 1159 | - } elseif ($type == 'mois') { |
|
| 1160 | - $boucle->where[] = array( |
|
| 1161 | - "'='", |
|
| 1162 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1163 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1164 | - ); |
|
| 1165 | - } elseif ($type == 'semaine') { |
|
| 1166 | - $boucle->where[] = array( |
|
| 1167 | - "'AND'", |
|
| 1168 | - array( |
|
| 1169 | - "'>='", |
|
| 1170 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1171 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1172 | - ), |
|
| 1173 | - array( |
|
| 1174 | - "'<='", |
|
| 1175 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1176 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1177 | - ) |
|
| 1178 | - ); |
|
| 1179 | - } elseif (count($crit->param) > 2) { |
|
| 1180 | - $boucle->where[] = array( |
|
| 1181 | - "'AND'", |
|
| 1182 | - array( |
|
| 1183 | - "'>='", |
|
| 1184 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1185 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1186 | - ), |
|
| 1187 | - array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1188 | - ); |
|
| 1189 | - } |
|
| 1190 | - // sinon on prend tout |
|
| 1085 | + $params = $crit->param; |
|
| 1086 | + |
|
| 1087 | + if (count($params) < 1) { |
|
| 1088 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $boucle = &$boucles[$idb]; |
|
| 1092 | + $parent = $boucle->id_parent; |
|
| 1093 | + $fields = $boucle->show['field']; |
|
| 1094 | + |
|
| 1095 | + $date = array_shift($params); |
|
| 1096 | + $type = array_shift($params); |
|
| 1097 | + |
|
| 1098 | + // la valeur $type doit etre connue a la compilation |
|
| 1099 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1100 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1101 | + |
|
| 1102 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1103 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1104 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1105 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1106 | + if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
|
| 1107 | + $date = $date[0]->texte; |
|
| 1108 | + if (!isset($fields[$date])) { |
|
| 1109 | + return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1110 | + } |
|
| 1111 | + } else { |
|
| 1112 | + $a = calculer_liste($date, array(), $boucles, $parent); |
|
| 1113 | + $noms = array_keys($fields); |
|
| 1114 | + $defaut = $noms[0]; |
|
| 1115 | + $noms = join(" ", $noms); |
|
| 1116 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1117 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1118 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1119 | + } |
|
| 1120 | + $annee = $params ? array_shift($params) : ""; |
|
| 1121 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1122 | + calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1123 | + ') ? $x : date("Y"))'; |
|
| 1124 | + |
|
| 1125 | + $mois = $params ? array_shift($params) : ""; |
|
| 1126 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1127 | + calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1128 | + ') ? $x : date("m"))'; |
|
| 1129 | + |
|
| 1130 | + $jour = $params ? array_shift($params) : ""; |
|
| 1131 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1132 | + calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1133 | + ') ? $x : date("d"))'; |
|
| 1134 | + |
|
| 1135 | + $annee2 = $params ? array_shift($params) : ""; |
|
| 1136 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1137 | + calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1138 | + ') ? $x : date("Y"))'; |
|
| 1139 | + |
|
| 1140 | + $mois2 = $params ? array_shift($params) : ""; |
|
| 1141 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1142 | + calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1143 | + ') ? $x : date("m"))'; |
|
| 1144 | + |
|
| 1145 | + $jour2 = $params ? array_shift($params) : ""; |
|
| 1146 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1147 | + calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1148 | + ') ? $x : date("d"))'; |
|
| 1149 | + |
|
| 1150 | + $date = $boucle->id_table . ".$date"; |
|
| 1151 | + |
|
| 1152 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1153 | + if ($type == 'jour') { |
|
| 1154 | + $boucle->where[] = array( |
|
| 1155 | + "'='", |
|
| 1156 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1157 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1158 | + ); |
|
| 1159 | + } elseif ($type == 'mois') { |
|
| 1160 | + $boucle->where[] = array( |
|
| 1161 | + "'='", |
|
| 1162 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1163 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1164 | + ); |
|
| 1165 | + } elseif ($type == 'semaine') { |
|
| 1166 | + $boucle->where[] = array( |
|
| 1167 | + "'AND'", |
|
| 1168 | + array( |
|
| 1169 | + "'>='", |
|
| 1170 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1171 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1172 | + ), |
|
| 1173 | + array( |
|
| 1174 | + "'<='", |
|
| 1175 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1176 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1177 | + ) |
|
| 1178 | + ); |
|
| 1179 | + } elseif (count($crit->param) > 2) { |
|
| 1180 | + $boucle->where[] = array( |
|
| 1181 | + "'AND'", |
|
| 1182 | + array( |
|
| 1183 | + "'>='", |
|
| 1184 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1185 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1186 | + ), |
|
| 1187 | + array("'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")) |
|
| 1188 | + ); |
|
| 1189 | + } |
|
| 1190 | + // sinon on prend tout |
|
| 1191 | 1191 | } |
| 1192 | 1192 | |
| 1193 | 1193 | |
@@ -1212,33 +1212,33 @@ discard block |
||
| 1212 | 1212 | * @return void |
| 1213 | 1213 | **/ |
| 1214 | 1214 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1215 | - $boucle = &$boucles[$idb]; |
|
| 1216 | - $a1 = $crit->param[0]; |
|
| 1217 | - $a2 = $crit->param[1]; |
|
| 1218 | - $op = $crit->op; |
|
| 1219 | - |
|
| 1220 | - list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1221 | - list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1222 | - |
|
| 1223 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1224 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1225 | - } else { |
|
| 1226 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1227 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1228 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1229 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1230 | - $mode = (($op == '/') ? '/' : |
|
| 1231 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1232 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1233 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1234 | - $boucle->limit = |
|
| 1235 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1236 | - . ".','." |
|
| 1237 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1238 | - } else { |
|
| 1239 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1240 | - } |
|
| 1241 | - } |
|
| 1215 | + $boucle = &$boucles[$idb]; |
|
| 1216 | + $a1 = $crit->param[0]; |
|
| 1217 | + $a2 = $crit->param[1]; |
|
| 1218 | + $op = $crit->op; |
|
| 1219 | + |
|
| 1220 | + list($a11, $a12) = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1221 | + list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1222 | + |
|
| 1223 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1224 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1225 | + } else { |
|
| 1226 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1227 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1228 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1229 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1230 | + $mode = (($op == '/') ? '/' : |
|
| 1231 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1232 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1233 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
|
| 1234 | + $boucle->limit = |
|
| 1235 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1236 | + . ".','." |
|
| 1237 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1238 | + } else { |
|
| 1239 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1240 | + } |
|
| 1241 | + } |
|
| 1242 | 1242 | } |
| 1243 | 1243 | |
| 1244 | 1244 | /** |
@@ -1266,63 +1266,63 @@ discard block |
||
| 1266 | 1266 | * @return void |
| 1267 | 1267 | **/ |
| 1268 | 1268 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1269 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1270 | - |
|
| 1271 | - preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1272 | - list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1273 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1274 | - // {1/3} |
|
| 1275 | - if ($op1 == '/') { |
|
| 1276 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1277 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1278 | - "($total_parties ? $total_parties : 1)"; |
|
| 1279 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1280 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1281 | - } else { |
|
| 1282 | - // cas {n-1,x} |
|
| 1283 | - if ($op1 == '-') { |
|
| 1284 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1285 | - } |
|
| 1286 | - |
|
| 1287 | - // cas {x,n-1} |
|
| 1288 | - if ($op2 == '-') { |
|
| 1289 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1290 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1291 | - ($total_parties . ' - 1')); |
|
| 1292 | - } else { |
|
| 1293 | - // {x,1} ou {pagination} |
|
| 1294 | - $fin = '$debut_boucle' |
|
| 1295 | - . (is_numeric($total_parties) ? |
|
| 1296 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1297 | - ('+' . $total_parties . ' - 1')); |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1301 | - if ($op1 == 'p') { |
|
| 1302 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1303 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1304 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1305 | - } |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - // Notes : |
|
| 1309 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1310 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1311 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1312 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1313 | - |
|
| 1314 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1315 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1316 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1317 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1318 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1319 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1320 | - . "\n\tif (\$debut_boucle>0" |
|
| 1321 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1322 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1323 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1324 | - |
|
| 1325 | - $boucles[$id_boucle]->partie = " |
|
| 1269 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1270 | + |
|
| 1271 | + preg_match(",([+-/p])([+-/])?,", $mode, $regs); |
|
| 1272 | + list(, $op1, $op2) = array_pad($regs, 3, null); |
|
| 1273 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1274 | + // {1/3} |
|
| 1275 | + if ($op1 == '/') { |
|
| 1276 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1277 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1278 | + "($total_parties ? $total_parties : 1)"; |
|
| 1279 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1280 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1281 | + } else { |
|
| 1282 | + // cas {n-1,x} |
|
| 1283 | + if ($op1 == '-') { |
|
| 1284 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1285 | + } |
|
| 1286 | + |
|
| 1287 | + // cas {x,n-1} |
|
| 1288 | + if ($op2 == '-') { |
|
| 1289 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1290 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1291 | + ($total_parties . ' - 1')); |
|
| 1292 | + } else { |
|
| 1293 | + // {x,1} ou {pagination} |
|
| 1294 | + $fin = '$debut_boucle' |
|
| 1295 | + . (is_numeric($total_parties) ? |
|
| 1296 | + (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1297 | + ('+' . $total_parties . ' - 1')); |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1301 | + if ($op1 == 'p') { |
|
| 1302 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1303 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1304 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1305 | + } |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + // Notes : |
|
| 1309 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1310 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1311 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1312 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1313 | + |
|
| 1314 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1315 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1316 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1317 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1318 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1319 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1320 | + . "\n\tif (\$debut_boucle>0" |
|
| 1321 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1322 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1323 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1324 | + |
|
| 1325 | + $boucles[$id_boucle]->partie = " |
|
| 1326 | 1326 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1327 | 1327 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1328 | 1328 | } |
@@ -1339,26 +1339,26 @@ discard block |
||
| 1339 | 1339 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1340 | 1340 | **/ |
| 1341 | 1341 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1342 | - if ($param[0]->type != 'texte') { |
|
| 1343 | - $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1344 | - if (isset($param[1]->texte)) { |
|
| 1345 | - preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1346 | - |
|
| 1347 | - return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1348 | - } else { |
|
| 1349 | - return array("intval($a1)", 0); |
|
| 1350 | - } |
|
| 1351 | - } else { |
|
| 1352 | - preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1353 | - $a1 = $m[1]; |
|
| 1354 | - if (empty($m[3])) { |
|
| 1355 | - return array($a1, 0); |
|
| 1356 | - } elseif (!empty($m[4])) { |
|
| 1357 | - return array($a1, $m[4]); |
|
| 1358 | - } else { |
|
| 1359 | - return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1360 | - } |
|
| 1361 | - } |
|
| 1342 | + if ($param[0]->type != 'texte') { |
|
| 1343 | + $a1 = calculer_liste(array($param[0]), array('id_mere' => $idb), $boucles, $boucles[$idb]->id_parent); |
|
| 1344 | + if (isset($param[1]->texte)) { |
|
| 1345 | + preg_match(',^ *(-([0-9]+))? *$,', $param[1]->texte, $m); |
|
| 1346 | + |
|
| 1347 | + return array("intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)); |
|
| 1348 | + } else { |
|
| 1349 | + return array("intval($a1)", 0); |
|
| 1350 | + } |
|
| 1351 | + } else { |
|
| 1352 | + preg_match(',^ *(([0-9]+)|n) *(- *([0-9]+)? *)?$,', $param[0]->texte, $m); |
|
| 1353 | + $a1 = $m[1]; |
|
| 1354 | + if (empty($m[3])) { |
|
| 1355 | + return array($a1, 0); |
|
| 1356 | + } elseif (!empty($m[4])) { |
|
| 1357 | + return array($a1, $m[4]); |
|
| 1358 | + } else { |
|
| 1359 | + return array($a1, calculer_liste(array($param[1]), array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 1360 | + } |
|
| 1361 | + } |
|
| 1362 | 1362 | } |
| 1363 | 1363 | |
| 1364 | 1364 | |
@@ -1385,47 +1385,47 @@ discard block |
||
| 1385 | 1385 | * array : Erreur sur un des critères |
| 1386 | 1386 | **/ |
| 1387 | 1387 | function calculer_criteres($idb, &$boucles) { |
| 1388 | - $msg = ''; |
|
| 1389 | - $boucle = $boucles[$idb]; |
|
| 1390 | - $table = strtoupper($boucle->type_requete); |
|
| 1391 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1392 | - |
|
| 1393 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1394 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1395 | - if (!is_array($boucle->criteres)) { |
|
| 1396 | - return array(); |
|
| 1397 | - } |
|
| 1398 | - |
|
| 1399 | - foreach ($boucle->criteres as $crit) { |
|
| 1400 | - $critere = $crit->op; |
|
| 1401 | - // critere personnalise ? |
|
| 1402 | - if ( |
|
| 1403 | - (!$serveur or |
|
| 1404 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1408 | - ) |
|
| 1409 | - ) |
|
| 1410 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1411 | - and (!function_exists($f = $f . "_dist")) |
|
| 1412 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1413 | - and (!function_exists($f = $f . "_dist")) |
|
| 1414 | - ) { |
|
| 1415 | - // fonction critere standard |
|
| 1416 | - $f = $defaut; |
|
| 1417 | - } |
|
| 1418 | - // compile le critere |
|
| 1419 | - $res = $f($idb, $boucles, $crit); |
|
| 1420 | - |
|
| 1421 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1422 | - if (is_array($res)) { |
|
| 1423 | - $msg = $res; |
|
| 1424 | - erreur_squelette($msg, $boucle); |
|
| 1425 | - } |
|
| 1426 | - } |
|
| 1427 | - |
|
| 1428 | - return $msg; |
|
| 1388 | + $msg = ''; |
|
| 1389 | + $boucle = $boucles[$idb]; |
|
| 1390 | + $table = strtoupper($boucle->type_requete); |
|
| 1391 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1392 | + |
|
| 1393 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1394 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1395 | + if (!is_array($boucle->criteres)) { |
|
| 1396 | + return array(); |
|
| 1397 | + } |
|
| 1398 | + |
|
| 1399 | + foreach ($boucle->criteres as $crit) { |
|
| 1400 | + $critere = $crit->op; |
|
| 1401 | + // critere personnalise ? |
|
| 1402 | + if ( |
|
| 1403 | + (!$serveur or |
|
| 1404 | + ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1405 | + and (!function_exists($f = $f . "_dist")) |
|
| 1406 | + and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1407 | + and (!function_exists($f = $f . "_dist")) |
|
| 1408 | + ) |
|
| 1409 | + ) |
|
| 1410 | + and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1411 | + and (!function_exists($f = $f . "_dist")) |
|
| 1412 | + and (!function_exists($f = "critere_" . $critere)) |
|
| 1413 | + and (!function_exists($f = $f . "_dist")) |
|
| 1414 | + ) { |
|
| 1415 | + // fonction critere standard |
|
| 1416 | + $f = $defaut; |
|
| 1417 | + } |
|
| 1418 | + // compile le critere |
|
| 1419 | + $res = $f($idb, $boucles, $crit); |
|
| 1420 | + |
|
| 1421 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1422 | + if (is_array($res)) { |
|
| 1423 | + $msg = $res; |
|
| 1424 | + erreur_squelette($msg, $boucle); |
|
| 1425 | + } |
|
| 1426 | + } |
|
| 1427 | + |
|
| 1428 | + return $msg; |
|
| 1429 | 1429 | } |
| 1430 | 1430 | |
| 1431 | 1431 | /** |
@@ -1442,11 +1442,11 @@ discard block |
||
| 1442 | 1442 | * @return string Code compilé rééchappé |
| 1443 | 1443 | */ |
| 1444 | 1444 | function kwote($lisp, $serveur = '', $type = '') { |
| 1445 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1446 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1447 | - } else { |
|
| 1448 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1449 | - } |
|
| 1445 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1446 | + return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1447 | + } else { |
|
| 1448 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1449 | + } |
|
| 1450 | 1450 | } |
| 1451 | 1451 | |
| 1452 | 1452 | |
@@ -1465,85 +1465,85 @@ discard block |
||
| 1465 | 1465 | * @return void |
| 1466 | 1466 | **/ |
| 1467 | 1467 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1468 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1469 | - if (!$r) { |
|
| 1470 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1471 | - } |
|
| 1472 | - list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1473 | - |
|
| 1474 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1475 | - |
|
| 1476 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1477 | - $where = $in; |
|
| 1478 | - if ($crit->cond) { |
|
| 1479 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1480 | - $where = array("'?'", $pred, $where, "''"); |
|
| 1481 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1482 | - { |
|
| 1483 | - $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1484 | - } |
|
| 1485 | - } |
|
| 1486 | - if ($crit->exclus) { |
|
| 1487 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1488 | - $where = array("'NOT'", $where); |
|
| 1489 | - } else |
|
| 1490 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1491 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1492 | - { |
|
| 1493 | - $where = array( |
|
| 1494 | - "'NOT'", |
|
| 1495 | - array( |
|
| 1496 | - "'IN'", |
|
| 1497 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1498 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1499 | - ) |
|
| 1500 | - ); |
|
| 1501 | - } |
|
| 1502 | - } |
|
| 1503 | - |
|
| 1504 | - $boucles[$idb]->where[] = $where; |
|
| 1505 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1506 | - { |
|
| 1507 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1508 | - } |
|
| 1468 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1469 | + if (!$r) { |
|
| 1470 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1471 | + } |
|
| 1472 | + list($arg, $op, $val, $col, $where_complement) = $r; |
|
| 1473 | + |
|
| 1474 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1475 | + |
|
| 1476 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1477 | + $where = $in; |
|
| 1478 | + if ($crit->cond) { |
|
| 1479 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1480 | + $where = array("'?'", $pred, $where, "''"); |
|
| 1481 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1482 | + { |
|
| 1483 | + $where_complement = array("'?'", $pred, $where_complement, "''"); |
|
| 1484 | + } |
|
| 1485 | + } |
|
| 1486 | + if ($crit->exclus) { |
|
| 1487 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1488 | + $where = array("'NOT'", $where); |
|
| 1489 | + } else |
|
| 1490 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1491 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1492 | + { |
|
| 1493 | + $where = array( |
|
| 1494 | + "'NOT'", |
|
| 1495 | + array( |
|
| 1496 | + "'IN'", |
|
| 1497 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1498 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1499 | + ) |
|
| 1500 | + ); |
|
| 1501 | + } |
|
| 1502 | + } |
|
| 1503 | + |
|
| 1504 | + $boucles[$idb]->where[] = $where; |
|
| 1505 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1506 | + { |
|
| 1507 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1508 | + } |
|
| 1509 | 1509 | } |
| 1510 | 1510 | |
| 1511 | 1511 | // http://code.spip.net/@critere_IN_cas |
| 1512 | 1512 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1513 | - static $num = array(); |
|
| 1514 | - $descr = $boucles[$idb]->descr; |
|
| 1515 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1516 | - |
|
| 1517 | - $var = '$in' . $cpt++; |
|
| 1518 | - $x = "\n\t$var = array();"; |
|
| 1519 | - foreach ($val as $k => $v) { |
|
| 1520 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1521 | - // optimiser le traitement des constantes |
|
| 1522 | - if (is_numeric($r[2])) { |
|
| 1523 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1524 | - } else { |
|
| 1525 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1526 | - } |
|
| 1527 | - } else { |
|
| 1528 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1529 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1530 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1531 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1532 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - |
|
| 1536 | - $boucles[$idb]->in .= $x; |
|
| 1537 | - |
|
| 1538 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1539 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1540 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1541 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1542 | - if (!$crit2) { |
|
| 1543 | - $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1544 | - } |
|
| 1545 | - |
|
| 1546 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1513 | + static $num = array(); |
|
| 1514 | + $descr = $boucles[$idb]->descr; |
|
| 1515 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1516 | + |
|
| 1517 | + $var = '$in' . $cpt++; |
|
| 1518 | + $x = "\n\t$var = array();"; |
|
| 1519 | + foreach ($val as $k => $v) { |
|
| 1520 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1521 | + // optimiser le traitement des constantes |
|
| 1522 | + if (is_numeric($r[2])) { |
|
| 1523 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1524 | + } else { |
|
| 1525 | + $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1526 | + } |
|
| 1527 | + } else { |
|
| 1528 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1529 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1530 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1531 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1532 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + |
|
| 1536 | + $boucles[$idb]->in .= $x; |
|
| 1537 | + |
|
| 1538 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1539 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1540 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1541 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1542 | + if (!$crit2) { |
|
| 1543 | + $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
|
| 1544 | + } |
|
| 1545 | + |
|
| 1546 | + return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1547 | 1547 | } |
| 1548 | 1548 | |
| 1549 | 1549 | /** |
@@ -1559,22 +1559,22 @@ discard block |
||
| 1559 | 1559 | * @return void |
| 1560 | 1560 | */ |
| 1561 | 1561 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1562 | - $boucle = &$boucles[$idb]; |
|
| 1563 | - if (isset($crit->param[0])) { |
|
| 1564 | - $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1565 | - } else { |
|
| 1566 | - $_where = '@$Pile[0]["where"]'; |
|
| 1567 | - } |
|
| 1568 | - |
|
| 1569 | - if ($crit->cond) { |
|
| 1570 | - $_where = "(($_where) ? ($_where) : '')"; |
|
| 1571 | - } |
|
| 1572 | - |
|
| 1573 | - if ($crit->not) { |
|
| 1574 | - $_where = "array('NOT',$_where)"; |
|
| 1575 | - } |
|
| 1576 | - |
|
| 1577 | - $boucle->where[] = $_where; |
|
| 1562 | + $boucle = &$boucles[$idb]; |
|
| 1563 | + if (isset($crit->param[0])) { |
|
| 1564 | + $_where = calculer_liste($crit->param[0], array(), $boucles, $boucle->id_parent); |
|
| 1565 | + } else { |
|
| 1566 | + $_where = '@$Pile[0]["where"]'; |
|
| 1567 | + } |
|
| 1568 | + |
|
| 1569 | + if ($crit->cond) { |
|
| 1570 | + $_where = "(($_where) ? ($_where) : '')"; |
|
| 1571 | + } |
|
| 1572 | + |
|
| 1573 | + if ($crit->not) { |
|
| 1574 | + $_where = "array('NOT',$_where)"; |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + $boucle->where[] = $_where; |
|
| 1578 | 1578 | } |
| 1579 | 1579 | |
| 1580 | 1580 | |
@@ -1630,27 +1630,27 @@ discard block |
||
| 1630 | 1630 | * @return void |
| 1631 | 1631 | */ |
| 1632 | 1632 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1633 | - $boucle = &$boucles[$idb]; |
|
| 1634 | - |
|
| 1635 | - // definition du champ par defaut |
|
| 1636 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1637 | - : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1638 | - $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1639 | - : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1640 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1641 | - : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1642 | - |
|
| 1643 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1644 | - |
|
| 1645 | - $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1646 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1647 | - |
|
| 1648 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1649 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1650 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1651 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1652 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1653 | - $boucle->hash .= " |
|
| 1633 | + $boucle = &$boucles[$idb]; |
|
| 1634 | + |
|
| 1635 | + // definition du champ par defaut |
|
| 1636 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1637 | + : calculer_liste(array($crit->param[0][0]), array(), $boucles, $boucle->id_parent); |
|
| 1638 | + $_sens_defaut = !isset($crit->param[1][0]) ? "1" |
|
| 1639 | + : calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
|
| 1640 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1641 | + : calculer_liste(array($crit->param[2][0]), array(), $boucles, $boucle->id_parent); |
|
| 1642 | + |
|
| 1643 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1644 | + |
|
| 1645 | + $_sens_defaut = "(is_array(\$s=$_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1646 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1647 | + |
|
| 1648 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1649 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1650 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1651 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1652 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1653 | + $boucle->hash .= " |
|
| 1654 | 1654 | \$senstri = ''; |
| 1655 | 1655 | \$tri = $_tri; |
| 1656 | 1656 | if (\$tri){ |
@@ -1658,8 +1658,8 @@ discard block |
||
| 1658 | 1658 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1659 | 1659 | }; |
| 1660 | 1660 | "; |
| 1661 | - $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1662 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1661 | + $boucle->select[] = "\".tri_champ_select(\$tri).\""; |
|
| 1662 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from']).\$senstri"; |
|
| 1663 | 1663 | } |
| 1664 | 1664 | |
| 1665 | 1665 | # Criteres de comparaison |
@@ -1676,20 +1676,20 @@ discard block |
||
| 1676 | 1676 | * @return void |
| 1677 | 1677 | **/ |
| 1678 | 1678 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1679 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1680 | - if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1681 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1682 | - } |
|
| 1683 | - |
|
| 1684 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1685 | - if (!$r) { |
|
| 1686 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1687 | - # if (!$crit->cond) { |
|
| 1688 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1689 | - # } |
|
| 1690 | - } else { |
|
| 1691 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1692 | - } |
|
| 1679 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1680 | + if (($crit->op == ",") or ($crit->op == '/')) { |
|
| 1681 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1682 | + } |
|
| 1683 | + |
|
| 1684 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1685 | + if (!$r) { |
|
| 1686 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1687 | + # if (!$crit->cond) { |
|
| 1688 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op))); |
|
| 1689 | + # } |
|
| 1690 | + } else { |
|
| 1691 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1692 | + } |
|
| 1693 | 1693 | } |
| 1694 | 1694 | |
| 1695 | 1695 | |
@@ -1709,63 +1709,63 @@ discard block |
||
| 1709 | 1709 | * @return void |
| 1710 | 1710 | **/ |
| 1711 | 1711 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1712 | - list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1713 | - |
|
| 1714 | - $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1715 | - |
|
| 1716 | - // inserer la negation (cf !...) |
|
| 1717 | - |
|
| 1718 | - if ($crit->not) { |
|
| 1719 | - $where = array("'NOT'", $where); |
|
| 1720 | - } |
|
| 1721 | - if ($crit->exclus) { |
|
| 1722 | - if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1723 | - $where = array("'NOT'", $where); |
|
| 1724 | - } else |
|
| 1725 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1726 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1727 | - { |
|
| 1728 | - $where = array( |
|
| 1729 | - "'NOT'", |
|
| 1730 | - array( |
|
| 1731 | - "'IN'", |
|
| 1732 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1733 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1734 | - ) |
|
| 1735 | - ); |
|
| 1736 | - } |
|
| 1737 | - } |
|
| 1738 | - |
|
| 1739 | - // inserer la condition (cf {lang?}) |
|
| 1740 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1741 | - if ($crit->cond) { |
|
| 1742 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1743 | - if ($col == "date" or $col == "date_redac") { |
|
| 1744 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1745 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1746 | - } |
|
| 1747 | - } |
|
| 1748 | - |
|
| 1749 | - if ($op == '=' and !$crit->not) { |
|
| 1750 | - $where = array( |
|
| 1751 | - "'?'", |
|
| 1752 | - "(is_array($pred))", |
|
| 1753 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1754 | - $where |
|
| 1755 | - ); |
|
| 1756 | - } |
|
| 1757 | - $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1758 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1759 | - { |
|
| 1760 | - $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1761 | - } |
|
| 1762 | - } |
|
| 1763 | - |
|
| 1764 | - $boucles[$idb]->where[] = $where; |
|
| 1765 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1766 | - { |
|
| 1767 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1768 | - } |
|
| 1712 | + list($arg, $op, $val, $col, $where_complement) = $args; |
|
| 1713 | + |
|
| 1714 | + $where = array("'$op'", "'$arg'", $val[0]); |
|
| 1715 | + |
|
| 1716 | + // inserer la negation (cf !...) |
|
| 1717 | + |
|
| 1718 | + if ($crit->not) { |
|
| 1719 | + $where = array("'NOT'", $where); |
|
| 1720 | + } |
|
| 1721 | + if ($crit->exclus) { |
|
| 1722 | + if (!preg_match(",^L[0-9]+[.],", $arg)) { |
|
| 1723 | + $where = array("'NOT'", $where); |
|
| 1724 | + } else |
|
| 1725 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1726 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1727 | + { |
|
| 1728 | + $where = array( |
|
| 1729 | + "'NOT'", |
|
| 1730 | + array( |
|
| 1731 | + "'IN'", |
|
| 1732 | + "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1733 | + array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1734 | + ) |
|
| 1735 | + ); |
|
| 1736 | + } |
|
| 1737 | + } |
|
| 1738 | + |
|
| 1739 | + // inserer la condition (cf {lang?}) |
|
| 1740 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1741 | + if ($crit->cond) { |
|
| 1742 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1743 | + if ($col == "date" or $col == "date_redac") { |
|
| 1744 | + if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1745 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1746 | + } |
|
| 1747 | + } |
|
| 1748 | + |
|
| 1749 | + if ($op == '=' and !$crit->not) { |
|
| 1750 | + $where = array( |
|
| 1751 | + "'?'", |
|
| 1752 | + "(is_array($pred))", |
|
| 1753 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, array($pred), $col), |
|
| 1754 | + $where |
|
| 1755 | + ); |
|
| 1756 | + } |
|
| 1757 | + $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
|
| 1758 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1759 | + { |
|
| 1760 | + $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
|
| 1761 | + } |
|
| 1762 | + } |
|
| 1763 | + |
|
| 1764 | + $boucles[$idb]->where[] = $where; |
|
| 1765 | + if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1766 | + { |
|
| 1767 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1768 | + } |
|
| 1769 | 1769 | } |
| 1770 | 1770 | |
| 1771 | 1771 | |
@@ -1806,167 +1806,167 @@ discard block |
||
| 1806 | 1806 | **/ |
| 1807 | 1807 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1808 | 1808 | |
| 1809 | - $boucle = &$boucles[$idb]; |
|
| 1810 | - $type = $boucle->type_requete; |
|
| 1811 | - $table = $boucle->id_table; |
|
| 1812 | - $desc = $boucle->show; |
|
| 1813 | - $col_vraie = null; |
|
| 1814 | - |
|
| 1815 | - list($fct, $col, $op, $val, $args_sql) = |
|
| 1816 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1817 | - |
|
| 1818 | - $col_alias = $col; |
|
| 1819 | - $where_complement = false; |
|
| 1820 | - |
|
| 1821 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1822 | - if ($col == 'id_enfant') { |
|
| 1823 | - $col = $boucle->primary; |
|
| 1824 | - } |
|
| 1825 | - |
|
| 1826 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1827 | - if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1828 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1829 | - ) { |
|
| 1830 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1831 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1832 | - else { |
|
| 1833 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1834 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1835 | - } |
|
| 1836 | - |
|
| 1837 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1838 | - // sauf si exception declaree : sauter cette etape |
|
| 1839 | - else { |
|
| 1840 | - if ( |
|
| 1841 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1842 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1843 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1844 | - ) { |
|
| 1845 | - $e = decompose_champ_id_objet($col); |
|
| 1846 | - $col = array_shift($e); |
|
| 1847 | - $where_complement = primary_doublee($e, $table); |
|
| 1848 | - } // Cas particulier : expressions de date |
|
| 1849 | - else { |
|
| 1850 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1851 | - list($col, $col_vraie) = $c; |
|
| 1852 | - $table = ''; |
|
| 1853 | - } // table explicitée {mots.titre} |
|
| 1854 | - else { |
|
| 1855 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1856 | - list(, $table, $col) = $r; |
|
| 1857 | - $col_alias = $col; |
|
| 1858 | - |
|
| 1859 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1860 | - if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1861 | - and isset($desc['field'][$col]) |
|
| 1862 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 1863 | - ) { |
|
| 1864 | - $table = $cle; |
|
| 1865 | - } else { |
|
| 1866 | - $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1867 | - } |
|
| 1868 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1869 | - if (!$table) { |
|
| 1870 | - return ''; |
|
| 1871 | - } |
|
| 1872 | - } |
|
| 1873 | - // si le champ n'est pas trouvé dans la table, |
|
| 1874 | - // on cherche si une jointure peut l'obtenir |
|
| 1875 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 1876 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1877 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 1878 | - $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 1879 | - } |
|
| 1880 | - else { |
|
| 1881 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1882 | - if (!$r) { |
|
| 1883 | - return ''; |
|
| 1884 | - } |
|
| 1885 | - list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1886 | - } |
|
| 1887 | - } |
|
| 1888 | - } |
|
| 1889 | - } |
|
| 1890 | - } |
|
| 1891 | - } |
|
| 1892 | - |
|
| 1893 | - $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 1894 | - // Dans tous les cas, |
|
| 1895 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 1896 | - // et passer dans sql_quote avec le type si connu |
|
| 1897 | - // et int sinon si la valeur est numerique |
|
| 1898 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1899 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1900 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 1901 | - $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 1902 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1903 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1904 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 1905 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 1906 | - } |
|
| 1907 | - // sinon expliciter les |
|
| 1908 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1909 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1910 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 1911 | - // sans toucher aux |
|
| 1912 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1913 | - // sql_quote(truc,'','varchar') |
|
| 1914 | - elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1915 | - // si pas deja un type |
|
| 1916 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 1917 | - ) { |
|
| 1918 | - $r = $r[1] |
|
| 1919 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 1920 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 1921 | - $val[0] = "sql_quote($r)"; |
|
| 1922 | - } |
|
| 1923 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1924 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 1925 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 1926 | - } |
|
| 1927 | - } |
|
| 1928 | - |
|
| 1929 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1930 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 1931 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 1932 | - } |
|
| 1933 | - |
|
| 1934 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1935 | - // leurs requetes par defaut, notamment le champ statut |
|
| 1936 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 1937 | - if ($table === $boucle->id_table) { |
|
| 1938 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1939 | - if ($col_alias != $col_vraie) { |
|
| 1940 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1941 | - } |
|
| 1942 | - } |
|
| 1943 | - |
|
| 1944 | - // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1945 | - // il faut alors interdire a la fonction de boucle |
|
| 1946 | - // de mettre ses propres criteres de statut |
|
| 1947 | - // http://www.spip.net/@statut (a documenter) |
|
| 1948 | - // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1949 | - if ($col == 'statut') { |
|
| 1950 | - $boucles[$idb]->statut = true; |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 1954 | - if ($table) { |
|
| 1955 | - if ($col[0] == "`") { |
|
| 1956 | - $arg = "$table." . substr($col, 1, -1); |
|
| 1957 | - } else { |
|
| 1958 | - $arg = "$table.$col"; |
|
| 1959 | - } |
|
| 1960 | - } else { |
|
| 1961 | - $arg = $col; |
|
| 1962 | - } |
|
| 1963 | - |
|
| 1964 | - // inserer la fonction SQL |
|
| 1965 | - if ($fct) { |
|
| 1966 | - $arg = "$fct($arg$args_sql)"; |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1809 | + $boucle = &$boucles[$idb]; |
|
| 1810 | + $type = $boucle->type_requete; |
|
| 1811 | + $table = $boucle->id_table; |
|
| 1812 | + $desc = $boucle->show; |
|
| 1813 | + $col_vraie = null; |
|
| 1814 | + |
|
| 1815 | + list($fct, $col, $op, $val, $args_sql) = |
|
| 1816 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 1817 | + |
|
| 1818 | + $col_alias = $col; |
|
| 1819 | + $where_complement = false; |
|
| 1820 | + |
|
| 1821 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 1822 | + if ($col == 'id_enfant') { |
|
| 1823 | + $col = $boucle->primary; |
|
| 1824 | + } |
|
| 1825 | + |
|
| 1826 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 1827 | + if ((in_array($col, array('id_parent', 'id_secteur')) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1828 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 1829 | + ) { |
|
| 1830 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 1831 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 1832 | + else { |
|
| 1833 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", "public", true))) { |
|
| 1834 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 1835 | + } |
|
| 1836 | + |
|
| 1837 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 1838 | + // sauf si exception declaree : sauter cette etape |
|
| 1839 | + else { |
|
| 1840 | + if ( |
|
| 1841 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 1842 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 1843 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 1844 | + ) { |
|
| 1845 | + $e = decompose_champ_id_objet($col); |
|
| 1846 | + $col = array_shift($e); |
|
| 1847 | + $where_complement = primary_doublee($e, $table); |
|
| 1848 | + } // Cas particulier : expressions de date |
|
| 1849 | + else { |
|
| 1850 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 1851 | + list($col, $col_vraie) = $c; |
|
| 1852 | + $table = ''; |
|
| 1853 | + } // table explicitée {mots.titre} |
|
| 1854 | + else { |
|
| 1855 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 1856 | + list(, $table, $col) = $r; |
|
| 1857 | + $col_alias = $col; |
|
| 1858 | + |
|
| 1859 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1860 | + if ($desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 1861 | + and isset($desc['field'][$col]) |
|
| 1862 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 1863 | + ) { |
|
| 1864 | + $table = $cle; |
|
| 1865 | + } else { |
|
| 1866 | + $table = trouver_jointure_champ($col, $boucle, array($table), ($crit->cond or $op != '=')); |
|
| 1867 | + } |
|
| 1868 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 1869 | + if (!$table) { |
|
| 1870 | + return ''; |
|
| 1871 | + } |
|
| 1872 | + } |
|
| 1873 | + // si le champ n'est pas trouvé dans la table, |
|
| 1874 | + // on cherche si une jointure peut l'obtenir |
|
| 1875 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 1876 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 1877 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 1878 | + $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 1879 | + } |
|
| 1880 | + else { |
|
| 1881 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 1882 | + if (!$r) { |
|
| 1883 | + return ''; |
|
| 1884 | + } |
|
| 1885 | + list($col, $col_alias, $table, $where_complement, $desc) = $r; |
|
| 1886 | + } |
|
| 1887 | + } |
|
| 1888 | + } |
|
| 1889 | + } |
|
| 1890 | + } |
|
| 1891 | + } |
|
| 1892 | + |
|
| 1893 | + $col_vraie = ($col_vraie ? $col_vraie : $col); |
|
| 1894 | + // Dans tous les cas, |
|
| 1895 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 1896 | + // et passer dans sql_quote avec le type si connu |
|
| 1897 | + // et int sinon si la valeur est numerique |
|
| 1898 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 1899 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 1900 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 1901 | + $type_cast_quote = (isset($desc['field'][$col_vraie]) ? $desc['field'][$col_vraie] : 'int NOT NULL'); |
|
| 1902 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 1903 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 1904 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 1905 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 1906 | + } |
|
| 1907 | + // sinon expliciter les |
|
| 1908 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 1909 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 1910 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 1911 | + // sans toucher aux |
|
| 1912 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 1913 | + // sql_quote(truc,'','varchar') |
|
| 1914 | + elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 1915 | + // si pas deja un type |
|
| 1916 | + and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 1917 | + ) { |
|
| 1918 | + $r = $r[1] |
|
| 1919 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 1920 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 1921 | + $val[0] = "sql_quote($r)"; |
|
| 1922 | + } |
|
| 1923 | + elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1924 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 1925 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 1926 | + } |
|
| 1927 | + } |
|
| 1928 | + |
|
| 1929 | + if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1930 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
|
| 1931 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 1932 | + } |
|
| 1933 | + |
|
| 1934 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 1935 | + // leurs requetes par defaut, notamment le champ statut |
|
| 1936 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 1937 | + if ($table === $boucle->id_table) { |
|
| 1938 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 1939 | + if ($col_alias != $col_vraie) { |
|
| 1940 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 1941 | + } |
|
| 1942 | + } |
|
| 1943 | + |
|
| 1944 | + // ajout pour le cas special d'une condition sur le champ statut: |
|
| 1945 | + // il faut alors interdire a la fonction de boucle |
|
| 1946 | + // de mettre ses propres criteres de statut |
|
| 1947 | + // http://www.spip.net/@statut (a documenter) |
|
| 1948 | + // garde pour compatibilite avec code des plugins anterieurs, mais redondant avec la ligne precedente |
|
| 1949 | + if ($col == 'statut') { |
|
| 1950 | + $boucles[$idb]->statut = true; |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 1954 | + if ($table) { |
|
| 1955 | + if ($col[0] == "`") { |
|
| 1956 | + $arg = "$table." . substr($col, 1, -1); |
|
| 1957 | + } else { |
|
| 1958 | + $arg = "$table.$col"; |
|
| 1959 | + } |
|
| 1960 | + } else { |
|
| 1961 | + $arg = $col; |
|
| 1962 | + } |
|
| 1963 | + |
|
| 1964 | + // inserer la fonction SQL |
|
| 1965 | + if ($fct) { |
|
| 1966 | + $arg = "$fct($arg$args_sql)"; |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + return array($arg, $op, $val, $col_alias, $where_complement); |
|
| 1970 | 1970 | } |
| 1971 | 1971 | |
| 1972 | 1972 | |
@@ -1995,77 +1995,77 @@ discard block |
||
| 1995 | 1995 | **/ |
| 1996 | 1996 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 1997 | 1997 | |
| 1998 | - $where = ''; |
|
| 1999 | - |
|
| 2000 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2001 | - // gestion par les plugins des jointures tordues |
|
| 2002 | - // pas automatiques mais necessaires |
|
| 2003 | - $table_sql = table_objet_sql($table); |
|
| 2004 | - if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2005 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2006 | - and |
|
| 2007 | - ( |
|
| 2008 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2009 | - or |
|
| 2010 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2011 | - ) |
|
| 2012 | - ) { |
|
| 2013 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2014 | - $index = isset($t[$col]) |
|
| 2015 | - ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2016 | - |
|
| 2017 | - if (count($index) == 3) { |
|
| 2018 | - list($t, $col, $calculer_critere_externe) = $index; |
|
| 2019 | - } elseif (count($index) == 2) { |
|
| 2020 | - list($t, $col) = $t[$col]; |
|
| 2021 | - } elseif (count($index) == 1) { |
|
| 2022 | - list($calculer_critere_externe) = $index; |
|
| 2023 | - $t = $table; |
|
| 2024 | - } else { |
|
| 2025 | - $t = ''; |
|
| 2026 | - } // jointure non declaree. La trouver. |
|
| 2027 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2028 | - list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2029 | - } else { |
|
| 2030 | - $t = ''; |
|
| 2031 | - } // jointure non declaree. La trouver. |
|
| 2032 | - |
|
| 2033 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2034 | - |
|
| 2035 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2036 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2037 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2038 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2039 | - $table = ""; |
|
| 2040 | - if ($boucle->jointures_explicites) { |
|
| 2041 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2042 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2043 | - } |
|
| 2044 | - |
|
| 2045 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2046 | - if (!$table) { |
|
| 2047 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2048 | - } |
|
| 2049 | - |
|
| 2050 | - if (!$table) { |
|
| 2051 | - return ''; |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2055 | - list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2056 | - |
|
| 2057 | - if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2058 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2059 | - if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2060 | - $e = decompose_champ_id_objet($col); |
|
| 2061 | - $col = array_shift($e); |
|
| 2062 | - $where = primary_doublee($e, $table); |
|
| 2063 | - } else { |
|
| 2064 | - $col = reset($cle); |
|
| 2065 | - } |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - return array($col, $col_alias, $table, $where, $desc); |
|
| 1998 | + $where = ''; |
|
| 1999 | + |
|
| 2000 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2001 | + // gestion par les plugins des jointures tordues |
|
| 2002 | + // pas automatiques mais necessaires |
|
| 2003 | + $table_sql = table_objet_sql($table); |
|
| 2004 | + if (isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2005 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2006 | + and |
|
| 2007 | + ( |
|
| 2008 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2009 | + or |
|
| 2010 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2011 | + ) |
|
| 2012 | + ) { |
|
| 2013 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2014 | + $index = isset($t[$col]) |
|
| 2015 | + ? $t[$col] : (isset($t['']) ? $t[''] : array()); |
|
| 2016 | + |
|
| 2017 | + if (count($index) == 3) { |
|
| 2018 | + list($t, $col, $calculer_critere_externe) = $index; |
|
| 2019 | + } elseif (count($index) == 2) { |
|
| 2020 | + list($t, $col) = $t[$col]; |
|
| 2021 | + } elseif (count($index) == 1) { |
|
| 2022 | + list($calculer_critere_externe) = $index; |
|
| 2023 | + $t = $table; |
|
| 2024 | + } else { |
|
| 2025 | + $t = ''; |
|
| 2026 | + } // jointure non declaree. La trouver. |
|
| 2027 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2028 | + list($t, $col) = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2029 | + } else { |
|
| 2030 | + $t = ''; |
|
| 2031 | + } // jointure non declaree. La trouver. |
|
| 2032 | + |
|
| 2033 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2034 | + |
|
| 2035 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2036 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2037 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2038 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2039 | + $table = ""; |
|
| 2040 | + if ($boucle->jointures_explicites) { |
|
| 2041 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2042 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2043 | + } |
|
| 2044 | + |
|
| 2045 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2046 | + if (!$table) { |
|
| 2047 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2048 | + } |
|
| 2049 | + |
|
| 2050 | + if (!$table) { |
|
| 2051 | + return ''; |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2055 | + list($nom, $desc, $cle) = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2056 | + |
|
| 2057 | + if (count($cle) > 1 or reset($cle) !== $col) { |
|
| 2058 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2059 | + if (count($cle) > 1 and reset($cle) == 'id_objet') { |
|
| 2060 | + $e = decompose_champ_id_objet($col); |
|
| 2061 | + $col = array_shift($e); |
|
| 2062 | + $where = primary_doublee($e, $table); |
|
| 2063 | + } else { |
|
| 2064 | + $col = reset($cle); |
|
| 2065 | + } |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + return array($col, $col_alias, $table, $where, $desc); |
|
| 2069 | 2069 | } |
| 2070 | 2070 | |
| 2071 | 2071 | |
@@ -2086,10 +2086,10 @@ discard block |
||
| 2086 | 2086 | * - valeur |
| 2087 | 2087 | **/ |
| 2088 | 2088 | function primary_doublee($decompose, $table) { |
| 2089 | - $e1 = reset($decompose); |
|
| 2090 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2089 | + $e1 = reset($decompose); |
|
| 2090 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2091 | 2091 | |
| 2092 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2092 | + return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2093 | 2093 | } |
| 2094 | 2094 | |
| 2095 | 2095 | /** |
@@ -2120,56 +2120,56 @@ discard block |
||
| 2120 | 2120 | * Vide sinon. |
| 2121 | 2121 | */ |
| 2122 | 2122 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2123 | - // si on demande un truc du genre spip_mots |
|
| 2124 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2125 | - // et qu'on est la |
|
| 2126 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2127 | - if ($checkarrivee |
|
| 2128 | - and is_string($checkarrivee) |
|
| 2129 | - and $a = table_objet($checkarrivee) |
|
| 2130 | - and in_array($a . '_liens', $joints) |
|
| 2131 | - ) { |
|
| 2132 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2133 | - return $res; |
|
| 2134 | - } |
|
| 2135 | - } |
|
| 2136 | - foreach ($joints as $joint) { |
|
| 2137 | - if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2138 | - // alias de table dans le from |
|
| 2139 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2140 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2141 | - $cols = $arrivee[2]; |
|
| 2142 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2143 | - if (count($cols) > 2) { |
|
| 2144 | - array_pop($cols); |
|
| 2145 | - } |
|
| 2146 | - if ($t) { |
|
| 2147 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2148 | - $joindre = false; |
|
| 2149 | - foreach ($cols as $col) { |
|
| 2150 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2151 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2152 | - $joindre = true; |
|
| 2153 | - } else { |
|
| 2154 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2155 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2156 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2157 | - $joindre = true; |
|
| 2158 | - } |
|
| 2159 | - } |
|
| 2160 | - } |
|
| 2161 | - if (!$joindre) { |
|
| 2162 | - return $t; |
|
| 2163 | - } |
|
| 2164 | - } |
|
| 2165 | - array_pop($arrivee); |
|
| 2166 | - if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2167 | - return $res; |
|
| 2168 | - } |
|
| 2169 | - } |
|
| 2170 | - } |
|
| 2171 | - |
|
| 2172 | - return ''; |
|
| 2123 | + // si on demande un truc du genre spip_mots |
|
| 2124 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2125 | + // et qu'on est la |
|
| 2126 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2127 | + if ($checkarrivee |
|
| 2128 | + and is_string($checkarrivee) |
|
| 2129 | + and $a = table_objet($checkarrivee) |
|
| 2130 | + and in_array($a . '_liens', $joints) |
|
| 2131 | + ) { |
|
| 2132 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2133 | + return $res; |
|
| 2134 | + } |
|
| 2135 | + } |
|
| 2136 | + foreach ($joints as $joint) { |
|
| 2137 | + if ($arrivee = trouver_champ_exterieur($col, array($joint), $boucle, $checkarrivee)) { |
|
| 2138 | + // alias de table dans le from |
|
| 2139 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2140 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2141 | + $cols = $arrivee[2]; |
|
| 2142 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2143 | + if (count($cols) > 2) { |
|
| 2144 | + array_pop($cols); |
|
| 2145 | + } |
|
| 2146 | + if ($t) { |
|
| 2147 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2148 | + $joindre = false; |
|
| 2149 | + foreach ($cols as $col) { |
|
| 2150 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2151 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2152 | + $joindre = true; |
|
| 2153 | + } else { |
|
| 2154 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2155 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2156 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2157 | + $joindre = true; |
|
| 2158 | + } |
|
| 2159 | + } |
|
| 2160 | + } |
|
| 2161 | + if (!$joindre) { |
|
| 2162 | + return $t; |
|
| 2163 | + } |
|
| 2164 | + } |
|
| 2165 | + array_pop($arrivee); |
|
| 2166 | + if ($res = calculer_jointure($boucle, array($boucle->id_table, $desc), $arrivee, $cols, $cond, 1)) { |
|
| 2167 | + return $res; |
|
| 2168 | + } |
|
| 2169 | + } |
|
| 2170 | + } |
|
| 2171 | + |
|
| 2172 | + return ''; |
|
| 2173 | 2173 | |
| 2174 | 2174 | } |
| 2175 | 2175 | |
@@ -2196,29 +2196,29 @@ discard block |
||
| 2196 | 2196 | * Alias de la table de jointure (Lx) |
| 2197 | 2197 | */ |
| 2198 | 2198 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2199 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2200 | - |
|
| 2201 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2202 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2203 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2204 | - |
|
| 2205 | - if (!$intermediaire or !$arrivee) { |
|
| 2206 | - return ''; |
|
| 2207 | - } |
|
| 2208 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2209 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2210 | - |
|
| 2211 | - $res = fabrique_jointures($boucle, |
|
| 2212 | - array( |
|
| 2213 | - array( |
|
| 2214 | - $boucle->id_table, |
|
| 2215 | - $intermediaire, |
|
| 2216 | - array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2217 | - ), |
|
| 2218 | - array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2219 | - ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2220 | - |
|
| 2221 | - return $res; |
|
| 2199 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2200 | + |
|
| 2201 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2202 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2203 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2204 | + |
|
| 2205 | + if (!$intermediaire or !$arrivee) { |
|
| 2206 | + return ''; |
|
| 2207 | + } |
|
| 2208 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2209 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2210 | + |
|
| 2211 | + $res = fabrique_jointures($boucle, |
|
| 2212 | + array( |
|
| 2213 | + array( |
|
| 2214 | + $boucle->id_table, |
|
| 2215 | + $intermediaire, |
|
| 2216 | + array(id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']) |
|
| 2217 | + ), |
|
| 2218 | + array(reset($intermediaire), $arrivee, $primary_arrivee) |
|
| 2219 | + ), $cond, $desc, $boucle->id_table, array($col)); |
|
| 2220 | + |
|
| 2221 | + return $res; |
|
| 2222 | 2222 | } |
| 2223 | 2223 | |
| 2224 | 2224 | |
@@ -2235,17 +2235,17 @@ discard block |
||
| 2235 | 2235 | * false sinon. |
| 2236 | 2236 | **/ |
| 2237 | 2237 | function trouver_champ($champ, $where) { |
| 2238 | - if (!is_array($where)) { |
|
| 2239 | - return preg_match($champ, $where); |
|
| 2240 | - } else { |
|
| 2241 | - foreach ($where as $clause) { |
|
| 2242 | - if (trouver_champ($champ, $clause)) { |
|
| 2243 | - return true; |
|
| 2244 | - } |
|
| 2245 | - } |
|
| 2246 | - |
|
| 2247 | - return false; |
|
| 2248 | - } |
|
| 2238 | + if (!is_array($where)) { |
|
| 2239 | + return preg_match($champ, $where); |
|
| 2240 | + } else { |
|
| 2241 | + foreach ($where as $clause) { |
|
| 2242 | + if (trouver_champ($champ, $clause)) { |
|
| 2243 | + return true; |
|
| 2244 | + } |
|
| 2245 | + } |
|
| 2246 | + |
|
| 2247 | + return false; |
|
| 2248 | + } |
|
| 2249 | 2249 | } |
| 2250 | 2250 | |
| 2251 | 2251 | |
@@ -2271,129 +2271,129 @@ discard block |
||
| 2271 | 2271 | * - string $args_sql Suite des arguments du critère. ? |
| 2272 | 2272 | **/ |
| 2273 | 2273 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2274 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2275 | - if (count($crit->param) == 0) { |
|
| 2276 | - $op = '='; |
|
| 2277 | - $col = $val = $crit->op; |
|
| 2278 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2279 | - $val = $r[2]; |
|
| 2280 | - } |
|
| 2281 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2282 | - if ($val == 'lang') { |
|
| 2283 | - $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2284 | - } else { |
|
| 2285 | - $defaut = null; |
|
| 2286 | - if ($val == 'id_parent') { |
|
| 2287 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2288 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2289 | - // pour eviter l'erreur SQL |
|
| 2290 | - $val = $boucles[$idb]->primary; |
|
| 2291 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2292 | - $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2293 | - } elseif ($val == 'id_enfant') { |
|
| 2294 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2295 | - // de la boucle superieure |
|
| 2296 | - $val = 'id_parent'; |
|
| 2297 | - } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2298 | - // un critere conditionnel sur date est traite a part |
|
| 2299 | - // car la date est mise d'office par SPIP, |
|
| 2300 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2301 | - } |
|
| 2302 | - |
|
| 2303 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2304 | - $val = array(kwote($val)); |
|
| 2305 | - } |
|
| 2306 | - } else { |
|
| 2307 | - // comparaison explicite |
|
| 2308 | - // le phraseur impose que le premier param soit du texte |
|
| 2309 | - $params = $crit->param; |
|
| 2310 | - $op = $crit->op; |
|
| 2311 | - if ($op == '==') { |
|
| 2312 | - $op = 'REGEXP'; |
|
| 2313 | - } |
|
| 2314 | - $col = array_shift($params); |
|
| 2315 | - $col = $col[0]->texte; |
|
| 2316 | - |
|
| 2317 | - $val = array(); |
|
| 2318 | - $desc = array('id_mere' => $idb); |
|
| 2319 | - $parent = $boucles[$idb]->id_parent; |
|
| 2320 | - |
|
| 2321 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2322 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2323 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2324 | - if (count($params) == 1 |
|
| 2325 | - and count($params[0]) == 3 |
|
| 2326 | - and $params[0][0]->type == 'texte' |
|
| 2327 | - and $params[0][2]->type == 'texte' |
|
| 2328 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2329 | - and (($p == "'") or ($p == '"')) |
|
| 2330 | - and $params[0][1]->type == 'champ' |
|
| 2331 | - ) { |
|
| 2332 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2333 | - } else { |
|
| 2334 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2335 | - $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2336 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2337 | - $val[] = $a; |
|
| 2338 | - } else { |
|
| 2339 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2340 | - } // toujours quoter en char ici |
|
| 2341 | - } |
|
| 2342 | - } |
|
| 2343 | - } |
|
| 2344 | - |
|
| 2345 | - $fct = $args_sql = ''; |
|
| 2346 | - // fonction SQL ? |
|
| 2347 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2348 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2349 | - $fct = $m[1]; |
|
| 2350 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2351 | - $col = $a[1]; |
|
| 2352 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2353 | - $col = $m[1]; |
|
| 2354 | - $args_sql = $m[2]; |
|
| 2355 | - } |
|
| 2356 | - $args_sql .= $a[2]; |
|
| 2357 | - } |
|
| 2358 | - |
|
| 2359 | - return array($fct, $col, $op, $val, $args_sql); |
|
| 2274 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2275 | + if (count($crit->param) == 0) { |
|
| 2276 | + $op = '='; |
|
| 2277 | + $col = $val = $crit->op; |
|
| 2278 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2279 | + $val = $r[2]; |
|
| 2280 | + } |
|
| 2281 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2282 | + if ($val == 'lang') { |
|
| 2283 | + $val = array(kwote('$GLOBALS[\'spip_lang\']')); |
|
| 2284 | + } else { |
|
| 2285 | + $defaut = null; |
|
| 2286 | + if ($val == 'id_parent') { |
|
| 2287 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2288 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2289 | + // pour eviter l'erreur SQL |
|
| 2290 | + $val = $boucles[$idb]->primary; |
|
| 2291 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2292 | + $defaut = "@\$Pile[0]['id_parent']"; |
|
| 2293 | + } elseif ($val == 'id_enfant') { |
|
| 2294 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2295 | + // de la boucle superieure |
|
| 2296 | + $val = 'id_parent'; |
|
| 2297 | + } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
|
| 2298 | + // un critere conditionnel sur date est traite a part |
|
| 2299 | + // car la date est mise d'office par SPIP, |
|
| 2300 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2301 | + } |
|
| 2302 | + |
|
| 2303 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2304 | + $val = array(kwote($val)); |
|
| 2305 | + } |
|
| 2306 | + } else { |
|
| 2307 | + // comparaison explicite |
|
| 2308 | + // le phraseur impose que le premier param soit du texte |
|
| 2309 | + $params = $crit->param; |
|
| 2310 | + $op = $crit->op; |
|
| 2311 | + if ($op == '==') { |
|
| 2312 | + $op = 'REGEXP'; |
|
| 2313 | + } |
|
| 2314 | + $col = array_shift($params); |
|
| 2315 | + $col = $col[0]->texte; |
|
| 2316 | + |
|
| 2317 | + $val = array(); |
|
| 2318 | + $desc = array('id_mere' => $idb); |
|
| 2319 | + $parent = $boucles[$idb]->id_parent; |
|
| 2320 | + |
|
| 2321 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2322 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2323 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2324 | + if (count($params) == 1 |
|
| 2325 | + and count($params[0]) == 3 |
|
| 2326 | + and $params[0][0]->type == 'texte' |
|
| 2327 | + and $params[0][2]->type == 'texte' |
|
| 2328 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2329 | + and (($p == "'") or ($p == '"')) |
|
| 2330 | + and $params[0][1]->type == 'champ' |
|
| 2331 | + ) { |
|
| 2332 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2333 | + } else { |
|
| 2334 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2335 | + $a = calculer_liste($p, $desc, $boucles, $parent); |
|
| 2336 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2337 | + $val[] = $a; |
|
| 2338 | + } else { |
|
| 2339 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2340 | + } // toujours quoter en char ici |
|
| 2341 | + } |
|
| 2342 | + } |
|
| 2343 | + } |
|
| 2344 | + |
|
| 2345 | + $fct = $args_sql = ''; |
|
| 2346 | + // fonction SQL ? |
|
| 2347 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2348 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2349 | + $fct = $m[1]; |
|
| 2350 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2351 | + $col = $a[1]; |
|
| 2352 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2353 | + $col = $m[1]; |
|
| 2354 | + $args_sql = $m[2]; |
|
| 2355 | + } |
|
| 2356 | + $args_sql .= $a[2]; |
|
| 2357 | + } |
|
| 2358 | + |
|
| 2359 | + return array($fct, $col, $op, $val, $args_sql); |
|
| 2360 | 2360 | } |
| 2361 | 2361 | |
| 2362 | 2362 | // compatibilite ancienne version |
| 2363 | 2363 | |
| 2364 | 2364 | // http://code.spip.net/@calculer_vieux_in |
| 2365 | 2365 | function calculer_vieux_in($params) { |
| 2366 | - $deb = $params[0][0]; |
|
| 2367 | - $k = count($params) - 1; |
|
| 2368 | - $last = $params[$k]; |
|
| 2369 | - $j = count($last) - 1; |
|
| 2370 | - $last = $last[$j]; |
|
| 2371 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2372 | - |
|
| 2373 | - if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2374 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2375 | - ) { |
|
| 2376 | - return $params; |
|
| 2377 | - } |
|
| 2378 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2379 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2380 | - $last = $params[$k][$j]; |
|
| 2381 | - $n = strlen($last->texte); |
|
| 2382 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2383 | - $newp = array(); |
|
| 2384 | - foreach ($params as $v) { |
|
| 2385 | - if ($v[0]->type != 'texte') { |
|
| 2386 | - $newp[] = $v; |
|
| 2387 | - } else { |
|
| 2388 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2389 | - $t = new Texte; |
|
| 2390 | - $t->texte = $x; |
|
| 2391 | - $newp[] = array($t); |
|
| 2392 | - } |
|
| 2393 | - } |
|
| 2394 | - } |
|
| 2395 | - |
|
| 2396 | - return $newp; |
|
| 2366 | + $deb = $params[0][0]; |
|
| 2367 | + $k = count($params) - 1; |
|
| 2368 | + $last = $params[$k]; |
|
| 2369 | + $j = count($last) - 1; |
|
| 2370 | + $last = $last[$j]; |
|
| 2371 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2372 | + |
|
| 2373 | + if (!((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2374 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2375 | + ) { |
|
| 2376 | + return $params; |
|
| 2377 | + } |
|
| 2378 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2379 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2380 | + $last = $params[$k][$j]; |
|
| 2381 | + $n = strlen($last->texte); |
|
| 2382 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2383 | + $newp = array(); |
|
| 2384 | + foreach ($params as $v) { |
|
| 2385 | + if ($v[0]->type != 'texte') { |
|
| 2386 | + $newp[] = $v; |
|
| 2387 | + } else { |
|
| 2388 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2389 | + $t = new Texte; |
|
| 2390 | + $t->texte = $x; |
|
| 2391 | + $newp[] = array($t); |
|
| 2392 | + } |
|
| 2393 | + } |
|
| 2394 | + } |
|
| 2395 | + |
|
| 2396 | + return $newp; |
|
| 2397 | 2397 | } |
| 2398 | 2398 | |
| 2399 | 2399 | /** |
@@ -2412,89 +2412,89 @@ discard block |
||
| 2412 | 2412 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2413 | 2413 | **/ |
| 2414 | 2414 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2415 | - if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2416 | - return ''; |
|
| 2417 | - } |
|
| 2418 | - |
|
| 2419 | - $boucle = $boucles[$idb]; |
|
| 2420 | - $table = $boucle->show; |
|
| 2421 | - |
|
| 2422 | - // si c'est une colonne de la table, ne rien faire |
|
| 2423 | - if (isset($table['field'][$col])) { |
|
| 2424 | - return ''; |
|
| 2425 | - } |
|
| 2426 | - |
|
| 2427 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2428 | - return ''; |
|
| 2429 | - } |
|
| 2430 | - $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2431 | - |
|
| 2432 | - $col = $regs[1]; |
|
| 2433 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2434 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2435 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2436 | - |
|
| 2437 | - if (isset($table['field']["date$suite"])) { |
|
| 2438 | - $date_orig = 'date' . $suite; |
|
| 2439 | - } else { |
|
| 2440 | - $date_orig = substr($suite, 1); |
|
| 2441 | - } |
|
| 2442 | - $pred = $date_orig; |
|
| 2443 | - } else { |
|
| 2444 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2445 | - $pred = 'date'; |
|
| 2446 | - } |
|
| 2447 | - } |
|
| 2448 | - |
|
| 2449 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2450 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2451 | - ") . '\""; |
|
| 2452 | - |
|
| 2453 | - $col_vraie = $date_orig; |
|
| 2454 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2455 | - |
|
| 2456 | - switch ($col) { |
|
| 2457 | - case 'date': |
|
| 2458 | - $col = $date_orig; |
|
| 2459 | - break; |
|
| 2460 | - case 'jour': |
|
| 2461 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2462 | - break; |
|
| 2463 | - case 'mois': |
|
| 2464 | - $col = "MONTH($date_orig)"; |
|
| 2465 | - break; |
|
| 2466 | - case 'annee': |
|
| 2467 | - $col = "YEAR($date_orig)"; |
|
| 2468 | - break; |
|
| 2469 | - case 'heure': |
|
| 2470 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2471 | - break; |
|
| 2472 | - case 'age': |
|
| 2473 | - $col = calculer_param_date("NOW()", $date_orig); |
|
| 2474 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2475 | - break; |
|
| 2476 | - case 'age_relatif': |
|
| 2477 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2478 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2479 | - break; |
|
| 2480 | - case 'jour_relatif': |
|
| 2481 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2482 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2483 | - break; |
|
| 2484 | - case 'mois_relatif': |
|
| 2485 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2486 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2487 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2488 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2489 | - break; |
|
| 2490 | - case 'annee_relatif': |
|
| 2491 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2492 | - $date_orig . ")"; |
|
| 2493 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2494 | - break; |
|
| 2495 | - } |
|
| 2496 | - |
|
| 2497 | - return array($col, $col_vraie); |
|
| 2415 | + if (!preg_match(",^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z]+)?$,", $col, $regs)) { |
|
| 2416 | + return ''; |
|
| 2417 | + } |
|
| 2418 | + |
|
| 2419 | + $boucle = $boucles[$idb]; |
|
| 2420 | + $table = $boucle->show; |
|
| 2421 | + |
|
| 2422 | + // si c'est une colonne de la table, ne rien faire |
|
| 2423 | + if (isset($table['field'][$col])) { |
|
| 2424 | + return ''; |
|
| 2425 | + } |
|
| 2426 | + |
|
| 2427 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2428 | + return ''; |
|
| 2429 | + } |
|
| 2430 | + $pred = $date_orig = isset($GLOBALS['table_date'][$table['id_table']]) ? $GLOBALS['table_date'][$table['id_table']] : $table['date']; |
|
| 2431 | + |
|
| 2432 | + $col = $regs[1]; |
|
| 2433 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2434 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2435 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2436 | + |
|
| 2437 | + if (isset($table['field']["date$suite"])) { |
|
| 2438 | + $date_orig = 'date' . $suite; |
|
| 2439 | + } else { |
|
| 2440 | + $date_orig = substr($suite, 1); |
|
| 2441 | + } |
|
| 2442 | + $pred = $date_orig; |
|
| 2443 | + } else { |
|
| 2444 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2445 | + $pred = 'date'; |
|
| 2446 | + } |
|
| 2447 | + } |
|
| 2448 | + |
|
| 2449 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2450 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2451 | + ") . '\""; |
|
| 2452 | + |
|
| 2453 | + $col_vraie = $date_orig; |
|
| 2454 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2455 | + |
|
| 2456 | + switch ($col) { |
|
| 2457 | + case 'date': |
|
| 2458 | + $col = $date_orig; |
|
| 2459 | + break; |
|
| 2460 | + case 'jour': |
|
| 2461 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2462 | + break; |
|
| 2463 | + case 'mois': |
|
| 2464 | + $col = "MONTH($date_orig)"; |
|
| 2465 | + break; |
|
| 2466 | + case 'annee': |
|
| 2467 | + $col = "YEAR($date_orig)"; |
|
| 2468 | + break; |
|
| 2469 | + case 'heure': |
|
| 2470 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2471 | + break; |
|
| 2472 | + case 'age': |
|
| 2473 | + $col = calculer_param_date("NOW()", $date_orig); |
|
| 2474 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2475 | + break; |
|
| 2476 | + case 'age_relatif': |
|
| 2477 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2478 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2479 | + break; |
|
| 2480 | + case 'jour_relatif': |
|
| 2481 | + $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2482 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2483 | + break; |
|
| 2484 | + case 'mois_relatif': |
|
| 2485 | + $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2486 | + $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2487 | + ")-YEAR(" . $date_orig . "))"; |
|
| 2488 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2489 | + break; |
|
| 2490 | + case 'annee_relatif': |
|
| 2491 | + $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2492 | + $date_orig . ")"; |
|
| 2493 | + $col_vraie = "";// comparer a un int (par defaut) |
|
| 2494 | + break; |
|
| 2495 | + } |
|
| 2496 | + |
|
| 2497 | + return array($col, $col_vraie); |
|
| 2498 | 2498 | } |
| 2499 | 2499 | |
| 2500 | 2500 | /** |
@@ -2513,16 +2513,16 @@ discard block |
||
| 2513 | 2513 | * de colonne SQL et une date. |
| 2514 | 2514 | **/ |
| 2515 | 2515 | function calculer_param_date($date_compare, $date_orig) { |
| 2516 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2517 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2518 | - $date_compare = '\'$x\''; |
|
| 2519 | - } else { |
|
| 2520 | - $init = $date_compare; |
|
| 2521 | - } |
|
| 2522 | - |
|
| 2523 | - return |
|
| 2524 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2525 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2516 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2517 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2518 | + $date_compare = '\'$x\''; |
|
| 2519 | + } else { |
|
| 2520 | + $init = $date_compare; |
|
| 2521 | + } |
|
| 2522 | + |
|
| 2523 | + return |
|
| 2524 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2525 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2526 | 2526 | } |
| 2527 | 2527 | |
| 2528 | 2528 | /** |
@@ -2540,18 +2540,18 @@ discard block |
||
| 2540 | 2540 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2541 | 2541 | */ |
| 2542 | 2542 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2543 | - $boucle = &$boucles[$idb]; |
|
| 2543 | + $boucle = &$boucles[$idb]; |
|
| 2544 | 2544 | |
| 2545 | - $args = array(); |
|
| 2546 | - foreach ($crit->param as &$param) { |
|
| 2547 | - array_push($args, |
|
| 2548 | - calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2549 | - } |
|
| 2545 | + $args = array(); |
|
| 2546 | + foreach ($crit->param as &$param) { |
|
| 2547 | + array_push($args, |
|
| 2548 | + calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent)); |
|
| 2549 | + } |
|
| 2550 | 2550 | |
| 2551 | - $boucle->hash .= ' |
|
| 2551 | + $boucle->hash .= ' |
|
| 2552 | 2552 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2553 | 2553 | |
| 2554 | - $boucle->hash .= ' |
|
| 2554 | + $boucle->hash .= ' |
|
| 2555 | 2555 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2556 | 2556 | } |
| 2557 | 2557 | |
@@ -2568,8 +2568,8 @@ discard block |
||
| 2568 | 2568 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2569 | 2569 | */ |
| 2570 | 2570 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2571 | - $boucle = &$boucles[$idb]; |
|
| 2572 | - $boucle->hash .= ' |
|
| 2571 | + $boucle = &$boucles[$idb]; |
|
| 2572 | + $boucle->hash .= ' |
|
| 2573 | 2573 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2574 | 2574 | $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2575 | 2575 | } |
@@ -2589,8 +2589,8 @@ discard block |
||
| 2589 | 2589 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2590 | 2590 | */ |
| 2591 | 2591 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2592 | - $boucle = &$boucles[$idb]; |
|
| 2593 | - $boucle->hash .= ' |
|
| 2592 | + $boucle = &$boucles[$idb]; |
|
| 2593 | + $boucle->hash .= ' |
|
| 2594 | 2594 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2595 | 2595 | } |
| 2596 | 2596 | |
@@ -2606,12 +2606,12 @@ discard block |
||
| 2606 | 2606 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2607 | 2607 | */ |
| 2608 | 2608 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2609 | - $boucle = &$boucles[$idb]; |
|
| 2610 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2611 | - foreach ($crit->param as $param) { |
|
| 2612 | - $boucle->hash .= ' |
|
| 2609 | + $boucle = &$boucles[$idb]; |
|
| 2610 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2611 | + foreach ($crit->param as $param) { |
|
| 2612 | + $boucle->hash .= ' |
|
| 2613 | 2613 | $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2614 | - } |
|
| 2614 | + } |
|
| 2615 | 2615 | } |
| 2616 | 2616 | |
| 2617 | 2617 | /** |
@@ -2628,12 +2628,12 @@ discard block |
||
| 2628 | 2628 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2629 | 2629 | */ |
| 2630 | 2630 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2631 | - $boucle = &$boucles[$idb]; |
|
| 2632 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2633 | - foreach ($crit->param as $param) { |
|
| 2634 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2635 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2636 | - } |
|
| 2631 | + $boucle = &$boucles[$idb]; |
|
| 2632 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2633 | + foreach ($crit->param as $param) { |
|
| 2634 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2635 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2636 | + } |
|
| 2637 | 2637 | } |
| 2638 | 2638 | |
| 2639 | 2639 | /** |
@@ -2658,12 +2658,12 @@ discard block |
||
| 2658 | 2658 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2659 | 2659 | */ |
| 2660 | 2660 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2661 | - $boucle = &$boucles[$idb]; |
|
| 2662 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2663 | - foreach ($crit->param as $param) { |
|
| 2664 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2665 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2666 | - } |
|
| 2661 | + $boucle = &$boucles[$idb]; |
|
| 2662 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2663 | + foreach ($crit->param as $param) { |
|
| 2664 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2665 | + $boucles[$idb]->id_parent) . ";\n"; |
|
| 2666 | + } |
|
| 2667 | 2667 | } |
| 2668 | 2668 | |
| 2669 | 2669 | /** |
@@ -2678,11 +2678,11 @@ discard block |
||
| 2678 | 2678 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2679 | 2679 | */ |
| 2680 | 2680 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2681 | - $boucle = &$boucles[$idb]; |
|
| 2682 | - foreach ($crit->param as $param) { |
|
| 2683 | - $boucle->hash .= ' |
|
| 2681 | + $boucle = &$boucles[$idb]; |
|
| 2682 | + foreach ($crit->param as $param) { |
|
| 2683 | + $boucle->hash .= ' |
|
| 2684 | 2684 | $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2685 | - } |
|
| 2685 | + } |
|
| 2686 | 2686 | } |
| 2687 | 2687 | |
| 2688 | 2688 | |
@@ -2714,20 +2714,20 @@ discard block |
||
| 2714 | 2714 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2715 | 2715 | */ |
| 2716 | 2716 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2717 | - $boucle = &$boucles[$idb]; |
|
| 2718 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2719 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2720 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2721 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2722 | - if ($crit->param) { |
|
| 2723 | - foreach ($crit->param as $param) { |
|
| 2724 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2725 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2726 | - } |
|
| 2727 | - // interdire {si 0} aussi ! |
|
| 2728 | - } else { |
|
| 2729 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2730 | - } |
|
| 2717 | + $boucle = &$boucles[$idb]; |
|
| 2718 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2719 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2720 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2721 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2722 | + if ($crit->param) { |
|
| 2723 | + foreach ($crit->param as $param) { |
|
| 2724 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2725 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2726 | + } |
|
| 2727 | + // interdire {si 0} aussi ! |
|
| 2728 | + } else { |
|
| 2729 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2730 | + } |
|
| 2731 | 2731 | } |
| 2732 | 2732 | |
| 2733 | 2733 | /** |
@@ -2743,8 +2743,8 @@ discard block |
||
| 2743 | 2743 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2744 | 2744 | */ |
| 2745 | 2745 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2746 | - $boucle = &$boucles[$idb]; |
|
| 2747 | - $boucle->hash .= ' |
|
| 2746 | + $boucle = &$boucles[$idb]; |
|
| 2747 | + $boucle->hash .= ' |
|
| 2748 | 2748 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
| 2749 | 2749 | $command[\'sourcemode\'] = \'table\';'; |
| 2750 | 2750 | } |
@@ -2765,29 +2765,29 @@ discard block |
||
| 2765 | 2765 | */ |
| 2766 | 2766 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2767 | 2767 | |
| 2768 | - $not = $crit->not; |
|
| 2769 | - $boucle = &$boucles[$idb]; |
|
| 2770 | - $primary = $boucle->primary; |
|
| 2768 | + $not = $crit->not; |
|
| 2769 | + $boucle = &$boucles[$idb]; |
|
| 2770 | + $primary = $boucle->primary; |
|
| 2771 | 2771 | |
| 2772 | - if (!$primary or strpos($primary, ',')) { |
|
| 2773 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2772 | + if (!$primary or strpos($primary, ',')) { |
|
| 2773 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2774 | 2774 | |
| 2775 | - return; |
|
| 2776 | - } |
|
| 2777 | - $table = $boucle->type_requete; |
|
| 2778 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2775 | + return; |
|
| 2776 | + } |
|
| 2777 | + $table = $boucle->type_requete; |
|
| 2778 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2779 | 2779 | |
| 2780 | - $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2781 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2782 | - 'id_parent'; |
|
| 2780 | + $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
|
| 2781 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2782 | + 'id_parent'; |
|
| 2783 | 2783 | |
| 2784 | - $in = "IN"; |
|
| 2785 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2786 | - if ($not) { |
|
| 2787 | - $where = array("'NOT'", $where); |
|
| 2788 | - } |
|
| 2784 | + $in = "IN"; |
|
| 2785 | + $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2786 | + if ($not) { |
|
| 2787 | + $where = array("'NOT'", $where); |
|
| 2788 | + } |
|
| 2789 | 2789 | |
| 2790 | - $boucle->where[] = $where; |
|
| 2790 | + $boucle->where[] = $where; |
|
| 2791 | 2791 | } |
| 2792 | 2792 | |
| 2793 | 2793 | /** |
@@ -2803,8 +2803,8 @@ discard block |
||
| 2803 | 2803 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2804 | 2804 | */ |
| 2805 | 2805 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2806 | - $not = $crit->not; |
|
| 2807 | - $crit->not = $not ? false : true; |
|
| 2808 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2809 | - $crit->not = $not; |
|
| 2806 | + $not = $crit->not; |
|
| 2807 | + $crit->not = $not ? false : true; |
|
| 2808 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2809 | + $crit->not = $not; |
|
| 2810 | 2810 | } |
@@ -46,10 +46,9 @@ discard block |
||
| 46 | 46 | $not = $crit->not; |
| 47 | 47 | $boucle = &$boucles[$idb]; |
| 48 | 48 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 49 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 50 | - 'id_parent'; |
|
| 49 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 51 | 50 | |
| 52 | - $c = array("'='", "'$boucle->id_table." . "$id_parent'", 0); |
|
| 51 | + $c = array("'='", "'$boucle->id_table."."$id_parent'", 0); |
|
| 53 | 52 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
| 54 | 53 | } |
| 55 | 54 | |
@@ -72,10 +71,10 @@ discard block |
||
| 72 | 71 | $id = $boucle->primary; |
| 73 | 72 | |
| 74 | 73 | if ($not or !$id) { |
| 75 | - return (array('zbug_critere_inconnu', array('critere' => $not . $crit->op))); |
|
| 74 | + return (array('zbug_critere_inconnu', array('critere' => $not.$crit->op))); |
|
| 76 | 75 | } |
| 77 | 76 | $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
| 78 | - $boucle->where[] = array("'!='", "'$boucle->id_table." . "$id'", $arg); |
|
| 77 | + $boucle->where[] = array("'!='", "'$boucle->id_table."."$id'", $arg); |
|
| 79 | 78 | } |
| 80 | 79 | |
| 81 | 80 | |
@@ -106,12 +105,12 @@ discard block |
||
| 106 | 105 | $not = ($crit->not ? '' : 'NOT'); |
| 107 | 106 | |
| 108 | 107 | // le doublon s'applique sur un type de boucle (article) |
| 109 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + $nom = "'".$boucle->type_requete."'"; |
|
| 110 | 109 | |
| 111 | 110 | // compléter le nom avec un nom précisé {doublons nom} |
| 112 | 111 | // on obtient $nom = "'article' . 'nom'" |
| 113 | 112 | if (isset($crit->param[0])) { |
| 114 | - $nom .= "." . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + $nom .= ".".calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent); |
|
| 115 | 114 | } |
| 116 | 115 | |
| 117 | 116 | // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
@@ -123,13 +122,13 @@ discard block |
||
| 123 | 122 | // $doublons et son index, ici $nom |
| 124 | 123 | |
| 125 | 124 | // debut du code "sql_in('articles.id_article', " |
| 126 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + $debut_in = "sql_in('".$boucle->id_table.'.'.$primary."', "; |
|
| 127 | 126 | // lecture des données du doublon "$doublons[$doublon_index[] = " |
| 128 | 127 | // Attention : boucle->doublons désigne une variable qu'on affecte |
| 129 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . "[]= ")); |
|
| 128 | + $debut_doub = '$doublons['.(!$not ? '' : ($boucle->doublons."[]= ")); |
|
| 130 | 129 | |
| 131 | 130 | // le debut complet du code des doublons |
| 132 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + $debut_doub = $debut_in.$debut_doub; |
|
| 133 | 132 | |
| 134 | 133 | // nom du doublon "('article' . 'nom')]" |
| 135 | 134 | $fin_doub = "($nom)]"; |
@@ -139,22 +138,22 @@ discard block |
||
| 139 | 138 | foreach ($boucle->where as $k => $w) { |
| 140 | 139 | if (strpos($w[0], $debut_doub) === 0) { |
| 141 | 140 | // fusionner le sql_in (du where) |
| 142 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + $boucle->where[$k][0] = $debut_doub.$fin_doub.' . '.substr($w[0], strlen($debut_in)); |
|
| 143 | 142 | // fusionner l'initialisation (du hash) pour faire plus joli |
| 144 | 143 | $x = strpos($boucle->hash, $init_comment); |
| 145 | 144 | $len = strlen($init_comment); |
| 146 | 145 | $boucle->hash = |
| 147 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + substr($boucle->hash, 0, $x + $len).$init_code.substr($boucle->hash, $x + $len); |
|
| 148 | 147 | |
| 149 | 148 | return; |
| 150 | 149 | } |
| 151 | 150 | } |
| 152 | 151 | |
| 153 | 152 | // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
| 154 | - $boucle->where[] = array($debut_doub . $fin_doub . ", '" . $not . "')"); |
|
| 153 | + $boucle->where[] = array($debut_doub.$fin_doub.", '".$not."')"); |
|
| 155 | 154 | |
| 156 | 155 | // déclarer le doublon s'il n'existe pas encore |
| 157 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + $boucle->hash .= $init_comment.$init_code; |
|
| 158 | 157 | |
| 159 | 158 | |
| 160 | 159 | # la ligne suivante avait l'intention d'eviter une collecte deja faite |
@@ -215,10 +214,10 @@ discard block |
||
| 215 | 214 | $un = $un[0]->texte; |
| 216 | 215 | $deux = $deux[0]->texte; |
| 217 | 216 | if ($deux) { |
| 218 | - $boucles[$idb]->limit = 'intval($Pile[0]["debut' . |
|
| 219 | - $un . |
|
| 220 | - '"]) . ",' . |
|
| 221 | - $deux . |
|
| 217 | + $boucles[$idb]->limit = 'intval($Pile[0]["debut'. |
|
| 218 | + $un. |
|
| 219 | + '"]) . ",'. |
|
| 220 | + $deux. |
|
| 222 | 221 | '"'; |
| 223 | 222 | } else { |
| 224 | 223 | calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
@@ -281,26 +280,26 @@ discard block |
||
| 281 | 280 | $type = calculer_liste(array($crit->param[1][0]), array(), $boucles, $boucle->id_parent); |
| 282 | 281 | } |
| 283 | 282 | |
| 284 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 283 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut".substr($type, 1)); |
|
| 285 | 284 | $boucle->modificateur['debut_nom'] = $type; |
| 286 | 285 | $partie = |
| 287 | 286 | // tester si le numero de page demande est de la forme '@yyy' |
| 288 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 287 | + 'isset($Pile[0]['.$debut.']) ? $Pile[0]['.$debut.'] : _request('.$debut.");\n" |
|
| 289 | 288 | . "\tif(substr(\$debut_boucle,0,1)=='@'){\n" |
| 290 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 291 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 289 | + . "\t\t".'$debut_boucle = $Pile[0]['.$debut.'] = quete_debut_pagination(\''.$boucle->primary.'\',$Pile[0][\'@'.$boucle->primary.'\'] = substr($debut_boucle,1),'.$pas.',$iter);'."\n" |
|
| 290 | + . "\t\t".'$iter->seek(0);'."\n" |
|
| 292 | 291 | . "\t}\n" |
| 293 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 292 | + . "\t".'$debut_boucle = intval($debut_boucle)'; |
|
| 294 | 293 | |
| 295 | 294 | $boucle->hash .= ' |
| 296 | - $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
|
| 295 | + $command[\'pagination\'] = array((isset($Pile[0][' . $debut.']) ? $Pile[0]['.$debut.'] : null), '.$pas.');'; |
|
| 297 | 296 | |
| 298 | 297 | $boucle->total_parties = $pas; |
| 299 | 298 | calculer_parties($boucles, $idb, $partie, 'p+'); |
| 300 | 299 | // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
| 301 | 300 | // sauf si pas de primaire, ou si primaire composee |
| 302 | 301 | // dans ce cas, on ne sait pas gerer une pagination indirecte |
| 303 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 302 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 304 | 303 | if ($boucle->primary |
| 305 | 304 | and !preg_match('/[,\s]/', $boucle->primary) |
| 306 | 305 | and !in_array($t, $boucle->select) |
@@ -346,24 +345,24 @@ discard block |
||
| 346 | 345 | $boucle->hash .= ' |
| 347 | 346 | // RECHERCHE' |
| 348 | 347 | . ($crit->cond ? ' |
| 349 | - if (!strlen(' . $quoi . ')){ |
|
| 348 | + if (!strlen(' . $quoi.')){ |
|
| 350 | 349 | list($rech_select, $rech_where) = array("0 as points",""); |
| 351 | - } else' : '') . ' |
|
| 350 | + } else' : '').' |
|
| 352 | 351 | { |
| 353 | 352 | $prepare_recherche = charger_fonction(\'prepare_recherche\', \'inc\'); |
| 354 | - list($rech_select, $rech_where) = $prepare_recherche(' . $quoi . ', "' . $boucle->id_table . '", "' . $crit->cond . '","' . $boucle->sql_serveur . '",' . $_modificateur . ',"' . $boucle->primary . '"); |
|
| 353 | + list($rech_select, $rech_where) = $prepare_recherche(' . $quoi.', "'.$boucle->id_table.'", "'.$crit->cond.'","'.$boucle->sql_serveur.'",'.$_modificateur.',"'.$boucle->primary.'"); |
|
| 355 | 354 | } |
| 356 | 355 | '; |
| 357 | 356 | |
| 358 | 357 | |
| 359 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 358 | + $t = $boucle->id_table.'.'.$boucle->primary; |
|
| 360 | 359 | if (!in_array($t, $boucles[$idb]->select)) { |
| 361 | 360 | $boucle->select[] = $t; |
| 362 | 361 | } # pour postgres, neuneu ici |
| 363 | 362 | // jointure uniquement sur le serveur principal |
| 364 | 363 | // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
| 365 | 364 | if (!$boucle->sql_serveur) { |
| 366 | - $boucle->join['resultats'] = array("'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"); |
|
| 365 | + $boucle->join['resultats'] = array("'".$boucle->id_table."'", "'id'", "'".$boucle->primary."'"); |
|
| 367 | 366 | $boucle->from['resultats'] = 'spip_resultats'; |
| 368 | 367 | } |
| 369 | 368 | $boucle->select[] = '$rech_select'; |
@@ -430,7 +429,7 @@ discard block |
||
| 430 | 429 | $c = |
| 431 | 430 | array( |
| 432 | 431 | "'OR'", |
| 433 | - array("'='", "'$table." . "id_trad'", "'$table.$prim'"), |
|
| 432 | + array("'='", "'$table."."id_trad'", "'$table.$prim'"), |
|
| 434 | 433 | array("'='", "'$table.id_trad'", "'0'") |
| 435 | 434 | ); |
| 436 | 435 | $boucle->where[] = ($crit->not ? array("'NOT'", $c) : $c); |
@@ -453,16 +452,15 @@ discard block |
||
| 453 | 452 | $boucle = &$boucles[$idb]; |
| 454 | 453 | $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
| 455 | 454 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 456 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 457 | - 'id_parent'; |
|
| 458 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 455 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 456 | + $mparent = $boucle->id_table.'.'.$id_parent; |
|
| 459 | 457 | |
| 460 | 458 | if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
| 461 | 459 | $boucle->where[] = array("'='", "'$mparent'", $arg); |
| 462 | 460 | |
| 463 | 461 | } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
| 464 | 462 | else { |
| 465 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ' . $boucle->type_requete))); |
|
| 463 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' '.$boucle->type_requete))); |
|
| 466 | 464 | } |
| 467 | 465 | } |
| 468 | 466 | |
@@ -515,16 +513,15 @@ discard block |
||
| 515 | 513 | if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
| 516 | 514 | $decompose = decompose_champ_id_objet($champ); |
| 517 | 515 | $champ = array_shift($decompose); |
| 518 | - $boucle->where[] = array("'='", _q($cle . "." . reset($decompose)), '"' . sql_quote(end($decompose)) . '"'); |
|
| 516 | + $boucle->where[] = array("'='", _q($cle.".".reset($decompose)), '"'.sql_quote(end($decompose)).'"'); |
|
| 519 | 517 | } |
| 520 | 518 | } else { |
| 521 | 519 | $cle = $boucle->id_table; |
| 522 | 520 | } |
| 523 | 521 | |
| 524 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 525 | - . ($not ? ", 'NOT'" : '') . ")"; |
|
| 526 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 527 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 522 | + $c = "sql_in('$cle".".$champ', calcul_branche_in($arg)" |
|
| 523 | + . ($not ? ", 'NOT'" : '').")"; |
|
| 524 | + $boucle->where[] = !$crit->cond ? $c : ("($arg ? $c : ".($not ? "'0=1'" : "'1=1'").')'); |
|
| 528 | 525 | } |
| 529 | 526 | |
| 530 | 527 | /** |
@@ -543,9 +540,9 @@ discard block |
||
| 543 | 540 | $not = $crit->not; |
| 544 | 541 | $boucle = &$boucles[$idb]; |
| 545 | 542 | |
| 546 | - $c = "sql_in('" . |
|
| 547 | - $boucle->id_table . '.' . $boucle->primary |
|
| 548 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '')"; |
|
| 543 | + $c = "sql_in('". |
|
| 544 | + $boucle->id_table.'.'.$boucle->primary |
|
| 545 | + . "', lister_objets_avec_logos('".$boucle->primary."'), '')"; |
|
| 549 | 546 | |
| 550 | 547 | if ($crit->cond) { |
| 551 | 548 | $c = "($arg ? $c : 1)"; |
@@ -585,7 +582,7 @@ discard block |
||
| 585 | 582 | $t = table_objet_sql($r[1]); |
| 586 | 583 | $t = array_search($t, $boucles[$idb]->from); |
| 587 | 584 | if ($t) { |
| 588 | - $t .= '.' . $r[2]; |
|
| 585 | + $t .= '.'.$r[2]; |
|
| 589 | 586 | } |
| 590 | 587 | } |
| 591 | 588 | } else { |
@@ -600,7 +597,7 @@ discard block |
||
| 600 | 597 | $boucles[$idb]->select[] = $t; |
| 601 | 598 | } |
| 602 | 599 | } else { |
| 603 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . ' ?'))); |
|
| 600 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op.' ?'))); |
|
| 604 | 601 | } |
| 605 | 602 | } |
| 606 | 603 | |
@@ -650,26 +647,26 @@ discard block |
||
| 650 | 647 | (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
| 651 | 648 | OR (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
| 652 | 649 | ) { |
| 653 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 650 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . ".$boucle->modificateur['collate']." . ' ", $i, 0); |
|
| 654 | 651 | } else { |
| 655 | - $boucle->order[$n - 1] .= " . " . $boucle->modificateur['collate']; |
|
| 652 | + $boucle->order[$n - 1] .= " . ".$boucle->modificateur['collate']; |
|
| 656 | 653 | } |
| 657 | 654 | } |
| 658 | 655 | } else { |
| 659 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " " . count($boucles[$idb]->order)))); |
|
| 656 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ".count($boucles[$idb]->order)))); |
|
| 660 | 657 | } |
| 661 | 658 | } |
| 662 | 659 | |
| 663 | 660 | // http://code.spip.net/@calculer_critere_arg_dynamique |
| 664 | 661 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 665 | 662 | $boucle = $boucles[$idb]; |
| 666 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 667 | - $var = '$champs_' . $idb; |
|
| 663 | + $alt = "('".$boucle->id_table.'.\' . $x'.$suffix.')'; |
|
| 664 | + $var = '$champs_'.$idb; |
|
| 668 | 665 | $desc = (strpos($boucle->in, "static $var =") !== false); |
| 669 | 666 | if (!$desc) { |
| 670 | 667 | $desc = $boucle->show['field']; |
| 671 | 668 | $desc = implode(',', array_map('_q', array_keys($desc))); |
| 672 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ");"; |
|
| 669 | + $boucles[$idb]->in .= "\n\tstatic $var = array(".$desc.");"; |
|
| 673 | 670 | } |
| 674 | 671 | if ($desc) { |
| 675 | 672 | $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
@@ -744,7 +741,7 @@ discard block |
||
| 744 | 741 | $sens = " . ' DESC'"; |
| 745 | 742 | } |
| 746 | 743 | if (isset($boucle->modificateur['collate'])) { |
| 747 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 744 | + $collecte = ' . '.$boucle->modificateur['collate']; |
|
| 748 | 745 | } |
| 749 | 746 | |
| 750 | 747 | // Pour chaque paramètre du critère |
@@ -766,14 +763,14 @@ discard block |
||
| 766 | 763 | if (preg_match(",^(\w+)[\s]+(.*)$,", $par, $m)) { |
| 767 | 764 | $expression = trim($m[1]); |
| 768 | 765 | $champ = trim($m[2]); |
| 769 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 766 | + if (function_exists($f = 'calculer_critere_par_expression_'.$expression)) { |
|
| 770 | 767 | $order = $f($idb, $boucles, $crit, $tri, $champ); |
| 771 | 768 | } else { |
| 772 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 769 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 773 | 770 | } |
| 774 | 771 | |
| 775 | 772 | // tris de la forme {par champ} ou {par FONCTION(champ)} |
| 776 | - } elseif (preg_match(",^" . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 773 | + } elseif (preg_match(",^".CHAMP_SQL_PLUS_FONC.'$,is', $par, $match)) { |
|
| 777 | 774 | // {par FONCTION(champ)} |
| 778 | 775 | if (count($match) > 2) { |
| 779 | 776 | $par = substr($match[2], 1, -1); |
@@ -783,7 +780,7 @@ discard block |
||
| 783 | 780 | if ($par == 'hasard') { |
| 784 | 781 | $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
| 785 | 782 | } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
| 786 | - $order = "'" . $boucle->id_table . "." . $boucle->show['date'] . "'"; |
|
| 783 | + $order = "'".$boucle->id_table.".".$boucle->show['date']."'"; |
|
| 787 | 784 | } else { |
| 788 | 785 | // cas général {par champ}, {par table.champ}, ... |
| 789 | 786 | $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
@@ -792,7 +789,7 @@ discard block |
||
| 792 | 789 | |
| 793 | 790 | // on ne sait pas traiter… |
| 794 | 791 | else { |
| 795 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 792 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 796 | 793 | } |
| 797 | 794 | |
| 798 | 795 | // En cas d'erreur de squelette retournée par une fonction |
@@ -812,14 +809,14 @@ discard block |
||
| 812 | 809 | |
| 813 | 810 | if ($fct) { |
| 814 | 811 | if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
| 815 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 812 | + $order = "'$fct(".$r[1].")'"; |
|
| 816 | 813 | } else { |
| 817 | 814 | $order = "'$fct(' . $order . ')'"; |
| 818 | 815 | } |
| 819 | 816 | } |
| 820 | - $t = $order . $collecte . $sens; |
|
| 817 | + $t = $order.$collecte.$sens; |
|
| 821 | 818 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 822 | - $t = $r[1] . $r[2]; |
|
| 819 | + $t = $r[1].$r[2]; |
|
| 823 | 820 | } |
| 824 | 821 | |
| 825 | 822 | $boucle->order[] = $t; |
@@ -869,16 +866,16 @@ discard block |
||
| 869 | 866 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 870 | 867 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 871 | 868 | if (is_array($_champ)) { |
| 872 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " num $champ")); |
|
| 869 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." num $champ")); |
|
| 873 | 870 | } |
| 874 | 871 | $boucle = &$boucles[$idb]; |
| 875 | - $texte = '0+' . $_champ; |
|
| 872 | + $texte = '0+'.$_champ; |
|
| 876 | 873 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 877 | 874 | if ($suite !== "''") { |
| 878 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 875 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 879 | 876 | } |
| 880 | - $as = 'num' . ($boucle->order ? count($boucle->order) : ""); |
|
| 881 | - $boucle->select[] = $texte . " AS $as"; |
|
| 877 | + $as = 'num'.($boucle->order ? count($boucle->order) : ""); |
|
| 878 | + $boucle->select[] = $texte." AS $as"; |
|
| 882 | 879 | $order = "'$as'"; |
| 883 | 880 | return $order; |
| 884 | 881 | } |
@@ -903,16 +900,16 @@ discard block |
||
| 903 | 900 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 904 | 901 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 905 | 902 | if (is_array($_champ)) { |
| 906 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " sinum $champ")); |
|
| 903 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." sinum $champ")); |
|
| 907 | 904 | } |
| 908 | 905 | $boucle = &$boucles[$idb]; |
| 909 | - $texte = '0+' . $_champ; |
|
| 906 | + $texte = '0+'.$_champ; |
|
| 910 | 907 | $suite = calculer_liste($tri, array(), $boucles, $boucle->id_parent); |
| 911 | 908 | if ($suite !== "''") { |
| 912 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . " . \""; |
|
| 909 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')"." . \""; |
|
| 913 | 910 | } |
| 914 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ""); |
|
| 915 | - $boucle->select[] = 'CASE (' . $texte . ') WHEN 0 THEN 1 ELSE 0 END AS ' . $as; |
|
| 911 | + $as = 'sinum'.($boucle->order ? count($boucle->order) : ""); |
|
| 912 | + $boucle->select[] = 'CASE ('.$texte.') WHEN 0 THEN 1 ELSE 0 END AS '.$as; |
|
| 916 | 913 | $order = "'$as'"; |
| 917 | 914 | return $order; |
| 918 | 915 | } |
@@ -936,10 +933,10 @@ discard block |
||
| 936 | 933 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 937 | 934 | $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
| 938 | 935 | if (is_array($_champ)) { |
| 939 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " multi $champ")); |
|
| 936 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." multi $champ")); |
|
| 940 | 937 | } |
| 941 | 938 | $boucle = &$boucles[$idb]; |
| 942 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 939 | + $boucle->select[] = "\".sql_multi('".$_champ."', \$GLOBALS['spip_lang']).\""; |
|
| 943 | 940 | $order = "'multi'"; |
| 944 | 941 | return $order; |
| 945 | 942 | } |
@@ -959,12 +956,12 @@ discard block |
||
| 959 | 956 | * @param bool $raw Retourne le champ pour le compilateur ("'alias.champ'") ou brut ('alias.champ') |
| 960 | 957 | * @return array|string |
| 961 | 958 | */ |
| 962 | -function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 959 | +function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
|
| 963 | 960 | $boucle = &$boucles[$idb]; |
| 964 | 961 | |
| 965 | 962 | // le champ existe dans la table, pas de souci (le plus commun) |
| 966 | 963 | if (isset($desc['field'][$par])) { |
| 967 | - $par = $boucle->id_table . "." . $par; |
|
| 964 | + $par = $boucle->id_table.".".$par; |
|
| 968 | 965 | } |
| 969 | 966 | // le champ est peut être une jointure |
| 970 | 967 | else { |
@@ -985,24 +982,24 @@ discard block |
||
| 985 | 982 | // Sinon on cherche le champ dans les tables possibles de jointures |
| 986 | 983 | // Si la table est déjà dans le from, on la réutilise. |
| 987 | 984 | if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
| 988 | - $par = $infos['alias'] . "." . $champ; |
|
| 985 | + $par = $infos['alias'].".".$champ; |
|
| 989 | 986 | } elseif ( |
| 990 | 987 | $boucle->jointures_explicites |
| 991 | 988 | and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
| 992 | 989 | ) { |
| 993 | - $par = $alias . "." . $champ; |
|
| 990 | + $par = $alias.".".$champ; |
|
| 994 | 991 | } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
| 995 | - $par = $alias . "." . $champ; |
|
| 992 | + $par = $alias.".".$champ; |
|
| 996 | 993 | // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
| 997 | 994 | } elseif ( |
| 998 | 995 | $table_alias |
| 999 | 996 | and isset($boucle->from[$table_alias]) |
| 1000 | 997 | and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
| 1001 | 998 | ) { |
| 1002 | - $par = $infos['alias'] . "." . $champ; |
|
| 999 | + $par = $infos['alias'].".".$champ; |
|
| 1003 | 1000 | } elseif ($table) { |
| 1004 | 1001 | // On avait table + champ, mais on ne les a pas trouvés |
| 1005 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " $par")); |
|
| 1002 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." $par")); |
|
| 1006 | 1003 | } else { |
| 1007 | 1004 | // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
| 1008 | 1005 | } |
@@ -1026,7 +1023,7 @@ discard block |
||
| 1026 | 1023 | if (!$t) { |
| 1027 | 1024 | $t = trouver_jointure_champ($champ, $boucle); |
| 1028 | 1025 | } |
| 1029 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1026 | + return !$t ? '' : ("'".$t.'.'.$champ."'"); |
|
| 1030 | 1027 | } |
| 1031 | 1028 | |
| 1032 | 1029 | /** |
@@ -1071,9 +1068,9 @@ discard block |
||
| 1071 | 1068 | $boucle->default_order[] = ' DESC'; |
| 1072 | 1069 | } |
| 1073 | 1070 | } else { |
| 1074 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1071 | + $t = $boucle->order[$n - 1]." . $order"; |
|
| 1075 | 1072 | if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
| 1076 | - $t = $r[1] . $r[2]; |
|
| 1073 | + $t = $r[1].$r[2]; |
|
| 1077 | 1074 | } |
| 1078 | 1075 | $boucle->order[$n - 1] = $t; |
| 1079 | 1076 | } |
@@ -1085,7 +1082,7 @@ discard block |
||
| 1085 | 1082 | $params = $crit->param; |
| 1086 | 1083 | |
| 1087 | 1084 | if (count($params) < 1) { |
| 1088 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " ?")); |
|
| 1085 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ?")); |
|
| 1089 | 1086 | } |
| 1090 | 1087 | |
| 1091 | 1088 | $boucle = &$boucles[$idb]; |
@@ -1106,7 +1103,7 @@ discard block |
||
| 1106 | 1103 | if ((count($date) == 1) and ($date[0]->type == 'texte')) { |
| 1107 | 1104 | $date = $date[0]->texte; |
| 1108 | 1105 | if (!isset($fields[$date])) { |
| 1109 | - return array('zbug_critere_inconnu', array('critere' => $crit->op . " " . $date)); |
|
| 1106 | + return array('zbug_critere_inconnu', array('critere' => $crit->op." ".$date)); |
|
| 1110 | 1107 | } |
| 1111 | 1108 | } else { |
| 1112 | 1109 | $a = calculer_liste($date, array(), $boucles, $parent); |
@@ -1118,38 +1115,38 @@ discard block |
||
| 1118 | 1115 | $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
| 1119 | 1116 | } |
| 1120 | 1117 | $annee = $params ? array_shift($params) : ""; |
| 1121 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1122 | - calculer_liste($annee, array(), $boucles, $parent) . |
|
| 1118 | + $annee = "\n".'sprintf("%04d", ($x = '. |
|
| 1119 | + calculer_liste($annee, array(), $boucles, $parent). |
|
| 1123 | 1120 | ') ? $x : date("Y"))'; |
| 1124 | 1121 | |
| 1125 | 1122 | $mois = $params ? array_shift($params) : ""; |
| 1126 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1127 | - calculer_liste($mois, array(), $boucles, $parent) . |
|
| 1123 | + $mois = "\n".'sprintf("%02d", ($x = '. |
|
| 1124 | + calculer_liste($mois, array(), $boucles, $parent). |
|
| 1128 | 1125 | ') ? $x : date("m"))'; |
| 1129 | 1126 | |
| 1130 | 1127 | $jour = $params ? array_shift($params) : ""; |
| 1131 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1132 | - calculer_liste($jour, array(), $boucles, $parent) . |
|
| 1128 | + $jour = "\n".'sprintf("%02d", ($x = '. |
|
| 1129 | + calculer_liste($jour, array(), $boucles, $parent). |
|
| 1133 | 1130 | ') ? $x : date("d"))'; |
| 1134 | 1131 | |
| 1135 | 1132 | $annee2 = $params ? array_shift($params) : ""; |
| 1136 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1137 | - calculer_liste($annee2, array(), $boucles, $parent) . |
|
| 1133 | + $annee2 = "\n".'sprintf("%04d", ($x = '. |
|
| 1134 | + calculer_liste($annee2, array(), $boucles, $parent). |
|
| 1138 | 1135 | ') ? $x : date("Y"))'; |
| 1139 | 1136 | |
| 1140 | 1137 | $mois2 = $params ? array_shift($params) : ""; |
| 1141 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1142 | - calculer_liste($mois2, array(), $boucles, $parent) . |
|
| 1138 | + $mois2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1139 | + calculer_liste($mois2, array(), $boucles, $parent). |
|
| 1143 | 1140 | ') ? $x : date("m"))'; |
| 1144 | 1141 | |
| 1145 | 1142 | $jour2 = $params ? array_shift($params) : ""; |
| 1146 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1147 | - calculer_liste($jour2, array(), $boucles, $parent) . |
|
| 1143 | + $jour2 = "\n".'sprintf("%02d", ($x = '. |
|
| 1144 | + calculer_liste($jour2, array(), $boucles, $parent). |
|
| 1148 | 1145 | ') ? $x : date("d"))'; |
| 1149 | 1146 | |
| 1150 | - $date = $boucle->id_table . ".$date"; |
|
| 1147 | + $date = $boucle->id_table.".$date"; |
|
| 1151 | 1148 | |
| 1152 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1149 | + $quote_end = ",'".$boucle->sql_serveur."','text'"; |
|
| 1153 | 1150 | if ($type == 'jour') { |
| 1154 | 1151 | $boucle->where[] = array( |
| 1155 | 1152 | "'='", |
@@ -1221,14 +1218,13 @@ discard block |
||
| 1221 | 1218 | list($a21, $a22) = calculer_critere_parties_aux($idb, $boucles, $a2); |
| 1222 | 1219 | |
| 1223 | 1220 | if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
| 1224 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1221 | + $boucle->limit = $a11.','.$a21; |
|
| 1225 | 1222 | } else { |
| 1226 | 1223 | // 3 dans {1/3}, {2,3} ou {1,n-3} |
| 1227 | 1224 | $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
| 1228 | 1225 | // 2 dans {2/3}, {2,5}, {n-2,1} |
| 1229 | 1226 | $partie = ($a11 != 'n') ? $a11 : $a12; |
| 1230 | - $mode = (($op == '/') ? '/' : |
|
| 1231 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1227 | + $mode = (($op == '/') ? '/' : (($a11 == 'n') ? '-' : '+').(($a21 == 'n') ? '-' : '+')); |
|
| 1232 | 1228 | // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
| 1233 | 1229 | if ($a11 !== 'n' and $a21 !== 'n' and $mode == "++" and $op == ',') { |
| 1234 | 1230 | $boucle->limit = |
@@ -1274,8 +1270,7 @@ discard block |
||
| 1274 | 1270 | // {1/3} |
| 1275 | 1271 | if ($op1 == '/') { |
| 1276 | 1272 | $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
| 1277 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1278 | - "($total_parties ? $total_parties : 1)"; |
|
| 1273 | + $totpos = is_numeric($total_parties) ? ($total_parties) : "($total_parties ? $total_parties : 1)"; |
|
| 1279 | 1274 | $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
| 1280 | 1275 | $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
| 1281 | 1276 | } else { |
@@ -1286,15 +1281,13 @@ discard block |
||
| 1286 | 1281 | |
| 1287 | 1282 | // cas {x,n-1} |
| 1288 | 1283 | if ($op2 == '-') { |
| 1289 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1290 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1291 | - ($total_parties . ' - 1')); |
|
| 1284 | + $fin = '$debut_boucle + '.$nombre_boucle.' - ' |
|
| 1285 | + . (is_numeric($total_parties) ? ($total_parties + 1) : ($total_parties.' - 1')); |
|
| 1292 | 1286 | } else { |
| 1293 | 1287 | // {x,1} ou {pagination} |
| 1294 | 1288 | $fin = '$debut_boucle' |
| 1295 | 1289 | . (is_numeric($total_parties) ? |
| 1296 | - (($total_parties == 1) ? "" : (' + ' . ($total_parties - 1))) : |
|
| 1297 | - ('+' . $total_parties . ' - 1')); |
|
| 1290 | + (($total_parties == 1) ? "" : (' + '.($total_parties - 1))) : ('+'.$total_parties.' - 1')); |
|
| 1298 | 1291 | } |
| 1299 | 1292 | |
| 1300 | 1293 | // {pagination}, gerer le debut_xx=-1 pour tout voir |
@@ -1312,11 +1305,11 @@ discard block |
||
| 1312 | 1305 | // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
| 1313 | 1306 | |
| 1314 | 1307 | $boucles[$id_boucle]->mode_partie = "\n\t" |
| 1315 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1308 | + . '$debut_boucle = '.$debut.";\n " |
|
| 1316 | 1309 | . "\$debut_boucle = intval(\$debut_boucle);\n " |
| 1317 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1318 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1319 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1310 | + . '$fin_boucle = min('.$fin.", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1311 | + . '$Numrows[\''.$id_boucle."']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1312 | + . '$Numrows[\''.$id_boucle.'\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1320 | 1313 | . "\n\tif (\$debut_boucle>0" |
| 1321 | 1314 | . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
| 1322 | 1315 | . " AND \$iter->seek(\$debut_boucle,'continue'))" |
@@ -1401,16 +1394,16 @@ discard block |
||
| 1401 | 1394 | // critere personnalise ? |
| 1402 | 1395 | if ( |
| 1403 | 1396 | (!$serveur or |
| 1404 | - ((!function_exists($f = "critere_" . $serveur . "_" . $table . "_" . $critere)) |
|
| 1405 | - and (!function_exists($f = $f . "_dist")) |
|
| 1406 | - and (!function_exists($f = "critere_" . $serveur . "_" . $critere)) |
|
| 1407 | - and (!function_exists($f = $f . "_dist")) |
|
| 1397 | + ((!function_exists($f = "critere_".$serveur."_".$table."_".$critere)) |
|
| 1398 | + and (!function_exists($f = $f."_dist")) |
|
| 1399 | + and (!function_exists($f = "critere_".$serveur."_".$critere)) |
|
| 1400 | + and (!function_exists($f = $f."_dist")) |
|
| 1408 | 1401 | ) |
| 1409 | 1402 | ) |
| 1410 | - and (!function_exists($f = "critere_" . $table . "_" . $critere)) |
|
| 1411 | - and (!function_exists($f = $f . "_dist")) |
|
| 1412 | - and (!function_exists($f = "critere_" . $critere)) |
|
| 1413 | - and (!function_exists($f = $f . "_dist")) |
|
| 1403 | + and (!function_exists($f = "critere_".$table."_".$critere)) |
|
| 1404 | + and (!function_exists($f = $f."_dist")) |
|
| 1405 | + and (!function_exists($f = "critere_".$critere)) |
|
| 1406 | + and (!function_exists($f = $f."_dist")) |
|
| 1414 | 1407 | ) { |
| 1415 | 1408 | // fonction critere standard |
| 1416 | 1409 | $f = $defaut; |
@@ -1443,9 +1436,9 @@ discard block |
||
| 1443 | 1436 | */ |
| 1444 | 1437 | function kwote($lisp, $serveur = '', $type = '') { |
| 1445 | 1438 | if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
| 1446 | - return $r[1] . "\"" . sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type) . "\""; |
|
| 1439 | + return $r[1]."\"".sql_quote(str_replace(array("\\'", "\\\\"), array("'", "\\"), $r[2]), $serveur, $type)."\""; |
|
| 1447 | 1440 | } else { |
| 1448 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1441 | + return "sql_quote($lisp, '$serveur', '".str_replace("'", "\\'", $type)."')"; |
|
| 1449 | 1442 | } |
| 1450 | 1443 | } |
| 1451 | 1444 | |
@@ -1467,7 +1460,7 @@ discard block |
||
| 1467 | 1460 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1468 | 1461 | $r = calculer_critere_infixe($idb, $boucles, $crit); |
| 1469 | 1462 | if (!$r) { |
| 1470 | - return (array('zbug_critere_inconnu', array('critere' => $crit->op . " ?"))); |
|
| 1463 | + return (array('zbug_critere_inconnu', array('critere' => $crit->op." ?"))); |
|
| 1471 | 1464 | } |
| 1472 | 1465 | list($arg, $op, $val, $col, $where_complement) = $r; |
| 1473 | 1466 | |
@@ -1494,8 +1487,8 @@ discard block |
||
| 1494 | 1487 | "'NOT'", |
| 1495 | 1488 | array( |
| 1496 | 1489 | "'IN'", |
| 1497 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1498 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1490 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1491 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1499 | 1492 | ) |
| 1500 | 1493 | ); |
| 1501 | 1494 | } |
@@ -1514,22 +1507,22 @@ discard block |
||
| 1514 | 1507 | $descr = $boucles[$idb]->descr; |
| 1515 | 1508 | $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
| 1516 | 1509 | |
| 1517 | - $var = '$in' . $cpt++; |
|
| 1510 | + $var = '$in'.$cpt++; |
|
| 1518 | 1511 | $x = "\n\t$var = array();"; |
| 1519 | 1512 | foreach ($val as $k => $v) { |
| 1520 | 1513 | if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
| 1521 | 1514 | // optimiser le traitement des constantes |
| 1522 | 1515 | if (is_numeric($r[2])) { |
| 1523 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1516 | + $x .= "\n\t$var"."[]= $r[2];"; |
|
| 1524 | 1517 | } else { |
| 1525 | - $x .= "\n\t$var" . "[]= " . sql_quote($r[2]) . ";"; |
|
| 1518 | + $x .= "\n\t$var"."[]= ".sql_quote($r[2]).";"; |
|
| 1526 | 1519 | } |
| 1527 | 1520 | } else { |
| 1528 | 1521 | // Pour permettre de passer des tableaux de valeurs |
| 1529 | 1522 | // on repere l'utilisation brute de #ENV**{X}, |
| 1530 | 1523 | // c'est-a-dire sa traduction en ($PILE[0][X]). |
| 1531 | 1524 | // et on deballe mais en rajoutant l'anti XSS |
| 1532 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1525 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var"."[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1533 | 1526 | } |
| 1534 | 1527 | } |
| 1535 | 1528 | |
@@ -1543,7 +1536,7 @@ discard block |
||
| 1543 | 1536 | $boucles[$idb]->default_order[] = "((!sql_quote($var) OR sql_quote($var)===\"''\") ? 0 : ('FIELD($arg,' . sql_quote($var) . ')'))"; |
| 1544 | 1537 | } |
| 1545 | 1538 | |
| 1546 | - return "sql_in('$arg',sql_quote($var)" . ($crit2 == 'NOT' ? ",'NOT'" : "") . ")"; |
|
| 1539 | + return "sql_in('$arg',sql_quote($var)".($crit2 == 'NOT' ? ",'NOT'" : "").")"; |
|
| 1547 | 1540 | } |
| 1548 | 1541 | |
| 1549 | 1542 | /** |
@@ -1729,8 +1722,8 @@ discard block |
||
| 1729 | 1722 | "'NOT'", |
| 1730 | 1723 | array( |
| 1731 | 1724 | "'IN'", |
| 1732 | - "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", |
|
| 1733 | - array("'SELF'", "'" . $boucles[$idb]->id_table . "." . $boucles[$idb]->primary . "'", $where) |
|
| 1725 | + "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", |
|
| 1726 | + array("'SELF'", "'".$boucles[$idb]->id_table.".".$boucles[$idb]->primary."'", $where) |
|
| 1734 | 1727 | ) |
| 1735 | 1728 | ); |
| 1736 | 1729 | } |
@@ -1741,7 +1734,7 @@ discard block |
||
| 1741 | 1734 | if ($crit->cond) { |
| 1742 | 1735 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1743 | 1736 | if ($col == "date" or $col == "date_redac") { |
| 1744 | - if ($pred == "\$Pile[0]['" . $col . "']") { |
|
| 1737 | + if ($pred == "\$Pile[0]['".$col."']") { |
|
| 1745 | 1738 | $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
| 1746 | 1739 | } |
| 1747 | 1740 | } |
@@ -1902,7 +1895,7 @@ discard block |
||
| 1902 | 1895 | // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
| 1903 | 1896 | // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
| 1904 | 1897 | if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
| 1905 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 1898 | + $val[0] = $r[1].'"'.sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote).'"'; |
|
| 1906 | 1899 | } |
| 1907 | 1900 | // sinon expliciter les |
| 1908 | 1901 | // sql_quote(truc) en sql_quote(truc,'',type) |
@@ -1913,22 +1906,22 @@ discard block |
||
| 1913 | 1906 | // sql_quote(truc,'','varchar') |
| 1914 | 1907 | elseif (preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
| 1915 | 1908 | // si pas deja un type |
| 1916 | - and (!isset($r[3]) or !$r[3] or !trim($r[3],", '")) |
|
| 1909 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 1917 | 1910 | ) { |
| 1918 | 1911 | $r = $r[1] |
| 1919 | 1912 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 1920 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 1913 | + . ",'".addslashes($type_cast_quote)."'"; |
|
| 1921 | 1914 | $val[0] = "sql_quote($r)"; |
| 1922 | 1915 | } |
| 1923 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1916 | + elseif (strpos($val[0], '@@defaultcast@@') !== false |
|
| 1924 | 1917 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 1925 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 1918 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'".addslashes($type_cast_quote)."')"; |
|
| 1926 | 1919 | } |
| 1927 | 1920 | } |
| 1928 | 1921 | |
| 1929 | - if(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1922 | + if (strpos($val[0], '@@defaultcast@@') !== false |
|
| 1930 | 1923 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 1931 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 1924 | + $val[0] = substr($val[0], 0, -strlen($r[0]))."'char')"; |
|
| 1932 | 1925 | } |
| 1933 | 1926 | |
| 1934 | 1927 | // Indicateur pour permettre aux fonctionx boucle_X de modifier |
@@ -1953,7 +1946,7 @@ discard block |
||
| 1953 | 1946 | // inserer le nom de la table SQL devant le nom du champ |
| 1954 | 1947 | if ($table) { |
| 1955 | 1948 | if ($col[0] == "`") { |
| 1956 | - $arg = "$table." . substr($col, 1, -1); |
|
| 1949 | + $arg = "$table.".substr($col, 1, -1); |
|
| 1957 | 1950 | } else { |
| 1958 | 1951 | $arg = "$table.$col"; |
| 1959 | 1952 | } |
@@ -2087,9 +2080,9 @@ discard block |
||
| 2087 | 2080 | **/ |
| 2088 | 2081 | function primary_doublee($decompose, $table) { |
| 2089 | 2082 | $e1 = reset($decompose); |
| 2090 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2083 | + $e2 = "sql_quote('".end($decompose)."')"; |
|
| 2091 | 2084 | |
| 2092 | - return array("'='", "'$table." . $e1 . "'", $e2); |
|
| 2085 | + return array("'='", "'$table.".$e1."'", $e2); |
|
| 2093 | 2086 | } |
| 2094 | 2087 | |
| 2095 | 2088 | /** |
@@ -2127,7 +2120,7 @@ discard block |
||
| 2127 | 2120 | if ($checkarrivee |
| 2128 | 2121 | and is_string($checkarrivee) |
| 2129 | 2122 | and $a = table_objet($checkarrivee) |
| 2130 | - and in_array($a . '_liens', $joints) |
|
| 2123 | + and in_array($a.'_liens', $joints) |
|
| 2131 | 2124 | ) { |
| 2132 | 2125 | if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
| 2133 | 2126 | return $res; |
@@ -2147,12 +2140,12 @@ discard block |
||
| 2147 | 2140 | // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
| 2148 | 2141 | $joindre = false; |
| 2149 | 2142 | foreach ($cols as $col) { |
| 2150 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2143 | + $c = '/\b'.$t.".$col".'\b/'; |
|
| 2151 | 2144 | if (trouver_champ($c, $boucle->where)) { |
| 2152 | 2145 | $joindre = true; |
| 2153 | 2146 | } else { |
| 2154 | 2147 | // mais ca peut etre dans le FIELD pour le Having |
| 2155 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2148 | + $c = "/FIELD.$t".".$col,/"; |
|
| 2156 | 2149 | if (trouver_champ($c, $boucle->select)) { |
| 2157 | 2150 | $joindre = true; |
| 2158 | 2151 | } |
@@ -2199,7 +2192,7 @@ discard block |
||
| 2199 | 2192 | $primary_arrivee = id_table_objet($checkarrivee); |
| 2200 | 2193 | |
| 2201 | 2194 | // [FIXME] $checkarrivee peut-il arriver avec false ???? |
| 2202 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . "_liens"); |
|
| 2195 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee."_liens"); |
|
| 2203 | 2196 | $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
| 2204 | 2197 | |
| 2205 | 2198 | if (!$intermediaire or !$arrivee) { |
@@ -2297,7 +2290,7 @@ discard block |
||
| 2297 | 2290 | } elseif ($crit->cond and ($col == "date" or $col == "date_redac")) { |
| 2298 | 2291 | // un critere conditionnel sur date est traite a part |
| 2299 | 2292 | // car la date est mise d'office par SPIP, |
| 2300 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2293 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['".$col."'])"; |
|
| 2301 | 2294 | } |
| 2302 | 2295 | |
| 2303 | 2296 | $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
@@ -2329,7 +2322,7 @@ discard block |
||
| 2329 | 2322 | and (($p == "'") or ($p == '"')) |
| 2330 | 2323 | and $params[0][1]->type == 'champ' |
| 2331 | 2324 | ) { |
| 2332 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2325 | + $val[] = "$p\\$p#".$params[0][1]->nom_champ."\\$p$p"; |
|
| 2333 | 2326 | } else { |
| 2334 | 2327 | foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
| 2335 | 2328 | $a = calculer_liste($p, $desc, $boucles, $parent); |
@@ -2345,7 +2338,7 @@ discard block |
||
| 2345 | 2338 | $fct = $args_sql = ''; |
| 2346 | 2339 | // fonction SQL ? |
| 2347 | 2340 | // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
| 2348 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2341 | + if (preg_match('/^(.*)'.SQL_ARGS.'$/', $col, $m)) { |
|
| 2349 | 2342 | $fct = $m[1]; |
| 2350 | 2343 | preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
| 2351 | 2344 | $col = $a[1]; |
@@ -2435,7 +2428,7 @@ discard block |
||
| 2435 | 2428 | # si oui choisir ce champ, sinon choisir xxxx |
| 2436 | 2429 | |
| 2437 | 2430 | if (isset($table['field']["date$suite"])) { |
| 2438 | - $date_orig = 'date' . $suite; |
|
| 2431 | + $date_orig = 'date'.$suite; |
|
| 2439 | 2432 | } else { |
| 2440 | 2433 | $date_orig = substr($suite, 1); |
| 2441 | 2434 | } |
@@ -2446,12 +2439,12 @@ discard block |
||
| 2446 | 2439 | } |
| 2447 | 2440 | } |
| 2448 | 2441 | |
| 2449 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2450 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2442 | + $date_compare = "\"' . normaliser_date(". |
|
| 2443 | + calculer_argument_precedent($idb, $pred, $boucles). |
|
| 2451 | 2444 | ") . '\""; |
| 2452 | 2445 | |
| 2453 | 2446 | $col_vraie = $date_orig; |
| 2454 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2447 | + $date_orig = $boucle->id_table.'.'.$date_orig; |
|
| 2455 | 2448 | |
| 2456 | 2449 | switch ($col) { |
| 2457 | 2450 | case 'date': |
@@ -2471,26 +2464,26 @@ discard block |
||
| 2471 | 2464 | break; |
| 2472 | 2465 | case 'age': |
| 2473 | 2466 | $col = calculer_param_date("NOW()", $date_orig); |
| 2474 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2467 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2475 | 2468 | break; |
| 2476 | 2469 | case 'age_relatif': |
| 2477 | 2470 | $col = calculer_param_date($date_compare, $date_orig); |
| 2478 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2471 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2479 | 2472 | break; |
| 2480 | 2473 | case 'jour_relatif': |
| 2481 | - $col = "(TO_DAYS(" . $date_compare . ")-TO_DAYS(" . $date_orig . "))"; |
|
| 2482 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2474 | + $col = "(TO_DAYS(".$date_compare.")-TO_DAYS(".$date_orig."))"; |
|
| 2475 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2483 | 2476 | break; |
| 2484 | 2477 | case 'mois_relatif': |
| 2485 | - $col = "MONTH(" . $date_compare . ")-MONTH(" . |
|
| 2486 | - $date_orig . ")+12*(YEAR(" . $date_compare . |
|
| 2487 | - ")-YEAR(" . $date_orig . "))"; |
|
| 2488 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2478 | + $col = "MONTH(".$date_compare.")-MONTH(". |
|
| 2479 | + $date_orig.")+12*(YEAR(".$date_compare. |
|
| 2480 | + ")-YEAR(".$date_orig."))"; |
|
| 2481 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2489 | 2482 | break; |
| 2490 | 2483 | case 'annee_relatif': |
| 2491 | - $col = "YEAR(" . $date_compare . ")-YEAR(" . |
|
| 2492 | - $date_orig . ")"; |
|
| 2493 | - $col_vraie = "";// comparer a un int (par defaut) |
|
| 2484 | + $col = "YEAR(".$date_compare.")-YEAR(". |
|
| 2485 | + $date_orig.")"; |
|
| 2486 | + $col_vraie = ""; // comparer a un int (par defaut) |
|
| 2494 | 2487 | break; |
| 2495 | 2488 | } |
| 2496 | 2489 | |
@@ -2549,10 +2542,10 @@ discard block |
||
| 2549 | 2542 | } |
| 2550 | 2543 | |
| 2551 | 2544 | $boucle->hash .= ' |
| 2552 | - $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
|
| 2545 | + $command[\'sourcemode\'] = ' . array_shift($args).";\n"; |
|
| 2553 | 2546 | |
| 2554 | 2547 | $boucle->hash .= ' |
| 2555 | - $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
|
| 2548 | + $command[\'source\'] = array(' . join(', ', $args).");\n"; |
|
| 2556 | 2549 | } |
| 2557 | 2550 | |
| 2558 | 2551 | |
@@ -2570,8 +2563,8 @@ discard block |
||
| 2570 | 2563 | function critere_DATA_datasource_dist($idb, &$boucles, $crit) { |
| 2571 | 2564 | $boucle = &$boucles[$idb]; |
| 2572 | 2565 | $boucle->hash .= ' |
| 2573 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2574 | - $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2566 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2567 | + $command[\'sourcemode\'] = ' . calculer_liste($crit->param[1], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2575 | 2568 | } |
| 2576 | 2569 | |
| 2577 | 2570 | |
@@ -2591,7 +2584,7 @@ discard block |
||
| 2591 | 2584 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2592 | 2585 | $boucle = &$boucles[$idb]; |
| 2593 | 2586 | $boucle->hash .= ' |
| 2594 | - $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2587 | + $command[\'datacache\'] = ' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2595 | 2588 | } |
| 2596 | 2589 | |
| 2597 | 2590 | |
@@ -2610,7 +2603,7 @@ discard block |
||
| 2610 | 2603 | $boucle->hash .= '$command[\'args\']=array();'; |
| 2611 | 2604 | foreach ($crit->param as $param) { |
| 2612 | 2605 | $boucle->hash .= ' |
| 2613 | - $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2606 | + $command[\'args\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2614 | 2607 | } |
| 2615 | 2608 | } |
| 2616 | 2609 | |
@@ -2629,10 +2622,10 @@ discard block |
||
| 2629 | 2622 | */ |
| 2630 | 2623 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2631 | 2624 | $boucle = &$boucles[$idb]; |
| 2632 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2625 | + $boucle->hash .= "\n\t".'$command[\'liste\'] = array();'."\n"; |
|
| 2633 | 2626 | foreach ($crit->param as $param) { |
| 2634 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2635 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2627 | + $boucle->hash .= "\t".'$command[\'liste\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2628 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2636 | 2629 | } |
| 2637 | 2630 | } |
| 2638 | 2631 | |
@@ -2659,10 +2652,10 @@ discard block |
||
| 2659 | 2652 | */ |
| 2660 | 2653 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2661 | 2654 | $boucle = &$boucles[$idb]; |
| 2662 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2655 | + $boucle->hash .= "\n\t".'$command[\'enum\'] = array();'."\n"; |
|
| 2663 | 2656 | foreach ($crit->param as $param) { |
| 2664 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste($param, array(), $boucles, |
|
| 2665 | - $boucles[$idb]->id_parent) . ";\n"; |
|
| 2657 | + $boucle->hash .= "\t".'$command[\'enum\'][] = '.calculer_liste($param, array(), $boucles, |
|
| 2658 | + $boucles[$idb]->id_parent).";\n"; |
|
| 2666 | 2659 | } |
| 2667 | 2660 | } |
| 2668 | 2661 | |
@@ -2681,7 +2674,7 @@ discard block |
||
| 2681 | 2674 | $boucle = &$boucles[$idb]; |
| 2682 | 2675 | foreach ($crit->param as $param) { |
| 2683 | 2676 | $boucle->hash .= ' |
| 2684 | - $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ';'; |
|
| 2677 | + $command[\'datapath\'][] = ' . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).';'; |
|
| 2685 | 2678 | } |
| 2686 | 2679 | } |
| 2687 | 2680 | |
@@ -2722,7 +2715,7 @@ discard block |
||
| 2722 | 2715 | if ($crit->param) { |
| 2723 | 2716 | foreach ($crit->param as $param) { |
| 2724 | 2717 | $boucle->hash .= "\t\$command['si'][] = " |
| 2725 | - . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2718 | + . calculer_liste($param, array(), $boucles, $boucles[$idb]->id_parent).";\n"; |
|
| 2726 | 2719 | } |
| 2727 | 2720 | // interdire {si 0} aussi ! |
| 2728 | 2721 | } else { |
@@ -2745,7 +2738,7 @@ discard block |
||
| 2745 | 2738 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2746 | 2739 | $boucle = &$boucles[$idb]; |
| 2747 | 2740 | $boucle->hash .= ' |
| 2748 | - $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent) . '); |
|
| 2741 | + $command[\'source\'] = array(' . calculer_liste($crit->param[0], array(), $boucles, $boucles[$idb]->id_parent).'); |
|
| 2749 | 2742 | $command[\'sourcemode\'] = \'table\';'; |
| 2750 | 2743 | } |
| 2751 | 2744 | |
@@ -2778,11 +2771,10 @@ discard block |
||
| 2778 | 2771 | $table_sql = table_objet_sql(objet_type($table)); |
| 2779 | 2772 | |
| 2780 | 2773 | $id_parent = isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent']) ? |
| 2781 | - $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : |
|
| 2782 | - 'id_parent'; |
|
| 2774 | + $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] : 'id_parent'; |
|
| 2783 | 2775 | |
| 2784 | 2776 | $in = "IN"; |
| 2785 | - $where = array("'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2777 | + $where = array("'IN'", "'$boucle->id_table."."$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"); |
|
| 2786 | 2778 | if ($not) { |
| 2787 | 2779 | $where = array("'NOT'", $where); |
| 2788 | 2780 | } |
@@ -1478,10 +1478,12 @@ discard block |
||
| 1478 | 1478 | if ($crit->cond) { |
| 1479 | 1479 | $pred = calculer_argument_precedent($idb, $col, $boucles); |
| 1480 | 1480 | $where = array("'?'", $pred, $where, "''"); |
| 1481 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1481 | + if ($where_complement) { |
|
| 1482 | + // condition annexe du type "AND (objet='article')" |
|
| 1482 | 1483 | { |
| 1483 | 1484 | $where_complement = array("'?'", $pred, $where_complement, "''"); |
| 1484 | 1485 | } |
| 1486 | + } |
|
| 1485 | 1487 | } |
| 1486 | 1488 | if ($crit->exclus) { |
| 1487 | 1489 | if (!preg_match(",^L[0-9]+[.],", $arg)) { |
@@ -1502,10 +1504,12 @@ discard block |
||
| 1502 | 1504 | } |
| 1503 | 1505 | |
| 1504 | 1506 | $boucles[$idb]->where[] = $where; |
| 1505 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1507 | + if ($where_complement) { |
|
| 1508 | + // condition annexe du type "AND (objet='article')" |
|
| 1506 | 1509 | { |
| 1507 | 1510 | $boucles[$idb]->where[] = $where_complement; |
| 1508 | 1511 | } |
| 1512 | + } |
|
| 1509 | 1513 | } |
| 1510 | 1514 | |
| 1511 | 1515 | // http://code.spip.net/@critere_IN_cas |
@@ -1755,17 +1759,21 @@ discard block |
||
| 1755 | 1759 | ); |
| 1756 | 1760 | } |
| 1757 | 1761 | $where = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where); |
| 1758 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1762 | + if ($where_complement) { |
|
| 1763 | + // condition annexe du type "AND (objet='article')" |
|
| 1759 | 1764 | { |
| 1760 | 1765 | $where_complement = array("'?'", "!(is_array($pred)?count($pred):strlen($pred))", "''", $where_complement); |
| 1761 | 1766 | } |
| 1767 | + } |
|
| 1762 | 1768 | } |
| 1763 | 1769 | |
| 1764 | 1770 | $boucles[$idb]->where[] = $where; |
| 1765 | - if ($where_complement) // condition annexe du type "AND (objet='article')" |
|
| 1771 | + if ($where_complement) { |
|
| 1772 | + // condition annexe du type "AND (objet='article')" |
|
| 1766 | 1773 | { |
| 1767 | 1774 | $boucles[$idb]->where[] = $where_complement; |
| 1768 | 1775 | } |
| 1776 | + } |
|
| 1769 | 1777 | } |
| 1770 | 1778 | |
| 1771 | 1779 | |
@@ -1876,8 +1884,7 @@ discard block |
||
| 1876 | 1884 | // Champ joker * des iterateurs DATA qui accepte tout |
| 1877 | 1885 | if (@array_key_exists('*', $desc['field'])) { |
| 1878 | 1886 | $desc['field'][$col_vraie ? $col_vraie : $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
| 1879 | - } |
|
| 1880 | - else { |
|
| 1887 | + } else { |
|
| 1881 | 1888 | $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
| 1882 | 1889 | if (!$r) { |
| 1883 | 1890 | return ''; |
@@ -1919,8 +1926,7 @@ discard block |
||
| 1919 | 1926 | . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
| 1920 | 1927 | . ",'" . addslashes($type_cast_quote) . "'"; |
| 1921 | 1928 | $val[0] = "sql_quote($r)"; |
| 1922 | - } |
|
| 1923 | - elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1929 | + } elseif(strpos($val[0], '@@defaultcast@@') !== false |
|
| 1924 | 1930 | and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r)) { |
| 1925 | 1931 | $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
| 1926 | 1932 | } |
@@ -418,6 +418,10 @@ discard block |
||
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // http://code.spip.net/@reference_boucle_debug |
| 421 | +/** |
|
| 422 | + * @param string $nom |
|
| 423 | + * @param string $self |
|
| 424 | + */ |
|
| 421 | 425 | function reference_boucle_debug($n, $nom, $self) { |
| 422 | 426 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 423 | 427 | |
@@ -806,6 +810,9 @@ discard block |
||
| 806 | 810 | } |
| 807 | 811 | |
| 808 | 812 | // http://code.spip.net/@debusquer_entete |
| 813 | +/** |
|
| 814 | + * @param string $corps |
|
| 815 | + */ |
|
| 809 | 816 | function debusquer_entete($titre, $corps) { |
| 810 | 817 | |
| 811 | 818 | include_spip('balise/formulaire_admin'); |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('public/decompiler'); |
@@ -66,135 +66,135 @@ discard block |
||
| 66 | 66 | * - string si $message à false. |
| 67 | 67 | **/ |
| 68 | 68 | function public_debusquer_dist($message = '', $lieu = '', $opt = array()) { |
| 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 | - |
|
| 79 | - return true; |
|
| 80 | - } |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // Erreur ou appel final ? |
|
| 84 | - if ($message) { |
|
| 85 | - $message = debusquer_compose_message($message); |
|
| 86 | - $tableau_des_erreurs[] = array($message, $lieu); |
|
| 87 | - set_request('var_mode', 'debug'); |
|
| 88 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | - // Permettre a la compil de continuer |
|
| 90 | - if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | - $lieu->code = "''"; |
|
| 92 | - } |
|
| 93 | - // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | - $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | - if (!$urgence) { |
|
| 96 | - return; |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | - // espace public ? |
|
| 101 | - if (isset($GLOBALS['fond'])) { |
|
| 102 | - $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/autoriser'); |
|
| 107 | - if (!autoriser('debug')) { |
|
| 108 | - return; |
|
| 109 | - } |
|
| 110 | - include_spip('inc/headers'); |
|
| 111 | - include_spip('inc/filtres'); |
|
| 112 | - |
|
| 113 | - // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | - // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | - // - ca fait 2 headers ! |
|
| 116 | - // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | - // actif par exemple) |
|
| 118 | - if (ob_get_length() |
|
| 119 | - and |
|
| 120 | - !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | - ) { |
|
| 122 | - ob_end_clean(); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | - $fonc = _request('var_mode_objet'); |
|
| 127 | - $mode = _request('var_mode_affiche'); |
|
| 128 | - $self = str_replace("\\'", ''', self()); |
|
| 129 | - $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | - |
|
| 131 | - $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | - . '<br />' |
|
| 133 | - . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | - |
|
| 135 | - if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | - return $res; |
|
| 137 | - } |
|
| 138 | - if ($tableau_des_erreurs) { |
|
| 139 | - http_status(503); |
|
| 140 | - } |
|
| 141 | - |
|
| 142 | - http_no_cache(); |
|
| 143 | - if (isset($_GET['var_profile'])) { |
|
| 144 | - $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | - $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | - } else { |
|
| 147 | - if (!$fonc) { |
|
| 148 | - $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | - } |
|
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | - } |
|
| 152 | - if ($message === false) { |
|
| 153 | - lang_select(); |
|
| 154 | - |
|
| 155 | - return debusquer_entete($titre, $res); |
|
| 156 | - } else { |
|
| 157 | - echo debusquer_entete($titre, $res); |
|
| 158 | - } |
|
| 159 | - exit; |
|
| 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 | + |
|
| 79 | + return true; |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // Erreur ou appel final ? |
|
| 84 | + if ($message) { |
|
| 85 | + $message = debusquer_compose_message($message); |
|
| 86 | + $tableau_des_erreurs[] = array($message, $lieu); |
|
| 87 | + set_request('var_mode', 'debug'); |
|
| 88 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 89 | + // Permettre a la compil de continuer |
|
| 90 | + if (is_object($lieu) and (!isset($lieu->code) or !$lieu->code)) { |
|
| 91 | + $lieu->code = "''"; |
|
| 92 | + } |
|
| 93 | + // forcer l'appel au debusqueur en cas de boucles infernales |
|
| 94 | + $urgence = (_DEBUG_MAX_SQUELETTE_ERREURS and count($tableau_des_erreurs) > _DEBUG_MAX_SQUELETTE_ERREURS); |
|
| 95 | + if (!$urgence) { |
|
| 96 | + return; |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + if (empty($GLOBALS['debug_objets']['principal'])) { |
|
| 100 | + // espace public ? |
|
| 101 | + if (isset($GLOBALS['fond'])) { |
|
| 102 | + $GLOBALS['debug_objets']['principal'] = $GLOBALS['fond']; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/autoriser'); |
|
| 107 | + if (!autoriser('debug')) { |
|
| 108 | + return; |
|
| 109 | + } |
|
| 110 | + include_spip('inc/headers'); |
|
| 111 | + include_spip('inc/filtres'); |
|
| 112 | + |
|
| 113 | + // en cas de squelette inclus, virer le code de l'incluant: |
|
| 114 | + // - il contient souvent une Div restreignant la largeur a 3 fois rien |
|
| 115 | + // - ca fait 2 headers ! |
|
| 116 | + // sauf si l'on se trouve deja dans un flux compresse (plugin compresseur |
|
| 117 | + // actif par exemple) |
|
| 118 | + if (ob_get_length() |
|
| 119 | + and |
|
| 120 | + !in_array('ob_gzhandler', ob_get_status()) |
|
| 121 | + ) { |
|
| 122 | + ob_end_clean(); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 126 | + $fonc = _request('var_mode_objet'); |
|
| 127 | + $mode = _request('var_mode_affiche'); |
|
| 128 | + $self = str_replace("\\'", ''', self()); |
|
| 129 | + $self = parametre_url($self, 'var_mode', 'debug'); |
|
| 130 | + |
|
| 131 | + $res = debusquer_bandeau($tableau_des_erreurs) |
|
| 132 | + . '<br />' |
|
| 133 | + . debusquer_squelette($fonc, $mode, $self); |
|
| 134 | + |
|
| 135 | + if (!_DIR_RESTREINT or headers_sent()) { |
|
| 136 | + return $res; |
|
| 137 | + } |
|
| 138 | + if ($tableau_des_erreurs) { |
|
| 139 | + http_status(503); |
|
| 140 | + } |
|
| 141 | + |
|
| 142 | + http_no_cache(); |
|
| 143 | + if (isset($_GET['var_profile'])) { |
|
| 144 | + $titre = parametre_url($GLOBALS['REQUEST_URI'], 'var_profile', ''); |
|
| 145 | + $titre = parametre_url($titre, 'var_mode', ''); |
|
| 146 | + } else { |
|
| 147 | + if (!$fonc) { |
|
| 148 | + $fonc = $GLOBALS['debug_objets']['principal']; |
|
| 149 | + } |
|
| 150 | + $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | + } |
|
| 152 | + if ($message === false) { |
|
| 153 | + lang_select(); |
|
| 154 | + |
|
| 155 | + return debusquer_entete($titre, $res); |
|
| 156 | + } else { |
|
| 157 | + echo debusquer_entete($titre, $res); |
|
| 158 | + } |
|
| 159 | + exit; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | function debusquer_compose_message($msg) { |
| 163 | - if (is_array($msg)) { |
|
| 164 | - // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | - // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | - if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | - // message avec argument: instancier |
|
| 168 | - $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | - } else { |
|
| 170 | - // message SQL: interpreter |
|
| 171 | - $msg = debusquer_requete($msg); |
|
| 172 | - } |
|
| 173 | - } |
|
| 174 | - // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | - // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | - $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | - // une erreur critique sort $message en array |
|
| 178 | - $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | - |
|
| 181 | - return $msg; |
|
| 163 | + if (is_array($msg)) { |
|
| 164 | + // si c'est un texte, c'est une traduction a faire, mais |
|
| 165 | + // sqlite renvoit aussi des erreurs alpha num (mais avec 3 arguments) |
|
| 166 | + if (!is_numeric($msg[0]) and count($msg) == 2) { |
|
| 167 | + // message avec argument: instancier |
|
| 168 | + $msg = _T($msg[0], $msg[1], 'spip-debug-arg'); |
|
| 169 | + } else { |
|
| 170 | + // message SQL: interpreter |
|
| 171 | + $msg = debusquer_requete($msg); |
|
| 172 | + } |
|
| 173 | + } |
|
| 174 | + // FIXME: le fond n'est pas la si on n'est pas dans un squelette |
|
| 175 | + // cela dit, ca serait bien d'indiquer tout de meme d'ou vient l'erreur |
|
| 176 | + $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
|
| 177 | + // une erreur critique sort $message en array |
|
| 178 | + $debug = is_array($msg) ? $msg[1] : $msg; |
|
| 179 | + spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 180 | + |
|
| 181 | + return $msg; |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | - if (!empty($erreurs)) { |
|
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 186 | + if (!empty($erreurs)) { |
|
| 187 | + $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | - return debusquer_navigation($erreurs, $n); |
|
| 190 | - } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | - include_spip('public/tracer'); |
|
| 192 | - list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 189 | + return debusquer_navigation($erreurs, $n); |
|
| 190 | + } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
|
| 191 | + include_spip('public/tracer'); |
|
| 192 | + list($temps, $nav) = chrono_requete($GLOBALS['tableau_des_temps']); |
|
| 193 | 193 | |
| 194 | - return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | - } else { |
|
| 196 | - return ''; |
|
| 197 | - } |
|
| 194 | + return debusquer_navigation($temps, $nav, 'debug-profile'); |
|
| 195 | + } else { |
|
| 196 | + return ''; |
|
| 197 | + } |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | /** |
@@ -205,28 +205,28 @@ discard block |
||
| 205 | 205 | **/ |
| 206 | 206 | function debusquer_contexte($env) { |
| 207 | 207 | |
| 208 | - if (is_array($env_tab = @unserialize($env))) { |
|
| 209 | - $env = $env_tab; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - if (!$env) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $res = ""; |
|
| 216 | - foreach ($env as $nom => $valeur) { |
|
| 217 | - if (is_array($valeur)) { |
|
| 218 | - $valeur_simple = array(); |
|
| 219 | - foreach ($valeur as $v) { |
|
| 220 | - $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 221 | - } |
|
| 222 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 223 | - } |
|
| 224 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 226 | - . "</td></tr>\n"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 208 | + if (is_array($env_tab = @unserialize($env))) { |
|
| 209 | + $env = $env_tab; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + if (!$env) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $res = ""; |
|
| 216 | + foreach ($env as $nom => $valeur) { |
|
| 217 | + if (is_array($valeur)) { |
|
| 218 | + $valeur_simple = array(); |
|
| 219 | + foreach ($valeur as $v) { |
|
| 220 | + $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 221 | + } |
|
| 222 | + $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 223 | + } |
|
| 224 | + $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | + . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 226 | + . "</td></tr>\n"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return "<div class='spip-env'><fieldset><legend>#ENV</legend>\n<div><table>$res</table></div></fieldset></div>\n"; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | // Affichage du tableau des erreurs ou des temps de calcul |
@@ -234,67 +234,67 @@ discard block |
||
| 234 | 234 | |
| 235 | 235 | function debusquer_navigation($tableau, $caption = array(), $id = 'debug-nav') { |
| 236 | 236 | |
| 237 | - if (_request('exec') == 'valider_xml') { |
|
| 238 | - return ''; |
|
| 239 | - } |
|
| 240 | - $GLOBALS['bouton_admin_debug'] = true; |
|
| 241 | - $res = ''; |
|
| 242 | - $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 243 | - foreach ($tableau as $i => $err) { |
|
| 244 | - $boucle = $ligne = $skel = ''; |
|
| 245 | - list($msg, $lieu) = $err; |
|
| 246 | - if (is_object($lieu)) { |
|
| 247 | - $ligne = $lieu->ligne; |
|
| 248 | - $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 249 | - if (isset($lieu->descr['nom'])) { |
|
| 250 | - $nom_code = $lieu->descr['nom']; |
|
| 251 | - $skel = $lieu->descr['sourcefile']; |
|
| 252 | - $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 253 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 254 | - $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 255 | - if ($boucle) { |
|
| 256 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | - $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 258 | - } |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - |
|
| 262 | - $j = ($i + 1); |
|
| 263 | - $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 264 | - . $j |
|
| 265 | - . " </td><td style='text-align: left'>" |
|
| 266 | - . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 267 | - . "</td><td style='text-align: left'>" |
|
| 268 | - . ($skel ? $skel : " / ") |
|
| 269 | - . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 270 | - . ($boucle ? $boucle : " / ") |
|
| 271 | - . "</td><td style='text-align: right'>" |
|
| 272 | - . $ligne |
|
| 273 | - . "</td></tr>\n"; |
|
| 274 | - |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - return "\n<table id='$id'>" |
|
| 278 | - . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 279 | - . $caption[0] |
|
| 237 | + if (_request('exec') == 'valider_xml') { |
|
| 238 | + return ''; |
|
| 239 | + } |
|
| 240 | + $GLOBALS['bouton_admin_debug'] = true; |
|
| 241 | + $res = ''; |
|
| 242 | + $href = quote_amp(parametre_url($GLOBALS['REQUEST_URI'], 'var_mode', 'debug')); |
|
| 243 | + foreach ($tableau as $i => $err) { |
|
| 244 | + $boucle = $ligne = $skel = ''; |
|
| 245 | + list($msg, $lieu) = $err; |
|
| 246 | + if (is_object($lieu)) { |
|
| 247 | + $ligne = $lieu->ligne; |
|
| 248 | + $boucle = $lieu->id_boucle ? $lieu->id_boucle : ''; |
|
| 249 | + if (isset($lieu->descr['nom'])) { |
|
| 250 | + $nom_code = $lieu->descr['nom']; |
|
| 251 | + $skel = $lieu->descr['sourcefile']; |
|
| 252 | + $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
|
| 253 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 254 | + $skel = "<a href='$h3'><b>$skel</b></a>"; |
|
| 255 | + if ($boucle) { |
|
| 256 | + $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | + $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
|
| 258 | + } |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + |
|
| 262 | + $j = ($i + 1); |
|
| 263 | + $res .= "<tr id='req$j'><td style='text-align: right'>" |
|
| 264 | + . $j |
|
| 265 | + . " </td><td style='text-align: left'>" |
|
| 266 | + . (is_array($msg) ? implode('', $msg) : $msg) |
|
| 267 | + . "</td><td style='text-align: left'>" |
|
| 268 | + . ($skel ? $skel : " / ") |
|
| 269 | + . "</td><td class='spip-debug-arg' style='text-align: left'>" |
|
| 270 | + . ($boucle ? $boucle : " / ") |
|
| 271 | + . "</td><td style='text-align: right'>" |
|
| 272 | + . $ligne |
|
| 273 | + . "</td></tr>\n"; |
|
| 274 | + |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + return "\n<table id='$id'>" |
|
| 278 | + . "<caption onclick=\"x = document.getElementById('$id'); (x.style.display == '' ? x.style.display = 'none' : x.style.display = '');\">" |
|
| 279 | + . $caption[0] |
|
| 280 | 280 | ## aide locale courte a ecrire, avec lien vers une grosse page de documentation |
| 281 | 281 | # aider('erreur_compilation'), |
| 282 | - . "</caption>" |
|
| 283 | - // fausse caption du chrono (mais vraie nav) |
|
| 284 | - . (!empty($caption[1]) ? $caption[1] : '') |
|
| 285 | - . "<tr><th>" |
|
| 286 | - . _T('numero') |
|
| 287 | - . "</th><th>" |
|
| 288 | - . _T('public:message') |
|
| 289 | - . "</th><th>" |
|
| 290 | - . _T('squelette') |
|
| 291 | - . "</th><th>" |
|
| 292 | - . _T('zbug_boucle') |
|
| 293 | - . "</th><th>" |
|
| 294 | - . _T('ligne') |
|
| 295 | - . "</th></tr>" |
|
| 296 | - . $res |
|
| 297 | - . "</table>"; |
|
| 282 | + . "</caption>" |
|
| 283 | + // fausse caption du chrono (mais vraie nav) |
|
| 284 | + . (!empty($caption[1]) ? $caption[1] : '') |
|
| 285 | + . "<tr><th>" |
|
| 286 | + . _T('numero') |
|
| 287 | + . "</th><th>" |
|
| 288 | + . _T('public:message') |
|
| 289 | + . "</th><th>" |
|
| 290 | + . _T('squelette') |
|
| 291 | + . "</th><th>" |
|
| 292 | + . _T('zbug_boucle') |
|
| 293 | + . "</th><th>" |
|
| 294 | + . _T('ligne') |
|
| 295 | + . "</th></tr>" |
|
| 296 | + . $res |
|
| 297 | + . "</table>"; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
@@ -314,125 +314,125 @@ discard block |
||
| 314 | 314 | * ou un tableau si l'erreur est critique |
| 315 | 315 | **/ |
| 316 | 316 | function debusquer_requete($message) { |
| 317 | - list($errno, $msg, $query) = $message; |
|
| 318 | - |
|
| 319 | - // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 320 | - // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 321 | - if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 322 | - $errno = $regs[2]; |
|
| 323 | - } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 324 | - and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 325 | - ) { |
|
| 326 | - $errno = $regs[1]; |
|
| 327 | - } |
|
| 328 | - |
|
| 329 | - // Erreur systeme |
|
| 330 | - if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 331 | - $retour = "<tt><br /><br /><blink>" |
|
| 332 | - . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 333 | - . "</blink><br />\n<b>" |
|
| 334 | - . _T('info_erreur_systeme2', |
|
| 335 | - array('script' => generer_url_ecrire('base_repair'))) |
|
| 336 | - . '</b><br />'; |
|
| 337 | - spip_log("Erreur systeme $errno"); |
|
| 338 | - |
|
| 339 | - return array($retour, ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // Requete erronee |
|
| 343 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 344 | - . spip_htmlspecialchars($msg) |
|
| 345 | - . "\n<br /><span style='color: red'><b>" |
|
| 346 | - . spip_htmlspecialchars($query) |
|
| 347 | - . "</b></span></tt><br />"; |
|
| 348 | - |
|
| 349 | - //. aider('erreur_mysql'); |
|
| 350 | - |
|
| 351 | - return $err; |
|
| 317 | + list($errno, $msg, $query) = $message; |
|
| 318 | + |
|
| 319 | + // FIXME: ces écritures mélangent divers syntaxe des moteurs SQL |
|
| 320 | + // il serait plus prudent certainement d'avoir une fonction d'analyse par moteur |
|
| 321 | + if (preg_match(',err(no|code):?[[:space:]]*([0-9]+),i', $msg, $regs)) { |
|
| 322 | + $errno = $regs[2]; |
|
| 323 | + } elseif (is_numeric($errno) and ($errno == 1030 or $errno <= 1026) |
|
| 324 | + and preg_match(',[^[:alnum:]]([0-9]+)[^[:alnum:]],', $msg, $regs) |
|
| 325 | + ) { |
|
| 326 | + $errno = $regs[1]; |
|
| 327 | + } |
|
| 328 | + |
|
| 329 | + // Erreur systeme |
|
| 330 | + if (is_numeric($errno) and $errno > 0 and $errno < 200) { |
|
| 331 | + $retour = "<tt><br /><br /><blink>" |
|
| 332 | + . _T('info_erreur_systeme', array('errsys' => $errno)) |
|
| 333 | + . "</blink><br />\n<b>" |
|
| 334 | + . _T('info_erreur_systeme2', |
|
| 335 | + array('script' => generer_url_ecrire('base_repair'))) |
|
| 336 | + . '</b><br />'; |
|
| 337 | + spip_log("Erreur systeme $errno"); |
|
| 338 | + |
|
| 339 | + return array($retour, ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // Requete erronee |
|
| 343 | + $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 344 | + . spip_htmlspecialchars($msg) |
|
| 345 | + . "\n<br /><span style='color: red'><b>" |
|
| 346 | + . spip_htmlspecialchars($query) |
|
| 347 | + . "</b></span></tt><br />"; |
|
| 348 | + |
|
| 349 | + //. aider('erreur_mysql'); |
|
| 350 | + |
|
| 351 | + return $err; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
| 355 | 355 | // http://code.spip.net/@trouve_boucle_debug |
| 356 | 356 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 357 | 357 | |
| 358 | - $id = $nom . $boucle; |
|
| 359 | - if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 360 | - foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 361 | - |
|
| 362 | - if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 363 | - $y = substr_count($v[0], "\n"); |
|
| 364 | - } else { |
|
| 365 | - if ($v[1][0] == '#') // balise dynamique |
|
| 366 | - { |
|
| 367 | - $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 368 | - } else // inclusion |
|
| 369 | - { |
|
| 370 | - $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 371 | - } |
|
| 372 | - $y = substr_count($incl, "\n") |
|
| 373 | - + substr_count($r[1], "\n") |
|
| 374 | - + substr_count($r[3], "\n"); |
|
| 375 | - } |
|
| 376 | - if ($n <= ($y + $debut)) { |
|
| 377 | - if ($v[1][0] == '?') { |
|
| 378 | - return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 379 | - } elseif ($v[1][0] == '!') { |
|
| 380 | - if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 381 | - return trouve_boucle_debug($n, $incl, $debut); |
|
| 382 | - } |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 386 | - } |
|
| 387 | - $debut += $y; |
|
| 388 | - } |
|
| 389 | - } |
|
| 390 | - |
|
| 391 | - return array($nom, $boucle, $n - $debut); |
|
| 358 | + $id = $nom . $boucle; |
|
| 359 | + if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
|
| 360 | + foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
|
| 361 | + |
|
| 362 | + if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
|
| 363 | + $y = substr_count($v[0], "\n"); |
|
| 364 | + } else { |
|
| 365 | + if ($v[1][0] == '#') // balise dynamique |
|
| 366 | + { |
|
| 367 | + $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
|
| 368 | + } else // inclusion |
|
| 369 | + { |
|
| 370 | + $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
|
| 371 | + } |
|
| 372 | + $y = substr_count($incl, "\n") |
|
| 373 | + + substr_count($r[1], "\n") |
|
| 374 | + + substr_count($r[3], "\n"); |
|
| 375 | + } |
|
| 376 | + if ($n <= ($y + $debut)) { |
|
| 377 | + if ($v[1][0] == '?') { |
|
| 378 | + return trouve_boucle_debug($n, $nom, $debut, substr($v[1], 1)); |
|
| 379 | + } elseif ($v[1][0] == '!') { |
|
| 380 | + if ($incl = trouve_squelette_inclus($v[1])) { |
|
| 381 | + return trouve_boucle_debug($n, $incl, $debut); |
|
| 382 | + } |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + return array($nom, $boucle, $v[2] - 1 + $n - $debut); |
|
| 386 | + } |
|
| 387 | + $debut += $y; |
|
| 388 | + } |
|
| 389 | + } |
|
| 390 | + |
|
| 391 | + return array($nom, $boucle, $n - $debut); |
|
| 392 | 392 | } |
| 393 | 393 | |
| 394 | 394 | // http://code.spip.net/@trouve_squelette_inclus |
| 395 | 395 | function trouve_squelette_inclus($script) { |
| 396 | 396 | |
| 397 | - preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 398 | - // si le script X.php n'est pas ecrire/public.php |
|
| 399 | - // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 400 | - if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | - { |
|
| 402 | - if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 403 | - { |
|
| 404 | - if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 405 | - $reg[1] = "inconnu"; |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - } |
|
| 409 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 410 | - |
|
| 411 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 412 | - if (preg_match($incl, $v)) { |
|
| 413 | - return $k; |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - return ""; |
|
| 397 | + preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
|
| 398 | + // si le script X.php n'est pas ecrire/public.php |
|
| 399 | + // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
|
| 400 | + if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | + { |
|
| 402 | + if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
|
| 403 | + { |
|
| 404 | + if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
|
| 405 | + $reg[1] = "inconnu"; |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + } |
|
| 409 | + $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 410 | + |
|
| 411 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
|
| 412 | + if (preg_match($incl, $v)) { |
|
| 413 | + return $k; |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + return ""; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | // http://code.spip.net/@reference_boucle_debug |
| 421 | 421 | function reference_boucle_debug($n, $nom, $self) { |
| 422 | - list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 423 | - |
|
| 424 | - if (!$boucle) { |
|
| 425 | - return !$ligne ? "" : |
|
| 426 | - (" (" . |
|
| 427 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | - _T('squelette_ligne')) . |
|
| 429 | - " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 430 | - } else { |
|
| 431 | - $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 432 | - |
|
| 433 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | - } |
|
| 422 | + list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
|
| 423 | + |
|
| 424 | + if (!$boucle) { |
|
| 425 | + return !$ligne ? "" : |
|
| 426 | + (" (" . |
|
| 427 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | + _T('squelette_ligne')) . |
|
| 429 | + " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
|
| 430 | + } else { |
|
| 431 | + $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
|
| 432 | + |
|
| 433 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | + " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | + } |
|
| 436 | 436 | } |
| 437 | 437 | |
| 438 | 438 | // affiche un texte avec numero de ligne et ancre. |
@@ -440,395 +440,395 @@ discard block |
||
| 440 | 440 | // http://code.spip.net/@ancre_texte |
| 441 | 441 | function ancre_texte($texte, $fautifs = array(), $nocpt = false) { |
| 442 | 442 | |
| 443 | - $var_mode_ligne = _request('var_mode_ligne'); |
|
| 444 | - if ($var_mode_ligne) { |
|
| 445 | - $fautifs[] = array($var_mode_ligne); |
|
| 446 | - } |
|
| 447 | - $res = ''; |
|
| 448 | - |
|
| 449 | - $s = highlight_string($texte, true); |
|
| 450 | - if (substr($s, 0, 6) == '<code>') { |
|
| 451 | - $s = substr($s, 6); |
|
| 452 | - $res = '<code>'; |
|
| 453 | - } |
|
| 454 | - |
|
| 455 | - $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 456 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 457 | - $s); |
|
| 458 | - |
|
| 459 | - |
|
| 460 | - $tableau = explode("<br />", $s); |
|
| 461 | - |
|
| 462 | - $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"; |
|
| 463 | - |
|
| 464 | - $format10 = str_replace('white', 'lightgrey', $format); |
|
| 465 | - $formaterr = "color: red;"; |
|
| 466 | - $i = 1; |
|
| 467 | - $flignes = array(); |
|
| 468 | - $loc = array(0, 0); |
|
| 469 | - foreach ($fautifs as $lc) { |
|
| 470 | - if (is_array($lc)) { |
|
| 471 | - $l = array_shift($lc); |
|
| 472 | - $flignes[$l] = $lc; |
|
| 473 | - } else { |
|
| 474 | - $flignes[$lc] = $loc; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - |
|
| 478 | - $ancre = md5($texte); |
|
| 479 | - foreach ($tableau as $ligne) { |
|
| 480 | - if (isset($flignes[$i])) { |
|
| 481 | - $ligne = str_replace(' ', ' ', $ligne); |
|
| 482 | - $indexmesg = $flignes[$i][1]; |
|
| 483 | - $err = textebrut($flignes[$i][2]); |
|
| 484 | - // tentative de pointer sur la colonne fautive; |
|
| 485 | - // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 486 | - // $m = $flignes[$i][0]; |
|
| 487 | - // $ligne = substr($ligne, 0, $m-1) . |
|
| 488 | - // sprintf($formaterr, substr($ligne,$m)); |
|
| 489 | - $bg = $formaterr; |
|
| 490 | - } else { |
|
| 491 | - $indexmesg = $ancre; |
|
| 492 | - $err = $bg = ''; |
|
| 493 | - } |
|
| 494 | - $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 495 | - $i++; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - return "<div id='T$ancre'>" |
|
| 499 | - . '<div onclick="' |
|
| 500 | - . "jQuery(this).parent().find('a').toggle();" |
|
| 501 | - . '" title="' |
|
| 502 | - . _T('masquer_colonne') |
|
| 503 | - . '" style="cursor: pointer;">' |
|
| 504 | - . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 505 | - . "</div> |
|
| 443 | + $var_mode_ligne = _request('var_mode_ligne'); |
|
| 444 | + if ($var_mode_ligne) { |
|
| 445 | + $fautifs[] = array($var_mode_ligne); |
|
| 446 | + } |
|
| 447 | + $res = ''; |
|
| 448 | + |
|
| 449 | + $s = highlight_string($texte, true); |
|
| 450 | + if (substr($s, 0, 6) == '<code>') { |
|
| 451 | + $s = substr($s, 6); |
|
| 452 | + $res = '<code>'; |
|
| 453 | + } |
|
| 454 | + |
|
| 455 | + $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
|
| 456 | + '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 457 | + $s); |
|
| 458 | + |
|
| 459 | + |
|
| 460 | + $tableau = explode("<br />", $s); |
|
| 461 | + |
|
| 462 | + $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"; |
|
| 463 | + |
|
| 464 | + $format10 = str_replace('white', 'lightgrey', $format); |
|
| 465 | + $formaterr = "color: red;"; |
|
| 466 | + $i = 1; |
|
| 467 | + $flignes = array(); |
|
| 468 | + $loc = array(0, 0); |
|
| 469 | + foreach ($fautifs as $lc) { |
|
| 470 | + if (is_array($lc)) { |
|
| 471 | + $l = array_shift($lc); |
|
| 472 | + $flignes[$l] = $lc; |
|
| 473 | + } else { |
|
| 474 | + $flignes[$lc] = $loc; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + |
|
| 478 | + $ancre = md5($texte); |
|
| 479 | + foreach ($tableau as $ligne) { |
|
| 480 | + if (isset($flignes[$i])) { |
|
| 481 | + $ligne = str_replace(' ', ' ', $ligne); |
|
| 482 | + $indexmesg = $flignes[$i][1]; |
|
| 483 | + $err = textebrut($flignes[$i][2]); |
|
| 484 | + // tentative de pointer sur la colonne fautive; |
|
| 485 | + // marche pas car highlight_string rajoute des entites. A revoir. |
|
| 486 | + // $m = $flignes[$i][0]; |
|
| 487 | + // $ligne = substr($ligne, 0, $m-1) . |
|
| 488 | + // sprintf($formaterr, substr($ligne,$m)); |
|
| 489 | + $bg = $formaterr; |
|
| 490 | + } else { |
|
| 491 | + $indexmesg = $ancre; |
|
| 492 | + $err = $bg = ''; |
|
| 493 | + } |
|
| 494 | + $res .= sprintf((($i % 10) ? $format : $format10), $i, $bg, $indexmesg, $err, $i, $ligne); |
|
| 495 | + $i++; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + return "<div id='T$ancre'>" |
|
| 499 | + . '<div onclick="' |
|
| 500 | + . "jQuery(this).parent().find('a').toggle();" |
|
| 501 | + . '" title="' |
|
| 502 | + . _T('masquer_colonne') |
|
| 503 | + . '" style="cursor: pointer;">' |
|
| 504 | + . ($nocpt ? '' : _T('info_numero_abbreviation')) |
|
| 505 | + . "</div> |
|
| 506 | 506 | " . $res . "</div>\n"; |
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | // l'environnement graphique du debuggueur |
| 510 | 510 | |
| 511 | 511 | function debusquer_squelette($fonc, $mode, $self) { |
| 512 | - $texte = ''; |
|
| 513 | - |
|
| 514 | - if ($mode !== 'validation') { |
|
| 515 | - if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 516 | - $res = "<div id='spip-boucles'>\n" |
|
| 517 | - . debusquer_navigation_squelettes($self) |
|
| 518 | - . "</div>"; |
|
| 519 | - } else { |
|
| 520 | - $res = ''; |
|
| 521 | - } |
|
| 522 | - if ($fonc) { |
|
| 523 | - $id = " id='$fonc'"; |
|
| 524 | - if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 525 | - list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 526 | - $texte .= $res2; |
|
| 527 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | - $legend = _T('zbug_' . $mode); |
|
| 529 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 530 | - $texte = ancre_texte($texte, array('', '')); |
|
| 531 | - } |
|
| 532 | - } else { |
|
| 533 | - if (strlen(trim($res))) { |
|
| 534 | - return "<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>"; |
|
| 535 | - } else { |
|
| 536 | - // cas de l'appel sur erreur: montre la page |
|
| 537 | - return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 538 | - ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 539 | - : ''; |
|
| 540 | - } |
|
| 541 | - } |
|
| 542 | - } else { |
|
| 543 | - $valider = charger_fonction('valider', 'xml'); |
|
| 544 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 545 | - // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 546 | - $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 547 | - list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 548 | - if ($err === false) { |
|
| 549 | - $err = _T('impossible'); |
|
| 550 | - } elseif ($err === true) { |
|
| 551 | - $err = _T('correcte'); |
|
| 552 | - } else { |
|
| 553 | - $err = ": $err"; |
|
| 554 | - } |
|
| 555 | - $legend = _T('validation') . ' ' . $err; |
|
| 556 | - $res = $id = ''; |
|
| 557 | - } |
|
| 558 | - |
|
| 559 | - return !trim($texte) ? '' : ( |
|
| 560 | - "<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" |
|
| 561 | - . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 562 | - . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 563 | - . ($legend ? $legend : $mode) |
|
| 564 | - . "</a></legend>" |
|
| 565 | - . $texte |
|
| 566 | - . "</fieldset></div>" |
|
| 567 | - . "</div>"); |
|
| 512 | + $texte = ''; |
|
| 513 | + |
|
| 514 | + if ($mode !== 'validation') { |
|
| 515 | + if (isset($GLOBALS['debug_objets']['sourcefile']) and $GLOBALS['debug_objets']['sourcefile']) { |
|
| 516 | + $res = "<div id='spip-boucles'>\n" |
|
| 517 | + . debusquer_navigation_squelettes($self) |
|
| 518 | + . "</div>"; |
|
| 519 | + } else { |
|
| 520 | + $res = ''; |
|
| 521 | + } |
|
| 522 | + if ($fonc) { |
|
| 523 | + $id = " id='$fonc'"; |
|
| 524 | + if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
|
| 525 | + list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
|
| 526 | + $texte .= $res2; |
|
| 527 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | + $legend = _T('zbug_' . $mode); |
|
| 529 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 530 | + $texte = ancre_texte($texte, array('', '')); |
|
| 531 | + } |
|
| 532 | + } else { |
|
| 533 | + if (strlen(trim($res))) { |
|
| 534 | + return "<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>"; |
|
| 535 | + } else { |
|
| 536 | + // cas de l'appel sur erreur: montre la page |
|
| 537 | + return isset($GLOBALS['debug_objets']['resultat']['tout']) |
|
| 538 | + ? $GLOBALS['debug_objets']['resultat']['tout'] |
|
| 539 | + : ''; |
|
| 540 | + } |
|
| 541 | + } |
|
| 542 | + } else { |
|
| 543 | + $valider = charger_fonction('valider', 'xml'); |
|
| 544 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 545 | + // Si erreur, signaler leur nombre dans le formulaire admin |
|
| 546 | + $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
|
| 547 | + list($texte, $err) = emboite_texte($val, $fonc, $self); |
|
| 548 | + if ($err === false) { |
|
| 549 | + $err = _T('impossible'); |
|
| 550 | + } elseif ($err === true) { |
|
| 551 | + $err = _T('correcte'); |
|
| 552 | + } else { |
|
| 553 | + $err = ": $err"; |
|
| 554 | + } |
|
| 555 | + $legend = _T('validation') . ' ' . $err; |
|
| 556 | + $res = $id = ''; |
|
| 557 | + } |
|
| 558 | + |
|
| 559 | + return !trim($texte) ? '' : ( |
|
| 560 | + "<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" |
|
| 561 | + . "<div id='debug_boucle'><fieldset$id><legend>" |
|
| 562 | + . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 563 | + . ($legend ? $legend : $mode) |
|
| 564 | + . "</a></legend>" |
|
| 565 | + . $texte |
|
| 566 | + . "</fieldset></div>" |
|
| 567 | + . "</div>"); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
| 571 | 571 | // http://code.spip.net/@emboite_texte |
| 572 | 572 | function emboite_texte($res, $fonc = '', $self = '') { |
| 573 | - $errs = $res->err; |
|
| 574 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 575 | - |
|
| 576 | - if (!$texte and !$errs) { |
|
| 577 | - return array(ancre_texte('', array('', '')), false); |
|
| 578 | - } |
|
| 579 | - if (!$errs) { |
|
| 580 | - return array(ancre_texte($texte, array('', '')), true); |
|
| 581 | - } |
|
| 582 | - |
|
| 583 | - if (!isset($GLOBALS['debug_objets'])) { |
|
| 584 | - |
|
| 585 | - $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 586 | - $encore = count_occ($errs); |
|
| 587 | - $encore2 = array(); |
|
| 588 | - $fautifs = array(); |
|
| 589 | - |
|
| 590 | - $err = '<tr><th>' |
|
| 591 | - . _T('numero') |
|
| 592 | - . "</th><th>" |
|
| 593 | - . _T('occurence') |
|
| 594 | - . "</th><th>" |
|
| 595 | - . _T('ligne') |
|
| 596 | - . "</th><th>" |
|
| 597 | - . _T('colonne') |
|
| 598 | - . "</th><th>" |
|
| 599 | - . _T('erreur') |
|
| 600 | - . "</th></tr>"; |
|
| 601 | - |
|
| 602 | - $i = 0; |
|
| 603 | - $style = "style='text-align: right; padding-right: 5px'"; |
|
| 604 | - foreach ($errs as $r) { |
|
| 605 | - $i++; |
|
| 606 | - list($msg, $ligne, $col) = $r; |
|
| 607 | - #spip_log("$r = list($msg, $ligne, $col"); |
|
| 608 | - if (isset($encore2[$msg])) { |
|
| 609 | - $ref = ++$encore2[$msg]; |
|
| 610 | - } else { |
|
| 611 | - $encore2[$msg] = $ref = 1; |
|
| 612 | - } |
|
| 613 | - $err .= "<tr style='background-color: " |
|
| 614 | - . $colors[$i % 2] |
|
| 615 | - . "'><td $style><a href='#debut_err'>" |
|
| 616 | - . $i |
|
| 617 | - . "</a></td><td $style>" |
|
| 618 | - . "$ref/$encore[$msg]</td>" |
|
| 619 | - . "<td $style><a href='#L" |
|
| 620 | - . $ligne |
|
| 621 | - . "' id='T$i'>" |
|
| 622 | - . $ligne |
|
| 623 | - . "</a></td><td $style>" |
|
| 624 | - . $col |
|
| 625 | - . "</td><td>$msg</td></tr>\n"; |
|
| 626 | - $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 627 | - } |
|
| 628 | - $err = "<h2 style='text-align: center'>" |
|
| 629 | - . $i |
|
| 630 | - . "<a href='#fin_err'>" |
|
| 631 | - . " " . _T('erreur_texte') |
|
| 632 | - . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 633 | - . $err |
|
| 634 | - . " </table><a id='fin_err'></a>"; |
|
| 635 | - |
|
| 636 | - return array(ancre_texte($texte, $fautifs), $err); |
|
| 637 | - } else { |
|
| 638 | - list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 639 | - $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 640 | - $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 641 | - $err = $msg . |
|
| 642 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 644 | - |
|
| 645 | - return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 646 | - } |
|
| 573 | + $errs = $res->err; |
|
| 574 | + $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 575 | + |
|
| 576 | + if (!$texte and !$errs) { |
|
| 577 | + return array(ancre_texte('', array('', '')), false); |
|
| 578 | + } |
|
| 579 | + if (!$errs) { |
|
| 580 | + return array(ancre_texte($texte, array('', '')), true); |
|
| 581 | + } |
|
| 582 | + |
|
| 583 | + if (!isset($GLOBALS['debug_objets'])) { |
|
| 584 | + |
|
| 585 | + $colors = array('#e0e0f0', '#f8f8ff'); |
|
| 586 | + $encore = count_occ($errs); |
|
| 587 | + $encore2 = array(); |
|
| 588 | + $fautifs = array(); |
|
| 589 | + |
|
| 590 | + $err = '<tr><th>' |
|
| 591 | + . _T('numero') |
|
| 592 | + . "</th><th>" |
|
| 593 | + . _T('occurence') |
|
| 594 | + . "</th><th>" |
|
| 595 | + . _T('ligne') |
|
| 596 | + . "</th><th>" |
|
| 597 | + . _T('colonne') |
|
| 598 | + . "</th><th>" |
|
| 599 | + . _T('erreur') |
|
| 600 | + . "</th></tr>"; |
|
| 601 | + |
|
| 602 | + $i = 0; |
|
| 603 | + $style = "style='text-align: right; padding-right: 5px'"; |
|
| 604 | + foreach ($errs as $r) { |
|
| 605 | + $i++; |
|
| 606 | + list($msg, $ligne, $col) = $r; |
|
| 607 | + #spip_log("$r = list($msg, $ligne, $col"); |
|
| 608 | + if (isset($encore2[$msg])) { |
|
| 609 | + $ref = ++$encore2[$msg]; |
|
| 610 | + } else { |
|
| 611 | + $encore2[$msg] = $ref = 1; |
|
| 612 | + } |
|
| 613 | + $err .= "<tr style='background-color: " |
|
| 614 | + . $colors[$i % 2] |
|
| 615 | + . "'><td $style><a href='#debut_err'>" |
|
| 616 | + . $i |
|
| 617 | + . "</a></td><td $style>" |
|
| 618 | + . "$ref/$encore[$msg]</td>" |
|
| 619 | + . "<td $style><a href='#L" |
|
| 620 | + . $ligne |
|
| 621 | + . "' id='T$i'>" |
|
| 622 | + . $ligne |
|
| 623 | + . "</a></td><td $style>" |
|
| 624 | + . $col |
|
| 625 | + . "</td><td>$msg</td></tr>\n"; |
|
| 626 | + $fautifs[] = array($ligne, $col, $i, $msg); |
|
| 627 | + } |
|
| 628 | + $err = "<h2 style='text-align: center'>" |
|
| 629 | + . $i |
|
| 630 | + . "<a href='#fin_err'>" |
|
| 631 | + . " " . _T('erreur_texte') |
|
| 632 | + . "</a></h2><table id='debut_err' style='width: 100%'>" |
|
| 633 | + . $err |
|
| 634 | + . " </table><a id='fin_err'></a>"; |
|
| 635 | + |
|
| 636 | + return array(ancre_texte($texte, $fautifs), $err); |
|
| 637 | + } else { |
|
| 638 | + list($msg, $fermant, $ouvrant) = $errs[0]; |
|
| 639 | + $rf = reference_boucle_debug($fermant, $fonc, $self); |
|
| 640 | + $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
|
| 641 | + $err = $msg . |
|
| 642 | + "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | + "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 644 | + |
|
| 645 | + return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
|
| 646 | + } |
|
| 647 | 647 | } |
| 648 | 648 | |
| 649 | 649 | // http://code.spip.net/@count_occ |
| 650 | 650 | function count_occ($regs) { |
| 651 | - $encore = array(); |
|
| 652 | - foreach ($regs as $r) { |
|
| 653 | - if (isset($encore[$r[0]])) { |
|
| 654 | - $encore[$r[0]]++; |
|
| 655 | - } else { |
|
| 656 | - $encore[$r[0]] = 1; |
|
| 657 | - } |
|
| 658 | - } |
|
| 659 | - |
|
| 660 | - return $encore; |
|
| 651 | + $encore = array(); |
|
| 652 | + foreach ($regs as $r) { |
|
| 653 | + if (isset($encore[$r[0]])) { |
|
| 654 | + $encore[$r[0]]++; |
|
| 655 | + } else { |
|
| 656 | + $encore[$r[0]] = 1; |
|
| 657 | + } |
|
| 658 | + } |
|
| 659 | + |
|
| 660 | + return $encore; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | function debusquer_navigation_squelettes($self) { |
| 664 | 664 | |
| 665 | - $res = ''; |
|
| 666 | - $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 667 | - $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 668 | - $t_skel = _T('squelette'); |
|
| 669 | - foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 670 | - $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 671 | - $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 672 | - $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 673 | - array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 674 | - |
|
| 675 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 676 | - . $t_skel |
|
| 677 | - . ' ' |
|
| 678 | - . $sourcefile |
|
| 679 | - . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 680 | - . $t_skel |
|
| 681 | - . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 682 | - . _T('zbug_resultat') |
|
| 683 | - . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 684 | - . _T('zbug_code') |
|
| 685 | - . "</a>\n<a href='" |
|
| 686 | - . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 687 | - . "'>" |
|
| 688 | - . _T('zbug_calcul') |
|
| 689 | - . "</a></legend>" |
|
| 690 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 691 | - . debusquer_contexte($contexte[$sourcefile]) |
|
| 692 | - . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 693 | - . "</fieldset>\n"; |
|
| 694 | - } |
|
| 695 | - |
|
| 696 | - return $res; |
|
| 665 | + $res = ''; |
|
| 666 | + $boucles = !empty($GLOBALS['debug_objets']['boucle']) ? $GLOBALS['debug_objets']['boucle'] : ''; |
|
| 667 | + $contexte = $GLOBALS['debug_objets']['contexte']; |
|
| 668 | + $t_skel = _T('squelette'); |
|
| 669 | + foreach ($GLOBALS['debug_objets']['sourcefile'] as $nom => $sourcefile) { |
|
| 670 | + $self2 = parametre_url($self, 'var_mode_objet', $nom); |
|
| 671 | + $nav = !$boucles ? '' : debusquer_navigation_boucles($boucles, $nom, $self, $sourcefile); |
|
| 672 | + $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
|
| 673 | + array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
|
| 674 | + |
|
| 675 | + $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 676 | + . $t_skel |
|
| 677 | + . ' ' |
|
| 678 | + . $sourcefile |
|
| 679 | + . " :\n<a href='$self2&var_mode_affiche=squelette#f_$nom'>" |
|
| 680 | + . $t_skel |
|
| 681 | + . "</a>\n<a href='$self2&var_mode_affiche=resultat#f_$nom'>" |
|
| 682 | + . _T('zbug_resultat') |
|
| 683 | + . "</a>\n<a href='$self2&var_mode_affiche=code#f_$nom'>" |
|
| 684 | + . _T('zbug_code') |
|
| 685 | + . "</a>\n<a href='" |
|
| 686 | + . str_replace('var_mode=debug', 'var_profile=1&var_mode=recalcul', $self) |
|
| 687 | + . "'>" |
|
| 688 | + . _T('zbug_calcul') |
|
| 689 | + . "</a></legend>" |
|
| 690 | + . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 691 | + . debusquer_contexte($contexte[$sourcefile]) |
|
| 692 | + . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
|
| 693 | + . "</fieldset>\n"; |
|
| 694 | + } |
|
| 695 | + |
|
| 696 | + return $res; |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | function debusquer_navigation_boucles($boucles, $nom_skel, $self, $nom_source) { |
| 700 | - $i = 0; |
|
| 701 | - $res = ''; |
|
| 702 | - $var_mode_objet = _request('var_mode_objet'); |
|
| 703 | - $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 704 | - |
|
| 705 | - foreach ($boucles as $objet => $boucle) { |
|
| 706 | - if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 707 | - $i++; |
|
| 708 | - $nom = $boucle->id_boucle; |
|
| 709 | - $req = $boucle->type_requete; |
|
| 710 | - $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 711 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | - |
|
| 713 | - $res .= "\n<tr style='background-color: " . |
|
| 714 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | - "'><td align='right'>$i</td><td>\n" . |
|
| 716 | - "<a class='debug_link_boucle' href='" . |
|
| 717 | - $self2 . |
|
| 718 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | - _T('zbug_boucle') . |
|
| 720 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | - $self2 . |
|
| 722 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | - _T('zbug_resultat') . |
|
| 724 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | - $self2 . |
|
| 726 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | - _T('zbug_code') . |
|
| 728 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | - "'>" . |
|
| 731 | - _T('zbug_calcul') . |
|
| 732 | - "</a></td><td>\n" . |
|
| 733 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | - "</td><td>\n" . |
|
| 735 | - $req . |
|
| 736 | - "</td><td>\n" . |
|
| 737 | - spip_htmlspecialchars($crit) . |
|
| 738 | - "</td></tr>"; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - return $res; |
|
| 700 | + $i = 0; |
|
| 701 | + $res = ''; |
|
| 702 | + $var_mode_objet = _request('var_mode_objet'); |
|
| 703 | + $gram = preg_match('/[.](\w+)$/', $nom_source, $r) ? $r[1] : ''; |
|
| 704 | + |
|
| 705 | + foreach ($boucles as $objet => $boucle) { |
|
| 706 | + if (substr($objet, 0, strlen($nom_skel)) == $nom_skel) { |
|
| 707 | + $i++; |
|
| 708 | + $nom = $boucle->id_boucle; |
|
| 709 | + $req = $boucle->type_requete; |
|
| 710 | + $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
|
| 711 | + $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | + |
|
| 713 | + $res .= "\n<tr style='background-color: " . |
|
| 714 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | + "'><td align='right'>$i</td><td>\n" . |
|
| 716 | + "<a class='debug_link_boucle' href='" . |
|
| 717 | + $self2 . |
|
| 718 | + "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | + _T('zbug_boucle') . |
|
| 720 | + "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | + $self2 . |
|
| 722 | + "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | + _T('zbug_resultat') . |
|
| 724 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | + $self2 . |
|
| 726 | + "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | + _T('zbug_code') . |
|
| 728 | + "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | + str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | + "'>" . |
|
| 731 | + _T('zbug_calcul') . |
|
| 732 | + "</a></td><td>\n" . |
|
| 733 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | + "</td><td>\n" . |
|
| 735 | + $req . |
|
| 736 | + "</td><td>\n" . |
|
| 737 | + spip_htmlspecialchars($crit) . |
|
| 738 | + "</td></tr>"; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + return $res; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | function debusquer_source($objet, $affiche) { |
| 746 | - $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 747 | - if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 748 | - $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 749 | - } else { |
|
| 750 | - $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 751 | - } |
|
| 752 | - $res2 = ""; |
|
| 753 | - |
|
| 754 | - if ($affiche == 'resultat') { |
|
| 755 | - $legend = $nom; |
|
| 756 | - $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 757 | - if (function_exists('_mysql_traite_query')) { |
|
| 758 | - $c = strtolower(_request('connect')); |
|
| 759 | - $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 760 | - $req = _mysql_traite_query($req, '', $c); |
|
| 761 | - } |
|
| 762 | - // permettre le copier/coller facile |
|
| 763 | - // $res = ancre_texte($req, array(), true); |
|
| 764 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 765 | - // formatage et affichage des resultats bruts de la requete |
|
| 766 | - $ress_req = spip_query($req); |
|
| 767 | - $brut_sql = ''; |
|
| 768 | - $num = 1; |
|
| 769 | - // eviter l'affichage de milliers de lignes |
|
| 770 | - // personnalisation possible dans mes_options |
|
| 771 | - $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 772 | - while ($retours_sql = sql_fetch($ress_req)) { |
|
| 773 | - if ($num <= $max_aff) { |
|
| 774 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 775 | - $brut_sql .= "<p>"; |
|
| 776 | - foreach ($retours_sql as $key => $val) { |
|
| 777 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 778 | - } |
|
| 779 | - $brut_sql .= "</p>"; |
|
| 780 | - } |
|
| 781 | - $num++; |
|
| 782 | - } |
|
| 783 | - $res2 = interdire_scripts($brut_sql); |
|
| 784 | - foreach ($quoi as $view) { |
|
| 785 | - // ne pas afficher les $contexte_inclus |
|
| 786 | - $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 787 | - if ($view) { |
|
| 788 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 789 | - } |
|
| 790 | - } |
|
| 791 | - |
|
| 792 | - } elseif ($affiche == 'code') { |
|
| 793 | - $legend = $nom; |
|
| 794 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 795 | - } elseif ($affiche == 'boucle') { |
|
| 796 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 797 | - // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 798 | - $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 799 | - $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 800 | - } elseif ($affiche == 'squelette') { |
|
| 801 | - $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 802 | - $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - return array($legend, $res, $res2); |
|
| 746 | + $quoi = $GLOBALS['debug_objets'][$affiche][$objet]; |
|
| 747 | + if (!empty($GLOBALS['debug_objets']['boucle'][$objet]->id_boucle)) { |
|
| 748 | + $nom = $GLOBALS['debug_objets']['boucle'][$objet]->id_boucle; |
|
| 749 | + } else { |
|
| 750 | + $nom = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 751 | + } |
|
| 752 | + $res2 = ""; |
|
| 753 | + |
|
| 754 | + if ($affiche == 'resultat') { |
|
| 755 | + $legend = $nom; |
|
| 756 | + $req = $GLOBALS['debug_objets']['requete'][$objet]; |
|
| 757 | + if (function_exists('_mysql_traite_query')) { |
|
| 758 | + $c = strtolower(_request('connect')); |
|
| 759 | + $c = $GLOBALS['connexions'][$c ? $c : 0]['prefixe']; |
|
| 760 | + $req = _mysql_traite_query($req, '', $c); |
|
| 761 | + } |
|
| 762 | + // permettre le copier/coller facile |
|
| 763 | + // $res = ancre_texte($req, array(), true); |
|
| 764 | + $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 765 | + // formatage et affichage des resultats bruts de la requete |
|
| 766 | + $ress_req = spip_query($req); |
|
| 767 | + $brut_sql = ''; |
|
| 768 | + $num = 1; |
|
| 769 | + // eviter l'affichage de milliers de lignes |
|
| 770 | + // personnalisation possible dans mes_options |
|
| 771 | + $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
|
| 772 | + while ($retours_sql = sql_fetch($ress_req)) { |
|
| 773 | + if ($num <= $max_aff) { |
|
| 774 | + $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 775 | + $brut_sql .= "<p>"; |
|
| 776 | + foreach ($retours_sql as $key => $val) { |
|
| 777 | + $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 778 | + } |
|
| 779 | + $brut_sql .= "</p>"; |
|
| 780 | + } |
|
| 781 | + $num++; |
|
| 782 | + } |
|
| 783 | + $res2 = interdire_scripts($brut_sql); |
|
| 784 | + foreach ($quoi as $view) { |
|
| 785 | + // ne pas afficher les $contexte_inclus |
|
| 786 | + $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
|
| 787 | + if ($view) { |
|
| 788 | + $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 789 | + } |
|
| 790 | + } |
|
| 791 | + |
|
| 792 | + } elseif ($affiche == 'code') { |
|
| 793 | + $legend = $nom; |
|
| 794 | + $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 795 | + } elseif ($affiche == 'boucle') { |
|
| 796 | + $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 797 | + // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
|
| 798 | + $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
|
| 799 | + $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
|
| 800 | + } elseif ($affiche == 'squelette') { |
|
| 801 | + $legend = $GLOBALS['debug_objets']['sourcefile'][$objet]; |
|
| 802 | + $res = ancre_texte($GLOBALS['debug_objets']['squelette'][$objet]); |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + return array($legend, $res, $res2); |
|
| 806 | 806 | } |
| 807 | 807 | |
| 808 | 808 | // http://code.spip.net/@debusquer_entete |
| 809 | 809 | function debusquer_entete($titre, $corps) { |
| 810 | 810 | |
| 811 | - include_spip('balise/formulaire_admin'); |
|
| 812 | - include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 813 | - include_spip('inc/texte'); // pour corriger_typo |
|
| 814 | - |
|
| 815 | - return _DOCTYPE_ECRIRE . |
|
| 816 | - html_lang_attributes() . |
|
| 817 | - "<head>\n<title>" . |
|
| 818 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | - ")</title>\n" . |
|
| 822 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | - "' />\n" . |
|
| 825 | - http_script('', 'jquery.js') |
|
| 826 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | - . "' type='text/css' />" . |
|
| 828 | - "</head>\n" . |
|
| 829 | - "<body style='margin:0 10px;'>\n" . |
|
| 830 | - "<div id='spip-debug-header'>" . |
|
| 831 | - $corps . |
|
| 832 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 833 | - '</div></body></html>'; |
|
| 811 | + include_spip('balise/formulaire_admin'); |
|
| 812 | + include_spip('public/assembler'); // pour inclure_balise_dynamique |
|
| 813 | + include_spip('inc/texte'); // pour corriger_typo |
|
| 814 | + |
|
| 815 | + return _DOCTYPE_ECRIRE . |
|
| 816 | + html_lang_attributes() . |
|
| 817 | + "<head>\n<title>" . |
|
| 818 | + ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | + _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | + ")</title>\n" . |
|
| 822 | + "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | + "' />\n" . |
|
| 825 | + http_script('', 'jquery.js') |
|
| 826 | + . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | + . "' type='text/css' />" . |
|
| 828 | + "</head>\n" . |
|
| 829 | + "<body style='margin:0 10px;'>\n" . |
|
| 830 | + "<div id='spip-debug-header'>" . |
|
| 831 | + $corps . |
|
| 832 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 833 | + '</div></body></html>'; |
|
| 834 | 834 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | if (!$fonc) { |
| 148 | 148 | $fonc = $GLOBALS['debug_objets']['principal']; |
| 149 | 149 | } |
| 150 | - $titre = !$mode ? $fonc : ($mode . (isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " " . $GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 150 | + $titre = !$mode ? $fonc : ($mode.(isset($GLOBALS['debug_objets']['sourcefile'][$fonc]) ? " ".$GLOBALS['debug_objets']['sourcefile'][$fonc] : "")); |
|
| 151 | 151 | } |
| 152 | 152 | if ($message === false) { |
| 153 | 153 | lang_select(); |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | $fond = isset($GLOBALS['fond']) ? $GLOBALS['fond'] : ""; |
| 177 | 177 | // une erreur critique sort $message en array |
| 178 | 178 | $debug = is_array($msg) ? $msg[1] : $msg; |
| 179 | - spip_log("Debug: " . $debug . " (" . $fond . ")"); |
|
| 179 | + spip_log("Debug: ".$debug." (".$fond.")"); |
|
| 180 | 180 | |
| 181 | 181 | return $msg; |
| 182 | 182 | } |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | function debusquer_bandeau($erreurs) { |
| 185 | 185 | |
| 186 | 186 | if (!empty($erreurs)) { |
| 187 | - $n = array(count($erreurs) . ' ' . _T('zbug_erreur_squelette')); |
|
| 187 | + $n = array(count($erreurs).' '._T('zbug_erreur_squelette')); |
|
| 188 | 188 | |
| 189 | 189 | return debusquer_navigation($erreurs, $n); |
| 190 | 190 | } elseif (!empty($GLOBALS['tableau_des_temps'])) { |
@@ -217,12 +217,12 @@ discard block |
||
| 217 | 217 | if (is_array($valeur)) { |
| 218 | 218 | $valeur_simple = array(); |
| 219 | 219 | foreach ($valeur as $v) { |
| 220 | - $valeur_simple[] = is_array($v) ? 'array(size=' . count($v) . ')' : $v; |
|
| 220 | + $valeur_simple[] = is_array($v) ? 'array(size='.count($v).')' : $v; |
|
| 221 | 221 | } |
| 222 | - $valeur = '(' . count($valeur) . ' items) [' . join(',', $valeur_simple) . ']'; |
|
| 222 | + $valeur = '('.count($valeur).' items) ['.join(',', $valeur_simple).']'; |
|
| 223 | 223 | } |
| 224 | - $res .= "\n<tr><td><strong>" . nl2br(entites_html($nom)) |
|
| 225 | - . "</strong></td><td>: " . nl2br(entites_html($valeur)) |
|
| 224 | + $res .= "\n<tr><td><strong>".nl2br(entites_html($nom)) |
|
| 225 | + . "</strong></td><td>: ".nl2br(entites_html($valeur)) |
|
| 226 | 226 | . "</td></tr>\n"; |
| 227 | 227 | } |
| 228 | 228 | |
@@ -250,10 +250,10 @@ discard block |
||
| 250 | 250 | $nom_code = $lieu->descr['nom']; |
| 251 | 251 | $skel = $lieu->descr['sourcefile']; |
| 252 | 252 | $h2 = parametre_url($href, 'var_mode_objet', $nom_code); |
| 253 | - $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette') . '#L' . $ligne; |
|
| 253 | + $h3 = parametre_url($h2, 'var_mode_affiche', 'squelette').'#L'.$ligne; |
|
| 254 | 254 | $skel = "<a href='$h3'><b>$skel</b></a>"; |
| 255 | 255 | if ($boucle) { |
| 256 | - $h3 = parametre_url($h2 . $boucle, 'var_mode_affiche', 'boucle'); |
|
| 256 | + $h3 = parametre_url($h2.$boucle, 'var_mode_affiche', 'boucle'); |
|
| 257 | 257 | $boucle = "<a href='$h3'><b>$boucle</b></a>"; |
| 258 | 258 | } |
| 259 | 259 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | // Requete erronee |
| 343 | - $err = "<b>" . _T('avis_erreur_mysql') . " $errno</b><br /><tt>\n" |
|
| 343 | + $err = "<b>"._T('avis_erreur_mysql')." $errno</b><br /><tt>\n" |
|
| 344 | 344 | . spip_htmlspecialchars($msg) |
| 345 | 345 | . "\n<br /><span style='color: red'><b>" |
| 346 | 346 | . spip_htmlspecialchars($query) |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | // http://code.spip.net/@trouve_boucle_debug |
| 356 | 356 | function trouve_boucle_debug($n, $nom, $debut = 0, $boucle = "") { |
| 357 | 357 | |
| 358 | - $id = $nom . $boucle; |
|
| 358 | + $id = $nom.$boucle; |
|
| 359 | 359 | if (is_array($GLOBALS['debug_objets']['sequence'][$id])) { |
| 360 | 360 | foreach ($GLOBALS['debug_objets']['sequence'][$id] as $v) { |
| 361 | 361 | |
@@ -406,7 +406,7 @@ discard block |
||
| 406 | 406 | } |
| 407 | 407 | } |
| 408 | 408 | } |
| 409 | - $incl = ',' . $reg[1] . '[.]\w$,'; |
|
| 409 | + $incl = ','.$reg[1].'[.]\w$,'; |
|
| 410 | 410 | |
| 411 | 411 | foreach ($GLOBALS['debug_objets']['sourcefile'] as $k => $v) { |
| 412 | 412 | if (preg_match($incl, $v)) { |
@@ -422,16 +422,13 @@ discard block |
||
| 422 | 422 | list($skel, $boucle, $ligne) = trouve_boucle_debug($n, $nom); |
| 423 | 423 | |
| 424 | 424 | if (!$boucle) { |
| 425 | - return !$ligne ? "" : |
|
| 426 | - (" (" . |
|
| 427 | - (($nom != $skel) ? _T('squelette_inclus_ligne') : |
|
| 428 | - _T('squelette_ligne')) . |
|
| 425 | + return !$ligne ? "" : (" (". |
|
| 426 | + (($nom != $skel) ? _T('squelette_inclus_ligne') : _T('squelette_ligne')). |
|
| 429 | 427 | " <a href='$self&var_mode_objet=$skel&var_mode_affiche=squelette&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"); |
| 430 | 428 | } else { |
| 431 | 429 | $self .= "&var_mode_objet=$skel$boucle&var_mode_affiche=boucle"; |
| 432 | 430 | |
| 433 | - return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : |
|
| 434 | - " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 431 | + return !$ligne ? " (boucle\n<a href='$self#$skel$boucle'>$boucle</a>)" : " (boucle $boucle ligne\n<a href='$self&var_mode_ligne=$ligne#L$ligne'>$ligne</a>)"; |
|
| 435 | 432 | } |
| 436 | 433 | } |
| 437 | 434 | |
@@ -453,13 +450,13 @@ discard block |
||
| 453 | 450 | } |
| 454 | 451 | |
| 455 | 452 | $s = preg_replace(',<(\w[^<>]*)>([^<]*)<br />([^<]*)</\1>,', |
| 456 | - '<\1>\2</\1><br />' . "\n" . '<\1>\3</\1>', |
|
| 453 | + '<\1>\2</\1><br />'."\n".'<\1>\3</\1>', |
|
| 457 | 454 | $s); |
| 458 | 455 | |
| 459 | 456 | |
| 460 | 457 | $tableau = explode("<br />", $s); |
| 461 | 458 | |
| 462 | - $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"; |
|
| 459 | + $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"; |
|
| 463 | 460 | |
| 464 | 461 | $format10 = str_replace('white', 'lightgrey', $format); |
| 465 | 462 | $formaterr = "color: red;"; |
@@ -503,7 +500,7 @@ discard block |
||
| 503 | 500 | . '" style="cursor: pointer;">' |
| 504 | 501 | . ($nocpt ? '' : _T('info_numero_abbreviation')) |
| 505 | 502 | . "</div> |
| 506 | - " . $res . "</div>\n"; |
|
| 503 | + " . $res."</div>\n"; |
|
| 507 | 504 | } |
| 508 | 505 | |
| 509 | 506 | // l'environnement graphique du debuggueur |
@@ -524,14 +521,14 @@ discard block |
||
| 524 | 521 | if (!empty($GLOBALS['debug_objets'][$mode][$fonc])) { |
| 525 | 522 | list($legend, $texte, $res2) = debusquer_source($fonc, $mode); |
| 526 | 523 | $texte .= $res2; |
| 527 | - } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc . 'tout'])) { |
|
| 528 | - $legend = _T('zbug_' . $mode); |
|
| 529 | - $texte = $GLOBALS['debug_objets'][$mode][$fonc . 'tout']; |
|
| 524 | + } elseif (!empty($GLOBALS['debug_objets'][$mode][$fonc.'tout'])) { |
|
| 525 | + $legend = _T('zbug_'.$mode); |
|
| 526 | + $texte = $GLOBALS['debug_objets'][$mode][$fonc.'tout']; |
|
| 530 | 527 | $texte = ancre_texte($texte, array('', '')); |
| 531 | 528 | } |
| 532 | 529 | } else { |
| 533 | 530 | if (strlen(trim($res))) { |
| 534 | - return "<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>"; |
|
| 531 | + return "<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>"; |
|
| 535 | 532 | } else { |
| 536 | 533 | // cas de l'appel sur erreur: montre la page |
| 537 | 534 | return isset($GLOBALS['debug_objets']['resultat']['tout']) |
@@ -541,7 +538,7 @@ discard block |
||
| 541 | 538 | } |
| 542 | 539 | } else { |
| 543 | 540 | $valider = charger_fonction('valider', 'xml'); |
| 544 | - $val = $valider($GLOBALS['debug_objets']['validation'][$fonc . 'tout']); |
|
| 541 | + $val = $valider($GLOBALS['debug_objets']['validation'][$fonc.'tout']); |
|
| 545 | 542 | // Si erreur, signaler leur nombre dans le formulaire admin |
| 546 | 543 | $GLOBALS['debug_objets']['validation'] = $val->err ? count($val->err) : ''; |
| 547 | 544 | list($texte, $err) = emboite_texte($val, $fonc, $self); |
@@ -552,14 +549,14 @@ discard block |
||
| 552 | 549 | } else { |
| 553 | 550 | $err = ": $err"; |
| 554 | 551 | } |
| 555 | - $legend = _T('validation') . ' ' . $err; |
|
| 552 | + $legend = _T('validation').' '.$err; |
|
| 556 | 553 | $res = $id = ''; |
| 557 | 554 | } |
| 558 | 555 | |
| 559 | 556 | return !trim($texte) ? '' : ( |
| 560 | - "<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" |
|
| 557 | + "<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" |
|
| 561 | 558 | . "<div id='debug_boucle'><fieldset$id><legend>" |
| 562 | - . "<a href='" . $self . "#f_" . substr($fonc, 0, 37) . "'> ↑ " |
|
| 559 | + . "<a href='".$self."#f_".substr($fonc, 0, 37)."'> ↑ " |
|
| 563 | 560 | . ($legend ? $legend : $mode) |
| 564 | 561 | . "</a></legend>" |
| 565 | 562 | . $texte |
@@ -571,7 +568,7 @@ discard block |
||
| 571 | 568 | // http://code.spip.net/@emboite_texte |
| 572 | 569 | function emboite_texte($res, $fonc = '', $self = '') { |
| 573 | 570 | $errs = $res->err; |
| 574 | - $texte = $res->entete . ($errs ? '' : $res->page); |
|
| 571 | + $texte = $res->entete.($errs ? '' : $res->page); |
|
| 575 | 572 | |
| 576 | 573 | if (!$texte and !$errs) { |
| 577 | 574 | return array(ancre_texte('', array('', '')), false); |
@@ -628,7 +625,7 @@ discard block |
||
| 628 | 625 | $err = "<h2 style='text-align: center'>" |
| 629 | 626 | . $i |
| 630 | 627 | . "<a href='#fin_err'>" |
| 631 | - . " " . _T('erreur_texte') |
|
| 628 | + . " "._T('erreur_texte') |
|
| 632 | 629 | . "</a></h2><table id='debut_err' style='width: 100%'>" |
| 633 | 630 | . $err |
| 634 | 631 | . " </table><a id='fin_err'></a>"; |
@@ -638,9 +635,9 @@ discard block |
||
| 638 | 635 | list($msg, $fermant, $ouvrant) = $errs[0]; |
| 639 | 636 | $rf = reference_boucle_debug($fermant, $fonc, $self); |
| 640 | 637 | $ro = reference_boucle_debug($ouvrant, $fonc, $self); |
| 641 | - $err = $msg . |
|
| 642 | - "<a href='#L" . $fermant . "'>$fermant</a>$rf<br />" . |
|
| 643 | - "<a href='#L" . $ouvrant . "'>$ouvrant</a>$ro"; |
|
| 638 | + $err = $msg. |
|
| 639 | + "<a href='#L".$fermant."'>$fermant</a>$rf<br />". |
|
| 640 | + "<a href='#L".$ouvrant."'>$ouvrant</a>$ro"; |
|
| 644 | 641 | |
| 645 | 642 | return array(ancre_texte($texte, array(array($ouvrant), array($fermant))), $err); |
| 646 | 643 | } |
@@ -672,7 +669,7 @@ discard block |
||
| 672 | 669 | $temps = !isset($GLOBALS['debug_objets']['profile'][$sourcefile]) ? '' : _T('zbug_profile', |
| 673 | 670 | array('time' => $GLOBALS['debug_objets']['profile'][$sourcefile])); |
| 674 | 671 | |
| 675 | - $res .= "<fieldset id='f_" . $nom . "'><legend>" |
|
| 672 | + $res .= "<fieldset id='f_".$nom."'><legend>" |
|
| 676 | 673 | . $t_skel |
| 677 | 674 | . ' ' |
| 678 | 675 | . $sourcefile |
@@ -687,7 +684,7 @@ discard block |
||
| 687 | 684 | . "'>" |
| 688 | 685 | . _T('zbug_calcul') |
| 689 | 686 | . "</a></legend>" |
| 690 | - . (!$temps ? '' : ("\n<span style='display:block;float:" . $GLOBALS['spip_lang_right'] . "'>$temps</span><br />")) |
|
| 687 | + . (!$temps ? '' : ("\n<span style='display:block;float:".$GLOBALS['spip_lang_right']."'>$temps</span><br />")) |
|
| 691 | 688 | . debusquer_contexte($contexte[$sourcefile]) |
| 692 | 689 | . (!$nav ? '' : ("<table width='100%'>\n$nav</table>\n")) |
| 693 | 690 | . "</fieldset>\n"; |
@@ -708,33 +705,33 @@ discard block |
||
| 708 | 705 | $nom = $boucle->id_boucle; |
| 709 | 706 | $req = $boucle->type_requete; |
| 710 | 707 | $crit = public_decompiler($boucle, $gram, 0, 'criteres'); |
| 711 | - $self2 = $self . "&var_mode_objet=" . $objet; |
|
| 712 | - |
|
| 713 | - $res .= "\n<tr style='background-color: " . |
|
| 714 | - ($i % 2 ? '#e0e0f0' : '#f8f8ff') . |
|
| 715 | - "'><td align='right'>$i</td><td>\n" . |
|
| 716 | - "<a class='debug_link_boucle' href='" . |
|
| 717 | - $self2 . |
|
| 718 | - "&var_mode_affiche=boucle#f_$nom_skel'>" . |
|
| 719 | - _T('zbug_boucle') . |
|
| 720 | - "</a></td><td>\n<a class='debug_link_boucle' href='" . |
|
| 721 | - $self2 . |
|
| 722 | - "&var_mode_affiche=resultat#f_$nom_skel'>" . |
|
| 723 | - _T('zbug_resultat') . |
|
| 724 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 725 | - $self2 . |
|
| 726 | - "&var_mode_affiche=code#f_$nom_skel'>" . |
|
| 727 | - _T('zbug_code') . |
|
| 728 | - "</a></td><td>\n<a class='debug_link_resultat' href='" . |
|
| 729 | - str_replace('var_mode=', 'var_profile=', $self2) . |
|
| 730 | - "'>" . |
|
| 731 | - _T('zbug_calcul') . |
|
| 732 | - "</a></td><td>\n" . |
|
| 733 | - (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom) . |
|
| 734 | - "</td><td>\n" . |
|
| 735 | - $req . |
|
| 736 | - "</td><td>\n" . |
|
| 737 | - spip_htmlspecialchars($crit) . |
|
| 708 | + $self2 = $self."&var_mode_objet=".$objet; |
|
| 709 | + |
|
| 710 | + $res .= "\n<tr style='background-color: ". |
|
| 711 | + ($i % 2 ? '#e0e0f0' : '#f8f8ff'). |
|
| 712 | + "'><td align='right'>$i</td><td>\n". |
|
| 713 | + "<a class='debug_link_boucle' href='". |
|
| 714 | + $self2. |
|
| 715 | + "&var_mode_affiche=boucle#f_$nom_skel'>". |
|
| 716 | + _T('zbug_boucle'). |
|
| 717 | + "</a></td><td>\n<a class='debug_link_boucle' href='". |
|
| 718 | + $self2. |
|
| 719 | + "&var_mode_affiche=resultat#f_$nom_skel'>". |
|
| 720 | + _T('zbug_resultat'). |
|
| 721 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 722 | + $self2. |
|
| 723 | + "&var_mode_affiche=code#f_$nom_skel'>". |
|
| 724 | + _T('zbug_code'). |
|
| 725 | + "</a></td><td>\n<a class='debug_link_resultat' href='". |
|
| 726 | + str_replace('var_mode=', 'var_profile=', $self2). |
|
| 727 | + "'>". |
|
| 728 | + _T('zbug_calcul'). |
|
| 729 | + "</a></td><td>\n". |
|
| 730 | + (($var_mode_objet == $objet) ? "<b>$nom</b>" : $nom). |
|
| 731 | + "</td><td>\n". |
|
| 732 | + $req. |
|
| 733 | + "</td><td>\n". |
|
| 734 | + spip_htmlspecialchars($crit). |
|
| 738 | 735 | "</td></tr>"; |
| 739 | 736 | } |
| 740 | 737 | } |
@@ -761,7 +758,7 @@ discard block |
||
| 761 | 758 | } |
| 762 | 759 | // permettre le copier/coller facile |
| 763 | 760 | // $res = ancre_texte($req, array(), true); |
| 764 | - $res = "<div id='T" . md5($req) . "'>\n<pre>\n" . $req . "</pre>\n</div>\n"; |
|
| 761 | + $res = "<div id='T".md5($req)."'>\n<pre>\n".$req."</pre>\n</div>\n"; |
|
| 765 | 762 | // formatage et affichage des resultats bruts de la requete |
| 766 | 763 | $ress_req = spip_query($req); |
| 767 | 764 | $brut_sql = ''; |
@@ -771,10 +768,10 @@ discard block |
||
| 771 | 768 | $max_aff = defined('_MAX_DEBUG_AFF') ? _MAX_DEBUG_AFF : 50; |
| 772 | 769 | while ($retours_sql = sql_fetch($ress_req)) { |
| 773 | 770 | if ($num <= $max_aff) { |
| 774 | - $brut_sql .= "<h3>" . ($num == 1 ? $num . " sur " . sql_count($ress_req) : $num) . "</h3>"; |
|
| 771 | + $brut_sql .= "<h3>".($num == 1 ? $num." sur ".sql_count($ress_req) : $num)."</h3>"; |
|
| 775 | 772 | $brut_sql .= "<p>"; |
| 776 | 773 | foreach ($retours_sql as $key => $val) { |
| 777 | - $brut_sql .= "<strong>" . $key . "</strong> => " . spip_htmlspecialchars(couper($val, 150)) . "<br />\n"; |
|
| 774 | + $brut_sql .= "<strong>".$key."</strong> => ".spip_htmlspecialchars(couper($val, 150))."<br />\n"; |
|
| 778 | 775 | } |
| 779 | 776 | $brut_sql .= "</p>"; |
| 780 | 777 | } |
@@ -785,15 +782,15 @@ discard block |
||
| 785 | 782 | // ne pas afficher les $contexte_inclus |
| 786 | 783 | $view = preg_replace(",<\?php.+\?[>],Uims", "", $view); |
| 787 | 784 | if ($view) { |
| 788 | - $res2 .= "\n<br /><fieldset>" . interdire_scripts($view) . "</fieldset>"; |
|
| 785 | + $res2 .= "\n<br /><fieldset>".interdire_scripts($view)."</fieldset>"; |
|
| 789 | 786 | } |
| 790 | 787 | } |
| 791 | 788 | |
| 792 | 789 | } elseif ($affiche == 'code') { |
| 793 | 790 | $legend = $nom; |
| 794 | - $res = ancre_texte("<" . "?php\n" . $quoi . "\n?" . ">"); |
|
| 791 | + $res = ancre_texte("<"."?php\n".$quoi."\n?".">"); |
|
| 795 | 792 | } elseif ($affiche == 'boucle') { |
| 796 | - $legend = _T('zbug_boucle') . ' ' . $nom; |
|
| 793 | + $legend = _T('zbug_boucle').' '.$nom; |
|
| 797 | 794 | // Le compilateur prefixe le nom des boucles par l'extension du fichier source. |
| 798 | 795 | $gram = preg_match('/^([^_]+)_/', $objet, $r) ? $r[1] : ''; |
| 799 | 796 | $res = ancre_texte(public_decompiler($quoi, $gram, 0, 'boucle')); |
@@ -812,23 +809,23 @@ discard block |
||
| 812 | 809 | include_spip('public/assembler'); // pour inclure_balise_dynamique |
| 813 | 810 | include_spip('inc/texte'); // pour corriger_typo |
| 814 | 811 | |
| 815 | - return _DOCTYPE_ECRIRE . |
|
| 816 | - html_lang_attributes() . |
|
| 817 | - "<head>\n<title>" . |
|
| 818 | - ('SPIP ' . $GLOBALS['spip_version_affichee'] . ' ' . |
|
| 819 | - _T('admin_debug') . ' ' . $titre . ' (' . |
|
| 820 | - supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))) . |
|
| 821 | - ")</title>\n" . |
|
| 822 | - "<meta http-equiv='Content-Type' content='text/html" . |
|
| 823 | - (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : '') . |
|
| 824 | - "' />\n" . |
|
| 812 | + return _DOCTYPE_ECRIRE. |
|
| 813 | + html_lang_attributes(). |
|
| 814 | + "<head>\n<title>". |
|
| 815 | + ('SPIP '.$GLOBALS['spip_version_affichee'].' '. |
|
| 816 | + _T('admin_debug').' '.$titre.' ('. |
|
| 817 | + supprimer_tags(corriger_typo($GLOBALS['meta']['nom_site']))). |
|
| 818 | + ")</title>\n". |
|
| 819 | + "<meta http-equiv='Content-Type' content='text/html". |
|
| 820 | + (($c = $GLOBALS['meta']['charset']) ? "; charset=$c" : ''). |
|
| 821 | + "' />\n". |
|
| 825 | 822 | http_script('', 'jquery.js') |
| 826 | - . "<link rel='stylesheet' href='" . url_absolue(find_in_path('spip_admin.css')) |
|
| 827 | - . "' type='text/css' />" . |
|
| 828 | - "</head>\n" . |
|
| 829 | - "<body style='margin:0 10px;'>\n" . |
|
| 830 | - "<div id='spip-debug-header'>" . |
|
| 831 | - $corps . |
|
| 832 | - inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false) . |
|
| 823 | + . "<link rel='stylesheet' href='".url_absolue(find_in_path('spip_admin.css')) |
|
| 824 | + . "' type='text/css' />". |
|
| 825 | + "</head>\n". |
|
| 826 | + "<body style='margin:0 10px;'>\n". |
|
| 827 | + "<div id='spip-debug-header'>". |
|
| 828 | + $corps. |
|
| 829 | + inclure_balise_dynamique(balise_FORMULAIRE_ADMIN_dyn('spip-admin-float', $GLOBALS['debug_objets']), false). |
|
| 833 | 830 | '</div></body></html>'; |
| 834 | 831 | } |
@@ -362,9 +362,11 @@ discard block |
||
| 362 | 362 | if (!preg_match('/^(.*)(<\?.*\?>)(.*)$/s', $v[0], $r)) { |
| 363 | 363 | $y = substr_count($v[0], "\n"); |
| 364 | 364 | } else { |
| 365 | - if ($v[1][0] == '#') // balise dynamique |
|
| 365 | + if ($v[1][0] == '#') { |
|
| 366 | + // balise dynamique |
|
| 366 | 367 | { |
| 367 | 368 | $incl = $GLOBALS['debug_objets']['resultat'][$v[2]]; |
| 369 | + } |
|
| 368 | 370 | } else // inclusion |
| 369 | 371 | { |
| 370 | 372 | $incl = $GLOBALS['debug_objets']['squelette'][trouve_squelette_inclus($v[0])]; |
@@ -397,12 +399,14 @@ discard block |
||
| 397 | 399 | preg_match('/include\(.(.*).php3?.\);/', $script, $reg); |
| 398 | 400 | // si le script X.php n'est pas ecrire/public.php |
| 399 | 401 | // on suppose qu'il prend le squelette X.html (pas sur, mais y a pas mieux) |
| 400 | - if ($reg[1] == 'ecrire/public') // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 402 | + if ($reg[1] == 'ecrire/public') { |
|
| 403 | + // si c'est bien ecrire/public on cherche le param 'fond' |
|
| 401 | 404 | { |
| 402 | 405 | if (!preg_match("/'fond' => '([^']*)'/", $script, $reg)) // a defaut on cherche le param 'page' |
| 403 | 406 | { |
| 404 | 407 | if (!preg_match("/'param' => '([^']*)'/", $script, $reg)) { |
| 405 | 408 | $reg[1] = "inconnu"; |
| 409 | + } |
|
| 406 | 410 | } |
| 407 | 411 | } |
| 408 | 412 | } |
@@ -457,6 +457,10 @@ |
||
| 457 | 457 | * aller a la position $n en parcourant |
| 458 | 458 | * un par un tous les elements |
| 459 | 459 | */ |
| 460 | + |
|
| 461 | + /** |
|
| 462 | + * @param integer $n |
|
| 463 | + */ |
|
| 460 | 464 | private function seek_loop($n) { |
| 461 | 465 | if ($this->pos > $n) { |
| 462 | 466 | $this->rewind(); |
@@ -79,9 +79,9 @@ discard block |
||
| 79 | 79 | // chercher la classe d'iterateur |
| 80 | 80 | // IterateurXXX |
| 81 | 81 | // definie dans le fichier iterateurs/xxx.php |
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 82 | + $class = "Iterateur".$iterateur; |
|
| 83 | 83 | if (!class_exists($class)) { |
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 84 | + if (!include_spip("iterateur/".strtolower($iterateur)) |
|
| 85 | 85 | or !class_exists($class) |
| 86 | 86 | ) { |
| 87 | 87 | die("Iterateur $iterateur non trouvé"); |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | return $this->iter->$nom(); |
| 209 | 209 | } catch (Exception $e) { |
| 210 | 210 | // #GETCHILDREN sur un fichier de DirectoryIterator ... |
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 211 | + spip_log("Methode $nom en echec sur ".get_class($this->iter)); |
|
| 212 | 212 | spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
| 213 | 213 | |
| 214 | 214 | return ''; |
@@ -264,9 +264,9 @@ discard block |
||
| 264 | 264 | if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
| 265 | 265 | $req = ''; |
| 266 | 266 | foreach ($s_req[1] as $key => $val) { |
| 267 | - $req .= trim($val, '(,)') . ','; |
|
| 267 | + $req .= trim($val, '(,)').','; |
|
| 268 | 268 | } |
| 269 | - $req = '(' . rtrim($req, ',') . ')'; |
|
| 269 | + $req = '('.rtrim($req, ',').')'; |
|
| 270 | 270 | } |
| 271 | 271 | if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', |
| 272 | 272 | $op, $regs)) { |
@@ -302,8 +302,8 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | // Creer la fonction de filtrage sur $this |
| 304 | 304 | if ($this->filtre) { |
| 305 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 306 | - $this->func_filtre = function () use ($filtres) { |
|
| 305 | + $filtres = 'return ('.join(') AND (', $this->filtre).');'; |
|
| 306 | + $this->func_filtre = function() use ($filtres) { |
|
| 307 | 307 | return eval($filtres); |
| 308 | 308 | }; |
| 309 | 309 | } |
@@ -325,28 +325,28 @@ discard block |
||
| 325 | 325 | # if (!in_array($cle, array('cle', 'valeur'))) |
| 326 | 326 | # return; |
| 327 | 327 | |
| 328 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 328 | + $a = '$this->get_select(\''.$cle.'\')'; |
|
| 329 | 329 | |
| 330 | 330 | $filtre = ''; |
| 331 | 331 | |
| 332 | 332 | if ($op == 'REGEXP') { |
| 333 | - $filtre = 'match(' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 333 | + $filtre = 'match('.$a.', '.str_replace('\"', '"', $valeur).')'; |
|
| 334 | 334 | $op = ''; |
| 335 | 335 | } else { |
| 336 | 336 | if ($op == 'LIKE') { |
| 337 | 337 | $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
| 338 | - $filtre = 'match(' . $a . ', ' . $valeur . ')'; |
|
| 338 | + $filtre = 'match('.$a.', '.$valeur.')'; |
|
| 339 | 339 | $op = ''; |
| 340 | 340 | } else { |
| 341 | 341 | if ($op == '=') { |
| 342 | 342 | $op = '=='; |
| 343 | 343 | } else { |
| 344 | 344 | if ($op == 'IN') { |
| 345 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 345 | + $filtre = 'in_array('.$a.', array'.$valeur.')'; |
|
| 346 | 346 | $op = ''; |
| 347 | 347 | } else { |
| 348 | 348 | if (!in_array($op, array('<', '<=', '>', '>='))) { |
| 349 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 349 | + spip_log('operateur non reconnu '.$op); // [todo] mettre une erreur de squelette |
|
| 350 | 350 | $op = ''; |
| 351 | 351 | } |
| 352 | 352 | } |
@@ -355,7 +355,7 @@ discard block |
||
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | if ($op) { |
| 358 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 358 | + $filtre = $a.$op.str_replace('\"', '"', $valeur); |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | if ($not) { |
@@ -558,7 +558,7 @@ discard block |
||
| 558 | 558 | if (method_exists($v, '__toString')) { |
| 559 | 559 | $v = $v->__toString(); |
| 560 | 560 | } else { |
| 561 | - $v = (array)$v; |
|
| 561 | + $v = (array) $v; |
|
| 562 | 562 | } |
| 563 | 563 | } |
| 564 | 564 | |
@@ -12,7 +12,7 @@ discard block |
||
| 12 | 12 | \***************************************************************************/ |
| 13 | 13 | |
| 14 | 14 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 15 | - return; |
|
| 15 | + return; |
|
| 16 | 16 | } |
| 17 | 17 | |
| 18 | 18 | /** |
@@ -22,599 +22,599 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | */ |
| 24 | 24 | class IterFactory { |
| 25 | - public static function create($iterateur, $command, $info = null) { |
|
| 26 | - |
|
| 27 | - // cas des SI {si expression} analises tres tot |
|
| 28 | - // pour eviter le chargement de tout iterateur |
|
| 29 | - if (isset($command['si'])) { |
|
| 30 | - foreach ($command['si'] as $si) { |
|
| 31 | - if (!$si) { |
|
| 32 | - // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | - // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | - return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | - } |
|
| 36 | - } |
|
| 37 | - } |
|
| 38 | - |
|
| 39 | - // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | - // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | - // pour etre certain qu'on est sur un "php:") |
|
| 42 | - if (class_exists($iterateur)) { |
|
| 43 | - $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | - |
|
| 45 | - // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | - // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | - if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | - $iter = $a[0]; |
|
| 49 | - |
|
| 50 | - // sinon, on cree un iterateur du type donne |
|
| 51 | - } else { |
|
| 52 | - // arguments de creation de l'iterateur... |
|
| 53 | - // (pas glop) |
|
| 54 | - try { |
|
| 55 | - switch (count($a)) { |
|
| 56 | - case 0: |
|
| 57 | - $iter = new $iterateur(); |
|
| 58 | - break; |
|
| 59 | - case 1: |
|
| 60 | - $iter = new $iterateur($a[0]); |
|
| 61 | - break; |
|
| 62 | - case 2: |
|
| 63 | - $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | - break; |
|
| 65 | - case 3: |
|
| 66 | - $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | - break; |
|
| 68 | - case 4: |
|
| 69 | - $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | - break; |
|
| 71 | - } |
|
| 72 | - } catch (Exception $e) { |
|
| 73 | - spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | - spip_log($e->getMessage()); |
|
| 75 | - $iter = new EmptyIterator(); |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } else { |
|
| 79 | - // chercher la classe d'iterateur |
|
| 80 | - // IterateurXXX |
|
| 81 | - // definie dans le fichier iterateurs/xxx.php |
|
| 82 | - $class = "Iterateur" . $iterateur; |
|
| 83 | - if (!class_exists($class)) { |
|
| 84 | - if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | - or !class_exists($class) |
|
| 86 | - ) { |
|
| 87 | - die("Iterateur $iterateur non trouvé"); |
|
| 88 | - // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | - # $iter = new EmptyIterator(); |
|
| 90 | - } |
|
| 91 | - } |
|
| 92 | - $iter = new $class($command, $info); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return new IterDecorator($iter, $command, $info); |
|
| 96 | - } |
|
| 25 | + public static function create($iterateur, $command, $info = null) { |
|
| 26 | + |
|
| 27 | + // cas des SI {si expression} analises tres tot |
|
| 28 | + // pour eviter le chargement de tout iterateur |
|
| 29 | + if (isset($command['si'])) { |
|
| 30 | + foreach ($command['si'] as $si) { |
|
| 31 | + if (!$si) { |
|
| 32 | + // $command pour boucle SQL peut generer des erreurs de compilation |
|
| 33 | + // s'il est transmis alors qu'on est dans un iterateur vide |
|
| 34 | + return new IterDecorator(new EmptyIterator(), array(), $info); |
|
| 35 | + } |
|
| 36 | + } |
|
| 37 | + } |
|
| 38 | + |
|
| 39 | + // chercher un iterateur PHP existant (par exemple dans SPL) |
|
| 40 | + // (il faudrait passer l'argument ->sql_serveur |
|
| 41 | + // pour etre certain qu'on est sur un "php:") |
|
| 42 | + if (class_exists($iterateur)) { |
|
| 43 | + $a = isset($command['args']) ? $command['args'] : array(); |
|
| 44 | + |
|
| 45 | + // permettre de passer un Iterateur directement {args #ITERATEUR} : |
|
| 46 | + // si on recoit deja un iterateur en argument, on l'utilise |
|
| 47 | + if (count($a) == 1 and is_object($a[0]) and is_subclass_of($a[0], 'Iterator')) { |
|
| 48 | + $iter = $a[0]; |
|
| 49 | + |
|
| 50 | + // sinon, on cree un iterateur du type donne |
|
| 51 | + } else { |
|
| 52 | + // arguments de creation de l'iterateur... |
|
| 53 | + // (pas glop) |
|
| 54 | + try { |
|
| 55 | + switch (count($a)) { |
|
| 56 | + case 0: |
|
| 57 | + $iter = new $iterateur(); |
|
| 58 | + break; |
|
| 59 | + case 1: |
|
| 60 | + $iter = new $iterateur($a[0]); |
|
| 61 | + break; |
|
| 62 | + case 2: |
|
| 63 | + $iter = new $iterateur($a[0], $a[1]); |
|
| 64 | + break; |
|
| 65 | + case 3: |
|
| 66 | + $iter = new $iterateur($a[0], $a[1], $a[2]); |
|
| 67 | + break; |
|
| 68 | + case 4: |
|
| 69 | + $iter = new $iterateur($a[0], $a[1], $a[2], $a[3]); |
|
| 70 | + break; |
|
| 71 | + } |
|
| 72 | + } catch (Exception $e) { |
|
| 73 | + spip_log("Erreur de chargement de l'iterateur $iterateur"); |
|
| 74 | + spip_log($e->getMessage()); |
|
| 75 | + $iter = new EmptyIterator(); |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } else { |
|
| 79 | + // chercher la classe d'iterateur |
|
| 80 | + // IterateurXXX |
|
| 81 | + // definie dans le fichier iterateurs/xxx.php |
|
| 82 | + $class = "Iterateur" . $iterateur; |
|
| 83 | + if (!class_exists($class)) { |
|
| 84 | + if (!include_spip("iterateur/" . strtolower($iterateur)) |
|
| 85 | + or !class_exists($class) |
|
| 86 | + ) { |
|
| 87 | + die("Iterateur $iterateur non trouvé"); |
|
| 88 | + // si l'iterateur n'existe pas, on se rabat sur le generique |
|
| 89 | + # $iter = new EmptyIterator(); |
|
| 90 | + } |
|
| 91 | + } |
|
| 92 | + $iter = new $class($command, $info); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return new IterDecorator($iter, $command, $info); |
|
| 96 | + } |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | |
| 100 | 100 | class IterDecorator extends FilterIterator { |
| 101 | - private $iter; |
|
| 102 | - |
|
| 103 | - /** |
|
| 104 | - * Conditions de filtrage |
|
| 105 | - * ie criteres de selection |
|
| 106 | - * |
|
| 107 | - * @var array |
|
| 108 | - */ |
|
| 109 | - protected $filtre = array(); |
|
| 110 | - |
|
| 111 | - /** |
|
| 112 | - * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | - * |
|
| 114 | - * @var string |
|
| 115 | - */ |
|
| 116 | - protected $func_filtre = null; |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Critere {offset, limit} |
|
| 120 | - * |
|
| 121 | - * @var int |
|
| 122 | - * @var int |
|
| 123 | - */ |
|
| 124 | - protected $offset = null; |
|
| 125 | - protected $limit = null; |
|
| 126 | - |
|
| 127 | - /** |
|
| 128 | - * nombre d'elements recuperes depuis la position 0, |
|
| 129 | - * en tenant compte des filtres |
|
| 130 | - * |
|
| 131 | - * @var int |
|
| 132 | - */ |
|
| 133 | - protected $fetched = 0; |
|
| 134 | - |
|
| 135 | - /** |
|
| 136 | - * Y a t'il une erreur ? |
|
| 137 | - * |
|
| 138 | - * @var bool |
|
| 139 | - **/ |
|
| 140 | - protected $err = false; |
|
| 141 | - |
|
| 142 | - /** |
|
| 143 | - * Drapeau a activer en cas d'echec |
|
| 144 | - * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | - */ |
|
| 146 | - public function err() { |
|
| 147 | - if (method_exists($this->iter, 'err')) { |
|
| 148 | - return $this->iter->err(); |
|
| 149 | - } |
|
| 150 | - if (property_exists($this->iter, 'err')) { |
|
| 151 | - return $this->iter->err; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | - parent::__construct($iter); |
|
| 159 | - parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | - |
|
| 161 | - // recuperer l'iterateur transmis |
|
| 162 | - $this->iter = $this->getInnerIterator(); |
|
| 163 | - $this->command = $command; |
|
| 164 | - $this->info = $info; |
|
| 165 | - $this->pos = 0; |
|
| 166 | - $this->fetched = 0; |
|
| 167 | - |
|
| 168 | - // chercher la liste des champs a retourner par |
|
| 169 | - // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | - if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | - $this->calculer_select(); |
|
| 172 | - $this->calculer_filtres(); |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | - if (isset($this->iter->err)) { |
|
| 177 | - $this->err = $this->iter->err; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | - //$this->total = $this->count(); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - |
|
| 185 | - // calcule les elements a retournes par fetch() |
|
| 186 | - // enleve les elements inutiles du select() |
|
| 187 | - // |
|
| 188 | - private function calculer_select() { |
|
| 189 | - if ($select = &$this->command['select']) { |
|
| 190 | - foreach ($select as $s) { |
|
| 191 | - // /!\ $s = '.nom' |
|
| 192 | - if ($s[0] == '.') { |
|
| 193 | - $s = substr($s, 1); |
|
| 194 | - } |
|
| 195 | - $this->select[] = $s; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - // recuperer la valeur d'une balise #X |
|
| 201 | - // en fonction des methodes |
|
| 202 | - // et proprietes disponibles |
|
| 203 | - public function get_select($nom) { |
|
| 204 | - if (is_object($this->iter) |
|
| 205 | - and method_exists($this->iter, $nom) |
|
| 206 | - ) { |
|
| 207 | - try { |
|
| 208 | - return $this->iter->$nom(); |
|
| 209 | - } catch (Exception $e) { |
|
| 210 | - // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | - spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | - spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | - |
|
| 214 | - return ''; |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - /* |
|
| 101 | + private $iter; |
|
| 102 | + |
|
| 103 | + /** |
|
| 104 | + * Conditions de filtrage |
|
| 105 | + * ie criteres de selection |
|
| 106 | + * |
|
| 107 | + * @var array |
|
| 108 | + */ |
|
| 109 | + protected $filtre = array(); |
|
| 110 | + |
|
| 111 | + /** |
|
| 112 | + * Fonction de filtrage compilee a partir des criteres de filtre |
|
| 113 | + * |
|
| 114 | + * @var string |
|
| 115 | + */ |
|
| 116 | + protected $func_filtre = null; |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Critere {offset, limit} |
|
| 120 | + * |
|
| 121 | + * @var int |
|
| 122 | + * @var int |
|
| 123 | + */ |
|
| 124 | + protected $offset = null; |
|
| 125 | + protected $limit = null; |
|
| 126 | + |
|
| 127 | + /** |
|
| 128 | + * nombre d'elements recuperes depuis la position 0, |
|
| 129 | + * en tenant compte des filtres |
|
| 130 | + * |
|
| 131 | + * @var int |
|
| 132 | + */ |
|
| 133 | + protected $fetched = 0; |
|
| 134 | + |
|
| 135 | + /** |
|
| 136 | + * Y a t'il une erreur ? |
|
| 137 | + * |
|
| 138 | + * @var bool |
|
| 139 | + **/ |
|
| 140 | + protected $err = false; |
|
| 141 | + |
|
| 142 | + /** |
|
| 143 | + * Drapeau a activer en cas d'echec |
|
| 144 | + * (select SQL errone, non chargement des DATA, etc) |
|
| 145 | + */ |
|
| 146 | + public function err() { |
|
| 147 | + if (method_exists($this->iter, 'err')) { |
|
| 148 | + return $this->iter->err(); |
|
| 149 | + } |
|
| 150 | + if (property_exists($this->iter, 'err')) { |
|
| 151 | + return $this->iter->err; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + public function __construct(Iterator $iter, $command, $info) { |
|
| 158 | + parent::__construct($iter); |
|
| 159 | + parent::rewind(); // remettre a la premiere position (bug? connu de FilterIterator) |
|
| 160 | + |
|
| 161 | + // recuperer l'iterateur transmis |
|
| 162 | + $this->iter = $this->getInnerIterator(); |
|
| 163 | + $this->command = $command; |
|
| 164 | + $this->info = $info; |
|
| 165 | + $this->pos = 0; |
|
| 166 | + $this->fetched = 0; |
|
| 167 | + |
|
| 168 | + // chercher la liste des champs a retourner par |
|
| 169 | + // fetch si l'objet ne les calcule pas tout seul |
|
| 170 | + if (!method_exists($this->iter, 'fetch')) { |
|
| 171 | + $this->calculer_select(); |
|
| 172 | + $this->calculer_filtres(); |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // emptyIterator critere {si} faux n'a pas d'erreur ! |
|
| 176 | + if (isset($this->iter->err)) { |
|
| 177 | + $this->err = $this->iter->err; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 181 | + //$this->total = $this->count(); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + |
|
| 185 | + // calcule les elements a retournes par fetch() |
|
| 186 | + // enleve les elements inutiles du select() |
|
| 187 | + // |
|
| 188 | + private function calculer_select() { |
|
| 189 | + if ($select = &$this->command['select']) { |
|
| 190 | + foreach ($select as $s) { |
|
| 191 | + // /!\ $s = '.nom' |
|
| 192 | + if ($s[0] == '.') { |
|
| 193 | + $s = substr($s, 1); |
|
| 194 | + } |
|
| 195 | + $this->select[] = $s; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + // recuperer la valeur d'une balise #X |
|
| 201 | + // en fonction des methodes |
|
| 202 | + // et proprietes disponibles |
|
| 203 | + public function get_select($nom) { |
|
| 204 | + if (is_object($this->iter) |
|
| 205 | + and method_exists($this->iter, $nom) |
|
| 206 | + ) { |
|
| 207 | + try { |
|
| 208 | + return $this->iter->$nom(); |
|
| 209 | + } catch (Exception $e) { |
|
| 210 | + // #GETCHILDREN sur un fichier de DirectoryIterator ... |
|
| 211 | + spip_log("Methode $nom en echec sur " . get_class($this->iter)); |
|
| 212 | + spip_log("Cela peut être normal : retour d'une ligne de resultat ne pouvant pas calculer cette methode"); |
|
| 213 | + |
|
| 214 | + return ''; |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + /* |
|
| 218 | 218 | if (property_exists($this->iter, $nom)) { |
| 219 | 219 | return $this->iter->$nom; |
| 220 | 220 | }*/ |
| 221 | - // cle et valeur par defaut |
|
| 222 | - // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | - if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | - and method_exists($this, $nom) |
|
| 225 | - ) { |
|
| 226 | - return $this->$nom(); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // Par defaut chercher en xpath dans la valeur() |
|
| 230 | - return table_valeur($this->valeur(), $nom, null); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - |
|
| 234 | - private function calculer_filtres() { |
|
| 235 | - |
|
| 236 | - // Issu de calculer_select() de public/composer L.519 |
|
| 237 | - // TODO: externaliser... |
|
| 238 | - // |
|
| 239 | - // retirer les criteres vides: |
|
| 240 | - // {X ?} avec X absent de l'URL |
|
| 241 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | - if ($where = &$this->command['where']) { |
|
| 244 | - foreach ($where as $k => $v) { |
|
| 245 | - if (is_array($v)) { |
|
| 246 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | - $op = false; |
|
| 248 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | - $op = false; |
|
| 250 | - } else { |
|
| 251 | - $op = $v[0] ? $v[0] : $v; |
|
| 252 | - } |
|
| 253 | - } else { |
|
| 254 | - $op = $v; |
|
| 255 | - } |
|
| 256 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | - unset($where[$k]); |
|
| 258 | - } |
|
| 259 | - // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | - // prendre en compte le cas particulier de sous-requetes |
|
| 261 | - // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 262 | - if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 263 | - $req = ''; |
|
| 264 | - foreach ($s_req[1] as $key => $val) { |
|
| 265 | - $req .= trim($val, '(,)') . ','; |
|
| 266 | - } |
|
| 267 | - $req = '(' . rtrim($req, ',') . ')'; |
|
| 268 | - } |
|
| 269 | - if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', |
|
| 270 | - $op, $regs)) { |
|
| 271 | - $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 272 | - unset($op, $where[$k]); |
|
| 273 | - } |
|
| 274 | - } |
|
| 275 | - foreach ($where as $k => $v) { |
|
| 276 | - // 3 possibilites : count($v) = |
|
| 277 | - // * 1 : {x y} ; on recoit $v[0] = y |
|
| 278 | - // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 279 | - // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 280 | - |
|
| 281 | - // 1 : forcement traite par un critere, on passe |
|
| 282 | - if (count($v) == 1) { |
|
| 283 | - continue; |
|
| 284 | - } |
|
| 285 | - if (count($v) == 2 and is_array($v[1])) { |
|
| 286 | - $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 287 | - } |
|
| 288 | - if (count($v) == 3) { |
|
| 289 | - $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - // critere {2,7} |
|
| 295 | - if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 296 | - $limit = explode(',', $this->command['limit']); |
|
| 297 | - $this->offset = $limit[0]; |
|
| 298 | - $this->limit = $limit[1]; |
|
| 299 | - } |
|
| 300 | - |
|
| 301 | - // Creer la fonction de filtrage sur $this |
|
| 302 | - if ($this->filtre) { |
|
| 303 | - $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 304 | - $this->func_filtre = function () use ($filtres) { |
|
| 305 | - return eval($filtres); |
|
| 306 | - }; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - |
|
| 310 | - |
|
| 311 | - protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 312 | - if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 313 | - if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 314 | - return; |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 318 | - # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 319 | - # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 320 | - # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 321 | - # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 322 | - |
|
| 323 | - # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 324 | - # return; |
|
| 325 | - |
|
| 326 | - $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 327 | - |
|
| 328 | - $filtre = ''; |
|
| 329 | - |
|
| 330 | - if ($op == 'REGEXP') { |
|
| 331 | - $filtre = 'match(' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 332 | - $op = ''; |
|
| 333 | - } else { |
|
| 334 | - if ($op == 'LIKE') { |
|
| 335 | - $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 336 | - $filtre = 'match(' . $a . ', ' . $valeur . ')'; |
|
| 337 | - $op = ''; |
|
| 338 | - } else { |
|
| 339 | - if ($op == '=') { |
|
| 340 | - $op = '=='; |
|
| 341 | - } else { |
|
| 342 | - if ($op == 'IN') { |
|
| 343 | - $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 344 | - $op = ''; |
|
| 345 | - } else { |
|
| 346 | - if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 347 | - spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 348 | - $op = ''; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - if ($op) { |
|
| 356 | - $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 357 | - } |
|
| 358 | - |
|
| 359 | - if ($not) { |
|
| 360 | - $filtre = "!($filtre)"; |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if ($filtre) { |
|
| 364 | - $this->filtre[] = $filtre; |
|
| 365 | - } |
|
| 366 | - } |
|
| 367 | - |
|
| 368 | - |
|
| 369 | - public function next() { |
|
| 370 | - $this->pos++; |
|
| 371 | - parent::next(); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - /** |
|
| 375 | - * revient au depart |
|
| 376 | - * |
|
| 377 | - * @return void |
|
| 378 | - */ |
|
| 379 | - public function rewind() { |
|
| 380 | - $this->pos = 0; |
|
| 381 | - $this->fetched = 0; |
|
| 382 | - parent::rewind(); |
|
| 383 | - } |
|
| 384 | - |
|
| 385 | - |
|
| 386 | - # Extension SPIP des iterateurs PHP |
|
| 387 | - /** |
|
| 388 | - * type de l'iterateur |
|
| 389 | - * |
|
| 390 | - * @var string |
|
| 391 | - */ |
|
| 392 | - protected $type; |
|
| 393 | - |
|
| 394 | - /** |
|
| 395 | - * parametres de l'iterateur |
|
| 396 | - * |
|
| 397 | - * @var array |
|
| 398 | - */ |
|
| 399 | - protected $command; |
|
| 400 | - |
|
| 401 | - /** |
|
| 402 | - * infos de compilateur |
|
| 403 | - * |
|
| 404 | - * @var array |
|
| 405 | - */ |
|
| 406 | - protected $info; |
|
| 407 | - |
|
| 408 | - /** |
|
| 409 | - * position courante de l'iterateur |
|
| 410 | - * |
|
| 411 | - * @var int |
|
| 412 | - */ |
|
| 413 | - protected $pos = null; |
|
| 414 | - |
|
| 415 | - /** |
|
| 416 | - * nombre total resultats dans l'iterateur |
|
| 417 | - * |
|
| 418 | - * @var int |
|
| 419 | - */ |
|
| 420 | - protected $total = null; |
|
| 421 | - |
|
| 422 | - /** |
|
| 423 | - * nombre maximal de recherche pour $total |
|
| 424 | - * si l'iterateur n'implemente pas de fonction specifique |
|
| 425 | - */ |
|
| 426 | - protected $max = 100000; |
|
| 427 | - |
|
| 428 | - |
|
| 429 | - /** |
|
| 430 | - * Liste des champs a inserer dans les $row |
|
| 431 | - * retournes par ->fetch() |
|
| 432 | - */ |
|
| 433 | - protected $select = array(); |
|
| 434 | - |
|
| 435 | - |
|
| 436 | - /** |
|
| 437 | - * aller a la position absolue n, |
|
| 438 | - * comptee depuis le debut |
|
| 439 | - * |
|
| 440 | - * @param int $n |
|
| 441 | - * absolute pos |
|
| 442 | - * @param string $continue |
|
| 443 | - * param for sql_ api |
|
| 444 | - * @return bool |
|
| 445 | - * success or fail if not implemented |
|
| 446 | - */ |
|
| 447 | - public function seek($n = 0, $continue = null) { |
|
| 448 | - if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 449 | - $this->seek_loop($n); |
|
| 450 | - } |
|
| 451 | - $this->pos = $n; |
|
| 452 | - $this->fetched = $n; |
|
| 453 | - |
|
| 454 | - return true; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - /* |
|
| 221 | + // cle et valeur par defaut |
|
| 222 | + // ICI PLANTAGE SI ON NE CONTROLE PAS $nom |
|
| 223 | + if (in_array($nom, array('cle', 'valeur')) |
|
| 224 | + and method_exists($this, $nom) |
|
| 225 | + ) { |
|
| 226 | + return $this->$nom(); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // Par defaut chercher en xpath dans la valeur() |
|
| 230 | + return table_valeur($this->valeur(), $nom, null); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + |
|
| 234 | + private function calculer_filtres() { |
|
| 235 | + |
|
| 236 | + // Issu de calculer_select() de public/composer L.519 |
|
| 237 | + // TODO: externaliser... |
|
| 238 | + // |
|
| 239 | + // retirer les criteres vides: |
|
| 240 | + // {X ?} avec X absent de l'URL |
|
| 241 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 242 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 243 | + if ($where = &$this->command['where']) { |
|
| 244 | + foreach ($where as $k => $v) { |
|
| 245 | + if (is_array($v)) { |
|
| 246 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 247 | + $op = false; |
|
| 248 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 249 | + $op = false; |
|
| 250 | + } else { |
|
| 251 | + $op = $v[0] ? $v[0] : $v; |
|
| 252 | + } |
|
| 253 | + } else { |
|
| 254 | + $op = $v; |
|
| 255 | + } |
|
| 256 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 257 | + unset($where[$k]); |
|
| 258 | + } |
|
| 259 | + // traiter {cle IN a,b} ou {valeur !IN a,b} |
|
| 260 | + // prendre en compte le cas particulier de sous-requetes |
|
| 261 | + // produites par sql_in quand plus de 255 valeurs passees a IN |
|
| 262 | + if (preg_match_all(',\s+IN\s+(\(.*\)),', $op, $s_req)) { |
|
| 263 | + $req = ''; |
|
| 264 | + foreach ($s_req[1] as $key => $val) { |
|
| 265 | + $req .= trim($val, '(,)') . ','; |
|
| 266 | + } |
|
| 267 | + $req = '(' . rtrim($req, ',') . ')'; |
|
| 268 | + } |
|
| 269 | + if (preg_match(',^\(\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\)(?:\s+(AND|OR)\s+\(([\w/]+)(\s+NOT)?\s+IN\s+(\(.*\))\))*\)$,', |
|
| 270 | + $op, $regs)) { |
|
| 271 | + $this->ajouter_filtre($regs[1], 'IN', strlen($req) ? $req : $regs[3], $regs[2]); |
|
| 272 | + unset($op, $where[$k]); |
|
| 273 | + } |
|
| 274 | + } |
|
| 275 | + foreach ($where as $k => $v) { |
|
| 276 | + // 3 possibilites : count($v) = |
|
| 277 | + // * 1 : {x y} ; on recoit $v[0] = y |
|
| 278 | + // * 2 : {x !op y} ; on recoit $v[0] = 'NOT', $v[1] = array() // array du type {x op y} |
|
| 279 | + // * 3 : {x op y} ; on recoit $v[0] = 'op', $v[1] = x, $v[2] = y |
|
| 280 | + |
|
| 281 | + // 1 : forcement traite par un critere, on passe |
|
| 282 | + if (count($v) == 1) { |
|
| 283 | + continue; |
|
| 284 | + } |
|
| 285 | + if (count($v) == 2 and is_array($v[1])) { |
|
| 286 | + $this->ajouter_filtre($v[1][1], $v[1][0], $v[1][2], 'NOT'); |
|
| 287 | + } |
|
| 288 | + if (count($v) == 3) { |
|
| 289 | + $this->ajouter_filtre($v[1], $v[0], $v[2]); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + // critere {2,7} |
|
| 295 | + if (isset($this->command['limit']) and $this->command['limit']) { |
|
| 296 | + $limit = explode(',', $this->command['limit']); |
|
| 297 | + $this->offset = $limit[0]; |
|
| 298 | + $this->limit = $limit[1]; |
|
| 299 | + } |
|
| 300 | + |
|
| 301 | + // Creer la fonction de filtrage sur $this |
|
| 302 | + if ($this->filtre) { |
|
| 303 | + $filtres = 'return (' . join(') AND (', $this->filtre) . ');'; |
|
| 304 | + $this->func_filtre = function () use ($filtres) { |
|
| 305 | + return eval($filtres); |
|
| 306 | + }; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + |
|
| 310 | + |
|
| 311 | + protected function ajouter_filtre($cle, $op, $valeur, $not = false) { |
|
| 312 | + if (method_exists($this->iter, 'exception_des_criteres')) { |
|
| 313 | + if (in_array($cle, $this->iter->exception_des_criteres())) { |
|
| 314 | + return; |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + // TODO: analyser le filtre pour refuser ce qu'on ne sait pas traiter ? |
|
| 318 | + # mais c'est normalement deja opere par calculer_critere_infixe() |
|
| 319 | + # qui regarde la description 'desc' (en casse reelle d'ailleurs : {isDir=1} |
|
| 320 | + # ne sera pas vu si l'on a defini desc['field']['isdir'] pour que #ISDIR soit present. |
|
| 321 | + # il faudrait peut etre definir les 2 champs isDir et isdir... a reflechir... |
|
| 322 | + |
|
| 323 | + # if (!in_array($cle, array('cle', 'valeur'))) |
|
| 324 | + # return; |
|
| 325 | + |
|
| 326 | + $a = '$this->get_select(\'' . $cle . '\')'; |
|
| 327 | + |
|
| 328 | + $filtre = ''; |
|
| 329 | + |
|
| 330 | + if ($op == 'REGEXP') { |
|
| 331 | + $filtre = 'match(' . $a . ', ' . str_replace('\"', '"', $valeur) . ')'; |
|
| 332 | + $op = ''; |
|
| 333 | + } else { |
|
| 334 | + if ($op == 'LIKE') { |
|
| 335 | + $valeur = str_replace(array('\"', '_', '%'), array('"', '.', '.*'), preg_quote($valeur)); |
|
| 336 | + $filtre = 'match(' . $a . ', ' . $valeur . ')'; |
|
| 337 | + $op = ''; |
|
| 338 | + } else { |
|
| 339 | + if ($op == '=') { |
|
| 340 | + $op = '=='; |
|
| 341 | + } else { |
|
| 342 | + if ($op == 'IN') { |
|
| 343 | + $filtre = 'in_array(' . $a . ', array' . $valeur . ')'; |
|
| 344 | + $op = ''; |
|
| 345 | + } else { |
|
| 346 | + if (!in_array($op, array('<', '<=', '>', '>='))) { |
|
| 347 | + spip_log('operateur non reconnu ' . $op); // [todo] mettre une erreur de squelette |
|
| 348 | + $op = ''; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + if ($op) { |
|
| 356 | + $filtre = $a . $op . str_replace('\"', '"', $valeur); |
|
| 357 | + } |
|
| 358 | + |
|
| 359 | + if ($not) { |
|
| 360 | + $filtre = "!($filtre)"; |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if ($filtre) { |
|
| 364 | + $this->filtre[] = $filtre; |
|
| 365 | + } |
|
| 366 | + } |
|
| 367 | + |
|
| 368 | + |
|
| 369 | + public function next() { |
|
| 370 | + $this->pos++; |
|
| 371 | + parent::next(); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + /** |
|
| 375 | + * revient au depart |
|
| 376 | + * |
|
| 377 | + * @return void |
|
| 378 | + */ |
|
| 379 | + public function rewind() { |
|
| 380 | + $this->pos = 0; |
|
| 381 | + $this->fetched = 0; |
|
| 382 | + parent::rewind(); |
|
| 383 | + } |
|
| 384 | + |
|
| 385 | + |
|
| 386 | + # Extension SPIP des iterateurs PHP |
|
| 387 | + /** |
|
| 388 | + * type de l'iterateur |
|
| 389 | + * |
|
| 390 | + * @var string |
|
| 391 | + */ |
|
| 392 | + protected $type; |
|
| 393 | + |
|
| 394 | + /** |
|
| 395 | + * parametres de l'iterateur |
|
| 396 | + * |
|
| 397 | + * @var array |
|
| 398 | + */ |
|
| 399 | + protected $command; |
|
| 400 | + |
|
| 401 | + /** |
|
| 402 | + * infos de compilateur |
|
| 403 | + * |
|
| 404 | + * @var array |
|
| 405 | + */ |
|
| 406 | + protected $info; |
|
| 407 | + |
|
| 408 | + /** |
|
| 409 | + * position courante de l'iterateur |
|
| 410 | + * |
|
| 411 | + * @var int |
|
| 412 | + */ |
|
| 413 | + protected $pos = null; |
|
| 414 | + |
|
| 415 | + /** |
|
| 416 | + * nombre total resultats dans l'iterateur |
|
| 417 | + * |
|
| 418 | + * @var int |
|
| 419 | + */ |
|
| 420 | + protected $total = null; |
|
| 421 | + |
|
| 422 | + /** |
|
| 423 | + * nombre maximal de recherche pour $total |
|
| 424 | + * si l'iterateur n'implemente pas de fonction specifique |
|
| 425 | + */ |
|
| 426 | + protected $max = 100000; |
|
| 427 | + |
|
| 428 | + |
|
| 429 | + /** |
|
| 430 | + * Liste des champs a inserer dans les $row |
|
| 431 | + * retournes par ->fetch() |
|
| 432 | + */ |
|
| 433 | + protected $select = array(); |
|
| 434 | + |
|
| 435 | + |
|
| 436 | + /** |
|
| 437 | + * aller a la position absolue n, |
|
| 438 | + * comptee depuis le debut |
|
| 439 | + * |
|
| 440 | + * @param int $n |
|
| 441 | + * absolute pos |
|
| 442 | + * @param string $continue |
|
| 443 | + * param for sql_ api |
|
| 444 | + * @return bool |
|
| 445 | + * success or fail if not implemented |
|
| 446 | + */ |
|
| 447 | + public function seek($n = 0, $continue = null) { |
|
| 448 | + if ($this->func_filtre or !method_exists($this->iter, 'seek') or !$this->iter->seek($n)) { |
|
| 449 | + $this->seek_loop($n); |
|
| 450 | + } |
|
| 451 | + $this->pos = $n; |
|
| 452 | + $this->fetched = $n; |
|
| 453 | + |
|
| 454 | + return true; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + /* |
|
| 458 | 458 | * aller a la position $n en parcourant |
| 459 | 459 | * un par un tous les elements |
| 460 | 460 | */ |
| 461 | - private function seek_loop($n) { |
|
| 462 | - if ($this->pos > $n) { |
|
| 463 | - $this->rewind(); |
|
| 464 | - } |
|
| 465 | - |
|
| 466 | - while ($this->pos < $n and $this->valid()) { |
|
| 467 | - $this->next(); |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - return true; |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - /** |
|
| 474 | - * Avancer de $saut pas |
|
| 475 | - * |
|
| 476 | - * @param $saut |
|
| 477 | - * @param $max |
|
| 478 | - * @return int |
|
| 479 | - */ |
|
| 480 | - public function skip($saut, $max = null) { |
|
| 481 | - // pas de saut en arriere autorise pour cette fonction |
|
| 482 | - if (($saut = intval($saut)) <= 0) { |
|
| 483 | - return $this->pos; |
|
| 484 | - } |
|
| 485 | - $seek = $this->pos + $saut; |
|
| 486 | - // si le saut fait depasser le maxi, on libere la resource |
|
| 487 | - // et on sort |
|
| 488 | - if (is_null($max)) { |
|
| 489 | - $max = $this->count(); |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ($seek >= $max or $seek >= $this->count()) { |
|
| 493 | - // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 494 | - $this->free(); |
|
| 495 | - |
|
| 496 | - return $max; |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $this->seek($seek); |
|
| 500 | - |
|
| 501 | - return $this->pos; |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - /** |
|
| 505 | - * Renvoyer un tableau des donnees correspondantes |
|
| 506 | - * a la position courante de l'iterateur |
|
| 507 | - * en controlant si on respecte le filtre |
|
| 508 | - * Appliquer aussi le critere {offset,limit} |
|
| 509 | - * |
|
| 510 | - * @return array|bool |
|
| 511 | - */ |
|
| 512 | - public function fetch() { |
|
| 513 | - if (method_exists($this->iter, 'fetch')) { |
|
| 514 | - return $this->iter->fetch(); |
|
| 515 | - } else { |
|
| 516 | - |
|
| 517 | - while ($this->valid() |
|
| 518 | - and ( |
|
| 519 | - !$this->accept() |
|
| 520 | - or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 521 | - )) { |
|
| 522 | - $this->next(); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - if (!$this->valid()) { |
|
| 526 | - return false; |
|
| 527 | - } |
|
| 528 | - |
|
| 529 | - if (isset($this->limit) |
|
| 530 | - and $this->fetched > $this->offset + $this->limit |
|
| 531 | - ) { |
|
| 532 | - return false; |
|
| 533 | - } |
|
| 534 | - |
|
| 535 | - $r = array(); |
|
| 536 | - foreach ($this->select as $nom) { |
|
| 537 | - $r[$nom] = $this->get_select($nom); |
|
| 538 | - } |
|
| 539 | - $this->next(); |
|
| 540 | - |
|
| 541 | - return $r; |
|
| 542 | - } |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - // retourner la cle pour #CLE |
|
| 546 | - public function cle() { |
|
| 547 | - return $this->key(); |
|
| 548 | - } |
|
| 549 | - |
|
| 550 | - // retourner la valeur pour #VALEUR |
|
| 551 | - public function valeur() { |
|
| 552 | - # attention PHP est mechant avec les objets, parfois il ne les |
|
| 553 | - # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 554 | - # on se rabat sur la version __toString() |
|
| 555 | - if (is_object($v = $this->current())) { |
|
| 556 | - if (method_exists($v, '__toString')) { |
|
| 557 | - $v = $v->__toString(); |
|
| 558 | - } else { |
|
| 559 | - $v = (array)$v; |
|
| 560 | - } |
|
| 561 | - } |
|
| 562 | - |
|
| 563 | - return $v; |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - /** |
|
| 567 | - * Accepte-t-on l'entree courante lue ? |
|
| 568 | - * On execute les filtres pour le savoir. |
|
| 569 | - **/ |
|
| 570 | - public function accept() { |
|
| 571 | - if ($f = $this->func_filtre) { |
|
| 572 | - return $f(); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return true; |
|
| 576 | - } |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * liberer la ressource |
|
| 580 | - * |
|
| 581 | - * @return bool |
|
| 582 | - */ |
|
| 583 | - public function free() { |
|
| 584 | - if (method_exists($this->iter, 'free')) { |
|
| 585 | - $this->iter->free(); |
|
| 586 | - } |
|
| 587 | - $this->pos = $this->total = 0; |
|
| 588 | - |
|
| 589 | - return true; |
|
| 590 | - } |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Compter le nombre total de resultats |
|
| 594 | - * pour #TOTAL_BOUCLE |
|
| 595 | - * |
|
| 596 | - * @return int |
|
| 597 | - */ |
|
| 598 | - public function count() { |
|
| 599 | - if (is_null($this->total)) { |
|
| 600 | - if (method_exists($this->iter, 'count') |
|
| 601 | - and !$this->func_filtre |
|
| 602 | - ) { |
|
| 603 | - return $this->total = $this->iter->count(); |
|
| 604 | - } else { |
|
| 605 | - // compter les lignes et rembobiner |
|
| 606 | - $total = 0; |
|
| 607 | - $pos = $this->pos; // sauver la position |
|
| 608 | - $this->rewind(); |
|
| 609 | - while ($this->fetch() and $total < $this->max) { |
|
| 610 | - $total++; |
|
| 611 | - } |
|
| 612 | - $this->seek($pos); |
|
| 613 | - $this->total = $total; |
|
| 614 | - } |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - return $this->total; |
|
| 618 | - } |
|
| 461 | + private function seek_loop($n) { |
|
| 462 | + if ($this->pos > $n) { |
|
| 463 | + $this->rewind(); |
|
| 464 | + } |
|
| 465 | + |
|
| 466 | + while ($this->pos < $n and $this->valid()) { |
|
| 467 | + $this->next(); |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + return true; |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + /** |
|
| 474 | + * Avancer de $saut pas |
|
| 475 | + * |
|
| 476 | + * @param $saut |
|
| 477 | + * @param $max |
|
| 478 | + * @return int |
|
| 479 | + */ |
|
| 480 | + public function skip($saut, $max = null) { |
|
| 481 | + // pas de saut en arriere autorise pour cette fonction |
|
| 482 | + if (($saut = intval($saut)) <= 0) { |
|
| 483 | + return $this->pos; |
|
| 484 | + } |
|
| 485 | + $seek = $this->pos + $saut; |
|
| 486 | + // si le saut fait depasser le maxi, on libere la resource |
|
| 487 | + // et on sort |
|
| 488 | + if (is_null($max)) { |
|
| 489 | + $max = $this->count(); |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ($seek >= $max or $seek >= $this->count()) { |
|
| 493 | + // sortie plus rapide que de faire next() jusqu'a la fin ! |
|
| 494 | + $this->free(); |
|
| 495 | + |
|
| 496 | + return $max; |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $this->seek($seek); |
|
| 500 | + |
|
| 501 | + return $this->pos; |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + /** |
|
| 505 | + * Renvoyer un tableau des donnees correspondantes |
|
| 506 | + * a la position courante de l'iterateur |
|
| 507 | + * en controlant si on respecte le filtre |
|
| 508 | + * Appliquer aussi le critere {offset,limit} |
|
| 509 | + * |
|
| 510 | + * @return array|bool |
|
| 511 | + */ |
|
| 512 | + public function fetch() { |
|
| 513 | + if (method_exists($this->iter, 'fetch')) { |
|
| 514 | + return $this->iter->fetch(); |
|
| 515 | + } else { |
|
| 516 | + |
|
| 517 | + while ($this->valid() |
|
| 518 | + and ( |
|
| 519 | + !$this->accept() |
|
| 520 | + or (isset($this->offset) and $this->fetched++ < $this->offset) |
|
| 521 | + )) { |
|
| 522 | + $this->next(); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + if (!$this->valid()) { |
|
| 526 | + return false; |
|
| 527 | + } |
|
| 528 | + |
|
| 529 | + if (isset($this->limit) |
|
| 530 | + and $this->fetched > $this->offset + $this->limit |
|
| 531 | + ) { |
|
| 532 | + return false; |
|
| 533 | + } |
|
| 534 | + |
|
| 535 | + $r = array(); |
|
| 536 | + foreach ($this->select as $nom) { |
|
| 537 | + $r[$nom] = $this->get_select($nom); |
|
| 538 | + } |
|
| 539 | + $this->next(); |
|
| 540 | + |
|
| 541 | + return $r; |
|
| 542 | + } |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + // retourner la cle pour #CLE |
|
| 546 | + public function cle() { |
|
| 547 | + return $this->key(); |
|
| 548 | + } |
|
| 549 | + |
|
| 550 | + // retourner la valeur pour #VALEUR |
|
| 551 | + public function valeur() { |
|
| 552 | + # attention PHP est mechant avec les objets, parfois il ne les |
|
| 553 | + # clone pas proprement (directoryiterator sous php 5.2.2) |
|
| 554 | + # on se rabat sur la version __toString() |
|
| 555 | + if (is_object($v = $this->current())) { |
|
| 556 | + if (method_exists($v, '__toString')) { |
|
| 557 | + $v = $v->__toString(); |
|
| 558 | + } else { |
|
| 559 | + $v = (array)$v; |
|
| 560 | + } |
|
| 561 | + } |
|
| 562 | + |
|
| 563 | + return $v; |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + /** |
|
| 567 | + * Accepte-t-on l'entree courante lue ? |
|
| 568 | + * On execute les filtres pour le savoir. |
|
| 569 | + **/ |
|
| 570 | + public function accept() { |
|
| 571 | + if ($f = $this->func_filtre) { |
|
| 572 | + return $f(); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return true; |
|
| 576 | + } |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * liberer la ressource |
|
| 580 | + * |
|
| 581 | + * @return bool |
|
| 582 | + */ |
|
| 583 | + public function free() { |
|
| 584 | + if (method_exists($this->iter, 'free')) { |
|
| 585 | + $this->iter->free(); |
|
| 586 | + } |
|
| 587 | + $this->pos = $this->total = 0; |
|
| 588 | + |
|
| 589 | + return true; |
|
| 590 | + } |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Compter le nombre total de resultats |
|
| 594 | + * pour #TOTAL_BOUCLE |
|
| 595 | + * |
|
| 596 | + * @return int |
|
| 597 | + */ |
|
| 598 | + public function count() { |
|
| 599 | + if (is_null($this->total)) { |
|
| 600 | + if (method_exists($this->iter, 'count') |
|
| 601 | + and !$this->func_filtre |
|
| 602 | + ) { |
|
| 603 | + return $this->total = $this->iter->count(); |
|
| 604 | + } else { |
|
| 605 | + // compter les lignes et rembobiner |
|
| 606 | + $total = 0; |
|
| 607 | + $pos = $this->pos; // sauver la position |
|
| 608 | + $this->rewind(); |
|
| 609 | + while ($this->fetch() and $total < $this->max) { |
|
| 610 | + $total++; |
|
| 611 | + } |
|
| 612 | + $this->seek($pos); |
|
| 613 | + $this->total = $total; |
|
| 614 | + } |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + return $this->total; |
|
| 618 | + } |
|
| 619 | 619 | |
| 620 | 620 | } |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @param array $depart |
| 233 | 233 | * @param array $arrivee |
| 234 | - * @param string|array $col |
|
| 234 | + * @param string $col |
|
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
@@ -178,7 +178,7 @@ discard block |
||
| 178 | 178 | $echap ? |
| 179 | 179 | array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
| 180 | 180 | : |
| 181 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 181 | + array($id_table, $j2, $j1, "$obj=".sql_quote($type)); |
|
| 182 | 182 | } else { |
| 183 | 183 | $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
| 184 | 184 | } |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | $groups = liste_champs_jointures($nom, $desc, true); |
| 212 | 212 | if (!$pk) { |
| 213 | 213 | foreach ($groups as $id_prim) { |
| 214 | - $id_field = $nom . '.' . $id_prim; |
|
| 214 | + $id_field = $nom.'.'.$id_prim; |
|
| 215 | 215 | if (!in_array($id_field, $boucle->group)) { |
| 216 | 216 | $boucle->group[] = $id_field; |
| 217 | 217 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -33,11 +33,11 @@ discard block |
||
| 33 | 33 | * Chaine sinon : le nom du champ (non décomposable donc) |
| 34 | 34 | */ |
| 35 | 35 | function decompose_champ_id_objet($champ) { |
| 36 | - if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | - return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 38 | - } |
|
| 36 | + if (($champ !== 'id_objet') and preg_match(',^id_([a-z_]+)$,', $champ, $regs)) { |
|
| 37 | + return array('id_objet', 'objet', objet_type($regs[1])); |
|
| 38 | + } |
|
| 39 | 39 | |
| 40 | - return $champ; |
|
| 40 | + return $champ; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -56,20 +56,20 @@ discard block |
||
| 56 | 56 | * - array(id_objet, objet), si le champ n'existe pas mais qu'on peut décomposer |
| 57 | 57 | */ |
| 58 | 58 | function trouver_champs_decomposes($champ, $desc) { |
| 59 | - if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | - or array_key_exists($champ, $desc['field']) |
|
| 61 | - ) { |
|
| 62 | - return array($champ); |
|
| 63 | - } |
|
| 64 | - // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | - if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | - array_pop($decompose); |
|
| 67 | - if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | - return $decompose; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - |
|
| 72 | - return array($champ); |
|
| 59 | + if (!is_array($desc) // on ne se risque pas en conjectures si on ne connait pas la table |
|
| 60 | + or array_key_exists($champ, $desc['field']) |
|
| 61 | + ) { |
|
| 62 | + return array($champ); |
|
| 63 | + } |
|
| 64 | + // si le champ se décompose, tester que les colonnes décomposées sont présentes |
|
| 65 | + if (is_array($decompose = decompose_champ_id_objet($champ))) { |
|
| 66 | + array_pop($decompose); |
|
| 67 | + if (count(array_intersect($decompose, array_keys($desc['field']))) == count($decompose)) { |
|
| 68 | + return $decompose; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + |
|
| 72 | + return array($champ); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -99,23 +99,23 @@ discard block |
||
| 99 | 99 | * Alias de la table de jointure (Lx) |
| 100 | 100 | */ |
| 101 | 101 | function calculer_jointure(&$boucle, $depart, $arrivee, $col = '', $cond = false, $max_liens = 5) { |
| 102 | - // les jointures minimales sont optimales : |
|
| 103 | - // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | - // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | - $max = 1; |
|
| 106 | - $res = false; |
|
| 107 | - $milieu_exclus = ($col ? $col : array()); |
|
| 108 | - while ($max <= $max_liens and !$res) { |
|
| 109 | - $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | - $max++; |
|
| 111 | - } |
|
| 112 | - if (!$res) { |
|
| 113 | - return ""; |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - list($nom, $desc) = $depart; |
|
| 117 | - |
|
| 118 | - return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 102 | + // les jointures minimales sont optimales : |
|
| 103 | + // on contraint le nombre d'etapes en l'augmentant |
|
| 104 | + // jusqu'a ce qu'on trouve une jointure ou qu'on atteigne la limite maxi |
|
| 105 | + $max = 1; |
|
| 106 | + $res = false; |
|
| 107 | + $milieu_exclus = ($col ? $col : array()); |
|
| 108 | + while ($max <= $max_liens and !$res) { |
|
| 109 | + $res = calculer_chaine_jointures($boucle, $depart, $arrivee, array(), $milieu_exclus, $max); |
|
| 110 | + $max++; |
|
| 111 | + } |
|
| 112 | + if (!$res) { |
|
| 113 | + return ""; |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + list($nom, $desc) = $depart; |
|
| 117 | + |
|
| 118 | + return fabrique_jointures($boucle, $res, $cond, $desc, $nom, $col); |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | /** |
@@ -154,73 +154,73 @@ discard block |
||
| 154 | 154 | * Alias de la table de jointure (Lx) |
| 155 | 155 | */ |
| 156 | 156 | function fabrique_jointures(&$boucle, $res, $cond = false, $desc = array(), $nom = '', $col = '', $echap = true) { |
| 157 | - static $num = array(); |
|
| 158 | - $id_table = ""; |
|
| 159 | - $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | - foreach ($res as $cle => $r) { |
|
| 161 | - list($d, $a, $j) = $r; |
|
| 162 | - if (!$id_table) { |
|
| 163 | - $id_table = $d; |
|
| 164 | - } |
|
| 165 | - $n = ++$cpt; |
|
| 166 | - if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | - list($j1, $j2, $obj, $type) = $j; |
|
| 168 | - // trouver de quel cote est (id_objet,objet) |
|
| 169 | - if ($j1 == "id_$obj") { |
|
| 170 | - $obj = "$id_table.$obj"; |
|
| 171 | - } else { |
|
| 172 | - $obj = "L$n.$obj"; |
|
| 173 | - } |
|
| 174 | - // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 175 | - // en cas d'optimisation |
|
| 176 | - //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 177 | - $boucle->join["L$n"] = |
|
| 178 | - $echap ? |
|
| 179 | - array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 180 | - : |
|
| 181 | - array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 182 | - } else { |
|
| 183 | - $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 184 | - } |
|
| 185 | - $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - |
|
| 189 | - // pas besoin de group by |
|
| 190 | - // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 191 | - // si une seule jointure et sur une table avec primary key formee |
|
| 192 | - // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 193 | - // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 194 | - |
|
| 195 | - if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 196 | - $pk = nogroupby_if($desc, $a[1], $col); |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - // pas de group by |
|
| 200 | - // si une seule jointure |
|
| 201 | - // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 202 | - if (!$pk |
|
| 203 | - and (count($boucle->from) == 2) |
|
| 204 | - and isset($a[1]['key']['PRIMARY KEY']) |
|
| 205 | - and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 206 | - ) { |
|
| 207 | - $pk = true; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 211 | - $groups = liste_champs_jointures($nom, $desc, true); |
|
| 212 | - if (!$pk) { |
|
| 213 | - foreach ($groups as $id_prim) { |
|
| 214 | - $id_field = $nom . '.' . $id_prim; |
|
| 215 | - if (!in_array($id_field, $boucle->group)) { |
|
| 216 | - $boucle->group[] = $id_field; |
|
| 217 | - } |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - |
|
| 221 | - $boucle->modificateur['lien'] = true; |
|
| 222 | - |
|
| 223 | - return "L$n"; |
|
| 157 | + static $num = array(); |
|
| 158 | + $id_table = ""; |
|
| 159 | + $cpt = &$num[$boucle->descr['nom']][$boucle->descr['gram']][$boucle->id_boucle]; |
|
| 160 | + foreach ($res as $cle => $r) { |
|
| 161 | + list($d, $a, $j) = $r; |
|
| 162 | + if (!$id_table) { |
|
| 163 | + $id_table = $d; |
|
| 164 | + } |
|
| 165 | + $n = ++$cpt; |
|
| 166 | + if (is_array($j)) { // c'est un lien sur un champ du type id_objet,objet,'article' |
|
| 167 | + list($j1, $j2, $obj, $type) = $j; |
|
| 168 | + // trouver de quel cote est (id_objet,objet) |
|
| 169 | + if ($j1 == "id_$obj") { |
|
| 170 | + $obj = "$id_table.$obj"; |
|
| 171 | + } else { |
|
| 172 | + $obj = "L$n.$obj"; |
|
| 173 | + } |
|
| 174 | + // le where complementaire est envoye dans la jointure pour pouvoir etre elimine avec la jointure |
|
| 175 | + // en cas d'optimisation |
|
| 176 | + //$boucle->where[] = array("'='","'$obj'","sql_quote('$type')"); |
|
| 177 | + $boucle->join["L$n"] = |
|
| 178 | + $echap ? |
|
| 179 | + array("'$id_table'", "'$j2'", "'$j1'", "'$obj='.sql_quote('$type')") |
|
| 180 | + : |
|
| 181 | + array($id_table, $j2, $j1, "$obj=" . sql_quote($type)); |
|
| 182 | + } else { |
|
| 183 | + $boucle->join["L$n"] = $echap ? array("'$id_table'", "'$j'") : array($id_table, $j); |
|
| 184 | + } |
|
| 185 | + $boucle->from[$id_table = "L$n"] = $a[0]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + |
|
| 189 | + // pas besoin de group by |
|
| 190 | + // (cf http://article.gmane.org/gmane.comp.web.spip.devel/30555) |
|
| 191 | + // si une seule jointure et sur une table avec primary key formee |
|
| 192 | + // de l'index principal et de l'index de jointure (non conditionnel! [6031]) |
|
| 193 | + // et operateur d'egalite (http://trac.rezo.net/trac/spip/ticket/477) |
|
| 194 | + |
|
| 195 | + if ($pk = (isset($a[1]) && (count($boucle->from) == 2) && !$cond)) { |
|
| 196 | + $pk = nogroupby_if($desc, $a[1], $col); |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + // pas de group by |
|
| 200 | + // si une seule jointure |
|
| 201 | + // et si l'index de jointure est une primary key a l'arrivee ! |
|
| 202 | + if (!$pk |
|
| 203 | + and (count($boucle->from) == 2) |
|
| 204 | + and isset($a[1]['key']['PRIMARY KEY']) |
|
| 205 | + and ($j == $a[1]['key']['PRIMARY KEY']) |
|
| 206 | + ) { |
|
| 207 | + $pk = true; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // la clause Group by est en conflit avec ORDER BY, a completer |
|
| 211 | + $groups = liste_champs_jointures($nom, $desc, true); |
|
| 212 | + if (!$pk) { |
|
| 213 | + foreach ($groups as $id_prim) { |
|
| 214 | + $id_field = $nom . '.' . $id_prim; |
|
| 215 | + if (!in_array($id_field, $boucle->group)) { |
|
| 216 | + $boucle->group[] = $id_field; |
|
| 217 | + } |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + |
|
| 221 | + $boucle->modificateur['lien'] = true; |
|
| 222 | + |
|
| 223 | + return "L$n"; |
|
| 224 | 224 | } |
| 225 | 225 | |
| 226 | 226 | /** |
@@ -235,16 +235,16 @@ discard block |
||
| 235 | 235 | * @return bool |
| 236 | 236 | */ |
| 237 | 237 | function nogroupby_if($depart, $arrivee, $col) { |
| 238 | - $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 239 | - if (!$pk) { |
|
| 240 | - return false; |
|
| 241 | - } |
|
| 242 | - $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 243 | - if (is_array($col)) { |
|
| 244 | - $col = implode(', *', $col); |
|
| 245 | - } // cas id_objet, objet |
|
| 246 | - return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 247 | - preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 238 | + $pk = $arrivee['key']['PRIMARY KEY']; |
|
| 239 | + if (!$pk) { |
|
| 240 | + return false; |
|
| 241 | + } |
|
| 242 | + $id_primary = $depart['key']['PRIMARY KEY']; |
|
| 243 | + if (is_array($col)) { |
|
| 244 | + $col = implode(', *', $col); |
|
| 245 | + } // cas id_objet, objet |
|
| 246 | + return (preg_match("/^$id_primary, *$col$/", $pk) or |
|
| 247 | + preg_match("/^$col, *$id_primary$/", $pk)); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -262,46 +262,46 @@ discard block |
||
| 262 | 262 | */ |
| 263 | 263 | function liste_champs_jointures($nom, $desc, $primary = false) { |
| 264 | 264 | |
| 265 | - static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 265 | + static $nojoin = array('idx', 'maj', 'date', 'statut'); |
|
| 266 | 266 | |
| 267 | - // si cle primaire demandee, la privilegier |
|
| 268 | - if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 269 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 270 | - } |
|
| 267 | + // si cle primaire demandee, la privilegier |
|
| 268 | + if ($primary && isset($desc['key']['PRIMARY KEY'])) { |
|
| 269 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 270 | + } |
|
| 271 | 271 | |
| 272 | - // les champs declares explicitement pour les jointures |
|
| 273 | - if (isset($desc['join'])) { |
|
| 274 | - return $desc['join']; |
|
| 275 | - } |
|
| 276 | - /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 272 | + // les champs declares explicitement pour les jointures |
|
| 273 | + if (isset($desc['join'])) { |
|
| 274 | + return $desc['join']; |
|
| 275 | + } |
|
| 276 | + /*elseif (isset($GLOBALS['tables_principales'][$nom]['join'])) return $GLOBALS['tables_principales'][$nom]['join']; |
|
| 277 | 277 | elseif (isset($GLOBALS['tables_auxiliaires'][$nom]['join'])) return $GLOBALS['tables_auxiliaires'][$nom]['join'];*/ |
| 278 | 278 | |
| 279 | - // si pas de cle, c'est fichu |
|
| 280 | - if (!isset($desc['key'])) { |
|
| 281 | - return array(); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - // si cle primaire |
|
| 285 | - if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 286 | - return split_key($desc['key']['PRIMARY KEY']); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // ici on se rabat sur les cles secondaires, |
|
| 290 | - // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 291 | - // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 292 | - // il faut declarer explicitement le champ 'join' de sa description |
|
| 293 | - |
|
| 294 | - $join = array(); |
|
| 295 | - foreach ($desc['key'] as $v) { |
|
| 296 | - $join = split_key($v, $join); |
|
| 297 | - } |
|
| 298 | - foreach ($join as $k) { |
|
| 299 | - if (in_array($k, $nojoin)) { |
|
| 300 | - unset($join[$k]); |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return $join; |
|
| 279 | + // si pas de cle, c'est fichu |
|
| 280 | + if (!isset($desc['key'])) { |
|
| 281 | + return array(); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + // si cle primaire |
|
| 285 | + if (isset($desc['key']['PRIMARY KEY'])) { |
|
| 286 | + return split_key($desc['key']['PRIMARY KEY']); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // ici on se rabat sur les cles secondaires, |
|
| 290 | + // en eliminant celles qui sont pas pertinentes (idx, maj) |
|
| 291 | + // si jamais le resultat n'est pas pertinent pour une table donnee, |
|
| 292 | + // il faut declarer explicitement le champ 'join' de sa description |
|
| 293 | + |
|
| 294 | + $join = array(); |
|
| 295 | + foreach ($desc['key'] as $v) { |
|
| 296 | + $join = split_key($v, $join); |
|
| 297 | + } |
|
| 298 | + foreach ($join as $k) { |
|
| 299 | + if (in_array($k, $nojoin)) { |
|
| 300 | + unset($join[$k]); |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return $join; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -312,14 +312,14 @@ discard block |
||
| 312 | 312 | * @return array |
| 313 | 313 | */ |
| 314 | 314 | function split_key($v, $join = array()) { |
| 315 | - foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 316 | - if (strpos($k, '(') !== false) { |
|
| 317 | - $k = explode('(', $k); |
|
| 318 | - $k = trim(reset($k)); |
|
| 319 | - } |
|
| 320 | - $join[$k] = $k; |
|
| 321 | - } |
|
| 322 | - return $join; |
|
| 315 | + foreach (preg_split('/,\s*/', $v) as $k) { |
|
| 316 | + if (strpos($k, '(') !== false) { |
|
| 317 | + $k = explode('(', $k); |
|
| 318 | + $k = trim(reset($k)); |
|
| 319 | + } |
|
| 320 | + $join[$k] = $k; |
|
| 321 | + } |
|
| 322 | + return $join; |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | /** |
@@ -342,126 +342,126 @@ discard block |
||
| 342 | 342 | * @return array |
| 343 | 343 | */ |
| 344 | 344 | function calculer_chaine_jointures( |
| 345 | - &$boucle, |
|
| 346 | - $depart, |
|
| 347 | - $arrivee, |
|
| 348 | - $vu = array(), |
|
| 349 | - $milieu_exclus = array(), |
|
| 350 | - $max_liens = 5 |
|
| 345 | + &$boucle, |
|
| 346 | + $depart, |
|
| 347 | + $arrivee, |
|
| 348 | + $vu = array(), |
|
| 349 | + $milieu_exclus = array(), |
|
| 350 | + $max_liens = 5 |
|
| 351 | 351 | ) { |
| 352 | - static $trouver_table; |
|
| 353 | - if (!$trouver_table) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (is_string($milieu_exclus)) { |
|
| 358 | - $milieu_exclus = array($milieu_exclus); |
|
| 359 | - } |
|
| 360 | - // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 361 | - // faire une jointure sur objet tout seul n'a pas de sens |
|
| 362 | - if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 363 | - $milieu_exclus[] = 'objet'; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - list($dnom, $ddesc) = $depart; |
|
| 367 | - list($anom, $adesc) = $arrivee; |
|
| 368 | - if (!count($vu)) { |
|
| 369 | - $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 370 | - $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - $akeys = array(); |
|
| 374 | - foreach ($adesc['key'] as $k) { |
|
| 375 | - // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 376 | - $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - // enlever les cles d'arrivee exclues par l'appel |
|
| 380 | - $akeys = array_diff($akeys, $milieu_exclus); |
|
| 381 | - |
|
| 382 | - // cles candidates au depart |
|
| 383 | - $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 384 | - // enlever les cles dde depart exclues par l'appel |
|
| 385 | - $keys = array_diff($keys, $milieu_exclus); |
|
| 386 | - |
|
| 387 | - $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 388 | - |
|
| 389 | - if ($v) { |
|
| 390 | - return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 394 | - if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 395 | - // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 396 | - // id_objet,objet |
|
| 397 | - // si oui on la prend |
|
| 398 | - foreach ($akeys as $key) { |
|
| 399 | - $v = decompose_champ_id_objet($key); |
|
| 400 | - if (is_array($v)) { |
|
| 401 | - $objet = array_shift($v); // objet,'article' |
|
| 402 | - array_unshift($v, $key); // id_article,objet,'article' |
|
| 403 | - array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 404 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } else { |
|
| 408 | - // regarder si l'une des cles de depart peut se decomposer en |
|
| 409 | - // id_objet,objet a l'arrivee |
|
| 410 | - // si oui on la prend |
|
| 411 | - foreach ($keys as $key) { |
|
| 412 | - if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 413 | - if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 414 | - $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 415 | - array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 416 | - return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 417 | - } |
|
| 418 | - } |
|
| 419 | - } |
|
| 420 | - } |
|
| 421 | - // si l'on voulait une jointure direct, c'est rate ! |
|
| 422 | - if ($max_liens <= 1) { |
|
| 423 | - return array(); |
|
| 424 | - } |
|
| 425 | - |
|
| 426 | - // sinon essayer de passer par une autre table |
|
| 427 | - $new = $vu; |
|
| 428 | - foreach ($boucle->jointures as $v) { |
|
| 429 | - if ($v |
|
| 430 | - and !in_array($v, $vu) |
|
| 431 | - and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 432 | - and !in_array($def['table_sql'], $vu) |
|
| 433 | - ) { |
|
| 434 | - // ne pas tester les cles qui sont exclues a l'appel |
|
| 435 | - // ie la cle de la jointure precedente |
|
| 436 | - $test_cles = $milieu_exclus; |
|
| 437 | - $new[] = $v; |
|
| 438 | - $max_iter = 50; // securite |
|
| 439 | - while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 440 | - $test_cles, 1)) |
|
| 441 | - and $max_iter--) { |
|
| 442 | - $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 443 | - $milieu = end($jointure_directe_possible); |
|
| 444 | - $exclure_fin = $milieu_exclus; |
|
| 445 | - if (is_string($milieu)) { |
|
| 446 | - $exclure_fin[] = $milieu; |
|
| 447 | - $test_cles[] = $milieu; |
|
| 448 | - } else { |
|
| 449 | - $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 450 | - $test_cles = array_merge($test_cles, $milieu); |
|
| 451 | - } |
|
| 452 | - // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 453 | - // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 454 | - $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 455 | - if ($r) { |
|
| 456 | - array_unshift($r, $jointure_directe_possible); |
|
| 457 | - |
|
| 458 | - return $r; |
|
| 459 | - } |
|
| 460 | - } |
|
| 461 | - } |
|
| 462 | - } |
|
| 463 | - |
|
| 464 | - return array(); |
|
| 352 | + static $trouver_table; |
|
| 353 | + if (!$trouver_table) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (is_string($milieu_exclus)) { |
|
| 358 | + $milieu_exclus = array($milieu_exclus); |
|
| 359 | + } |
|
| 360 | + // quand on a exclus id_objet comme cle de jointure, il faut aussi exclure objet |
|
| 361 | + // faire une jointure sur objet tout seul n'a pas de sens |
|
| 362 | + if (in_array('id_objet', $milieu_exclus) and !in_array('objet', $milieu_exclus)) { |
|
| 363 | + $milieu_exclus[] = 'objet'; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + list($dnom, $ddesc) = $depart; |
|
| 367 | + list($anom, $adesc) = $arrivee; |
|
| 368 | + if (!count($vu)) { |
|
| 369 | + $vu[] = $dnom; // ne pas oublier la table de depart |
|
| 370 | + $vu[] = $anom; // ne pas oublier la table d'arrivee |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + $akeys = array(); |
|
| 374 | + foreach ($adesc['key'] as $k) { |
|
| 375 | + // respecter l'ordre de $adesc['key'] pour ne pas avoir id_trad en premier entre autres... |
|
| 376 | + $akeys = array_merge($akeys, preg_split('/,\s*/', $k)); |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + // enlever les cles d'arrivee exclues par l'appel |
|
| 380 | + $akeys = array_diff($akeys, $milieu_exclus); |
|
| 381 | + |
|
| 382 | + // cles candidates au depart |
|
| 383 | + $keys = liste_champs_jointures($dnom, $ddesc); |
|
| 384 | + // enlever les cles dde depart exclues par l'appel |
|
| 385 | + $keys = array_diff($keys, $milieu_exclus); |
|
| 386 | + |
|
| 387 | + $v = !$keys ? false : array_intersect(array_values($keys), $akeys); |
|
| 388 | + |
|
| 389 | + if ($v) { |
|
| 390 | + return array(array($dnom, array($adesc['table'], $adesc), array_shift($v))); |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + // regarder si l'on a (id_objet,objet) au depart et si on peut le mapper sur un id_xx |
|
| 394 | + if (count(array_intersect(array('id_objet', 'objet'), $keys)) == 2) { |
|
| 395 | + // regarder si l'une des cles d'arrivee peut se decomposer en |
|
| 396 | + // id_objet,objet |
|
| 397 | + // si oui on la prend |
|
| 398 | + foreach ($akeys as $key) { |
|
| 399 | + $v = decompose_champ_id_objet($key); |
|
| 400 | + if (is_array($v)) { |
|
| 401 | + $objet = array_shift($v); // objet,'article' |
|
| 402 | + array_unshift($v, $key); // id_article,objet,'article' |
|
| 403 | + array_unshift($v, $objet); // id_objet,id_article,objet,'article' |
|
| 404 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } else { |
|
| 408 | + // regarder si l'une des cles de depart peut se decomposer en |
|
| 409 | + // id_objet,objet a l'arrivee |
|
| 410 | + // si oui on la prend |
|
| 411 | + foreach ($keys as $key) { |
|
| 412 | + if (count($v = trouver_champs_decomposes($key, $adesc)) > 1) { |
|
| 413 | + if (count($v) == count(array_intersect($v, $akeys))) { |
|
| 414 | + $v = decompose_champ_id_objet($key); // id_objet,objet,'article' |
|
| 415 | + array_unshift($v, $key); // id_article,id_objet,objet,'article' |
|
| 416 | + return array(array($dnom, array($adesc['table'], $adesc), $v)); |
|
| 417 | + } |
|
| 418 | + } |
|
| 419 | + } |
|
| 420 | + } |
|
| 421 | + // si l'on voulait une jointure direct, c'est rate ! |
|
| 422 | + if ($max_liens <= 1) { |
|
| 423 | + return array(); |
|
| 424 | + } |
|
| 425 | + |
|
| 426 | + // sinon essayer de passer par une autre table |
|
| 427 | + $new = $vu; |
|
| 428 | + foreach ($boucle->jointures as $v) { |
|
| 429 | + if ($v |
|
| 430 | + and !in_array($v, $vu) |
|
| 431 | + and $def = $trouver_table($v, $boucle->sql_serveur) |
|
| 432 | + and !in_array($def['table_sql'], $vu) |
|
| 433 | + ) { |
|
| 434 | + // ne pas tester les cles qui sont exclues a l'appel |
|
| 435 | + // ie la cle de la jointure precedente |
|
| 436 | + $test_cles = $milieu_exclus; |
|
| 437 | + $new[] = $v; |
|
| 438 | + $max_iter = 50; // securite |
|
| 439 | + while (count($jointure_directe_possible = calculer_chaine_jointures($boucle, $depart, array($v, $def), $vu, |
|
| 440 | + $test_cles, 1)) |
|
| 441 | + and $max_iter--) { |
|
| 442 | + $jointure_directe_possible = reset($jointure_directe_possible); |
|
| 443 | + $milieu = end($jointure_directe_possible); |
|
| 444 | + $exclure_fin = $milieu_exclus; |
|
| 445 | + if (is_string($milieu)) { |
|
| 446 | + $exclure_fin[] = $milieu; |
|
| 447 | + $test_cles[] = $milieu; |
|
| 448 | + } else { |
|
| 449 | + $exclure_fin = array_merge($exclure_fin, $milieu); |
|
| 450 | + $test_cles = array_merge($test_cles, $milieu); |
|
| 451 | + } |
|
| 452 | + // essayer de rejoindre l'arrivee a partir de cette etape intermediaire |
|
| 453 | + // sans repasser par la meme cle milieu, ni une cle deja vue ! |
|
| 454 | + $r = calculer_chaine_jointures($boucle, array($v, $def), $arrivee, $new, $exclure_fin, $max_liens - 1); |
|
| 455 | + if ($r) { |
|
| 456 | + array_unshift($r, $jointure_directe_possible); |
|
| 457 | + |
|
| 458 | + return $r; |
|
| 459 | + } |
|
| 460 | + } |
|
| 461 | + } |
|
| 462 | + } |
|
| 463 | + |
|
| 464 | + return array(); |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -472,18 +472,18 @@ discard block |
||
| 472 | 472 | * @return array |
| 473 | 473 | */ |
| 474 | 474 | function trouver_cles_table($keys) { |
| 475 | - $res = array(); |
|
| 476 | - foreach ($keys as $v) { |
|
| 477 | - if (!strpos($v, ",")) { |
|
| 478 | - $res[$v] = 1; |
|
| 479 | - } else { |
|
| 480 | - foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 481 | - $res[$k] = 1; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - return array_keys($res); |
|
| 475 | + $res = array(); |
|
| 476 | + foreach ($keys as $v) { |
|
| 477 | + if (!strpos($v, ",")) { |
|
| 478 | + $res[$v] = 1; |
|
| 479 | + } else { |
|
| 480 | + foreach (preg_split("/\s*,\s*/", $v) as $k) { |
|
| 481 | + $res[$k] = 1; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + return array_keys($res); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -510,33 +510,33 @@ discard block |
||
| 510 | 510 | * - 'alias' : alias utilisé pour la table (si pertinent. ie: avec `$boucle->from` transmis par exemple) |
| 511 | 511 | */ |
| 512 | 512 | function chercher_champ_dans_tables($cle, $tables, $connect, $checkarrivee = false) { |
| 513 | - static $trouver_table = ''; |
|
| 514 | - if (!$trouver_table) { |
|
| 515 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 516 | - } |
|
| 517 | - |
|
| 518 | - if (!is_array($cle)) { |
|
| 519 | - $cle = array($cle); |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - foreach ($tables as $k => $table) { |
|
| 523 | - if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 524 | - if (isset($desc['field']) |
|
| 525 | - // verifier que toutes les cles cherchees sont la |
|
| 526 | - and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 527 | - // si on sait ou on veut arriver, il faut que ca colle |
|
| 528 | - and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 529 | - ) { |
|
| 530 | - return array( |
|
| 531 | - 'desc' => $desc, |
|
| 532 | - 'table' => $desc['table'], |
|
| 533 | - 'alias' => $k, |
|
| 534 | - ); |
|
| 535 | - } |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - |
|
| 539 | - return false; |
|
| 513 | + static $trouver_table = ''; |
|
| 514 | + if (!$trouver_table) { |
|
| 515 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 516 | + } |
|
| 517 | + |
|
| 518 | + if (!is_array($cle)) { |
|
| 519 | + $cle = array($cle); |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + foreach ($tables as $k => $table) { |
|
| 523 | + if ($table && $desc = $trouver_table($table, $connect)) { |
|
| 524 | + if (isset($desc['field']) |
|
| 525 | + // verifier que toutes les cles cherchees sont la |
|
| 526 | + and (count(array_intersect($cle, array_keys($desc['field']))) == count($cle)) |
|
| 527 | + // si on sait ou on veut arriver, il faut que ca colle |
|
| 528 | + and ($checkarrivee == false || $checkarrivee == $desc['table']) |
|
| 529 | + ) { |
|
| 530 | + return array( |
|
| 531 | + 'desc' => $desc, |
|
| 532 | + 'table' => $desc['table'], |
|
| 533 | + 'alias' => $k, |
|
| 534 | + ); |
|
| 535 | + } |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + |
|
| 539 | + return false; |
|
| 540 | 540 | } |
| 541 | 541 | |
| 542 | 542 | /** |
@@ -562,52 +562,52 @@ discard block |
||
| 562 | 562 | */ |
| 563 | 563 | function trouver_champ_exterieur($cle, $joints, &$boucle, $checkarrivee = false) { |
| 564 | 564 | |
| 565 | - // support de la recherche multi champ : |
|
| 566 | - // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 567 | - // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 568 | - // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 569 | - if (!is_array($cle)) { |
|
| 570 | - $cle = array($cle); |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 574 | - return array($infos['table'], $infos['desc'], $cle); |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - // au premier coup, on essaye de decomposer, si possible |
|
| 578 | - if (count($cle) == 1 |
|
| 579 | - and $c = reset($cle) |
|
| 580 | - and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 581 | - ) { |
|
| 582 | - |
|
| 583 | - $desc = $boucle->show; |
|
| 584 | - |
|
| 585 | - // cas 1 : la cle id_xx est dans la table de depart |
|
| 586 | - // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 587 | - if (isset($desc['field'][$c])) { |
|
| 588 | - $cle = array(); |
|
| 589 | - $cle[] = array_shift($decompose); // id_objet |
|
| 590 | - $cle[] = array_shift($decompose); // objet |
|
| 591 | - return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 592 | - } |
|
| 593 | - // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 594 | - // -> il faut trouver une cle de depart zzz telle que |
|
| 595 | - // id_objet,objet,zzz soit a l'arrivee |
|
| 596 | - else { |
|
| 597 | - $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 598 | - foreach ($depart as $d) { |
|
| 599 | - $cle = array(); |
|
| 600 | - $cle[] = array_shift($decompose); // id_objet |
|
| 601 | - $cle[] = array_shift($decompose); // objet |
|
| 602 | - $cle[] = $d; |
|
| 603 | - if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 604 | - return $ext; |
|
| 605 | - } |
|
| 606 | - } |
|
| 607 | - } |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - return ""; |
|
| 565 | + // support de la recherche multi champ : |
|
| 566 | + // si en seconde etape on a decompose le champ id_xx en id_objet,objet |
|
| 567 | + // on reentre ici soit en cherchant une table les 2 champs id_objet,objet |
|
| 568 | + // soit une table avec les 3 champs id_xx, id_objet, objet |
|
| 569 | + if (!is_array($cle)) { |
|
| 570 | + $cle = array($cle); |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if ($infos = chercher_champ_dans_tables($cle, $joints, $boucle->sql_serveur, $checkarrivee)) { |
|
| 574 | + return array($infos['table'], $infos['desc'], $cle); |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + // au premier coup, on essaye de decomposer, si possible |
|
| 578 | + if (count($cle) == 1 |
|
| 579 | + and $c = reset($cle) |
|
| 580 | + and is_array($decompose = decompose_champ_id_objet($c)) |
|
| 581 | + ) { |
|
| 582 | + |
|
| 583 | + $desc = $boucle->show; |
|
| 584 | + |
|
| 585 | + // cas 1 : la cle id_xx est dans la table de depart |
|
| 586 | + // -> on cherche uniquement id_objet,objet a l'arrivee |
|
| 587 | + if (isset($desc['field'][$c])) { |
|
| 588 | + $cle = array(); |
|
| 589 | + $cle[] = array_shift($decompose); // id_objet |
|
| 590 | + $cle[] = array_shift($decompose); // objet |
|
| 591 | + return trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee); |
|
| 592 | + } |
|
| 593 | + // cas 2 : la cle id_xx n'est pas dans la table de depart |
|
| 594 | + // -> il faut trouver une cle de depart zzz telle que |
|
| 595 | + // id_objet,objet,zzz soit a l'arrivee |
|
| 596 | + else { |
|
| 597 | + $depart = liste_champs_jointures((isset($desc['table']) ? $desc['table'] : ''), $desc); |
|
| 598 | + foreach ($depart as $d) { |
|
| 599 | + $cle = array(); |
|
| 600 | + $cle[] = array_shift($decompose); // id_objet |
|
| 601 | + $cle[] = array_shift($decompose); // objet |
|
| 602 | + $cle[] = $d; |
|
| 603 | + if ($ext = trouver_champ_exterieur($cle, $joints, $boucle, $checkarrivee)) { |
|
| 604 | + return $ext; |
|
| 605 | + } |
|
| 606 | + } |
|
| 607 | + } |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + return ""; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -639,21 +639,21 @@ discard block |
||
| 639 | 639 | * @return string |
| 640 | 640 | */ |
| 641 | 641 | function trouver_jointure_champ($champ, &$boucle, $jointures = false, $cond = false, $checkarrivee = false) { |
| 642 | - if ($jointures === false) { |
|
| 643 | - $jointures = $boucle->jointures; |
|
| 644 | - } |
|
| 645 | - // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 646 | - // mais pas poour construire la jointure ensuite |
|
| 647 | - $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 648 | - if ($arrivee) { |
|
| 649 | - $desc = $boucle->show; |
|
| 650 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 651 | - $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 652 | - if ($cle) { |
|
| 653 | - return $cle; |
|
| 654 | - } |
|
| 655 | - } |
|
| 656 | - spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 657 | - |
|
| 658 | - return ''; |
|
| 642 | + if ($jointures === false) { |
|
| 643 | + $jointures = $boucle->jointures; |
|
| 644 | + } |
|
| 645 | + // TODO : aberration, on utilise $jointures pour trouver le champ |
|
| 646 | + // mais pas poour construire la jointure ensuite |
|
| 647 | + $arrivee = trouver_champ_exterieur($champ, $jointures, $boucle, $checkarrivee); |
|
| 648 | + if ($arrivee) { |
|
| 649 | + $desc = $boucle->show; |
|
| 650 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 651 | + $cle = calculer_jointure($boucle, array($desc['id_table'], $desc), $arrivee, '', $cond); |
|
| 652 | + if ($cle) { |
|
| 653 | + return $cle; |
|
| 654 | + } |
|
| 655 | + } |
|
| 656 | + spip_log("trouver_jointure_champ: $champ inconnu"); |
|
| 657 | + |
|
| 658 | + return ''; |
|
| 659 | 659 | } |
@@ -75,6 +75,9 @@ |
||
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | +/** |
|
| 79 | + * @param string $nom |
|
| 80 | + */ |
|
| 78 | 81 | function phraser_logo_faux_filtres($nom) { |
| 79 | 82 | switch ($nom) { |
| 80 | 83 | case 'top': |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | // Les fonctions de ce fichier sont appelees en certains points |
@@ -25,135 +25,135 @@ discard block |
||
| 25 | 25 | // -> http://www.spip.net/fr_article901.html |
| 26 | 26 | |
| 27 | 27 | function phraser_vieux_logos(&$p) { |
| 28 | - if ($p->param[0][0]) { |
|
| 29 | - $args = array(''); |
|
| 30 | - } else { |
|
| 31 | - $args = array_shift($p->param); |
|
| 32 | - } |
|
| 33 | - |
|
| 34 | - foreach ($p->param as $couple) { |
|
| 35 | - $nom = trim($couple[0]); |
|
| 36 | - if ($nom == '') { |
|
| 37 | - array_shift($p->param); |
|
| 38 | - break; |
|
| 39 | - } |
|
| 40 | - $r = phraser_logo_faux_filtres($nom); |
|
| 41 | - if ($r === 0) { |
|
| 42 | - $c = new Texte; |
|
| 43 | - $c->texte = $nom; |
|
| 44 | - $args[] = array($c); |
|
| 45 | - array_shift($p->param); |
|
| 46 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | - } elseif ($r === 2) { |
|
| 48 | - $p->etoile = '**'; |
|
| 49 | - array_shift($p->param); |
|
| 50 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | - } elseif ($r === 1) { |
|
| 52 | - array_shift($p->param); |
|
| 53 | - $p->etoile = '*'; |
|
| 54 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | - |
|
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | - $champ = new Champ(); |
|
| 58 | - $champ->nom_boucle = $m[2]; |
|
| 59 | - $champ->nom_champ = $m[3]; |
|
| 60 | - $champ->etoile = $m[5]; |
|
| 61 | - $champ = array($champ); |
|
| 62 | - if ($m[6]) { |
|
| 63 | - $r = new Texte; |
|
| 64 | - $r->texte = $m[6]; |
|
| 65 | - $champ[] = $r; |
|
| 66 | - } |
|
| 67 | - $args[] = $champ; |
|
| 68 | - array_shift($p->param); |
|
| 69 | - spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | - |
|
| 71 | - } // le cas else est la seule incompatibilite |
|
| 72 | - |
|
| 73 | - } |
|
| 74 | - array_unshift($p->param, $args); |
|
| 28 | + if ($p->param[0][0]) { |
|
| 29 | + $args = array(''); |
|
| 30 | + } else { |
|
| 31 | + $args = array_shift($p->param); |
|
| 32 | + } |
|
| 33 | + |
|
| 34 | + foreach ($p->param as $couple) { |
|
| 35 | + $nom = trim($couple[0]); |
|
| 36 | + if ($nom == '') { |
|
| 37 | + array_shift($p->param); |
|
| 38 | + break; |
|
| 39 | + } |
|
| 40 | + $r = phraser_logo_faux_filtres($nom); |
|
| 41 | + if ($r === 0) { |
|
| 42 | + $c = new Texte; |
|
| 43 | + $c->texte = $nom; |
|
| 44 | + $args[] = array($c); |
|
| 45 | + array_shift($p->param); |
|
| 46 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 47 | + } elseif ($r === 2) { |
|
| 48 | + $p->etoile = '**'; |
|
| 49 | + array_shift($p->param); |
|
| 50 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 51 | + } elseif ($r === 1) { |
|
| 52 | + array_shift($p->param); |
|
| 53 | + $p->etoile = '*'; |
|
| 54 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 55 | + |
|
| 56 | + } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 57 | + $champ = new Champ(); |
|
| 58 | + $champ->nom_boucle = $m[2]; |
|
| 59 | + $champ->nom_champ = $m[3]; |
|
| 60 | + $champ->etoile = $m[5]; |
|
| 61 | + $champ = array($champ); |
|
| 62 | + if ($m[6]) { |
|
| 63 | + $r = new Texte; |
|
| 64 | + $r->texte = $m[6]; |
|
| 65 | + $champ[] = $r; |
|
| 66 | + } |
|
| 67 | + $args[] = $champ; |
|
| 68 | + array_shift($p->param); |
|
| 69 | + spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
|
| 70 | + |
|
| 71 | + } // le cas else est la seule incompatibilite |
|
| 72 | + |
|
| 73 | + } |
|
| 74 | + array_unshift($p->param, $args); |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | |
| 78 | 78 | function phraser_logo_faux_filtres($nom) { |
| 79 | - switch ($nom) { |
|
| 80 | - case 'top': |
|
| 81 | - case 'left': |
|
| 82 | - case 'right': |
|
| 83 | - case 'center': |
|
| 84 | - case 'bottom': |
|
| 85 | - return 0; |
|
| 86 | - case 'lien': |
|
| 87 | - return 1; |
|
| 88 | - case 'fichier': |
|
| 89 | - return 2; |
|
| 90 | - default: |
|
| 91 | - return $nom; |
|
| 92 | - } |
|
| 79 | + switch ($nom) { |
|
| 80 | + case 'top': |
|
| 81 | + case 'left': |
|
| 82 | + case 'right': |
|
| 83 | + case 'center': |
|
| 84 | + case 'bottom': |
|
| 85 | + return 0; |
|
| 86 | + case 'lien': |
|
| 87 | + return 1; |
|
| 88 | + case 'fichier': |
|
| 89 | + return 2; |
|
| 90 | + default: |
|
| 91 | + return $nom; |
|
| 92 | + } |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | |
| 96 | 96 | // La balise embed_document est a present le modele emb |
| 97 | 97 | |
| 98 | 98 | function phraser_vieux_emb(&$p) { |
| 99 | - if (!is_array($p->param)) { |
|
| 100 | - $p->param = array(); |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - // Produire le premier argument {emb} |
|
| 104 | - $texte = new Texte; |
|
| 105 | - $texte->texte = 'emb'; |
|
| 106 | - $param = array('', array($texte)); |
|
| 107 | - |
|
| 108 | - // Transformer les filtres en arguments |
|
| 109 | - for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | - if ($p->param[$i][0]) { |
|
| 111 | - if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | - break; |
|
| 113 | - }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | - $texte = new Texte; |
|
| 115 | - $texte->texte = $p->param[$i][0]; |
|
| 116 | - $param[] = array($texte); |
|
| 117 | - } |
|
| 118 | - array_shift($p->param); |
|
| 119 | - } |
|
| 120 | - array_unshift($p->param, $param); |
|
| 121 | - spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | - $p->nom_champ = 'MODELE'; |
|
| 99 | + if (!is_array($p->param)) { |
|
| 100 | + $p->param = array(); |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + // Produire le premier argument {emb} |
|
| 104 | + $texte = new Texte; |
|
| 105 | + $texte->texte = 'emb'; |
|
| 106 | + $param = array('', array($texte)); |
|
| 107 | + |
|
| 108 | + // Transformer les filtres en arguments |
|
| 109 | + for ($i = 0; $i < count($p->param); $i++) { |
|
| 110 | + if ($p->param[$i][0]) { |
|
| 111 | + if (!strstr($p->param[$i][0], '=')) { |
|
| 112 | + break; |
|
| 113 | + }# on a rencontre un vrai filtre, c'est fini |
|
| 114 | + $texte = new Texte; |
|
| 115 | + $texte->texte = $p->param[$i][0]; |
|
| 116 | + $param[] = array($texte); |
|
| 117 | + } |
|
| 118 | + array_shift($p->param); |
|
| 119 | + } |
|
| 120 | + array_unshift($p->param, $param); |
|
| 121 | + spip_log('balise EMBED_DOCUMENT obsolete', 'vieilles_defs'); |
|
| 122 | + $p->nom_champ = 'MODELE'; |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // Vieux formulaire de recherch |
| 126 | 126 | |
| 127 | 127 | function phraser_vieux_recherche($p) { |
| 128 | - if ($p->param[0][0]) { |
|
| 129 | - $c = new Texte; |
|
| 130 | - $c->texte = $p->param[0][0]; |
|
| 131 | - $p->param[0][1] = array($c); |
|
| 132 | - $p->param[0][0] = ''; |
|
| 133 | - $p->fonctions = array(); |
|
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | - } |
|
| 128 | + if ($p->param[0][0]) { |
|
| 129 | + $c = new Texte; |
|
| 130 | + $c->texte = $p->param[0][0]; |
|
| 131 | + $p->param[0][1] = array($c); |
|
| 132 | + $p->param[0][0] = ''; |
|
| 133 | + $p->fonctions = array(); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | // Gerer la notation [(#EXPOSER|on,off)] |
| 139 | 139 | function phraser_vieux_exposer($p) { |
| 140 | - if ($a = $p->fonctions) { |
|
| 141 | - preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | - $args = array(); |
|
| 143 | - if ($regs[1]) { |
|
| 144 | - $a = new Texte; |
|
| 145 | - $a->texte = $regs[1]; |
|
| 146 | - $args = array('', array($a)); |
|
| 147 | - if ($regs[3]) { |
|
| 148 | - $a = new Texte; |
|
| 149 | - $a->texte = $regs[3]; |
|
| 150 | - $args[] = array($a); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - $p->param[0] = $args; |
|
| 154 | - $p->fonctions = array(); |
|
| 155 | - $p->nom_champ = 'EXPOSE'; |
|
| 156 | - } |
|
| 140 | + if ($a = $p->fonctions) { |
|
| 141 | + preg_match("#([^,]*)(,(.*))?#", $a[0][0], $regs); |
|
| 142 | + $args = array(); |
|
| 143 | + if ($regs[1]) { |
|
| 144 | + $a = new Texte; |
|
| 145 | + $a->texte = $regs[1]; |
|
| 146 | + $args = array('', array($a)); |
|
| 147 | + if ($regs[3]) { |
|
| 148 | + $a = new Texte; |
|
| 149 | + $a->texte = $regs[3]; |
|
| 150 | + $args[] = array($a); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + $p->param[0] = $args; |
|
| 154 | + $p->fonctions = array(); |
|
| 155 | + $p->nom_champ = 'EXPOSE'; |
|
| 156 | + } |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | function phraser_vieux_modele($p) { normaliser_args_inclumodel($p); } |
@@ -161,55 +161,55 @@ discard block |
||
| 161 | 161 | function phraser_vieux_inclu($p) { normaliser_args_inclumodel($p); } |
| 162 | 162 | |
| 163 | 163 | function normaliser_args_inclumodel($p) { |
| 164 | - $params = $p->param; |
|
| 165 | - if (!$params) { |
|
| 166 | - return; |
|
| 167 | - } |
|
| 168 | - $args = $params[0]; |
|
| 169 | - if ($args[0]) { |
|
| 170 | - return; |
|
| 171 | - } // filtre immediat |
|
| 172 | - array_shift($p->param); |
|
| 173 | - foreach ($p->param as $l) { |
|
| 174 | - if (!array_shift($l)) { |
|
| 175 | - $args = array_merge($args, $l); |
|
| 176 | - array_shift($p->param); |
|
| 177 | - } else { |
|
| 178 | - break; |
|
| 179 | - } // filtre |
|
| 180 | - } |
|
| 181 | - array_unshift($p->param, $args); |
|
| 164 | + $params = $p->param; |
|
| 165 | + if (!$params) { |
|
| 166 | + return; |
|
| 167 | + } |
|
| 168 | + $args = $params[0]; |
|
| 169 | + if ($args[0]) { |
|
| 170 | + return; |
|
| 171 | + } // filtre immediat |
|
| 172 | + array_shift($p->param); |
|
| 173 | + foreach ($p->param as $l) { |
|
| 174 | + if (!array_shift($l)) { |
|
| 175 | + $args = array_merge($args, $l); |
|
| 176 | + array_shift($p->param); |
|
| 177 | + } else { |
|
| 178 | + break; |
|
| 179 | + } // filtre |
|
| 180 | + } |
|
| 181 | + array_unshift($p->param, $args); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | function normaliser_inclure($champ) { |
| 185 | - normaliser_args_inclumodel($champ); |
|
| 186 | - $l = $champ->param[0]; |
|
| 187 | - if (is_array($l) and !$l[0]) { |
|
| 188 | - foreach ($l as $k => $p) { |
|
| 189 | - if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | - $p[0]->texte = trim($p[0]->texte); |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - foreach ($l as $k => $p) { |
|
| 194 | - if (!$p or $p[0]->type != 'texte' or |
|
| 195 | - !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | - ) { |
|
| 197 | - continue; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ($r[1]) { |
|
| 201 | - $p[0]->texte = $r[1]; |
|
| 202 | - } else { |
|
| 203 | - unset($p[0]); |
|
| 204 | - } |
|
| 205 | - $champ->texte = $p; |
|
| 206 | - unset($champ->param[0][$k]); |
|
| 207 | - if (count($champ->param[0]) == 1) { |
|
| 208 | - array_shift($champ->param); |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - return; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - spip_log("inclure sans fond ni fichier"); |
|
| 185 | + normaliser_args_inclumodel($champ); |
|
| 186 | + $l = $champ->param[0]; |
|
| 187 | + if (is_array($l) and !$l[0]) { |
|
| 188 | + foreach ($l as $k => $p) { |
|
| 189 | + if ($p and $p[0]->type == 'texte' and !strpos($p[0]->texte, '=')) { |
|
| 190 | + $p[0]->texte = trim($p[0]->texte); |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + foreach ($l as $k => $p) { |
|
| 194 | + if (!$p or $p[0]->type != 'texte' or |
|
| 195 | + !preg_match('/^fond\s*=\s*(.*)$/', $p[0]->texte, $r) |
|
| 196 | + ) { |
|
| 197 | + continue; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ($r[1]) { |
|
| 201 | + $p[0]->texte = $r[1]; |
|
| 202 | + } else { |
|
| 203 | + unset($p[0]); |
|
| 204 | + } |
|
| 205 | + $champ->texte = $p; |
|
| 206 | + unset($champ->param[0][$k]); |
|
| 207 | + if (count($champ->param[0]) == 1) { |
|
| 208 | + array_shift($champ->param); |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + return; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + spip_log("inclure sans fond ni fichier"); |
|
| 215 | 215 | } |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | $p->etoile = '*'; |
| 54 | 54 | spip_log("filtre de logo obsolete $nom", 'vieilles_defs'); |
| 55 | 55 | |
| 56 | - } elseif (preg_match("/^" . NOM_DE_CHAMP . '(.*)$/sS', $nom, $m)) { |
|
| 56 | + } elseif (preg_match("/^".NOM_DE_CHAMP.'(.*)$/sS', $nom, $m)) { |
|
| 57 | 57 | $champ = new Champ(); |
| 58 | 58 | $champ->nom_boucle = $m[2]; |
| 59 | 59 | $champ->nom_champ = $m[3]; |
@@ -131,7 +131,7 @@ discard block |
||
| 131 | 131 | $p->param[0][1] = array($c); |
| 132 | 132 | $p->param[0][0] = ''; |
| 133 | 133 | $p->fonctions = array(); |
| 134 | - spip_log('FORMULAIRE_RECHERCHE avec filtre ' . $c->texte, 'vieilles_defs'); |
|
| 134 | + spip_log('FORMULAIRE_RECHERCHE avec filtre '.$c->texte, 'vieilles_defs'); |
|
| 135 | 135 | } |
| 136 | 136 | } |
| 137 | 137 | |
@@ -231,7 +231,7 @@ |
||
| 231 | 231 | * |
| 232 | 232 | * @uses public_tester_redirection_dist() |
| 233 | 233 | * @param string $fond |
| 234 | - * @param array $contexte |
|
| 234 | + * @param string $contexte |
|
| 235 | 235 | * @param string $connect |
| 236 | 236 | * @return array|bool |
| 237 | 237 | */ |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/lang'); |
@@ -19,16 +19,16 @@ discard block |
||
| 19 | 19 | // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
| 20 | 20 | // donc il faut l'inclure "en globals" |
| 21 | 21 | if ($f = find_in_path('mes_fonctions.php')) { |
| 22 | - global $dossier_squelettes; |
|
| 23 | - include_once(_ROOT_CWD . $f); |
|
| 22 | + global $dossier_squelettes; |
|
| 23 | + include_once(_ROOT_CWD . $f); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
| 27 | - // chargement optimise precompile |
|
| 28 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 27 | + // chargement optimise precompile |
|
| 28 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 29 | 29 | } |
| 30 | 30 | if (test_espace_prive()) { |
| 31 | - include_spip('inc/filtres_ecrire'); |
|
| 31 | + include_spip('inc/filtres_ecrire'); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | # Determine le squelette associe a une requete |
@@ -46,180 +46,180 @@ discard block |
||
| 46 | 46 | |
| 47 | 47 | // http://code.spip.net/@public_parametrer_dist |
| 48 | 48 | function public_parametrer_dist($fond, $contexte = '', $cache = '', $connect = '') { |
| 49 | - static $composer, $styliser, $notes = null; |
|
| 50 | - $page = tester_redirection($fond, $contexte, $connect); |
|
| 51 | - if ($page) { |
|
| 52 | - return $page; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - if (isset($contexte['lang'])) { |
|
| 56 | - $lang = $contexte['lang']; |
|
| 57 | - } elseif (!isset($lang)) { |
|
| 58 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 62 | - if ($select) { |
|
| 63 | - $select = lang_select($lang); |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 67 | - |
|
| 68 | - if (!$styliser) { |
|
| 69 | - $styliser = charger_fonction('styliser', 'public'); |
|
| 70 | - } |
|
| 71 | - list($skel, $mime_type, $gram, $sourcefile) = |
|
| 72 | - $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 73 | - |
|
| 74 | - if ($skel) { |
|
| 75 | - |
|
| 76 | - // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 77 | - // (recursion possible a cause des modeles) |
|
| 78 | - if ($debug) { |
|
| 79 | - $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 80 | - $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 81 | - } |
|
| 82 | - |
|
| 83 | - // charger le squelette en specifiant les langages cibles et source |
|
| 84 | - // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 85 | - |
|
| 86 | - if (!$composer) { |
|
| 87 | - $composer = charger_fonction('composer', 'public'); |
|
| 88 | - } |
|
| 89 | - $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 90 | - } else { |
|
| 91 | - $fonc = ''; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 95 | - $page = $fonc; |
|
| 96 | - } else { |
|
| 97 | - // Preparer l'appel de la fonction principale du squelette |
|
| 98 | - |
|
| 99 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 100 | - |
|
| 101 | - // On cree un marqueur de notes unique lie a cette composition |
|
| 102 | - // et on enregistre l'etat courant des globales de notes... |
|
| 103 | - if (is_null($notes)) { |
|
| 104 | - $notes = charger_fonction('notes', 'inc', true); |
|
| 105 | - } |
|
| 106 | - if ($notes) { |
|
| 107 | - $notes('', 'empiler'); |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - // Rajouter d'office ces deux parametres |
|
| 111 | - // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 112 | - // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 113 | - if (!isset($contexte['date'])) { |
|
| 114 | - $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 115 | - $contexte['date_default'] = true; |
|
| 116 | - } else { |
|
| 117 | - $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - if (!isset($contexte['date_redac'])) { |
|
| 121 | - $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 122 | - $contexte['date_redac_default'] = true; |
|
| 123 | - } else { |
|
| 124 | - $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 125 | - } |
|
| 126 | - |
|
| 127 | - // Passer le nom du cache pour produire sa destruction automatique |
|
| 128 | - $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 129 | - |
|
| 130 | - // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 131 | - // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 132 | - // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 133 | - // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 134 | - // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 135 | - if ($notes) { |
|
| 136 | - $notes('', 'depiler'); |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // reinjecter en dynamique la pile des notes |
|
| 140 | - // si il y a des inclure dynamiques |
|
| 141 | - // si la pile n'est pas vide |
|
| 142 | - // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 143 | - // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 144 | - if ($notes) { |
|
| 145 | - $page['notes'] = $notes('', 'sauver_etat'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - // spip_log: un joli contexte |
|
| 149 | - $infos = array(); |
|
| 150 | - foreach (array_filter($contexte) as $var => $val) { |
|
| 151 | - if (is_array($val)) { |
|
| 152 | - $val = serialize($val); |
|
| 153 | - } |
|
| 154 | - if (strlen("$val") > 30) { |
|
| 155 | - $val = substr("$val", 0, 27) . '..'; |
|
| 156 | - } |
|
| 157 | - if (strstr($val, ' ')) { |
|
| 158 | - $val = "'$val'"; |
|
| 159 | - } |
|
| 160 | - $infos[] = $var . '=' . $val; |
|
| 161 | - } |
|
| 162 | - $profile = spip_timer($a); |
|
| 163 | - spip_log("calcul ($profile) [$skel] " |
|
| 164 | - . join(', ', $infos) |
|
| 165 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 166 | - |
|
| 167 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 168 | - spip_log("calcul ($profile) [$skel] " |
|
| 169 | - . join(', ', $infos) |
|
| 170 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if ($debug) { |
|
| 174 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 175 | - $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 176 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 177 | - $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 178 | - $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 179 | - if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 180 | - and (_request('var_mode_objet') == $fonc) |
|
| 181 | - and (_request('var_mode_affiche') == 'resultat') |
|
| 182 | - ) { |
|
| 183 | - erreur_squelette(); |
|
| 184 | - } |
|
| 185 | - } |
|
| 186 | - // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 187 | - if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 188 | - // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 189 | - // si aucun #CACHE{} spécifié |
|
| 190 | - // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 191 | - // entre public et prive |
|
| 192 | - if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 193 | - $page['entetes']['X-Spip-Cache'] = 0; |
|
| 194 | - } else { |
|
| 195 | - $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - $page['contexte'] = $contexte; |
|
| 200 | - |
|
| 201 | - // faire remonter le fichier source |
|
| 202 | - static $js_inclus = false; |
|
| 203 | - if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 204 | - $page['sourcefile'] = $sourcefile; |
|
| 205 | - $page['texte'] = |
|
| 206 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 207 | - . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 208 | - $js_inclus = true; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 212 | - if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 213 | - $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 214 | - unset($GLOBALS['cache_utilise_session']); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - if ($select) { |
|
| 219 | - lang_select(); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - return $page; |
|
| 49 | + static $composer, $styliser, $notes = null; |
|
| 50 | + $page = tester_redirection($fond, $contexte, $connect); |
|
| 51 | + if ($page) { |
|
| 52 | + return $page; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + if (isset($contexte['lang'])) { |
|
| 56 | + $lang = $contexte['lang']; |
|
| 57 | + } elseif (!isset($lang)) { |
|
| 58 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + $select = ((!isset($GLOBALS['forcer_lang']) or !$GLOBALS['forcer_lang']) and $lang <> $GLOBALS['spip_lang']); |
|
| 62 | + if ($select) { |
|
| 63 | + $select = lang_select($lang); |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + $debug = (defined('_VAR_MODE') && _VAR_MODE == 'debug'); |
|
| 67 | + |
|
| 68 | + if (!$styliser) { |
|
| 69 | + $styliser = charger_fonction('styliser', 'public'); |
|
| 70 | + } |
|
| 71 | + list($skel, $mime_type, $gram, $sourcefile) = |
|
| 72 | + $styliser($fond, $contexte, $GLOBALS['spip_lang'], $connect); |
|
| 73 | + |
|
| 74 | + if ($skel) { |
|
| 75 | + |
|
| 76 | + // sauver le nom de l'eventuel squelette en cours d'execution |
|
| 77 | + // (recursion possible a cause des modeles) |
|
| 78 | + if ($debug) { |
|
| 79 | + $courant = @$GLOBALS['debug_objets']['courant']; |
|
| 80 | + $GLOBALS['debug_objets']['contexte'][$sourcefile] = $contexte; |
|
| 81 | + } |
|
| 82 | + |
|
| 83 | + // charger le squelette en specifiant les langages cibles et source |
|
| 84 | + // au cas il faudrait le compiler (source posterieure au resultat) |
|
| 85 | + |
|
| 86 | + if (!$composer) { |
|
| 87 | + $composer = charger_fonction('composer', 'public'); |
|
| 88 | + } |
|
| 89 | + $fonc = $composer($skel, $mime_type, $gram, $sourcefile, $connect); |
|
| 90 | + } else { |
|
| 91 | + $fonc = ''; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (!$fonc) { // squelette inconnu (==='') ou faux (===false) |
|
| 95 | + $page = $fonc; |
|
| 96 | + } else { |
|
| 97 | + // Preparer l'appel de la fonction principale du squelette |
|
| 98 | + |
|
| 99 | + spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 100 | + |
|
| 101 | + // On cree un marqueur de notes unique lie a cette composition |
|
| 102 | + // et on enregistre l'etat courant des globales de notes... |
|
| 103 | + if (is_null($notes)) { |
|
| 104 | + $notes = charger_fonction('notes', 'inc', true); |
|
| 105 | + } |
|
| 106 | + if ($notes) { |
|
| 107 | + $notes('', 'empiler'); |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + // Rajouter d'office ces deux parametres |
|
| 111 | + // (mais vaudrait mieux que le compilateur sache le simuler |
|
| 112 | + // car ca interdit l'usage de criteres conditionnels dessus). |
|
| 113 | + if (!isset($contexte['date'])) { |
|
| 114 | + $contexte['date'] = date("Y-m-d H:i:s"); |
|
| 115 | + $contexte['date_default'] = true; |
|
| 116 | + } else { |
|
| 117 | + $contexte['date'] = normaliser_date($contexte['date'], true); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + if (!isset($contexte['date_redac'])) { |
|
| 121 | + $contexte['date_redac'] = date("Y-m-d H:i:s"); |
|
| 122 | + $contexte['date_redac_default'] = true; |
|
| 123 | + } else { |
|
| 124 | + $contexte['date_redac'] = normaliser_date($contexte['date_redac'], true); |
|
| 125 | + } |
|
| 126 | + |
|
| 127 | + // Passer le nom du cache pour produire sa destruction automatique |
|
| 128 | + $page = $fonc(array('cache' => $cache), array($contexte)); |
|
| 129 | + |
|
| 130 | + // Restituer les globales de notes telles qu'elles etaient avant l'appel |
|
| 131 | + // Si l'inclus n'a pas affiche ses notes, tant pis (elles *doivent* |
|
| 132 | + // etre dans son resultat, autrement elles ne seraient pas prises en |
|
| 133 | + // compte a chaque calcul d'un texte contenant un modele, mais seulement |
|
| 134 | + // quand le modele serait calcule, et on aurait des resultats incoherents) |
|
| 135 | + if ($notes) { |
|
| 136 | + $notes('', 'depiler'); |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // reinjecter en dynamique la pile des notes |
|
| 140 | + // si il y a des inclure dynamiques |
|
| 141 | + // si la pile n'est pas vide |
|
| 142 | + // la generalisation de cette injection permettrait de corriger le point juste au dessus |
|
| 143 | + // en faisant remonter les notes a l'incluant (A tester et valider avant application) |
|
| 144 | + if ($notes) { |
|
| 145 | + $page['notes'] = $notes('', 'sauver_etat'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + // spip_log: un joli contexte |
|
| 149 | + $infos = array(); |
|
| 150 | + foreach (array_filter($contexte) as $var => $val) { |
|
| 151 | + if (is_array($val)) { |
|
| 152 | + $val = serialize($val); |
|
| 153 | + } |
|
| 154 | + if (strlen("$val") > 30) { |
|
| 155 | + $val = substr("$val", 0, 27) . '..'; |
|
| 156 | + } |
|
| 157 | + if (strstr($val, ' ')) { |
|
| 158 | + $val = "'$val'"; |
|
| 159 | + } |
|
| 160 | + $infos[] = $var . '=' . $val; |
|
| 161 | + } |
|
| 162 | + $profile = spip_timer($a); |
|
| 163 | + spip_log("calcul ($profile) [$skel] " |
|
| 164 | + . join(', ', $infos) |
|
| 165 | + . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 166 | + |
|
| 167 | + if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 168 | + spip_log("calcul ($profile) [$skel] " |
|
| 169 | + . join(', ', $infos) |
|
| 170 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if ($debug) { |
|
| 174 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 175 | + $t = strlen($page['texte']) ? $page['texte'] : " "; |
|
| 176 | + $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 177 | + $GLOBALS['debug_objets']['courant'] = $courant; |
|
| 178 | + $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
|
| 179 | + if ($GLOBALS['debug_objets']['sourcefile'] |
|
| 180 | + and (_request('var_mode_objet') == $fonc) |
|
| 181 | + and (_request('var_mode_affiche') == 'resultat') |
|
| 182 | + ) { |
|
| 183 | + erreur_squelette(); |
|
| 184 | + } |
|
| 185 | + } |
|
| 186 | + // Si #CACHE{} n'etait pas la, le mettre a $delais |
|
| 187 | + if (!isset($page['entetes']['X-Spip-Cache'])) { |
|
| 188 | + // Dans l'espace prive ou dans un modeles/ on pose un cache 0 par defaut |
|
| 189 | + // si aucun #CACHE{} spécifié |
|
| 190 | + // le contexte implicite qui conditionne le cache assure qu'on retombe pas sur le meme |
|
| 191 | + // entre public et prive |
|
| 192 | + if (test_espace_prive() or strncmp($fond, 'modeles/', 8) == 0) { |
|
| 193 | + $page['entetes']['X-Spip-Cache'] = 0; |
|
| 194 | + } else { |
|
| 195 | + $page['entetes']['X-Spip-Cache'] = isset($GLOBALS['delais']) ? $GLOBALS['delais'] : 36000; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + $page['contexte'] = $contexte; |
|
| 200 | + |
|
| 201 | + // faire remonter le fichier source |
|
| 202 | + static $js_inclus = false; |
|
| 203 | + if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
|
| 204 | + $page['sourcefile'] = $sourcefile; |
|
| 205 | + $page['texte'] = |
|
| 206 | + "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 207 | + . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
|
| 208 | + $js_inclus = true; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // Si un modele contenait #SESSION, on note l'info dans $page |
|
| 212 | + if (isset($GLOBALS['cache_utilise_session'])) { |
|
| 213 | + $page['invalideurs']['session'] = $GLOBALS['cache_utilise_session']; |
|
| 214 | + unset($GLOBALS['cache_utilise_session']); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + if ($select) { |
|
| 219 | + lang_select(); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + return $page; |
|
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | |
@@ -236,11 +236,11 @@ discard block |
||
| 236 | 236 | * @return array|bool |
| 237 | 237 | */ |
| 238 | 238 | function tester_redirection($fond, $contexte, $connect) { |
| 239 | - static $tester_redirection = null; |
|
| 240 | - if (is_null($tester_redirection)) { |
|
| 241 | - $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 242 | - } |
|
| 243 | - return $tester_redirection($fond, $contexte, $connect); |
|
| 239 | + static $tester_redirection = null; |
|
| 240 | + if (is_null($tester_redirection)) { |
|
| 241 | + $tester_redirection = charger_fonction('tester_redirection', 'public'); |
|
| 242 | + } |
|
| 243 | + return $tester_redirection($fond, $contexte, $connect); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -256,40 +256,40 @@ discard block |
||
| 256 | 256 | * @return array|bool |
| 257 | 257 | */ |
| 258 | 258 | function public_tester_redirection_dist($fond, $contexte, $connect) { |
| 259 | - if ($fond == 'article' |
|
| 260 | - and $id_article = intval($contexte['id_article']) |
|
| 261 | - ) { |
|
| 262 | - include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 263 | - $m = quete_virtuel($id_article, $connect); |
|
| 264 | - if (strlen($m)) { |
|
| 265 | - include_spip('inc/texte'); |
|
| 266 | - // les navigateurs pataugent si l'URL est vide |
|
| 267 | - if ($url = virtuel_redirige($m, true)) { |
|
| 268 | - // passer en url absolue car cette redirection pourra |
|
| 269 | - // etre utilisee dans un contexte d'url qui change |
|
| 270 | - // y compris url arbo |
|
| 271 | - $status = 302; |
|
| 272 | - if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 273 | - $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 274 | - } |
|
| 275 | - if (!preg_match(',^\w+:,', $url)) { |
|
| 276 | - include_spip('inc/filtres_mini'); |
|
| 277 | - $url = url_absolue($url); |
|
| 278 | - } |
|
| 279 | - $url = str_replace('&', '&', $url); |
|
| 280 | - |
|
| 281 | - return array( |
|
| 282 | - 'texte' => "<" |
|
| 283 | - . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 284 | - . texte_script($url) |
|
| 285 | - . "','',$status);" |
|
| 286 | - . "?" . ">", |
|
| 287 | - 'process_ins' => 'php', |
|
| 288 | - 'status' => $status |
|
| 289 | - ); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - return false; |
|
| 259 | + if ($fond == 'article' |
|
| 260 | + and $id_article = intval($contexte['id_article']) |
|
| 261 | + ) { |
|
| 262 | + include_spip('public/quete'); // pour quete_virtuel et ses dependances |
|
| 263 | + $m = quete_virtuel($id_article, $connect); |
|
| 264 | + if (strlen($m)) { |
|
| 265 | + include_spip('inc/texte'); |
|
| 266 | + // les navigateurs pataugent si l'URL est vide |
|
| 267 | + if ($url = virtuel_redirige($m, true)) { |
|
| 268 | + // passer en url absolue car cette redirection pourra |
|
| 269 | + // etre utilisee dans un contexte d'url qui change |
|
| 270 | + // y compris url arbo |
|
| 271 | + $status = 302; |
|
| 272 | + if (defined('_STATUS_REDIRECTION_VIRTUEL')) { |
|
| 273 | + $status = _STATUS_REDIRECTION_VIRTUEL; |
|
| 274 | + } |
|
| 275 | + if (!preg_match(',^\w+:,', $url)) { |
|
| 276 | + include_spip('inc/filtres_mini'); |
|
| 277 | + $url = url_absolue($url); |
|
| 278 | + } |
|
| 279 | + $url = str_replace('&', '&', $url); |
|
| 280 | + |
|
| 281 | + return array( |
|
| 282 | + 'texte' => "<" |
|
| 283 | + . "?php include_spip('inc/headers');redirige_par_entete('" |
|
| 284 | + . texte_script($url) |
|
| 285 | + . "','',$status);" |
|
| 286 | + . "?" . ">", |
|
| 287 | + 'process_ins' => 'php', |
|
| 288 | + 'status' => $status |
|
| 289 | + ); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + return false; |
|
| 295 | 295 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | // donc il faut l'inclure "en globals" |
| 21 | 21 | if ($f = find_in_path('mes_fonctions.php')) { |
| 22 | 22 | global $dossier_squelettes; |
| 23 | - include_once(_ROOT_CWD . $f); |
|
| 23 | + include_once(_ROOT_CWD.$f); |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | if (@is_readable(_CACHE_PLUGINS_FCT)) { |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } else { |
| 97 | 97 | // Preparer l'appel de la fonction principale du squelette |
| 98 | 98 | |
| 99 | - spip_timer($a = 'calcul page ' . rand(0, 1000)); |
|
| 99 | + spip_timer($a = 'calcul page '.rand(0, 1000)); |
|
| 100 | 100 | |
| 101 | 101 | // On cree un marqueur de notes unique lie a cette composition |
| 102 | 102 | // et on enregistre l'etat courant des globales de notes... |
@@ -152,28 +152,28 @@ discard block |
||
| 152 | 152 | $val = serialize($val); |
| 153 | 153 | } |
| 154 | 154 | if (strlen("$val") > 30) { |
| 155 | - $val = substr("$val", 0, 27) . '..'; |
|
| 155 | + $val = substr("$val", 0, 27).'..'; |
|
| 156 | 156 | } |
| 157 | 157 | if (strstr($val, ' ')) { |
| 158 | 158 | $val = "'$val'"; |
| 159 | 159 | } |
| 160 | - $infos[] = $var . '=' . $val; |
|
| 160 | + $infos[] = $var.'='.$val; |
|
| 161 | 161 | } |
| 162 | 162 | $profile = spip_timer($a); |
| 163 | 163 | spip_log("calcul ($profile) [$skel] " |
| 164 | 164 | . join(', ', $infos) |
| 165 | - . ' (' . strlen($page['texte']) . ' octets)'); |
|
| 165 | + . ' ('.strlen($page['texte']).' octets)'); |
|
| 166 | 166 | |
| 167 | - if (defined('_CALCUL_PROFILER') AND intval($profile)>_CALCUL_PROFILER){ |
|
| 167 | + if (defined('_CALCUL_PROFILER') AND intval($profile) > _CALCUL_PROFILER) { |
|
| 168 | 168 | spip_log("calcul ($profile) [$skel] " |
| 169 | 169 | . join(', ', $infos) |
| 170 | - .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'],"profiler"._LOG_AVERTISSEMENT); |
|
| 170 | + .' ('.strlen($page['texte']).' octets) | '.$_SERVER['REQUEST_URI'], "profiler"._LOG_AVERTISSEMENT); |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | if ($debug) { |
| 174 | 174 | // si c'est ce que demande le debusqueur, lui passer la main |
| 175 | 175 | $t = strlen($page['texte']) ? $page['texte'] : " "; |
| 176 | - $GLOBALS['debug_objets']['resultat'][$fonc . 'tout'] = $t; |
|
| 176 | + $GLOBALS['debug_objets']['resultat'][$fonc.'tout'] = $t; |
|
| 177 | 177 | $GLOBALS['debug_objets']['courant'] = $courant; |
| 178 | 178 | $GLOBALS['debug_objets']['profile'][$sourcefile] = $profile; |
| 179 | 179 | if ($GLOBALS['debug_objets']['sourcefile'] |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | if (defined('_VAR_INCLURE') and _VAR_INCLURE) { |
| 204 | 204 | $page['sourcefile'] = $sourcefile; |
| 205 | 205 | $page['texte'] = |
| 206 | - "<div class='inclure_blocs'><h6>" . $page['sourcefile'] . "</h6>" . $page['texte'] . "</div>" |
|
| 206 | + "<div class='inclure_blocs'><h6>".$page['sourcefile']."</h6>".$page['texte']."</div>" |
|
| 207 | 207 | . ($js_inclus ? "" : "<script type='text/javascript'>jQuery(function(){jQuery('.inclure_blocs > h6:first-child').hover(function(){jQuery(this).parent().addClass('hover')},function(){jQuery(this).parent().removeClass('hover')})});</script>"); |
| 208 | 208 | $js_inclus = true; |
| 209 | 209 | } |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | . "?php include_spip('inc/headers');redirige_par_entete('" |
| 284 | 284 | . texte_script($url) |
| 285 | 285 | . "','',$status);" |
| 286 | - . "?" . ">", |
|
| 286 | + . "?".">", |
|
| 287 | 287 | 'process_ins' => 'php', |
| 288 | 288 | 'status' => $status |
| 289 | 289 | ); |
@@ -293,7 +293,7 @@ discard block |
||
| 293 | 293 | * est dans une autre table et construit la jointure dessus |
| 294 | 294 | * - liste (table, champ, fonction) idem, mais en passant un |
| 295 | 295 | * nom de fonction qui s'occupera de créer la jointure. |
| 296 | - * @return array |
|
| 296 | + * @return string[] |
|
| 297 | 297 | * Liste (nom du champ alias, nom du champ). Le nom du champ alias |
| 298 | 298 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 299 | 299 | **/ |
@@ -471,7 +471,7 @@ discard block |
||
| 471 | 471 | * Nom de la balise |
| 472 | 472 | * @param Champ $p |
| 473 | 473 | * AST au niveau de la balise |
| 474 | - * @return string |
|
| 474 | + * @return Champ |
|
| 475 | 475 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 476 | 476 | **/ |
| 477 | 477 | function calculer_balise_DEFAUT_dist($nom, $p) { |
@@ -755,6 +755,9 @@ discard block |
||
| 755 | 755 | // - deux etoiles => pas de securite non plus ! |
| 756 | 756 | // |
| 757 | 757 | // http://code.spip.net/@applique_filtres |
| 758 | +/** |
|
| 759 | + * @param Champ $p |
|
| 760 | + */ |
|
| 758 | 761 | function applique_filtres($p) { |
| 759 | 762 | |
| 760 | 763 | // Traitements standards (cf. supra) |
@@ -829,6 +832,9 @@ discard block |
||
| 829 | 832 | |
| 830 | 833 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 831 | 834 | // et comparateurs |
| 835 | +/** |
|
| 836 | + * @param string $arg |
|
| 837 | + */ |
|
| 832 | 838 | function filtre_logique($fonc, $code, $arg) { |
| 833 | 839 | |
| 834 | 840 | switch (true) { |
@@ -852,6 +858,9 @@ discard block |
||
| 852 | 858 | } |
| 853 | 859 | |
| 854 | 860 | // http://code.spip.net/@compose_filtres_args |
| 861 | +/** |
|
| 862 | + * @param string $sep |
|
| 863 | + */ |
|
| 855 | 864 | function compose_filtres_args($p, $args, $sep) { |
| 856 | 865 | $arglist = ""; |
| 857 | 866 | foreach ($args as $arg) { |
@@ -899,6 +908,11 @@ discard block |
||
| 899 | 908 | // |
| 900 | 909 | |
| 901 | 910 | // http://code.spip.net/@rindex_pile |
| 911 | +/** |
|
| 912 | + * @param Champ $p |
|
| 913 | + * @param string $champ |
|
| 914 | + * @param string $motif |
|
| 915 | + */ |
|
| 902 | 916 | function rindex_pile($p, $champ, $motif) { |
| 903 | 917 | $n = 0; |
| 904 | 918 | $b = $p->id_boucle; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | 44 | |
| 45 | - $idb = $p->id_boucle; |
|
| 46 | - $explicite = $p->nom_boucle; |
|
| 45 | + $idb = $p->id_boucle; |
|
| 46 | + $explicite = $p->nom_boucle; |
|
| 47 | 47 | |
| 48 | - if (strlen($explicite)) { |
|
| 49 | - // Recherche d'un champ dans un etage superieur |
|
| 50 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 51 | - $idb = $p->boucles[$idb]->id_parent; |
|
| 52 | - } |
|
| 53 | - } |
|
| 48 | + if (strlen($explicite)) { |
|
| 49 | + // Recherche d'un champ dans un etage superieur |
|
| 50 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 51 | + $idb = $p->boucles[$idb]->id_parent; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - return $idb; |
|
| 55 | + return $idb; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -86,69 +86,69 @@ discard block |
||
| 86 | 86 | * Code PHP pour obtenir le champ SQL |
| 87 | 87 | */ |
| 88 | 88 | function index_pile( |
| 89 | - $idb, |
|
| 90 | - $nom_champ, |
|
| 91 | - &$boucles, |
|
| 92 | - $explicite = '', |
|
| 93 | - $defaut = null, |
|
| 94 | - $remonte_pile = true, |
|
| 95 | - $select = true |
|
| 89 | + $idb, |
|
| 90 | + $nom_champ, |
|
| 91 | + &$boucles, |
|
| 92 | + $explicite = '', |
|
| 93 | + $defaut = null, |
|
| 94 | + $remonte_pile = true, |
|
| 95 | + $select = true |
|
| 96 | 96 | ) { |
| 97 | - if (!is_string($defaut)) { |
|
| 98 | - $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']'; |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - $i = 0; |
|
| 102 | - if (strlen($explicite)) { |
|
| 103 | - // Recherche d'un champ dans un etage superieur |
|
| 104 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 105 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 106 | - $i++; |
|
| 107 | - $idb = $boucles[$idb]->id_parent; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 112 | - $nom_champ = strtolower($nom_champ); |
|
| 113 | - $conditionnel = array(); |
|
| 114 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 115 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 116 | - while (isset($boucles[$idb])) { |
|
| 117 | - $joker = true; |
|
| 118 | - // modifie $joker si tous les champs sont autorisés. |
|
| 119 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 120 | - // $c = le nom du champ demandé |
|
| 121 | - list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 122 | - if ($t) { |
|
| 123 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 124 | - $boucles[$idb]->select[] = $t; |
|
| 125 | - } |
|
| 126 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 127 | - if (!$joker) { |
|
| 128 | - return index_compose($conditionnel, $champ); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 132 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 133 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 134 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 135 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - if ($remonte_pile) { |
|
| 139 | - # spip_log("On remonte vers $i"); |
|
| 140 | - // Sinon on remonte d'un cran |
|
| 141 | - $idb = $boucles[$idb]->id_parent; |
|
| 142 | - $i++; |
|
| 143 | - } else { |
|
| 144 | - $idb = null; |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - # spip_log("Pas vu $nom_champ"); |
|
| 149 | - // esperons qu'il y sera |
|
| 150 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 151 | - return index_compose($conditionnel, $defaut); |
|
| 97 | + if (!is_string($defaut)) { |
|
| 98 | + $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']'; |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + $i = 0; |
|
| 102 | + if (strlen($explicite)) { |
|
| 103 | + // Recherche d'un champ dans un etage superieur |
|
| 104 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 105 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 106 | + $i++; |
|
| 107 | + $idb = $boucles[$idb]->id_parent; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 112 | + $nom_champ = strtolower($nom_champ); |
|
| 113 | + $conditionnel = array(); |
|
| 114 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 115 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 116 | + while (isset($boucles[$idb])) { |
|
| 117 | + $joker = true; |
|
| 118 | + // modifie $joker si tous les champs sont autorisés. |
|
| 119 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 120 | + // $c = le nom du champ demandé |
|
| 121 | + list($t, $c) = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 122 | + if ($t) { |
|
| 123 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 124 | + $boucles[$idb]->select[] = $t; |
|
| 125 | + } |
|
| 126 | + $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 127 | + if (!$joker) { |
|
| 128 | + return index_compose($conditionnel, $champ); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 132 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 133 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 134 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 135 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + if ($remonte_pile) { |
|
| 139 | + # spip_log("On remonte vers $i"); |
|
| 140 | + // Sinon on remonte d'un cran |
|
| 141 | + $idb = $boucles[$idb]->id_parent; |
|
| 142 | + $i++; |
|
| 143 | + } else { |
|
| 144 | + $idb = null; |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + # spip_log("Pas vu $nom_champ"); |
|
| 149 | + // esperons qu'il y sera |
|
| 150 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 151 | + return index_compose($conditionnel, $defaut); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -162,12 +162,12 @@ discard block |
||
| 162 | 162 | * @return string Code PHP complet de recherche d'un champ |
| 163 | 163 | */ |
| 164 | 164 | function index_compose($conditionnel, $defaut) { |
| 165 | - while ($c = array_pop($conditionnel)) { |
|
| 166 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 167 | - $defaut = "($c:(" . ($defaut ? $defaut : "''") . "))"; |
|
| 168 | - } |
|
| 165 | + while ($c = array_pop($conditionnel)) { |
|
| 166 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 167 | + $defaut = "($c:(" . ($defaut ? $defaut : "''") . "))"; |
|
| 168 | + } |
|
| 169 | 169 | |
| 170 | - return $defaut; |
|
| 170 | + return $defaut; |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | /** |
@@ -203,74 +203,74 @@ discard block |
||
| 203 | 203 | **/ |
| 204 | 204 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 205 | 205 | |
| 206 | - $r = $boucles[$idb]->type_requete; |
|
| 207 | - // boucle recursive, c'est foutu... |
|
| 208 | - if ($r == TYPE_RECURSIF) { |
|
| 209 | - return array(); |
|
| 210 | - } |
|
| 211 | - if (!$r) { |
|
| 212 | - $joker = false; // indiquer a l'appelant |
|
| 213 | - # continuer pour chercher l'erreur suivante |
|
| 214 | - return array("'#" . $r . ':' . $nom_champ . "'", ''); |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - $desc = $boucles[$idb]->show; |
|
| 218 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 219 | - $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 220 | - if ($excep) { |
|
| 221 | - $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 222 | - } |
|
| 223 | - if ($excep) { |
|
| 224 | - $joker = false; // indiquer a l'appelant |
|
| 225 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 226 | - } // pas d'alias. Le champ existe t'il ? |
|
| 227 | - else { |
|
| 228 | - // le champ est réellement présent, on le prend. |
|
| 229 | - if (isset($desc['field'][$nom_champ])) { |
|
| 230 | - $t = $boucles[$idb]->id_table; |
|
| 231 | - $joker = false; // indiquer a l'appelant |
|
| 232 | - return array("$t.$nom_champ", $nom_champ); |
|
| 233 | - } |
|
| 234 | - // Tous les champs sont-ils acceptés ? |
|
| 235 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 236 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 237 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 238 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 239 | - elseif (/*$joker AND */ |
|
| 240 | - isset($desc['field']['*']) |
|
| 241 | - ) { |
|
| 242 | - $joker = true; // indiquer a l'appelant |
|
| 243 | - return array($nom_champ, $nom_champ); |
|
| 244 | - } |
|
| 245 | - // pas d'alias, pas de champ, pas de joker... |
|
| 246 | - // tenter via une jointure... |
|
| 247 | - else { |
|
| 248 | - $joker = false; // indiquer a l'appelant |
|
| 249 | - // regarder si le champ est deja dans une jointure existante |
|
| 250 | - // sinon, si il y a des joitures explicites, la construire |
|
| 251 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 252 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 253 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 254 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 255 | - // mais est-ce ce qu'on veut ? |
|
| 256 | - $jointures = preg_split("/\s+/", $boucles[$idb]->jointures_explicites); |
|
| 257 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 258 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 259 | - } |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - if ($t) { |
|
| 263 | - // si on a trouvé une jointure possible, on fait comme |
|
| 264 | - // si c'était une exception pour le champ demandé |
|
| 265 | - return index_exception($boucles[$idb], |
|
| 266 | - $desc, |
|
| 267 | - $nom_champ, |
|
| 268 | - array($t[1]['id_table'], reset($t[2]))); |
|
| 269 | - } |
|
| 270 | - |
|
| 271 | - return array('', ''); |
|
| 272 | - } |
|
| 273 | - } |
|
| 206 | + $r = $boucles[$idb]->type_requete; |
|
| 207 | + // boucle recursive, c'est foutu... |
|
| 208 | + if ($r == TYPE_RECURSIF) { |
|
| 209 | + return array(); |
|
| 210 | + } |
|
| 211 | + if (!$r) { |
|
| 212 | + $joker = false; // indiquer a l'appelant |
|
| 213 | + # continuer pour chercher l'erreur suivante |
|
| 214 | + return array("'#" . $r . ':' . $nom_champ . "'", ''); |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + $desc = $boucles[$idb]->show; |
|
| 218 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 219 | + $excep = isset($GLOBALS['exceptions_des_tables'][$r]) ? $GLOBALS['exceptions_des_tables'][$r] : ''; |
|
| 220 | + if ($excep) { |
|
| 221 | + $excep = isset($excep[$nom_champ]) ? $excep[$nom_champ] : ''; |
|
| 222 | + } |
|
| 223 | + if ($excep) { |
|
| 224 | + $joker = false; // indiquer a l'appelant |
|
| 225 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 226 | + } // pas d'alias. Le champ existe t'il ? |
|
| 227 | + else { |
|
| 228 | + // le champ est réellement présent, on le prend. |
|
| 229 | + if (isset($desc['field'][$nom_champ])) { |
|
| 230 | + $t = $boucles[$idb]->id_table; |
|
| 231 | + $joker = false; // indiquer a l'appelant |
|
| 232 | + return array("$t.$nom_champ", $nom_champ); |
|
| 233 | + } |
|
| 234 | + // Tous les champs sont-ils acceptés ? |
|
| 235 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 236 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 237 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 238 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 239 | + elseif (/*$joker AND */ |
|
| 240 | + isset($desc['field']['*']) |
|
| 241 | + ) { |
|
| 242 | + $joker = true; // indiquer a l'appelant |
|
| 243 | + return array($nom_champ, $nom_champ); |
|
| 244 | + } |
|
| 245 | + // pas d'alias, pas de champ, pas de joker... |
|
| 246 | + // tenter via une jointure... |
|
| 247 | + else { |
|
| 248 | + $joker = false; // indiquer a l'appelant |
|
| 249 | + // regarder si le champ est deja dans une jointure existante |
|
| 250 | + // sinon, si il y a des joitures explicites, la construire |
|
| 251 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 252 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 253 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 254 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 255 | + // mais est-ce ce qu'on veut ? |
|
| 256 | + $jointures = preg_split("/\s+/", $boucles[$idb]->jointures_explicites); |
|
| 257 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 258 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 259 | + } |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + if ($t) { |
|
| 263 | + // si on a trouvé une jointure possible, on fait comme |
|
| 264 | + // si c'était une exception pour le champ demandé |
|
| 265 | + return index_exception($boucles[$idb], |
|
| 266 | + $desc, |
|
| 267 | + $nom_champ, |
|
| 268 | + array($t[1]['id_table'], reset($t[2]))); |
|
| 269 | + } |
|
| 270 | + |
|
| 271 | + return array('', ''); |
|
| 272 | + } |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -298,52 +298,52 @@ discard block |
||
| 298 | 298 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 299 | 299 | **/ |
| 300 | 300 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 301 | - static $trouver_table; |
|
| 302 | - if (!$trouver_table) { |
|
| 303 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | - } |
|
| 305 | - |
|
| 306 | - if (is_array($excep)) { |
|
| 307 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 308 | - $t = null; |
|
| 309 | - if (count($excep) == 3) { |
|
| 310 | - $index_exception_derogatoire = array_pop($excep); |
|
| 311 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 312 | - } |
|
| 313 | - if ($t == null) { |
|
| 314 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 315 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 316 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 317 | - if (!$j) { |
|
| 318 | - return array('', ''); |
|
| 319 | - } |
|
| 320 | - $e = $j['table']; |
|
| 321 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 322 | - $k = $j['key']['PRIMARY KEY']; |
|
| 323 | - if (strpos($k, ',')) { |
|
| 324 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 325 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 326 | - if (!in_array($k, $l)) { |
|
| 327 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 328 | - |
|
| 329 | - return array('', ''); |
|
| 330 | - } |
|
| 331 | - } |
|
| 332 | - $k = array($boucle->id_table, array($e), $k); |
|
| 333 | - fabrique_jointures($boucle, array($k)); |
|
| 334 | - $t = array_search($e, $boucle->from); |
|
| 335 | - } |
|
| 336 | - } |
|
| 337 | - } else { |
|
| 338 | - $t = $boucle->id_table; |
|
| 339 | - } |
|
| 340 | - // demander a SQL de gerer le synonyme |
|
| 341 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 342 | - if ($excep != $nom_champ) { |
|
| 343 | - $excep .= ' AS ' . $nom_champ; |
|
| 344 | - } |
|
| 345 | - |
|
| 346 | - return array("$t.$excep", $nom_champ); |
|
| 301 | + static $trouver_table; |
|
| 302 | + if (!$trouver_table) { |
|
| 303 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | + } |
|
| 305 | + |
|
| 306 | + if (is_array($excep)) { |
|
| 307 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 308 | + $t = null; |
|
| 309 | + if (count($excep) == 3) { |
|
| 310 | + $index_exception_derogatoire = array_pop($excep); |
|
| 311 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 312 | + } |
|
| 313 | + if ($t == null) { |
|
| 314 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 315 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 316 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 317 | + if (!$j) { |
|
| 318 | + return array('', ''); |
|
| 319 | + } |
|
| 320 | + $e = $j['table']; |
|
| 321 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 322 | + $k = $j['key']['PRIMARY KEY']; |
|
| 323 | + if (strpos($k, ',')) { |
|
| 324 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 325 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 326 | + if (!in_array($k, $l)) { |
|
| 327 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 328 | + |
|
| 329 | + return array('', ''); |
|
| 330 | + } |
|
| 331 | + } |
|
| 332 | + $k = array($boucle->id_table, array($e), $k); |
|
| 333 | + fabrique_jointures($boucle, array($k)); |
|
| 334 | + $t = array_search($e, $boucle->from); |
|
| 335 | + } |
|
| 336 | + } |
|
| 337 | + } else { |
|
| 338 | + $t = $boucle->id_table; |
|
| 339 | + } |
|
| 340 | + // demander a SQL de gerer le synonyme |
|
| 341 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 342 | + if ($excep != $nom_champ) { |
|
| 343 | + $excep .= ' AS ' . $nom_champ; |
|
| 344 | + } |
|
| 345 | + |
|
| 346 | + return array("$t.$excep", $nom_champ); |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -368,7 +368,7 @@ discard block |
||
| 368 | 368 | * Code PHP pour retrouver le champ |
| 369 | 369 | */ |
| 370 | 370 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 371 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 371 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 372 | 372 | } |
| 373 | 373 | |
| 374 | 374 | |
@@ -388,9 +388,9 @@ discard block |
||
| 388 | 388 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 389 | 389 | **/ |
| 390 | 390 | function calculer_champ($p) { |
| 391 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 391 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 392 | 392 | |
| 393 | - return applique_filtres($p); |
|
| 393 | + return applique_filtres($p); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | |
@@ -427,28 +427,28 @@ discard block |
||
| 427 | 427 | **/ |
| 428 | 428 | function calculer_balise($nom, $p) { |
| 429 | 429 | |
| 430 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 431 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 432 | - $p->balise_calculee = true; |
|
| 433 | - $res = $f($p); |
|
| 434 | - if ($res !== null and is_object($res)) { |
|
| 435 | - return $res; |
|
| 436 | - } |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Certaines des balises comportant un _ sont generiques |
|
| 440 | - if ($f = strpos($nom, '_') |
|
| 441 | - and $f = charger_fonction(substr($nom, 0, $f + 1), 'balise', true) |
|
| 442 | - ) { |
|
| 443 | - $res = $f($p); |
|
| 444 | - if ($res !== null and is_object($res)) { |
|
| 445 | - return $res; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 450 | - |
|
| 451 | - return $f($nom, $p); |
|
| 430 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 431 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 432 | + $p->balise_calculee = true; |
|
| 433 | + $res = $f($p); |
|
| 434 | + if ($res !== null and is_object($res)) { |
|
| 435 | + return $res; |
|
| 436 | + } |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Certaines des balises comportant un _ sont generiques |
|
| 440 | + if ($f = strpos($nom, '_') |
|
| 441 | + and $f = charger_fonction(substr($nom, 0, $f + 1), 'balise', true) |
|
| 442 | + ) { |
|
| 443 | + $res = $f($p); |
|
| 444 | + if ($res !== null and is_object($res)) { |
|
| 445 | + return $res; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 450 | + |
|
| 451 | + return $f($nom, $p); |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
@@ -476,36 +476,36 @@ discard block |
||
| 476 | 476 | **/ |
| 477 | 477 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 478 | 478 | |
| 479 | - // ca pourrait etre un champ SQL homonyme, |
|
| 480 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 481 | - |
|
| 482 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 483 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 484 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 485 | - $code = addslashes($p->fonctions[0][1]); |
|
| 486 | - $p->code .= " . '$code'"; |
|
| 487 | - } |
|
| 488 | - |
|
| 489 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 490 | - if (strpos($nom, 'ID_') === 0) { |
|
| 491 | - $p->interdire_scripts = false; |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 495 | - // SI le champ SQL n'est pas trouve |
|
| 496 | - // ET si la balise a une forme de couleur |
|
| 497 | - // ET s'il n'y a ni filtre ni etoile |
|
| 498 | - // ALORS retourner la couleur. |
|
| 499 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 500 | - if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 501 | - and !$p->etoile |
|
| 502 | - and !$p->fonctions |
|
| 503 | - ) { |
|
| 504 | - $p->code = "'#$nom'"; |
|
| 505 | - $p->interdire_scripts = false; |
|
| 506 | - } |
|
| 507 | - |
|
| 508 | - return $p; |
|
| 479 | + // ca pourrait etre un champ SQL homonyme, |
|
| 480 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 481 | + |
|
| 482 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 483 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 484 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 485 | + $code = addslashes($p->fonctions[0][1]); |
|
| 486 | + $p->code .= " . '$code'"; |
|
| 487 | + } |
|
| 488 | + |
|
| 489 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 490 | + if (strpos($nom, 'ID_') === 0) { |
|
| 491 | + $p->interdire_scripts = false; |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 495 | + // SI le champ SQL n'est pas trouve |
|
| 496 | + // ET si la balise a une forme de couleur |
|
| 497 | + // ET s'il n'y a ni filtre ni etoile |
|
| 498 | + // ALORS retourner la couleur. |
|
| 499 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 500 | + if (preg_match("/^[A-F]{1,6}$/i", $nom) |
|
| 501 | + and !$p->etoile |
|
| 502 | + and !$p->fonctions |
|
| 503 | + ) { |
|
| 504 | + $p->code = "'#$nom'"; |
|
| 505 | + $p->interdire_scripts = false; |
|
| 506 | + } |
|
| 507 | + |
|
| 508 | + return $p; |
|
| 509 | 509 | } |
| 510 | 510 | |
| 511 | 511 | |
@@ -548,36 +548,36 @@ discard block |
||
| 548 | 548 | **/ |
| 549 | 549 | function calculer_balise_dynamique($p, $nom, $l, $supp = array()) { |
| 550 | 550 | |
| 551 | - if (!balise_distante_interdite($p)) { |
|
| 552 | - $p->code = "''"; |
|
| 553 | - |
|
| 554 | - return $p; |
|
| 555 | - } |
|
| 556 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 557 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 558 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 559 | - $p->fonctions = null; |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - if ($p->param and ($c = $p->param[0])) { |
|
| 563 | - // liste d'arguments commence toujours par la chaine vide |
|
| 564 | - array_shift($c); |
|
| 565 | - // construire la liste d'arguments comme pour un filtre |
|
| 566 | - $param = compose_filtres_args($p, $c, ','); |
|
| 567 | - } else { |
|
| 568 | - $param = ""; |
|
| 569 | - } |
|
| 570 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 571 | - |
|
| 572 | - $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 573 | - join(',', $collecte), |
|
| 574 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 575 | - memoriser_contexte_compil($p), |
|
| 576 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 577 | - |
|
| 578 | - $p->interdire_scripts = false; |
|
| 579 | - |
|
| 580 | - return $p; |
|
| 551 | + if (!balise_distante_interdite($p)) { |
|
| 552 | + $p->code = "''"; |
|
| 553 | + |
|
| 554 | + return $p; |
|
| 555 | + } |
|
| 556 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 557 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 558 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 559 | + $p->fonctions = null; |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + if ($p->param and ($c = $p->param[0])) { |
|
| 563 | + // liste d'arguments commence toujours par la chaine vide |
|
| 564 | + array_shift($c); |
|
| 565 | + // construire la liste d'arguments comme pour un filtre |
|
| 566 | + $param = compose_filtres_args($p, $c, ','); |
|
| 567 | + } else { |
|
| 568 | + $param = ""; |
|
| 569 | + } |
|
| 570 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 571 | + |
|
| 572 | + $p->code = sprintf(CODE_EXECUTER_BALISE, $nom, |
|
| 573 | + join(',', $collecte), |
|
| 574 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 575 | + memoriser_contexte_compil($p), |
|
| 576 | + (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 577 | + |
|
| 578 | + $p->interdire_scripts = false; |
|
| 579 | + |
|
| 580 | + return $p; |
|
| 581 | 581 | } |
| 582 | 582 | |
| 583 | 583 | |
@@ -607,13 +607,13 @@ discard block |
||
| 607 | 607 | * Liste des codes PHP d'éxecution des balises collectées |
| 608 | 608 | **/ |
| 609 | 609 | function collecter_balise_dynamique($l, &$p, $nom) { |
| 610 | - $args = array(); |
|
| 611 | - foreach ($l as $c) { |
|
| 612 | - $x = calculer_balise($c, $p); |
|
| 613 | - $args[] = $x->code; |
|
| 614 | - } |
|
| 610 | + $args = array(); |
|
| 611 | + foreach ($l as $c) { |
|
| 612 | + $x = calculer_balise($c, $p); |
|
| 613 | + $args[] = $x->code; |
|
| 614 | + } |
|
| 615 | 615 | |
| 616 | - return $args; |
|
| 616 | + return $args; |
|
| 617 | 617 | } |
| 618 | 618 | |
| 619 | 619 | |
@@ -628,20 +628,20 @@ discard block |
||
| 628 | 628 | * Nom de la connexion |
| 629 | 629 | **/ |
| 630 | 630 | function trouver_nom_serveur_distant($p) { |
| 631 | - $nom = $p->id_boucle; |
|
| 632 | - if ($nom |
|
| 633 | - and isset($p->boucles[$nom]) |
|
| 634 | - ) { |
|
| 635 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 636 | - if (strlen($s) |
|
| 637 | - and strlen($serveur = strtolower($s)) |
|
| 638 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 639 | - ) { |
|
| 640 | - return $serveur; |
|
| 641 | - } |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - return ""; |
|
| 631 | + $nom = $p->id_boucle; |
|
| 632 | + if ($nom |
|
| 633 | + and isset($p->boucles[$nom]) |
|
| 634 | + ) { |
|
| 635 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 636 | + if (strlen($s) |
|
| 637 | + and strlen($serveur = strtolower($s)) |
|
| 638 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 639 | + ) { |
|
| 640 | + return $serveur; |
|
| 641 | + } |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + return ""; |
|
| 645 | 645 | } |
| 646 | 646 | |
| 647 | 647 | |
@@ -665,15 +665,15 @@ discard block |
||
| 665 | 665 | * - false : La balise est interdite car le serveur est distant |
| 666 | 666 | **/ |
| 667 | 667 | function balise_distante_interdite($p) { |
| 668 | - $nom = $p->id_boucle; |
|
| 668 | + $nom = $p->id_boucle; |
|
| 669 | 669 | |
| 670 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 671 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 670 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 671 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 672 | 672 | |
| 673 | - return false; |
|
| 674 | - } |
|
| 673 | + return false; |
|
| 674 | + } |
|
| 675 | 675 | |
| 676 | - return true; |
|
| 676 | + return true; |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | |
@@ -684,67 +684,67 @@ discard block |
||
| 684 | 684 | // http://code.spip.net/@champs_traitements |
| 685 | 685 | function champs_traitements($p) { |
| 686 | 686 | |
| 687 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 688 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 689 | - } else { |
|
| 690 | - // quand on utilise un traitement catch-all * |
|
| 691 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 692 | - // leur propre securite |
|
| 693 | - if (!$p->balise_calculee) { |
|
| 694 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 695 | - } else { |
|
| 696 | - $ps = false; |
|
| 697 | - } |
|
| 698 | - } |
|
| 699 | - |
|
| 700 | - if (is_array($ps)) { |
|
| 701 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 702 | - $idb = index_boucle($p); |
|
| 703 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 704 | - $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 705 | - $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 706 | - |
|
| 707 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 708 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 709 | - $ps = $ps[$table_sql]; |
|
| 710 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 711 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 712 | - $ps = $ps[$type_requete]; |
|
| 713 | - } // ou pour indiferrement quelle que soit la boucle |
|
| 714 | - elseif (isset($ps[0])) { |
|
| 715 | - $ps = $ps[0]; |
|
| 716 | - } else { |
|
| 717 | - $ps = false; |
|
| 718 | - } |
|
| 719 | - } |
|
| 720 | - |
|
| 721 | - if (!$ps) { |
|
| 722 | - return $p->code; |
|
| 723 | - } |
|
| 724 | - |
|
| 725 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 726 | - // ou si in INCLURE contient {doublons} |
|
| 727 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 728 | - // dans les filtres propre() ou typo() |
|
| 729 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 730 | - |
|
| 731 | - if (isset($p->descr['documents']) |
|
| 732 | - and |
|
| 733 | - $p->descr['documents'] |
|
| 734 | - and ( |
|
| 735 | - (strpos($ps, 'propre') !== false) |
|
| 736 | - or |
|
| 737 | - (strpos($ps, 'typo') !== false) |
|
| 738 | - ) |
|
| 739 | - ) { |
|
| 740 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 741 | - } |
|
| 742 | - |
|
| 743 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 744 | - // dans la declaration des traitements des champs sensibles |
|
| 745 | - |
|
| 746 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 747 | - return str_replace('%s', $p->code, $ps); |
|
| 687 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 688 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 689 | + } else { |
|
| 690 | + // quand on utilise un traitement catch-all * |
|
| 691 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 692 | + // leur propre securite |
|
| 693 | + if (!$p->balise_calculee) { |
|
| 694 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 695 | + } else { |
|
| 696 | + $ps = false; |
|
| 697 | + } |
|
| 698 | + } |
|
| 699 | + |
|
| 700 | + if (is_array($ps)) { |
|
| 701 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 702 | + $idb = index_boucle($p); |
|
| 703 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 704 | + $type_requete = isset($p->boucles[$idb]->type_requete) ? $p->boucles[$idb]->type_requete : false; |
|
| 705 | + $table_sql = isset($p->boucles[$idb]->show['table_sql']) ? $p->boucles[$idb]->show['table_sql'] : false; |
|
| 706 | + |
|
| 707 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 708 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 709 | + $ps = $ps[$table_sql]; |
|
| 710 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 711 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 712 | + $ps = $ps[$type_requete]; |
|
| 713 | + } // ou pour indiferrement quelle que soit la boucle |
|
| 714 | + elseif (isset($ps[0])) { |
|
| 715 | + $ps = $ps[0]; |
|
| 716 | + } else { |
|
| 717 | + $ps = false; |
|
| 718 | + } |
|
| 719 | + } |
|
| 720 | + |
|
| 721 | + if (!$ps) { |
|
| 722 | + return $p->code; |
|
| 723 | + } |
|
| 724 | + |
|
| 725 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 726 | + // ou si in INCLURE contient {doublons} |
|
| 727 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 728 | + // dans les filtres propre() ou typo() |
|
| 729 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 730 | + |
|
| 731 | + if (isset($p->descr['documents']) |
|
| 732 | + and |
|
| 733 | + $p->descr['documents'] |
|
| 734 | + and ( |
|
| 735 | + (strpos($ps, 'propre') !== false) |
|
| 736 | + or |
|
| 737 | + (strpos($ps, 'typo') !== false) |
|
| 738 | + ) |
|
| 739 | + ) { |
|
| 740 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 741 | + } |
|
| 742 | + |
|
| 743 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 744 | + // dans la declaration des traitements des champs sensibles |
|
| 745 | + |
|
| 746 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 747 | + return str_replace('%s', $p->code, $ps); |
|
| 748 | 748 | } |
| 749 | 749 | |
| 750 | 750 | |
@@ -757,109 +757,109 @@ discard block |
||
| 757 | 757 | // http://code.spip.net/@applique_filtres |
| 758 | 758 | function applique_filtres($p) { |
| 759 | 759 | |
| 760 | - // Traitements standards (cf. supra) |
|
| 761 | - if ($p->etoile == '') { |
|
| 762 | - $code = champs_traitements($p); |
|
| 763 | - } else { |
|
| 764 | - $code = $p->code; |
|
| 765 | - } |
|
| 760 | + // Traitements standards (cf. supra) |
|
| 761 | + if ($p->etoile == '') { |
|
| 762 | + $code = champs_traitements($p); |
|
| 763 | + } else { |
|
| 764 | + $code = $p->code; |
|
| 765 | + } |
|
| 766 | 766 | |
| 767 | - // Appliquer les filtres perso |
|
| 768 | - if ($p->param) { |
|
| 769 | - $code = compose_filtres($p, $code); |
|
| 770 | - } |
|
| 767 | + // Appliquer les filtres perso |
|
| 768 | + if ($p->param) { |
|
| 769 | + $code = compose_filtres($p, $code); |
|
| 770 | + } |
|
| 771 | 771 | |
| 772 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 773 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 774 | - if (isset($p->descr['session'])) { |
|
| 775 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 776 | - } |
|
| 772 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 773 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 774 | + if (isset($p->descr['session'])) { |
|
| 775 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 776 | + } |
|
| 777 | 777 | |
| 778 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 778 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 779 | 779 | |
| 780 | - return $code; |
|
| 780 | + return $code; |
|
| 781 | 781 | } |
| 782 | 782 | |
| 783 | 783 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 784 | 784 | // http://code.spip.net/@compose_filtres |
| 785 | 785 | function compose_filtres(&$p, $code) { |
| 786 | 786 | |
| 787 | - $image_miette = false; |
|
| 788 | - foreach ($p->param as $filtre) { |
|
| 789 | - $fonc = array_shift($filtre); |
|
| 790 | - if (!$fonc) { |
|
| 791 | - continue; |
|
| 792 | - } // normalement qu'au premier tour. |
|
| 793 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 794 | - if ($image_miette and !$is_filtre_image) { |
|
| 795 | - // il faut graver maintenant car apres le filtre en cours |
|
| 796 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 797 | - $code = "filtrer('image_graver', $code)"; |
|
| 798 | - $image_miette = false; |
|
| 799 | - } |
|
| 800 | - // recuperer les arguments du filtre, |
|
| 801 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 802 | - if ($fonc !== '?') { |
|
| 803 | - $sep = ','; |
|
| 804 | - } else { |
|
| 805 | - $sep = ':'; |
|
| 806 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 807 | - if (count($filtre) != 2) { |
|
| 808 | - $filtre = array(isset($filtre[0]) ? $filtre[0] : "", isset($filtre[1]) ? $filtre[1] : ""); |
|
| 809 | - } |
|
| 810 | - } |
|
| 811 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 812 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 813 | - if ($logique) { |
|
| 814 | - $code = $logique; |
|
| 815 | - } else { |
|
| 816 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p); |
|
| 817 | - if ($is_filtre_image) { |
|
| 818 | - $image_miette = true; |
|
| 819 | - } |
|
| 820 | - } |
|
| 821 | - } |
|
| 822 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 823 | - if ($image_miette) { |
|
| 824 | - $code = "filtrer('image_graver',$code)"; |
|
| 825 | - } |
|
| 826 | - |
|
| 827 | - return $code; |
|
| 787 | + $image_miette = false; |
|
| 788 | + foreach ($p->param as $filtre) { |
|
| 789 | + $fonc = array_shift($filtre); |
|
| 790 | + if (!$fonc) { |
|
| 791 | + continue; |
|
| 792 | + } // normalement qu'au premier tour. |
|
| 793 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 794 | + if ($image_miette and !$is_filtre_image) { |
|
| 795 | + // il faut graver maintenant car apres le filtre en cours |
|
| 796 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 797 | + $code = "filtrer('image_graver', $code)"; |
|
| 798 | + $image_miette = false; |
|
| 799 | + } |
|
| 800 | + // recuperer les arguments du filtre, |
|
| 801 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 802 | + if ($fonc !== '?') { |
|
| 803 | + $sep = ','; |
|
| 804 | + } else { |
|
| 805 | + $sep = ':'; |
|
| 806 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 807 | + if (count($filtre) != 2) { |
|
| 808 | + $filtre = array(isset($filtre[0]) ? $filtre[0] : "", isset($filtre[1]) ? $filtre[1] : ""); |
|
| 809 | + } |
|
| 810 | + } |
|
| 811 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 812 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 813 | + if ($logique) { |
|
| 814 | + $code = $logique; |
|
| 815 | + } else { |
|
| 816 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p); |
|
| 817 | + if ($is_filtre_image) { |
|
| 818 | + $image_miette = true; |
|
| 819 | + } |
|
| 820 | + } |
|
| 821 | + } |
|
| 822 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 823 | + if ($image_miette) { |
|
| 824 | + $code = "filtrer('image_graver',$code)"; |
|
| 825 | + } |
|
| 826 | + |
|
| 827 | + return $code; |
|
| 828 | 828 | } |
| 829 | 829 | |
| 830 | 830 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 831 | 831 | // et comparateurs |
| 832 | 832 | function filtre_logique($fonc, $code, $arg) { |
| 833 | 833 | |
| 834 | - switch (true) { |
|
| 835 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 836 | - return "($code $fonc $arg)"; |
|
| 837 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 838 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 839 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 840 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 841 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 842 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 843 | - case ($fonc == 'sinon'): |
|
| 844 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 845 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 846 | - return "(($code) ?'' :' ')"; |
|
| 847 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 848 | - return "(($code) ?' ' :'')"; |
|
| 849 | - } |
|
| 850 | - |
|
| 851 | - return ''; |
|
| 834 | + switch (true) { |
|
| 835 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 836 | + return "($code $fonc $arg)"; |
|
| 837 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 838 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 839 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 840 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 841 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 842 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 843 | + case ($fonc == 'sinon'): |
|
| 844 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 845 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 846 | + return "(($code) ?'' :' ')"; |
|
| 847 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 848 | + return "(($code) ?' ' :'')"; |
|
| 849 | + } |
|
| 850 | + |
|
| 851 | + return ''; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | // http://code.spip.net/@compose_filtres_args |
| 855 | 855 | function compose_filtres_args($p, $args, $sep) { |
| 856 | - $arglist = ""; |
|
| 857 | - foreach ($args as $arg) { |
|
| 858 | - $arglist .= $sep . |
|
| 859 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 860 | - } |
|
| 856 | + $arglist = ""; |
|
| 857 | + foreach ($args as $arg) { |
|
| 858 | + $arglist .= $sep . |
|
| 859 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 860 | + } |
|
| 861 | 861 | |
| 862 | - return $arglist; |
|
| 862 | + return $arglist; |
|
| 863 | 863 | } |
| 864 | 864 | |
| 865 | 865 | |
@@ -877,15 +877,15 @@ discard block |
||
| 877 | 877 | **/ |
| 878 | 878 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 879 | 879 | |
| 880 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 881 | - if ($boucles[$idb]->externe) { |
|
| 882 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 883 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 884 | - // on ignore le defaut fourni dans ce cas |
|
| 885 | - $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 886 | - } |
|
| 880 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 881 | + if ($boucles[$idb]->externe) { |
|
| 882 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 883 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 884 | + // on ignore le defaut fourni dans ce cas |
|
| 885 | + $defaut = "@\$Pile[\$SP]['$nom_champ']"; |
|
| 886 | + } |
|
| 887 | 887 | |
| 888 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 888 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 889 | 889 | } |
| 890 | 890 | |
| 891 | 891 | // |
@@ -900,28 +900,28 @@ discard block |
||
| 900 | 900 | |
| 901 | 901 | // http://code.spip.net/@rindex_pile |
| 902 | 902 | function rindex_pile($p, $champ, $motif) { |
| 903 | - $n = 0; |
|
| 904 | - $b = $p->id_boucle; |
|
| 905 | - $p->code = ''; |
|
| 906 | - while ($b != '') { |
|
| 907 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 908 | - if ($critere->op == $motif) { |
|
| 909 | - $p->code = '$Pile[$SP' . (($n == 0) ? "" : "-$n") . |
|
| 910 | - "]['$champ']"; |
|
| 911 | - $b = ''; |
|
| 912 | - break 2; |
|
| 913 | - } |
|
| 914 | - } |
|
| 915 | - $n++; |
|
| 916 | - $b = $p->boucles[$b]->id_parent; |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 920 | - if (!$p->code) { |
|
| 921 | - $p->code = "''"; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $p->interdire_scripts = false; |
|
| 925 | - |
|
| 926 | - return $p; |
|
| 903 | + $n = 0; |
|
| 904 | + $b = $p->id_boucle; |
|
| 905 | + $p->code = ''; |
|
| 906 | + while ($b != '') { |
|
| 907 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 908 | + if ($critere->op == $motif) { |
|
| 909 | + $p->code = '$Pile[$SP' . (($n == 0) ? "" : "-$n") . |
|
| 910 | + "]['$champ']"; |
|
| 911 | + $b = ''; |
|
| 912 | + break 2; |
|
| 913 | + } |
|
| 914 | + } |
|
| 915 | + $n++; |
|
| 916 | + $b = $p->boucles[$b]->id_parent; |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 920 | + if (!$p->code) { |
|
| 921 | + $p->code = "''"; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $p->interdire_scripts = false; |
|
| 925 | + |
|
| 926 | + return $p; |
|
| 927 | 927 | } |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | $select = true |
| 96 | 96 | ) { |
| 97 | 97 | if (!is_string($defaut)) { |
| 98 | - $defaut = '@$Pile[0][\'' . strtolower($nom_champ) . '\']'; |
|
| 98 | + $defaut = '@$Pile[0][\''.strtolower($nom_champ).'\']'; |
|
| 99 | 99 | } |
| 100 | 100 | |
| 101 | 101 | $i = 0; |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | if ($select and !in_array($t, $boucles[$idb]->select)) { |
| 124 | 124 | $boucles[$idb]->select[] = $t; |
| 125 | 125 | } |
| 126 | - $champ = '$Pile[$SP' . ($i ? "-$i" : "") . '][\'' . $c . '\']'; |
|
| 126 | + $champ = '$Pile[$SP'.($i ? "-$i" : "").'][\''.$c.'\']'; |
|
| 127 | 127 | if (!$joker) { |
| 128 | 128 | return index_compose($conditionnel, $champ); |
| 129 | 129 | } |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | function index_compose($conditionnel, $defaut) { |
| 165 | 165 | while ($c = array_pop($conditionnel)) { |
| 166 | 166 | // si on passe defaut = '', ne pas générer d'erreur de compilation. |
| 167 | - $defaut = "($c:(" . ($defaut ? $defaut : "''") . "))"; |
|
| 167 | + $defaut = "($c:(".($defaut ? $defaut : "''")."))"; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | return $defaut; |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | if (!$r) { |
| 212 | 212 | $joker = false; // indiquer a l'appelant |
| 213 | 213 | # continuer pour chercher l'erreur suivante |
| 214 | - return array("'#" . $r . ':' . $nom_champ . "'", ''); |
|
| 214 | + return array("'#".$r.':'.$nom_champ."'", ''); |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | $desc = $boucles[$idb]->show; |
@@ -311,8 +311,8 @@ discard block |
||
| 311 | 311 | $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
| 312 | 312 | } |
| 313 | 313 | if ($t == null) { |
| 314 | - list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 315 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 314 | + list($e, $x) = $excep; #PHP4 affecte de gauche a droite |
|
| 315 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 316 | 316 | $j = $trouver_table($e, $boucle->sql_serveur); |
| 317 | 317 | if (!$j) { |
| 318 | 318 | return array('', ''); |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | $l = (preg_split('/\s*,\s*/', $k)); |
| 325 | 325 | $k = $desc['key']['PRIMARY KEY']; |
| 326 | 326 | if (!in_array($k, $l)) { |
| 327 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 327 | + spip_log("jointure impossible $e ".join(',', $l)); |
|
| 328 | 328 | |
| 329 | 329 | return array('', ''); |
| 330 | 330 | } |
@@ -340,7 +340,7 @@ discard block |
||
| 340 | 340 | // demander a SQL de gerer le synonyme |
| 341 | 341 | // ca permet que excep soit dynamique (Cedric, 2/3/06) |
| 342 | 342 | if ($excep != $nom_champ) { |
| 343 | - $excep .= ' AS ' . $nom_champ; |
|
| 343 | + $excep .= ' AS '.$nom_champ; |
|
| 344 | 344 | } |
| 345 | 345 | |
| 346 | 346 | return array("$t.$excep", $nom_champ); |
@@ -573,7 +573,7 @@ discard block |
||
| 573 | 573 | join(',', $collecte), |
| 574 | 574 | ($collecte ? $param : substr($param, 1)), # virer la virgule |
| 575 | 575 | memoriser_contexte_compil($p), |
| 576 | - (!$supp ? '' : (', ' . join(',', $supp)))); |
|
| 576 | + (!$supp ? '' : (', '.join(',', $supp)))); |
|
| 577 | 577 | |
| 578 | 578 | $p->interdire_scripts = false; |
| 579 | 579 | |
@@ -668,7 +668,7 @@ discard block |
||
| 668 | 668 | $nom = $p->id_boucle; |
| 669 | 669 | |
| 670 | 670 | if ($nom and trouver_nom_serveur_distant($p)) { |
| 671 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 671 | + spip_log($nom.':'.$p->nom_champ.' '._T('zbug_distant_interdit')); |
|
| 672 | 672 | |
| 673 | 673 | return false; |
| 674 | 674 | } |
@@ -737,7 +737,7 @@ discard block |
||
| 737 | 737 | (strpos($ps, 'typo') !== false) |
| 738 | 738 | ) |
| 739 | 739 | ) { |
| 740 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 740 | + $ps = 'traiter_doublons_documents($doublons, '.$ps.')'; |
|
| 741 | 741 | } |
| 742 | 742 | |
| 743 | 743 | // La protection des champs par |safehtml est assuree par les extensions |
@@ -855,7 +855,7 @@ discard block |
||
| 855 | 855 | function compose_filtres_args($p, $args, $sep) { |
| 856 | 856 | $arglist = ""; |
| 857 | 857 | foreach ($args as $arg) { |
| 858 | - $arglist .= $sep . |
|
| 858 | + $arglist .= $sep. |
|
| 859 | 859 | calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
| 860 | 860 | } |
| 861 | 861 | |
@@ -906,7 +906,7 @@ discard block |
||
| 906 | 906 | while ($b != '') { |
| 907 | 907 | foreach ($p->boucles[$b]->criteres as $critere) { |
| 908 | 908 | if ($critere->op == $motif) { |
| 909 | - $p->code = '$Pile[$SP' . (($n == 0) ? "" : "-$n") . |
|
| 909 | + $p->code = '$Pile[$SP'.(($n == 0) ? "" : "-$n"). |
|
| 910 | 910 | "]['$champ']"; |
| 911 | 911 | $b = ''; |
| 912 | 912 | break 2; |
@@ -158,7 +158,7 @@ |
||
| 158 | 158 | * @param string $corps |
| 159 | 159 | * @param array $filtres |
| 160 | 160 | * Tableau de filtres à appliquer. |
| 161 | - * @return mixed|string |
|
| 161 | + * @return string |
|
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | 164 | $series_filtres = func_get_args(); |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | **/ |
| 24 | 24 | |
| 25 | 25 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 26 | - return; |
|
| 26 | + return; |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -41,9 +41,9 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -58,35 +58,35 @@ discard block |
||
| 58 | 58 | * @return string |
| 59 | 59 | */ |
| 60 | 60 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p) { |
| 61 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 62 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 63 | - } |
|
| 64 | - |
|
| 65 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 66 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 67 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 68 | - |
|
| 69 | - // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | - // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | - if (strpbrk($f, ':')) { // Class::method |
|
| 72 | - $refl = new ReflectionMethod($f); |
|
| 73 | - } else { |
|
| 74 | - $refl = new ReflectionFunction($f); |
|
| 75 | - } |
|
| 76 | - $refs = $refl->getParameters(); |
|
| 77 | - if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | - $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | - } else { |
|
| 80 | - $code = "$f($code$arglist)"; |
|
| 81 | - } |
|
| 82 | - } |
|
| 83 | - // le filtre n'existe pas, |
|
| 84 | - // on le notifie |
|
| 85 | - else { |
|
| 86 | - erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - return $code; |
|
| 61 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 62 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 63 | + } |
|
| 64 | + |
|
| 65 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 66 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 67 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 68 | + |
|
| 69 | + // cas particulier : le filtre |set doit acceder a la $Pile |
|
| 70 | + // proto: filtre_set(&$Pile, $val, $args...) |
|
| 71 | + if (strpbrk($f, ':')) { // Class::method |
|
| 72 | + $refl = new ReflectionMethod($f); |
|
| 73 | + } else { |
|
| 74 | + $refl = new ReflectionFunction($f); |
|
| 75 | + } |
|
| 76 | + $refs = $refl->getParameters(); |
|
| 77 | + if (isset($refs[0]) and $refs[0]->name == 'Pile') { |
|
| 78 | + $code = "$f(\$Pile,$code$arglist)"; |
|
| 79 | + } else { |
|
| 80 | + $code = "$f($code$arglist)"; |
|
| 81 | + } |
|
| 82 | + } |
|
| 83 | + // le filtre n'existe pas, |
|
| 84 | + // on le notifie |
|
| 85 | + else { |
|
| 86 | + erreur_squelette(array('zbug_erreur_filtre', array('filtre' => texte_script($fonc))), $p); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + return $code; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | // Calculer un <INCLURE(xx.php)> |
@@ -110,15 +110,15 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 113 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | - // si inexistant, on essaiera a l'execution |
|
| 115 | - if ($path = find_in_path($fichier)) { |
|
| 116 | - $path = "\"$path\""; |
|
| 117 | - } else { |
|
| 118 | - $path = "find_in_path(\"$fichier\")"; |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 113 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 114 | + // si inexistant, on essaiera a l'execution |
|
| 115 | + if ($path = find_in_path($fichier)) { |
|
| 116 | + $path = "\"$path\""; |
|
| 117 | + } else { |
|
| 118 | + $path = "find_in_path(\"$fichier\")"; |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | /** |
@@ -130,19 +130,19 @@ discard block |
||
| 130 | 130 | * @return string |
| 131 | 131 | */ |
| 132 | 132 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 133 | - // Securite |
|
| 134 | - if ($p->interdire_scripts |
|
| 135 | - and $p->etoile != '**' |
|
| 136 | - ) { |
|
| 137 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 138 | - $code = "interdire_scripts($code)"; |
|
| 139 | - } else { |
|
| 140 | - $code = interdire_scripts($r[2]); |
|
| 141 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - return $code; |
|
| 133 | + // Securite |
|
| 134 | + if ($p->interdire_scripts |
|
| 135 | + and $p->etoile != '**' |
|
| 136 | + ) { |
|
| 137 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 138 | + $code = "interdire_scripts($code)"; |
|
| 139 | + } else { |
|
| 140 | + $code = interdire_scripts($r[2]); |
|
| 141 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + return $code; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | |
@@ -161,30 +161,30 @@ discard block |
||
| 161 | 161 | * @return mixed|string |
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | - $series_filtres = func_get_args(); |
|
| 165 | - array_shift($series_filtres);// skel |
|
| 166 | - array_shift($series_filtres);// corps |
|
| 167 | - |
|
| 168 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 169 | - if ($skel['process_ins'] == 'php') { |
|
| 170 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - // recuperer les couples de remplacement |
|
| 174 | - $replace = echapper_php_callback(); |
|
| 175 | - |
|
| 176 | - foreach ($series_filtres as $filtres) { |
|
| 177 | - if (count($filtres)) { |
|
| 178 | - foreach ($filtres as $filtre) { |
|
| 179 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 180 | - $corps = $f($corps); |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // restaurer les echappements |
|
| 187 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 164 | + $series_filtres = func_get_args(); |
|
| 165 | + array_shift($series_filtres);// skel |
|
| 166 | + array_shift($series_filtres);// corps |
|
| 167 | + |
|
| 168 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 169 | + if ($skel['process_ins'] == 'php') { |
|
| 170 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + // recuperer les couples de remplacement |
|
| 174 | + $replace = echapper_php_callback(); |
|
| 175 | + |
|
| 176 | + foreach ($series_filtres as $filtres) { |
|
| 177 | + if (count($filtres)) { |
|
| 178 | + foreach ($filtres as $filtre) { |
|
| 179 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 180 | + $corps = $f($corps); |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // restaurer les echappements |
|
| 187 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | |
@@ -203,21 +203,21 @@ discard block |
||
| 203 | 203 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 204 | 204 | **/ |
| 205 | 205 | function echapper_php_callback($r = null) { |
| 206 | - static $src = array(); |
|
| 207 | - static $dst = array(); |
|
| 206 | + static $src = array(); |
|
| 207 | + static $dst = array(); |
|
| 208 | 208 | |
| 209 | - // si on recoit un tableau, on est en mode echappement |
|
| 210 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 211 | - if (is_array($r)) { |
|
| 212 | - $dst[] = $r[0]; |
|
| 209 | + // si on recoit un tableau, on est en mode echappement |
|
| 210 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 211 | + if (is_array($r)) { |
|
| 212 | + $dst[] = $r[0]; |
|
| 213 | 213 | |
| 214 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 215 | - } |
|
| 214 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 215 | + } |
|
| 216 | 216 | |
| 217 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 218 | - // et on RAZ les remplacements |
|
| 219 | - $r = array($src, $dst); |
|
| 220 | - $src = $dst = array(); |
|
| 217 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 218 | + // et on RAZ les remplacements |
|
| 219 | + $r = array($src, $dst); |
|
| 220 | + $src = $dst = array(); |
|
| 221 | 221 | |
| 222 | - return $r; |
|
| 222 | + return $r; |
|
| 223 | 223 | } |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | * Texte |
| 42 | 42 | */ |
| 43 | 43 | function sandbox_composer_texte($texte, &$p) { |
| 44 | - $code = "'" . str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte) . "'"; |
|
| 44 | + $code = "'".str_replace(array("\\", "'"), array("\\\\", "\\'"), $texte)."'"; |
|
| 45 | 45 | |
| 46 | 46 | return $code; |
| 47 | 47 | } |
@@ -162,8 +162,8 @@ discard block |
||
| 162 | 162 | */ |
| 163 | 163 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 164 | 164 | $series_filtres = func_get_args(); |
| 165 | - array_shift($series_filtres);// skel |
|
| 166 | - array_shift($series_filtres);// corps |
|
| 165 | + array_shift($series_filtres); // skel |
|
| 166 | + array_shift($series_filtres); // corps |
|
| 167 | 167 | |
| 168 | 168 | // proteger les <INCLUDE> et tous les morceaux de php licites |
| 169 | 169 | if ($skel['process_ins'] == 'php') { |
@@ -211,7 +211,7 @@ discard block |
||
| 211 | 211 | if (is_array($r)) { |
| 212 | 212 | $dst[] = $r[0]; |
| 213 | 213 | |
| 214 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 214 | + return $src[] = '___'.md5($r[0]).'___'; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | // si on recoit pas un tableau, on renvoit les couples de substitution |