@@ -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'); |
@@ -41,234 +41,234 @@ discard block |
||
| 41 | 41 | |
| 42 | 42 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 43 | 43 | |
| 44 | - $skel = null; |
|
| 45 | - $boucle = null; |
|
| 46 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | - |
|
| 48 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | - if (function_exists($nom)) { |
|
| 50 | - return $nom; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | - |
|
| 59 | - // si squelette est deja compile et perenne, le charger |
|
| 60 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | - include_once $phpfile; |
|
| 62 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | - ## eval('?'.'>'.$skel_code); |
|
| 66 | - # spip_log($skel_code, 'comp') |
|
| 67 | - #} |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | - include_once $lib; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | - |
|
| 76 | - if (function_exists($nom)) { |
|
| 77 | - return $nom; |
|
| 78 | - } |
|
| 79 | - |
|
| 80 | - // charger le source, si possible, et compiler |
|
| 81 | - $skel_code = ''; |
|
| 82 | - if (lire_fichier($source, $skel)) { |
|
| 83 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | - if (!$skel_code) { |
|
| 89 | - return false; |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - foreach ($skel_code as $id => $boucle) { |
|
| 93 | - $f = $boucle->return; |
|
| 94 | - try { |
|
| 95 | - eval("return true; $f ;"); |
|
| 96 | - } catch (\ParseError $e) { |
|
| 97 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | - erreur_squelette($msg, $boucle); |
|
| 100 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | - // mais prevenir que c'est mort |
|
| 102 | - $nom = ''; |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // contexte de compil inutile a present |
|
| 106 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | - $skel_code[$id] = $f; |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - $code = ''; |
|
| 111 | - if ($nom) { |
|
| 112 | - // Si le code est bon, concatener et mettre en cache |
|
| 113 | - if (function_exists($nom)) { |
|
| 114 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | - } else { |
|
| 116 | - // code semantiquement faux: bug du compilateur |
|
| 117 | - // $boucle est en fait ici la fct principale du squelette |
|
| 118 | - $msg = _T('zbug_erreur_compilation'); |
|
| 119 | - erreur_squelette($msg, $boucle); |
|
| 120 | - $nom = ''; |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | - // Tracer ce qui vient d'etre compile |
|
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | - |
|
| 128 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | - if ( |
|
| 130 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | - and (_request('var_mode_objet') == $nom) |
|
| 132 | - and (_request('var_mode_affiche') == 'code') |
|
| 133 | - ) { |
|
| 134 | - erreur_squelette(); |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $nom ?: false; |
|
| 44 | + $skel = null; |
|
| 45 | + $boucle = null; |
|
| 46 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 47 | + |
|
| 48 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 49 | + if (function_exists($nom)) { |
|
| 50 | + return $nom; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 54 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 58 | + |
|
| 59 | + // si squelette est deja compile et perenne, le charger |
|
| 60 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 61 | + include_once $phpfile; |
|
| 62 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 63 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 64 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 65 | + ## eval('?'.'>'.$skel_code); |
|
| 66 | + # spip_log($skel_code, 'comp') |
|
| 67 | + #} |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 71 | + include_once $lib; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 75 | + |
|
| 76 | + if (function_exists($nom)) { |
|
| 77 | + return $nom; |
|
| 78 | + } |
|
| 79 | + |
|
| 80 | + // charger le source, si possible, et compiler |
|
| 81 | + $skel_code = ''; |
|
| 82 | + if (lire_fichier($source, $skel)) { |
|
| 83 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 84 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 88 | + if (!$skel_code) { |
|
| 89 | + return false; |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + foreach ($skel_code as $id => $boucle) { |
|
| 93 | + $f = $boucle->return; |
|
| 94 | + try { |
|
| 95 | + eval("return true; $f ;"); |
|
| 96 | + } catch (\ParseError $e) { |
|
| 97 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 98 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 99 | + erreur_squelette($msg, $boucle); |
|
| 100 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 101 | + // mais prevenir que c'est mort |
|
| 102 | + $nom = ''; |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // contexte de compil inutile a present |
|
| 106 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 107 | + $skel_code[$id] = $f; |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + $code = ''; |
|
| 111 | + if ($nom) { |
|
| 112 | + // Si le code est bon, concatener et mettre en cache |
|
| 113 | + if (function_exists($nom)) { |
|
| 114 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 115 | + } else { |
|
| 116 | + // code semantiquement faux: bug du compilateur |
|
| 117 | + // $boucle est en fait ici la fct principale du squelette |
|
| 118 | + $msg = _T('zbug_erreur_compilation'); |
|
| 119 | + erreur_squelette($msg, $boucle); |
|
| 120 | + $nom = ''; |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 125 | + // Tracer ce qui vient d'etre compile |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 127 | + |
|
| 128 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 129 | + if ( |
|
| 130 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 131 | + and (_request('var_mode_objet') == $nom) |
|
| 132 | + and (_request('var_mode_affiche') == 'code') |
|
| 133 | + ) { |
|
| 134 | + erreur_squelette(); |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $nom ?: false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - $code = null; |
|
| 144 | - // Le dernier index est '' (fonction principale) |
|
| 145 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | - if (CODE_COMMENTE) { |
|
| 147 | - $code = " |
|
| 143 | + $code = null; |
|
| 144 | + // Le dernier index est '' (fonction principale) |
|
| 145 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 146 | + if (CODE_COMMENTE) { |
|
| 147 | + $code = " |
|
| 148 | 148 | /* |
| 149 | 149 | * Squelette : $sourcefile |
| 150 | 150 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 151 | 151 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 152 | 152 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 153 | 153 | */ '; |
| 154 | - } |
|
| 154 | + } |
|
| 155 | 155 | |
| 156 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | - ecrire_fichier($phpfile, $code); |
|
| 159 | - } |
|
| 156 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 157 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 158 | + ecrire_fichier($phpfile, $code); |
|
| 159 | + } |
|
| 160 | 160 | |
| 161 | - return $code; |
|
| 161 | + return $code; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // Le squelette compile est-il trop vieux ? |
| 165 | 165 | function squelette_obsolete($skel, $squelette) { |
| 166 | - static $date_change = null; |
|
| 167 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | - // par hit |
|
| 169 | - if (is_null($date_change)) { |
|
| 170 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | - $date_change = @filemtime($fonc); |
|
| 172 | - } # compatibilite |
|
| 173 | - if (defined('_FILE_OPTIONS')) { |
|
| 174 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return ( |
|
| 179 | - (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | - or !@file_exists($skel) |
|
| 181 | - or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | - > ($date = @filemtime($skel))) |
|
| 183 | - or ($date_change > $date) |
|
| 184 | - ); |
|
| 166 | + static $date_change = null; |
|
| 167 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 168 | + // par hit |
|
| 169 | + if (is_null($date_change)) { |
|
| 170 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 171 | + $date_change = @filemtime($fonc); |
|
| 172 | + } # compatibilite |
|
| 173 | + if (defined('_FILE_OPTIONS')) { |
|
| 174 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return ( |
|
| 179 | + (defined('_VAR_MODE') and in_array(_VAR_MODE, ['recalcul', 'preview', 'debug'])) |
|
| 180 | + or !@file_exists($skel) |
|
| 181 | + or ((@file_exists($squelette) ? @filemtime($squelette) : 0) |
|
| 182 | + > ($date = @filemtime($skel))) |
|
| 183 | + or ($date_change > $date) |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - and preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - strpos($corps, '<' . '?') === false |
|
| 227 | - or |
|
| 228 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | - ) |
|
| 231 | - ? 'html' |
|
| 232 | - : 'php'; |
|
| 233 | - |
|
| 234 | - $skel = [ |
|
| 235 | - 'squelette' => $nom, |
|
| 236 | - 'source' => $source, |
|
| 237 | - 'process_ins' => $process_ins, |
|
| 238 | - 'invalideurs' => $cache, |
|
| 239 | - 'entetes' => $headers, |
|
| 240 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | - ]; |
|
| 242 | - |
|
| 243 | - // traiter #FILTRE{} et filtres |
|
| 244 | - if (!isset($filtres[$nom])) { |
|
| 245 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | - } |
|
| 247 | - $filtres_headers = []; |
|
| 248 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | - unset($headers['X-Spip-Filtre']); |
|
| 251 | - } |
|
| 252 | - if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | - include_spip('public/sandbox'); |
|
| 254 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | - |
|
| 256 | - if ($process_ins == 'html') { |
|
| 257 | - $skel['process_ins'] = ( |
|
| 258 | - strpos($corps, '<' . '?') === false |
|
| 259 | - or |
|
| 260 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | - ) |
|
| 263 | - ? 'html' |
|
| 264 | - : 'php'; |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - |
|
| 268 | - $skel['entetes'] = $headers; |
|
| 269 | - $skel['texte'] = $corps; |
|
| 270 | - |
|
| 271 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + and preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + strpos($corps, '<' . '?') === false |
|
| 227 | + or |
|
| 228 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 229 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 230 | + ) |
|
| 231 | + ? 'html' |
|
| 232 | + : 'php'; |
|
| 233 | + |
|
| 234 | + $skel = [ |
|
| 235 | + 'squelette' => $nom, |
|
| 236 | + 'source' => $source, |
|
| 237 | + 'process_ins' => $process_ins, |
|
| 238 | + 'invalideurs' => $cache, |
|
| 239 | + 'entetes' => $headers, |
|
| 240 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 241 | + ]; |
|
| 242 | + |
|
| 243 | + // traiter #FILTRE{} et filtres |
|
| 244 | + if (!isset($filtres[$nom])) { |
|
| 245 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 246 | + } |
|
| 247 | + $filtres_headers = []; |
|
| 248 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 249 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 250 | + unset($headers['X-Spip-Filtre']); |
|
| 251 | + } |
|
| 252 | + if (is_array($filtres[$nom]) || $filtres[$nom] instanceof \Countable ? count($filtres[$nom]) : 0 or count($filtres_headers)) { |
|
| 253 | + include_spip('public/sandbox'); |
|
| 254 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 255 | + |
|
| 256 | + if ($process_ins == 'html') { |
|
| 257 | + $skel['process_ins'] = ( |
|
| 258 | + strpos($corps, '<' . '?') === false |
|
| 259 | + or |
|
| 260 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 261 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 262 | + ) |
|
| 263 | + ? 'html' |
|
| 264 | + : 'php'; |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + |
|
| 268 | + $skel['entetes'] = $headers; |
|
| 269 | + $skel['texte'] = $corps; |
|
| 270 | + |
|
| 271 | + return $skel; |
|
| 272 | 272 | } |
| 273 | 273 | |
| 274 | 274 | // |
@@ -282,7 +282,7 @@ discard block |
||
| 282 | 282 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 283 | 283 | if ($lang_select) lang_select(); |
| 284 | 284 | ?' |
| 285 | - . '>'); |
|
| 285 | + . '>'); |
|
| 286 | 286 | |
| 287 | 287 | /** |
| 288 | 288 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -302,35 +302,35 @@ discard block |
||
| 302 | 302 | * Code PHP pour inclure le squelette de la balise dynamique |
| 303 | 303 | **/ |
| 304 | 304 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 305 | - if ( |
|
| 306 | - strncmp($file, '/', 1) !== 0 |
|
| 307 | - // pas de lien symbolique sous Windows |
|
| 308 | - and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | - ) { |
|
| 310 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - $lang = $context_compil[4]; |
|
| 314 | - if (preg_match(',\W,', $lang)) { |
|
| 315 | - $lang = ''; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $args = array_map('argumenter_squelette', $args); |
|
| 319 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | - } |
|
| 322 | - $args = join(', ', $args); |
|
| 323 | - |
|
| 324 | - $r = sprintf( |
|
| 325 | - CODE_INCLURE_BALISE, |
|
| 326 | - $file, |
|
| 327 | - $lang, |
|
| 328 | - $nom, |
|
| 329 | - $args, |
|
| 330 | - join(', ', array_map('_q', $context_compil)) |
|
| 331 | - ); |
|
| 332 | - |
|
| 333 | - return $r; |
|
| 305 | + if ( |
|
| 306 | + strncmp($file, '/', 1) !== 0 |
|
| 307 | + // pas de lien symbolique sous Windows |
|
| 308 | + and !(stristr(PHP_OS, 'WIN') and str_contains($file, ':')) |
|
| 309 | + ) { |
|
| 310 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + $lang = $context_compil[4]; |
|
| 314 | + if (preg_match(',\W,', $lang)) { |
|
| 315 | + $lang = ''; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $args = array_map('argumenter_squelette', $args); |
|
| 319 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 320 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + } |
|
| 322 | + $args = join(', ', $args); |
|
| 323 | + |
|
| 324 | + $r = sprintf( |
|
| 325 | + CODE_INCLURE_BALISE, |
|
| 326 | + $file, |
|
| 327 | + $lang, |
|
| 328 | + $nom, |
|
| 329 | + $args, |
|
| 330 | + join(', ', array_map('_q', $context_compil)) |
|
| 331 | + ); |
|
| 332 | + |
|
| 333 | + return $r; |
|
| 334 | 334 | } |
| 335 | 335 | |
| 336 | 336 | /** |
@@ -348,18 +348,18 @@ discard block |
||
| 348 | 348 | **/ |
| 349 | 349 | function argumenter_squelette($v) { |
| 350 | 350 | |
| 351 | - if (is_object($v)) { |
|
| 352 | - return var_export($v, true); |
|
| 353 | - } elseif (!is_array($v)) { |
|
| 354 | - return "'" . texte_script((string) $v) . "'"; |
|
| 355 | - } else { |
|
| 356 | - $out = []; |
|
| 357 | - foreach ($v as $k => $val) { |
|
| 358 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | - } |
|
| 351 | + if (is_object($v)) { |
|
| 352 | + return var_export($v, true); |
|
| 353 | + } elseif (!is_array($v)) { |
|
| 354 | + return "'" . texte_script((string) $v) . "'"; |
|
| 355 | + } else { |
|
| 356 | + $out = []; |
|
| 357 | + foreach ($v as $k => $val) { |
|
| 358 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + } |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,13 +378,13 @@ discard block |
||
| 378 | 378 | * @return string |
| 379 | 379 | */ |
| 380 | 380 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 381 | - if (test_espace_prive()) { |
|
| 382 | - return executer_balise_dynamique(...$args); |
|
| 383 | - } |
|
| 384 | - else { |
|
| 385 | - $str_args = base64_encode(serialize($args)); |
|
| 386 | - return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | - } |
|
| 381 | + if (test_espace_prive()) { |
|
| 382 | + return executer_balise_dynamique(...$args); |
|
| 383 | + } |
|
| 384 | + else { |
|
| 385 | + $str_args = base64_encode(serialize($args)); |
|
| 386 | + return "<?" . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?".">\n"; |
|
| 387 | + } |
|
| 388 | 388 | } |
| 389 | 389 | |
| 390 | 390 | |
@@ -415,87 +415,87 @@ discard block |
||
| 415 | 415 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 416 | 416 | **/ |
| 417 | 417 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 418 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | - $nom_balise = $nom; |
|
| 420 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | - $nom_balise_generique = ''; |
|
| 422 | - |
|
| 423 | - $appel_php_depuis_modele = false; |
|
| 424 | - if ( |
|
| 425 | - is_array($context_compil) |
|
| 426 | - and !is_numeric($context_compil[3]) |
|
| 427 | - and empty($context_compil[0]) |
|
| 428 | - and empty($context_compil[1]) |
|
| 429 | - and empty($context_compil[2]) |
|
| 430 | - and empty($context_compil[3]) |
|
| 431 | - ) { |
|
| 432 | - $appel_php_depuis_modele = true; |
|
| 433 | - } |
|
| 434 | - |
|
| 435 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | - // injecter en premier arg le nom de la balise |
|
| 439 | - array_unshift($args, $nom); |
|
| 440 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | - $nom_balise = $nom_balise_generique; |
|
| 443 | - } |
|
| 444 | - unset($balise_generique); |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if (!$fonction_balise) { |
|
| 448 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | - erreur_squelette($msg, $context_compil); |
|
| 450 | - |
|
| 451 | - return ''; |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // retrouver le fichier qui a déclaré la fonction |
|
| 455 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | - } |
|
| 462 | - |
|
| 463 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | - |
|
| 466 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | - |
|
| 468 | - if (!is_array($r)) { |
|
| 469 | - return $r; |
|
| 470 | - } |
|
| 471 | - |
|
| 472 | - // verifier que la fonction dyn est la, |
|
| 473 | - // sinon se replier sur la generique si elle existe |
|
| 474 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | - if ( |
|
| 476 | - $balise_generique = chercher_balise_generique($nom) |
|
| 477 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | - ) { |
|
| 481 | - // et lui injecter en premier arg le nom de la balise |
|
| 482 | - array_unshift($r, $nom); |
|
| 483 | - $nom_balise = $nom_balise_generique; |
|
| 484 | - if (!_DIR_RESTREINT) { |
|
| 485 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | - } |
|
| 487 | - } else { |
|
| 488 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | - erreur_squelette($msg, $context_compil); |
|
| 490 | - |
|
| 491 | - return ''; |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($appel_php_depuis_modele) { |
|
| 496 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | - } |
|
| 498 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 418 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 419 | + $nom_balise = $nom; |
|
| 420 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 421 | + $nom_balise_generique = ''; |
|
| 422 | + |
|
| 423 | + $appel_php_depuis_modele = false; |
|
| 424 | + if ( |
|
| 425 | + is_array($context_compil) |
|
| 426 | + and !is_numeric($context_compil[3]) |
|
| 427 | + and empty($context_compil[0]) |
|
| 428 | + and empty($context_compil[1]) |
|
| 429 | + and empty($context_compil[2]) |
|
| 430 | + and empty($context_compil[3]) |
|
| 431 | + ) { |
|
| 432 | + $appel_php_depuis_modele = true; |
|
| 433 | + } |
|
| 434 | + |
|
| 435 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 436 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 437 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 438 | + // injecter en premier arg le nom de la balise |
|
| 439 | + array_unshift($args, $nom); |
|
| 440 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 441 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 442 | + $nom_balise = $nom_balise_generique; |
|
| 443 | + } |
|
| 444 | + unset($balise_generique); |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if (!$fonction_balise) { |
|
| 448 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 449 | + erreur_squelette($msg, $context_compil); |
|
| 450 | + |
|
| 451 | + return ''; |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // retrouver le fichier qui a déclaré la fonction |
|
| 455 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 456 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 457 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 458 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 459 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 460 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 461 | + } |
|
| 462 | + |
|
| 463 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 464 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 465 | + |
|
| 466 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 467 | + |
|
| 468 | + if (!is_array($r)) { |
|
| 469 | + return $r; |
|
| 470 | + } |
|
| 471 | + |
|
| 472 | + // verifier que la fonction dyn est la, |
|
| 473 | + // sinon se replier sur la generique si elle existe |
|
| 474 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 475 | + if ( |
|
| 476 | + $balise_generique = chercher_balise_generique($nom) |
|
| 477 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 478 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 479 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 480 | + ) { |
|
| 481 | + // et lui injecter en premier arg le nom de la balise |
|
| 482 | + array_unshift($r, $nom); |
|
| 483 | + $nom_balise = $nom_balise_generique; |
|
| 484 | + if (!_DIR_RESTREINT) { |
|
| 485 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 486 | + } |
|
| 487 | + } else { |
|
| 488 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 489 | + erreur_squelette($msg, $context_compil); |
|
| 490 | + |
|
| 491 | + return ''; |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($appel_php_depuis_modele) { |
|
| 496 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 497 | + } |
|
| 498 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 499 | 499 | } |
| 500 | 500 | |
| 501 | 501 | /** |
@@ -510,23 +510,23 @@ discard block |
||
| 510 | 510 | * @return array|null |
| 511 | 511 | */ |
| 512 | 512 | function chercher_balise_generique($nom) { |
| 513 | - if (!str_contains($nom, '_')) { |
|
| 514 | - return null; |
|
| 515 | - } |
|
| 516 | - $nom_generique = $nom; |
|
| 517 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | - if ($fonction_generique) { |
|
| 521 | - return [ |
|
| 522 | - 'nom' => $nom, |
|
| 523 | - 'nom_generique' => $nom_generique, |
|
| 524 | - 'fonction_generique' => $fonction_generique, |
|
| 525 | - ]; |
|
| 526 | - } |
|
| 527 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | - } |
|
| 529 | - return null; |
|
| 513 | + if (!str_contains($nom, '_')) { |
|
| 514 | + return null; |
|
| 515 | + } |
|
| 516 | + $nom_generique = $nom; |
|
| 517 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 518 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 519 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 520 | + if ($fonction_generique) { |
|
| 521 | + return [ |
|
| 522 | + 'nom' => $nom, |
|
| 523 | + 'nom_generique' => $nom_generique, |
|
| 524 | + 'fonction_generique' => $fonction_generique, |
|
| 525 | + ]; |
|
| 526 | + } |
|
| 527 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 528 | + } |
|
| 529 | + return null; |
|
| 530 | 530 | } |
| 531 | 531 | |
| 532 | 532 | |
@@ -550,50 +550,50 @@ discard block |
||
| 550 | 550 | * @return null; |
| 551 | 551 | **/ |
| 552 | 552 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 553 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | - if ( |
|
| 555 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | - and $lang_select !== 'oui' |
|
| 557 | - ) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | - elseif (!strlen($lang)) { |
|
| 561 | - $lang = $GLOBALS['spip_lang']; |
|
| 562 | - } // Cas 3. l'objet est multilingue ! |
|
| 563 | - elseif ( |
|
| 564 | - $lang_select !== 'oui' |
|
| 565 | - and strlen($titre) > 10 |
|
| 566 | - and str_contains($titre, '<multi>') |
|
| 567 | - and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | - ) { |
|
| 569 | - $lang = $GLOBALS['spip_lang']; |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | - lang_select($lang); |
|
| 574 | - |
|
| 575 | - return; |
|
| 553 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 554 | + if ( |
|
| 555 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 556 | + and $lang_select !== 'oui' |
|
| 557 | + ) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 560 | + elseif (!strlen($lang)) { |
|
| 561 | + $lang = $GLOBALS['spip_lang']; |
|
| 562 | + } // Cas 3. l'objet est multilingue ! |
|
| 563 | + elseif ( |
|
| 564 | + $lang_select !== 'oui' |
|
| 565 | + and strlen($titre) > 10 |
|
| 566 | + and str_contains($titre, '<multi>') |
|
| 567 | + and str_contains(echappe_html($titre), '<multi>') |
|
| 568 | + ) { |
|
| 569 | + $lang = $GLOBALS['spip_lang']; |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 573 | + lang_select($lang); |
|
| 574 | + |
|
| 575 | + return; |
|
| 576 | 576 | } |
| 577 | 577 | |
| 578 | 578 | |
| 579 | 579 | // Si un tableau &doublons[articles] est passe en parametre, |
| 580 | 580 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 581 | 581 | function nettoyer_env_doublons($envd) { |
| 582 | - foreach ($envd as $table => $liste) { |
|
| 583 | - $n = ''; |
|
| 584 | - foreach (explode(',', $liste) as $val) { |
|
| 585 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | - $n .= ',' . $val; |
|
| 587 | - } |
|
| 588 | - } |
|
| 589 | - if (strlen($n)) { |
|
| 590 | - $envd[$table] = $n; |
|
| 591 | - } else { |
|
| 592 | - unset($envd[$table]); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $envd; |
|
| 582 | + foreach ($envd as $table => $liste) { |
|
| 583 | + $n = ''; |
|
| 584 | + foreach (explode(',', $liste) as $val) { |
|
| 585 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 586 | + $n .= ',' . $val; |
|
| 587 | + } |
|
| 588 | + } |
|
| 589 | + if (strlen($n)) { |
|
| 590 | + $envd[$table] = $n; |
|
| 591 | + } else { |
|
| 592 | + unset($envd[$table]); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $envd; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -612,21 +612,21 @@ discard block |
||
| 612 | 612 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 613 | 613 | **/ |
| 614 | 614 | function match_self($w) { |
| 615 | - if (is_string($w)) { |
|
| 616 | - return false; |
|
| 617 | - } |
|
| 618 | - if (is_array($w)) { |
|
| 619 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | - return $w; |
|
| 621 | - } |
|
| 622 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | - if ($m = match_self($sw)) { |
|
| 624 | - return $m; |
|
| 625 | - } |
|
| 626 | - } |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - return false; |
|
| 615 | + if (is_string($w)) { |
|
| 616 | + return false; |
|
| 617 | + } |
|
| 618 | + if (is_array($w)) { |
|
| 619 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 620 | + return $w; |
|
| 621 | + } |
|
| 622 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 623 | + if ($m = match_self($sw)) { |
|
| 624 | + return $m; |
|
| 625 | + } |
|
| 626 | + } |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + return false; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | 632 | /** |
@@ -642,16 +642,16 @@ discard block |
||
| 642 | 642 | * est remplacée par son code. |
| 643 | 643 | **/ |
| 644 | 644 | function remplace_sous_requete($w, $sousrequete) { |
| 645 | - if (is_array($w)) { |
|
| 646 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | - return $sousrequete; |
|
| 648 | - } |
|
| 649 | - foreach ($w as $k => $sw) { |
|
| 650 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $w; |
|
| 645 | + if (is_array($w)) { |
|
| 646 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 647 | + return $sousrequete; |
|
| 648 | + } |
|
| 649 | + foreach ($w as $k => $sw) { |
|
| 650 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $w; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -665,17 +665,17 @@ discard block |
||
| 665 | 665 | * - Conditions avec des sous requêtes |
| 666 | 666 | **/ |
| 667 | 667 | function trouver_sous_requetes($where) { |
| 668 | - $where_simples = []; |
|
| 669 | - $where_sous = []; |
|
| 670 | - foreach ($where as $k => $w) { |
|
| 671 | - if (match_self($w)) { |
|
| 672 | - $where_sous[$k] = $w; |
|
| 673 | - } else { |
|
| 674 | - $where_simples[$k] = $w; |
|
| 675 | - } |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return [$where_simples, $where_sous]; |
|
| 668 | + $where_simples = []; |
|
| 669 | + $where_sous = []; |
|
| 670 | + foreach ($where as $k => $w) { |
|
| 671 | + if (match_self($w)) { |
|
| 672 | + $where_sous[$k] = $w; |
|
| 673 | + } else { |
|
| 674 | + $where_simples[$k] = $w; |
|
| 675 | + } |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return [$where_simples, $where_sous]; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -701,292 +701,292 @@ discard block |
||
| 701 | 701 | * @return resource |
| 702 | 702 | */ |
| 703 | 703 | function calculer_select( |
| 704 | - $select = [], |
|
| 705 | - $from = [], |
|
| 706 | - $from_type = [], |
|
| 707 | - $where = [], |
|
| 708 | - $join = [], |
|
| 709 | - $groupby = [], |
|
| 710 | - $orderby = [], |
|
| 711 | - $limit = '', |
|
| 712 | - $having = [], |
|
| 713 | - $table = '', |
|
| 714 | - $id = '', |
|
| 715 | - $serveur = '', |
|
| 716 | - $requeter = true |
|
| 704 | + $select = [], |
|
| 705 | + $from = [], |
|
| 706 | + $from_type = [], |
|
| 707 | + $where = [], |
|
| 708 | + $join = [], |
|
| 709 | + $groupby = [], |
|
| 710 | + $orderby = [], |
|
| 711 | + $limit = '', |
|
| 712 | + $having = [], |
|
| 713 | + $table = '', |
|
| 714 | + $id = '', |
|
| 715 | + $serveur = '', |
|
| 716 | + $requeter = true |
|
| 717 | 717 | ) { |
| 718 | 718 | |
| 719 | - // retirer les criteres vides: |
|
| 720 | - // {X ?} avec X absent de l'URL |
|
| 721 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | - $menage = false; |
|
| 724 | - foreach ($where as $k => $v) { |
|
| 725 | - if (is_array($v) and count($v)) { |
|
| 726 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | - $op = false; |
|
| 728 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | - $op = false; |
|
| 730 | - } else { |
|
| 731 | - $op = $v[0] ?: $v; |
|
| 732 | - } |
|
| 733 | - } else { |
|
| 734 | - $op = $v; |
|
| 735 | - } |
|
| 736 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | - unset($where[$k]); |
|
| 738 | - $menage = true; |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - |
|
| 742 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | - $groupby = array_diff($groupby, ['']); |
|
| 744 | - |
|
| 745 | - // remplacer les sous requetes recursives au calcul |
|
| 746 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | - foreach ($where_sous as $k => $w) { |
|
| 748 | - $menage = true; |
|
| 749 | - // on recupere la sous requete |
|
| 750 | - $sous = match_self($w); |
|
| 751 | - if ($sous[0] == 'SELF') { |
|
| 752 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | - array_push($where_simples, $sous[2]); |
|
| 754 | - $wheresub = [ |
|
| 755 | - $sous[2], |
|
| 756 | - '0=0' |
|
| 757 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | - $jsub = $join; |
|
| 759 | - // trouver les jointures utiles a |
|
| 760 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | - // ie L1.objet='article' |
|
| 762 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | - $i = 0; |
|
| 764 | - do { |
|
| 765 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | - [$sous[1] . ' AS id'], |
|
| 767 | - $from, |
|
| 768 | - $from_type, |
|
| 769 | - $wheresub, |
|
| 770 | - $jsub, |
|
| 771 | - [], |
|
| 772 | - [], |
|
| 773 | - '', |
|
| 774 | - $having, |
|
| 775 | - $table, |
|
| 776 | - $id, |
|
| 777 | - $serveur, |
|
| 778 | - false |
|
| 779 | - ) . ')'); |
|
| 780 | - if (!$i) { |
|
| 781 | - $i = 1; |
|
| 782 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | - foreach ($join as $cle => $wj) { |
|
| 784 | - if ( |
|
| 785 | - (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | - and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | - ) { |
|
| 788 | - $i = 0; |
|
| 789 | - $wheresub[] = $wj[3]; |
|
| 790 | - unset($jsub[$cle][3]); |
|
| 791 | - } |
|
| 792 | - } |
|
| 793 | - } |
|
| 794 | - } while ($i++ < 1); |
|
| 795 | - } |
|
| 796 | - if ($sous[0] == 'SUBSELECT') { |
|
| 797 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | - $sous[1], # select |
|
| 801 | - $sous[2], #from |
|
| 802 | - [], #from_type |
|
| 803 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | - [], #join |
|
| 806 | - $sous[4] ?: [], #groupby |
|
| 807 | - $sous[5] ?: [], #orderby |
|
| 808 | - $sous[6], #limit |
|
| 809 | - $sous[7] ?: [], #having |
|
| 810 | - $table, |
|
| 811 | - $id, |
|
| 812 | - $serveur, |
|
| 813 | - false |
|
| 814 | - ) . ')'); |
|
| 815 | - } |
|
| 816 | - array_pop($where_simples); |
|
| 817 | - } |
|
| 818 | - |
|
| 819 | - foreach ($having as $k => $v) { |
|
| 820 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | - unset($having[$k]); |
|
| 822 | - } |
|
| 823 | - } |
|
| 824 | - |
|
| 825 | - // Installer les jointures. |
|
| 826 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | - |
|
| 830 | - $afrom = []; |
|
| 831 | - $equiv = []; |
|
| 832 | - $k = count($join); |
|
| 833 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | - $cle = $cledef; |
|
| 835 | - // le format de join est : |
|
| 836 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | - if (count($join[$cle]) == 2) { |
|
| 839 | - $join[$cle][] = $join[$cle][1]; |
|
| 840 | - } |
|
| 841 | - if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | - $join[$cle][] = ''; |
|
| 843 | - } |
|
| 844 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | - // pour compat avec ancienne convention |
|
| 847 | - if (is_numeric($cle)) { |
|
| 848 | - $cle = "L$k"; |
|
| 849 | - } |
|
| 850 | - $cle_where_lie = "JOIN-$cle"; |
|
| 851 | - if ( |
|
| 852 | - !$menage |
|
| 853 | - or isset($afrom[$cle]) |
|
| 854 | - or calculer_jointnul($cle, $select) |
|
| 855 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | - or calculer_jointnul($cle, $having) |
|
| 857 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | - ) { |
|
| 859 | - // corriger les references non explicites dans select |
|
| 860 | - // ou groupby |
|
| 861 | - foreach ($select as $i => $s) { |
|
| 862 | - if ($s == $c) { |
|
| 863 | - $select[$i] = "$cle.$c AS $c"; |
|
| 864 | - break; |
|
| 865 | - } |
|
| 866 | - } |
|
| 867 | - foreach ($groupby as $i => $g) { |
|
| 868 | - if ($g == $c) { |
|
| 869 | - $groupby[$i] = "$cle.$c"; |
|
| 870 | - break; |
|
| 871 | - } |
|
| 872 | - } |
|
| 873 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | - // sans recours a preg_match |
|
| 875 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | - $afrom[$t][$cle] = [ |
|
| 877 | - "\n" . |
|
| 878 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | - $from[$cle], |
|
| 880 | - "AS $cle", |
|
| 881 | - 'ON (', |
|
| 882 | - "$cle.$c", |
|
| 883 | - '=', |
|
| 884 | - "$t.$carr", |
|
| 885 | - ($and ? 'AND ' . $and : '') . |
|
| 886 | - ')' |
|
| 887 | - ]; |
|
| 888 | - if (isset($afrom[$cle])) { |
|
| 889 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | - unset($afrom[$cle]); |
|
| 891 | - } |
|
| 892 | - $equiv[] = $carr; |
|
| 893 | - } else { |
|
| 894 | - unset($join[$cledef]); |
|
| 895 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | - unset($where_simples[$cle_where_lie]); |
|
| 897 | - unset($where[$cle_where_lie]); |
|
| 898 | - } |
|
| 899 | - } |
|
| 900 | - unset($from[$cle]); |
|
| 901 | - $k--; |
|
| 902 | - } |
|
| 903 | - |
|
| 904 | - if (count($afrom)) { |
|
| 905 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | - // ou dans |
|
| 910 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | - // qui comporte plusieurs jointures |
|
| 912 | - // ou dans |
|
| 913 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | - |
|
| 920 | - $t = key($from); |
|
| 921 | - $c = current($from); |
|
| 922 | - reset($from); |
|
| 923 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | - if ( |
|
| 925 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | - calculer_jointnul($t, $select, $e) or |
|
| 927 | - calculer_jointnul($t, $join, $e) or |
|
| 928 | - calculer_jointnul($t, $where, $e) or |
|
| 929 | - calculer_jointnul($t, $orderby, $e) or |
|
| 930 | - calculer_jointnul($t, $groupby, $e) or |
|
| 931 | - calculer_jointnul($t, $having, $e)) |
|
| 932 | - && count($afrom[$t]) |
|
| 933 | - ) { |
|
| 934 | - $nfrom = reset($afrom[$t]); |
|
| 935 | - $nt = array_key_first($afrom[$t]); |
|
| 936 | - unset($from[$t]); |
|
| 937 | - $from[$nt] = $nfrom[1]; |
|
| 938 | - unset($afrom[$t][$nt]); |
|
| 939 | - $afrom[$nt] = $afrom[$t]; |
|
| 940 | - unset($afrom[$t]); |
|
| 941 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | - $t = $nfrom[4]; |
|
| 943 | - $alias = ''; |
|
| 944 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | - $oldcle = explode('.', $nfrom[6]); |
|
| 946 | - $oldcle = end($oldcle); |
|
| 947 | - $newcle = explode('.', $nfrom[4]); |
|
| 948 | - $newcle = end($newcle); |
|
| 949 | - if ($newcle != $oldcle) { |
|
| 950 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | - // reprendre simplement ce AS |
|
| 952 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | - $alias = ''; |
|
| 955 | - } else { |
|
| 956 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | - } |
|
| 958 | - } |
|
| 959 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | - } |
|
| 966 | - $from = reinjecte_joint($afrom, $from); |
|
| 967 | - } |
|
| 968 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | - $GLOBALS['debug'] = []; |
|
| 971 | - if ($wasdebug) { |
|
| 972 | - $GLOBALS['debug']['debug'] = true; |
|
| 973 | - } |
|
| 974 | - } |
|
| 975 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | - $r = sql_select( |
|
| 977 | - $select, |
|
| 978 | - $from, |
|
| 979 | - $where, |
|
| 980 | - $groupby, |
|
| 981 | - array_filter($orderby), |
|
| 982 | - $limit, |
|
| 983 | - $having, |
|
| 984 | - $serveur, |
|
| 985 | - $requeter |
|
| 986 | - ); |
|
| 987 | - unset($GLOBALS['debug']['aucasou']); |
|
| 988 | - |
|
| 989 | - return $r; |
|
| 719 | + // retirer les criteres vides: |
|
| 720 | + // {X ?} avec X absent de l'URL |
|
| 721 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 722 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 723 | + $menage = false; |
|
| 724 | + foreach ($where as $k => $v) { |
|
| 725 | + if (is_array($v) and count($v)) { |
|
| 726 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 727 | + $op = false; |
|
| 728 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 729 | + $op = false; |
|
| 730 | + } else { |
|
| 731 | + $op = $v[0] ?: $v; |
|
| 732 | + } |
|
| 733 | + } else { |
|
| 734 | + $op = $v; |
|
| 735 | + } |
|
| 736 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 737 | + unset($where[$k]); |
|
| 738 | + $menage = true; |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + |
|
| 742 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 743 | + $groupby = array_diff($groupby, ['']); |
|
| 744 | + |
|
| 745 | + // remplacer les sous requetes recursives au calcul |
|
| 746 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 747 | + foreach ($where_sous as $k => $w) { |
|
| 748 | + $menage = true; |
|
| 749 | + // on recupere la sous requete |
|
| 750 | + $sous = match_self($w); |
|
| 751 | + if ($sous[0] == 'SELF') { |
|
| 752 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 753 | + array_push($where_simples, $sous[2]); |
|
| 754 | + $wheresub = [ |
|
| 755 | + $sous[2], |
|
| 756 | + '0=0' |
|
| 757 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 758 | + $jsub = $join; |
|
| 759 | + // trouver les jointures utiles a |
|
| 760 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 761 | + // ie L1.objet='article' |
|
| 762 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 763 | + $i = 0; |
|
| 764 | + do { |
|
| 765 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 766 | + [$sous[1] . ' AS id'], |
|
| 767 | + $from, |
|
| 768 | + $from_type, |
|
| 769 | + $wheresub, |
|
| 770 | + $jsub, |
|
| 771 | + [], |
|
| 772 | + [], |
|
| 773 | + '', |
|
| 774 | + $having, |
|
| 775 | + $table, |
|
| 776 | + $id, |
|
| 777 | + $serveur, |
|
| 778 | + false |
|
| 779 | + ) . ')'); |
|
| 780 | + if (!$i) { |
|
| 781 | + $i = 1; |
|
| 782 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 783 | + foreach ($join as $cle => $wj) { |
|
| 784 | + if ( |
|
| 785 | + (is_countable($wj) ? count($wj) : 0) == 4 |
|
| 786 | + and str_contains($wherestring, (string) "{$cle}.") |
|
| 787 | + ) { |
|
| 788 | + $i = 0; |
|
| 789 | + $wheresub[] = $wj[3]; |
|
| 790 | + unset($jsub[$cle][3]); |
|
| 791 | + } |
|
| 792 | + } |
|
| 793 | + } |
|
| 794 | + } while ($i++ < 1); |
|
| 795 | + } |
|
| 796 | + if ($sous[0] == 'SUBSELECT') { |
|
| 797 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 798 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 799 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 800 | + $sous[1], # select |
|
| 801 | + $sous[2], #from |
|
| 802 | + [], #from_type |
|
| 803 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 804 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 805 | + [], #join |
|
| 806 | + $sous[4] ?: [], #groupby |
|
| 807 | + $sous[5] ?: [], #orderby |
|
| 808 | + $sous[6], #limit |
|
| 809 | + $sous[7] ?: [], #having |
|
| 810 | + $table, |
|
| 811 | + $id, |
|
| 812 | + $serveur, |
|
| 813 | + false |
|
| 814 | + ) . ')'); |
|
| 815 | + } |
|
| 816 | + array_pop($where_simples); |
|
| 817 | + } |
|
| 818 | + |
|
| 819 | + foreach ($having as $k => $v) { |
|
| 820 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 821 | + unset($having[$k]); |
|
| 822 | + } |
|
| 823 | + } |
|
| 824 | + |
|
| 825 | + // Installer les jointures. |
|
| 826 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 827 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 828 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 829 | + |
|
| 830 | + $afrom = []; |
|
| 831 | + $equiv = []; |
|
| 832 | + $k = count($join); |
|
| 833 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 834 | + $cle = $cledef; |
|
| 835 | + // le format de join est : |
|
| 836 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 837 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 838 | + if (count($join[$cle]) == 2) { |
|
| 839 | + $join[$cle][] = $join[$cle][1]; |
|
| 840 | + } |
|
| 841 | + if ((is_array($join[$cle]) || $join[$cle] instanceof \Countable ? count($join[$cle]) : 0) == 3) { |
|
| 842 | + $join[$cle][] = ''; |
|
| 843 | + } |
|
| 844 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 845 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 846 | + // pour compat avec ancienne convention |
|
| 847 | + if (is_numeric($cle)) { |
|
| 848 | + $cle = "L$k"; |
|
| 849 | + } |
|
| 850 | + $cle_where_lie = "JOIN-$cle"; |
|
| 851 | + if ( |
|
| 852 | + !$menage |
|
| 853 | + or isset($afrom[$cle]) |
|
| 854 | + or calculer_jointnul($cle, $select) |
|
| 855 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 856 | + or calculer_jointnul($cle, $having) |
|
| 857 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 858 | + ) { |
|
| 859 | + // corriger les references non explicites dans select |
|
| 860 | + // ou groupby |
|
| 861 | + foreach ($select as $i => $s) { |
|
| 862 | + if ($s == $c) { |
|
| 863 | + $select[$i] = "$cle.$c AS $c"; |
|
| 864 | + break; |
|
| 865 | + } |
|
| 866 | + } |
|
| 867 | + foreach ($groupby as $i => $g) { |
|
| 868 | + if ($g == $c) { |
|
| 869 | + $groupby[$i] = "$cle.$c"; |
|
| 870 | + break; |
|
| 871 | + } |
|
| 872 | + } |
|
| 873 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 874 | + // sans recours a preg_match |
|
| 875 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 876 | + $afrom[$t][$cle] = [ |
|
| 877 | + "\n" . |
|
| 878 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 879 | + $from[$cle], |
|
| 880 | + "AS $cle", |
|
| 881 | + 'ON (', |
|
| 882 | + "$cle.$c", |
|
| 883 | + '=', |
|
| 884 | + "$t.$carr", |
|
| 885 | + ($and ? 'AND ' . $and : '') . |
|
| 886 | + ')' |
|
| 887 | + ]; |
|
| 888 | + if (isset($afrom[$cle])) { |
|
| 889 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 890 | + unset($afrom[$cle]); |
|
| 891 | + } |
|
| 892 | + $equiv[] = $carr; |
|
| 893 | + } else { |
|
| 894 | + unset($join[$cledef]); |
|
| 895 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 896 | + unset($where_simples[$cle_where_lie]); |
|
| 897 | + unset($where[$cle_where_lie]); |
|
| 898 | + } |
|
| 899 | + } |
|
| 900 | + unset($from[$cle]); |
|
| 901 | + $k--; |
|
| 902 | + } |
|
| 903 | + |
|
| 904 | + if (count($afrom)) { |
|
| 905 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 906 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 907 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 908 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 909 | + // ou dans |
|
| 910 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 911 | + // qui comporte plusieurs jointures |
|
| 912 | + // ou dans |
|
| 913 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 914 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 915 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 916 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 917 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 918 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 919 | + |
|
| 920 | + $t = key($from); |
|
| 921 | + $c = current($from); |
|
| 922 | + reset($from); |
|
| 923 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 924 | + if ( |
|
| 925 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 926 | + calculer_jointnul($t, $select, $e) or |
|
| 927 | + calculer_jointnul($t, $join, $e) or |
|
| 928 | + calculer_jointnul($t, $where, $e) or |
|
| 929 | + calculer_jointnul($t, $orderby, $e) or |
|
| 930 | + calculer_jointnul($t, $groupby, $e) or |
|
| 931 | + calculer_jointnul($t, $having, $e)) |
|
| 932 | + && count($afrom[$t]) |
|
| 933 | + ) { |
|
| 934 | + $nfrom = reset($afrom[$t]); |
|
| 935 | + $nt = array_key_first($afrom[$t]); |
|
| 936 | + unset($from[$t]); |
|
| 937 | + $from[$nt] = $nfrom[1]; |
|
| 938 | + unset($afrom[$t][$nt]); |
|
| 939 | + $afrom[$nt] = $afrom[$t]; |
|
| 940 | + unset($afrom[$t]); |
|
| 941 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 942 | + $t = $nfrom[4]; |
|
| 943 | + $alias = ''; |
|
| 944 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 945 | + $oldcle = explode('.', $nfrom[6]); |
|
| 946 | + $oldcle = end($oldcle); |
|
| 947 | + $newcle = explode('.', $nfrom[4]); |
|
| 948 | + $newcle = end($newcle); |
|
| 949 | + if ($newcle != $oldcle) { |
|
| 950 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 951 | + // reprendre simplement ce AS |
|
| 952 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 953 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 954 | + $alias = ''; |
|
| 955 | + } else { |
|
| 956 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 957 | + } |
|
| 958 | + } |
|
| 959 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 960 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 961 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 962 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 963 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 964 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 965 | + } |
|
| 966 | + $from = reinjecte_joint($afrom, $from); |
|
| 967 | + } |
|
| 968 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 969 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 970 | + $GLOBALS['debug'] = []; |
|
| 971 | + if ($wasdebug) { |
|
| 972 | + $GLOBALS['debug']['debug'] = true; |
|
| 973 | + } |
|
| 974 | + } |
|
| 975 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 976 | + $r = sql_select( |
|
| 977 | + $select, |
|
| 978 | + $from, |
|
| 979 | + $where, |
|
| 980 | + $groupby, |
|
| 981 | + array_filter($orderby), |
|
| 982 | + $limit, |
|
| 983 | + $having, |
|
| 984 | + $serveur, |
|
| 985 | + $requeter |
|
| 986 | + ); |
|
| 987 | + unset($GLOBALS['debug']['aucasou']); |
|
| 988 | + |
|
| 989 | + return $r; |
|
| 990 | 990 | } |
| 991 | 991 | |
| 992 | 992 | /** |
@@ -997,79 +997,79 @@ discard block |
||
| 997 | 997 | * @return string |
| 998 | 998 | */ |
| 999 | 999 | function calculer_where_to_string($v, $join = 'AND') { |
| 1000 | - if (empty($v)) { |
|
| 1001 | - return ''; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - if (!is_array($v)) { |
|
| 1005 | - return $v; |
|
| 1006 | - } else { |
|
| 1007 | - $exp = ''; |
|
| 1008 | - if (strtoupper($join) === 'AND') { |
|
| 1009 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | - } else { |
|
| 1011 | - return $exp . join($join, $v); |
|
| 1012 | - } |
|
| 1013 | - } |
|
| 1000 | + if (empty($v)) { |
|
| 1001 | + return ''; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + if (!is_array($v)) { |
|
| 1005 | + return $v; |
|
| 1006 | + } else { |
|
| 1007 | + $exp = ''; |
|
| 1008 | + if (strtoupper($join) === 'AND') { |
|
| 1009 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1010 | + } else { |
|
| 1011 | + return $exp . join($join, $v); |
|
| 1012 | + } |
|
| 1013 | + } |
|
| 1014 | 1014 | } |
| 1015 | 1015 | |
| 1016 | 1016 | |
| 1017 | 1017 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1018 | 1018 | |
| 1019 | 1019 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1020 | - if (!is_array($exp)) { |
|
| 1021 | - if ($equiv) { |
|
| 1022 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | - } |
|
| 1024 | - |
|
| 1025 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | - } else { |
|
| 1027 | - foreach ($exp as $v) { |
|
| 1028 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | - return true; |
|
| 1030 | - } |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - return false; |
|
| 1034 | - } |
|
| 1020 | + if (!is_array($exp)) { |
|
| 1021 | + if ($equiv) { |
|
| 1022 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1023 | + } |
|
| 1024 | + |
|
| 1025 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1026 | + } else { |
|
| 1027 | + foreach ($exp as $v) { |
|
| 1028 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1029 | + return true; |
|
| 1030 | + } |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + return false; |
|
| 1034 | + } |
|
| 1035 | 1035 | } |
| 1036 | 1036 | |
| 1037 | 1037 | function reinjecte_joint($afrom, $from) { |
| 1038 | - $from_synth = []; |
|
| 1039 | - foreach ($from as $k => $v) { |
|
| 1040 | - $from_synth[$k] = $from[$k]; |
|
| 1041 | - if (isset($afrom[$k])) { |
|
| 1042 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | - } |
|
| 1045 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | - unset($afrom[$k]); |
|
| 1047 | - } |
|
| 1048 | - } |
|
| 1049 | - |
|
| 1050 | - return $from_synth; |
|
| 1038 | + $from_synth = []; |
|
| 1039 | + foreach ($from as $k => $v) { |
|
| 1040 | + $from_synth[$k] = $from[$k]; |
|
| 1041 | + if (isset($afrom[$k])) { |
|
| 1042 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1043 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1044 | + } |
|
| 1045 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1046 | + unset($afrom[$k]); |
|
| 1047 | + } |
|
| 1048 | + } |
|
| 1049 | + |
|
| 1050 | + return $from_synth; |
|
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1054 | - if (!is_array($exp)) { |
|
| 1055 | - return preg_replace($equiv, $cle, $exp); |
|
| 1056 | - } else { |
|
| 1057 | - foreach ($exp as $k => $v) { |
|
| 1058 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | - } |
|
| 1060 | - |
|
| 1061 | - return $exp; |
|
| 1062 | - } |
|
| 1054 | + if (!is_array($exp)) { |
|
| 1055 | + return preg_replace($equiv, $cle, $exp); |
|
| 1056 | + } else { |
|
| 1057 | + foreach ($exp as $k => $v) { |
|
| 1058 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1059 | + } |
|
| 1060 | + |
|
| 1061 | + return $exp; |
|
| 1062 | + } |
|
| 1063 | 1063 | } |
| 1064 | 1064 | |
| 1065 | 1065 | // calcul du nom du squelette |
| 1066 | 1066 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1067 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | - } |
|
| 1071 | - |
|
| 1072 | - return $mime_type |
|
| 1073 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1067 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1068 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1069 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1070 | + } |
|
| 1071 | + |
|
| 1072 | + return $mime_type |
|
| 1073 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1074 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1075 | 1075 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | * @package SPIP\Core\Public\Styliser |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -29,193 +29,193 @@ discard block |
||
| 29 | 29 | * @return array Données modifiées du pipeline |
| 30 | 30 | */ |
| 31 | 31 | function public_styliser_par_z_dist($flux) { |
| 32 | - static $prefix_path = null; |
|
| 33 | - static $prefix_length; |
|
| 34 | - static $z_blocs; |
|
| 35 | - static $apl_constant; |
|
| 36 | - static $page; |
|
| 37 | - static $disponible = []; |
|
| 38 | - static $echafauder; |
|
| 39 | - static $prepend = ''; |
|
| 40 | - |
|
| 41 | - if (!isset($prefix_path)) { |
|
| 42 | - $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | - if (test_espace_prive()) { |
|
| 44 | - $prefix_path = 'prive/squelettes/'; |
|
| 45 | - $prefix_length = strlen($prefix_path); |
|
| 46 | - $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | - $page = 'exec'; |
|
| 48 | - $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | - define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | - } else { |
|
| 51 | - $prefix_path = ''; |
|
| 52 | - $prefix_length = 0; |
|
| 53 | - $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | - $page = _SPIP_PAGE; |
|
| 55 | - $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | - define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | - _DIR_PLUGIN_DIST, |
|
| 58 | - '/' |
|
| 59 | - ) : '')); |
|
| 60 | - } |
|
| 61 | - $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | - } |
|
| 63 | - $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | - |
|
| 65 | - $fond = $flux['args']['fond']; |
|
| 66 | - |
|
| 67 | - if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | - $fond = substr($fond, $prefix_length); |
|
| 69 | - $squelette = $flux['data']; |
|
| 70 | - $ext = $flux['args']['ext']; |
|
| 71 | - // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | - if ( |
|
| 73 | - defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | - and $dir = explode('/', $fond) |
|
| 75 | - and count($dir) == 2 // pas un sous repertoire |
|
| 76 | - and $dir = reset($dir) |
|
| 77 | - and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | - and defined($apl_constant) |
|
| 79 | - and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | - and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | - ) { |
|
| 82 | - $flux['data'] = $pipe; |
|
| 83 | - |
|
| 84 | - return $flux; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | - if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | - $squelette = ''; |
|
| 90 | - $echafauder = ''; |
|
| 91 | - } |
|
| 92 | - if ($prepend) { |
|
| 93 | - $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | - if ($squelette) { |
|
| 95 | - $flux['data'] = $squelette; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - // gerer les squelettes non trouves |
|
| 100 | - // -> router vers les /dist.html |
|
| 101 | - // ou scaffolding ou page automatique les contenus |
|
| 102 | - if (!$squelette) { |
|
| 103 | - // si on est sur un ?page=XX non trouve |
|
| 104 | - if ( |
|
| 105 | - (isset($flux['args']['contexte'][$page]) |
|
| 106 | - and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | - or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | - and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | - or ($fond == 'sommaire' |
|
| 110 | - and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | - ) { |
|
| 112 | - // si on est sur un ?page=XX non trouve |
|
| 113 | - // se brancher sur contenu/xx si il existe |
|
| 114 | - // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | - if (!isset($disponible[$fond])) { |
|
| 116 | - $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - if ($disponible[$fond]) { |
|
| 120 | - $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // echafaudage : |
|
| 125 | - // si c'est un fond de contenu d'un objet en base |
|
| 126 | - // generer un fond automatique a la volee pour les webmestres |
|
| 127 | - elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | - $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | - $type = $flux['args']['contexte'][$page]; |
|
| 131 | - } |
|
| 132 | - if (!isset($disponible[$type])) { |
|
| 133 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | - } |
|
| 135 | - if (is_string($disponible[$type])) { |
|
| 136 | - $flux['data'] = $disponible[$type]; |
|
| 137 | - } elseif ( |
|
| 138 | - $echafauder |
|
| 139 | - and include_spip('inc/autoriser') |
|
| 140 | - and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | - and autoriser('echafauder', $type) |
|
| 142 | - and $is = $disponible[$type] |
|
| 143 | - and is_array($is) |
|
| 144 | - ) { |
|
| 145 | - $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | - } else { |
|
| 147 | - $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | - $prefix_path . $prepend, |
|
| 149 | - $z_contenu, |
|
| 150 | - '404', |
|
| 151 | - $ext, |
|
| 152 | - $echafauder |
|
| 153 | - )); |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | - // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | - // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | - else { |
|
| 161 | - if ( |
|
| 162 | - $dir = explode('/', $fond) |
|
| 163 | - and $dir = reset($dir) |
|
| 164 | - and $dir !== $z_contenu |
|
| 165 | - and in_array($dir, $z_blocs) |
|
| 166 | - ) { |
|
| 167 | - $type = substr($fond, strlen("$dir/")); |
|
| 168 | - if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | - $type = $flux['args']['contexte'][$page]; |
|
| 170 | - } |
|
| 171 | - if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | - $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | - } |
|
| 174 | - if ($type == 'page' or $disponible[$type]) { |
|
| 175 | - $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - } |
|
| 179 | - $squelette = $flux['data']; |
|
| 180 | - } |
|
| 181 | - // layout specifiques par type et compositions : |
|
| 182 | - // body-article.html |
|
| 183 | - // body-sommaire.html |
|
| 184 | - // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | - // meme dossier que body.html |
|
| 186 | - if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | - if ( |
|
| 188 | - isset($flux['args']['contexte']['type-page']) |
|
| 189 | - and ( |
|
| 190 | - (isset($flux['args']['contexte']['composition']) |
|
| 191 | - and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | - or |
|
| 193 | - file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | - ) |
|
| 195 | - ) { |
|
| 196 | - $flux['data'] = $f; |
|
| 197 | - } |
|
| 198 | - } elseif ( |
|
| 199 | - $fond == 'structure' |
|
| 200 | - and z_sanitize_var_zajax() |
|
| 201 | - and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | - ) { |
|
| 203 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | - } // chercher le fond correspondant a la composition |
|
| 205 | - elseif ( |
|
| 206 | - isset($flux['args']['contexte']['composition']) |
|
| 207 | - and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | - and $dir = substr($fond, $prefix_length) |
|
| 209 | - and $dir = explode('/', $dir) |
|
| 210 | - and $dir = reset($dir) |
|
| 211 | - and in_array($dir, $z_blocs) |
|
| 212 | - and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | - ) { |
|
| 214 | - $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | - } |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - return $flux; |
|
| 32 | + static $prefix_path = null; |
|
| 33 | + static $prefix_length; |
|
| 34 | + static $z_blocs; |
|
| 35 | + static $apl_constant; |
|
| 36 | + static $page; |
|
| 37 | + static $disponible = []; |
|
| 38 | + static $echafauder; |
|
| 39 | + static $prepend = ''; |
|
| 40 | + |
|
| 41 | + if (!isset($prefix_path)) { |
|
| 42 | + $z_blocs = z_blocs(test_espace_prive()); |
|
| 43 | + if (test_espace_prive()) { |
|
| 44 | + $prefix_path = 'prive/squelettes/'; |
|
| 45 | + $prefix_length = strlen($prefix_path); |
|
| 46 | + $apl_constant = '_ECRIRE_AJAX_PARALLEL_LOAD'; |
|
| 47 | + $page = 'exec'; |
|
| 48 | + $echafauder = charger_fonction('echafauder', 'prive', true); |
|
| 49 | + define('_ZCORE_EXCLURE_PATH', ''); |
|
| 50 | + } else { |
|
| 51 | + $prefix_path = ''; |
|
| 52 | + $prefix_length = 0; |
|
| 53 | + $apl_constant = '_Z_AJAX_PARALLEL_LOAD'; |
|
| 54 | + $page = _SPIP_PAGE; |
|
| 55 | + $echafauder = charger_fonction('echafauder', 'public', true); |
|
| 56 | + define('_ZCORE_EXCLURE_PATH', '\bprive|\bsquelettes-dist' . (defined('_DIR_PLUGIN_DIST') ? '|\b' . rtrim( |
|
| 57 | + _DIR_PLUGIN_DIST, |
|
| 58 | + '/' |
|
| 59 | + ) : '')); |
|
| 60 | + } |
|
| 61 | + $prepend = (defined('_Z_PREPEND_PATH') ? _Z_PREPEND_PATH : ''); |
|
| 62 | + } |
|
| 63 | + $z_contenu = reset($z_blocs); // contenu par defaut |
|
| 64 | + |
|
| 65 | + $fond = $flux['args']['fond']; |
|
| 66 | + |
|
| 67 | + if ($prepend or strncmp($fond, $prefix_path, $prefix_length) == 0) { |
|
| 68 | + $fond = substr($fond, $prefix_length); |
|
| 69 | + $squelette = $flux['data']; |
|
| 70 | + $ext = $flux['args']['ext']; |
|
| 71 | + // Ajax Parallel loading : ne pas calculer le bloc, mais renvoyer un js qui le loadera en ajax |
|
| 72 | + if ( |
|
| 73 | + defined('_Z_AJAX_PARALLEL_LOAD_OK') |
|
| 74 | + and $dir = explode('/', $fond) |
|
| 75 | + and count($dir) == 2 // pas un sous repertoire |
|
| 76 | + and $dir = reset($dir) |
|
| 77 | + and in_array($dir, $z_blocs) // verifier deja qu'on est dans un bloc Z |
|
| 78 | + and defined($apl_constant) |
|
| 79 | + and in_array($dir, explode(',', constant($apl_constant))) // et dans un demande en APL |
|
| 80 | + and $pipe = z_trouver_bloc($prefix_path . $prepend, $dir, 'z_apl', $ext) // et qui contient le squelette APL |
|
| 81 | + ) { |
|
| 82 | + $flux['data'] = $pipe; |
|
| 83 | + |
|
| 84 | + return $flux; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // surcharger aussi les squelettes venant de squelettes-dist/ |
|
| 88 | + if ($squelette and !z_fond_valide($squelette)) { |
|
| 89 | + $squelette = ''; |
|
| 90 | + $echafauder = ''; |
|
| 91 | + } |
|
| 92 | + if ($prepend) { |
|
| 93 | + $squelette = substr(find_in_path($prefix_path . $prepend . "$fond.$ext"), 0, -strlen(".$ext")); |
|
| 94 | + if ($squelette) { |
|
| 95 | + $flux['data'] = $squelette; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + // gerer les squelettes non trouves |
|
| 100 | + // -> router vers les /dist.html |
|
| 101 | + // ou scaffolding ou page automatique les contenus |
|
| 102 | + if (!$squelette) { |
|
| 103 | + // si on est sur un ?page=XX non trouve |
|
| 104 | + if ( |
|
| 105 | + (isset($flux['args']['contexte'][$page]) |
|
| 106 | + and $flux['args']['contexte'][$page] == $fond) |
|
| 107 | + or (isset($flux['args']['contexte']['type-page']) |
|
| 108 | + and $flux['args']['contexte']['type-page'] == $fond) |
|
| 109 | + or ($fond == 'sommaire' |
|
| 110 | + and (!isset($flux['args']['contexte'][$page]) or !$flux['args']['contexte'][$page])) |
|
| 111 | + ) { |
|
| 112 | + // si on est sur un ?page=XX non trouve |
|
| 113 | + // se brancher sur contenu/xx si il existe |
|
| 114 | + // ou si c'est un objet spip, associe a une table, utiliser le fond homonyme |
|
| 115 | + if (!isset($disponible[$fond])) { |
|
| 116 | + $disponible[$fond] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $fond, $ext, $echafauder); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + if ($disponible[$fond]) { |
|
| 120 | + $flux['data'] = substr(find_in_path($prefix_path . "page.$ext"), 0, -strlen(".$ext")); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // echafaudage : |
|
| 125 | + // si c'est un fond de contenu d'un objet en base |
|
| 126 | + // generer un fond automatique a la volee pour les webmestres |
|
| 127 | + elseif (strncmp($fond, "$z_contenu/", strlen($z_contenu) + 1) == 0) { |
|
| 128 | + $type = substr($fond, strlen($z_contenu) + 1); |
|
| 129 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 130 | + $type = $flux['args']['contexte'][$page]; |
|
| 131 | + } |
|
| 132 | + if (!isset($disponible[$type])) { |
|
| 133 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 134 | + } |
|
| 135 | + if (is_string($disponible[$type])) { |
|
| 136 | + $flux['data'] = $disponible[$type]; |
|
| 137 | + } elseif ( |
|
| 138 | + $echafauder |
|
| 139 | + and include_spip('inc/autoriser') |
|
| 140 | + and isset($GLOBALS['visiteur_session']['statut']) // performance |
|
| 141 | + and autoriser('echafauder', $type) |
|
| 142 | + and $is = $disponible[$type] |
|
| 143 | + and is_array($is) |
|
| 144 | + ) { |
|
| 145 | + $flux['data'] = $echafauder($type, $is[0], $is[1], $is[2], $ext); |
|
| 146 | + } else { |
|
| 147 | + $flux['data'] = ($disponible['404'] = z_contenu_disponible( |
|
| 148 | + $prefix_path . $prepend, |
|
| 149 | + $z_contenu, |
|
| 150 | + '404', |
|
| 151 | + $ext, |
|
| 152 | + $echafauder |
|
| 153 | + )); |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // sinon, si on demande un fond non trouve dans un des autres blocs |
|
| 158 | + // et si il y a bien un contenu correspondant ou echafaudable |
|
| 159 | + // se rabbatre sur le dist.html du bloc concerne |
|
| 160 | + else { |
|
| 161 | + if ( |
|
| 162 | + $dir = explode('/', $fond) |
|
| 163 | + and $dir = reset($dir) |
|
| 164 | + and $dir !== $z_contenu |
|
| 165 | + and in_array($dir, $z_blocs) |
|
| 166 | + ) { |
|
| 167 | + $type = substr($fond, strlen("$dir/")); |
|
| 168 | + if (($type == 'page') and isset($flux['args']['contexte'][$page])) { |
|
| 169 | + $type = $flux['args']['contexte'][$page]; |
|
| 170 | + } |
|
| 171 | + if ($type !== 'page' and !isset($disponible[$type])) { |
|
| 172 | + $disponible[$type] = z_contenu_disponible($prefix_path . $prepend, $z_contenu, $type, $ext, $echafauder); |
|
| 173 | + } |
|
| 174 | + if ($type == 'page' or $disponible[$type]) { |
|
| 175 | + $flux['data'] = z_trouver_bloc($prefix_path . $prepend, $dir, 'dist', $ext); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + } |
|
| 179 | + $squelette = $flux['data']; |
|
| 180 | + } |
|
| 181 | + // layout specifiques par type et compositions : |
|
| 182 | + // body-article.html |
|
| 183 | + // body-sommaire.html |
|
| 184 | + // pour des raisons de perfo, les declinaisons doivent etre dans le |
|
| 185 | + // meme dossier que body.html |
|
| 186 | + if ($fond == 'body' and substr($squelette, -strlen($fond)) == $fond) { |
|
| 187 | + if ( |
|
| 188 | + isset($flux['args']['contexte']['type-page']) |
|
| 189 | + and ( |
|
| 190 | + (isset($flux['args']['contexte']['composition']) |
|
| 191 | + and file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page'] . '-' . $flux['args']['contexte']['composition']) . ".$ext")) |
|
| 192 | + or |
|
| 193 | + file_exists(($f = $squelette . '-' . $flux['args']['contexte']['type-page']) . ".$ext") |
|
| 194 | + ) |
|
| 195 | + ) { |
|
| 196 | + $flux['data'] = $f; |
|
| 197 | + } |
|
| 198 | + } elseif ( |
|
| 199 | + $fond == 'structure' |
|
| 200 | + and z_sanitize_var_zajax() |
|
| 201 | + and $f = find_in_path($prefix_path . $prepend . 'ajax' . ".$ext") |
|
| 202 | + ) { |
|
| 203 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 204 | + } // chercher le fond correspondant a la composition |
|
| 205 | + elseif ( |
|
| 206 | + isset($flux['args']['contexte']['composition']) |
|
| 207 | + and (basename($fond) == 'page' or ($squelette and substr($squelette, -strlen($fond)) == $fond)) |
|
| 208 | + and $dir = substr($fond, $prefix_length) |
|
| 209 | + and $dir = explode('/', $dir) |
|
| 210 | + and $dir = reset($dir) |
|
| 211 | + and in_array($dir, $z_blocs) |
|
| 212 | + and $f = find_in_path($prefix_path . $prepend . $fond . '-' . $flux['args']['contexte']['composition'] . ".$ext") |
|
| 213 | + ) { |
|
| 214 | + $flux['data'] = substr($f, 0, -strlen(".$ext")); |
|
| 215 | + } |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + return $flux; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -225,18 +225,18 @@ discard block |
||
| 225 | 225 | * @return array |
| 226 | 226 | */ |
| 227 | 227 | function z_blocs($espace_prive = false) { |
| 228 | - if ($espace_prive) { |
|
| 229 | - return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | - 'contenu', |
|
| 231 | - 'navigation', |
|
| 232 | - 'extra', |
|
| 233 | - 'head', |
|
| 234 | - 'hierarchie', |
|
| 235 | - 'top' |
|
| 236 | - ]); |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 228 | + if ($espace_prive) { |
|
| 229 | + return ($GLOBALS['z_blocs_ecrire'] ?? [ |
|
| 230 | + 'contenu', |
|
| 231 | + 'navigation', |
|
| 232 | + 'extra', |
|
| 233 | + 'head', |
|
| 234 | + 'hierarchie', |
|
| 235 | + 'top' |
|
| 236 | + ]); |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return ($GLOBALS['z_blocs'] ?? ['contenu']); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * @return mixed |
| 252 | 252 | */ |
| 253 | 253 | function z_contenu_disponible($prefix_path, $z_contenu, $type, $ext, $echafauder = true) { |
| 254 | - if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | - return $d; |
|
| 256 | - } |
|
| 254 | + if ($d = z_trouver_bloc($prefix_path, $z_contenu, $type, $ext)) { |
|
| 255 | + return $d; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return $echafauder ? z_echafaudable($type) : false; |
|
| 258 | + return $echafauder ? z_echafaudable($type) : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | /** |
@@ -269,14 +269,14 @@ discard block |
||
| 269 | 269 | * `true` si on peut l'utiliser, `false` sinon. |
| 270 | 270 | **/ |
| 271 | 271 | function z_fond_valide($squelette) { |
| 272 | - if ( |
|
| 273 | - !_ZCORE_EXCLURE_PATH |
|
| 274 | - or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | - ) { |
|
| 276 | - return true; |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - return false; |
|
| 272 | + if ( |
|
| 273 | + !_ZCORE_EXCLURE_PATH |
|
| 274 | + or !preg_match(',(' . _ZCORE_EXCLURE_PATH . ')/,', $squelette) |
|
| 275 | + ) { |
|
| 276 | + return true; |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + return false; |
|
| 280 | 280 | } |
| 281 | 281 | |
| 282 | 282 | /** |
@@ -294,14 +294,14 @@ discard block |
||
| 294 | 294 | * @return string |
| 295 | 295 | */ |
| 296 | 296 | function z_trouver_bloc($prefix_path, $bloc, $fond, $ext) { |
| 297 | - if ( |
|
| 298 | - (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | - or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | - ) { |
|
| 301 | - return substr($f, 0, -strlen(".$ext")); |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - return ''; |
|
| 297 | + if ( |
|
| 298 | + (defined('_ZCORE_BLOC_PREFIX_SKEL') and $f = find_in_path("$prefix_path$bloc/$bloc.$fond.$ext") and z_fond_valide($f)) |
|
| 299 | + or ($f = find_in_path("$prefix_path$bloc/$fond.$ext") and z_fond_valide($f)) |
|
| 300 | + ) { |
|
| 301 | + return substr($f, 0, -strlen(".$ext")); |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + return ''; |
|
| 305 | 305 | } |
| 306 | 306 | |
| 307 | 307 | /** |
@@ -313,52 +313,52 @@ discard block |
||
| 313 | 313 | * @return bool |
| 314 | 314 | */ |
| 315 | 315 | function z_echafaudable($type) { |
| 316 | - static $pages = null; |
|
| 317 | - static $echafaudable = []; |
|
| 318 | - if (isset($echafaudable[$type])) { |
|
| 319 | - return $echafaudable[$type]; |
|
| 320 | - } |
|
| 321 | - if (preg_match(',[^\w],', $type)) { |
|
| 322 | - return $echafaudable[$type] = false; |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - if (test_espace_prive()) { |
|
| 326 | - if (!function_exists('trouver_objet_exec')) { |
|
| 327 | - include_spip('inc/pipelines_ecrire'); |
|
| 328 | - } |
|
| 329 | - if ($e = trouver_objet_exec($type)) { |
|
| 330 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | - } else { |
|
| 332 | - // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | - if ( |
|
| 334 | - ($t = objet_type($type, false)) !== $type |
|
| 335 | - and $e = trouver_objet_exec($t) |
|
| 336 | - ) { |
|
| 337 | - return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - } else { |
|
| 341 | - if (is_null($pages)) { |
|
| 342 | - $pages = []; |
|
| 343 | - $liste = lister_tables_objets_sql(); |
|
| 344 | - foreach ($liste as $t => $d) { |
|
| 345 | - if ($d['page']) { |
|
| 346 | - $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | - } |
|
| 348 | - } |
|
| 349 | - } |
|
| 350 | - if (!isset($pages[$type])) { |
|
| 351 | - return $echafaudable[$type] = false; |
|
| 352 | - } |
|
| 353 | - if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | - $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - return $echafaudable[$type] = $pages[$type]; |
|
| 359 | - } |
|
| 360 | - |
|
| 361 | - return $echafaudable[$type] = false; |
|
| 316 | + static $pages = null; |
|
| 317 | + static $echafaudable = []; |
|
| 318 | + if (isset($echafaudable[$type])) { |
|
| 319 | + return $echafaudable[$type]; |
|
| 320 | + } |
|
| 321 | + if (preg_match(',[^\w],', $type)) { |
|
| 322 | + return $echafaudable[$type] = false; |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + if (test_espace_prive()) { |
|
| 326 | + if (!function_exists('trouver_objet_exec')) { |
|
| 327 | + include_spip('inc/pipelines_ecrire'); |
|
| 328 | + } |
|
| 329 | + if ($e = trouver_objet_exec($type)) { |
|
| 330 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $e]; |
|
| 331 | + } else { |
|
| 332 | + // peut etre c'est un exec=types qui liste tous les objets "type" |
|
| 333 | + if ( |
|
| 334 | + ($t = objet_type($type, false)) !== $type |
|
| 335 | + and $e = trouver_objet_exec($t) |
|
| 336 | + ) { |
|
| 337 | + return $echafaudable[$type] = [$e['table'], $e['table_objet_sql'], $t]; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + } else { |
|
| 341 | + if (is_null($pages)) { |
|
| 342 | + $pages = []; |
|
| 343 | + $liste = lister_tables_objets_sql(); |
|
| 344 | + foreach ($liste as $t => $d) { |
|
| 345 | + if ($d['page']) { |
|
| 346 | + $pages[$d['page']] = [$d['table_objet'], $t]; |
|
| 347 | + } |
|
| 348 | + } |
|
| 349 | + } |
|
| 350 | + if (!isset($pages[$type])) { |
|
| 351 | + return $echafaudable[$type] = false; |
|
| 352 | + } |
|
| 353 | + if ((is_countable($pages[$type]) ? count($pages[$type]) : 0) == 2) { |
|
| 354 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 355 | + $pages[$type][] = $trouver_table(reset($pages[$type])); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + return $echafaudable[$type] = $pages[$type]; |
|
| 359 | + } |
|
| 360 | + |
|
| 361 | + return $echafaudable[$type] = false; |
|
| 362 | 362 | } |
| 363 | 363 | |
| 364 | 364 | |
@@ -375,46 +375,46 @@ discard block |
||
| 375 | 375 | * @return string |
| 376 | 376 | */ |
| 377 | 377 | function prive_echafauder_dist($exec, $table, $table_sql, $desc_exec, $ext) { |
| 378 | - $scaffold = ''; |
|
| 379 | - |
|
| 380 | - // page objet ou objet_edit |
|
| 381 | - if (is_array($desc_exec)) { |
|
| 382 | - $type = $desc_exec['type']; |
|
| 383 | - $primary = $desc_exec['id_table_objet']; |
|
| 384 | - |
|
| 385 | - if ($desc_exec['edition'] === false) { |
|
| 386 | - $fond = 'objet'; |
|
| 387 | - } else { |
|
| 388 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | - $desc = $trouver_table($table_sql); |
|
| 390 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | - $fond = 'objet_edit'; |
|
| 392 | - } else { |
|
| 393 | - $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | - } |
|
| 395 | - } |
|
| 396 | - $dir = z_blocs(test_espace_prive()); |
|
| 397 | - $dir = reset($dir); |
|
| 398 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | - } // page objets |
|
| 400 | - elseif ($type = $desc_exec and !str_contains($type, '/')) { |
|
| 401 | - $dir = z_blocs(test_espace_prive()); |
|
| 402 | - $dir = reset($dir); |
|
| 403 | - $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | - } |
|
| 405 | - // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | - // et objet et tire de $table |
|
| 407 | - elseif ($fond = $desc_exec) { |
|
| 408 | - $dir = md5(dirname($fond)); |
|
| 409 | - $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | - $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | - $f = $base_dir . "$exec"; |
|
| 415 | - ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | - |
|
| 417 | - return $f; |
|
| 378 | + $scaffold = ''; |
|
| 379 | + |
|
| 380 | + // page objet ou objet_edit |
|
| 381 | + if (is_array($desc_exec)) { |
|
| 382 | + $type = $desc_exec['type']; |
|
| 383 | + $primary = $desc_exec['id_table_objet']; |
|
| 384 | + |
|
| 385 | + if ($desc_exec['edition'] === false) { |
|
| 386 | + $fond = 'objet'; |
|
| 387 | + } else { |
|
| 388 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 389 | + $desc = $trouver_table($table_sql); |
|
| 390 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 391 | + $fond = 'objet_edit'; |
|
| 392 | + } else { |
|
| 393 | + $fond = 'objet_edit.sans_rubrique'; |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | + $dir = z_blocs(test_espace_prive()); |
|
| 397 | + $dir = reset($dir); |
|
| 398 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/" . $fond . ',objet=' . $type . ',id_objet=#' . strtoupper($primary) . ',env}>'; |
|
| 399 | + } // page objets |
|
| 400 | + elseif ($type = $desc_exec and !str_contains($type, '/')) { |
|
| 401 | + $dir = z_blocs(test_espace_prive()); |
|
| 402 | + $dir = reset($dir); |
|
| 403 | + $scaffold = "<INCLURE{fond=prive/echafaudage/$dir/objets,objet=" . $type . ',env} />'; |
|
| 404 | + } |
|
| 405 | + // morceau d'objet : on fournit le fond de sibstitution dans $desc_exec |
|
| 406 | + // et objet et tire de $table |
|
| 407 | + elseif ($fond = $desc_exec) { |
|
| 408 | + $dir = md5(dirname($fond)); |
|
| 409 | + $scaffold = "<INCLURE{fond=$fond,objet=" . objet_type($table) . ',env} />'; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + $base_dir = sous_repertoire(_DIR_CACHE, 'scaffold', false); |
|
| 413 | + $base_dir = sous_repertoire($base_dir, $dir, false); |
|
| 414 | + $f = $base_dir . "$exec"; |
|
| 415 | + ecrire_fichier("$f.$ext", $scaffold); |
|
| 416 | + |
|
| 417 | + return $f; |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -423,17 +423,17 @@ discard block |
||
| 423 | 423 | * @return bool|string |
| 424 | 424 | */ |
| 425 | 425 | function z_sanitize_var_zajax() { |
| 426 | - $z_ajax = _request('var_zajax'); |
|
| 427 | - if (!$z_ajax) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - if ( |
|
| 431 | - !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | - or !in_array($z_ajax, $z_blocs) |
|
| 433 | - ) { |
|
| 434 | - set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | - $z_ajax = false; |
|
| 436 | - } |
|
| 437 | - |
|
| 438 | - return $z_ajax; |
|
| 426 | + $z_ajax = _request('var_zajax'); |
|
| 427 | + if (!$z_ajax) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + if ( |
|
| 431 | + !$z_blocs = z_blocs(test_espace_prive()) |
|
| 432 | + or !in_array($z_ajax, $z_blocs) |
|
| 433 | + ) { |
|
| 434 | + set_request('var_zajax'); // enlever cette demande incongrue |
|
| 435 | + $z_ajax = false; |
|
| 436 | + } |
|
| 437 | + |
|
| 438 | + return $z_ajax; |
|
| 439 | 439 | } |
@@ -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(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 44 | + $code = "'" . str_replace(['\\', "'"], ['\\\\', "\\'"], $texte) . "'"; |
|
| 45 | 45 | |
| 46 | - return $code; |
|
| 46 | + return $code; |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | |
@@ -59,42 +59,42 @@ discard block |
||
| 59 | 59 | * @return string |
| 60 | 60 | */ |
| 61 | 61 | function sandbox_composer_filtre($fonc, $code, $arglist, &$p, $nb_arg_droite = 1000): string { |
| 62 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | - $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | - // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | - elseif ($f = chercher_filtre($fonc)) { |
|
| 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 | - $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | - } else { |
|
| 81 | - $code = "$f($code$arglist)"; |
|
| 82 | - $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | - } |
|
| 84 | - $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | - $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | - if (($nb_args_f < $min_f)) { |
|
| 87 | - $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | - erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | - } |
|
| 90 | - } |
|
| 91 | - // le filtre n'existe pas, |
|
| 92 | - // on le notifie |
|
| 93 | - else { |
|
| 94 | - erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - return $code; |
|
| 62 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 63 | + $code = "filtrer('$fonc',$code$arglist)"; |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // le filtre est defini sous forme de fonction ou de methode |
|
| 67 | + // par ex. dans inc_texte, inc_filtres ou mes_fonctions |
|
| 68 | + elseif ($f = chercher_filtre($fonc)) { |
|
| 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 | + $nb_arg_gauche = 2; // la balise à laquelle s'applique le filtre + $Pile |
|
| 80 | + } else { |
|
| 81 | + $code = "$f($code$arglist)"; |
|
| 82 | + $nb_arg_gauche = 1; // la balise à laquelle s'applique le filtre |
|
| 83 | + } |
|
| 84 | + $nb_args_f = $nb_arg_gauche + $nb_arg_droite; |
|
| 85 | + $min_f = $refl->getNumberOfRequiredParameters(); |
|
| 86 | + if (($nb_args_f < $min_f)) { |
|
| 87 | + $msg_args = ['filtre' => texte_script($fonc), 'nb' => $min_f - $nb_args_f]; |
|
| 88 | + erreur_squelette([ 'zbug_erreur_filtre_nbarg_min', $msg_args], $p); |
|
| 89 | + } |
|
| 90 | + } |
|
| 91 | + // le filtre n'existe pas, |
|
| 92 | + // on le notifie |
|
| 93 | + else { |
|
| 94 | + erreur_squelette(['zbug_erreur_filtre', ['filtre' => texte_script($fonc)]], $p); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + return $code; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Calculer un <INCLURE(xx.php)> |
@@ -117,15 +117,15 @@ discard block |
||
| 117 | 117 | * @return string |
| 118 | 118 | */ |
| 119 | 119 | function sandbox_composer_inclure_php($fichier, &$p, $_contexte) { |
| 120 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | - // si inexistant, on essaiera a l'execution |
|
| 122 | - if ($path = find_in_path($fichier)) { |
|
| 123 | - $path = "\"$path\""; |
|
| 124 | - } else { |
|
| 125 | - $path = "find_in_path(\"$fichier\")"; |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 120 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 121 | + // si inexistant, on essaiera a l'execution |
|
| 122 | + if ($path = find_in_path($fichier)) { |
|
| 123 | + $path = "\"$path\""; |
|
| 124 | + } else { |
|
| 125 | + $path = "find_in_path(\"$fichier\")"; |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + return sprintf(CODE_INCLURE_SCRIPT, $path, $fichier, $compil, $_contexte); |
|
| 129 | 129 | } |
| 130 | 130 | |
| 131 | 131 | /** |
@@ -137,20 +137,20 @@ discard block |
||
| 137 | 137 | * @return string |
| 138 | 138 | */ |
| 139 | 139 | function sandbox_composer_interdire_scripts($code, &$p) { |
| 140 | - // Securite |
|
| 141 | - if ( |
|
| 142 | - $p->interdire_scripts |
|
| 143 | - and $p->etoile != '**' |
|
| 144 | - ) { |
|
| 145 | - if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | - $code = "interdire_scripts($code)"; |
|
| 147 | - } else { |
|
| 148 | - $code = interdire_scripts($r[2]); |
|
| 149 | - $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | - } |
|
| 151 | - } |
|
| 152 | - |
|
| 153 | - return $code; |
|
| 140 | + // Securite |
|
| 141 | + if ( |
|
| 142 | + $p->interdire_scripts |
|
| 143 | + and $p->etoile != '**' |
|
| 144 | + ) { |
|
| 145 | + if (!preg_match("/^sinon[(](.*),'([^']*)'[)]$/", $code, $r)) { |
|
| 146 | + $code = "interdire_scripts($code)"; |
|
| 147 | + } else { |
|
| 148 | + $code = interdire_scripts($r[2]); |
|
| 149 | + $code = "sinon(interdire_scripts($r[1]),'$code')"; |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | + |
|
| 153 | + return $code; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | |
@@ -169,30 +169,30 @@ discard block |
||
| 169 | 169 | * @return mixed|string |
| 170 | 170 | */ |
| 171 | 171 | function sandbox_filtrer_squelette($skel, $corps, $filtres) { |
| 172 | - $series_filtres = func_get_args(); |
|
| 173 | - array_shift($series_filtres);// skel |
|
| 174 | - array_shift($series_filtres);// corps |
|
| 175 | - |
|
| 176 | - // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | - if ($skel['process_ins'] == 'php') { |
|
| 178 | - $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // recuperer les couples de remplacement |
|
| 182 | - $replace = echapper_php_callback(); |
|
| 183 | - |
|
| 184 | - foreach ($series_filtres as $filtres) { |
|
| 185 | - if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | - foreach ($filtres as $filtre) { |
|
| 187 | - if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | - $corps = $f($corps); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - // restaurer les echappements |
|
| 195 | - return str_replace($replace[0], $replace[1], $corps); |
|
| 172 | + $series_filtres = func_get_args(); |
|
| 173 | + array_shift($series_filtres);// skel |
|
| 174 | + array_shift($series_filtres);// corps |
|
| 175 | + |
|
| 176 | + // proteger les <INCLUDE> et tous les morceaux de php licites |
|
| 177 | + if ($skel['process_ins'] == 'php') { |
|
| 178 | + $corps = preg_replace_callback(',<[?](\s|php|=).*[?]>,UimsS', 'echapper_php_callback', $corps); |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // recuperer les couples de remplacement |
|
| 182 | + $replace = echapper_php_callback(); |
|
| 183 | + |
|
| 184 | + foreach ($series_filtres as $filtres) { |
|
| 185 | + if (is_countable($filtres) ? count($filtres) : 0) { |
|
| 186 | + foreach ($filtres as $filtre) { |
|
| 187 | + if ($filtre and $f = chercher_filtre($filtre)) { |
|
| 188 | + $corps = $f($corps); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + // restaurer les echappements |
|
| 195 | + return str_replace($replace[0], $replace[1], $corps); |
|
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | |
@@ -211,21 +211,21 @@ discard block |
||
| 211 | 211 | * - array : Liste( liste des codes PHP, liste des substitutions ) |
| 212 | 212 | **/ |
| 213 | 213 | function echapper_php_callback($r = null) { |
| 214 | - static $src = []; |
|
| 215 | - static $dst = []; |
|
| 214 | + static $src = []; |
|
| 215 | + static $dst = []; |
|
| 216 | 216 | |
| 217 | - // si on recoit un tableau, on est en mode echappement |
|
| 218 | - // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | - if (is_array($r)) { |
|
| 220 | - $dst[] = $r[0]; |
|
| 217 | + // si on recoit un tableau, on est en mode echappement |
|
| 218 | + // on enregistre le code a echapper dans dst, et le code echappe dans src |
|
| 219 | + if (is_array($r)) { |
|
| 220 | + $dst[] = $r[0]; |
|
| 221 | 221 | |
| 222 | - return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | - } |
|
| 222 | + return $src[] = '___' . md5($r[0]) . '___'; |
|
| 223 | + } |
|
| 224 | 224 | |
| 225 | - // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | - // et on RAZ les remplacements |
|
| 227 | - $r = [$src, $dst]; |
|
| 228 | - $src = $dst = []; |
|
| 225 | + // si on recoit pas un tableau, on renvoit les couples de substitution |
|
| 226 | + // et on RAZ les remplacements |
|
| 227 | + $r = [$src, $dst]; |
|
| 228 | + $src = $dst = []; |
|
| 229 | 229 | |
| 230 | - return $r; |
|
| 230 | + return $r; |
|
| 231 | 231 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | **/ |
| 29 | 29 | |
| 30 | 30 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 31 | - return; |
|
| 31 | + return; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** Début de la partie principale d'une boucle */ |
@@ -72,82 +72,82 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | function phraser_inclure($texte, $ligne, $result) { |
| 74 | 74 | |
| 75 | - while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 76 | - $match = array_pad($match, 3, null); |
|
| 77 | - $p = strpos($texte, (string) $match[0]); |
|
| 78 | - $debut = substr($texte, 0, $p); |
|
| 79 | - if ($p) { |
|
| 80 | - $result = phraser_idiomes($debut, $ligne, $result); |
|
| 81 | - } |
|
| 82 | - $ligne += substr_count($debut, "\n"); |
|
| 83 | - $champ = new Inclure(); |
|
| 84 | - $champ->ligne = $ligne; |
|
| 85 | - $ligne += substr_count($match[0], "\n"); |
|
| 86 | - $fichier = $match[2]; |
|
| 87 | - # assurer ici la migration .php3 => .php |
|
| 88 | - # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 89 | - if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 90 | - $fichier = $r[1]; |
|
| 91 | - } |
|
| 92 | - $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 93 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 94 | - // on assimile {var=val} a une liste de un argument sans fonction |
|
| 95 | - $pos_apres = 0; |
|
| 96 | - phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 97 | - if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 98 | - if (!function_exists('normaliser_inclure')) { |
|
| 99 | - include_spip('public/normaliser'); |
|
| 100 | - } |
|
| 101 | - normaliser_inclure($champ); |
|
| 102 | - } |
|
| 103 | - $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 104 | - $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 105 | - $result[] = $champ; |
|
| 106 | - } |
|
| 107 | - |
|
| 108 | - return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 75 | + while (preg_match(BALISE_INCLURE, $texte, $match)) { |
|
| 76 | + $match = array_pad($match, 3, null); |
|
| 77 | + $p = strpos($texte, (string) $match[0]); |
|
| 78 | + $debut = substr($texte, 0, $p); |
|
| 79 | + if ($p) { |
|
| 80 | + $result = phraser_idiomes($debut, $ligne, $result); |
|
| 81 | + } |
|
| 82 | + $ligne += substr_count($debut, "\n"); |
|
| 83 | + $champ = new Inclure(); |
|
| 84 | + $champ->ligne = $ligne; |
|
| 85 | + $ligne += substr_count($match[0], "\n"); |
|
| 86 | + $fichier = $match[2]; |
|
| 87 | + # assurer ici la migration .php3 => .php |
|
| 88 | + # et de l'ancienne syntaxe INCLURE(page.php3) devenue surperflue |
|
| 89 | + if ($fichier and preg_match(',^(.*[.]php)3$,', $fichier, $r)) { |
|
| 90 | + $fichier = $r[1]; |
|
| 91 | + } |
|
| 92 | + $champ->texte = ($fichier !== 'page.php') ? $fichier : ''; |
|
| 93 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 94 | + // on assimile {var=val} a une liste de un argument sans fonction |
|
| 95 | + $pos_apres = 0; |
|
| 96 | + phraser_args($texte, '/>', '', $result, $champ, $pos_apres); |
|
| 97 | + if (!$champ->texte or (is_countable($champ->param) ? count($champ->param) : 0) > 1) { |
|
| 98 | + if (!function_exists('normaliser_inclure')) { |
|
| 99 | + include_spip('public/normaliser'); |
|
| 100 | + } |
|
| 101 | + normaliser_inclure($champ); |
|
| 102 | + } |
|
| 103 | + $texte = substr($texte, strpos($texte, '>', $pos_apres) + 1); |
|
| 104 | + $texte = preg_replace(',^</INCLU[DR]E>,', '', $texte); |
|
| 105 | + $result[] = $champ; |
|
| 106 | + } |
|
| 107 | + |
|
| 108 | + return (($texte === '') ? $result : phraser_idiomes($texte, $ligne, $result)); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | function phraser_polyglotte($texte, $ligne, $result) { |
| 112 | 112 | |
| 113 | - if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 114 | - foreach ($m as $match) { |
|
| 115 | - $p = strpos($texte, (string) $match[0]); |
|
| 116 | - $debut = substr($texte, 0, $p); |
|
| 117 | - if ($p) { |
|
| 118 | - $champ = new Texte(); |
|
| 119 | - $champ->texte = $debut; |
|
| 120 | - $champ->ligne = $ligne; |
|
| 121 | - $result[] = $champ; |
|
| 122 | - $ligne += substr_count($champ->texte, "\n"); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - $champ = new Polyglotte(); |
|
| 126 | - $champ->ligne = $ligne; |
|
| 127 | - $ligne += substr_count($match[0], "\n"); |
|
| 128 | - $lang = ''; |
|
| 129 | - $bloc = $match[1]; |
|
| 130 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 131 | - while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 132 | - $trad = $regs[1]; |
|
| 133 | - if ($trad or $lang) { |
|
| 134 | - $champ->traductions[$lang] = $trad; |
|
| 135 | - } |
|
| 136 | - $lang = $regs[2]; |
|
| 137 | - $bloc = $regs[3]; |
|
| 138 | - } |
|
| 139 | - $champ->traductions[$lang] = $bloc; |
|
| 140 | - $result[] = $champ; |
|
| 141 | - } |
|
| 142 | - } |
|
| 143 | - if ($texte !== '') { |
|
| 144 | - $champ = new Texte(); |
|
| 145 | - $champ->texte = $texte; |
|
| 146 | - $champ->ligne = $ligne; |
|
| 147 | - $result[] = $champ; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $result; |
|
| 113 | + if (preg_match_all(BALISE_POLYGLOTTE, $texte, $m, PREG_SET_ORDER)) { |
|
| 114 | + foreach ($m as $match) { |
|
| 115 | + $p = strpos($texte, (string) $match[0]); |
|
| 116 | + $debut = substr($texte, 0, $p); |
|
| 117 | + if ($p) { |
|
| 118 | + $champ = new Texte(); |
|
| 119 | + $champ->texte = $debut; |
|
| 120 | + $champ->ligne = $ligne; |
|
| 121 | + $result[] = $champ; |
|
| 122 | + $ligne += substr_count($champ->texte, "\n"); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + $champ = new Polyglotte(); |
|
| 126 | + $champ->ligne = $ligne; |
|
| 127 | + $ligne += substr_count($match[0], "\n"); |
|
| 128 | + $lang = ''; |
|
| 129 | + $bloc = $match[1]; |
|
| 130 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 131 | + while (preg_match('/^[[:space:]]*([^[{]*)[[:space:]]*[[{]([a-z_]+)[]}](.*)$/si', $bloc, $regs)) { |
|
| 132 | + $trad = $regs[1]; |
|
| 133 | + if ($trad or $lang) { |
|
| 134 | + $champ->traductions[$lang] = $trad; |
|
| 135 | + } |
|
| 136 | + $lang = $regs[2]; |
|
| 137 | + $bloc = $regs[3]; |
|
| 138 | + } |
|
| 139 | + $champ->traductions[$lang] = $bloc; |
|
| 140 | + $result[] = $champ; |
|
| 141 | + } |
|
| 142 | + } |
|
| 143 | + if ($texte !== '') { |
|
| 144 | + $champ = new Texte(); |
|
| 145 | + $champ->texte = $texte; |
|
| 146 | + $champ->ligne = $ligne; |
|
| 147 | + $result[] = $champ; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $result; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | |
@@ -169,43 +169,43 @@ discard block |
||
| 169 | 169 | * @return array |
| 170 | 170 | **/ |
| 171 | 171 | function phraser_idiomes($texte, $ligne, $result) { |
| 172 | - while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 173 | - $match = array_pad($match, 8, null); |
|
| 174 | - $p = strpos($texte, (string) $match[0]); |
|
| 175 | - $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 176 | - $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 177 | - if ($debut) { |
|
| 178 | - $result = phraser_champs($debut, $ligne, $result); |
|
| 179 | - } |
|
| 180 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 181 | - $ligne += substr_count($debut, "\n"); |
|
| 182 | - if ($ko) { |
|
| 183 | - continue; |
|
| 184 | - } // faux idiome |
|
| 185 | - $champ = new Idiome(); |
|
| 186 | - $champ->ligne = $ligne; |
|
| 187 | - $ligne += substr_count($match[0], "\n"); |
|
| 188 | - // Stocker les arguments de la balise de traduction |
|
| 189 | - $args = []; |
|
| 190 | - $largs = $match[5]; |
|
| 191 | - while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 192 | - $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 193 | - $largs = substr($largs, strlen($r[0])); |
|
| 194 | - } |
|
| 195 | - $champ->arg = $args; |
|
| 196 | - $champ->nom_champ = strtolower($match[3]); |
|
| 197 | - $champ->module = $match[2]; |
|
| 198 | - // pas d'imbrication pour les filtres sur langue |
|
| 199 | - $pos_apres = 0; |
|
| 200 | - phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 201 | - $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 202 | - $result[] = $champ; |
|
| 203 | - } |
|
| 204 | - if ($texte !== '') { |
|
| 205 | - $result = phraser_champs($texte, $ligne, $result); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $result; |
|
| 172 | + while (preg_match(BALISE_IDIOMES, $texte, $match)) { |
|
| 173 | + $match = array_pad($match, 8, null); |
|
| 174 | + $p = strpos($texte, (string) $match[0]); |
|
| 175 | + $ko = (!$match[3] && ($match[5][0] !== '=')); |
|
| 176 | + $debut = substr($texte, 0, $p + ($ko ? strlen($match[0]) : 0)); |
|
| 177 | + if ($debut) { |
|
| 178 | + $result = phraser_champs($debut, $ligne, $result); |
|
| 179 | + } |
|
| 180 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 181 | + $ligne += substr_count($debut, "\n"); |
|
| 182 | + if ($ko) { |
|
| 183 | + continue; |
|
| 184 | + } // faux idiome |
|
| 185 | + $champ = new Idiome(); |
|
| 186 | + $champ->ligne = $ligne; |
|
| 187 | + $ligne += substr_count($match[0], "\n"); |
|
| 188 | + // Stocker les arguments de la balise de traduction |
|
| 189 | + $args = []; |
|
| 190 | + $largs = $match[5]; |
|
| 191 | + while (preg_match(BALISE_IDIOMES_ARGS, $largs, $r)) { |
|
| 192 | + $args[$r[1]] = phraser_champs($r[2], 0, []); |
|
| 193 | + $largs = substr($largs, strlen($r[0])); |
|
| 194 | + } |
|
| 195 | + $champ->arg = $args; |
|
| 196 | + $champ->nom_champ = strtolower($match[3]); |
|
| 197 | + $champ->module = $match[2]; |
|
| 198 | + // pas d'imbrication pour les filtres sur langue |
|
| 199 | + $pos_apres = 0; |
|
| 200 | + phraser_args($match[7] ?? '', ':', '', [], $champ, $pos_apres); |
|
| 201 | + $champ->apres = substr($match[7] ?? '', $pos_apres); |
|
| 202 | + $result[] = $champ; |
|
| 203 | + } |
|
| 204 | + if ($texte !== '') { |
|
| 205 | + $result = phraser_champs($texte, $ligne, $result); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $result; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | /** |
@@ -223,47 +223,47 @@ discard block |
||
| 223 | 223 | * @return array |
| 224 | 224 | **/ |
| 225 | 225 | function phraser_champs($texte, $ligne, $result) { |
| 226 | - while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 227 | - $p = strpos($texte, (string) $match[0]); |
|
| 228 | - // texte après la balise |
|
| 229 | - $suite = substr($texte, $p + strlen($match[0])); |
|
| 230 | - |
|
| 231 | - $debut = substr($texte, 0, $p); |
|
| 232 | - if ($p) { |
|
| 233 | - $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 234 | - } |
|
| 235 | - $ligne += substr_count($debut, "\n"); |
|
| 236 | - $champ = new Champ(); |
|
| 237 | - $champ->ligne = $ligne; |
|
| 238 | - $ligne += substr_count($match[0], "\n"); |
|
| 239 | - $champ->nom_boucle = $match[2]; |
|
| 240 | - $champ->nom_champ = $match[3]; |
|
| 241 | - $champ->etoile = $match[5]; |
|
| 242 | - |
|
| 243 | - if ($suite and $suite[0] == '{') { |
|
| 244 | - phraser_arg($suite, '', [], $champ); |
|
| 245 | - // ce ltrim est une ereur de conception |
|
| 246 | - // mais on le conserve par souci de compatibilite |
|
| 247 | - $texte = ltrim($suite); |
|
| 248 | - // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 249 | - // pour faire sauter ce cas particulier a la decompilation. |
|
| 250 | - /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 226 | + while (preg_match('/' . NOM_DE_CHAMP . '/S', $texte, $match)) { |
|
| 227 | + $p = strpos($texte, (string) $match[0]); |
|
| 228 | + // texte après la balise |
|
| 229 | + $suite = substr($texte, $p + strlen($match[0])); |
|
| 230 | + |
|
| 231 | + $debut = substr($texte, 0, $p); |
|
| 232 | + if ($p) { |
|
| 233 | + $result = phraser_polyglotte($debut, $ligne, $result); |
|
| 234 | + } |
|
| 235 | + $ligne += substr_count($debut, "\n"); |
|
| 236 | + $champ = new Champ(); |
|
| 237 | + $champ->ligne = $ligne; |
|
| 238 | + $ligne += substr_count($match[0], "\n"); |
|
| 239 | + $champ->nom_boucle = $match[2]; |
|
| 240 | + $champ->nom_champ = $match[3]; |
|
| 241 | + $champ->etoile = $match[5]; |
|
| 242 | + |
|
| 243 | + if ($suite and $suite[0] == '{') { |
|
| 244 | + phraser_arg($suite, '', [], $champ); |
|
| 245 | + // ce ltrim est une ereur de conception |
|
| 246 | + // mais on le conserve par souci de compatibilite |
|
| 247 | + $texte = ltrim($suite); |
|
| 248 | + // Il faudrait le normaliser dans l'arbre de syntaxe abstraite |
|
| 249 | + // pour faire sauter ce cas particulier a la decompilation. |
|
| 250 | + /* Ce qui suit est malheureusement incomplet pour cela: |
|
| 251 | 251 | if ($n = (strlen($suite) - strlen($texte))) { |
| 252 | 252 | $champ->apres = array(new Texte); |
| 253 | 253 | $champ->apres[0]->texte = substr($suite,0,$n); |
| 254 | 254 | } |
| 255 | 255 | */ |
| 256 | - } else { |
|
| 257 | - $texte = $suite; |
|
| 258 | - } |
|
| 259 | - phraser_vieux($champ); |
|
| 260 | - $result[] = $champ; |
|
| 261 | - } |
|
| 262 | - if ($texte !== '') { |
|
| 263 | - $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - return $result; |
|
| 256 | + } else { |
|
| 257 | + $texte = $suite; |
|
| 258 | + } |
|
| 259 | + phraser_vieux($champ); |
|
| 260 | + $result[] = $champ; |
|
| 261 | + } |
|
| 262 | + if ($texte !== '') { |
|
| 263 | + $result = phraser_polyglotte($texte, $ligne, $result); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + return $result; |
|
| 267 | 267 | } |
| 268 | 268 | |
| 269 | 269 | // Gestion des imbrications: |
@@ -272,15 +272,15 @@ discard block |
||
| 272 | 272 | // on recommence tant qu'il y a des [...] en substituant a l'appel suivant |
| 273 | 273 | |
| 274 | 274 | function phraser_champs_etendus($texte, $ligne, $result) { |
| 275 | - if ($texte === '') { |
|
| 276 | - return $result; |
|
| 277 | - } |
|
| 278 | - $sep = '##'; |
|
| 279 | - while (strpos($texte, (string) $sep) !== false) { |
|
| 280 | - $sep .= '#'; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 275 | + if ($texte === '') { |
|
| 276 | + return $result; |
|
| 277 | + } |
|
| 278 | + $sep = '##'; |
|
| 279 | + while (strpos($texte, (string) $sep) !== false) { |
|
| 280 | + $sep .= '#'; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + return array_merge($result, phraser_champs_interieurs($texte, $ligne, $sep, [])); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | /** |
@@ -299,275 +299,275 @@ discard block |
||
| 299 | 299 | * @return array |
| 300 | 300 | */ |
| 301 | 301 | function phraser_args(string $texte, $fin, $sep, $result, &$pointeur_champ, &$pos_debut) { |
| 302 | - $length = strlen($texte); |
|
| 303 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | - $pos_debut++; |
|
| 305 | - } |
|
| 306 | - while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 307 | - // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 308 | - $st = substr($texte, $pos_debut); |
|
| 309 | - $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 310 | - $pos_debut = $length - strlen($st); |
|
| 311 | - while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 312 | - $pos_debut++; |
|
| 313 | - } |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - return $result; |
|
| 302 | + $length = strlen($texte); |
|
| 303 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 304 | + $pos_debut++; |
|
| 305 | + } |
|
| 306 | + while (($pos_debut < $length) && !str_contains($fin, $texte[$pos_debut])) { |
|
| 307 | + // phraser_arg modifie directement le $texte, on fait donc avec ici en passant par une sous chaine |
|
| 308 | + $st = substr($texte, $pos_debut); |
|
| 309 | + $result = phraser_arg($st, $sep, $result, $pointeur_champ); |
|
| 310 | + $pos_debut = $length - strlen($st); |
|
| 311 | + while ($pos_debut < $length and trim($texte[$pos_debut]) === '') { |
|
| 312 | + $pos_debut++; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + return $result; |
|
| 317 | 317 | } |
| 318 | 318 | |
| 319 | 319 | function phraser_arg(&$texte, $sep, $result, &$pointeur_champ) { |
| 320 | - preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 321 | - $suite = ltrim($match[2]); |
|
| 322 | - $fonc = trim($match[1]); |
|
| 323 | - if ($fonc && $fonc[0] == '|') { |
|
| 324 | - $fonc = ltrim(substr($fonc, 1)); |
|
| 325 | - } |
|
| 326 | - $res = [$fonc]; |
|
| 327 | - $err_f = ''; |
|
| 328 | - // cas du filtre sans argument ou du critere / |
|
| 329 | - if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 330 | - // si pas d'argument, alors il faut une fonction ou un double | |
|
| 331 | - if (!$match[1]) { |
|
| 332 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 333 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 334 | - $texte = ''; |
|
| 335 | - } else { |
|
| 336 | - $texte = $suite; |
|
| 337 | - } |
|
| 338 | - if ($err_f) { |
|
| 339 | - $pointeur_champ->param = false; |
|
| 340 | - } elseif ($fonc !== '') { |
|
| 341 | - $pointeur_champ->param[] = $res; |
|
| 342 | - } |
|
| 343 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 344 | - $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 345 | - |
|
| 346 | - return $result; |
|
| 347 | - } |
|
| 348 | - $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 349 | - $collecte = []; |
|
| 350 | - while ($args && $args[0] != '}') { |
|
| 351 | - if ($args[0] == '"') { |
|
| 352 | - preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 353 | - } elseif ($args[0] == "'") { |
|
| 354 | - preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 355 | - } else { |
|
| 356 | - preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 357 | - if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 358 | - $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 359 | - erreur_squelette($err_f, $pointeur_champ); |
|
| 360 | - $champ = new Texte(); |
|
| 361 | - $champ->apres = $champ->avant = $args = ''; |
|
| 362 | - break; |
|
| 363 | - } |
|
| 364 | - } |
|
| 365 | - $arg = $regs[2]; |
|
| 366 | - if (trim($regs[1])) { |
|
| 367 | - $champ = new Texte(); |
|
| 368 | - $champ->texte = $arg; |
|
| 369 | - $champ->apres = $champ->avant = $regs[1]; |
|
| 370 | - $result[] = $champ; |
|
| 371 | - $collecte[] = $champ; |
|
| 372 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 373 | - } else { |
|
| 374 | - if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 375 | - // 0 est un aveu d'impuissance. A completer |
|
| 376 | - $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 377 | - |
|
| 378 | - $args = ltrim($regs[count($regs) - 1]); |
|
| 379 | - $collecte = array_merge($collecte, $arg); |
|
| 380 | - $result = array_merge($result, $arg); |
|
| 381 | - } else { |
|
| 382 | - $n = strpos($args, (string) $r[0]); |
|
| 383 | - $pred = substr($args, 0, $n); |
|
| 384 | - $par = ',}'; |
|
| 385 | - if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 386 | - $pred = $m[1]; |
|
| 387 | - $par = ')'; |
|
| 388 | - } |
|
| 389 | - if ($pred) { |
|
| 390 | - $champ = new Texte(); |
|
| 391 | - $champ->texte = $pred; |
|
| 392 | - $champ->apres = $champ->avant = ''; |
|
| 393 | - $result[] = $champ; |
|
| 394 | - $collecte[] = $champ; |
|
| 395 | - } |
|
| 396 | - $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 397 | - $champ = new Champ(); |
|
| 398 | - $champ->nom_boucle = $r[2]; |
|
| 399 | - $champ->nom_champ = $r[3]; |
|
| 400 | - $champ->etoile = $r[5]; |
|
| 401 | - $next = $r[6]; |
|
| 402 | - while ($next == '{') { |
|
| 403 | - phraser_arg($rec, $sep, [], $champ); |
|
| 404 | - $args = ltrim($rec); |
|
| 405 | - $next = $args[0] ?? ''; |
|
| 406 | - } |
|
| 407 | - while ($next == '|') { |
|
| 408 | - $pos_apres = 0; |
|
| 409 | - phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 410 | - $args = substr($rec, $pos_apres); |
|
| 411 | - $next = $args[0] ?? ''; |
|
| 412 | - } |
|
| 413 | - // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 414 | - if ($champ->param === false) { |
|
| 415 | - $err_f = true; |
|
| 416 | - } else { |
|
| 417 | - phraser_vieux($champ); |
|
| 418 | - } |
|
| 419 | - if ($par == ')') { |
|
| 420 | - $args = substr($args, 1); |
|
| 421 | - } |
|
| 422 | - $collecte[] = $champ; |
|
| 423 | - $result[] = $champ; |
|
| 424 | - } |
|
| 425 | - } |
|
| 426 | - if (isset($args[0]) and $args[0] == ',') { |
|
| 427 | - $args = ltrim(substr($args, 1)); |
|
| 428 | - if ($collecte) { |
|
| 429 | - $res[] = $collecte; |
|
| 430 | - $collecte = []; |
|
| 431 | - } |
|
| 432 | - } |
|
| 433 | - } |
|
| 434 | - if ($collecte) { |
|
| 435 | - $res[] = $collecte; |
|
| 436 | - $collecte = []; |
|
| 437 | - } |
|
| 438 | - $texte = substr($args, 1); |
|
| 439 | - $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 440 | - // propager les erreurs, et ignorer les param vides |
|
| 441 | - if ($pointeur_champ->param !== false) { |
|
| 442 | - if ($err_f) { |
|
| 443 | - $pointeur_champ->param = false; |
|
| 444 | - } elseif ($fonc !== '' || count($res) > 1) { |
|
| 445 | - $pointeur_champ->param[] = $res; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 449 | - $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 450 | - |
|
| 451 | - return $result; |
|
| 320 | + preg_match(',^(\|?[^}{)|]*)(.*)$,ms', $texte, $match); |
|
| 321 | + $suite = ltrim($match[2]); |
|
| 322 | + $fonc = trim($match[1]); |
|
| 323 | + if ($fonc && $fonc[0] == '|') { |
|
| 324 | + $fonc = ltrim(substr($fonc, 1)); |
|
| 325 | + } |
|
| 326 | + $res = [$fonc]; |
|
| 327 | + $err_f = ''; |
|
| 328 | + // cas du filtre sans argument ou du critere / |
|
| 329 | + if (($suite && ($suite[0] != '{')) || ($fonc && $fonc[0] == '/')) { |
|
| 330 | + // si pas d'argument, alors il faut une fonction ou un double | |
|
| 331 | + if (!$match[1]) { |
|
| 332 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $texte]]; |
|
| 333 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 334 | + $texte = ''; |
|
| 335 | + } else { |
|
| 336 | + $texte = $suite; |
|
| 337 | + } |
|
| 338 | + if ($err_f) { |
|
| 339 | + $pointeur_champ->param = false; |
|
| 340 | + } elseif ($fonc !== '') { |
|
| 341 | + $pointeur_champ->param[] = $res; |
|
| 342 | + } |
|
| 343 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 344 | + $pointeur_champ->fonctions[] = [$fonc, '']; |
|
| 345 | + |
|
| 346 | + return $result; |
|
| 347 | + } |
|
| 348 | + $args = ltrim(substr($suite, 1)); // virer le '(' initial |
|
| 349 | + $collecte = []; |
|
| 350 | + while ($args && $args[0] != '}') { |
|
| 351 | + if ($args[0] == '"') { |
|
| 352 | + preg_match('/^(")([^"]*)(")(.*)$/ms', $args, $regs); |
|
| 353 | + } elseif ($args[0] == "'") { |
|
| 354 | + preg_match("/^(')([^']*)(')(.*)$/ms", $args, $regs); |
|
| 355 | + } else { |
|
| 356 | + preg_match('/^([[:space:]]*)([^,([{}]*([(\[{][^])}]*[])}])?[^,}]*)([,}].*)$/ms', $args, $regs); |
|
| 357 | + if (!isset($regs[2]) or !strlen($regs[2])) { |
|
| 358 | + $err_f = ['zbug_erreur_filtre', ['filtre' => $args]]; |
|
| 359 | + erreur_squelette($err_f, $pointeur_champ); |
|
| 360 | + $champ = new Texte(); |
|
| 361 | + $champ->apres = $champ->avant = $args = ''; |
|
| 362 | + break; |
|
| 363 | + } |
|
| 364 | + } |
|
| 365 | + $arg = $regs[2]; |
|
| 366 | + if (trim($regs[1])) { |
|
| 367 | + $champ = new Texte(); |
|
| 368 | + $champ->texte = $arg; |
|
| 369 | + $champ->apres = $champ->avant = $regs[1]; |
|
| 370 | + $result[] = $champ; |
|
| 371 | + $collecte[] = $champ; |
|
| 372 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 373 | + } else { |
|
| 374 | + if (!preg_match('/' . NOM_DE_CHAMP . '([{|])/', $arg, $r)) { |
|
| 375 | + // 0 est un aveu d'impuissance. A completer |
|
| 376 | + $arg = phraser_champs_exterieurs($arg, 0, $sep, $result); |
|
| 377 | + |
|
| 378 | + $args = ltrim($regs[count($regs) - 1]); |
|
| 379 | + $collecte = array_merge($collecte, $arg); |
|
| 380 | + $result = array_merge($result, $arg); |
|
| 381 | + } else { |
|
| 382 | + $n = strpos($args, (string) $r[0]); |
|
| 383 | + $pred = substr($args, 0, $n); |
|
| 384 | + $par = ',}'; |
|
| 385 | + if (preg_match('/^(.*)\($/', $pred, $m)) { |
|
| 386 | + $pred = $m[1]; |
|
| 387 | + $par = ')'; |
|
| 388 | + } |
|
| 389 | + if ($pred) { |
|
| 390 | + $champ = new Texte(); |
|
| 391 | + $champ->texte = $pred; |
|
| 392 | + $champ->apres = $champ->avant = ''; |
|
| 393 | + $result[] = $champ; |
|
| 394 | + $collecte[] = $champ; |
|
| 395 | + } |
|
| 396 | + $rec = substr($args, $n + strlen($r[0]) - 1); |
|
| 397 | + $champ = new Champ(); |
|
| 398 | + $champ->nom_boucle = $r[2]; |
|
| 399 | + $champ->nom_champ = $r[3]; |
|
| 400 | + $champ->etoile = $r[5]; |
|
| 401 | + $next = $r[6]; |
|
| 402 | + while ($next == '{') { |
|
| 403 | + phraser_arg($rec, $sep, [], $champ); |
|
| 404 | + $args = ltrim($rec); |
|
| 405 | + $next = $args[0] ?? ''; |
|
| 406 | + } |
|
| 407 | + while ($next == '|') { |
|
| 408 | + $pos_apres = 0; |
|
| 409 | + phraser_args($rec, $par, $sep, [], $champ, $pos_apres); |
|
| 410 | + $args = substr($rec, $pos_apres); |
|
| 411 | + $next = $args[0] ?? ''; |
|
| 412 | + } |
|
| 413 | + // Si erreur de syntaxe dans un sous-argument, propager. |
|
| 414 | + if ($champ->param === false) { |
|
| 415 | + $err_f = true; |
|
| 416 | + } else { |
|
| 417 | + phraser_vieux($champ); |
|
| 418 | + } |
|
| 419 | + if ($par == ')') { |
|
| 420 | + $args = substr($args, 1); |
|
| 421 | + } |
|
| 422 | + $collecte[] = $champ; |
|
| 423 | + $result[] = $champ; |
|
| 424 | + } |
|
| 425 | + } |
|
| 426 | + if (isset($args[0]) and $args[0] == ',') { |
|
| 427 | + $args = ltrim(substr($args, 1)); |
|
| 428 | + if ($collecte) { |
|
| 429 | + $res[] = $collecte; |
|
| 430 | + $collecte = []; |
|
| 431 | + } |
|
| 432 | + } |
|
| 433 | + } |
|
| 434 | + if ($collecte) { |
|
| 435 | + $res[] = $collecte; |
|
| 436 | + $collecte = []; |
|
| 437 | + } |
|
| 438 | + $texte = substr($args, 1); |
|
| 439 | + $source = substr($suite, 0, strlen($suite) - strlen($texte)); |
|
| 440 | + // propager les erreurs, et ignorer les param vides |
|
| 441 | + if ($pointeur_champ->param !== false) { |
|
| 442 | + if ($err_f) { |
|
| 443 | + $pointeur_champ->param = false; |
|
| 444 | + } elseif ($fonc !== '' || count($res) > 1) { |
|
| 445 | + $pointeur_champ->param[] = $res; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + // pour les balises avec faux filtres qui boudent ce dur larbeur |
|
| 449 | + $pointeur_champ->fonctions[] = [$fonc, $source]; |
|
| 450 | + |
|
| 451 | + return $result; |
|
| 452 | 452 | } |
| 453 | 453 | |
| 454 | 454 | |
| 455 | 455 | function phraser_champs_exterieurs($texte, $ligne, $sep, $nested) { |
| 456 | - $res = []; |
|
| 457 | - while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 458 | - if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 459 | - break; |
|
| 460 | - } |
|
| 461 | - $debut = substr($texte, 0, $p); |
|
| 462 | - $texte = substr($texte, $p + strlen($m[0])); |
|
| 463 | - if ($p) { |
|
| 464 | - $res = phraser_inclure($debut, $ligne, $res); |
|
| 465 | - } |
|
| 466 | - $ligne += substr_count($debut, "\n"); |
|
| 467 | - $res[] = $nested[$m[1]]; |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 456 | + $res = []; |
|
| 457 | + while (($p = strpos($texte, (string) "%$sep")) !== false) { |
|
| 458 | + if (!preg_match(',^%' . preg_quote($sep) . '([0-9]+)@,', substr($texte, $p), $m)) { |
|
| 459 | + break; |
|
| 460 | + } |
|
| 461 | + $debut = substr($texte, 0, $p); |
|
| 462 | + $texte = substr($texte, $p + strlen($m[0])); |
|
| 463 | + if ($p) { |
|
| 464 | + $res = phraser_inclure($debut, $ligne, $res); |
|
| 465 | + } |
|
| 466 | + $ligne += substr_count($debut, "\n"); |
|
| 467 | + $res[] = $nested[$m[1]]; |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + return (($texte === '') ? $res : phraser_inclure($texte, $ligne, $res)); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | function phraser_champs_interieurs($texte, $ligne, $sep, $result) { |
| 474 | - $i = 0; // en fait count($result) |
|
| 475 | - $x = ''; |
|
| 476 | - |
|
| 477 | - while (true) { |
|
| 478 | - $j = $i; |
|
| 479 | - $n = $ligne; |
|
| 480 | - while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | - $p = strpos($texte, (string) $match[0]); |
|
| 482 | - $debut = substr($texte, 0, $p); |
|
| 483 | - if ($p) { |
|
| 484 | - $result[$i] = $debut; |
|
| 485 | - $i++; |
|
| 486 | - } |
|
| 487 | - $nom = $match[4]; |
|
| 488 | - $champ = new Champ(); |
|
| 489 | - // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | - $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | - $champ->nom_boucle = $match[3]; |
|
| 492 | - $champ->nom_champ = $nom; |
|
| 493 | - $champ->etoile = $match[6]; |
|
| 494 | - // phraser_args indiquera ou commence apres |
|
| 495 | - $pos_apres = 0; |
|
| 496 | - $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | - phraser_vieux($champ); |
|
| 498 | - $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | - $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | - if (!empty($debut)) { |
|
| 501 | - $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | - } |
|
| 503 | - $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | - |
|
| 505 | - // reinjecter la boucle si c'en est une |
|
| 506 | - phraser_boucle_placeholder($champ); |
|
| 507 | - |
|
| 508 | - $result[$i] = $champ; |
|
| 509 | - $i++; |
|
| 510 | - $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | - } |
|
| 512 | - if ($texte !== '') { |
|
| 513 | - $result[$i] = $texte; |
|
| 514 | - $i++; |
|
| 515 | - } |
|
| 516 | - $x = ''; |
|
| 517 | - |
|
| 518 | - while ($j < $i) { |
|
| 519 | - $z = $result[$j]; |
|
| 520 | - // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | - if (is_object($z)) { |
|
| 522 | - $x .= "%$sep$j@"; |
|
| 523 | - } else { |
|
| 524 | - $x .= $z; |
|
| 525 | - } |
|
| 526 | - $j++; |
|
| 527 | - } |
|
| 528 | - if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | - $texte = $x; |
|
| 530 | - } else { |
|
| 531 | - return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | - } |
|
| 533 | - } |
|
| 474 | + $i = 0; // en fait count($result) |
|
| 475 | + $x = ''; |
|
| 476 | + |
|
| 477 | + while (true) { |
|
| 478 | + $j = $i; |
|
| 479 | + $n = $ligne; |
|
| 480 | + while (preg_match(CHAMP_ETENDU, $texte, $match)) { |
|
| 481 | + $p = strpos($texte, (string) $match[0]); |
|
| 482 | + $debut = substr($texte, 0, $p); |
|
| 483 | + if ($p) { |
|
| 484 | + $result[$i] = $debut; |
|
| 485 | + $i++; |
|
| 486 | + } |
|
| 487 | + $nom = $match[4]; |
|
| 488 | + $champ = new Champ(); |
|
| 489 | + // ca ne marche pas encore en cas de champ imbrique |
|
| 490 | + $champ->ligne = $x ? 0 : ($n + substr_count($debut, "\n")); |
|
| 491 | + $champ->nom_boucle = $match[3]; |
|
| 492 | + $champ->nom_champ = $nom; |
|
| 493 | + $champ->etoile = $match[6]; |
|
| 494 | + // phraser_args indiquera ou commence apres |
|
| 495 | + $pos_apres = 0; |
|
| 496 | + $result = phraser_args($match[7], ')', $sep, $result, $champ, $pos_apres); |
|
| 497 | + phraser_vieux($champ); |
|
| 498 | + $champ->avant = phraser_champs_exterieurs($match[1], $n, $sep, $result); |
|
| 499 | + $debut = substr($match[7], $pos_apres + 1); |
|
| 500 | + if (!empty($debut)) { |
|
| 501 | + $n += substr_count(substr($texte, 0, strpos($texte, $debut)), "\n"); |
|
| 502 | + } |
|
| 503 | + $champ->apres = phraser_champs_exterieurs($debut, $n, $sep, $result); |
|
| 504 | + |
|
| 505 | + // reinjecter la boucle si c'en est une |
|
| 506 | + phraser_boucle_placeholder($champ); |
|
| 507 | + |
|
| 508 | + $result[$i] = $champ; |
|
| 509 | + $i++; |
|
| 510 | + $texte = substr($texte, $p + strlen($match[0])); |
|
| 511 | + } |
|
| 512 | + if ($texte !== '') { |
|
| 513 | + $result[$i] = $texte; |
|
| 514 | + $i++; |
|
| 515 | + } |
|
| 516 | + $x = ''; |
|
| 517 | + |
|
| 518 | + while ($j < $i) { |
|
| 519 | + $z = $result[$j]; |
|
| 520 | + // j'aurais besoin de connaitre le nombre de lignes... |
|
| 521 | + if (is_object($z)) { |
|
| 522 | + $x .= "%$sep$j@"; |
|
| 523 | + } else { |
|
| 524 | + $x .= $z; |
|
| 525 | + } |
|
| 526 | + $j++; |
|
| 527 | + } |
|
| 528 | + if (preg_match(CHAMP_ETENDU, $x)) { |
|
| 529 | + $texte = $x; |
|
| 530 | + } else { |
|
| 531 | + return phraser_champs_exterieurs($x, $ligne, $sep, $result); |
|
| 532 | + } |
|
| 533 | + } |
|
| 534 | 534 | } |
| 535 | 535 | |
| 536 | 536 | function phraser_vieux(&$champ) { |
| 537 | - $nom = $champ->nom_champ; |
|
| 538 | - if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | - if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | - include_spip('public/normaliser'); |
|
| 541 | - } |
|
| 542 | - phraser_vieux_emb($champ); |
|
| 543 | - } elseif ($nom == 'EXPOSER') { |
|
| 544 | - if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | - include_spip('public/normaliser'); |
|
| 546 | - } |
|
| 547 | - phraser_vieux_exposer($champ); |
|
| 548 | - } elseif ($champ->param) { |
|
| 549 | - if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | - if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | - include_spip('public/normaliser'); |
|
| 552 | - } |
|
| 553 | - phraser_vieux_recherche($champ); |
|
| 554 | - } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | - if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | - include_spip('public/normaliser'); |
|
| 557 | - } |
|
| 558 | - phraser_vieux_logos($champ); |
|
| 559 | - } elseif ($nom == 'MODELE') { |
|
| 560 | - if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | - include_spip('public/normaliser'); |
|
| 562 | - } |
|
| 563 | - phraser_vieux_modele($champ); |
|
| 564 | - } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | - if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | - include_spip('public/normaliser'); |
|
| 567 | - } |
|
| 568 | - phraser_vieux_inclu($champ); |
|
| 569 | - } |
|
| 570 | - } |
|
| 537 | + $nom = $champ->nom_champ; |
|
| 538 | + if ($nom == 'EMBED_DOCUMENT') { |
|
| 539 | + if (!function_exists('phraser_vieux_emb')) { |
|
| 540 | + include_spip('public/normaliser'); |
|
| 541 | + } |
|
| 542 | + phraser_vieux_emb($champ); |
|
| 543 | + } elseif ($nom == 'EXPOSER') { |
|
| 544 | + if (!function_exists('phraser_vieux_exposer')) { |
|
| 545 | + include_spip('public/normaliser'); |
|
| 546 | + } |
|
| 547 | + phraser_vieux_exposer($champ); |
|
| 548 | + } elseif ($champ->param) { |
|
| 549 | + if ($nom == 'FORMULAIRE_RECHERCHE') { |
|
| 550 | + if (!function_exists('phraser_vieux_recherche')) { |
|
| 551 | + include_spip('public/normaliser'); |
|
| 552 | + } |
|
| 553 | + phraser_vieux_recherche($champ); |
|
| 554 | + } elseif (preg_match(',^LOGO_[A-Z]+,', $nom)) { |
|
| 555 | + if (!function_exists('phraser_vieux_logos')) { |
|
| 556 | + include_spip('public/normaliser'); |
|
| 557 | + } |
|
| 558 | + phraser_vieux_logos($champ); |
|
| 559 | + } elseif ($nom == 'MODELE') { |
|
| 560 | + if (!function_exists('phraser_vieux_modele')) { |
|
| 561 | + include_spip('public/normaliser'); |
|
| 562 | + } |
|
| 563 | + phraser_vieux_modele($champ); |
|
| 564 | + } elseif ($nom == 'INCLURE' or $nom == 'INCLUDE') { |
|
| 565 | + if (!function_exists('phraser_vieux_inclu')) { |
|
| 566 | + include_spip('public/normaliser'); |
|
| 567 | + } |
|
| 568 | + phraser_vieux_inclu($champ); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
| 572 | 572 | |
| 573 | 573 | |
@@ -595,200 +595,200 @@ discard block |
||
| 595 | 595 | **/ |
| 596 | 596 | function phraser_criteres($params, &$result) { |
| 597 | 597 | |
| 598 | - $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | - $args = []; |
|
| 600 | - $type = $result->type_requete; |
|
| 601 | - $doublons = []; |
|
| 602 | - foreach ($params as $v) { |
|
| 603 | - $var = $v[1][0]; |
|
| 604 | - $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | - if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | - // plus d'un argument et pas le critere IN: |
|
| 607 | - // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | - if ( |
|
| 609 | - $var->type != 'texte' |
|
| 610 | - or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | - ) { |
|
| 612 | - $op = ','; |
|
| 613 | - $not = false; |
|
| 614 | - $cond = false; |
|
| 615 | - } else { |
|
| 616 | - // Le debut du premier argument est l'operateur |
|
| 617 | - preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | - $op = $m[2]; |
|
| 619 | - $not = (bool) $m[1]; |
|
| 620 | - $cond = $m[3]; |
|
| 621 | - // virer le premier argument, |
|
| 622 | - // et mettre son reliquat eventuel |
|
| 623 | - // Recopier pour ne pas alterer le texte source |
|
| 624 | - // utile au debusqueur |
|
| 625 | - if ($m[4]) { |
|
| 626 | - // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | - if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | - $c = null; |
|
| 629 | - eval('$c = ' . $m[4] . ';'); |
|
| 630 | - if (isset($c)) { |
|
| 631 | - $m[4] = $c; |
|
| 632 | - } |
|
| 633 | - } |
|
| 634 | - $texte = new Texte(); |
|
| 635 | - $texte->texte = $m[4]; |
|
| 636 | - $v[1][0] = $texte; |
|
| 637 | - } else { |
|
| 638 | - array_shift($v[1]); |
|
| 639 | - } |
|
| 640 | - } |
|
| 641 | - array_shift($v); // $v[O] est vide |
|
| 642 | - $crit = new Critere(); |
|
| 643 | - $crit->op = $op; |
|
| 644 | - $crit->not = $not; |
|
| 645 | - $crit->cond = $cond; |
|
| 646 | - $crit->exclus = ''; |
|
| 647 | - $crit->param = $v; |
|
| 648 | - $args[] = $crit; |
|
| 649 | - } else { |
|
| 650 | - if ($var->type != 'texte') { |
|
| 651 | - // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | - // erreur ou critere infixe "/" |
|
| 653 | - if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | - $err_ci = [ |
|
| 655 | - 'zbug_critere_inconnu', |
|
| 656 | - ['critere' => $var->nom_champ] |
|
| 657 | - ]; |
|
| 658 | - erreur_squelette($err_ci, $result); |
|
| 659 | - } else { |
|
| 660 | - $crit = new Critere(); |
|
| 661 | - $crit->op = '/'; |
|
| 662 | - $crit->not = false; |
|
| 663 | - $crit->exclus = ''; |
|
| 664 | - $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | - $args[] = $crit; |
|
| 666 | - } |
|
| 667 | - } else { |
|
| 668 | - // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | - // les separateurs |
|
| 670 | - if ($var->apres) { |
|
| 671 | - $result->separateur[] = $param; |
|
| 672 | - } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | - $result->modificateur['tout'] = true; |
|
| 674 | - } elseif ($param == 'plat') { |
|
| 675 | - $result->modificateur['plat'] = true; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | - // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | - // ceux-ci pour avoir la rubrique mere... |
|
| 681 | - // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | - // traités normalement. |
|
| 683 | - elseif ( |
|
| 684 | - strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | - and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | - and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | - ) { |
|
| 688 | - $result->modificateur['tout'] = true; |
|
| 689 | - } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | - // rien a faire sur {id_rubrique} tout seul |
|
| 691 | - } else { |
|
| 692 | - // pas d'emplacement statique, faut un dynamique |
|
| 693 | - // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | - if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | - // cette variable sera inseree dans le code |
|
| 696 | - // et son nom sert d'indicateur des maintenant |
|
| 697 | - $result->doublons = '$doublons_index'; |
|
| 698 | - if ($param == 'unique') { |
|
| 699 | - $param = 'doublons'; |
|
| 700 | - } |
|
| 701 | - } elseif ($param == 'recherche') { |
|
| 702 | - // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | - $result->hash = ' '; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | - $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | - } elseif ( |
|
| 709 | - preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | - ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | - ) { |
|
| 712 | - $a2 = trim($m[8]); |
|
| 713 | - if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | - $a2 = substr($a2, 1, -1); |
|
| 715 | - } |
|
| 716 | - $crit = phraser_critere_infixe( |
|
| 717 | - $m[2], |
|
| 718 | - $a2, |
|
| 719 | - $v, |
|
| 720 | - (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | - $m[6], |
|
| 722 | - $m[5] |
|
| 723 | - ); |
|
| 724 | - $crit->exclus = $m[1]; |
|
| 725 | - } elseif ( |
|
| 726 | - preg_match('/^([!]?)\s*(' . |
|
| 727 | - CHAMP_SQL_PLUS_FONC . |
|
| 728 | - ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | - ) { |
|
| 730 | - // contient aussi les comparaisons implicites ! |
|
| 731 | - // Comme ci-dessus: |
|
| 732 | - // le premier arg contient l'operateur |
|
| 733 | - array_shift($v); |
|
| 734 | - if ($m[6]) { |
|
| 735 | - $v[0][0] = new Texte(); |
|
| 736 | - $v[0][0]->texte = $m[6]; |
|
| 737 | - } else { |
|
| 738 | - array_shift($v[0]); |
|
| 739 | - if (!$v[0]) { |
|
| 740 | - array_shift($v); |
|
| 741 | - } |
|
| 742 | - } |
|
| 743 | - $crit = new Critere(); |
|
| 744 | - $crit->op = $m[2]; |
|
| 745 | - $crit->param = $v; |
|
| 746 | - $crit->not = (bool) $m[1]; |
|
| 747 | - $crit->cond = $m[5]; |
|
| 748 | - } else { |
|
| 749 | - $err_ci = [ |
|
| 750 | - 'zbug_critere_inconnu', |
|
| 751 | - ['critere' => $param] |
|
| 752 | - ]; |
|
| 753 | - erreur_squelette($err_ci, $result); |
|
| 754 | - } |
|
| 755 | - |
|
| 756 | - if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | - $args[] = $crit; |
|
| 758 | - } else { |
|
| 759 | - $doublons[] = $crit; |
|
| 760 | - } |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - } |
|
| 764 | - } |
|
| 765 | - |
|
| 766 | - // les doublons non nies doivent etre le dernier critere |
|
| 767 | - // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | - // cf critere_doublon |
|
| 769 | - if ($doublons) { |
|
| 770 | - $args = [...$args, ...$doublons]; |
|
| 771 | - } |
|
| 772 | - |
|
| 773 | - // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | - if (!$err_ci) { |
|
| 775 | - $result->criteres = $args; |
|
| 776 | - } |
|
| 598 | + $err_ci = ''; // indiquera s'il y a eu une erreur |
|
| 599 | + $args = []; |
|
| 600 | + $type = $result->type_requete; |
|
| 601 | + $doublons = []; |
|
| 602 | + foreach ($params as $v) { |
|
| 603 | + $var = $v[1][0]; |
|
| 604 | + $param = ($var->type != 'texte') ? '' : $var->texte; |
|
| 605 | + if (((is_countable($v) ? count($v) : 0) > 2) && (!preg_match(',[^A-Za-z]IN[^A-Za-z],i', $param))) { |
|
| 606 | + // plus d'un argument et pas le critere IN: |
|
| 607 | + // detecter comme on peut si c'est le critere implicite LIMIT debut, fin |
|
| 608 | + if ( |
|
| 609 | + $var->type != 'texte' |
|
| 610 | + or preg_match('/^(n|n-|(n-)?\d+)$/S', $param) |
|
| 611 | + ) { |
|
| 612 | + $op = ','; |
|
| 613 | + $not = false; |
|
| 614 | + $cond = false; |
|
| 615 | + } else { |
|
| 616 | + // Le debut du premier argument est l'operateur |
|
| 617 | + preg_match('/^([!]?)([a-zA-Z][a-zA-Z0-9_]*)[[:space:]]*(\??)[[:space:]]*(.*)$/ms', $param, $m); |
|
| 618 | + $op = $m[2]; |
|
| 619 | + $not = (bool) $m[1]; |
|
| 620 | + $cond = $m[3]; |
|
| 621 | + // virer le premier argument, |
|
| 622 | + // et mettre son reliquat eventuel |
|
| 623 | + // Recopier pour ne pas alterer le texte source |
|
| 624 | + // utile au debusqueur |
|
| 625 | + if ($m[4]) { |
|
| 626 | + // une maniere tres sale de supprimer les "' autour de {critere "xxx","yyy"} |
|
| 627 | + if (preg_match(',^(["\'])(.*)\1$,', $m[4])) { |
|
| 628 | + $c = null; |
|
| 629 | + eval('$c = ' . $m[4] . ';'); |
|
| 630 | + if (isset($c)) { |
|
| 631 | + $m[4] = $c; |
|
| 632 | + } |
|
| 633 | + } |
|
| 634 | + $texte = new Texte(); |
|
| 635 | + $texte->texte = $m[4]; |
|
| 636 | + $v[1][0] = $texte; |
|
| 637 | + } else { |
|
| 638 | + array_shift($v[1]); |
|
| 639 | + } |
|
| 640 | + } |
|
| 641 | + array_shift($v); // $v[O] est vide |
|
| 642 | + $crit = new Critere(); |
|
| 643 | + $crit->op = $op; |
|
| 644 | + $crit->not = $not; |
|
| 645 | + $crit->cond = $cond; |
|
| 646 | + $crit->exclus = ''; |
|
| 647 | + $crit->param = $v; |
|
| 648 | + $args[] = $crit; |
|
| 649 | + } else { |
|
| 650 | + if ($var->type != 'texte') { |
|
| 651 | + // cas 1 seul arg ne commencant pas par du texte brut: |
|
| 652 | + // erreur ou critere infixe "/" |
|
| 653 | + if (($v[1][1]->type != 'texte') || (trim($v[1][1]->texte) != '/')) { |
|
| 654 | + $err_ci = [ |
|
| 655 | + 'zbug_critere_inconnu', |
|
| 656 | + ['critere' => $var->nom_champ] |
|
| 657 | + ]; |
|
| 658 | + erreur_squelette($err_ci, $result); |
|
| 659 | + } else { |
|
| 660 | + $crit = new Critere(); |
|
| 661 | + $crit->op = '/'; |
|
| 662 | + $crit->not = false; |
|
| 663 | + $crit->exclus = ''; |
|
| 664 | + $crit->param = [[$v[1][0]], [$v[1][2]]]; |
|
| 665 | + $args[] = $crit; |
|
| 666 | + } |
|
| 667 | + } else { |
|
| 668 | + // traiter qq lexemes particuliers pour faciliter la suite |
|
| 669 | + // les separateurs |
|
| 670 | + if ($var->apres) { |
|
| 671 | + $result->separateur[] = $param; |
|
| 672 | + } elseif (($param == 'tout') or ($param == 'tous')) { |
|
| 673 | + $result->modificateur['tout'] = true; |
|
| 674 | + } elseif ($param == 'plat') { |
|
| 675 | + $result->modificateur['plat'] = true; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + // Boucle hierarchie, analyser le critere id_rubrique |
|
| 679 | + // et les autres critères {id_x} pour forcer {tout} sur |
|
| 680 | + // ceux-ci pour avoir la rubrique mere... |
|
| 681 | + // Les autres critères de la boucle hierarchie doivent être |
|
| 682 | + // traités normalement. |
|
| 683 | + elseif ( |
|
| 684 | + strcasecmp($type, 'hierarchie') == 0 |
|
| 685 | + and !preg_match(",^id_rubrique\b,", $param) |
|
| 686 | + and preg_match(',^id_\w+\s*$,', $param) |
|
| 687 | + ) { |
|
| 688 | + $result->modificateur['tout'] = true; |
|
| 689 | + } elseif (strcasecmp($type, 'hierarchie') == 0 and $param == 'id_rubrique') { |
|
| 690 | + // rien a faire sur {id_rubrique} tout seul |
|
| 691 | + } else { |
|
| 692 | + // pas d'emplacement statique, faut un dynamique |
|
| 693 | + // mais il y a 2 cas qui ont les 2 ! |
|
| 694 | + if (($param == 'unique') || (preg_match(',^!?doublons *,', $param))) { |
|
| 695 | + // cette variable sera inseree dans le code |
|
| 696 | + // et son nom sert d'indicateur des maintenant |
|
| 697 | + $result->doublons = '$doublons_index'; |
|
| 698 | + if ($param == 'unique') { |
|
| 699 | + $param = 'doublons'; |
|
| 700 | + } |
|
| 701 | + } elseif ($param == 'recherche') { |
|
| 702 | + // meme chose (a cause de #nom_de_boucle:URL_*) |
|
| 703 | + $result->hash = ' '; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (preg_match(',^ *([0-9-]+) *(/) *(.+) *$,', $param, $m)) { |
|
| 707 | + $crit = phraser_critere_infixe($m[1], $m[3], $v, '/', '', ''); |
|
| 708 | + } elseif ( |
|
| 709 | + preg_match(',^([!]?)(' . CHAMP_SQL_PLUS_FONC . |
|
| 710 | + ')[[:space:]]*(\??)(!?)(<=?|>=?|==?|\b(?:IN|LIKE)\b)(.*)$,is', $param, $m) |
|
| 711 | + ) { |
|
| 712 | + $a2 = trim($m[8]); |
|
| 713 | + if ($a2 and ($a2[0] == "'" or $a2[0] == '"') and ($a2[0] == substr($a2, -1))) { |
|
| 714 | + $a2 = substr($a2, 1, -1); |
|
| 715 | + } |
|
| 716 | + $crit = phraser_critere_infixe( |
|
| 717 | + $m[2], |
|
| 718 | + $a2, |
|
| 719 | + $v, |
|
| 720 | + (($m[2] == 'lang_select') ? $m[2] : $m[7]), |
|
| 721 | + $m[6], |
|
| 722 | + $m[5] |
|
| 723 | + ); |
|
| 724 | + $crit->exclus = $m[1]; |
|
| 725 | + } elseif ( |
|
| 726 | + preg_match('/^([!]?)\s*(' . |
|
| 727 | + CHAMP_SQL_PLUS_FONC . |
|
| 728 | + ')\s*(\??)(.*)$/is', $param, $m) |
|
| 729 | + ) { |
|
| 730 | + // contient aussi les comparaisons implicites ! |
|
| 731 | + // Comme ci-dessus: |
|
| 732 | + // le premier arg contient l'operateur |
|
| 733 | + array_shift($v); |
|
| 734 | + if ($m[6]) { |
|
| 735 | + $v[0][0] = new Texte(); |
|
| 736 | + $v[0][0]->texte = $m[6]; |
|
| 737 | + } else { |
|
| 738 | + array_shift($v[0]); |
|
| 739 | + if (!$v[0]) { |
|
| 740 | + array_shift($v); |
|
| 741 | + } |
|
| 742 | + } |
|
| 743 | + $crit = new Critere(); |
|
| 744 | + $crit->op = $m[2]; |
|
| 745 | + $crit->param = $v; |
|
| 746 | + $crit->not = (bool) $m[1]; |
|
| 747 | + $crit->cond = $m[5]; |
|
| 748 | + } else { |
|
| 749 | + $err_ci = [ |
|
| 750 | + 'zbug_critere_inconnu', |
|
| 751 | + ['critere' => $param] |
|
| 752 | + ]; |
|
| 753 | + erreur_squelette($err_ci, $result); |
|
| 754 | + } |
|
| 755 | + |
|
| 756 | + if ((!preg_match(',^!?doublons *,', $param)) || $crit->not) { |
|
| 757 | + $args[] = $crit; |
|
| 758 | + } else { |
|
| 759 | + $doublons[] = $crit; |
|
| 760 | + } |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + } |
|
| 764 | + } |
|
| 765 | + |
|
| 766 | + // les doublons non nies doivent etre le dernier critere |
|
| 767 | + // pour que la variable $doublon_index ait la bonne valeur |
|
| 768 | + // cf critere_doublon |
|
| 769 | + if ($doublons) { |
|
| 770 | + $args = [...$args, ...$doublons]; |
|
| 771 | + } |
|
| 772 | + |
|
| 773 | + // Si erreur, laisser la chaine dans ce champ pour le HTTP 503 |
|
| 774 | + if (!$err_ci) { |
|
| 775 | + $result->criteres = $args; |
|
| 776 | + } |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | function phraser_critere_infixe($arg1, $arg2, $args, $op, $not, $cond) { |
| 780 | - $args[0] = new Texte(); |
|
| 781 | - $args[0]->texte = $arg1; |
|
| 782 | - $args[0] = [$args[0]]; |
|
| 783 | - $args[1][0] = new Texte(); |
|
| 784 | - $args[1][0]->texte = $arg2; |
|
| 785 | - $crit = new Critere(); |
|
| 786 | - $crit->op = $op; |
|
| 787 | - $crit->not = $not; |
|
| 788 | - $crit->cond = $cond; |
|
| 789 | - $crit->param = $args; |
|
| 790 | - |
|
| 791 | - return $crit; |
|
| 780 | + $args[0] = new Texte(); |
|
| 781 | + $args[0]->texte = $arg1; |
|
| 782 | + $args[0] = [$args[0]]; |
|
| 783 | + $args[1][0] = new Texte(); |
|
| 784 | + $args[1][0]->texte = $arg2; |
|
| 785 | + $crit = new Critere(); |
|
| 786 | + $crit->op = $op; |
|
| 787 | + $crit->not = $not; |
|
| 788 | + $crit->cond = $cond; |
|
| 789 | + $crit->param = $args; |
|
| 790 | + |
|
| 791 | + return $crit; |
|
| 792 | 792 | } |
| 793 | 793 | |
| 794 | 794 | /** |
@@ -799,12 +799,12 @@ discard block |
||
| 799 | 799 | * @return int |
| 800 | 800 | */ |
| 801 | 801 | function public_compte_ligne($texte, $debut = 0, $fin = null) { |
| 802 | - if (is_null($fin)) { |
|
| 803 | - return substr_count($texte, "\n", $debut); |
|
| 804 | - } |
|
| 805 | - else { |
|
| 806 | - return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 807 | - } |
|
| 802 | + if (is_null($fin)) { |
|
| 803 | + return substr_count($texte, "\n", $debut); |
|
| 804 | + } |
|
| 805 | + else { |
|
| 806 | + return substr_count($texte, "\n", $debut, $fin - $debut); |
|
| 807 | + } |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | |
@@ -820,87 +820,87 @@ discard block |
||
| 820 | 820 | * @return array|null |
| 821 | 821 | */ |
| 822 | 822 | function public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte = 0) { |
| 823 | - $premiere_boucle = null; |
|
| 824 | - $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 825 | - |
|
| 826 | - $current_pos = $pos_debut_texte; |
|
| 827 | - while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 828 | - $current_pos = $pos_boucle + 1; |
|
| 829 | - $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 830 | - |
|
| 831 | - $id_boucle = ''; |
|
| 832 | - if ($pos_parent !== false) { |
|
| 833 | - $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 834 | - } |
|
| 835 | - if ( |
|
| 836 | - $pos_parent === false |
|
| 837 | - or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 838 | - ) { |
|
| 839 | - $result = new Boucle(); |
|
| 840 | - $result->id_parent = $id_parent; |
|
| 841 | - $result->descr = $descr; |
|
| 842 | - |
|
| 843 | - // un id_boucle pour l'affichage de l'erreur |
|
| 844 | - if (!strlen($id_boucle)) { |
|
| 845 | - $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 846 | - } |
|
| 847 | - $result->id_boucle = $id_boucle; |
|
| 848 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 849 | - erreur_squelette($err_b, $result); |
|
| 850 | - |
|
| 851 | - continue; |
|
| 852 | - } |
|
| 853 | - else { |
|
| 854 | - $boucle = [ |
|
| 855 | - 'id_boucle' => $id_boucle, |
|
| 856 | - 'id_boucle_err' => $id_boucle, |
|
| 857 | - 'debut_boucle' => $pos_boucle, |
|
| 858 | - 'pos_boucle' => $pos_boucle, |
|
| 859 | - 'pos_parent' => $pos_parent, |
|
| 860 | - 'pos_precond' => false, |
|
| 861 | - 'pos_precond_inside' => false, |
|
| 862 | - 'pos_preaff' => false, |
|
| 863 | - 'pos_preaff_inside' => false, |
|
| 864 | - ]; |
|
| 865 | - |
|
| 866 | - // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 867 | - if (!strlen($id_boucle)) { |
|
| 868 | - $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 869 | - } |
|
| 870 | - |
|
| 871 | - // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 872 | - $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | - $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 874 | - if ( |
|
| 875 | - $pos_precond !== false |
|
| 876 | - and $pos_precond < $boucle['debut_boucle'] |
|
| 877 | - ) { |
|
| 878 | - $boucle['debut_boucle'] = $pos_precond; |
|
| 879 | - $boucle['pos_precond'] = $pos_precond; |
|
| 880 | - $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 881 | - } |
|
| 882 | - |
|
| 883 | - $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | - $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 885 | - if ( |
|
| 886 | - $pos_preaff !== false |
|
| 887 | - and $pos_preaff < $boucle['debut_boucle'] |
|
| 888 | - ) { |
|
| 889 | - $boucle['debut_boucle'] = $pos_preaff; |
|
| 890 | - $boucle['pos_preaff'] = $pos_preaff; |
|
| 891 | - $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 892 | - } |
|
| 893 | - if (!strlen($id_boucle)) { |
|
| 894 | - $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 895 | - } |
|
| 896 | - |
|
| 897 | - if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 898 | - $premiere_boucle = $boucle; |
|
| 899 | - } |
|
| 900 | - } |
|
| 901 | - } |
|
| 902 | - |
|
| 903 | - return $premiere_boucle; |
|
| 823 | + $premiere_boucle = null; |
|
| 824 | + $pos_derniere_boucle_anonyme = $pos_debut_texte; |
|
| 825 | + |
|
| 826 | + $current_pos = $pos_debut_texte; |
|
| 827 | + while (($pos_boucle = strpos($texte, BALISE_BOUCLE, $current_pos)) !== false) { |
|
| 828 | + $current_pos = $pos_boucle + 1; |
|
| 829 | + $pos_parent = strpos($texte, '(', $pos_boucle); |
|
| 830 | + |
|
| 831 | + $id_boucle = ''; |
|
| 832 | + if ($pos_parent !== false) { |
|
| 833 | + $id_boucle = trim(substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), $pos_parent - $pos_boucle - strlen(BALISE_BOUCLE))); |
|
| 834 | + } |
|
| 835 | + if ( |
|
| 836 | + $pos_parent === false |
|
| 837 | + or (strlen($id_boucle) and !(is_numeric($id_boucle) or strpos($id_boucle, '_') === 0)) |
|
| 838 | + ) { |
|
| 839 | + $result = new Boucle(); |
|
| 840 | + $result->id_parent = $id_parent; |
|
| 841 | + $result->descr = $descr; |
|
| 842 | + |
|
| 843 | + // un id_boucle pour l'affichage de l'erreur |
|
| 844 | + if (!strlen($id_boucle)) { |
|
| 845 | + $id_boucle = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 846 | + } |
|
| 847 | + $result->id_boucle = $id_boucle; |
|
| 848 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 849 | + erreur_squelette($err_b, $result); |
|
| 850 | + |
|
| 851 | + continue; |
|
| 852 | + } |
|
| 853 | + else { |
|
| 854 | + $boucle = [ |
|
| 855 | + 'id_boucle' => $id_boucle, |
|
| 856 | + 'id_boucle_err' => $id_boucle, |
|
| 857 | + 'debut_boucle' => $pos_boucle, |
|
| 858 | + 'pos_boucle' => $pos_boucle, |
|
| 859 | + 'pos_parent' => $pos_parent, |
|
| 860 | + 'pos_precond' => false, |
|
| 861 | + 'pos_precond_inside' => false, |
|
| 862 | + 'pos_preaff' => false, |
|
| 863 | + 'pos_preaff_inside' => false, |
|
| 864 | + ]; |
|
| 865 | + |
|
| 866 | + // un id_boucle pour l'affichage de l'erreur sur les boucle anonymes |
|
| 867 | + if (!strlen($id_boucle)) { |
|
| 868 | + $boucle['id_boucle_err'] = substr($texte, $pos_boucle + strlen(BALISE_BOUCLE), 15); |
|
| 869 | + } |
|
| 870 | + |
|
| 871 | + // trouver sa position de depart reelle : au <Bxx> ou au <BBxx> |
|
| 872 | + $precond_boucle = BALISE_PRECOND_BOUCLE . $id_boucle . '>'; |
|
| 873 | + $pos_precond = strpos($texte, $precond_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 874 | + if ( |
|
| 875 | + $pos_precond !== false |
|
| 876 | + and $pos_precond < $boucle['debut_boucle'] |
|
| 877 | + ) { |
|
| 878 | + $boucle['debut_boucle'] = $pos_precond; |
|
| 879 | + $boucle['pos_precond'] = $pos_precond; |
|
| 880 | + $boucle['pos_precond_inside'] = $pos_precond + strlen($precond_boucle); |
|
| 881 | + } |
|
| 882 | + |
|
| 883 | + $preaff_boucle = BALISE_PREAFF_BOUCLE . $id_boucle . '>'; |
|
| 884 | + $pos_preaff = strpos($texte, $preaff_boucle, $id_boucle ? $pos_debut_texte : $pos_derniere_boucle_anonyme); |
|
| 885 | + if ( |
|
| 886 | + $pos_preaff !== false |
|
| 887 | + and $pos_preaff < $boucle['debut_boucle'] |
|
| 888 | + ) { |
|
| 889 | + $boucle['debut_boucle'] = $pos_preaff; |
|
| 890 | + $boucle['pos_preaff'] = $pos_preaff; |
|
| 891 | + $boucle['pos_preaff_inside'] = $pos_preaff + strlen($preaff_boucle); |
|
| 892 | + } |
|
| 893 | + if (!strlen($id_boucle)) { |
|
| 894 | + $pos_derniere_boucle_anonyme = $pos_boucle; |
|
| 895 | + } |
|
| 896 | + |
|
| 897 | + if (is_null($premiere_boucle) or $premiere_boucle['debut_boucle'] > $boucle['debut_boucle']) { |
|
| 898 | + $premiere_boucle = $boucle; |
|
| 899 | + } |
|
| 900 | + } |
|
| 901 | + } |
|
| 902 | + |
|
| 903 | + return $premiere_boucle; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -915,68 +915,68 @@ discard block |
||
| 915 | 915 | * @return mixed |
| 916 | 916 | */ |
| 917 | 917 | function public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_debut_texte, $result) { |
| 918 | - $id_boucle = $boucle['id_boucle']; |
|
| 919 | - $pos_courante = $pos_debut_texte; |
|
| 920 | - |
|
| 921 | - $boucle['pos_postcond'] = false; |
|
| 922 | - $boucle['pos_postcond_inside'] = false; |
|
| 923 | - $boucle['pos_altern'] = false; |
|
| 924 | - $boucle['pos_altern_inside'] = false; |
|
| 925 | - $boucle['pos_postaff'] = false; |
|
| 926 | - $boucle['pos_postaff_inside'] = false; |
|
| 927 | - |
|
| 928 | - $pos_anonyme_next = null; |
|
| 929 | - // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 930 | - if (!strlen($id_boucle)) { |
|
| 931 | - $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | - } |
|
| 933 | - |
|
| 934 | - // |
|
| 935 | - // 1. Recuperer la partie conditionnelle apres |
|
| 936 | - // |
|
| 937 | - $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | - $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 939 | - if ( |
|
| 940 | - $pos_apres !== false |
|
| 941 | - and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 942 | - ) { |
|
| 943 | - $boucle['pos_postcond'] = $pos_apres; |
|
| 944 | - $pos_apres += strlen($apres_boucle); |
|
| 945 | - $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 946 | - $pos_courante = $pos_apres ; |
|
| 947 | - } |
|
| 948 | - |
|
| 949 | - // |
|
| 950 | - // 2. Récuperer la partie alternative apres |
|
| 951 | - // |
|
| 952 | - $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | - $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 954 | - if ( |
|
| 955 | - $pos_altern !== false |
|
| 956 | - and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 957 | - ) { |
|
| 958 | - $boucle['pos_altern'] = $pos_altern; |
|
| 959 | - $pos_altern += strlen($altern_boucle); |
|
| 960 | - $boucle['pos_altern_inside'] = $pos_altern; |
|
| 961 | - $pos_courante = $pos_altern; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - // |
|
| 965 | - // 3. Recuperer la partie footer non alternative |
|
| 966 | - // |
|
| 967 | - $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | - $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 969 | - if ( |
|
| 970 | - $pos_postaff !== false |
|
| 971 | - and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 972 | - ) { |
|
| 973 | - $boucle['pos_postaff'] = $pos_postaff; |
|
| 974 | - $pos_postaff += strlen($postaff_boucle); |
|
| 975 | - $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 976 | - $pos_courante = $pos_postaff ; |
|
| 977 | - } |
|
| 978 | - |
|
| 979 | - return $boucle; |
|
| 918 | + $id_boucle = $boucle['id_boucle']; |
|
| 919 | + $pos_courante = $pos_debut_texte; |
|
| 920 | + |
|
| 921 | + $boucle['pos_postcond'] = false; |
|
| 922 | + $boucle['pos_postcond_inside'] = false; |
|
| 923 | + $boucle['pos_altern'] = false; |
|
| 924 | + $boucle['pos_altern_inside'] = false; |
|
| 925 | + $boucle['pos_postaff'] = false; |
|
| 926 | + $boucle['pos_postaff_inside'] = false; |
|
| 927 | + |
|
| 928 | + $pos_anonyme_next = null; |
|
| 929 | + // si c'est une boucle anonyme, chercher la position de la prochaine boucle anonyme |
|
| 930 | + if (!strlen($id_boucle)) { |
|
| 931 | + $pos_anonyme_next = strpos($texte, BALISE_BOUCLE . '(', $pos_courante); |
|
| 932 | + } |
|
| 933 | + |
|
| 934 | + // |
|
| 935 | + // 1. Recuperer la partie conditionnelle apres |
|
| 936 | + // |
|
| 937 | + $apres_boucle = BALISE_POSTCOND_BOUCLE . $id_boucle . '>'; |
|
| 938 | + $pos_apres = strpos($texte, $apres_boucle, $pos_courante); |
|
| 939 | + if ( |
|
| 940 | + $pos_apres !== false |
|
| 941 | + and (!$pos_anonyme_next or $pos_apres < $pos_anonyme_next) |
|
| 942 | + ) { |
|
| 943 | + $boucle['pos_postcond'] = $pos_apres; |
|
| 944 | + $pos_apres += strlen($apres_boucle); |
|
| 945 | + $boucle['pos_postcond_inside'] = $pos_apres; |
|
| 946 | + $pos_courante = $pos_apres ; |
|
| 947 | + } |
|
| 948 | + |
|
| 949 | + // |
|
| 950 | + // 2. Récuperer la partie alternative apres |
|
| 951 | + // |
|
| 952 | + $altern_boucle = BALISE_ALT_BOUCLE . $id_boucle . '>'; |
|
| 953 | + $pos_altern = strpos($texte, $altern_boucle, $pos_courante); |
|
| 954 | + if ( |
|
| 955 | + $pos_altern !== false |
|
| 956 | + and (!$pos_anonyme_next or $pos_altern < $pos_anonyme_next) |
|
| 957 | + ) { |
|
| 958 | + $boucle['pos_altern'] = $pos_altern; |
|
| 959 | + $pos_altern += strlen($altern_boucle); |
|
| 960 | + $boucle['pos_altern_inside'] = $pos_altern; |
|
| 961 | + $pos_courante = $pos_altern; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + // |
|
| 965 | + // 3. Recuperer la partie footer non alternative |
|
| 966 | + // |
|
| 967 | + $postaff_boucle = BALISE_POSTAFF_BOUCLE . $id_boucle . '>'; |
|
| 968 | + $pos_postaff = strpos($texte, $postaff_boucle, $pos_courante); |
|
| 969 | + if ( |
|
| 970 | + $pos_postaff !== false |
|
| 971 | + and (!$pos_anonyme_next or $pos_postaff < $pos_anonyme_next) |
|
| 972 | + ) { |
|
| 973 | + $boucle['pos_postaff'] = $pos_postaff; |
|
| 974 | + $pos_postaff += strlen($postaff_boucle); |
|
| 975 | + $boucle['pos_postaff_inside'] = $pos_postaff; |
|
| 976 | + $pos_courante = $pos_postaff ; |
|
| 977 | + } |
|
| 978 | + |
|
| 979 | + return $boucle; |
|
| 980 | 980 | } |
| 981 | 981 | |
| 982 | 982 | |
@@ -986,21 +986,21 @@ discard block |
||
| 986 | 986 | * @param null|object $boucle |
| 987 | 987 | */ |
| 988 | 988 | function phraser_boucle_placeholder(&$champ, $boucle_placeholder = null, $boucle = null) { |
| 989 | - static $boucles_connues = []; |
|
| 990 | - // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 991 | - if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 992 | - $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 993 | - } |
|
| 994 | - else { |
|
| 995 | - if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 996 | - $placeholder = $champ->nom_champ; |
|
| 997 | - $id = reset($champ->param[0][1]); |
|
| 998 | - $id = $id->texte; |
|
| 999 | - if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1000 | - $champ = $boucles_connues[$placeholder][$id]; |
|
| 1001 | - } |
|
| 1002 | - } |
|
| 1003 | - } |
|
| 989 | + static $boucles_connues = []; |
|
| 990 | + // si c'est un appel pour memoriser une boucle, memorisons la |
|
| 991 | + if (is_string($champ) and !empty($boucle_placeholder) and !empty($boucle)) { |
|
| 992 | + $boucles_connues[$boucle_placeholder][$champ] = &$boucle; |
|
| 993 | + } |
|
| 994 | + else { |
|
| 995 | + if (!empty($champ->nom_champ) and !empty($boucles_connues[$champ->nom_champ])) { |
|
| 996 | + $placeholder = $champ->nom_champ; |
|
| 997 | + $id = reset($champ->param[0][1]); |
|
| 998 | + $id = $id->texte; |
|
| 999 | + if (!empty($boucles_connues[$placeholder][$id])) { |
|
| 1000 | + $champ = $boucles_connues[$placeholder][$id]; |
|
| 1001 | + } |
|
| 1002 | + } |
|
| 1003 | + } |
|
| 1004 | 1004 | } |
| 1005 | 1005 | |
| 1006 | 1006 | |
@@ -1013,274 +1013,274 @@ discard block |
||
| 1013 | 1013 | * @return string |
| 1014 | 1014 | */ |
| 1015 | 1015 | function public_generer_boucle_placeholder($id_boucle, &$boucle, $boucle_placeholder, $nb_lignes) { |
| 1016 | - $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | - //memoriser la boucle a reinjecter |
|
| 1018 | - $id_boucle = "$id_boucle"; |
|
| 1019 | - phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1020 | - return $placeholder; |
|
| 1016 | + $placeholder = "[(#{$boucle_placeholder}{" . $id_boucle . '})' . str_pad('', $nb_lignes, "\n") . ']'; |
|
| 1017 | + //memoriser la boucle a reinjecter |
|
| 1018 | + $id_boucle = "$id_boucle"; |
|
| 1019 | + phraser_boucle_placeholder($id_boucle, $boucle_placeholder, $boucle); |
|
| 1020 | + return $placeholder; |
|
| 1021 | 1021 | } |
| 1022 | 1022 | |
| 1023 | 1023 | function public_phraser_html_dist($texte, $id_parent, &$boucles, $descr, $ligne_debut_texte = 1, $boucle_placeholder = null) { |
| 1024 | 1024 | |
| 1025 | - $all_res = []; |
|
| 1026 | - // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1027 | - if (is_null($boucle_placeholder)) { |
|
| 1028 | - do { |
|
| 1029 | - $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | - } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1031 | - } |
|
| 1032 | - |
|
| 1033 | - $ligne_debut_initial = $ligne_debut_texte; |
|
| 1034 | - $pos_debut_texte = 0; |
|
| 1035 | - while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1036 | - $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1037 | - $result = new Boucle(); |
|
| 1038 | - $result->id_parent = $id_parent; |
|
| 1039 | - $result->descr = $descr; |
|
| 1040 | - |
|
| 1041 | - $pos_courante = $boucle['pos_boucle']; |
|
| 1042 | - $pos_parent = $boucle['pos_parent']; |
|
| 1043 | - $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1044 | - |
|
| 1045 | - $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1046 | - |
|
| 1047 | - // boucle anonyme ? |
|
| 1048 | - if (!strlen($id_boucle)) { |
|
| 1049 | - $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1050 | - } |
|
| 1051 | - |
|
| 1052 | - $pos_debut_boucle = $pos_courante; |
|
| 1053 | - |
|
| 1054 | - $pos_milieu = $pos_parent; |
|
| 1055 | - |
|
| 1056 | - // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1057 | - if ($boucle['pos_precond'] !== false) { |
|
| 1058 | - $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1059 | - |
|
| 1060 | - $pos_avant = $boucle['pos_precond_inside']; |
|
| 1061 | - $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1062 | - $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | - } |
|
| 1064 | - |
|
| 1065 | - // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1066 | - if ($boucle['pos_preaff'] !== false) { |
|
| 1067 | - $end_preaff = $pos_debut_boucle; |
|
| 1068 | - |
|
| 1069 | - $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1070 | - $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1071 | - $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | - } |
|
| 1073 | - |
|
| 1074 | - $result->id_boucle = $id_boucle; |
|
| 1075 | - |
|
| 1076 | - if ( |
|
| 1077 | - !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1078 | - or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1079 | - or $pos_match > $pos_milieu |
|
| 1080 | - ) { |
|
| 1081 | - $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1082 | - erreur_squelette($err_b, $result); |
|
| 1083 | - |
|
| 1084 | - $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1085 | - $pos_debut_texte = $pos_courante + 1; |
|
| 1086 | - continue; |
|
| 1087 | - } |
|
| 1088 | - |
|
| 1089 | - $result->type_requete = $match[0]; |
|
| 1090 | - $pos_milieu += strlen($match[0]); |
|
| 1091 | - $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1092 | - |
|
| 1093 | - $type = $match[1]; |
|
| 1094 | - $jointures = trim($match[2]); |
|
| 1095 | - $table_optionnelle = ($match[3]); |
|
| 1096 | - if ($jointures) { |
|
| 1097 | - // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1098 | - // ou elles seront completees des jointures declarees |
|
| 1099 | - $result->jointures_explicites = $jointures; |
|
| 1100 | - } |
|
| 1101 | - |
|
| 1102 | - if ($table_optionnelle) { |
|
| 1103 | - $result->table_optionnelle = $type; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1107 | - // Resultat mis dans result->param |
|
| 1108 | - $pos_fin_criteres = $pos_milieu; |
|
| 1109 | - phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1110 | - |
|
| 1111 | - // En 2e passe result->criteres contiendra un tableau |
|
| 1112 | - // pour l'instant on met le source (chaine) : |
|
| 1113 | - // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1114 | - $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1115 | - $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1116 | - $pos_milieu = $pos_fin_criteres; |
|
| 1117 | - |
|
| 1118 | - // |
|
| 1119 | - // Recuperer la fin : |
|
| 1120 | - // |
|
| 1121 | - if ($texte[$pos_milieu] === '/') { |
|
| 1122 | - // boucle autofermante : pas de partie conditionnelle apres |
|
| 1123 | - $pos_courante += 2; |
|
| 1124 | - $result->milieu = ''; |
|
| 1125 | - } else { |
|
| 1126 | - $pos_milieu += 1; |
|
| 1127 | - |
|
| 1128 | - $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | - $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1130 | - if ($pos_fin === false) { |
|
| 1131 | - $err_b = [ |
|
| 1132 | - 'zbug_erreur_boucle_fermant', |
|
| 1133 | - ['id' => $id_boucle] |
|
| 1134 | - ]; |
|
| 1135 | - erreur_squelette($err_b, $result); |
|
| 1136 | - $pos_courante += strlen($fin_boucle); |
|
| 1137 | - } |
|
| 1138 | - else { |
|
| 1139 | - // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1140 | - // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1141 | - $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | - $search_from = $pos_milieu; |
|
| 1143 | - $nb_open = 1; |
|
| 1144 | - $nb_close = 1; |
|
| 1145 | - $maxiter = 0; |
|
| 1146 | - do { |
|
| 1147 | - while ( |
|
| 1148 | - $nb_close < $nb_open |
|
| 1149 | - and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1150 | - ) { |
|
| 1151 | - $nb_close++; |
|
| 1152 | - $pos_fin = $p; |
|
| 1153 | - } |
|
| 1154 | - // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1155 | - if ($nb_close < $nb_open) { |
|
| 1156 | - break; |
|
| 1157 | - } |
|
| 1158 | - while ( |
|
| 1159 | - $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1160 | - and $p < $pos_fin |
|
| 1161 | - ) { |
|
| 1162 | - $nb_open++; |
|
| 1163 | - $search_from = $p + 1; |
|
| 1164 | - } |
|
| 1165 | - } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1166 | - |
|
| 1167 | - $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1168 | - } |
|
| 1169 | - $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1170 | - } |
|
| 1171 | - |
|
| 1172 | - $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1173 | - $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1174 | - |
|
| 1175 | - // |
|
| 1176 | - // 1. Partie conditionnelle apres ? |
|
| 1177 | - // |
|
| 1178 | - if ($boucle['pos_postcond']) { |
|
| 1179 | - $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1180 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1181 | - $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | - } |
|
| 1183 | - |
|
| 1184 | - |
|
| 1185 | - // |
|
| 1186 | - // 2. Partie alternative apres ? |
|
| 1187 | - // |
|
| 1188 | - $ligne_altern = $ligne_suite; |
|
| 1189 | - if ($boucle['pos_altern']) { |
|
| 1190 | - $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1191 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1192 | - $pos_courante = $boucle['pos_altern_inside']; |
|
| 1193 | - } |
|
| 1194 | - |
|
| 1195 | - // |
|
| 1196 | - // 3. Partie footer non alternative ? |
|
| 1197 | - // |
|
| 1198 | - $ligne_postaff = $ligne_suite; |
|
| 1199 | - if ($boucle['pos_postaff']) { |
|
| 1200 | - $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1201 | - $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1202 | - $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - $result->ligne = $ligne_preaff; |
|
| 1206 | - |
|
| 1207 | - if ($p = strpos($type, ':')) { |
|
| 1208 | - $result->sql_serveur = substr($type, 0, $p); |
|
| 1209 | - $type = substr($type, $p + 1); |
|
| 1210 | - } |
|
| 1211 | - $soustype = strtolower($type); |
|
| 1212 | - |
|
| 1213 | - if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1214 | - $soustype = $type; |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - $result->type_requete = $soustype; |
|
| 1218 | - // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1219 | - if (!is_array($result->param)) { |
|
| 1220 | - $err_b = true; |
|
| 1221 | - } else { |
|
| 1222 | - phraser_criteres($result->param, $result); |
|
| 1223 | - if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1224 | - $result->type_requete = TYPE_RECURSIF; |
|
| 1225 | - $args = $result->param; |
|
| 1226 | - array_unshift( |
|
| 1227 | - $args, |
|
| 1228 | - substr($type, strlen(TYPE_RECURSIF)) |
|
| 1229 | - ); |
|
| 1230 | - $result->param = $args; |
|
| 1231 | - } |
|
| 1232 | - } |
|
| 1233 | - |
|
| 1234 | - $descr['id_mere_contexte'] = $id_boucle; |
|
| 1235 | - $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1236 | - // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1237 | - // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1238 | - // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1239 | - if (empty($boucles[$id_boucle])) { |
|
| 1240 | - $boucles[$id_boucle] = null; |
|
| 1241 | - } |
|
| 1242 | - $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1243 | - $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1244 | - $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1245 | - $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1246 | - $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1247 | - |
|
| 1248 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1249 | - if ($err_b) { |
|
| 1250 | - $result->type_requete = false; |
|
| 1251 | - } |
|
| 1252 | - |
|
| 1253 | - // Verifier qu'il n'y a pas double definition |
|
| 1254 | - // apres analyse des sous-parties (pas avant). |
|
| 1255 | - if (!empty($boucles[$id_boucle])) { |
|
| 1256 | - if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1257 | - $err_b_d = [ |
|
| 1258 | - 'zbug_erreur_boucle_double', |
|
| 1259 | - ['id' => $id_boucle] |
|
| 1260 | - ]; |
|
| 1261 | - erreur_squelette($err_b_d, $result); |
|
| 1262 | - // Prevenir le generateur de code que le squelette est faux |
|
| 1263 | - $boucles[$id_boucle]->type_requete = false; |
|
| 1264 | - } |
|
| 1265 | - } else { |
|
| 1266 | - $boucles[$id_boucle] = $result; |
|
| 1267 | - } |
|
| 1268 | - |
|
| 1269 | - // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1270 | - $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1271 | - $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1272 | - $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1273 | - $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1274 | - |
|
| 1275 | - // phraser la partie avant le debut de la boucle |
|
| 1276 | - #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1277 | - #$all_res[] = &$boucles[$id_boucle]; |
|
| 1278 | - |
|
| 1279 | - $ligne_debut_texte = $ligne_suite; |
|
| 1280 | - $pos_debut_texte = $pos_courante; |
|
| 1281 | - } |
|
| 1282 | - |
|
| 1283 | - $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1284 | - |
|
| 1285 | - return $all_res; |
|
| 1025 | + $all_res = []; |
|
| 1026 | + // definir un placholder pour les boucles dont on est sur d'avoir aucune occurence dans le squelette |
|
| 1027 | + if (is_null($boucle_placeholder)) { |
|
| 1028 | + do { |
|
| 1029 | + $boucle_placeholder = 'BOUCLE_PLACEHOLDER_' . strtoupper(md5(uniqid())); |
|
| 1030 | + } while (strpos($texte, $boucle_placeholder) !== false); |
|
| 1031 | + } |
|
| 1032 | + |
|
| 1033 | + $ligne_debut_initial = $ligne_debut_texte; |
|
| 1034 | + $pos_debut_texte = 0; |
|
| 1035 | + while ($boucle = public_trouver_premiere_boucle($texte, $id_parent, $descr, $pos_debut_texte)) { |
|
| 1036 | + $err_b = ''; // indiquera s'il y a eu une erreur |
|
| 1037 | + $result = new Boucle(); |
|
| 1038 | + $result->id_parent = $id_parent; |
|
| 1039 | + $result->descr = $descr; |
|
| 1040 | + |
|
| 1041 | + $pos_courante = $boucle['pos_boucle']; |
|
| 1042 | + $pos_parent = $boucle['pos_parent']; |
|
| 1043 | + $id_boucle_search = $id_boucle = $boucle['id_boucle']; |
|
| 1044 | + |
|
| 1045 | + $ligne_preaff = $ligne_avant = $ligne_milieu = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_parent); |
|
| 1046 | + |
|
| 1047 | + // boucle anonyme ? |
|
| 1048 | + if (!strlen($id_boucle)) { |
|
| 1049 | + $id_boucle = '_anon_L' . $ligne_milieu . '_' . substr(md5('anonyme:' . $id_parent . ':' . json_encode($boucle, JSON_THROW_ON_ERROR)), 0, 8); |
|
| 1050 | + } |
|
| 1051 | + |
|
| 1052 | + $pos_debut_boucle = $pos_courante; |
|
| 1053 | + |
|
| 1054 | + $pos_milieu = $pos_parent; |
|
| 1055 | + |
|
| 1056 | + // Regarder si on a une partie conditionnelle avant <B_xxx> |
|
| 1057 | + if ($boucle['pos_precond'] !== false) { |
|
| 1058 | + $pos_debut_boucle = $boucle['pos_precond']; |
|
| 1059 | + |
|
| 1060 | + $pos_avant = $boucle['pos_precond_inside']; |
|
| 1061 | + $result->avant = substr($texte, $pos_avant, $pos_courante - $pos_avant); |
|
| 1062 | + $ligne_avant = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_avant); |
|
| 1063 | + } |
|
| 1064 | + |
|
| 1065 | + // Regarder si on a une partie inconditionnelle avant <BB_xxx> |
|
| 1066 | + if ($boucle['pos_preaff'] !== false) { |
|
| 1067 | + $end_preaff = $pos_debut_boucle; |
|
| 1068 | + |
|
| 1069 | + $pos_preaff = $boucle['pos_preaff_inside']; |
|
| 1070 | + $result->preaff = substr($texte, $pos_preaff, $end_preaff - $pos_preaff); |
|
| 1071 | + $ligne_preaff = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_preaff); |
|
| 1072 | + } |
|
| 1073 | + |
|
| 1074 | + $result->id_boucle = $id_boucle; |
|
| 1075 | + |
|
| 1076 | + if ( |
|
| 1077 | + !preg_match(SPEC_BOUCLE, $texte, $match, 0, $pos_milieu) |
|
| 1078 | + or ($pos_match = strpos($texte, (string) $match[0], $pos_milieu)) === false |
|
| 1079 | + or $pos_match > $pos_milieu |
|
| 1080 | + ) { |
|
| 1081 | + $err_b = ['zbug_erreur_boucle_syntaxe', ['id' => $id_boucle]]; |
|
| 1082 | + erreur_squelette($err_b, $result); |
|
| 1083 | + |
|
| 1084 | + $ligne_debut_texte += public_compte_ligne($texte, $pos_debut_texte, $pos_courante + 1); |
|
| 1085 | + $pos_debut_texte = $pos_courante + 1; |
|
| 1086 | + continue; |
|
| 1087 | + } |
|
| 1088 | + |
|
| 1089 | + $result->type_requete = $match[0]; |
|
| 1090 | + $pos_milieu += strlen($match[0]); |
|
| 1091 | + $pos_courante = $pos_milieu; // on s'en sert pour compter les lignes plus precisemment |
|
| 1092 | + |
|
| 1093 | + $type = $match[1]; |
|
| 1094 | + $jointures = trim($match[2]); |
|
| 1095 | + $table_optionnelle = ($match[3]); |
|
| 1096 | + if ($jointures) { |
|
| 1097 | + // on affecte pas ici les jointures explicites, mais dans la compilation |
|
| 1098 | + // ou elles seront completees des jointures declarees |
|
| 1099 | + $result->jointures_explicites = $jointures; |
|
| 1100 | + } |
|
| 1101 | + |
|
| 1102 | + if ($table_optionnelle) { |
|
| 1103 | + $result->table_optionnelle = $type; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + // 1ere passe sur les criteres, vu comme des arguments sans fct |
|
| 1107 | + // Resultat mis dans result->param |
|
| 1108 | + $pos_fin_criteres = $pos_milieu; |
|
| 1109 | + phraser_args($texte, '/>', '', $all_res, $result, $pos_fin_criteres); |
|
| 1110 | + |
|
| 1111 | + // En 2e passe result->criteres contiendra un tableau |
|
| 1112 | + // pour l'instant on met le source (chaine) : |
|
| 1113 | + // si elle reste ici au final, c'est qu'elle contient une erreur |
|
| 1114 | + $pos_courante = $pos_fin_criteres; // on s'en sert pour compter les lignes plus precisemment |
|
| 1115 | + $result->criteres = substr($texte, $pos_milieu, $pos_fin_criteres - $pos_milieu); |
|
| 1116 | + $pos_milieu = $pos_fin_criteres; |
|
| 1117 | + |
|
| 1118 | + // |
|
| 1119 | + // Recuperer la fin : |
|
| 1120 | + // |
|
| 1121 | + if ($texte[$pos_milieu] === '/') { |
|
| 1122 | + // boucle autofermante : pas de partie conditionnelle apres |
|
| 1123 | + $pos_courante += 2; |
|
| 1124 | + $result->milieu = ''; |
|
| 1125 | + } else { |
|
| 1126 | + $pos_milieu += 1; |
|
| 1127 | + |
|
| 1128 | + $fin_boucle = BALISE_FIN_BOUCLE . $id_boucle_search . '>'; |
|
| 1129 | + $pos_fin = strpos($texte, $fin_boucle, $pos_milieu); |
|
| 1130 | + if ($pos_fin === false) { |
|
| 1131 | + $err_b = [ |
|
| 1132 | + 'zbug_erreur_boucle_fermant', |
|
| 1133 | + ['id' => $id_boucle] |
|
| 1134 | + ]; |
|
| 1135 | + erreur_squelette($err_b, $result); |
|
| 1136 | + $pos_courante += strlen($fin_boucle); |
|
| 1137 | + } |
|
| 1138 | + else { |
|
| 1139 | + // verifier une eventuelle imbrication d'une boucle homonyme |
|
| 1140 | + // (interdite, generera une erreur plus loin, mais permet de signaler la bonne erreur) |
|
| 1141 | + $search_debut_boucle = BALISE_BOUCLE . $id_boucle_search . '('; |
|
| 1142 | + $search_from = $pos_milieu; |
|
| 1143 | + $nb_open = 1; |
|
| 1144 | + $nb_close = 1; |
|
| 1145 | + $maxiter = 0; |
|
| 1146 | + do { |
|
| 1147 | + while ( |
|
| 1148 | + $nb_close < $nb_open |
|
| 1149 | + and $p = strpos($texte, $fin_boucle, $pos_fin + 1) |
|
| 1150 | + ) { |
|
| 1151 | + $nb_close++; |
|
| 1152 | + $pos_fin = $p; |
|
| 1153 | + } |
|
| 1154 | + // si on a pas trouve assez de boucles fermantes, sortir de la, on a fait de notre mieux |
|
| 1155 | + if ($nb_close < $nb_open) { |
|
| 1156 | + break; |
|
| 1157 | + } |
|
| 1158 | + while ( |
|
| 1159 | + $p = strpos($texte, $search_debut_boucle, $search_from) |
|
| 1160 | + and $p < $pos_fin |
|
| 1161 | + ) { |
|
| 1162 | + $nb_open++; |
|
| 1163 | + $search_from = $p + 1; |
|
| 1164 | + } |
|
| 1165 | + } while ($nb_close < $nb_open and $maxiter++ < 5); |
|
| 1166 | + |
|
| 1167 | + $pos_courante = $pos_fin + strlen($fin_boucle); |
|
| 1168 | + } |
|
| 1169 | + $result->milieu = substr($texte, $pos_milieu, $pos_fin - $pos_milieu); |
|
| 1170 | + } |
|
| 1171 | + |
|
| 1172 | + $ligne_suite = $ligne_apres = $ligne_debut_texte + public_compte_ligne($texte, $pos_debut_texte, $pos_courante); |
|
| 1173 | + $boucle = public_trouver_fin_boucle($texte, $id_parent, $boucle, $pos_courante, $result); |
|
| 1174 | + |
|
| 1175 | + // |
|
| 1176 | + // 1. Partie conditionnelle apres ? |
|
| 1177 | + // |
|
| 1178 | + if ($boucle['pos_postcond']) { |
|
| 1179 | + $result->apres = substr($texte, $pos_courante, $boucle['pos_postcond'] - $pos_courante); |
|
| 1180 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postcond_inside']); |
|
| 1181 | + $pos_courante = $boucle['pos_postcond_inside'] ; |
|
| 1182 | + } |
|
| 1183 | + |
|
| 1184 | + |
|
| 1185 | + // |
|
| 1186 | + // 2. Partie alternative apres ? |
|
| 1187 | + // |
|
| 1188 | + $ligne_altern = $ligne_suite; |
|
| 1189 | + if ($boucle['pos_altern']) { |
|
| 1190 | + $result->altern = substr($texte, $pos_courante, $boucle['pos_altern'] - $pos_courante); |
|
| 1191 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_altern_inside']); |
|
| 1192 | + $pos_courante = $boucle['pos_altern_inside']; |
|
| 1193 | + } |
|
| 1194 | + |
|
| 1195 | + // |
|
| 1196 | + // 3. Partie footer non alternative ? |
|
| 1197 | + // |
|
| 1198 | + $ligne_postaff = $ligne_suite; |
|
| 1199 | + if ($boucle['pos_postaff']) { |
|
| 1200 | + $result->postaff = substr($texte, $pos_courante, $boucle['pos_postaff'] - $pos_courante); |
|
| 1201 | + $ligne_suite += public_compte_ligne($texte, $pos_courante, $boucle['pos_postaff_inside']); |
|
| 1202 | + $pos_courante = $boucle['pos_postaff_inside']; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + $result->ligne = $ligne_preaff; |
|
| 1206 | + |
|
| 1207 | + if ($p = strpos($type, ':')) { |
|
| 1208 | + $result->sql_serveur = substr($type, 0, $p); |
|
| 1209 | + $type = substr($type, $p + 1); |
|
| 1210 | + } |
|
| 1211 | + $soustype = strtolower($type); |
|
| 1212 | + |
|
| 1213 | + if (!isset($GLOBALS['table_des_tables'][$soustype])) { |
|
| 1214 | + $soustype = $type; |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + $result->type_requete = $soustype; |
|
| 1218 | + // Lancer la 2e passe sur les criteres si la 1ere etait bonne |
|
| 1219 | + if (!is_array($result->param)) { |
|
| 1220 | + $err_b = true; |
|
| 1221 | + } else { |
|
| 1222 | + phraser_criteres($result->param, $result); |
|
| 1223 | + if (strncasecmp($soustype, TYPE_RECURSIF, strlen(TYPE_RECURSIF)) == 0) { |
|
| 1224 | + $result->type_requete = TYPE_RECURSIF; |
|
| 1225 | + $args = $result->param; |
|
| 1226 | + array_unshift( |
|
| 1227 | + $args, |
|
| 1228 | + substr($type, strlen(TYPE_RECURSIF)) |
|
| 1229 | + ); |
|
| 1230 | + $result->param = $args; |
|
| 1231 | + } |
|
| 1232 | + } |
|
| 1233 | + |
|
| 1234 | + $descr['id_mere_contexte'] = $id_boucle; |
|
| 1235 | + $result->milieu = public_phraser_html_dist($result->milieu, $id_boucle, $boucles, $descr, $ligne_milieu, $boucle_placeholder); |
|
| 1236 | + // reserver la place dans la pile des boucles pour compiler ensuite dans le bon ordre |
|
| 1237 | + // ie les boucles qui apparaissent dans les partie conditionnelles doivent etre compilees apres cette boucle |
|
| 1238 | + // si il y a deja une boucle de ce nom, cela declenchera une erreur ensuite |
|
| 1239 | + if (empty($boucles[$id_boucle])) { |
|
| 1240 | + $boucles[$id_boucle] = null; |
|
| 1241 | + } |
|
| 1242 | + $result->preaff = public_phraser_html_dist($result->preaff, $id_parent, $boucles, $descr, $ligne_preaff, $boucle_placeholder); |
|
| 1243 | + $result->avant = public_phraser_html_dist($result->avant, $id_parent, $boucles, $descr, $ligne_avant, $boucle_placeholder); |
|
| 1244 | + $result->apres = public_phraser_html_dist($result->apres, $id_parent, $boucles, $descr, $ligne_apres, $boucle_placeholder); |
|
| 1245 | + $result->altern = public_phraser_html_dist($result->altern, $id_parent, $boucles, $descr, $ligne_altern, $boucle_placeholder); |
|
| 1246 | + $result->postaff = public_phraser_html_dist($result->postaff, $id_parent, $boucles, $descr, $ligne_postaff, $boucle_placeholder); |
|
| 1247 | + |
|
| 1248 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1249 | + if ($err_b) { |
|
| 1250 | + $result->type_requete = false; |
|
| 1251 | + } |
|
| 1252 | + |
|
| 1253 | + // Verifier qu'il n'y a pas double definition |
|
| 1254 | + // apres analyse des sous-parties (pas avant). |
|
| 1255 | + if (!empty($boucles[$id_boucle])) { |
|
| 1256 | + if ($boucles[$id_boucle]->type_requete !== false) { |
|
| 1257 | + $err_b_d = [ |
|
| 1258 | + 'zbug_erreur_boucle_double', |
|
| 1259 | + ['id' => $id_boucle] |
|
| 1260 | + ]; |
|
| 1261 | + erreur_squelette($err_b_d, $result); |
|
| 1262 | + // Prevenir le generateur de code que le squelette est faux |
|
| 1263 | + $boucles[$id_boucle]->type_requete = false; |
|
| 1264 | + } |
|
| 1265 | + } else { |
|
| 1266 | + $boucles[$id_boucle] = $result; |
|
| 1267 | + } |
|
| 1268 | + |
|
| 1269 | + // remplacer la boucle par un placeholder qui compte le meme nombre de lignes |
|
| 1270 | + $placeholder = public_generer_boucle_placeholder($id_boucle, $boucles[$id_boucle], $boucle_placeholder, $ligne_suite - $ligne_debut_texte); |
|
| 1271 | + $longueur_boucle = $pos_courante - $boucle['debut_boucle']; |
|
| 1272 | + $texte = substr_replace($texte, $placeholder, $boucle['debut_boucle'], $longueur_boucle); |
|
| 1273 | + $pos_courante = $pos_courante - $longueur_boucle + strlen($placeholder); |
|
| 1274 | + |
|
| 1275 | + // phraser la partie avant le debut de la boucle |
|
| 1276 | + #$all_res = phraser_champs_etendus(substr($texte, $pos_debut_texte, $boucle['debut_boucle'] - $pos_debut_texte), $ligne_debut_texte, $all_res); |
|
| 1277 | + #$all_res[] = &$boucles[$id_boucle]; |
|
| 1278 | + |
|
| 1279 | + $ligne_debut_texte = $ligne_suite; |
|
| 1280 | + $pos_debut_texte = $pos_courante; |
|
| 1281 | + } |
|
| 1282 | + |
|
| 1283 | + $all_res = phraser_champs_etendus($texte, $ligne_debut_initial, $all_res); |
|
| 1284 | + |
|
| 1285 | + return $all_res; |
|
| 1286 | 1286 | } |
@@ -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 | /** |
@@ -35,19 +35,19 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function genie_maintenance_dist($t) { |
| 37 | 37 | |
| 38 | - // (re)mettre .htaccess avec deny from all |
|
| 39 | - // dans les deux repertoires dits inaccessibles par http |
|
| 40 | - include_spip('inc/acces'); |
|
| 41 | - verifier_htaccess(_DIR_ETC); |
|
| 42 | - verifier_htaccess(_DIR_TMP); |
|
| 43 | - verifier_htaccess(_DIR_VENDOR); |
|
| 38 | + // (re)mettre .htaccess avec deny from all |
|
| 39 | + // dans les deux repertoires dits inaccessibles par http |
|
| 40 | + include_spip('inc/acces'); |
|
| 41 | + verifier_htaccess(_DIR_ETC); |
|
| 42 | + verifier_htaccess(_DIR_TMP); |
|
| 43 | + verifier_htaccess(_DIR_VENDOR); |
|
| 44 | 44 | |
| 45 | - // Verifier qu'aucune table n'est crashee |
|
| 46 | - if (!_request('reinstall')) { |
|
| 47 | - verifier_crash_tables(); |
|
| 48 | - } |
|
| 45 | + // Verifier qu'aucune table n'est crashee |
|
| 46 | + if (!_request('reinstall')) { |
|
| 47 | + verifier_crash_tables(); |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return 1; |
|
| 50 | + return 1; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -64,33 +64,33 @@ discard block |
||
| 64 | 64 | * des tables qui ont crashé. |
| 65 | 65 | */ |
| 66 | 66 | function verifier_crash_tables() { |
| 67 | - if (spip_connect()) { |
|
| 68 | - include_spip('base/serial'); |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - $crash = []; |
|
| 71 | - foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | - foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | - if ( |
|
| 74 | - !sql_select('*', $table, '', '', '', 1) |
|
| 75 | - and !defined('spip_interdire_cache') |
|
| 76 | - ) { # cas "LOST CONNECTION" |
|
| 77 | - $crash[] = $table; |
|
| 78 | - } |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - #$crash[] = 'test'; |
|
| 82 | - if ($crash) { |
|
| 83 | - ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | - spip_log('crash des tables', 'err'); |
|
| 85 | - spip_log($crash, 'err'); |
|
| 86 | - } else { |
|
| 87 | - effacer_meta('message_crash_tables'); |
|
| 88 | - } |
|
| 67 | + if (spip_connect()) { |
|
| 68 | + include_spip('base/serial'); |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + $crash = []; |
|
| 71 | + foreach (['tables_principales', 'tables_auxiliaires'] as $com) { |
|
| 72 | + foreach ($GLOBALS[$com] as $table => $desc) { |
|
| 73 | + if ( |
|
| 74 | + !sql_select('*', $table, '', '', '', 1) |
|
| 75 | + and !defined('spip_interdire_cache') |
|
| 76 | + ) { # cas "LOST CONNECTION" |
|
| 77 | + $crash[] = $table; |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + #$crash[] = 'test'; |
|
| 82 | + if ($crash) { |
|
| 83 | + ecrire_meta('message_crash_tables', serialize($crash)); |
|
| 84 | + spip_log('crash des tables', 'err'); |
|
| 85 | + spip_log($crash, 'err'); |
|
| 86 | + } else { |
|
| 87 | + effacer_meta('message_crash_tables'); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - return $crash; |
|
| 91 | - } |
|
| 90 | + return $crash; |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return false; |
|
| 93 | + return false; |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -106,16 +106,16 @@ discard block |
||
| 106 | 106 | * @return string |
| 107 | 107 | */ |
| 108 | 108 | function message_crash_tables() { |
| 109 | - if ($crash = verifier_crash_tables()) { |
|
| 110 | - return |
|
| 111 | - '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | - . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | - . generer_form_ecrire( |
|
| 114 | - 'base_repair', |
|
| 115 | - _T('texte_crash_base'), |
|
| 116 | - '', |
|
| 117 | - _T('bouton_tenter_recuperation') |
|
| 118 | - ); |
|
| 119 | - } |
|
| 120 | - return ''; |
|
| 109 | + if ($crash = verifier_crash_tables()) { |
|
| 110 | + return |
|
| 111 | + '<strong>' . _T('texte_recuperer_base') . '</strong><br />' |
|
| 112 | + . ' <tt>' . join(', ', $crash) . '</tt><br />' |
|
| 113 | + . generer_form_ecrire( |
|
| 114 | + 'base_repair', |
|
| 115 | + _T('texte_crash_base'), |
|
| 116 | + '', |
|
| 117 | + _T('bouton_tenter_recuperation') |
|
| 118 | + ); |
|
| 119 | + } |
|
| 120 | + return ''; |
|
| 121 | 121 | } |
@@ -19,11 +19,11 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | if (!defined('_DATA_SOURCE_MAX_SIZE')) { |
| 26 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | |
@@ -44,17 +44,17 @@ discard block |
||
| 44 | 44 | * Description de la boucle complétée des champs |
| 45 | 45 | */ |
| 46 | 46 | function iterateur_DATA_dist($b) { |
| 47 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | - $b->show = [ |
|
| 49 | - 'field' => [ |
|
| 50 | - 'cle' => 'STRING', |
|
| 51 | - 'valeur' => 'STRING', |
|
| 52 | - '*' => 'ALL' // Champ joker * |
|
| 53 | - ] |
|
| 54 | - ]; |
|
| 55 | - $b->select[] = '.valeur'; |
|
| 56 | - |
|
| 57 | - return $b; |
|
| 47 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 48 | + $b->show = [ |
|
| 49 | + 'field' => [ |
|
| 50 | + 'cle' => 'STRING', |
|
| 51 | + 'valeur' => 'STRING', |
|
| 52 | + '*' => 'ALL' // Champ joker * |
|
| 53 | + ] |
|
| 54 | + ]; |
|
| 55 | + $b->select[] = '.valeur'; |
|
| 56 | + |
|
| 57 | + return $b; |
|
| 58 | 58 | } |
| 59 | 59 | |
| 60 | 60 | |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return array |
| 70 | 70 | */ |
| 71 | 71 | function inc_file_to_array_dist($data) { |
| 72 | - return preg_split('/\r?\n/', $data); |
|
| 72 | + return preg_split('/\r?\n/', $data); |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | function inc_plugins_to_array_dist() { |
| 81 | - include_spip('inc/plugin'); |
|
| 81 | + include_spip('inc/plugin'); |
|
| 82 | 82 | |
| 83 | - return liste_chemin_plugin_actifs(); |
|
| 83 | + return liste_chemin_plugin_actifs(); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | * @return array |
| 91 | 91 | */ |
| 92 | 92 | function inc_xml_to_array_dist($data) { |
| 93 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 94 | 94 | } |
| 95 | 95 | |
| 96 | 96 | /** |
@@ -102,14 +102,14 @@ discard block |
||
| 102 | 102 | * |
| 103 | 103 | */ |
| 104 | 104 | function inc_object_to_array($object) { |
| 105 | - if (!is_object($object) && !is_array($object)) { |
|
| 106 | - return $object; |
|
| 107 | - } |
|
| 108 | - if (is_object($object)) { |
|
| 109 | - $object = get_object_vars($object); |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - return array_map('inc_object_to_array', $object); |
|
| 105 | + if (!is_object($object) && !is_array($object)) { |
|
| 106 | + return $object; |
|
| 107 | + } |
|
| 108 | + if (is_object($object)) { |
|
| 109 | + $object = get_object_vars($object); |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + return array_map('inc_object_to_array', $object); |
|
| 113 | 113 | } |
| 114 | 114 | |
| 115 | 115 | /** |
@@ -119,20 +119,20 @@ discard block |
||
| 119 | 119 | * @return array|bool |
| 120 | 120 | */ |
| 121 | 121 | function inc_sql_to_array_dist($data) { |
| 122 | - # sortir le connecteur de $data |
|
| 123 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | - $serveur = (string)$v[1]; |
|
| 125 | - $req = trim($v[2]); |
|
| 126 | - if ($s = sql_query($req, $serveur)) { |
|
| 127 | - $r = []; |
|
| 128 | - while ($t = sql_fetch($s)) { |
|
| 129 | - $r[] = $t; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - return $r; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - return false; |
|
| 122 | + # sortir le connecteur de $data |
|
| 123 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 124 | + $serveur = (string)$v[1]; |
|
| 125 | + $req = trim($v[2]); |
|
| 126 | + if ($s = sql_query($req, $serveur)) { |
|
| 127 | + $r = []; |
|
| 128 | + while ($t = sql_fetch($s)) { |
|
| 129 | + $r[] = $t; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + return $r; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + return false; |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -142,13 +142,13 @@ discard block |
||
| 142 | 142 | * @return array|bool |
| 143 | 143 | */ |
| 144 | 144 | function inc_json_to_array_dist($data) { |
| 145 | - try { |
|
| 146 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | - } catch (JsonException $e) { |
|
| 148 | - $json = null; |
|
| 149 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | - } |
|
| 151 | - return is_array($json) ? (array) $json : []; |
|
| 145 | + try { |
|
| 146 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 147 | + } catch (JsonException $e) { |
|
| 148 | + $json = null; |
|
| 149 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 150 | + } |
|
| 151 | + return is_array($json) ? (array) $json : []; |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -158,30 +158,30 @@ discard block |
||
| 158 | 158 | * @return array|bool |
| 159 | 159 | */ |
| 160 | 160 | function inc_csv_to_array_dist($data) { |
| 161 | - include_spip('inc/csv'); |
|
| 162 | - [$entete, $csv] = analyse_csv($data); |
|
| 163 | - array_unshift($csv, $entete); |
|
| 164 | - |
|
| 165 | - include_spip('inc/charsets'); |
|
| 166 | - $i = 1; |
|
| 167 | - foreach ($entete as $k => $v) { |
|
| 168 | - if (trim($v) == '') { |
|
| 169 | - $v = 'col' . $i; |
|
| 170 | - } // reperer des eventuelles cases vides |
|
| 171 | - if (is_numeric($v) and $v < 0) { |
|
| 172 | - $v = '__' . $v; |
|
| 173 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | - if (is_numeric($v)) { |
|
| 175 | - $v = '_' . $v; |
|
| 176 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | - foreach ($csv as &$item) { |
|
| 179 | - $item[$v] = &$item[$k]; |
|
| 180 | - } |
|
| 181 | - $i++; |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - return $csv; |
|
| 161 | + include_spip('inc/csv'); |
|
| 162 | + [$entete, $csv] = analyse_csv($data); |
|
| 163 | + array_unshift($csv, $entete); |
|
| 164 | + |
|
| 165 | + include_spip('inc/charsets'); |
|
| 166 | + $i = 1; |
|
| 167 | + foreach ($entete as $k => $v) { |
|
| 168 | + if (trim($v) == '') { |
|
| 169 | + $v = 'col' . $i; |
|
| 170 | + } // reperer des eventuelles cases vides |
|
| 171 | + if (is_numeric($v) and $v < 0) { |
|
| 172 | + $v = '__' . $v; |
|
| 173 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 174 | + if (is_numeric($v)) { |
|
| 175 | + $v = '_' . $v; |
|
| 176 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 177 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 178 | + foreach ($csv as &$item) { |
|
| 179 | + $item[$v] = &$item[$k]; |
|
| 180 | + } |
|
| 181 | + $i++; |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + return $csv; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -191,13 +191,13 @@ discard block |
||
| 191 | 191 | * @return array|bool |
| 192 | 192 | */ |
| 193 | 193 | function inc_rss_to_array_dist($data) { |
| 194 | - $tableau = null; |
|
| 195 | - include_spip('inc/syndic'); |
|
| 196 | - if (is_array($rss = analyser_backend($data))) { |
|
| 197 | - $tableau = $rss; |
|
| 198 | - } |
|
| 194 | + $tableau = null; |
|
| 195 | + include_spip('inc/syndic'); |
|
| 196 | + if (is_array($rss = analyser_backend($data))) { |
|
| 197 | + $tableau = $rss; |
|
| 198 | + } |
|
| 199 | 199 | |
| 200 | - return $tableau; |
|
| 200 | + return $tableau; |
|
| 201 | 201 | } |
| 202 | 202 | |
| 203 | 203 | /** |
@@ -207,9 +207,9 @@ discard block |
||
| 207 | 207 | * @return array|bool |
| 208 | 208 | */ |
| 209 | 209 | function inc_atom_to_array_dist($data) { |
| 210 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 211 | 211 | |
| 212 | - return $rss_to_array($data); |
|
| 212 | + return $rss_to_array($data); |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -220,12 +220,12 @@ discard block |
||
| 220 | 220 | * @return array|bool |
| 221 | 221 | */ |
| 222 | 222 | function inc_glob_to_array_dist($data) { |
| 223 | - $a = glob( |
|
| 224 | - $data, |
|
| 225 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | - ); |
|
| 223 | + $a = glob( |
|
| 224 | + $data, |
|
| 225 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 226 | + ); |
|
| 227 | 227 | |
| 228 | - return $a ?: []; |
|
| 228 | + return $a ?: []; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -236,14 +236,14 @@ discard block |
||
| 236 | 236 | * @throws Exception |
| 237 | 237 | */ |
| 238 | 238 | function inc_yaml_to_array_dist($data) { |
| 239 | - include_spip('inc/yaml-mini'); |
|
| 240 | - if (!function_exists('yaml_decode')) { |
|
| 241 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 239 | + include_spip('inc/yaml-mini'); |
|
| 240 | + if (!function_exists('yaml_decode')) { |
|
| 241 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 242 | 242 | |
| 243 | - return false; |
|
| 244 | - } |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - return yaml_decode($data); |
|
| 246 | + return yaml_decode($data); |
|
| 247 | 247 | } |
| 248 | 248 | |
| 249 | 249 | |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | * @return array|bool |
| 259 | 259 | */ |
| 260 | 260 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 261 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -270,23 +270,23 @@ discard block |
||
| 270 | 270 | * @return array|bool |
| 271 | 271 | */ |
| 272 | 272 | function inc_ls_to_array_dist($data) { |
| 273 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | - $a = $glob_to_array($data); |
|
| 275 | - foreach ($a as &$v) { |
|
| 276 | - $b = (array)@stat($v); |
|
| 277 | - foreach ($b as $k => $ignore) { |
|
| 278 | - if (is_numeric($k)) { |
|
| 279 | - unset($b[$k]); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | - $v = array_merge( |
|
| 284 | - pathinfo($v), |
|
| 285 | - $b |
|
| 286 | - ); |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - return $a; |
|
| 273 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 274 | + $a = $glob_to_array($data); |
|
| 275 | + foreach ($a as &$v) { |
|
| 276 | + $b = (array)@stat($v); |
|
| 277 | + foreach ($b as $k => $ignore) { |
|
| 278 | + if (is_numeric($k)) { |
|
| 279 | + unset($b[$k]); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 283 | + $v = array_merge( |
|
| 284 | + pathinfo($v), |
|
| 285 | + $b |
|
| 286 | + ); |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + return $a; |
|
| 290 | 290 | } |
| 291 | 291 | |
| 292 | 292 | /** |
@@ -296,25 +296,25 @@ discard block |
||
| 296 | 296 | * @return array|bool |
| 297 | 297 | */ |
| 298 | 298 | function XMLObjectToArray($object) { |
| 299 | - $xml_array = []; |
|
| 300 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | - $key .= '-' . uniqid(); |
|
| 303 | - } |
|
| 304 | - $vars = get_object_vars($object->current()); |
|
| 305 | - if (isset($vars['@attributes'])) { |
|
| 306 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | - $xml_array[$key][$k] = $v; |
|
| 308 | - } |
|
| 309 | - } |
|
| 310 | - if ($object->hasChildren()) { |
|
| 311 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | - $object->current() |
|
| 313 | - ); |
|
| 314 | - } else { |
|
| 315 | - $xml_array[$key][] = strval($object->current()); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - return $xml_array; |
|
| 299 | + $xml_array = []; |
|
| 300 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 301 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 302 | + $key .= '-' . uniqid(); |
|
| 303 | + } |
|
| 304 | + $vars = get_object_vars($object->current()); |
|
| 305 | + if (isset($vars['@attributes'])) { |
|
| 306 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 307 | + $xml_array[$key][$k] = $v; |
|
| 308 | + } |
|
| 309 | + } |
|
| 310 | + if ($object->hasChildren()) { |
|
| 311 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 312 | + $object->current() |
|
| 313 | + ); |
|
| 314 | + } else { |
|
| 315 | + $xml_array[$key][] = strval($object->current()); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + return $xml_array; |
|
| 320 | 320 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('iterateur/data'); |
@@ -37,10 +37,10 @@ discard block |
||
| 37 | 37 | * Description de la boucle complétée des champs |
| 38 | 38 | */ |
| 39 | 39 | function iterateur_CONDITION_dist($b) { |
| 40 | - $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | - $b->show = [ |
|
| 42 | - 'field' => [] |
|
| 43 | - ]; |
|
| 40 | + $b->iterateur = 'CONDITION'; # designe la classe d'iterateur |
|
| 41 | + $b->show = [ |
|
| 42 | + 'field' => [] |
|
| 43 | + ]; |
|
| 44 | 44 | |
| 45 | - return $b; |
|
| 45 | + return $b; |
|
| 46 | 46 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -38,13 +38,13 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_POUR_dist($b) { |
| 41 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 41 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | 48 | |
| 49 | - return $b; |
|
| 49 | + return $b; |
|
| 50 | 50 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -38,17 +38,17 @@ discard block |
||
| 38 | 38 | * Description de la boucle complétée des champs |
| 39 | 39 | */ |
| 40 | 40 | function iterateur_php_dist($b, $iteratorName) { |
| 41 | - $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | - $b->show = [ |
|
| 43 | - 'field' => [ |
|
| 44 | - 'cle' => 'STRING', |
|
| 45 | - 'valeur' => 'STRING', |
|
| 46 | - ] |
|
| 47 | - ]; |
|
| 48 | - |
|
| 49 | - foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | - $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $b; |
|
| 41 | + $b->iterateur = $iteratorName; # designe la classe d'iterateur |
|
| 42 | + $b->show = [ |
|
| 43 | + 'field' => [ |
|
| 44 | + 'cle' => 'STRING', |
|
| 45 | + 'valeur' => 'STRING', |
|
| 46 | + ] |
|
| 47 | + ]; |
|
| 48 | + |
|
| 49 | + foreach (get_class_methods($iteratorName) as $method) { |
|
| 50 | + $b->show['field'][strtolower($method)] = 'METHOD'; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $b; |
|
| 54 | 54 | } |