@@ -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 | } |