@@ -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'); |
@@ -43,233 +43,233 @@ discard block |
||
| 43 | 43 | // https://code.spip.net/@public_composer_dist |
| 44 | 44 | function public_composer_dist($squelette, $mime_type, $gram, $source, $connect = '') { |
| 45 | 45 | |
| 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 ? $nom : false; |
|
| 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 ? $nom : false; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 142 | 142 | |
| 143 | - // Le dernier index est '' (fonction principale) |
|
| 144 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | - if (CODE_COMMENTE) { |
|
| 146 | - $code = " |
|
| 143 | + // Le dernier index est '' (fonction principale) |
|
| 144 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 145 | + if (CODE_COMMENTE) { |
|
| 146 | + $code = " |
|
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | 149 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 150 | 150 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 151 | 151 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 152 | 152 | */ '; |
| 153 | - } |
|
| 153 | + } |
|
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | - if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | - ecrire_fichier($phpfile, $code); |
|
| 158 | - } |
|
| 155 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 156 | + if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
|
| 157 | + ecrire_fichier($phpfile, $code); |
|
| 158 | + } |
|
| 159 | 159 | |
| 160 | - return $code; |
|
| 160 | + return $code; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // Le squelette compile est-il trop vieux ? |
| 164 | 164 | // https://code.spip.net/@squelette_obsolete |
| 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 | // https://code.spip.net/@invalideur_session |
| 189 | 189 | function invalideur_session(&$Cache, $code = null) { |
| 190 | - $Cache['session'] = spip_session(); |
|
| 190 | + $Cache['session'] = spip_session(); |
|
| 191 | 191 | |
| 192 | - return $code; |
|
| 192 | + return $code; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | |
| 196 | 196 | // https://code.spip.net/@analyse_resultat_skel |
| 197 | 197 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 198 | - static $filtres = []; |
|
| 199 | - $headers = []; |
|
| 200 | - |
|
| 201 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | - if ( |
|
| 205 | - stripos($corps, 'header') !== false |
|
| 206 | - and preg_match_all( |
|
| 207 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | - $corps, |
|
| 209 | - $regs, |
|
| 210 | - PREG_SET_ORDER |
|
| 211 | - ) |
|
| 212 | - ) { |
|
| 213 | - foreach ($regs as $r) { |
|
| 214 | - $corps = str_replace($r[0], '', $corps); |
|
| 215 | - # $j = Content-Type, et pas content-TYPE. |
|
| 216 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | - |
|
| 218 | - if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 220 | - } else { |
|
| 221 | - $headers[$j] = $r[3]; |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - } |
|
| 225 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | - $process_ins = ( |
|
| 227 | - strpos($corps, '<' . '?') === false |
|
| 228 | - or |
|
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | - ) |
|
| 232 | - ? 'html' |
|
| 233 | - : 'php'; |
|
| 234 | - |
|
| 235 | - $skel = [ |
|
| 236 | - 'squelette' => $nom, |
|
| 237 | - 'source' => $source, |
|
| 238 | - 'process_ins' => $process_ins, |
|
| 239 | - 'invalideurs' => $cache, |
|
| 240 | - 'entetes' => $headers, |
|
| 241 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | - ]; |
|
| 243 | - |
|
| 244 | - // traiter #FILTRE{} et filtres |
|
| 245 | - if (!isset($filtres[$nom])) { |
|
| 246 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | - } |
|
| 248 | - $filtres_headers = []; |
|
| 249 | - if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | - unset($headers['X-Spip-Filtre']); |
|
| 252 | - } |
|
| 253 | - if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | - include_spip('public/sandbox'); |
|
| 255 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | - |
|
| 257 | - if ($process_ins == 'html') { |
|
| 258 | - $skel['process_ins'] = ( |
|
| 259 | - strpos($corps, '<' . '?') === false |
|
| 260 | - or |
|
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | - ) |
|
| 264 | - ? 'html' |
|
| 265 | - : 'php'; |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - $skel['entetes'] = $headers; |
|
| 270 | - $skel['texte'] = $corps; |
|
| 271 | - |
|
| 272 | - return $skel; |
|
| 198 | + static $filtres = []; |
|
| 199 | + $headers = []; |
|
| 200 | + |
|
| 201 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 202 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 203 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 204 | + if ( |
|
| 205 | + stripos($corps, 'header') !== false |
|
| 206 | + and preg_match_all( |
|
| 207 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 208 | + $corps, |
|
| 209 | + $regs, |
|
| 210 | + PREG_SET_ORDER |
|
| 211 | + ) |
|
| 212 | + ) { |
|
| 213 | + foreach ($regs as $r) { |
|
| 214 | + $corps = str_replace($r[0], '', $corps); |
|
| 215 | + # $j = Content-Type, et pas content-TYPE. |
|
| 216 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 217 | + |
|
| 218 | + if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
|
| 219 | + $headers[$j] .= '|' . $r[3]; |
|
| 220 | + } else { |
|
| 221 | + $headers[$j] = $r[3]; |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + } |
|
| 225 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 226 | + $process_ins = ( |
|
| 227 | + strpos($corps, '<' . '?') === false |
|
| 228 | + or |
|
| 229 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 231 | + ) |
|
| 232 | + ? 'html' |
|
| 233 | + : 'php'; |
|
| 234 | + |
|
| 235 | + $skel = [ |
|
| 236 | + 'squelette' => $nom, |
|
| 237 | + 'source' => $source, |
|
| 238 | + 'process_ins' => $process_ins, |
|
| 239 | + 'invalideurs' => $cache, |
|
| 240 | + 'entetes' => $headers, |
|
| 241 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 242 | + ]; |
|
| 243 | + |
|
| 244 | + // traiter #FILTRE{} et filtres |
|
| 245 | + if (!isset($filtres[$nom])) { |
|
| 246 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 247 | + } |
|
| 248 | + $filtres_headers = []; |
|
| 249 | + if (isset($headers['X-Spip-Filtre']) and strlen($headers['X-Spip-Filtre'])) { |
|
| 250 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 251 | + unset($headers['X-Spip-Filtre']); |
|
| 252 | + } |
|
| 253 | + if (count($filtres[$nom]) or count($filtres_headers)) { |
|
| 254 | + include_spip('public/sandbox'); |
|
| 255 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 256 | + |
|
| 257 | + if ($process_ins == 'html') { |
|
| 258 | + $skel['process_ins'] = ( |
|
| 259 | + strpos($corps, '<' . '?') === false |
|
| 260 | + or |
|
| 261 | + (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | + strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 263 | + ) |
|
| 264 | + ? 'html' |
|
| 265 | + : 'php'; |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + $skel['entetes'] = $headers; |
|
| 270 | + $skel['texte'] = $corps; |
|
| 271 | + |
|
| 272 | + return $skel; |
|
| 273 | 273 | } |
| 274 | 274 | |
| 275 | 275 | // |
@@ -283,7 +283,7 @@ discard block |
||
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 284 | 284 | if ($lang_select) lang_select(); |
| 285 | 285 | ?' |
| 286 | - . '>'); |
|
| 286 | + . '>'); |
|
| 287 | 287 | |
| 288 | 288 | /** |
| 289 | 289 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -303,35 +303,35 @@ discard block |
||
| 303 | 303 | * Code PHP pour inclure le squelette de la balise dynamique |
| 304 | 304 | **/ |
| 305 | 305 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 306 | - if ( |
|
| 307 | - strncmp($file, '/', 1) !== 0 |
|
| 308 | - // pas de lien symbolique sous Windows |
|
| 309 | - and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | - ) { |
|
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $lang = $context_compil[4]; |
|
| 315 | - if (preg_match(',\W,', $lang)) { |
|
| 316 | - $lang = ''; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $args = array_map('argumenter_squelette', $args); |
|
| 320 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | - } |
|
| 323 | - $args = join(', ', $args); |
|
| 324 | - |
|
| 325 | - $r = sprintf( |
|
| 326 | - CODE_INCLURE_BALISE, |
|
| 327 | - $file, |
|
| 328 | - $lang, |
|
| 329 | - $nom, |
|
| 330 | - $args, |
|
| 331 | - join(', ', array_map('_q', $context_compil)) |
|
| 332 | - ); |
|
| 333 | - |
|
| 334 | - return $r; |
|
| 306 | + if ( |
|
| 307 | + strncmp($file, '/', 1) !== 0 |
|
| 308 | + // pas de lien symbolique sous Windows |
|
| 309 | + and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
|
| 310 | + ) { |
|
| 311 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $lang = $context_compil[4]; |
|
| 315 | + if (preg_match(',\W,', $lang)) { |
|
| 316 | + $lang = ''; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $args = array_map('argumenter_squelette', $args); |
|
| 320 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 322 | + } |
|
| 323 | + $args = join(', ', $args); |
|
| 324 | + |
|
| 325 | + $r = sprintf( |
|
| 326 | + CODE_INCLURE_BALISE, |
|
| 327 | + $file, |
|
| 328 | + $lang, |
|
| 329 | + $nom, |
|
| 330 | + $args, |
|
| 331 | + join(', ', array_map('_q', $context_compil)) |
|
| 332 | + ); |
|
| 333 | + |
|
| 334 | + return $r; |
|
| 335 | 335 | } |
| 336 | 336 | |
| 337 | 337 | /** |
@@ -349,18 +349,18 @@ discard block |
||
| 349 | 349 | **/ |
| 350 | 350 | function argumenter_squelette($v) { |
| 351 | 351 | |
| 352 | - if (is_object($v)) { |
|
| 353 | - return var_export($v, true); |
|
| 354 | - } elseif (!is_array($v)) { |
|
| 355 | - return "'" . texte_script($v) . "'"; |
|
| 356 | - } else { |
|
| 357 | - $out = []; |
|
| 358 | - foreach ($v as $k => $val) { |
|
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 363 | - } |
|
| 352 | + if (is_object($v)) { |
|
| 353 | + return var_export($v, true); |
|
| 354 | + } elseif (!is_array($v)) { |
|
| 355 | + return "'" . texte_script($v) . "'"; |
|
| 356 | + } else { |
|
| 357 | + $out = []; |
|
| 358 | + foreach ($v as $k => $val) { |
|
| 359 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return 'array(' . join(', ', $out) . ')'; |
|
| 363 | + } |
|
| 364 | 364 | } |
| 365 | 365 | |
| 366 | 366 | |
@@ -391,87 +391,87 @@ discard block |
||
| 391 | 391 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 392 | 392 | **/ |
| 393 | 393 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 394 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | - $nom_balise = $nom; |
|
| 396 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | - $nom_balise_generique = ''; |
|
| 398 | - |
|
| 399 | - $appel_php_depuis_modele = false; |
|
| 400 | - if ( |
|
| 401 | - is_array($context_compil) |
|
| 402 | - and !is_numeric($context_compil[3]) |
|
| 403 | - and empty($context_compil[0]) |
|
| 404 | - and empty($context_compil[1]) |
|
| 405 | - and empty($context_compil[2]) |
|
| 406 | - and empty($context_compil[3]) |
|
| 407 | - ) { |
|
| 408 | - $appel_php_depuis_modele = true; |
|
| 409 | - } |
|
| 410 | - |
|
| 411 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | - // injecter en premier arg le nom de la balise |
|
| 415 | - array_unshift($args, $nom); |
|
| 416 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | - $nom_balise = $nom_balise_generique; |
|
| 419 | - } |
|
| 420 | - unset($balise_generique); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!$fonction_balise) { |
|
| 424 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | - erreur_squelette($msg, $context_compil); |
|
| 426 | - |
|
| 427 | - return ''; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - // retrouver le fichier qui a déclaré la fonction |
|
| 431 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | - $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | - if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | - $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | - |
|
| 442 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | - |
|
| 444 | - if (!is_array($r)) { |
|
| 445 | - return $r; |
|
| 446 | - } |
|
| 447 | - |
|
| 448 | - // verifier que la fonction dyn est la, |
|
| 449 | - // sinon se replier sur la generique si elle existe |
|
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | - if ( |
|
| 452 | - $balise_generique = chercher_balise_generique($nom) |
|
| 453 | - and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | - ) { |
|
| 457 | - // et lui injecter en premier arg le nom de la balise |
|
| 458 | - array_unshift($r, $nom); |
|
| 459 | - $nom_balise = $nom_balise_generique; |
|
| 460 | - if (!_DIR_RESTREINT) { |
|
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | - } |
|
| 463 | - } else { |
|
| 464 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | - erreur_squelette($msg, $context_compil); |
|
| 466 | - |
|
| 467 | - return ''; |
|
| 468 | - } |
|
| 469 | - } |
|
| 470 | - |
|
| 471 | - if ($appel_php_depuis_modele) { |
|
| 472 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | - } |
|
| 474 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 394 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 395 | + $nom_balise = $nom; |
|
| 396 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 397 | + $nom_balise_generique = ''; |
|
| 398 | + |
|
| 399 | + $appel_php_depuis_modele = false; |
|
| 400 | + if ( |
|
| 401 | + is_array($context_compil) |
|
| 402 | + and !is_numeric($context_compil[3]) |
|
| 403 | + and empty($context_compil[0]) |
|
| 404 | + and empty($context_compil[1]) |
|
| 405 | + and empty($context_compil[2]) |
|
| 406 | + and empty($context_compil[3]) |
|
| 407 | + ) { |
|
| 408 | + $appel_php_depuis_modele = true; |
|
| 409 | + } |
|
| 410 | + |
|
| 411 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 412 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 413 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 414 | + // injecter en premier arg le nom de la balise |
|
| 415 | + array_unshift($args, $nom); |
|
| 416 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 417 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 418 | + $nom_balise = $nom_balise_generique; |
|
| 419 | + } |
|
| 420 | + unset($balise_generique); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!$fonction_balise) { |
|
| 424 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 425 | + erreur_squelette($msg, $context_compil); |
|
| 426 | + |
|
| 427 | + return ''; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + // retrouver le fichier qui a déclaré la fonction |
|
| 431 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 432 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 433 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 434 | + $file = str_replace('\\', '/', $reflector->getFileName()); |
|
| 435 | + if (strncmp($file, str_replace('\\', '/', _ROOT_RACINE), strlen(_ROOT_RACINE)) === 0) { |
|
| 436 | + $file = substr($file, strlen(_ROOT_RACINE)); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 440 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 441 | + |
|
| 442 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 443 | + |
|
| 444 | + if (!is_array($r)) { |
|
| 445 | + return $r; |
|
| 446 | + } |
|
| 447 | + |
|
| 448 | + // verifier que la fonction dyn est la, |
|
| 449 | + // sinon se replier sur la generique si elle existe |
|
| 450 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 451 | + if ( |
|
| 452 | + $balise_generique = chercher_balise_generique($nom) |
|
| 453 | + and $nom_balise_generique = $balise_generique['nom_generique'] |
|
| 454 | + and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 456 | + ) { |
|
| 457 | + // et lui injecter en premier arg le nom de la balise |
|
| 458 | + array_unshift($r, $nom); |
|
| 459 | + $nom_balise = $nom_balise_generique; |
|
| 460 | + if (!_DIR_RESTREINT) { |
|
| 461 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 462 | + } |
|
| 463 | + } else { |
|
| 464 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 465 | + erreur_squelette($msg, $context_compil); |
|
| 466 | + |
|
| 467 | + return ''; |
|
| 468 | + } |
|
| 469 | + } |
|
| 470 | + |
|
| 471 | + if ($appel_php_depuis_modele) { |
|
| 472 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 473 | + } |
|
| 474 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 475 | 475 | } |
| 476 | 476 | |
| 477 | 477 | /** |
@@ -486,23 +486,23 @@ discard block |
||
| 486 | 486 | * @return array|null |
| 487 | 487 | */ |
| 488 | 488 | function chercher_balise_generique($nom) { |
| 489 | - if (false === strpos($nom, '_')) { |
|
| 490 | - return null; |
|
| 491 | - } |
|
| 492 | - $nom_generique = $nom; |
|
| 493 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | - if ($fonction_generique) { |
|
| 497 | - return [ |
|
| 498 | - 'nom' => $nom, |
|
| 499 | - 'nom_generique' => $nom_generique, |
|
| 500 | - 'fonction_generique' => $fonction_generique, |
|
| 501 | - ]; |
|
| 502 | - } |
|
| 503 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | - } |
|
| 505 | - return null; |
|
| 489 | + if (false === strpos($nom, '_')) { |
|
| 490 | + return null; |
|
| 491 | + } |
|
| 492 | + $nom_generique = $nom; |
|
| 493 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 494 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 495 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 496 | + if ($fonction_generique) { |
|
| 497 | + return [ |
|
| 498 | + 'nom' => $nom, |
|
| 499 | + 'nom_generique' => $nom_generique, |
|
| 500 | + 'fonction_generique' => $fonction_generique, |
|
| 501 | + ]; |
|
| 502 | + } |
|
| 503 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 504 | + } |
|
| 505 | + return null; |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | |
@@ -526,29 +526,29 @@ discard block |
||
| 526 | 526 | * @return null; |
| 527 | 527 | **/ |
| 528 | 528 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 529 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | - if ( |
|
| 531 | - isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | - and $lang_select !== 'oui' |
|
| 533 | - ) { |
|
| 534 | - $lang = $GLOBALS['spip_lang']; |
|
| 535 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | - elseif (!strlen($lang)) { |
|
| 537 | - $lang = $GLOBALS['spip_lang']; |
|
| 538 | - } // Cas 3. l'objet est multilingue ! |
|
| 539 | - elseif ( |
|
| 540 | - $lang_select !== 'oui' |
|
| 541 | - and strlen($titre) > 10 |
|
| 542 | - and strpos($titre, '<multi>') !== false |
|
| 543 | - and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | - ) { |
|
| 545 | - $lang = $GLOBALS['spip_lang']; |
|
| 546 | - } |
|
| 547 | - |
|
| 548 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | - lang_select($lang); |
|
| 550 | - |
|
| 551 | - return; |
|
| 529 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 530 | + if ( |
|
| 531 | + isset($GLOBALS['forcer_lang']) and $GLOBALS['forcer_lang'] |
|
| 532 | + and $lang_select !== 'oui' |
|
| 533 | + ) { |
|
| 534 | + $lang = $GLOBALS['spip_lang']; |
|
| 535 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 536 | + elseif (!strlen($lang)) { |
|
| 537 | + $lang = $GLOBALS['spip_lang']; |
|
| 538 | + } // Cas 3. l'objet est multilingue ! |
|
| 539 | + elseif ( |
|
| 540 | + $lang_select !== 'oui' |
|
| 541 | + and strlen($titre) > 10 |
|
| 542 | + and strpos($titre, '<multi>') !== false |
|
| 543 | + and strpos(echappe_html($titre), '<multi>') !== false |
|
| 544 | + ) { |
|
| 545 | + $lang = $GLOBALS['spip_lang']; |
|
| 546 | + } |
|
| 547 | + |
|
| 548 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 549 | + lang_select($lang); |
|
| 550 | + |
|
| 551 | + return; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | |
@@ -556,21 +556,21 @@ discard block |
||
| 556 | 556 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 557 | 557 | // https://code.spip.net/@nettoyer_env_doublons |
| 558 | 558 | function nettoyer_env_doublons($envd) { |
| 559 | - foreach ($envd as $table => $liste) { |
|
| 560 | - $n = ''; |
|
| 561 | - foreach (explode(',', $liste) as $val) { |
|
| 562 | - if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | - $n .= ',' . $val; |
|
| 564 | - } |
|
| 565 | - } |
|
| 566 | - if (strlen($n)) { |
|
| 567 | - $envd[$table] = $n; |
|
| 568 | - } else { |
|
| 569 | - unset($envd[$table]); |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - return $envd; |
|
| 559 | + foreach ($envd as $table => $liste) { |
|
| 560 | + $n = ''; |
|
| 561 | + foreach (explode(',', $liste) as $val) { |
|
| 562 | + if ($a = intval($val) and $val === strval($a)) { |
|
| 563 | + $n .= ',' . $val; |
|
| 564 | + } |
|
| 565 | + } |
|
| 566 | + if (strlen($n)) { |
|
| 567 | + $envd[$table] = $n; |
|
| 568 | + } else { |
|
| 569 | + unset($envd[$table]); |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + return $envd; |
|
| 574 | 574 | } |
| 575 | 575 | |
| 576 | 576 | /** |
@@ -589,21 +589,21 @@ discard block |
||
| 589 | 589 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 590 | 590 | **/ |
| 591 | 591 | function match_self($w) { |
| 592 | - if (is_string($w)) { |
|
| 593 | - return false; |
|
| 594 | - } |
|
| 595 | - if (is_array($w)) { |
|
| 596 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | - return $w; |
|
| 598 | - } |
|
| 599 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | - if ($m = match_self($sw)) { |
|
| 601 | - return $m; |
|
| 602 | - } |
|
| 603 | - } |
|
| 604 | - } |
|
| 605 | - |
|
| 606 | - return false; |
|
| 592 | + if (is_string($w)) { |
|
| 593 | + return false; |
|
| 594 | + } |
|
| 595 | + if (is_array($w)) { |
|
| 596 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 597 | + return $w; |
|
| 598 | + } |
|
| 599 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 600 | + if ($m = match_self($sw)) { |
|
| 601 | + return $m; |
|
| 602 | + } |
|
| 603 | + } |
|
| 604 | + } |
|
| 605 | + |
|
| 606 | + return false; |
|
| 607 | 607 | } |
| 608 | 608 | |
| 609 | 609 | /** |
@@ -619,16 +619,16 @@ discard block |
||
| 619 | 619 | * est remplacée par son code. |
| 620 | 620 | **/ |
| 621 | 621 | function remplace_sous_requete($w, $sousrequete) { |
| 622 | - if (is_array($w)) { |
|
| 623 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | - return $sousrequete; |
|
| 625 | - } |
|
| 626 | - foreach ($w as $k => $sw) { |
|
| 627 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | - } |
|
| 629 | - } |
|
| 630 | - |
|
| 631 | - return $w; |
|
| 622 | + if (is_array($w)) { |
|
| 623 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 624 | + return $sousrequete; |
|
| 625 | + } |
|
| 626 | + foreach ($w as $k => $sw) { |
|
| 627 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 628 | + } |
|
| 629 | + } |
|
| 630 | + |
|
| 631 | + return $w; |
|
| 632 | 632 | } |
| 633 | 633 | |
| 634 | 634 | /** |
@@ -642,17 +642,17 @@ discard block |
||
| 642 | 642 | * - Conditions avec des sous requêtes |
| 643 | 643 | **/ |
| 644 | 644 | function trouver_sous_requetes($where) { |
| 645 | - $where_simples = []; |
|
| 646 | - $where_sous = []; |
|
| 647 | - foreach ($where as $k => $w) { |
|
| 648 | - if (match_self($w)) { |
|
| 649 | - $where_sous[$k] = $w; |
|
| 650 | - } else { |
|
| 651 | - $where_simples[$k] = $w; |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return [$where_simples, $where_sous]; |
|
| 645 | + $where_simples = []; |
|
| 646 | + $where_sous = []; |
|
| 647 | + foreach ($where as $k => $w) { |
|
| 648 | + if (match_self($w)) { |
|
| 649 | + $where_sous[$k] = $w; |
|
| 650 | + } else { |
|
| 651 | + $where_simples[$k] = $w; |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return [$where_simples, $where_sous]; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | |
@@ -678,292 +678,292 @@ discard block |
||
| 678 | 678 | * @return resource |
| 679 | 679 | */ |
| 680 | 680 | function calculer_select( |
| 681 | - $select = [], |
|
| 682 | - $from = [], |
|
| 683 | - $from_type = [], |
|
| 684 | - $where = [], |
|
| 685 | - $join = [], |
|
| 686 | - $groupby = [], |
|
| 687 | - $orderby = [], |
|
| 688 | - $limit = '', |
|
| 689 | - $having = [], |
|
| 690 | - $table = '', |
|
| 691 | - $id = '', |
|
| 692 | - $serveur = '', |
|
| 693 | - $requeter = true |
|
| 681 | + $select = [], |
|
| 682 | + $from = [], |
|
| 683 | + $from_type = [], |
|
| 684 | + $where = [], |
|
| 685 | + $join = [], |
|
| 686 | + $groupby = [], |
|
| 687 | + $orderby = [], |
|
| 688 | + $limit = '', |
|
| 689 | + $having = [], |
|
| 690 | + $table = '', |
|
| 691 | + $id = '', |
|
| 692 | + $serveur = '', |
|
| 693 | + $requeter = true |
|
| 694 | 694 | ) { |
| 695 | 695 | |
| 696 | - // retirer les criteres vides: |
|
| 697 | - // {X ?} avec X absent de l'URL |
|
| 698 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | - $menage = false; |
|
| 701 | - foreach ($where as $k => $v) { |
|
| 702 | - if (is_array($v)) { |
|
| 703 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | - $op = false; |
|
| 705 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | - $op = false; |
|
| 707 | - } else { |
|
| 708 | - $op = $v[0] ? $v[0] : $v; |
|
| 709 | - } |
|
| 710 | - } else { |
|
| 711 | - $op = $v; |
|
| 712 | - } |
|
| 713 | - if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | - unset($where[$k]); |
|
| 715 | - $menage = true; |
|
| 716 | - } |
|
| 717 | - } |
|
| 718 | - |
|
| 719 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | - $groupby = array_diff($groupby, ['']); |
|
| 721 | - |
|
| 722 | - // remplacer les sous requetes recursives au calcul |
|
| 723 | - list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | - foreach ($where_sous as $k => $w) { |
|
| 725 | - $menage = true; |
|
| 726 | - // on recupere la sous requete |
|
| 727 | - $sous = match_self($w); |
|
| 728 | - if ($sous[0] == 'SELF') { |
|
| 729 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | - array_push($where_simples, $sous[2]); |
|
| 731 | - $wheresub = [ |
|
| 732 | - $sous[2], |
|
| 733 | - '0=0' |
|
| 734 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | - $jsub = $join; |
|
| 736 | - // trouver les jointures utiles a |
|
| 737 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | - // ie L1.objet='article' |
|
| 739 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | - $i = 0; |
|
| 741 | - do { |
|
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 744 | - $from, |
|
| 745 | - $from_type, |
|
| 746 | - $wheresub, |
|
| 747 | - $jsub, |
|
| 748 | - [], |
|
| 749 | - [], |
|
| 750 | - '', |
|
| 751 | - $having, |
|
| 752 | - $table, |
|
| 753 | - $id, |
|
| 754 | - $serveur, |
|
| 755 | - false |
|
| 756 | - ) . ')'); |
|
| 757 | - if (!$i) { |
|
| 758 | - $i = 1; |
|
| 759 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | - foreach ($join as $cle => $wj) { |
|
| 761 | - if ( |
|
| 762 | - count($wj) == 4 |
|
| 763 | - and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | - ) { |
|
| 765 | - $i = 0; |
|
| 766 | - $wheresub[] = $wj[3]; |
|
| 767 | - unset($jsub[$cle][3]); |
|
| 768 | - } |
|
| 769 | - } |
|
| 770 | - } |
|
| 771 | - } while ($i++ < 1); |
|
| 772 | - } |
|
| 773 | - if ($sous[0] == 'SUBSELECT') { |
|
| 774 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | - $sous[1], # select |
|
| 778 | - $sous[2], #from |
|
| 779 | - [], #from_type |
|
| 780 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | - [], #join |
|
| 783 | - $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | - $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | - $sous[6], #limit |
|
| 786 | - $sous[7] ? $sous[7] : [], #having |
|
| 787 | - $table, |
|
| 788 | - $id, |
|
| 789 | - $serveur, |
|
| 790 | - false |
|
| 791 | - ) . ')'); |
|
| 792 | - } |
|
| 793 | - array_pop($where_simples); |
|
| 794 | - } |
|
| 795 | - |
|
| 796 | - foreach ($having as $k => $v) { |
|
| 797 | - if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | - unset($having[$k]); |
|
| 799 | - } |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - // Installer les jointures. |
|
| 803 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | - |
|
| 807 | - $afrom = []; |
|
| 808 | - $equiv = []; |
|
| 809 | - $k = count($join); |
|
| 810 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | - $cle = $cledef; |
|
| 812 | - // le format de join est : |
|
| 813 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | - if (count($join[$cle]) == 2) { |
|
| 816 | - $join[$cle][] = $join[$cle][1]; |
|
| 817 | - } |
|
| 818 | - if (count($join[$cle]) == 3) { |
|
| 819 | - $join[$cle][] = ''; |
|
| 820 | - } |
|
| 821 | - list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | - // pour compat avec ancienne convention |
|
| 824 | - if (is_numeric($cle)) { |
|
| 825 | - $cle = "L$k"; |
|
| 826 | - } |
|
| 827 | - $cle_where_lie = "JOIN-$cle"; |
|
| 828 | - if ( |
|
| 829 | - !$menage |
|
| 830 | - or isset($afrom[$cle]) |
|
| 831 | - or calculer_jointnul($cle, $select) |
|
| 832 | - or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | - or calculer_jointnul($cle, $having) |
|
| 834 | - or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | - ) { |
|
| 836 | - // corriger les references non explicites dans select |
|
| 837 | - // ou groupby |
|
| 838 | - foreach ($select as $i => $s) { |
|
| 839 | - if ($s == $c) { |
|
| 840 | - $select[$i] = "$cle.$c AS $c"; |
|
| 841 | - break; |
|
| 842 | - } |
|
| 843 | - } |
|
| 844 | - foreach ($groupby as $i => $g) { |
|
| 845 | - if ($g == $c) { |
|
| 846 | - $groupby[$i] = "$cle.$c"; |
|
| 847 | - break; |
|
| 848 | - } |
|
| 849 | - } |
|
| 850 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | - // sans recours a preg_match |
|
| 852 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | - $afrom[$t][$cle] = [ |
|
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | - $from[$cle], |
|
| 857 | - "AS $cle", |
|
| 858 | - 'ON (', |
|
| 859 | - "$cle.$c", |
|
| 860 | - '=', |
|
| 861 | - "$t.$carr", |
|
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 863 | - ')' |
|
| 864 | - ]; |
|
| 865 | - if (isset($afrom[$cle])) { |
|
| 866 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | - unset($afrom[$cle]); |
|
| 868 | - } |
|
| 869 | - $equiv[] = $carr; |
|
| 870 | - } else { |
|
| 871 | - unset($join[$cledef]); |
|
| 872 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | - unset($where_simples[$cle_where_lie]); |
|
| 874 | - unset($where[$cle_where_lie]); |
|
| 875 | - } |
|
| 876 | - } |
|
| 877 | - unset($from[$cle]); |
|
| 878 | - $k--; |
|
| 879 | - } |
|
| 880 | - |
|
| 881 | - if (count($afrom)) { |
|
| 882 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | - // ou dans |
|
| 887 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | - // qui comporte plusieurs jointures |
|
| 889 | - // ou dans |
|
| 890 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | - |
|
| 897 | - $t = key($from); |
|
| 898 | - $c = current($from); |
|
| 899 | - reset($from); |
|
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | - if ( |
|
| 902 | - !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | - calculer_jointnul($t, $select, $e) or |
|
| 904 | - calculer_jointnul($t, $join, $e) or |
|
| 905 | - calculer_jointnul($t, $where, $e) or |
|
| 906 | - calculer_jointnul($t, $orderby, $e) or |
|
| 907 | - calculer_jointnul($t, $groupby, $e) or |
|
| 908 | - calculer_jointnul($t, $having, $e)) |
|
| 909 | - && count($afrom[$t]) |
|
| 910 | - ) { |
|
| 911 | - $nfrom = reset($afrom[$t]); |
|
| 912 | - $nt = key($afrom[$t]); |
|
| 913 | - unset($from[$t]); |
|
| 914 | - $from[$nt] = $nfrom[1]; |
|
| 915 | - unset($afrom[$t][$nt]); |
|
| 916 | - $afrom[$nt] = $afrom[$t]; |
|
| 917 | - unset($afrom[$t]); |
|
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | - $t = $nfrom[4]; |
|
| 920 | - $alias = ''; |
|
| 921 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | - $oldcle = explode('.', $nfrom[6]); |
|
| 923 | - $oldcle = end($oldcle); |
|
| 924 | - $newcle = explode('.', $nfrom[4]); |
|
| 925 | - $newcle = end($newcle); |
|
| 926 | - if ($newcle != $oldcle) { |
|
| 927 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | - // reprendre simplement ce AS |
|
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | - $alias = ''; |
|
| 932 | - } else { |
|
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | - } |
|
| 935 | - } |
|
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | - } |
|
| 943 | - $from = reinjecte_joint($afrom, $from); |
|
| 944 | - } |
|
| 945 | - if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | - $GLOBALS['debug'] = []; |
|
| 948 | - if ($wasdebug) { |
|
| 949 | - $GLOBALS['debug']['debug'] = true; |
|
| 950 | - } |
|
| 951 | - } |
|
| 952 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | - $r = sql_select( |
|
| 954 | - $select, |
|
| 955 | - $from, |
|
| 956 | - $where, |
|
| 957 | - $groupby, |
|
| 958 | - array_filter($orderby), |
|
| 959 | - $limit, |
|
| 960 | - $having, |
|
| 961 | - $serveur, |
|
| 962 | - $requeter |
|
| 963 | - ); |
|
| 964 | - unset($GLOBALS['debug']['aucasou']); |
|
| 965 | - |
|
| 966 | - return $r; |
|
| 696 | + // retirer les criteres vides: |
|
| 697 | + // {X ?} avec X absent de l'URL |
|
| 698 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 699 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 700 | + $menage = false; |
|
| 701 | + foreach ($where as $k => $v) { |
|
| 702 | + if (is_array($v)) { |
|
| 703 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 704 | + $op = false; |
|
| 705 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 706 | + $op = false; |
|
| 707 | + } else { |
|
| 708 | + $op = $v[0] ? $v[0] : $v; |
|
| 709 | + } |
|
| 710 | + } else { |
|
| 711 | + $op = $v; |
|
| 712 | + } |
|
| 713 | + if ((!$op) or ($op == 1) or ($op == '0=0')) { |
|
| 714 | + unset($where[$k]); |
|
| 715 | + $menage = true; |
|
| 716 | + } |
|
| 717 | + } |
|
| 718 | + |
|
| 719 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 720 | + $groupby = array_diff($groupby, ['']); |
|
| 721 | + |
|
| 722 | + // remplacer les sous requetes recursives au calcul |
|
| 723 | + list($where_simples, $where_sous) = trouver_sous_requetes($where); |
|
| 724 | + foreach ($where_sous as $k => $w) { |
|
| 725 | + $menage = true; |
|
| 726 | + // on recupere la sous requete |
|
| 727 | + $sous = match_self($w); |
|
| 728 | + if ($sous[0] == 'SELF') { |
|
| 729 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 730 | + array_push($where_simples, $sous[2]); |
|
| 731 | + $wheresub = [ |
|
| 732 | + $sous[2], |
|
| 733 | + '0=0' |
|
| 734 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 735 | + $jsub = $join; |
|
| 736 | + // trouver les jointures utiles a |
|
| 737 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 738 | + // ie L1.objet='article' |
|
| 739 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 740 | + $i = 0; |
|
| 741 | + do { |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | + [$sous[1] . ' AS id'], |
|
| 744 | + $from, |
|
| 745 | + $from_type, |
|
| 746 | + $wheresub, |
|
| 747 | + $jsub, |
|
| 748 | + [], |
|
| 749 | + [], |
|
| 750 | + '', |
|
| 751 | + $having, |
|
| 752 | + $table, |
|
| 753 | + $id, |
|
| 754 | + $serveur, |
|
| 755 | + false |
|
| 756 | + ) . ')'); |
|
| 757 | + if (!$i) { |
|
| 758 | + $i = 1; |
|
| 759 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 760 | + foreach ($join as $cle => $wj) { |
|
| 761 | + if ( |
|
| 762 | + count($wj) == 4 |
|
| 763 | + and strpos($wherestring, "{$cle}.") !== false |
|
| 764 | + ) { |
|
| 765 | + $i = 0; |
|
| 766 | + $wheresub[] = $wj[3]; |
|
| 767 | + unset($jsub[$cle][3]); |
|
| 768 | + } |
|
| 769 | + } |
|
| 770 | + } |
|
| 771 | + } while ($i++ < 1); |
|
| 772 | + } |
|
| 773 | + if ($sous[0] == 'SUBSELECT') { |
|
| 774 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 775 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 777 | + $sous[1], # select |
|
| 778 | + $sous[2], #from |
|
| 779 | + [], #from_type |
|
| 780 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 781 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 782 | + [], #join |
|
| 783 | + $sous[4] ? $sous[4] : [], #groupby |
|
| 784 | + $sous[5] ? $sous[5] : [], #orderby |
|
| 785 | + $sous[6], #limit |
|
| 786 | + $sous[7] ? $sous[7] : [], #having |
|
| 787 | + $table, |
|
| 788 | + $id, |
|
| 789 | + $serveur, |
|
| 790 | + false |
|
| 791 | + ) . ')'); |
|
| 792 | + } |
|
| 793 | + array_pop($where_simples); |
|
| 794 | + } |
|
| 795 | + |
|
| 796 | + foreach ($having as $k => $v) { |
|
| 797 | + if ((!$v) or ($v == 1) or ($v == '0=0')) { |
|
| 798 | + unset($having[$k]); |
|
| 799 | + } |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + // Installer les jointures. |
|
| 803 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 804 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 805 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 806 | + |
|
| 807 | + $afrom = []; |
|
| 808 | + $equiv = []; |
|
| 809 | + $k = count($join); |
|
| 810 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 811 | + $cle = $cledef; |
|
| 812 | + // le format de join est : |
|
| 813 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 814 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 815 | + if (count($join[$cle]) == 2) { |
|
| 816 | + $join[$cle][] = $join[$cle][1]; |
|
| 817 | + } |
|
| 818 | + if (count($join[$cle]) == 3) { |
|
| 819 | + $join[$cle][] = ''; |
|
| 820 | + } |
|
| 821 | + list($t, $c, $carr, $and) = $join[$cle]; |
|
| 822 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 823 | + // pour compat avec ancienne convention |
|
| 824 | + if (is_numeric($cle)) { |
|
| 825 | + $cle = "L$k"; |
|
| 826 | + } |
|
| 827 | + $cle_where_lie = "JOIN-$cle"; |
|
| 828 | + if ( |
|
| 829 | + !$menage |
|
| 830 | + or isset($afrom[$cle]) |
|
| 831 | + or calculer_jointnul($cle, $select) |
|
| 832 | + or calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 833 | + or calculer_jointnul($cle, $having) |
|
| 834 | + or calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 835 | + ) { |
|
| 836 | + // corriger les references non explicites dans select |
|
| 837 | + // ou groupby |
|
| 838 | + foreach ($select as $i => $s) { |
|
| 839 | + if ($s == $c) { |
|
| 840 | + $select[$i] = "$cle.$c AS $c"; |
|
| 841 | + break; |
|
| 842 | + } |
|
| 843 | + } |
|
| 844 | + foreach ($groupby as $i => $g) { |
|
| 845 | + if ($g == $c) { |
|
| 846 | + $groupby[$i] = "$cle.$c"; |
|
| 847 | + break; |
|
| 848 | + } |
|
| 849 | + } |
|
| 850 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 851 | + // sans recours a preg_match |
|
| 852 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 853 | + $afrom[$t][$cle] = [ |
|
| 854 | + "\n" . |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 856 | + $from[$cle], |
|
| 857 | + "AS $cle", |
|
| 858 | + 'ON (', |
|
| 859 | + "$cle.$c", |
|
| 860 | + '=', |
|
| 861 | + "$t.$carr", |
|
| 862 | + ($and ? 'AND ' . $and : '') . |
|
| 863 | + ')' |
|
| 864 | + ]; |
|
| 865 | + if (isset($afrom[$cle])) { |
|
| 866 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 867 | + unset($afrom[$cle]); |
|
| 868 | + } |
|
| 869 | + $equiv[] = $carr; |
|
| 870 | + } else { |
|
| 871 | + unset($join[$cledef]); |
|
| 872 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 873 | + unset($where_simples[$cle_where_lie]); |
|
| 874 | + unset($where[$cle_where_lie]); |
|
| 875 | + } |
|
| 876 | + } |
|
| 877 | + unset($from[$cle]); |
|
| 878 | + $k--; |
|
| 879 | + } |
|
| 880 | + |
|
| 881 | + if (count($afrom)) { |
|
| 882 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 883 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 884 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 885 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 886 | + // ou dans |
|
| 887 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 888 | + // qui comporte plusieurs jointures |
|
| 889 | + // ou dans |
|
| 890 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 891 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 892 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 893 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 894 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 895 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 896 | + |
|
| 897 | + $t = key($from); |
|
| 898 | + $c = current($from); |
|
| 899 | + reset($from); |
|
| 900 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 901 | + if ( |
|
| 902 | + !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
|
| 903 | + calculer_jointnul($t, $select, $e) or |
|
| 904 | + calculer_jointnul($t, $join, $e) or |
|
| 905 | + calculer_jointnul($t, $where, $e) or |
|
| 906 | + calculer_jointnul($t, $orderby, $e) or |
|
| 907 | + calculer_jointnul($t, $groupby, $e) or |
|
| 908 | + calculer_jointnul($t, $having, $e)) |
|
| 909 | + && count($afrom[$t]) |
|
| 910 | + ) { |
|
| 911 | + $nfrom = reset($afrom[$t]); |
|
| 912 | + $nt = key($afrom[$t]); |
|
| 913 | + unset($from[$t]); |
|
| 914 | + $from[$nt] = $nfrom[1]; |
|
| 915 | + unset($afrom[$t][$nt]); |
|
| 916 | + $afrom[$nt] = $afrom[$t]; |
|
| 917 | + unset($afrom[$t]); |
|
| 918 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 919 | + $t = $nfrom[4]; |
|
| 920 | + $alias = ''; |
|
| 921 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 922 | + $oldcle = explode('.', $nfrom[6]); |
|
| 923 | + $oldcle = end($oldcle); |
|
| 924 | + $newcle = explode('.', $nfrom[4]); |
|
| 925 | + $newcle = end($newcle); |
|
| 926 | + if ($newcle != $oldcle) { |
|
| 927 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 928 | + // reprendre simplement ce AS |
|
| 929 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 930 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 931 | + $alias = ''; |
|
| 932 | + } else { |
|
| 933 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 934 | + } |
|
| 935 | + } |
|
| 936 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 937 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 938 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 939 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 940 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 941 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 942 | + } |
|
| 943 | + $from = reinjecte_joint($afrom, $from); |
|
| 944 | + } |
|
| 945 | + if (empty($GLOBALS['debug']) or !is_array($GLOBALS['debug'])) { |
|
| 946 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 947 | + $GLOBALS['debug'] = []; |
|
| 948 | + if ($wasdebug) { |
|
| 949 | + $GLOBALS['debug']['debug'] = true; |
|
| 950 | + } |
|
| 951 | + } |
|
| 952 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 953 | + $r = sql_select( |
|
| 954 | + $select, |
|
| 955 | + $from, |
|
| 956 | + $where, |
|
| 957 | + $groupby, |
|
| 958 | + array_filter($orderby), |
|
| 959 | + $limit, |
|
| 960 | + $having, |
|
| 961 | + $serveur, |
|
| 962 | + $requeter |
|
| 963 | + ); |
|
| 964 | + unset($GLOBALS['debug']['aucasou']); |
|
| 965 | + |
|
| 966 | + return $r; |
|
| 967 | 967 | } |
| 968 | 968 | |
| 969 | 969 | /** |
@@ -974,20 +974,20 @@ discard block |
||
| 974 | 974 | * @return string |
| 975 | 975 | */ |
| 976 | 976 | function calculer_where_to_string($v, $join = 'AND') { |
| 977 | - if (empty($v)) { |
|
| 978 | - return ''; |
|
| 979 | - } |
|
| 980 | - |
|
| 981 | - if (!is_array($v)) { |
|
| 982 | - return $v; |
|
| 983 | - } else { |
|
| 984 | - $exp = ''; |
|
| 985 | - if (strtoupper($join) === 'AND') { |
|
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | - } else { |
|
| 988 | - return $exp . join($join, $v); |
|
| 989 | - } |
|
| 990 | - } |
|
| 977 | + if (empty($v)) { |
|
| 978 | + return ''; |
|
| 979 | + } |
|
| 980 | + |
|
| 981 | + if (!is_array($v)) { |
|
| 982 | + return $v; |
|
| 983 | + } else { |
|
| 984 | + $exp = ''; |
|
| 985 | + if (strtoupper($join) === 'AND') { |
|
| 986 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | + } else { |
|
| 988 | + return $exp . join($join, $v); |
|
| 989 | + } |
|
| 990 | + } |
|
| 991 | 991 | } |
| 992 | 992 | |
| 993 | 993 | |
@@ -995,62 +995,62 @@ discard block |
||
| 995 | 995 | |
| 996 | 996 | // https://code.spip.net/@calculer_jointnul |
| 997 | 997 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 998 | - if (!is_array($exp)) { |
|
| 999 | - if ($equiv) { |
|
| 1000 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | - } |
|
| 1002 | - |
|
| 1003 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | - } else { |
|
| 1005 | - foreach ($exp as $v) { |
|
| 1006 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | - return true; |
|
| 1008 | - } |
|
| 1009 | - } |
|
| 1010 | - |
|
| 1011 | - return false; |
|
| 1012 | - } |
|
| 998 | + if (!is_array($exp)) { |
|
| 999 | + if ($equiv) { |
|
| 1000 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1001 | + } |
|
| 1002 | + |
|
| 1003 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1004 | + } else { |
|
| 1005 | + foreach ($exp as $v) { |
|
| 1006 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1007 | + return true; |
|
| 1008 | + } |
|
| 1009 | + } |
|
| 1010 | + |
|
| 1011 | + return false; |
|
| 1012 | + } |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | // https://code.spip.net/@reinjecte_joint |
| 1016 | 1016 | function reinjecte_joint($afrom, $from) { |
| 1017 | - $from_synth = []; |
|
| 1018 | - foreach ($from as $k => $v) { |
|
| 1019 | - $from_synth[$k] = $from[$k]; |
|
| 1020 | - if (isset($afrom[$k])) { |
|
| 1021 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | - } |
|
| 1024 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | - unset($afrom[$k]); |
|
| 1026 | - } |
|
| 1027 | - } |
|
| 1028 | - |
|
| 1029 | - return $from_synth; |
|
| 1017 | + $from_synth = []; |
|
| 1018 | + foreach ($from as $k => $v) { |
|
| 1019 | + $from_synth[$k] = $from[$k]; |
|
| 1020 | + if (isset($afrom[$k])) { |
|
| 1021 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1022 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1023 | + } |
|
| 1024 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1025 | + unset($afrom[$k]); |
|
| 1026 | + } |
|
| 1027 | + } |
|
| 1028 | + |
|
| 1029 | + return $from_synth; |
|
| 1030 | 1030 | } |
| 1031 | 1031 | |
| 1032 | 1032 | // https://code.spip.net/@remplacer_jointnul |
| 1033 | 1033 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1034 | - if (!is_array($exp)) { |
|
| 1035 | - return preg_replace($equiv, $cle, $exp); |
|
| 1036 | - } else { |
|
| 1037 | - foreach ($exp as $k => $v) { |
|
| 1038 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | - } |
|
| 1040 | - |
|
| 1041 | - return $exp; |
|
| 1042 | - } |
|
| 1034 | + if (!is_array($exp)) { |
|
| 1035 | + return preg_replace($equiv, $cle, $exp); |
|
| 1036 | + } else { |
|
| 1037 | + foreach ($exp as $k => $v) { |
|
| 1038 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1039 | + } |
|
| 1040 | + |
|
| 1041 | + return $exp; |
|
| 1042 | + } |
|
| 1043 | 1043 | } |
| 1044 | 1044 | |
| 1045 | 1045 | // calcul du nom du squelette |
| 1046 | 1046 | // https://code.spip.net/@calculer_nom_fonction_squel |
| 1047 | 1047 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', $connect = '') { |
| 1048 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | - if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | - } |
|
| 1052 | - |
|
| 1053 | - return $mime_type |
|
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1048 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1049 | + if ($l = strlen(_DIR_RACINE) and strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1050 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1051 | + } |
|
| 1052 | + |
|
| 1053 | + return $mime_type |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -54,7 +54,7 @@ discard block |
||
| 54 | 54 | $GLOBALS['debug_objets']['courant'] = $nom; |
| 55 | 55 | } |
| 56 | 56 | |
| 57 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 57 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true).$nom.'.php'; |
|
| 58 | 58 | |
| 59 | 59 | // si squelette est deja compile et perenne, le charger |
| 60 | 60 | if (!squelette_obsolete($phpfile, $source)) { |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | #} |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 70 | + if (file_exists($lib = $squelette.'_fonctions'.'.php')) { |
|
| 71 | 71 | include_once $lib; |
| 72 | 72 | } |
| 73 | 73 | |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | eval("return true; $f ;"); |
| 96 | 96 | } catch (\ParseError $e) { |
| 97 | 97 | // Code syntaxiquement faux (critere etc mal programme') |
| 98 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 98 | + $msg = _T('zbug_erreur_compilation').' | Line '.$e->getLine().' : '.$e->getMessage(); |
|
| 99 | 99 | erreur_squelette($msg, $boucle); |
| 100 | 100 | // continuer pour trouver d'autres fautes eventuelles |
| 101 | 101 | // mais prevenir que c'est mort |
@@ -123,7 +123,7 @@ discard block |
||
| 123 | 123 | |
| 124 | 124 | if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
| 125 | 125 | // Tracer ce qui vient d'etre compile |
| 126 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 126 | + $GLOBALS['debug_objets']['code'][$nom.'tout'] = $code; |
|
| 127 | 127 | |
| 128 | 128 | // si c'est ce que demande le debusqueur, lui passer la main |
| 129 | 129 | if ( |
@@ -146,13 +146,13 @@ discard block |
||
| 146 | 146 | $code = " |
| 147 | 147 | /* |
| 148 | 148 | * Squelette : $sourcefile |
| 149 | - * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
|
| 150 | - * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
|
| 151 | - * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
|
| 149 | + * Date : ".gmdate('D, d M Y H:i:s', @filemtime($sourcefile)).' GMT |
|
| 150 | + * Compile : ' . gmdate('D, d M Y H:i:s', time()).' GMT |
|
| 151 | + * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : '.$noms)).' |
|
| 152 | 152 | */ '; |
| 153 | 153 | } |
| 154 | 154 | |
| 155 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n?" . '>'; |
|
| 155 | + $code = '<'."?php\n".$code.join('', $boucles)."\n?".'>'; |
|
| 156 | 156 | if (!defined('_VAR_NOCACHE') or !_VAR_NOCACHE) { |
| 157 | 157 | ecrire_fichier($phpfile, $code); |
| 158 | 158 | } |
@@ -216,7 +216,7 @@ discard block |
||
| 216 | 216 | $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
| 217 | 217 | |
| 218 | 218 | if ($j == 'X-Spip-Filtre' and isset($headers[$j])) { |
| 219 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | + $headers[$j] .= '|'.$r[3]; |
|
| 220 | 220 | } else { |
| 221 | 221 | $headers[$j] = $r[3]; |
| 222 | 222 | } |
@@ -224,10 +224,10 @@ discard block |
||
| 224 | 224 | } |
| 225 | 225 | // S'agit-il d'un resultat constant ou contenant du code php |
| 226 | 226 | $process_ins = ( |
| 227 | - strpos($corps, '<' . '?') === false |
|
| 227 | + strpos($corps, '<'.'?') === false |
|
| 228 | 228 | or |
| 229 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 230 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 229 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 230 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 231 | 231 | ) |
| 232 | 232 | ? 'html' |
| 233 | 233 | : 'php'; |
@@ -256,10 +256,10 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | if ($process_ins == 'html') { |
| 258 | 258 | $skel['process_ins'] = ( |
| 259 | - strpos($corps, '<' . '?') === false |
|
| 259 | + strpos($corps, '<'.'?') === false |
|
| 260 | 260 | or |
| 261 | - (strpos($corps, '<' . '?xml') !== false and |
|
| 262 | - strpos(str_replace('<' . '?xml', '', $corps), '<' . '?') === false) |
|
| 261 | + (strpos($corps, '<'.'?xml') !== false and |
|
| 262 | + strpos(str_replace('<'.'?xml', '', $corps), '<'.'?') === false) |
|
| 263 | 263 | ) |
| 264 | 264 | ? 'html' |
| 265 | 265 | : 'php'; |
@@ -277,7 +277,7 @@ discard block |
||
| 277 | 277 | // |
| 278 | 278 | |
| 279 | 279 | /** Code PHP pour inclure une balise dynamique à l'exécution d'une page */ |
| 280 | -define('CODE_INCLURE_BALISE', '<' . '?php |
|
| 280 | +define('CODE_INCLURE_BALISE', '<'.'?php |
|
| 281 | 281 | include_once("%s"); |
| 282 | 282 | if ($lang_select = "%s") $lang_select = lang_select($lang_select); |
| 283 | 283 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
@@ -308,7 +308,7 @@ discard block |
||
| 308 | 308 | // pas de lien symbolique sous Windows |
| 309 | 309 | and !(stristr(PHP_OS, 'WIN') and strpos($file, ':') !== false) |
| 310 | 310 | ) { |
| 311 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 311 | + $file = './" . _DIR_RACINE . "'.$file; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | $lang = $context_compil[4]; |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | $args = array_map('argumenter_squelette', $args); |
| 320 | 320 | if (!empty($context_compil['appel_php_depuis_modele'])) { |
| 321 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 321 | + $args[0] = 'arguments_balise_dyn_depuis_modele('.$args[0].')'; |
|
| 322 | 322 | } |
| 323 | 323 | $args = join(', ', $args); |
| 324 | 324 | |
@@ -352,14 +352,14 @@ discard block |
||
| 352 | 352 | if (is_object($v)) { |
| 353 | 353 | return var_export($v, true); |
| 354 | 354 | } elseif (!is_array($v)) { |
| 355 | - return "'" . texte_script($v) . "'"; |
|
| 355 | + return "'".texte_script($v)."'"; |
|
| 356 | 356 | } else { |
| 357 | 357 | $out = []; |
| 358 | 358 | foreach ($v as $k => $val) { |
| 359 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 359 | + $out [] = argumenter_squelette($k).'=>'.argumenter_squelette($val); |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | - return 'array(' . join(', ', $out) . ')'; |
|
| 362 | + return 'array('.join(', ', $out).')'; |
|
| 363 | 363 | } |
| 364 | 364 | } |
| 365 | 365 | |
@@ -437,7 +437,7 @@ discard block |
||
| 437 | 437 | } |
| 438 | 438 | |
| 439 | 439 | // Y a-t-il une fonction de traitement des arguments ? |
| 440 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 440 | + $f = 'balise_'.$nom_balise.'_stat'; |
|
| 441 | 441 | |
| 442 | 442 | $r = !function_exists($f) ? $args : $f($args, $context_compil); |
| 443 | 443 | |
@@ -447,18 +447,18 @@ discard block |
||
| 447 | 447 | |
| 448 | 448 | // verifier que la fonction dyn est la, |
| 449 | 449 | // sinon se replier sur la generique si elle existe |
| 450 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 450 | + if (!function_exists('balise_'.$nom_balise.'_dyn')) { |
|
| 451 | 451 | if ( |
| 452 | 452 | $balise_generique = chercher_balise_generique($nom) |
| 453 | 453 | and $nom_balise_generique = $balise_generique['nom_generique'] |
| 454 | - and $file = include_spip('balise/' . strtolower($nom_balise_generique)) |
|
| 455 | - and function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 454 | + and $file = include_spip('balise/'.strtolower($nom_balise_generique)) |
|
| 455 | + and function_exists('balise_'.$nom_balise_generique.'_dyn') |
|
| 456 | 456 | ) { |
| 457 | 457 | // et lui injecter en premier arg le nom de la balise |
| 458 | 458 | array_unshift($r, $nom); |
| 459 | 459 | $nom_balise = $nom_balise_generique; |
| 460 | 460 | if (!_DIR_RESTREINT) { |
| 461 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 461 | + $file = _DIR_RESTREINT_ABS.$file; |
|
| 462 | 462 | } |
| 463 | 463 | } else { |
| 464 | 464 | $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
@@ -560,7 +560,7 @@ discard block |
||
| 560 | 560 | $n = ''; |
| 561 | 561 | foreach (explode(',', $liste) as $val) { |
| 562 | 562 | if ($a = intval($val) and $val === strval($a)) { |
| 563 | - $n .= ',' . $val; |
|
| 563 | + $n .= ','.$val; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | if (strlen($n)) { |
@@ -739,8 +739,8 @@ discard block |
||
| 739 | 739 | // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
| 740 | 740 | $i = 0; |
| 741 | 741 | do { |
| 742 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 743 | - [$sous[1] . ' AS id'], |
|
| 742 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 743 | + [$sous[1].' AS id'], |
|
| 744 | 744 | $from, |
| 745 | 745 | $from_type, |
| 746 | 746 | $wheresub, |
@@ -753,7 +753,7 @@ discard block |
||
| 753 | 753 | $id, |
| 754 | 754 | $serveur, |
| 755 | 755 | false |
| 756 | - ) . ')'); |
|
| 756 | + ).')'); |
|
| 757 | 757 | if (!$i) { |
| 758 | 758 | $i = 1; |
| 759 | 759 | $wherestring = calculer_where_to_string($where[$k]); |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | if ($sous[0] == 'SUBSELECT') { |
| 774 | 774 | // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
| 775 | 775 | array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
| 776 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 776 | + $where[$k] = remplace_sous_requete($w, '('.calculer_select( |
|
| 777 | 777 | $sous[1], # select |
| 778 | 778 | $sous[2], #from |
| 779 | 779 | [], #from_type |
@@ -788,7 +788,7 @@ discard block |
||
| 788 | 788 | $id, |
| 789 | 789 | $serveur, |
| 790 | 790 | false |
| 791 | - ) . ')'); |
|
| 791 | + ).')'); |
|
| 792 | 792 | } |
| 793 | 793 | array_pop($where_simples); |
| 794 | 794 | } |
@@ -851,15 +851,15 @@ discard block |
||
| 851 | 851 | // sans recours a preg_match |
| 852 | 852 | // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
| 853 | 853 | $afrom[$t][$cle] = [ |
| 854 | - "\n" . |
|
| 855 | - (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER') . ' JOIN', |
|
| 854 | + "\n". |
|
| 855 | + (isset($from_type[$cle]) ? $from_type[$cle] : 'INNER').' JOIN', |
|
| 856 | 856 | $from[$cle], |
| 857 | 857 | "AS $cle", |
| 858 | 858 | 'ON (', |
| 859 | 859 | "$cle.$c", |
| 860 | 860 | '=', |
| 861 | 861 | "$t.$carr", |
| 862 | - ($and ? 'AND ' . $and : '') . |
|
| 862 | + ($and ? 'AND '.$and : ''). |
|
| 863 | 863 | ')' |
| 864 | 864 | ]; |
| 865 | 865 | if (isset($afrom[$cle])) { |
@@ -897,7 +897,7 @@ discard block |
||
| 897 | 897 | $t = key($from); |
| 898 | 898 | $c = current($from); |
| 899 | 899 | reset($from); |
| 900 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 900 | + $e = '/\b('."$t\\.".join('|'.$t.'\.', $equiv).')\b/'; |
|
| 901 | 901 | if ( |
| 902 | 902 | !(strpos($t, ' ') or // jointure des le depart cf boucle_doc |
| 903 | 903 | calculer_jointnul($t, $select, $e) or |
@@ -915,7 +915,7 @@ discard block |
||
| 915 | 915 | unset($afrom[$t][$nt]); |
| 916 | 916 | $afrom[$nt] = $afrom[$t]; |
| 917 | 917 | unset($afrom[$t]); |
| 918 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 918 | + $e = '/\b'.preg_quote($nfrom[6]).'\b/'; |
|
| 919 | 919 | $t = $nfrom[4]; |
| 920 | 920 | $alias = ''; |
| 921 | 921 | // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
@@ -926,14 +926,14 @@ discard block |
||
| 926 | 926 | if ($newcle != $oldcle) { |
| 927 | 927 | // si l'ancienne cle etait deja dans le select avec un AS |
| 928 | 928 | // reprendre simplement ce AS |
| 929 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 929 | + $as = '/\b'.preg_quote($nfrom[6]).'\s+(AS\s+\w+)\b/'; |
|
| 930 | 930 | if (preg_match($as, implode(',', $select), $m)) { |
| 931 | 931 | $alias = ''; |
| 932 | 932 | } else { |
| 933 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 933 | + $alias = ', '.$nfrom[4]." AS $oldcle"; |
|
| 934 | 934 | } |
| 935 | 935 | } |
| 936 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 936 | + $select = remplacer_jointnul($t.$alias, $select, $e); |
|
| 937 | 937 | $join = remplacer_jointnul($t, $join, $e); |
| 938 | 938 | $where = remplacer_jointnul($t, $where, $e); |
| 939 | 939 | $having = remplacer_jointnul($t, $having, $e); |
@@ -983,9 +983,9 @@ discard block |
||
| 983 | 983 | } else { |
| 984 | 984 | $exp = ''; |
| 985 | 985 | if (strtoupper($join) === 'AND') { |
| 986 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 986 | + return $exp.join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 987 | 987 | } else { |
| 988 | - return $exp . join($join, $v); |
|
| 988 | + return $exp.join($join, $v); |
|
| 989 | 989 | } |
| 990 | 990 | } |
| 991 | 991 | } |
@@ -1051,6 +1051,6 @@ discard block |
||
| 1051 | 1051 | } |
| 1052 | 1052 | |
| 1053 | 1053 | return $mime_type |
| 1054 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1055 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1054 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)).'_' |
|
| 1055 | + . md5($GLOBALS['spip_version_code'].' * '.$skel.(isset($GLOBALS['marqueur_skel']) ? '*'.$GLOBALS['marqueur_skel'] : '')); |
|
| 1056 | 1056 | } |
@@ -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 | |
@@ -32,7 +32,7 @@ discard block |
||
| 32 | 32 | * Code PHP compilé de la boucle |
| 33 | 33 | **/ |
| 34 | 34 | function boucle_DEFAUT_dist($id_boucle, &$boucles) { |
| 35 | - return calculer_boucle($id_boucle, $boucles); |
|
| 35 | + return calculer_boucle($id_boucle, $boucles); |
|
| 36 | 36 | } |
| 37 | 37 | |
| 38 | 38 | |
@@ -51,7 +51,7 @@ discard block |
||
| 51 | 51 | * Code PHP compilé de la boucle |
| 52 | 52 | **/ |
| 53 | 53 | function boucle_BOUCLE_dist($id_boucle, &$boucles) { |
| 54 | - return calculer_boucle($id_boucle, $boucles); |
|
| 54 | + return calculer_boucle($id_boucle, $boucles); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
@@ -81,30 +81,30 @@ discard block |
||
| 81 | 81 | * Code PHP compilé de la boucle |
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | - $boucle = &$boucles[$id_boucle]; |
|
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 84 | + $boucle = &$boucles[$id_boucle]; |
|
| 85 | + $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 86 | 86 | |
| 87 | - // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | - // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | - // ou {id_article} qui positionne aussi le {tout} |
|
| 87 | + // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
|
| 88 | + // sauf en presence du critere {tout} (vu par phraser_html) |
|
| 89 | + // ou {id_article} qui positionne aussi le {tout} |
|
| 90 | 90 | |
| 91 | - $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | - . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | - . ")))\n\t\treturn '';\n\t" |
|
| 94 | - . "include_spip('inc/rubriques');\n\t" |
|
| 95 | - . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | - . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | - . ");\n\t" |
|
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 91 | + $boucle->hierarchie = 'if (!($id_rubrique = intval(' |
|
| 92 | + . calculer_argument_precedent($boucle->id_boucle, 'id_rubrique', $boucles) |
|
| 93 | + . ")))\n\t\treturn '';\n\t" |
|
| 94 | + . "include_spip('inc/rubriques');\n\t" |
|
| 95 | + . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
|
| 96 | + . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
|
| 97 | + . ");\n\t" |
|
| 98 | + . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 99 | 99 | |
| 100 | - $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 100 | + $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
|
| 101 | 101 | |
| 102 | - $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | - if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | - $boucle->default_order[] = "\"$order\""; |
|
| 105 | - } else { |
|
| 106 | - $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | - } |
|
| 102 | + $order = "FIELD($id_table, \$hierarchie)"; |
|
| 103 | + if (!isset($boucle->default_order[0]) or $boucle->default_order[0] != ' DESC') { |
|
| 104 | + $boucle->default_order[] = "\"$order\""; |
|
| 105 | + } else { |
|
| 106 | + $boucle->default_order[0] = "\"$order DESC\""; |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return calculer_boucle($id_boucle, $boucles); |
|
| 109 | + return calculer_boucle($id_boucle, $boucles); |
|
| 110 | 110 | } |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | **/ |
| 83 | 83 | function boucle_HIERARCHIE_dist($id_boucle, &$boucles) { |
| 84 | 84 | $boucle = &$boucles[$id_boucle]; |
| 85 | - $id_table = $boucle->id_table . '.id_rubrique'; |
|
| 85 | + $id_table = $boucle->id_table.'.id_rubrique'; |
|
| 86 | 86 | |
| 87 | 87 | // Si la boucle mere est une boucle RUBRIQUES il faut ignorer la feuille |
| 88 | 88 | // sauf en presence du critere {tout} (vu par phraser_html) |
@@ -95,7 +95,7 @@ discard block |
||
| 95 | 95 | . '$hierarchie = calcul_hierarchie_in($id_rubrique,' |
| 96 | 96 | . (isset($boucle->modificateur['tout']) ? 'true' : 'false') |
| 97 | 97 | . ");\n\t" |
| 98 | - . 'if (!$hierarchie) return "";' . "\n\t"; |
|
| 98 | + . 'if (!$hierarchie) return "";'."\n\t"; |
|
| 99 | 99 | |
| 100 | 100 | $boucle->where[] = ["'IN'", "'$id_table'", '"($hierarchie)"']; |
| 101 | 101 | |
@@ -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 | // Ce fichier doit imperativement definir la fonction ci-dessous: |
@@ -39,59 +39,59 @@ discard block |
||
| 39 | 39 | * @return array |
| 40 | 40 | */ |
| 41 | 41 | function public_styliser_dist($fond, $contexte, $lang = '', $connect = '') { |
| 42 | - static $styliser_par_z; |
|
| 43 | - |
|
| 44 | - // s'assurer que le fond est licite |
|
| 45 | - // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | - if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | - $fond = '404'; |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | - $modele = substr($fond, 8); |
|
| 52 | - $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | - $fond = "modeles/$modele"; |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | - $id_rubrique = 0; |
|
| 58 | - // Chercher le fond qui va servir de squelette |
|
| 59 | - if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | - list($id_rubrique, $lang) = $r; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // trouver un squelette du nom demande |
|
| 64 | - // ne rien dire si on ne trouve pas, |
|
| 65 | - // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | - // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | - $squelette = trouver_fond($fond, '', true); |
|
| 68 | - $ext = $squelette['extension']; |
|
| 69 | - |
|
| 70 | - $flux = [ |
|
| 71 | - 'args' => [ |
|
| 72 | - 'id_rubrique' => $id_rubrique, |
|
| 73 | - 'ext' => $ext, |
|
| 74 | - 'fond' => $fond, |
|
| 75 | - 'lang' => $lang, |
|
| 76 | - 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | - 'connect' => $connect |
|
| 78 | - ], |
|
| 79 | - 'data' => $squelette['fond'], |
|
| 80 | - ]; |
|
| 81 | - |
|
| 82 | - if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | - if (!$styliser_par_z) { |
|
| 84 | - $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | - } |
|
| 86 | - $flux = $styliser_par_z($flux); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $flux = styliser_par_objets($flux); |
|
| 90 | - |
|
| 91 | - // pipeline styliser |
|
| 92 | - $squelette = pipeline('styliser', $flux); |
|
| 93 | - |
|
| 94 | - return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 42 | + static $styliser_par_z; |
|
| 43 | + |
|
| 44 | + // s'assurer que le fond est licite |
|
| 45 | + // car il peut etre construit a partir d'une variable d'environnement |
|
| 46 | + if (strpos($fond, '../') !== false or strncmp($fond, '/', 1) == 0) { |
|
| 47 | + $fond = '404'; |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + if (strncmp($fond, 'modeles/', 8) == 0) { |
|
| 51 | + $modele = substr($fond, 8); |
|
| 52 | + $modele = styliser_modele($modele, null, $contexte); |
|
| 53 | + $fond = "modeles/$modele"; |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // Choisir entre $fond-dist.html, $fond=7.html, etc? |
|
| 57 | + $id_rubrique = 0; |
|
| 58 | + // Chercher le fond qui va servir de squelette |
|
| 59 | + if ($r = quete_rubrique_fond($contexte)) { |
|
| 60 | + list($id_rubrique, $lang) = $r; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // trouver un squelette du nom demande |
|
| 64 | + // ne rien dire si on ne trouve pas, |
|
| 65 | + // c'est l'appelant qui sait comment gerer la situation |
|
| 66 | + // ou les plugins qui feront mieux dans le pipeline |
|
| 67 | + $squelette = trouver_fond($fond, '', true); |
|
| 68 | + $ext = $squelette['extension']; |
|
| 69 | + |
|
| 70 | + $flux = [ |
|
| 71 | + 'args' => [ |
|
| 72 | + 'id_rubrique' => $id_rubrique, |
|
| 73 | + 'ext' => $ext, |
|
| 74 | + 'fond' => $fond, |
|
| 75 | + 'lang' => $lang, |
|
| 76 | + 'contexte' => $contexte, // le style d'un objet peut dependre de lui meme |
|
| 77 | + 'connect' => $connect |
|
| 78 | + ], |
|
| 79 | + 'data' => $squelette['fond'], |
|
| 80 | + ]; |
|
| 81 | + |
|
| 82 | + if (test_espace_prive() or defined('_ZPIP')) { |
|
| 83 | + if (!$styliser_par_z) { |
|
| 84 | + $styliser_par_z = charger_fonction('styliser_par_z', 'public'); |
|
| 85 | + } |
|
| 86 | + $flux = $styliser_par_z($flux); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $flux = styliser_par_objets($flux); |
|
| 90 | + |
|
| 91 | + // pipeline styliser |
|
| 92 | + $squelette = pipeline('styliser', $flux); |
|
| 93 | + |
|
| 94 | + return [$squelette, $ext, $ext, "$squelette.$ext"]; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -110,32 +110,32 @@ discard block |
||
| 110 | 110 | * Données du pipeline styliser |
| 111 | 111 | **/ |
| 112 | 112 | function styliser_par_objets($flux) { |
| 113 | - if ( |
|
| 114 | - test_espace_prive() |
|
| 115 | - and !$squelette = $flux['data'] |
|
| 116 | - and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | - and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | - ) { |
|
| 119 | - if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | - $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | - $table_sql = table_objet_sql($table); |
|
| 122 | - $objets = lister_tables_objets_sql(); |
|
| 123 | - if (isset($objets[$table_sql])) { |
|
| 124 | - $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | - } |
|
| 126 | - } |
|
| 127 | - if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | - $type = substr($flux['args']['fond'], 21); |
|
| 129 | - $table = table_objet($type); |
|
| 130 | - $table_sql = table_objet_sql($table); |
|
| 131 | - $objets = lister_tables_objets_sql(); |
|
| 132 | - if (isset($objets[$table_sql])) { |
|
| 133 | - $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return $flux; |
|
| 113 | + if ( |
|
| 114 | + test_espace_prive() |
|
| 115 | + and !$squelette = $flux['data'] |
|
| 116 | + and strncmp($flux['args']['fond'], 'prive/objets/', 13) == 0 |
|
| 117 | + and $echafauder = charger_fonction('echafauder', 'prive', true) |
|
| 118 | + ) { |
|
| 119 | + if (strncmp($flux['args']['fond'], 'prive/objets/liste/', 19) == 0) { |
|
| 120 | + $table = table_objet(substr($flux['args']['fond'], 19)); |
|
| 121 | + $table_sql = table_objet_sql($table); |
|
| 122 | + $objets = lister_tables_objets_sql(); |
|
| 123 | + if (isset($objets[$table_sql])) { |
|
| 124 | + $flux['data'] = $echafauder($table, $table, $table_sql, 'prive/objets/liste/objets', $flux['args']['ext']); |
|
| 125 | + } |
|
| 126 | + } |
|
| 127 | + if (strncmp($flux['args']['fond'], 'prive/objets/contenu/', 21) == 0) { |
|
| 128 | + $type = substr($flux['args']['fond'], 21); |
|
| 129 | + $table = table_objet($type); |
|
| 130 | + $table_sql = table_objet_sql($table); |
|
| 131 | + $objets = lister_tables_objets_sql(); |
|
| 132 | + if (isset($objets[$table_sql])) { |
|
| 133 | + $flux['data'] = $echafauder($type, $table, $table_sql, 'prive/objets/contenu/objet', $flux['args']['ext']); |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return $flux; |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -151,50 +151,50 @@ discard block |
||
| 151 | 151 | * @return array |
| 152 | 152 | */ |
| 153 | 153 | function quete_rubrique_fond($contexte) { |
| 154 | - static $liste_objets = null; |
|
| 155 | - static $quete = []; |
|
| 156 | - if (is_null($liste_objets)) { |
|
| 157 | - $liste_objets = []; |
|
| 158 | - include_spip('inc/urls'); |
|
| 159 | - include_spip('public/quete'); |
|
| 160 | - $l = urls_liste_objets(false); |
|
| 161 | - // placer la rubrique en tete des objets |
|
| 162 | - $l = array_diff($l, ['rubrique']); |
|
| 163 | - array_unshift($l, 'rubrique'); |
|
| 164 | - foreach ($l as $objet) { |
|
| 165 | - $id = id_table_objet($objet); |
|
| 166 | - if (!isset($liste_objets[$id])) { |
|
| 167 | - $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | - if (!count($c)) { |
|
| 173 | - return false; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - $c = array_map('intval', $c); |
|
| 177 | - $s = serialize($c); |
|
| 178 | - if (isset($quete[$s])) { |
|
| 179 | - return $quete[$s]; |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | - unset($c['id_rubrique']); |
|
| 184 | - $c = ['id_rubrique' => $r] + $c; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - foreach ($c as $_id => $id) { |
|
| 188 | - if ( |
|
| 189 | - $id |
|
| 190 | - and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | - ) { |
|
| 192 | - $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | - if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | - return $quete[$s] = [$id, $lang]; |
|
| 195 | - } |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $quete[$s] = false; |
|
| 154 | + static $liste_objets = null; |
|
| 155 | + static $quete = []; |
|
| 156 | + if (is_null($liste_objets)) { |
|
| 157 | + $liste_objets = []; |
|
| 158 | + include_spip('inc/urls'); |
|
| 159 | + include_spip('public/quete'); |
|
| 160 | + $l = urls_liste_objets(false); |
|
| 161 | + // placer la rubrique en tete des objets |
|
| 162 | + $l = array_diff($l, ['rubrique']); |
|
| 163 | + array_unshift($l, 'rubrique'); |
|
| 164 | + foreach ($l as $objet) { |
|
| 165 | + $id = id_table_objet($objet); |
|
| 166 | + if (!isset($liste_objets[$id])) { |
|
| 167 | + $liste_objets[$id] = objet_type($objet, false); |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + $c = array_intersect_key($contexte, $liste_objets); |
|
| 172 | + if (!count($c)) { |
|
| 173 | + return false; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + $c = array_map('intval', $c); |
|
| 177 | + $s = serialize($c); |
|
| 178 | + if (isset($quete[$s])) { |
|
| 179 | + return $quete[$s]; |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + if (isset($c['id_rubrique']) and $r = $c['id_rubrique']) { |
|
| 183 | + unset($c['id_rubrique']); |
|
| 184 | + $c = ['id_rubrique' => $r] + $c; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + foreach ($c as $_id => $id) { |
|
| 188 | + if ( |
|
| 189 | + $id |
|
| 190 | + and $row = quete_parent_lang(table_objet_sql($liste_objets[$_id]), $id) |
|
| 191 | + ) { |
|
| 192 | + $lang = isset($row['lang']) ? $row['lang'] : ''; |
|
| 193 | + if ($_id == 'id_rubrique' or (isset($row['id_rubrique']) and $id = $row['id_rubrique'])) { |
|
| 194 | + return $quete[$s] = [$id, $lang]; |
|
| 195 | + } |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $quete[$s] = false; |
|
| 200 | 200 | } |
@@ -19,10 +19,10 @@ |
||
| 19 | 19 | * @package SPIP\Core\SQL\Upgrade |
| 20 | 20 | **/ |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021021800] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 28 | 28 | ]; |
@@ -23,6 +23,6 @@ |
||
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][2021021800] = [ |
| 26 | - ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL" ], |
|
| 27 | - ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL" ], |
|
| 26 | + ['sql_alter', "TABLE spip_auteurs CHANGE imessage imessage VARCHAR(3) DEFAULT '' NOT NULL"], |
|
| 27 | + ['sql_updateq', 'spip_auteurs', ['imessage' => 'oui'], "imessage != 'non' OR imessage IS NULL"], |
|
| 28 | 28 | ]; |
@@ -18,12 +18,12 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][21676] = [ |
| 26 | - ['ranger_cache_gd2'], |
|
| 26 | + ['ranger_cache_gd2'], |
|
| 27 | 27 | ]; |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -32,30 +32,30 @@ discard block |
||
| 32 | 32 | * https://core.spip.net/issues/3277 |
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | - spip_log('ranger_cache_gd2'); |
|
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | - if (is_dir($base) and is_readable($base)) { |
|
| 38 | - if ($dir = opendir($base)) { |
|
| 39 | - while (($f = readdir($dir)) !== false) { |
|
| 40 | - if ( |
|
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | - and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | - ) { |
|
| 44 | - $sub = substr($f, 0, 2); |
|
| 45 | - $sub = sous_repertoire($base, $sub); |
|
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | - } |
|
| 49 | - if (time() >= _TIME_OUT) { |
|
| 50 | - return; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 35 | + spip_log('ranger_cache_gd2'); |
|
| 36 | + $base = _DIR_VAR . 'cache-gd2/'; |
|
| 37 | + if (is_dir($base) and is_readable($base)) { |
|
| 38 | + if ($dir = opendir($base)) { |
|
| 39 | + while (($f = readdir($dir)) !== false) { |
|
| 40 | + if ( |
|
| 41 | + !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | + and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
|
| 43 | + ) { |
|
| 44 | + $sub = substr($f, 0, 2); |
|
| 45 | + $sub = sous_repertoire($base, $sub); |
|
| 46 | + @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | + @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 48 | + } |
|
| 49 | + if (time() >= _TIME_OUT) { |
|
| 50 | + return; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | |
| 58 | 58 | $GLOBALS['maj'][21742] = [ |
| 59 | - ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | - ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 59 | + ['sql_alter', "TABLE spip_articles CHANGE url_site url_site text DEFAULT '' NOT NULL"], |
|
| 60 | + ['sql_alter', "TABLE spip_articles CHANGE virtuel virtuel text DEFAULT '' NOT NULL"], |
|
| 61 | 61 | ]; |
@@ -33,18 +33,18 @@ |
||
| 33 | 33 | */ |
| 34 | 34 | function ranger_cache_gd2() { |
| 35 | 35 | spip_log('ranger_cache_gd2'); |
| 36 | - $base = _DIR_VAR . 'cache-gd2/'; |
|
| 36 | + $base = _DIR_VAR.'cache-gd2/'; |
|
| 37 | 37 | if (is_dir($base) and is_readable($base)) { |
| 38 | 38 | if ($dir = opendir($base)) { |
| 39 | 39 | while (($f = readdir($dir)) !== false) { |
| 40 | 40 | if ( |
| 41 | - !is_dir($base . $f) and strncmp($f, '.', 1) !== 0 |
|
| 41 | + !is_dir($base.$f) and strncmp($f, '.', 1) !== 0 |
|
| 42 | 42 | and preg_match(',[0-9a-f]{32}\.\w+,', $f) |
| 43 | 43 | ) { |
| 44 | 44 | $sub = substr($f, 0, 2); |
| 45 | 45 | $sub = sous_repertoire($base, $sub); |
| 46 | - @rename($base . $f, $sub . substr($f, 2)); |
|
| 47 | - @unlink($base . $f); // au cas ou le rename a foire (collision) |
|
| 46 | + @rename($base.$f, $sub.substr($f, 2)); |
|
| 47 | + @unlink($base.$f); // au cas ou le rename a foire (collision) |
|
| 48 | 48 | } |
| 49 | 49 | if (time() >= _TIME_OUT) { |
| 50 | 50 | return; |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][16428] = [ |
| 26 | - ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | - ['maj_liens', 'auteur', 'article'], |
|
| 28 | - ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | - ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | - ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | - ['maj_liens', 'auteur', 'message'], |
|
| 32 | - ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 26 | + ['maj_liens', 'auteur'], // creer la table liens |
|
| 27 | + ['maj_liens', 'auteur', 'article'], |
|
| 28 | + ['sql_drop_table', 'spip_auteurs_articles'], |
|
| 29 | + ['maj_liens', 'auteur', 'rubrique'], |
|
| 30 | + ['sql_drop_table', 'spip_auteurs_rubriques'], |
|
| 31 | + ['maj_liens', 'auteur', 'message'], |
|
| 32 | + ['sql_drop_table', 'spip_auteurs_messages'], |
|
| 33 | 33 | ]; |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -55,89 +55,89 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | function maj_liens($pivot, $l = '') { |
| 57 | 57 | |
| 58 | - @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | - |
|
| 60 | - $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | - |
|
| 62 | - $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | - $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 66 | - // Creer spip_auteurs_liens |
|
| 67 | - global $tables_auxiliaires; |
|
| 68 | - if (!$l) { |
|
| 69 | - include_spip('base/auxiliaires'); |
|
| 70 | - include_spip('base/create'); |
|
| 71 | - creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | - } else { |
|
| 73 | - // Preparer |
|
| 74 | - $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | - $primary = "id_$l"; |
|
| 76 | - $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | - $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | - $pool = 400; |
|
| 80 | - |
|
| 81 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | - if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | - return; |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - // securite pour ne pas perdre de donnees |
|
| 87 | - if (!$trouver_table($liens)) { |
|
| 88 | - return; |
|
| 89 | - } |
|
| 90 | - |
|
| 91 | - $champs = $desc['field']; |
|
| 92 | - if (isset($champs['maj'])) { |
|
| 93 | - unset($champs['maj']); |
|
| 94 | - } |
|
| 95 | - if (isset($champs[$primary])) { |
|
| 96 | - unset($champs[$primary]); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $champs = array_keys($champs); |
|
| 100 | - // ne garder que les champs qui existent sur la table destination |
|
| 101 | - if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | - $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - $champs[] = "$primary as id_objet"; |
|
| 106 | - $champs[] = "'$objet' as objet"; |
|
| 107 | - $champs = implode(', ', $champs); |
|
| 108 | - |
|
| 109 | - // Recopier les donnees |
|
| 110 | - $sub_pool = 100; |
|
| 111 | - while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | - $insert = []; |
|
| 113 | - foreach ($ids as $id) { |
|
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | - $n += count($t); |
|
| 117 | - // empiler en s'assurant a minima de l'unicite |
|
| 118 | - while ($r = array_shift($t)) { |
|
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | - } |
|
| 121 | - if (count($insert) >= $sub_pool) { |
|
| 122 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | - $insert = []; |
|
| 124 | - } |
|
| 125 | - // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | - // et on verifiera/repartira de la |
|
| 127 | - if (time() >= _TIME_OUT) { |
|
| 128 | - return; |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - if (time() >= _TIME_OUT) { |
|
| 132 | - return; |
|
| 133 | - } |
|
| 134 | - } |
|
| 135 | - if (count($insert)) { |
|
| 136 | - maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | - } |
|
| 138 | - sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | - } |
|
| 140 | - } |
|
| 58 | + @define('_LOG_FILTRE_GRAVITE', 8); |
|
| 59 | + |
|
| 60 | + $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
|
| 61 | + |
|
| 62 | + $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
|
| 63 | + $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | + $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | + $id_pivot = 'id_' . $pivot; |
|
| 66 | + // Creer spip_auteurs_liens |
|
| 67 | + global $tables_auxiliaires; |
|
| 68 | + if (!$l) { |
|
| 69 | + include_spip('base/auxiliaires'); |
|
| 70 | + include_spip('base/create'); |
|
| 71 | + creer_ou_upgrader_table($liens, $tables_auxiliaires[$liens], false); |
|
| 72 | + } else { |
|
| 73 | + // Preparer |
|
| 74 | + $l = preg_replace(',[^\w],', '', $l); // securite |
|
| 75 | + $primary = "id_$l"; |
|
| 76 | + $objet = ($l == 'syndic' ? 'site' : $l); |
|
| 77 | + $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | + $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 79 | + $pool = 400; |
|
| 80 | + |
|
| 81 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 82 | + if (!$desc = $trouver_table($ancienne_table)) { |
|
| 83 | + return; |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + // securite pour ne pas perdre de donnees |
|
| 87 | + if (!$trouver_table($liens)) { |
|
| 88 | + return; |
|
| 89 | + } |
|
| 90 | + |
|
| 91 | + $champs = $desc['field']; |
|
| 92 | + if (isset($champs['maj'])) { |
|
| 93 | + unset($champs['maj']); |
|
| 94 | + } |
|
| 95 | + if (isset($champs[$primary])) { |
|
| 96 | + unset($champs[$primary]); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $champs = array_keys($champs); |
|
| 100 | + // ne garder que les champs qui existent sur la table destination |
|
| 101 | + if ($desc_cible = $trouver_table($liens)) { |
|
| 102 | + $champs = array_intersect($champs, array_keys($desc_cible['field'])); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + $champs[] = "$primary as id_objet"; |
|
| 106 | + $champs[] = "'$objet' as objet"; |
|
| 107 | + $champs = implode(', ', $champs); |
|
| 108 | + |
|
| 109 | + // Recopier les donnees |
|
| 110 | + $sub_pool = 100; |
|
| 111 | + while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
|
| 112 | + $insert = []; |
|
| 113 | + foreach ($ids as $id) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | + $n += count($t); |
|
| 117 | + // empiler en s'assurant a minima de l'unicite |
|
| 118 | + while ($r = array_shift($t)) { |
|
| 119 | + $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 120 | + } |
|
| 121 | + if (count($insert) >= $sub_pool) { |
|
| 122 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 123 | + $insert = []; |
|
| 124 | + } |
|
| 125 | + // si timeout, sortir, la relance nous ramenera dans cette fonction |
|
| 126 | + // et on verifiera/repartira de la |
|
| 127 | + if (time() >= _TIME_OUT) { |
|
| 128 | + return; |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + if (time() >= _TIME_OUT) { |
|
| 132 | + return; |
|
| 133 | + } |
|
| 134 | + } |
|
| 135 | + if (count($insert)) { |
|
| 136 | + maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
|
| 137 | + } |
|
| 138 | + sql_delete($ancienne_table, sql_in($primary, $ids)); |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -151,86 +151,86 @@ discard block |
||
| 151 | 151 | * @return void |
| 152 | 152 | **/ |
| 153 | 153 | function maj_liens_insertq_multi_check($table, $couples, $desc = []) { |
| 154 | - $n_before = sql_countsel($table); |
|
| 155 | - sql_insertq_multi($table, $couples, $desc); |
|
| 156 | - $n_after = sql_countsel($table); |
|
| 157 | - if (($n_after - $n_before) == count($couples)) { |
|
| 158 | - return; |
|
| 159 | - } |
|
| 160 | - // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | - // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | - foreach ($couples as $c) { |
|
| 163 | - sql_insertq($table, $c, $desc); |
|
| 164 | - } |
|
| 154 | + $n_before = sql_countsel($table); |
|
| 155 | + sql_insertq_multi($table, $couples, $desc); |
|
| 156 | + $n_after = sql_countsel($table); |
|
| 157 | + if (($n_after - $n_before) == count($couples)) { |
|
| 158 | + return; |
|
| 159 | + } |
|
| 160 | + // si ecart, on recommence l'insertion ligne par ligne... |
|
| 161 | + // moins rapide mais secure : seul le couple en doublon echouera, et non toute la serie |
|
| 162 | + foreach ($couples as $c) { |
|
| 163 | + sql_insertq($table, $c, $desc); |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | $GLOBALS['maj'][17311] = [ |
| 168 | - [ |
|
| 169 | - 'ecrire_meta', |
|
| 170 | - 'multi_objets', |
|
| 171 | - implode( |
|
| 172 | - ',', |
|
| 173 | - array_diff( |
|
| 174 | - [ |
|
| 175 | - (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | - ? 'spip_rubriques' : '', |
|
| 177 | - (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | - ? 'spip_articles' : '' |
|
| 179 | - ], |
|
| 180 | - [''] |
|
| 181 | - ) |
|
| 182 | - ) |
|
| 183 | - ], |
|
| 184 | - [ |
|
| 185 | - 'ecrire_meta', |
|
| 186 | - 'gerer_trad_objets', |
|
| 187 | - implode( |
|
| 188 | - ',', |
|
| 189 | - array_diff( |
|
| 190 | - [ |
|
| 191 | - (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | - ? 'spip_articles' : '' |
|
| 193 | - ], |
|
| 194 | - [''] |
|
| 195 | - ) |
|
| 196 | - ) |
|
| 197 | - ], |
|
| 168 | + [ |
|
| 169 | + 'ecrire_meta', |
|
| 170 | + 'multi_objets', |
|
| 171 | + implode( |
|
| 172 | + ',', |
|
| 173 | + array_diff( |
|
| 174 | + [ |
|
| 175 | + (isset($GLOBALS['meta']['multi_rubriques']) and $GLOBALS['meta']['multi_rubriques'] == 'oui') |
|
| 176 | + ? 'spip_rubriques' : '', |
|
| 177 | + (isset($GLOBALS['meta']['multi_articles']) and $GLOBALS['meta']['multi_articles'] == 'oui') |
|
| 178 | + ? 'spip_articles' : '' |
|
| 179 | + ], |
|
| 180 | + [''] |
|
| 181 | + ) |
|
| 182 | + ) |
|
| 183 | + ], |
|
| 184 | + [ |
|
| 185 | + 'ecrire_meta', |
|
| 186 | + 'gerer_trad_objets', |
|
| 187 | + implode( |
|
| 188 | + ',', |
|
| 189 | + array_diff( |
|
| 190 | + [ |
|
| 191 | + (isset($GLOBALS['meta']['gerer_trad']) and $GLOBALS['meta']['gerer_trad'] == 'oui') |
|
| 192 | + ? 'spip_articles' : '' |
|
| 193 | + ], |
|
| 194 | + [''] |
|
| 195 | + ) |
|
| 196 | + ) |
|
| 197 | + ], |
|
| 198 | 198 | ]; |
| 199 | 199 | $GLOBALS['maj'][17555] = [ |
| 200 | - ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | - ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 200 | + ['sql_alter', "TABLE spip_resultats ADD table_objet varchar(30) DEFAULT '' NOT NULL"], |
|
| 201 | + ['sql_alter', "TABLE spip_resultats ADD serveur char(16) DEFAULT '' NOT NULL"], |
|
| 202 | 202 | ]; |
| 203 | 203 | |
| 204 | 204 | $GLOBALS['maj'][17563] = [ |
| 205 | - ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | - ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 205 | + ['sql_alter', "TABLE spip_articles ADD virtuel VARCHAR(255) DEFAULT '' NOT NULL"], |
|
| 206 | + ['sql_update', 'spip_articles', ['virtuel' => 'SUBSTRING(chapo,2)', 'chapo' => "''"], "chapo LIKE '=_%'"], |
|
| 207 | 207 | ]; |
| 208 | 208 | |
| 209 | 209 | $GLOBALS['maj'][17577] = [ |
| 210 | - ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 210 | + ['maj_tables', ['spip_jobs', 'spip_jobs_liens']], |
|
| 211 | 211 | ]; |
| 212 | 212 | |
| 213 | 213 | $GLOBALS['maj'][17743] = [ |
| 214 | - ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 214 | + ['sql_update', 'spip_auteurs', ['prefs' => 'bio', 'bio' => "''"], "statut='nouveau' AND bio<>''"], |
|
| 215 | 215 | ]; |
| 216 | 216 | |
| 217 | 217 | $GLOBALS['maj'][18219] = [ |
| 218 | - ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | - ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 218 | + ['sql_alter', 'TABLE spip_rubriques DROP id_import'], |
|
| 219 | + ['sql_alter', 'TABLE spip_rubriques DROP export'], |
|
| 220 | 220 | ]; |
| 221 | 221 | |
| 222 | 222 | $GLOBALS['maj'][18310] = [ |
| 223 | - ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 223 | + ['sql_alter', "TABLE spip_auteurs_liens CHANGE vu vu VARCHAR(6) DEFAULT 'non' NOT NULL"], |
|
| 224 | 224 | ]; |
| 225 | 225 | |
| 226 | 226 | $GLOBALS['maj'][18597] = [ |
| 227 | - ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | - ['maj_propager_les_secteurs'], |
|
| 227 | + ['sql_alter', "TABLE spip_rubriques ADD profondeur smallint(5) DEFAULT '0' NOT NULL"], |
|
| 228 | + ['maj_propager_les_secteurs'], |
|
| 229 | 229 | ]; |
| 230 | 230 | |
| 231 | 231 | $GLOBALS['maj'][18955] = [ |
| 232 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | - ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 232 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX id_objet (id_objet)'], |
|
| 233 | + ['sql_alter', 'TABLE spip_auteurs_liens ADD INDEX objet (objet)'], |
|
| 234 | 234 | ]; |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -239,8 +239,8 @@ discard block |
||
| 239 | 239 | * @uses propager_les_secteurs() |
| 240 | 240 | **/ |
| 241 | 241 | function maj_propager_les_secteurs() { |
| 242 | - include_spip('inc/rubriques'); |
|
| 243 | - propager_les_secteurs(); |
|
| 242 | + include_spip('inc/rubriques'); |
|
| 243 | + propager_les_secteurs(); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -253,87 +253,87 @@ discard block |
||
| 253 | 253 | function maj_collation_sqlite() { |
| 254 | 254 | |
| 255 | 255 | |
| 256 | - include_spip('base/dump'); |
|
| 257 | - $tables = base_lister_toutes_tables(); |
|
| 258 | - |
|
| 259 | - // rien a faire si base non sqlite |
|
| 260 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | - return; |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | - // forcer le vidage de cache |
|
| 266 | - $trouver_table(''); |
|
| 267 | - |
|
| 268 | - // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | - $desc = $trouver_table('spip_auteurs'); |
|
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | - if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | - spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | - sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | - $trouver_table(''); |
|
| 275 | - $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - foreach ($tables as $table) { |
|
| 280 | - if (time() >= _TIME_OUT) { |
|
| 281 | - return; |
|
| 282 | - } |
|
| 283 | - if ($desc = $trouver_table($table)) { |
|
| 284 | - $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | - if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | - spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | - |
|
| 288 | - // cas particulier spip_urls : |
|
| 289 | - // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | - if ($table == 'spip_urls') { |
|
| 291 | - // par date DESC pour conserver les urls les plus recentes |
|
| 292 | - $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | - $urls = []; |
|
| 294 | - foreach ($data as $d) { |
|
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | - if (!isset($urls[$key])) { |
|
| 297 | - $urls[$key] = true; |
|
| 298 | - } else { |
|
| 299 | - spip_log( |
|
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | - ); |
|
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | - } |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - foreach ($desc['field'] as $field => $type) { |
|
| 308 | - if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | - $trouver_table(''); |
|
| 312 | - $new_desc = $trouver_table($table); |
|
| 313 | - spip_log( |
|
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | - ); |
|
| 317 | - continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - } |
|
| 323 | - |
|
| 324 | - // forcer le vidage de cache |
|
| 325 | - $trouver_table(''); |
|
| 256 | + include_spip('base/dump'); |
|
| 257 | + $tables = base_lister_toutes_tables(); |
|
| 258 | + |
|
| 259 | + // rien a faire si base non sqlite |
|
| 260 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'sqlite', 6) !== 0) { |
|
| 261 | + return; |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 265 | + // forcer le vidage de cache |
|
| 266 | + $trouver_table(''); |
|
| 267 | + |
|
| 268 | + // cas particulier spip_auteurs : retablir le collate binary sur le login |
|
| 269 | + $desc = $trouver_table('spip_auteurs'); |
|
| 270 | + spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 271 | + if (stripos($desc['field']['login'], 'BINARY') === false) { |
|
| 272 | + spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
|
| 273 | + sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
|
| 274 | + $trouver_table(''); |
|
| 275 | + $new_desc = $trouver_table('spip_auteurs'); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + foreach ($tables as $table) { |
|
| 280 | + if (time() >= _TIME_OUT) { |
|
| 281 | + return; |
|
| 282 | + } |
|
| 283 | + if ($desc = $trouver_table($table)) { |
|
| 284 | + $desc_collate = _sqlite_remplacements_definitions_table($desc['field']); |
|
| 285 | + if ($d = array_diff($desc['field'], $desc_collate)) { |
|
| 286 | + spip_log("Table $table COLLATE incorrects", 'maj'); |
|
| 287 | + |
|
| 288 | + // cas particulier spip_urls : |
|
| 289 | + // supprimer les doublons avant conversion sinon echec (on garde les urls les plus recentes) |
|
| 290 | + if ($table == 'spip_urls') { |
|
| 291 | + // par date DESC pour conserver les urls les plus recentes |
|
| 292 | + $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
|
| 293 | + $urls = []; |
|
| 294 | + foreach ($data as $d) { |
|
| 295 | + $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 296 | + if (!isset($urls[$key])) { |
|
| 297 | + $urls[$key] = true; |
|
| 298 | + } else { |
|
| 299 | + spip_log( |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 302 | + ); |
|
| 303 | + sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + foreach ($desc['field'] as $field => $type) { |
|
| 308 | + if ($desc['field'][$field] !== $desc_collate[$field]) { |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 311 | + $trouver_table(''); |
|
| 312 | + $new_desc = $trouver_table($table); |
|
| 313 | + spip_log( |
|
| 314 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 316 | + ); |
|
| 317 | + continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + } |
|
| 323 | + |
|
| 324 | + // forcer le vidage de cache |
|
| 325 | + $trouver_table(''); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | - ['maj_collation_sqlite'], |
|
| 330 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | + ['maj_collation_sqlite'], |
|
| 333 | 333 | ]; |
| 334 | 334 | |
| 335 | 335 | $GLOBALS['maj'][19268] = [ |
| 336 | - ['supprimer_toutes_sessions'], |
|
| 336 | + ['supprimer_toutes_sessions'], |
|
| 337 | 337 | ]; |
| 338 | 338 | |
| 339 | 339 | /** |
@@ -342,13 +342,13 @@ discard block |
||
| 342 | 342 | * Obligera tous les auteurs à se reconnecter ! |
| 343 | 343 | **/ |
| 344 | 344 | function supprimer_toutes_sessions() { |
| 345 | - spip_log('supprimer sessions auteur'); |
|
| 346 | - if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | - while (($f = readdir($dir)) !== false) { |
|
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | - if (time() >= _TIME_OUT) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - } |
|
| 353 | - } |
|
| 345 | + spip_log('supprimer sessions auteur'); |
|
| 346 | + if ($dir = opendir(_DIR_SESSIONS)) { |
|
| 347 | + while (($f = readdir($dir)) !== false) { |
|
| 348 | + spip_unlink(_DIR_SESSIONS . $f); |
|
| 349 | + if (time() >= _TIME_OUT) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | 354 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | $exceptions_pluriel = ['forum' => 'forum', 'syndic' => 'syndic']; |
| 61 | 61 | |
| 62 | 62 | $pivot = preg_replace(',[^\w],', '', $pivot); // securite |
| 63 | - $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot . 's'); |
|
| 64 | - $liens = 'spip_' . $pivots . '_liens'; |
|
| 65 | - $id_pivot = 'id_' . $pivot; |
|
| 63 | + $pivots = (isset($exceptions_pluriel[$pivot]) ? $exceptions_pluriel[$pivot] : $pivot.'s'); |
|
| 64 | + $liens = 'spip_'.$pivots.'_liens'; |
|
| 65 | + $id_pivot = 'id_'.$pivot; |
|
| 66 | 66 | // Creer spip_auteurs_liens |
| 67 | 67 | global $tables_auxiliaires; |
| 68 | 68 | if (!$l) { |
@@ -74,8 +74,8 @@ discard block |
||
| 74 | 74 | $l = preg_replace(',[^\w],', '', $l); // securite |
| 75 | 75 | $primary = "id_$l"; |
| 76 | 76 | $objet = ($l == 'syndic' ? 'site' : $l); |
| 77 | - $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l . 's'); |
|
| 78 | - $ancienne_table = 'spip_' . $pivots . '_' . $ls; |
|
| 77 | + $ls = (isset($exceptions_pluriel[$l]) ? $exceptions_pluriel[$l] : $l.'s'); |
|
| 78 | + $ancienne_table = 'spip_'.$pivots.'_'.$ls; |
|
| 79 | 79 | $pool = 400; |
| 80 | 80 | |
| 81 | 81 | $trouver_table = charger_fonction('trouver_table', 'base'); |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | while ($ids = array_map('reset', sql_allfetsel("$primary", $ancienne_table, '', '', '', "0,$sub_pool"))) { |
| 112 | 112 | $insert = []; |
| 113 | 113 | foreach ($ids as $id) { |
| 114 | - $n = sql_countsel($liens, "objet='$objet' AND id_objet=" . intval($id)); |
|
| 115 | - while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=" . intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 114 | + $n = sql_countsel($liens, "objet='$objet' AND id_objet=".intval($id)); |
|
| 115 | + while ($t = sql_allfetsel($champs, $ancienne_table, "$primary=".intval($id), '', $id_pivot, "$n,$pool")) { |
|
| 116 | 116 | $n += count($t); |
| 117 | 117 | // empiler en s'assurant a minima de l'unicite |
| 118 | 118 | while ($r = array_shift($t)) { |
| 119 | - $insert[$r[$id_pivot] . ':' . $r['id_objet']] = $r; |
|
| 119 | + $insert[$r[$id_pivot].':'.$r['id_objet']] = $r; |
|
| 120 | 120 | } |
| 121 | 121 | if (count($insert) >= $sub_pool) { |
| 122 | 122 | maj_liens_insertq_multi_check($liens, $insert, $tables_auxiliaires[$liens]); |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // cas particulier spip_auteurs : retablir le collate binary sur le login |
| 269 | 269 | $desc = $trouver_table('spip_auteurs'); |
| 270 | - spip_log('spip_auteurs : ' . var_export($desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 270 | + spip_log('spip_auteurs : '.var_export($desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 271 | 271 | if (stripos($desc['field']['login'], 'BINARY') === false) { |
| 272 | 272 | spip_log('Retablir champ login BINARY sur table spip_auteurs', 'maj'); |
| 273 | 273 | sql_alter('table spip_auteurs change login login VARCHAR(255) BINARY'); |
| 274 | 274 | $trouver_table(''); |
| 275 | 275 | $new_desc = $trouver_table('spip_auteurs'); |
| 276 | - spip_log('Apres conversion spip_auteurs : ' . var_export($new_desc['field'], true), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 276 | + spip_log('Apres conversion spip_auteurs : '.var_export($new_desc['field'], true), 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | foreach ($tables as $table) { |
@@ -292,27 +292,27 @@ discard block |
||
| 292 | 292 | $data = sql_allfetsel('*', 'spip_urls', '', '', 'date DESC'); |
| 293 | 293 | $urls = []; |
| 294 | 294 | foreach ($data as $d) { |
| 295 | - $key = $d['id_parent'] . '::' . strtolower($d['url']); |
|
| 295 | + $key = $d['id_parent'].'::'.strtolower($d['url']); |
|
| 296 | 296 | if (!isset($urls[$key])) { |
| 297 | 297 | $urls[$key] = true; |
| 298 | 298 | } else { |
| 299 | 299 | spip_log( |
| 300 | - 'Suppression doublon dans spip_urls avant conversion : ' . serialize($d), |
|
| 301 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 300 | + 'Suppression doublon dans spip_urls avant conversion : '.serialize($d), |
|
| 301 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 302 | 302 | ); |
| 303 | - sql_delete('spip_urls', 'id_parent=' . sql_quote($d['id_parent']) . ' AND url=' . sql_quote($d['url'])); |
|
| 303 | + sql_delete('spip_urls', 'id_parent='.sql_quote($d['id_parent']).' AND url='.sql_quote($d['url'])); |
|
| 304 | 304 | } |
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | foreach ($desc['field'] as $field => $type) { |
| 308 | 308 | if ($desc['field'][$field] !== $desc_collate[$field]) { |
| 309 | - spip_log("Conversion COLLATE table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 310 | - sql_alter("table $table change $field $field " . $desc_collate[$field]); |
|
| 309 | + spip_log("Conversion COLLATE table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 310 | + sql_alter("table $table change $field $field ".$desc_collate[$field]); |
|
| 311 | 311 | $trouver_table(''); |
| 312 | 312 | $new_desc = $trouver_table($table); |
| 313 | 313 | spip_log( |
| 314 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 315 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 314 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 315 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 316 | 316 | ); |
| 317 | 317 | continue 2; // inutile de continuer pour cette table : un seul alter remet tout a jour en sqlite |
| 318 | 318 | } |
@@ -328,7 +328,7 @@ discard block |
||
| 328 | 328 | |
| 329 | 329 | $GLOBALS['maj'][19236] = [ |
| 330 | 330 | ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom='version_installee'"], // version base principale |
| 331 | - ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 331 | + ['sql_updateq', 'spip_meta', ['impt' => 'oui'], "nom LIKE '%_base_version'"], // version base plugins |
|
| 332 | 332 | ['maj_collation_sqlite'], |
| 333 | 333 | ]; |
| 334 | 334 | |
@@ -345,7 +345,7 @@ discard block |
||
| 345 | 345 | spip_log('supprimer sessions auteur'); |
| 346 | 346 | if ($dir = opendir(_DIR_SESSIONS)) { |
| 347 | 347 | while (($f = readdir($dir)) !== false) { |
| 348 | - spip_unlink(_DIR_SESSIONS . $f); |
|
| 348 | + spip_unlink(_DIR_SESSIONS.$f); |
|
| 349 | 349 | if (time() >= _TIME_OUT) { |
| 350 | 350 | return; |
| 351 | 351 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | include_spip('base/medias'); |
@@ -27,27 +27,27 @@ discard block |
||
| 27 | 27 | |
| 28 | 28 | // http://archives.rezo.net/archives/spip-zone.mbox/C6RZKNBUNJYN42IOEOC4QKVCA233AMLI/ |
| 29 | 29 | $GLOBALS['maj'][13833] = [ |
| 30 | - ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 30 | + ['sql_alter', 'TABLE spip_documents_liens ADD INDEX objet(id_objet,objet)'] |
|
| 31 | 31 | ]; |
| 32 | 32 | |
| 33 | 33 | // 2.1 |
| 34 | 34 | |
| 35 | 35 | $GLOBALS['maj'][13904] = [ |
| 36 | - ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | - [ |
|
| 38 | - 'sql_update', |
|
| 39 | - 'spip_auteurs', |
|
| 40 | - ['webmestre' => "'oui'"], |
|
| 41 | - sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | - ':', |
|
| 43 | - _ID_WEBMESTRES |
|
| 44 | - ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | - ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 36 | + ['sql_alter', "TABLE spip_auteurs ADD webmestre varchar(3) DEFAULT 'non' NOT NULL"], |
|
| 37 | + [ |
|
| 38 | + 'sql_update', |
|
| 39 | + 'spip_auteurs', |
|
| 40 | + ['webmestre' => "'oui'"], |
|
| 41 | + sql_in('id_auteur', defined('_ID_WEBMESTRES') ? explode( |
|
| 42 | + ':', |
|
| 43 | + _ID_WEBMESTRES |
|
| 44 | + ) : (autoriser('configurer') ? [$GLOBALS['visiteur_session']['id_auteur']] : [0])) |
|
| 45 | + ] // le webmestre est celui qui fait l'upgrade si rien de defini |
|
| 46 | 46 | ]; |
| 47 | 47 | |
| 48 | 48 | // sites plantes en mode "'su" au lieu de "sus" |
| 49 | 49 | $GLOBALS['maj'][13929] = [ |
| 50 | - ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 50 | + ['sql_update', 'spip_syndic', ['syndication' => "'sus'"], "syndication LIKE '\\'%'"] |
|
| 51 | 51 | ]; |
| 52 | 52 | |
| 53 | 53 | // Types de fichiers m4a/m4b/m4p/m4u/m4v/dv |
@@ -61,24 +61,24 @@ discard block |
||
| 61 | 61 | // La version 14588 etait une mauvaise piste: |
| 62 | 62 | // Retour en arriere pour ceux qui l'ont subi, ne rien faire sinon |
| 63 | 63 | if (@$GLOBALS['meta']['version_installee'] >= 14588) { |
| 64 | - // "mode" est un mot-cle d'Oracle |
|
| 65 | - $GLOBALS['maj'][14588] = [ |
|
| 66 | - ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | - [ |
|
| 68 | - 'sql_alter', |
|
| 69 | - "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | - ], |
|
| 71 | - ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | - ]; |
|
| 73 | - // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | - $GLOBALS['maj'][14598] = [ |
|
| 75 | - ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | - [ |
|
| 77 | - 'sql_alter', |
|
| 78 | - "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | - ], |
|
| 80 | - ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | - ]; |
|
| 64 | + // "mode" est un mot-cle d'Oracle |
|
| 65 | + $GLOBALS['maj'][14588] = [ |
|
| 66 | + ['sql_alter', 'TABLE spip_documents DROP INDEX mode'], |
|
| 67 | + [ |
|
| 68 | + 'sql_alter', |
|
| 69 | + "TABLE spip_documents CHANGE mode genre ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 70 | + ], |
|
| 71 | + ['sql_alter', 'TABLE spip_documents ADD INDEX genre(genre)'] |
|
| 72 | + ]; |
|
| 73 | + // solution moins intrusive au pb de mot-cle d'Oracle, retour avant 14588 |
|
| 74 | + $GLOBALS['maj'][14598] = [ |
|
| 75 | + ['sql_alter', 'TABLE spip_documents DROP INDEX genre'], |
|
| 76 | + [ |
|
| 77 | + 'sql_alter', |
|
| 78 | + "TABLE spip_documents CHANGE genre mode ENUM('vignette', 'image', 'document') DEFAULT 'document' NOT NULL" |
|
| 79 | + ], |
|
| 80 | + ['sql_alter', 'TABLE spip_documents ADD INDEX mode(mode)'] |
|
| 81 | + ]; |
|
| 82 | 82 | } |
| 83 | 83 | |
| 84 | 84 | // Restauration correcte des types mime des fichiers Ogg |
@@ -18,10 +18,10 @@ |
||
| 18 | 18 | * @package SPIP\Core\SQL\Upgrade |
| 19 | 19 | **/ |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
| 25 | 25 | $GLOBALS['maj'][23375] = [ |
| 26 | - ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 26 | + ['sql_alter', 'TABLE spip_auteurs CHANGE prefs prefs text'], |
|
| 27 | 27 | ]; |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | * @package SPIP\Core\SQL\Upgrade |
| 21 | 21 | **/ |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | |
@@ -35,49 +35,49 @@ discard block |
||
| 35 | 35 | **/ |
| 36 | 36 | function maj_timestamp_mysql($tables = null) { |
| 37 | 37 | |
| 38 | - include_spip('base/dump'); |
|
| 39 | - if (is_null($tables)) { |
|
| 40 | - $tables = base_lister_toutes_tables(); |
|
| 41 | - } elseif (is_string($tables)) { |
|
| 42 | - $tables = [$tables]; |
|
| 43 | - } elseif (!is_array($tables)) { |
|
| 44 | - return; |
|
| 45 | - } |
|
| 38 | + include_spip('base/dump'); |
|
| 39 | + if (is_null($tables)) { |
|
| 40 | + $tables = base_lister_toutes_tables(); |
|
| 41 | + } elseif (is_string($tables)) { |
|
| 42 | + $tables = [$tables]; |
|
| 43 | + } elseif (!is_array($tables)) { |
|
| 44 | + return; |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - // rien a faire si base non mysql |
|
| 48 | - if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | - return; |
|
| 50 | - } |
|
| 47 | + // rien a faire si base non mysql |
|
| 48 | + if (strncmp($GLOBALS['connexions'][0]['type'], 'mysql', 5) !== 0) { |
|
| 49 | + return; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | - // forcer le vidage de cache |
|
| 54 | - $trouver_table(''); |
|
| 52 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 53 | + // forcer le vidage de cache |
|
| 54 | + $trouver_table(''); |
|
| 55 | 55 | |
| 56 | - foreach ($tables as $table) { |
|
| 57 | - if (time() >= _TIME_OUT) { |
|
| 58 | - return; |
|
| 59 | - } |
|
| 60 | - if ($desc = $trouver_table($table)) { |
|
| 61 | - $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | - $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | - if ($d) { |
|
| 64 | - spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | - foreach ($desc['field'] as $field => $type) { |
|
| 66 | - if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | - $trouver_table(''); |
|
| 70 | - $new_desc = $trouver_table($table); |
|
| 71 | - spip_log( |
|
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | - ); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - } |
|
| 79 | - } |
|
| 56 | + foreach ($tables as $table) { |
|
| 57 | + if (time() >= _TIME_OUT) { |
|
| 58 | + return; |
|
| 59 | + } |
|
| 60 | + if ($desc = $trouver_table($table)) { |
|
| 61 | + $fields_corrected = _mysql_remplacements_definitions_table($desc['field']); |
|
| 62 | + $d = array_diff($desc['field'], $fields_corrected); |
|
| 63 | + if ($d) { |
|
| 64 | + spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
|
| 65 | + foreach ($desc['field'] as $field => $type) { |
|
| 66 | + if ($desc['field'][$field] !== $fields_corrected[$field]) { |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 69 | + $trouver_table(''); |
|
| 70 | + $new_desc = $trouver_table($table); |
|
| 71 | + spip_log( |
|
| 72 | + "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 74 | + ); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - // forcer le vidage de cache |
|
| 82 | - $trouver_table(''); |
|
| 81 | + // forcer le vidage de cache |
|
| 82 | + $trouver_table(''); |
|
| 83 | 83 | } |
@@ -64,13 +64,13 @@ |
||
| 64 | 64 | spip_log("Table $table TIMESTAMP incorrect", 'maj'); |
| 65 | 65 | foreach ($desc['field'] as $field => $type) { |
| 66 | 66 | if ($desc['field'][$field] !== $fields_corrected[$field]) { |
| 67 | - spip_log("Adaptation TIMESTAMP table $table", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 68 | - sql_alter("table $table change $field $field " . $fields_corrected[$field]); |
|
| 67 | + spip_log("Adaptation TIMESTAMP table $table", 'maj.'._LOG_INFO_IMPORTANTE); |
|
| 68 | + sql_alter("table $table change $field $field ".$fields_corrected[$field]); |
|
| 69 | 69 | $trouver_table(''); |
| 70 | 70 | $new_desc = $trouver_table($table); |
| 71 | 71 | spip_log( |
| 72 | - "Apres conversion $table : " . var_export($new_desc['field'], true), |
|
| 73 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 72 | + "Apres conversion $table : ".var_export($new_desc['field'], true), |
|
| 73 | + 'maj.'._LOG_INFO_IMPORTANTE |
|
| 74 | 74 | ); |
| 75 | 75 | } |
| 76 | 76 | } |