@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | **/ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/texte'); |
@@ -42,229 +42,229 @@ discard block |
||
| 42 | 42 | |
| 43 | 43 | function public_composer_dist($squelette, $mime_type, $gram, $source, string $connect = '') { |
| 44 | 44 | |
| 45 | - $skel = null; |
|
| 46 | - $boucle = null; |
|
| 47 | - $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | - |
|
| 49 | - // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | - if (function_exists($nom)) { |
|
| 51 | - return $nom; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 55 | - $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | - |
|
| 60 | - // si squelette est deja compile et perenne, le charger |
|
| 61 | - if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | - include_once $phpfile; |
|
| 63 | - #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | - # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | - # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | - ## eval('?'.'>'.$skel_code); |
|
| 67 | - # spip_log($skel_code, 'comp') |
|
| 68 | - #} |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | - include_once $lib; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | - |
|
| 77 | - if (function_exists($nom)) { |
|
| 78 | - return $nom; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - // charger le source, si possible, et compiler |
|
| 82 | - $skel_code = ''; |
|
| 83 | - if (lire_fichier($source, $skel)) { |
|
| 84 | - $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | - $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | - } |
|
| 87 | - |
|
| 88 | - // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | - if (!$skel_code) { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - |
|
| 93 | - foreach ($skel_code as $id => $boucle) { |
|
| 94 | - $f = $boucle->return; |
|
| 95 | - try { |
|
| 96 | - eval("return true; $f ;"); |
|
| 97 | - } catch (\ParseError $e) { |
|
| 98 | - // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | - $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | - erreur_squelette($msg, $boucle); |
|
| 101 | - // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | - // mais prevenir que c'est mort |
|
| 103 | - $nom = ''; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - // contexte de compil inutile a present |
|
| 107 | - // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | - $skel_code[$id] = $f; |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - $code = ''; |
|
| 112 | - if ($nom) { |
|
| 113 | - // Si le code est bon, concatener et mettre en cache |
|
| 114 | - if (function_exists($nom)) { |
|
| 115 | - $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | - } else { |
|
| 117 | - // code semantiquement faux: bug du compilateur |
|
| 118 | - // $boucle est en fait ici la fct principale du squelette |
|
| 119 | - $msg = _T('zbug_erreur_compilation'); |
|
| 120 | - erreur_squelette($msg, $boucle); |
|
| 121 | - $nom = ''; |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 126 | - // Tracer ce qui vient d'etre compile |
|
| 127 | - $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | - |
|
| 129 | - // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | - if ( |
|
| 131 | - $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | - && _request('var_mode_objet') == $nom |
|
| 133 | - && _request('var_mode_affiche') == 'code' |
|
| 134 | - ) { |
|
| 135 | - erreur_squelette(); |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - return $nom ?: false; |
|
| 45 | + $skel = null; |
|
| 46 | + $boucle = null; |
|
| 47 | + $nom = calculer_nom_fonction_squel($squelette, $mime_type, $connect); |
|
| 48 | + |
|
| 49 | + // si deja en memoire (INCLURE a repetition) c'est bon. |
|
| 50 | + if (function_exists($nom)) { |
|
| 51 | + return $nom; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 55 | + $GLOBALS['debug_objets']['courant'] = $nom; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + $phpfile = sous_repertoire(_DIR_SKELS, '', false, true) . $nom . '.php'; |
|
| 59 | + |
|
| 60 | + // si squelette est deja compile et perenne, le charger |
|
| 61 | + if (!squelette_obsolete($phpfile, $source)) { |
|
| 62 | + include_once $phpfile; |
|
| 63 | + #if (!squelette_obsolete($phpfile, $source) |
|
| 64 | + # AND lire_fichier ($phpfile, $skel_code, |
|
| 65 | + # array('critique' => 'oui', 'phpcheck' => 'oui'))){ |
|
| 66 | + ## eval('?'.'>'.$skel_code); |
|
| 67 | + # spip_log($skel_code, 'comp') |
|
| 68 | + #} |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (file_exists($lib = $squelette . '_fonctions' . '.php')) { |
|
| 72 | + include_once $lib; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + // tester si le eval ci-dessus a mis le squelette en memoire |
|
| 76 | + |
|
| 77 | + if (function_exists($nom)) { |
|
| 78 | + return $nom; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + // charger le source, si possible, et compiler |
|
| 82 | + $skel_code = ''; |
|
| 83 | + if (lire_fichier($source, $skel)) { |
|
| 84 | + $compiler = charger_fonction('compiler', 'public'); |
|
| 85 | + $skel_code = $compiler($skel, $nom, $gram, $source, $connect); |
|
| 86 | + } |
|
| 87 | + |
|
| 88 | + // Ne plus rien faire si le compilateur n'a pas pu operer. |
|
| 89 | + if (!$skel_code) { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + |
|
| 93 | + foreach ($skel_code as $id => $boucle) { |
|
| 94 | + $f = $boucle->return; |
|
| 95 | + try { |
|
| 96 | + eval("return true; $f ;"); |
|
| 97 | + } catch (\ParseError $e) { |
|
| 98 | + // Code syntaxiquement faux (critere etc mal programme') |
|
| 99 | + $msg = _T('zbug_erreur_compilation') . ' | Line ' . $e->getLine() . ' : ' . $e->getMessage(); |
|
| 100 | + erreur_squelette($msg, $boucle); |
|
| 101 | + // continuer pour trouver d'autres fautes eventuelles |
|
| 102 | + // mais prevenir que c'est mort |
|
| 103 | + $nom = ''; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + // contexte de compil inutile a present |
|
| 107 | + // (mais la derniere valeur de $boucle est utilisee ci-dessous) |
|
| 108 | + $skel_code[$id] = $f; |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + $code = ''; |
|
| 112 | + if ($nom) { |
|
| 113 | + // Si le code est bon, concatener et mettre en cache |
|
| 114 | + if (function_exists($nom)) { |
|
| 115 | + $code = squelette_traduit($skel, $source, $phpfile, $skel_code); |
|
| 116 | + } else { |
|
| 117 | + // code semantiquement faux: bug du compilateur |
|
| 118 | + // $boucle est en fait ici la fct principale du squelette |
|
| 119 | + $msg = _T('zbug_erreur_compilation'); |
|
| 120 | + erreur_squelette($msg, $boucle); |
|
| 121 | + $nom = ''; |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + if (defined('_VAR_MODE') && _VAR_MODE == 'debug') { |
|
| 126 | + // Tracer ce qui vient d'etre compile |
|
| 127 | + $GLOBALS['debug_objets']['code'][$nom . 'tout'] = $code; |
|
| 128 | + |
|
| 129 | + // si c'est ce que demande le debusqueur, lui passer la main |
|
| 130 | + if ( |
|
| 131 | + $GLOBALS['debug_objets']['sourcefile'] |
|
| 132 | + && _request('var_mode_objet') == $nom |
|
| 133 | + && _request('var_mode_affiche') == 'code' |
|
| 134 | + ) { |
|
| 135 | + erreur_squelette(); |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + return $nom ?: false; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | function squelette_traduit($squelette, $sourcefile, $phpfile, $boucles) { |
| 143 | 143 | |
| 144 | - $code = null; |
|
| 145 | - // Le dernier index est '' (fonction principale) |
|
| 146 | - $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | - if (CODE_COMMENTE) { |
|
| 148 | - $code = " |
|
| 144 | + $code = null; |
|
| 145 | + // Le dernier index est '' (fonction principale) |
|
| 146 | + $noms = substr(join(', ', array_keys($boucles)), 0, -2); |
|
| 147 | + if (CODE_COMMENTE) { |
|
| 148 | + $code = " |
|
| 149 | 149 | /* |
| 150 | 150 | * Squelette : $sourcefile |
| 151 | 151 | * Date : " . gmdate('D, d M Y H:i:s', @filemtime($sourcefile)) . ' GMT |
| 152 | 152 | * Compile : ' . gmdate('D, d M Y H:i:s', time()) . ' GMT |
| 153 | 153 | * ' . (!$boucles ? 'Pas de boucle' : ('Boucles : ' . $noms)) . ' |
| 154 | 154 | */ '; |
| 155 | - } |
|
| 155 | + } |
|
| 156 | 156 | |
| 157 | - $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | - if (!defined('_VAR_NOCACHE') || !_VAR_NOCACHE) { |
|
| 159 | - ecrire_fichier($phpfile, $code); |
|
| 160 | - } |
|
| 157 | + $code = '<' . "?php\n" . $code . join('', $boucles) . "\n"; |
|
| 158 | + if (!defined('_VAR_NOCACHE') || !_VAR_NOCACHE) { |
|
| 159 | + ecrire_fichier($phpfile, $code); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - return $code; |
|
| 162 | + return $code; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Le squelette compile est-il trop vieux ? |
| 166 | 166 | function squelette_obsolete($skel, $squelette) { |
| 167 | - static $date_change = null; |
|
| 168 | - // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | - // par hit |
|
| 170 | - if (is_null($date_change)) { |
|
| 171 | - if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | - $date_change = @filemtime($fonc); |
|
| 173 | - } # compatibilite |
|
| 174 | - if (defined('_FILE_OPTIONS')) { |
|
| 175 | - $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | - } |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return ( |
|
| 180 | - defined('_VAR_MODE') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | - || !@file_exists($skel) |
|
| 182 | - || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | - || $date_change > $date |
|
| 184 | - ); |
|
| 167 | + static $date_change = null; |
|
| 168 | + // ne verifier la date de mes_fonctions et mes_options qu'une seule fois |
|
| 169 | + // par hit |
|
| 170 | + if (is_null($date_change)) { |
|
| 171 | + if (@file_exists($fonc = 'mes_fonctions.php')) { |
|
| 172 | + $date_change = @filemtime($fonc); |
|
| 173 | + } # compatibilite |
|
| 174 | + if (defined('_FILE_OPTIONS')) { |
|
| 175 | + $date_change = max($date_change, @filemtime(_FILE_OPTIONS)); |
|
| 176 | + } |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return ( |
|
| 180 | + defined('_VAR_MODE') && in_array(_VAR_MODE, ['recalcul', 'preview', 'debug']) |
|
| 181 | + || !@file_exists($skel) |
|
| 182 | + || (@file_exists($squelette) ? @filemtime($squelette) : 0) > ($date = @filemtime($skel)) |
|
| 183 | + || $date_change > $date |
|
| 184 | + ); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | // Activer l'invalideur de session |
| 188 | 188 | function invalideur_session(&$Cache, $code = null) { |
| 189 | - $Cache['session'] = spip_session(); |
|
| 189 | + $Cache['session'] = spip_session(); |
|
| 190 | 190 | |
| 191 | - return $code; |
|
| 191 | + return $code; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
| 195 | 195 | function analyse_resultat_skel($nom, $cache, $corps, $source = '') { |
| 196 | - static $filtres = []; |
|
| 197 | - $headers = []; |
|
| 198 | - $corps ??= ''; |
|
| 199 | - |
|
| 200 | - // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | - // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | - // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | - if ( |
|
| 204 | - stripos($corps, 'header') !== false |
|
| 205 | - && preg_match_all( |
|
| 206 | - '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | - $corps, |
|
| 208 | - $regs, |
|
| 209 | - PREG_SET_ORDER |
|
| 210 | - ) |
|
| 211 | - ) { |
|
| 212 | - foreach ($regs as $r) { |
|
| 213 | - $corps = str_replace($r[0], '', $corps); |
|
| 214 | - # $j = Content-Type, et pas content-TYPE. |
|
| 215 | - $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | - |
|
| 217 | - if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | - $headers[$j] .= '|' . $r[3]; |
|
| 219 | - } else { |
|
| 220 | - $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 223 | - } |
|
| 224 | - // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | - $process_ins = ( |
|
| 226 | - !str_contains($corps, '<' . '?') |
|
| 227 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | - ) |
|
| 229 | - ? 'html' |
|
| 230 | - : 'php'; |
|
| 231 | - |
|
| 232 | - $skel = [ |
|
| 233 | - 'squelette' => $nom, |
|
| 234 | - 'source' => $source, |
|
| 235 | - 'process_ins' => $process_ins, |
|
| 236 | - 'invalideurs' => $cache, |
|
| 237 | - 'entetes' => $headers, |
|
| 238 | - 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | - ]; |
|
| 240 | - |
|
| 241 | - // traiter #FILTRE{} et filtres |
|
| 242 | - if (!isset($filtres[$nom])) { |
|
| 243 | - $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | - } |
|
| 245 | - $filtres_headers = []; |
|
| 246 | - if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | - $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | - unset($headers['X-Spip-Filtre']); |
|
| 249 | - } |
|
| 250 | - if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | - include_spip('public/sandbox'); |
|
| 252 | - $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | - |
|
| 254 | - if ($process_ins == 'html') { |
|
| 255 | - $skel['process_ins'] = ( |
|
| 256 | - !str_contains($corps, '<' . '?') |
|
| 257 | - || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | - ) |
|
| 259 | - ? 'html' |
|
| 260 | - : 'php'; |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - $skel['entetes'] = $headers; |
|
| 265 | - $skel['texte'] = $corps; |
|
| 266 | - |
|
| 267 | - return $skel; |
|
| 196 | + static $filtres = []; |
|
| 197 | + $headers = []; |
|
| 198 | + $corps ??= ''; |
|
| 199 | + |
|
| 200 | + // Recupere les < ?php header('Xx: y'); ? > pour $page['headers'] |
|
| 201 | + // note: on essaie d'attrapper aussi certains de ces entetes codes |
|
| 202 | + // "a la main" dans les squelettes, mais evidemment sans exhaustivite |
|
| 203 | + if ( |
|
| 204 | + stripos($corps, 'header') !== false |
|
| 205 | + && preg_match_all( |
|
| 206 | + '/(<[?]php\s+)@?header\s*\(\s*.([^:\'"]*):?\s*([^)]*)[^)]\s*\)\s*[;]?\s*[?]>/ims', |
|
| 207 | + $corps, |
|
| 208 | + $regs, |
|
| 209 | + PREG_SET_ORDER |
|
| 210 | + ) |
|
| 211 | + ) { |
|
| 212 | + foreach ($regs as $r) { |
|
| 213 | + $corps = str_replace($r[0], '', $corps); |
|
| 214 | + # $j = Content-Type, et pas content-TYPE. |
|
| 215 | + $j = join('-', array_map('ucwords', explode('-', strtolower($r[2])))); |
|
| 216 | + |
|
| 217 | + if ($j == 'X-Spip-Filtre' && isset($headers[$j])) { |
|
| 218 | + $headers[$j] .= '|' . $r[3]; |
|
| 219 | + } else { |
|
| 220 | + $headers[$j] = str_replace(['\\\\',"\\'",'\\"'], ['\\',"'",'"'], $r[3]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | + } |
|
| 224 | + // S'agit-il d'un resultat constant ou contenant du code php |
|
| 225 | + $process_ins = ( |
|
| 226 | + !str_contains($corps, '<' . '?') |
|
| 227 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 228 | + ) |
|
| 229 | + ? 'html' |
|
| 230 | + : 'php'; |
|
| 231 | + |
|
| 232 | + $skel = [ |
|
| 233 | + 'squelette' => $nom, |
|
| 234 | + 'source' => $source, |
|
| 235 | + 'process_ins' => $process_ins, |
|
| 236 | + 'invalideurs' => $cache, |
|
| 237 | + 'entetes' => $headers, |
|
| 238 | + 'duree' => isset($headers['X-Spip-Cache']) ? intval($headers['X-Spip-Cache']) : 0 |
|
| 239 | + ]; |
|
| 240 | + |
|
| 241 | + // traiter #FILTRE{} et filtres |
|
| 242 | + if (!isset($filtres[$nom])) { |
|
| 243 | + $filtres[$nom] = pipeline('declarer_filtres_squelettes', ['args' => $skel, 'data' => []]); |
|
| 244 | + } |
|
| 245 | + $filtres_headers = []; |
|
| 246 | + if (isset($headers['X-Spip-Filtre']) && strlen($headers['X-Spip-Filtre'])) { |
|
| 247 | + $filtres_headers = array_filter(explode('|', $headers['X-Spip-Filtre'])); |
|
| 248 | + unset($headers['X-Spip-Filtre']); |
|
| 249 | + } |
|
| 250 | + if ((is_countable($filtres[$nom]) ? count($filtres[$nom]) : 0) || count($filtres_headers)) { |
|
| 251 | + include_spip('public/sandbox'); |
|
| 252 | + $corps = sandbox_filtrer_squelette($skel, $corps, $filtres_headers, $filtres[$nom]); |
|
| 253 | + |
|
| 254 | + if ($process_ins == 'html') { |
|
| 255 | + $skel['process_ins'] = ( |
|
| 256 | + !str_contains($corps, '<' . '?') |
|
| 257 | + || str_contains($corps, '<' . '?xml') && !str_contains(str_replace('<' . '?xml', '', $corps), '<' . '?') |
|
| 258 | + ) |
|
| 259 | + ? 'html' |
|
| 260 | + : 'php'; |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + $skel['entetes'] = $headers; |
|
| 265 | + $skel['texte'] = $corps; |
|
| 266 | + |
|
| 267 | + return $skel; |
|
| 268 | 268 | } |
| 269 | 269 | |
| 270 | 270 | // |
@@ -278,7 +278,7 @@ discard block |
||
| 278 | 278 | inserer_balise_dynamique(balise_%s_dyn(%s), array(%s)); |
| 279 | 279 | if ($lang_select) lang_select(); |
| 280 | 280 | ?' |
| 281 | - . '>'); |
|
| 281 | + . '>'); |
|
| 282 | 282 | |
| 283 | 283 | /** |
| 284 | 284 | * Synthétise une balise dynamique : crée l'appel à l'inclusion |
@@ -298,35 +298,35 @@ discard block |
||
| 298 | 298 | * Code PHP pour inclure le squelette de la balise dynamique |
| 299 | 299 | **/ |
| 300 | 300 | function synthetiser_balise_dynamique($nom, $args, $file, $context_compil) { |
| 301 | - if ( |
|
| 302 | - !str_starts_with($file, '/') |
|
| 303 | - // pas de lien symbolique sous Windows |
|
| 304 | - && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | - ) { |
|
| 306 | - $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - $lang = $context_compil[4]; |
|
| 310 | - if (preg_match(',\W,', $lang)) { |
|
| 311 | - $lang = ''; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $args = array_map('argumenter_squelette', $args); |
|
| 315 | - if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | - $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | - } |
|
| 318 | - $args = join(', ', $args); |
|
| 319 | - |
|
| 320 | - $r = sprintf( |
|
| 321 | - CODE_INCLURE_BALISE, |
|
| 322 | - $file, |
|
| 323 | - $lang, |
|
| 324 | - $nom, |
|
| 325 | - $args, |
|
| 326 | - join(', ', array_map('_q', $context_compil)) |
|
| 327 | - ); |
|
| 328 | - |
|
| 329 | - return $r; |
|
| 301 | + if ( |
|
| 302 | + !str_starts_with($file, '/') |
|
| 303 | + // pas de lien symbolique sous Windows |
|
| 304 | + && !(stristr(PHP_OS, 'WIN') && str_contains($file, ':')) |
|
| 305 | + ) { |
|
| 306 | + $file = './" . _DIR_RACINE . "' . $file; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + $lang = $context_compil[4]; |
|
| 310 | + if (preg_match(',\W,', $lang)) { |
|
| 311 | + $lang = ''; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $args = array_map('argumenter_squelette', $args); |
|
| 315 | + if (!empty($context_compil['appel_php_depuis_modele'])) { |
|
| 316 | + $args[0] = 'arguments_balise_dyn_depuis_modele(' . $args[0] . ')'; |
|
| 317 | + } |
|
| 318 | + $args = join(', ', $args); |
|
| 319 | + |
|
| 320 | + $r = sprintf( |
|
| 321 | + CODE_INCLURE_BALISE, |
|
| 322 | + $file, |
|
| 323 | + $lang, |
|
| 324 | + $nom, |
|
| 325 | + $args, |
|
| 326 | + join(', ', array_map('_q', $context_compil)) |
|
| 327 | + ); |
|
| 328 | + |
|
| 329 | + return $r; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | /** |
@@ -344,18 +344,18 @@ discard block |
||
| 344 | 344 | **/ |
| 345 | 345 | function argumenter_squelette($v) { |
| 346 | 346 | |
| 347 | - if (is_object($v)) { |
|
| 348 | - return var_export($v, true); |
|
| 349 | - } elseif (!is_array($v)) { |
|
| 350 | - return "'" . texte_script((string) $v) . "'"; |
|
| 351 | - } else { |
|
| 352 | - $out = []; |
|
| 353 | - foreach ($v as $k => $val) { |
|
| 354 | - $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - return 'array(' . join(', ', $out) . ')'; |
|
| 358 | - } |
|
| 347 | + if (is_object($v)) { |
|
| 348 | + return var_export($v, true); |
|
| 349 | + } elseif (!is_array($v)) { |
|
| 350 | + return "'" . texte_script((string) $v) . "'"; |
|
| 351 | + } else { |
|
| 352 | + $out = []; |
|
| 353 | + foreach ($v as $k => $val) { |
|
| 354 | + $out [] = argumenter_squelette($k) . '=>' . argumenter_squelette($val); |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + return 'array(' . join(', ', $out) . ')'; |
|
| 358 | + } |
|
| 359 | 359 | } |
| 360 | 360 | |
| 361 | 361 | /** |
@@ -374,13 +374,13 @@ discard block |
||
| 374 | 374 | * @return string |
| 375 | 375 | */ |
| 376 | 376 | function executer_balise_dynamique_dans_un_modele(...$args) { |
| 377 | - if (test_espace_prive()) { |
|
| 378 | - return executer_balise_dynamique(...$args); |
|
| 379 | - } |
|
| 380 | - else { |
|
| 381 | - $str_args = base64_encode(serialize($args)); |
|
| 382 | - return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | - } |
|
| 377 | + if (test_espace_prive()) { |
|
| 378 | + return executer_balise_dynamique(...$args); |
|
| 379 | + } |
|
| 380 | + else { |
|
| 381 | + $str_args = base64_encode(serialize($args)); |
|
| 382 | + return '<?' . "php \$_zargs=unserialize(base64_decode('$str_args'));echo executer_balise_dynamique(...\$_zargs); ?" . ">\n"; |
|
| 383 | + } |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | |
@@ -411,87 +411,87 @@ discard block |
||
| 411 | 411 | * Code PHP d'exécutant l'inclusion du squelette (ou texte) de la balise dynamique |
| 412 | 412 | **/ |
| 413 | 413 | function executer_balise_dynamique($nom, $args, $context_compil) { |
| 414 | - /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | - $nom_balise = $nom; |
|
| 416 | - /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | - $nom_balise_generique = ''; |
|
| 418 | - |
|
| 419 | - $appel_php_depuis_modele = false; |
|
| 420 | - if ( |
|
| 421 | - is_array($context_compil) |
|
| 422 | - && !is_numeric($context_compil[3]) |
|
| 423 | - && empty($context_compil[0]) |
|
| 424 | - && empty($context_compil[1]) |
|
| 425 | - && empty($context_compil[2]) |
|
| 426 | - && empty($context_compil[3]) |
|
| 427 | - ) { |
|
| 428 | - $appel_php_depuis_modele = true; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | - // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | - // injecter en premier arg le nom de la balise |
|
| 435 | - array_unshift($args, $nom); |
|
| 436 | - $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | - $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | - $nom_balise = $nom_balise_generique; |
|
| 439 | - } |
|
| 440 | - unset($balise_generique); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - if (!$fonction_balise) { |
|
| 444 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | - erreur_squelette($msg, $context_compil); |
|
| 446 | - |
|
| 447 | - return ''; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - // retrouver le fichier qui a déclaré la fonction |
|
| 451 | - // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | - // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | - $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | - $file = $reflector->getFileName(); |
|
| 455 | - if (str_starts_with($file, _ROOT_RACINE)) { |
|
| 456 | - $file = str_replace(\DIRECTORY_SEPARATOR, '/', substr($file, strlen(_ROOT_RACINE))); |
|
| 457 | - } |
|
| 458 | - |
|
| 459 | - // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | - $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | - |
|
| 462 | - $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | - |
|
| 464 | - if (!is_array($r)) { |
|
| 465 | - return $r; |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // verifier que la fonction dyn est la, |
|
| 469 | - // sinon se replier sur la generique si elle existe |
|
| 470 | - if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | - if ( |
|
| 472 | - ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | - && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | - && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | - && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | - ) { |
|
| 477 | - // et lui injecter en premier arg le nom de la balise |
|
| 478 | - array_unshift($r, $nom); |
|
| 479 | - $nom_balise = $nom_balise_generique; |
|
| 480 | - if (!_DIR_RESTREINT) { |
|
| 481 | - $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | - } |
|
| 483 | - } else { |
|
| 484 | - $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | - erreur_squelette($msg, $context_compil); |
|
| 486 | - |
|
| 487 | - return ''; |
|
| 488 | - } |
|
| 489 | - } |
|
| 490 | - |
|
| 491 | - if ($appel_php_depuis_modele) { |
|
| 492 | - $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | - } |
|
| 494 | - return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 414 | + /** @var string Nom de la balise à charger (balise demandée ou balise générique) */ |
|
| 415 | + $nom_balise = $nom; |
|
| 416 | + /** @var string Nom de la balise générique (si utilisée) */ |
|
| 417 | + $nom_balise_generique = ''; |
|
| 418 | + |
|
| 419 | + $appel_php_depuis_modele = false; |
|
| 420 | + if ( |
|
| 421 | + is_array($context_compil) |
|
| 422 | + && !is_numeric($context_compil[3]) |
|
| 423 | + && empty($context_compil[0]) |
|
| 424 | + && empty($context_compil[1]) |
|
| 425 | + && empty($context_compil[2]) |
|
| 426 | + && empty($context_compil[3]) |
|
| 427 | + ) { |
|
| 428 | + $appel_php_depuis_modele = true; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + if (!$fonction_balise = charger_fonction($nom_balise, 'balise', true)) { |
|
| 432 | + // Calculer un nom générique (ie. 'formulaire_' dans 'formulaire_editer_article') |
|
| 433 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 434 | + // injecter en premier arg le nom de la balise |
|
| 435 | + array_unshift($args, $nom); |
|
| 436 | + $nom_balise_generique = $balise_generique['nom_generique']; |
|
| 437 | + $fonction_balise = $balise_generique['fonction_generique']; |
|
| 438 | + $nom_balise = $nom_balise_generique; |
|
| 439 | + } |
|
| 440 | + unset($balise_generique); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + if (!$fonction_balise) { |
|
| 444 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 445 | + erreur_squelette($msg, $context_compil); |
|
| 446 | + |
|
| 447 | + return ''; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + // retrouver le fichier qui a déclaré la fonction |
|
| 451 | + // même si la fonction dynamique est déclarée dans un fichier de fonctions. |
|
| 452 | + // Attention sous windows, getFileName() retourne un antislash. |
|
| 453 | + $reflector = new ReflectionFunction($fonction_balise); |
|
| 454 | + $file = $reflector->getFileName(); |
|
| 455 | + if (str_starts_with($file, _ROOT_RACINE)) { |
|
| 456 | + $file = str_replace(\DIRECTORY_SEPARATOR, '/', substr($file, strlen(_ROOT_RACINE))); |
|
| 457 | + } |
|
| 458 | + |
|
| 459 | + // Y a-t-il une fonction de traitement des arguments ? |
|
| 460 | + $f = 'balise_' . $nom_balise . '_stat'; |
|
| 461 | + |
|
| 462 | + $r = !function_exists($f) ? $args : $f($args, $context_compil); |
|
| 463 | + |
|
| 464 | + if (!is_array($r)) { |
|
| 465 | + return $r; |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // verifier que la fonction dyn est la, |
|
| 469 | + // sinon se replier sur la generique si elle existe |
|
| 470 | + if (!function_exists('balise_' . $nom_balise . '_dyn')) { |
|
| 471 | + if ( |
|
| 472 | + ($balise_generique = chercher_balise_generique($nom)) |
|
| 473 | + && ($nom_balise_generique = $balise_generique['nom_generique']) |
|
| 474 | + && ($file = include_spip('balise/' . strtolower($nom_balise_generique))) |
|
| 475 | + && function_exists('balise_' . $nom_balise_generique . '_dyn') |
|
| 476 | + ) { |
|
| 477 | + // et lui injecter en premier arg le nom de la balise |
|
| 478 | + array_unshift($r, $nom); |
|
| 479 | + $nom_balise = $nom_balise_generique; |
|
| 480 | + if (!_DIR_RESTREINT) { |
|
| 481 | + $file = _DIR_RESTREINT_ABS . $file; |
|
| 482 | + } |
|
| 483 | + } else { |
|
| 484 | + $msg = ['zbug_balise_inexistante', ['from' => 'CVT', 'balise' => $nom]]; |
|
| 485 | + erreur_squelette($msg, $context_compil); |
|
| 486 | + |
|
| 487 | + return ''; |
|
| 488 | + } |
|
| 489 | + } |
|
| 490 | + |
|
| 491 | + if ($appel_php_depuis_modele) { |
|
| 492 | + $context_compil['appel_php_depuis_modele'] = true; |
|
| 493 | + } |
|
| 494 | + return synthetiser_balise_dynamique($nom_balise, $r, $file, $context_compil); |
|
| 495 | 495 | } |
| 496 | 496 | |
| 497 | 497 | /** |
@@ -506,23 +506,23 @@ discard block |
||
| 506 | 506 | * @return array|null |
| 507 | 507 | */ |
| 508 | 508 | function chercher_balise_generique($nom) { |
| 509 | - if (!str_contains($nom, '_')) { |
|
| 510 | - return null; |
|
| 511 | - } |
|
| 512 | - $nom_generique = $nom; |
|
| 513 | - while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | - $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | - $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | - if ($fonction_generique) { |
|
| 517 | - return [ |
|
| 518 | - 'nom' => $nom, |
|
| 519 | - 'nom_generique' => $nom_generique, |
|
| 520 | - 'fonction_generique' => $fonction_generique, |
|
| 521 | - ]; |
|
| 522 | - } |
|
| 523 | - $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | - } |
|
| 525 | - return null; |
|
| 509 | + if (!str_contains($nom, '_')) { |
|
| 510 | + return null; |
|
| 511 | + } |
|
| 512 | + $nom_generique = $nom; |
|
| 513 | + while (false !== ($p = strrpos($nom_generique, '_'))) { |
|
| 514 | + $nom_generique = substr($nom_generique, 0, $p + 1); |
|
| 515 | + $fonction_generique = charger_fonction($nom_generique, 'balise', true); |
|
| 516 | + if ($fonction_generique) { |
|
| 517 | + return [ |
|
| 518 | + 'nom' => $nom, |
|
| 519 | + 'nom_generique' => $nom_generique, |
|
| 520 | + 'fonction_generique' => $fonction_generique, |
|
| 521 | + ]; |
|
| 522 | + } |
|
| 523 | + $nom_generique = substr($nom_generique, 0, -1); |
|
| 524 | + } |
|
| 525 | + return null; |
|
| 526 | 526 | } |
| 527 | 527 | |
| 528 | 528 | |
@@ -546,51 +546,51 @@ discard block |
||
| 546 | 546 | * @return null; |
| 547 | 547 | **/ |
| 548 | 548 | function lang_select_public($lang, $lang_select, $titre = null) { |
| 549 | - // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | - if ( |
|
| 551 | - isset($GLOBALS['forcer_lang']) |
|
| 552 | - && $GLOBALS['forcer_lang'] |
|
| 553 | - && $lang_select !== 'oui' |
|
| 554 | - ) { |
|
| 555 | - $lang = $GLOBALS['spip_lang']; |
|
| 556 | - } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | - elseif (!strlen($lang)) { |
|
| 558 | - $lang = $GLOBALS['spip_lang']; |
|
| 559 | - } // Cas 3. l'objet est multilingue ! |
|
| 560 | - elseif ( |
|
| 561 | - $lang_select !== 'oui' |
|
| 562 | - && strlen($titre) > 10 |
|
| 563 | - && str_contains($titre, '<multi>') |
|
| 564 | - && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | - ) { |
|
| 566 | - $lang = $GLOBALS['spip_lang']; |
|
| 567 | - } |
|
| 568 | - |
|
| 569 | - // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | - lang_select($lang); |
|
| 571 | - |
|
| 572 | - return; |
|
| 549 | + // Cas 1. forcer_lang = true et pas de critere {lang_select} |
|
| 550 | + if ( |
|
| 551 | + isset($GLOBALS['forcer_lang']) |
|
| 552 | + && $GLOBALS['forcer_lang'] |
|
| 553 | + && $lang_select !== 'oui' |
|
| 554 | + ) { |
|
| 555 | + $lang = $GLOBALS['spip_lang']; |
|
| 556 | + } // Cas 2. l'objet n'a pas de langue definie (ou definie a '') |
|
| 557 | + elseif (!strlen($lang)) { |
|
| 558 | + $lang = $GLOBALS['spip_lang']; |
|
| 559 | + } // Cas 3. l'objet est multilingue ! |
|
| 560 | + elseif ( |
|
| 561 | + $lang_select !== 'oui' |
|
| 562 | + && strlen($titre) > 10 |
|
| 563 | + && str_contains($titre, '<multi>') |
|
| 564 | + && str_contains(CollecteurHtmlTag::proteger_balisesHtml($titre), '<multi>') |
|
| 565 | + ) { |
|
| 566 | + $lang = $GLOBALS['spip_lang']; |
|
| 567 | + } |
|
| 568 | + |
|
| 569 | + // faire un lang_select() eventuellement sur la langue inchangee |
|
| 570 | + lang_select($lang); |
|
| 571 | + |
|
| 572 | + return; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | |
| 576 | 576 | // Si un tableau &doublons[articles] est passe en parametre, |
| 577 | 577 | // il faut le nettoyer car il pourrait etre injecte en SQL |
| 578 | 578 | function nettoyer_env_doublons($envd) { |
| 579 | - foreach ($envd as $table => $liste) { |
|
| 580 | - $n = ''; |
|
| 581 | - foreach (explode(',', $liste) as $val) { |
|
| 582 | - if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | - $n .= ',' . $val; |
|
| 584 | - } |
|
| 585 | - } |
|
| 586 | - if (strlen($n)) { |
|
| 587 | - $envd[$table] = $n; |
|
| 588 | - } else { |
|
| 589 | - unset($envd[$table]); |
|
| 590 | - } |
|
| 591 | - } |
|
| 592 | - |
|
| 593 | - return $envd; |
|
| 579 | + foreach ($envd as $table => $liste) { |
|
| 580 | + $n = ''; |
|
| 581 | + foreach (explode(',', $liste) as $val) { |
|
| 582 | + if (($a = intval($val)) && $val === strval($a)) { |
|
| 583 | + $n .= ',' . $val; |
|
| 584 | + } |
|
| 585 | + } |
|
| 586 | + if (strlen($n)) { |
|
| 587 | + $envd[$table] = $n; |
|
| 588 | + } else { |
|
| 589 | + unset($envd[$table]); |
|
| 590 | + } |
|
| 591 | + } |
|
| 592 | + |
|
| 593 | + return $envd; |
|
| 594 | 594 | } |
| 595 | 595 | |
| 596 | 596 | /** |
@@ -609,21 +609,21 @@ discard block |
||
| 609 | 609 | * Opérateur trouvé (SELF ou SUBSELECT) sinon false. |
| 610 | 610 | **/ |
| 611 | 611 | function match_self($w) { |
| 612 | - if (is_string($w)) { |
|
| 613 | - return false; |
|
| 614 | - } |
|
| 615 | - if (is_array($w)) { |
|
| 616 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | - return $w; |
|
| 618 | - } |
|
| 619 | - foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | - if ($m = match_self($sw)) { |
|
| 621 | - return $m; |
|
| 622 | - } |
|
| 623 | - } |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - return false; |
|
| 612 | + if (is_string($w)) { |
|
| 613 | + return false; |
|
| 614 | + } |
|
| 615 | + if (is_array($w)) { |
|
| 616 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 617 | + return $w; |
|
| 618 | + } |
|
| 619 | + foreach (array_filter($w, 'is_array') as $sw) { |
|
| 620 | + if ($m = match_self($sw)) { |
|
| 621 | + return $m; |
|
| 622 | + } |
|
| 623 | + } |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + return false; |
|
| 627 | 627 | } |
| 628 | 628 | |
| 629 | 629 | /** |
@@ -639,16 +639,16 @@ discard block |
||
| 639 | 639 | * est remplacée par son code. |
| 640 | 640 | **/ |
| 641 | 641 | function remplace_sous_requete($w, $sousrequete) { |
| 642 | - if (is_array($w)) { |
|
| 643 | - if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | - return $sousrequete; |
|
| 645 | - } |
|
| 646 | - foreach ($w as $k => $sw) { |
|
| 647 | - $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - return $w; |
|
| 642 | + if (is_array($w)) { |
|
| 643 | + if (in_array(reset($w), ['SELF', 'SUBSELECT'])) { |
|
| 644 | + return $sousrequete; |
|
| 645 | + } |
|
| 646 | + foreach ($w as $k => $sw) { |
|
| 647 | + $w[$k] = remplace_sous_requete($sw, $sousrequete); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + return $w; |
|
| 652 | 652 | } |
| 653 | 653 | |
| 654 | 654 | /** |
@@ -662,17 +662,17 @@ discard block |
||
| 662 | 662 | * - Conditions avec des sous requêtes |
| 663 | 663 | **/ |
| 664 | 664 | function trouver_sous_requetes($where) { |
| 665 | - $where_simples = []; |
|
| 666 | - $where_sous = []; |
|
| 667 | - foreach ($where as $k => $w) { |
|
| 668 | - if (match_self($w)) { |
|
| 669 | - $where_sous[$k] = $w; |
|
| 670 | - } else { |
|
| 671 | - $where_simples[$k] = $w; |
|
| 672 | - } |
|
| 673 | - } |
|
| 674 | - |
|
| 675 | - return [$where_simples, $where_sous]; |
|
| 665 | + $where_simples = []; |
|
| 666 | + $where_sous = []; |
|
| 667 | + foreach ($where as $k => $w) { |
|
| 668 | + if (match_self($w)) { |
|
| 669 | + $where_sous[$k] = $w; |
|
| 670 | + } else { |
|
| 671 | + $where_simples[$k] = $w; |
|
| 672 | + } |
|
| 673 | + } |
|
| 674 | + |
|
| 675 | + return [$where_simples, $where_sous]; |
|
| 676 | 676 | } |
| 677 | 677 | |
| 678 | 678 | |
@@ -698,293 +698,293 @@ discard block |
||
| 698 | 698 | * @return resource |
| 699 | 699 | */ |
| 700 | 700 | function calculer_select( |
| 701 | - $select = [], |
|
| 702 | - $from = [], |
|
| 703 | - $from_type = [], |
|
| 704 | - $where = [], |
|
| 705 | - $join = [], |
|
| 706 | - $groupby = [], |
|
| 707 | - $orderby = [], |
|
| 708 | - $limit = '', |
|
| 709 | - $having = [], |
|
| 710 | - $table = '', |
|
| 711 | - $id = '', |
|
| 712 | - $serveur = '', |
|
| 713 | - $requeter = true |
|
| 701 | + $select = [], |
|
| 702 | + $from = [], |
|
| 703 | + $from_type = [], |
|
| 704 | + $where = [], |
|
| 705 | + $join = [], |
|
| 706 | + $groupby = [], |
|
| 707 | + $orderby = [], |
|
| 708 | + $limit = '', |
|
| 709 | + $having = [], |
|
| 710 | + $table = '', |
|
| 711 | + $id = '', |
|
| 712 | + $serveur = '', |
|
| 713 | + $requeter = true |
|
| 714 | 714 | ) { |
| 715 | 715 | |
| 716 | - // retirer les criteres vides: |
|
| 717 | - // {X ?} avec X absent de l'URL |
|
| 718 | - // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | - // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | - $menage = false; |
|
| 721 | - foreach ($where as $k => $v) { |
|
| 722 | - if (is_array($v) && count($v)) { |
|
| 723 | - if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | - $op = false; |
|
| 725 | - } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | - $op = false; |
|
| 727 | - } else { |
|
| 728 | - $op = $v[0] ?: $v; |
|
| 729 | - } |
|
| 730 | - } else { |
|
| 731 | - $op = $v; |
|
| 732 | - } |
|
| 733 | - if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | - unset($where[$k]); |
|
| 735 | - $menage = true; |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | - $groupby = array_diff($groupby, ['']); |
|
| 741 | - |
|
| 742 | - // remplacer les sous requetes recursives au calcul |
|
| 743 | - [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | - foreach ($where_sous as $k => $w) { |
|
| 745 | - $menage = true; |
|
| 746 | - // on recupere la sous requete |
|
| 747 | - $sous = match_self($w); |
|
| 748 | - if ($sous[0] == 'SELF') { |
|
| 749 | - // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | - array_push($where_simples, $sous[2]); |
|
| 751 | - $wheresub = [ |
|
| 752 | - $sous[2], |
|
| 753 | - '0=0' |
|
| 754 | - ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | - $jsub = $join; |
|
| 756 | - // trouver les jointures utiles a |
|
| 757 | - // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | - // ie L1.objet='article' |
|
| 759 | - // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | - $i = 0; |
|
| 761 | - do { |
|
| 762 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | - [$sous[1] . ' AS id'], |
|
| 764 | - $from, |
|
| 765 | - $from_type, |
|
| 766 | - $wheresub, |
|
| 767 | - $jsub, |
|
| 768 | - [], |
|
| 769 | - [], |
|
| 770 | - '', |
|
| 771 | - $having, |
|
| 772 | - $table, |
|
| 773 | - $id, |
|
| 774 | - $serveur, |
|
| 775 | - false |
|
| 776 | - ) . ')'); |
|
| 777 | - if (!$i) { |
|
| 778 | - $i = 1; |
|
| 779 | - $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | - foreach ($join as $cle => $wj) { |
|
| 781 | - if ( |
|
| 782 | - (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | - ) { |
|
| 784 | - $i = 0; |
|
| 785 | - $wheresub[] = $wj[3]; |
|
| 786 | - unset($jsub[$cle][3]); |
|
| 787 | - } |
|
| 788 | - } |
|
| 789 | - } |
|
| 790 | - } while ($i++ < 1); |
|
| 791 | - } |
|
| 792 | - if ($sous[0] == 'SUBSELECT') { |
|
| 793 | - // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | - array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | - $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | - $sous[1], # select |
|
| 797 | - $sous[2], #from |
|
| 798 | - [], #from_type |
|
| 799 | - $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | - #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | - [], #join |
|
| 802 | - $sous[4] ?: [], #groupby |
|
| 803 | - $sous[5] ?: [], #orderby |
|
| 804 | - $sous[6], #limit |
|
| 805 | - $sous[7] ?: [], #having |
|
| 806 | - $table, |
|
| 807 | - $id, |
|
| 808 | - $serveur, |
|
| 809 | - false |
|
| 810 | - ) . ')'); |
|
| 811 | - } |
|
| 812 | - array_pop($where_simples); |
|
| 813 | - } |
|
| 814 | - |
|
| 815 | - foreach ($having as $k => $v) { |
|
| 816 | - if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | - unset($having[$k]); |
|
| 818 | - } |
|
| 819 | - } |
|
| 820 | - |
|
| 821 | - // Installer les jointures. |
|
| 822 | - // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | - // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | - // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | - |
|
| 826 | - $afrom = []; |
|
| 827 | - $equiv = []; |
|
| 828 | - $k = count($join); |
|
| 829 | - foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | - $cle = $cledef; |
|
| 831 | - // le format de join est : |
|
| 832 | - // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | - $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | - if (count($join[$cle]) == 2) { |
|
| 835 | - $join[$cle][] = $join[$cle][1]; |
|
| 836 | - } |
|
| 837 | - if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | - $join[$cle][] = ''; |
|
| 839 | - } |
|
| 840 | - [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | - // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | - // pour compat avec ancienne convention |
|
| 843 | - if (is_numeric($cle)) { |
|
| 844 | - $cle = "L$k"; |
|
| 845 | - } |
|
| 846 | - $cle_where_lie = "JOIN-$cle"; |
|
| 847 | - if ( |
|
| 848 | - !$menage |
|
| 849 | - || isset($afrom[$cle]) |
|
| 850 | - || calculer_jointnul($cle, $select) |
|
| 851 | - || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | - || calculer_jointnul($cle, $having) |
|
| 853 | - || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | - ) { |
|
| 855 | - // corriger les references non explicites dans select |
|
| 856 | - // ou groupby |
|
| 857 | - foreach ($select as $i => $s) { |
|
| 858 | - if ($s == $c) { |
|
| 859 | - $select[$i] = "$cle.$c AS $c"; |
|
| 860 | - break; |
|
| 861 | - } |
|
| 862 | - } |
|
| 863 | - foreach ($groupby as $i => $g) { |
|
| 864 | - if ($g == $c) { |
|
| 865 | - $groupby[$i] = "$cle.$c"; |
|
| 866 | - break; |
|
| 867 | - } |
|
| 868 | - } |
|
| 869 | - // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | - // sans recours a preg_match |
|
| 871 | - // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | - $afrom[$t][$cle] = [ |
|
| 873 | - "\n" . |
|
| 874 | - ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | - $from[$cle], |
|
| 876 | - "AS $cle", |
|
| 877 | - 'ON (', |
|
| 878 | - "$cle.$c", |
|
| 879 | - '=', |
|
| 880 | - "$t.$carr", |
|
| 881 | - ($and ? 'AND ' . $and : '') . |
|
| 882 | - ')' |
|
| 883 | - ]; |
|
| 884 | - if (isset($afrom[$cle])) { |
|
| 885 | - $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | - unset($afrom[$cle]); |
|
| 887 | - } |
|
| 888 | - $equiv[] = $carr; |
|
| 889 | - } else { |
|
| 890 | - unset($join[$cledef]); |
|
| 891 | - if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | - unset($where_simples[$cle_where_lie]); |
|
| 893 | - unset($where[$cle_where_lie]); |
|
| 894 | - } |
|
| 895 | - } |
|
| 896 | - unset($from[$cle]); |
|
| 897 | - $k--; |
|
| 898 | - } |
|
| 899 | - |
|
| 900 | - if (count($afrom)) { |
|
| 901 | - // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | - //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | - //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | - //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | - // ou dans |
|
| 906 | - //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | - // qui comporte plusieurs jointures |
|
| 908 | - // ou dans |
|
| 909 | - // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | - // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | - // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | - // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | - // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | - // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | - |
|
| 916 | - $t = key($from); |
|
| 917 | - $c = current($from); |
|
| 918 | - reset($from); |
|
| 919 | - $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | - if ( |
|
| 921 | - !( |
|
| 922 | - strpos($t, ' ') |
|
| 923 | - // jointure des le depart cf boucle_doc |
|
| 924 | - || calculer_jointnul($t, $select, $e) |
|
| 925 | - || calculer_jointnul($t, $join, $e) |
|
| 926 | - || calculer_jointnul($t, $where, $e) |
|
| 927 | - || calculer_jointnul($t, $orderby, $e) |
|
| 928 | - || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | - ) |
|
| 930 | - && count($afrom[$t]) |
|
| 931 | - ) { |
|
| 932 | - $nfrom = reset($afrom[$t]); |
|
| 933 | - $nt = array_key_first($afrom[$t]); |
|
| 934 | - unset($from[$t]); |
|
| 935 | - $from[$nt] = $nfrom[1]; |
|
| 936 | - unset($afrom[$t][$nt]); |
|
| 937 | - $afrom[$nt] = $afrom[$t]; |
|
| 938 | - unset($afrom[$t]); |
|
| 939 | - $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | - $t = $nfrom[4]; |
|
| 941 | - $alias = ''; |
|
| 942 | - // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | - $oldcle = explode('.', $nfrom[6]); |
|
| 944 | - $oldcle = end($oldcle); |
|
| 945 | - $newcle = explode('.', $nfrom[4]); |
|
| 946 | - $newcle = end($newcle); |
|
| 947 | - if ($newcle != $oldcle) { |
|
| 948 | - // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | - // reprendre simplement ce AS |
|
| 950 | - $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | - if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | - $alias = ''; |
|
| 953 | - } else { |
|
| 954 | - $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | - } |
|
| 956 | - } |
|
| 957 | - $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | - $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | - $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | - $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | - $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | - $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | - } |
|
| 964 | - $from = reinjecte_joint($afrom, $from); |
|
| 965 | - } |
|
| 966 | - if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | - $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | - $GLOBALS['debug'] = []; |
|
| 969 | - if ($wasdebug) { |
|
| 970 | - $GLOBALS['debug']['debug'] = true; |
|
| 971 | - } |
|
| 972 | - } |
|
| 973 | - $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | - $r = sql_select( |
|
| 975 | - $select, |
|
| 976 | - $from, |
|
| 977 | - $where, |
|
| 978 | - $groupby, |
|
| 979 | - array_filter($orderby), |
|
| 980 | - $limit, |
|
| 981 | - $having, |
|
| 982 | - $serveur, |
|
| 983 | - $requeter |
|
| 984 | - ); |
|
| 985 | - unset($GLOBALS['debug']['aucasou']); |
|
| 986 | - |
|
| 987 | - return $r; |
|
| 716 | + // retirer les criteres vides: |
|
| 717 | + // {X ?} avec X absent de l'URL |
|
| 718 | + // {par #ENV{X}} avec X absent de l'URL |
|
| 719 | + // IN sur collection vide (ce dernier devrait pouvoir etre fait a la compil) |
|
| 720 | + $menage = false; |
|
| 721 | + foreach ($where as $k => $v) { |
|
| 722 | + if (is_array($v) && count($v)) { |
|
| 723 | + if ((count($v) >= 2) && ($v[0] == 'REGEXP') && ($v[2] == "'.*'")) { |
|
| 724 | + $op = false; |
|
| 725 | + } elseif ((count($v) >= 2) && ($v[0] == 'LIKE') && ($v[2] == "'%'")) { |
|
| 726 | + $op = false; |
|
| 727 | + } else { |
|
| 728 | + $op = $v[0] ?: $v; |
|
| 729 | + } |
|
| 730 | + } else { |
|
| 731 | + $op = $v; |
|
| 732 | + } |
|
| 733 | + if (!$op || $op == 1 || $op == '0=0') { |
|
| 734 | + unset($where[$k]); |
|
| 735 | + $menage = true; |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + // evacuer les eventuels groupby vide issus d'un calcul dynamique |
|
| 740 | + $groupby = array_diff($groupby, ['']); |
|
| 741 | + |
|
| 742 | + // remplacer les sous requetes recursives au calcul |
|
| 743 | + [$where_simples, $where_sous] = trouver_sous_requetes($where); |
|
| 744 | + foreach ($where_sous as $k => $w) { |
|
| 745 | + $menage = true; |
|
| 746 | + // on recupere la sous requete |
|
| 747 | + $sous = match_self($w); |
|
| 748 | + if ($sous[0] == 'SELF') { |
|
| 749 | + // c'est une sous requete identique a elle meme sous la forme (SELF,$select,$where) |
|
| 750 | + array_push($where_simples, $sous[2]); |
|
| 751 | + $wheresub = [ |
|
| 752 | + $sous[2], |
|
| 753 | + '0=0' |
|
| 754 | + ]; // pour accepter une string et forcer a faire le menage car on a surement simplifie select et where |
|
| 755 | + $jsub = $join; |
|
| 756 | + // trouver les jointures utiles a |
|
| 757 | + // reinjecter dans le where de la sous requete les conditions supplementaires des jointures qui y sont mentionnees |
|
| 758 | + // ie L1.objet='article' |
|
| 759 | + // on construit le where une fois, puis on ajoute les where complentaires si besoin, et on reconstruit le where en fonction |
|
| 760 | + $i = 0; |
|
| 761 | + do { |
|
| 762 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 763 | + [$sous[1] . ' AS id'], |
|
| 764 | + $from, |
|
| 765 | + $from_type, |
|
| 766 | + $wheresub, |
|
| 767 | + $jsub, |
|
| 768 | + [], |
|
| 769 | + [], |
|
| 770 | + '', |
|
| 771 | + $having, |
|
| 772 | + $table, |
|
| 773 | + $id, |
|
| 774 | + $serveur, |
|
| 775 | + false |
|
| 776 | + ) . ')'); |
|
| 777 | + if (!$i) { |
|
| 778 | + $i = 1; |
|
| 779 | + $wherestring = calculer_where_to_string($where[$k]); |
|
| 780 | + foreach ($join as $cle => $wj) { |
|
| 781 | + if ( |
|
| 782 | + (is_countable($wj) ? count($wj) : 0) == 4 && str_contains($wherestring, (string) "{$cle}.") |
|
| 783 | + ) { |
|
| 784 | + $i = 0; |
|
| 785 | + $wheresub[] = $wj[3]; |
|
| 786 | + unset($jsub[$cle][3]); |
|
| 787 | + } |
|
| 788 | + } |
|
| 789 | + } |
|
| 790 | + } while ($i++ < 1); |
|
| 791 | + } |
|
| 792 | + if ($sous[0] == 'SUBSELECT') { |
|
| 793 | + // c'est une sous requete explicite sous la forme identique a sql_select : (SUBSELECT,$select,$from,$where,$groupby,$orderby,$limit,$having) |
|
| 794 | + array_push($where_simples, $sous[3]); // est-ce utile dans ce cas ? |
|
| 795 | + $where[$k] = remplace_sous_requete($w, '(' . calculer_select( |
|
| 796 | + $sous[1], # select |
|
| 797 | + $sous[2], #from |
|
| 798 | + [], #from_type |
|
| 799 | + $sous[3] ? (is_array($sous[3]) ? $sous[3] : [$sous[3]]) : [], |
|
| 800 | + #where, qui peut etre de la forme string comme dans sql_select |
|
| 801 | + [], #join |
|
| 802 | + $sous[4] ?: [], #groupby |
|
| 803 | + $sous[5] ?: [], #orderby |
|
| 804 | + $sous[6], #limit |
|
| 805 | + $sous[7] ?: [], #having |
|
| 806 | + $table, |
|
| 807 | + $id, |
|
| 808 | + $serveur, |
|
| 809 | + false |
|
| 810 | + ) . ')'); |
|
| 811 | + } |
|
| 812 | + array_pop($where_simples); |
|
| 813 | + } |
|
| 814 | + |
|
| 815 | + foreach ($having as $k => $v) { |
|
| 816 | + if (!$v || $v == 1 || $v == '0=0') { |
|
| 817 | + unset($having[$k]); |
|
| 818 | + } |
|
| 819 | + } |
|
| 820 | + |
|
| 821 | + // Installer les jointures. |
|
| 822 | + // Retirer celles seulement utiles aux criteres finalement absents mais |
|
| 823 | + // parcourir de la plus recente a la moins recente pour pouvoir eliminer Ln |
|
| 824 | + // si elle est seulement utile a Ln+1 elle meme inutile |
|
| 825 | + |
|
| 826 | + $afrom = []; |
|
| 827 | + $equiv = []; |
|
| 828 | + $k = count($join); |
|
| 829 | + foreach (array_reverse($join, true) as $cledef => $j) { |
|
| 830 | + $cle = $cledef; |
|
| 831 | + // le format de join est : |
|
| 832 | + // array(table depart, cle depart [,cle arrivee[,condition optionnelle and ...]]) |
|
| 833 | + $join[$cle] = array_values($join[$cle]); // recalculer les cles car des unset ont pu perturber |
|
| 834 | + if (count($join[$cle]) == 2) { |
|
| 835 | + $join[$cle][] = $join[$cle][1]; |
|
| 836 | + } |
|
| 837 | + if ((is_countable($join[$cle]) ? count($join[$cle]) : 0) == 3) { |
|
| 838 | + $join[$cle][] = ''; |
|
| 839 | + } |
|
| 840 | + [$t, $c, $carr, $and] = $join[$cle]; |
|
| 841 | + // si le nom de la jointure n'a pas ete specifiee, on prend Lx avec x sont rang dans la liste |
|
| 842 | + // pour compat avec ancienne convention |
|
| 843 | + if (is_numeric($cle)) { |
|
| 844 | + $cle = "L$k"; |
|
| 845 | + } |
|
| 846 | + $cle_where_lie = "JOIN-$cle"; |
|
| 847 | + if ( |
|
| 848 | + !$menage |
|
| 849 | + || isset($afrom[$cle]) |
|
| 850 | + || calculer_jointnul($cle, $select) |
|
| 851 | + || calculer_jointnul($cle, array_diff_key($join, [$cle => $join[$cle]])) |
|
| 852 | + || calculer_jointnul($cle, $having) |
|
| 853 | + || calculer_jointnul($cle, array_diff_key($where_simples, [$cle_where_lie => ''])) |
|
| 854 | + ) { |
|
| 855 | + // corriger les references non explicites dans select |
|
| 856 | + // ou groupby |
|
| 857 | + foreach ($select as $i => $s) { |
|
| 858 | + if ($s == $c) { |
|
| 859 | + $select[$i] = "$cle.$c AS $c"; |
|
| 860 | + break; |
|
| 861 | + } |
|
| 862 | + } |
|
| 863 | + foreach ($groupby as $i => $g) { |
|
| 864 | + if ($g == $c) { |
|
| 865 | + $groupby[$i] = "$cle.$c"; |
|
| 866 | + break; |
|
| 867 | + } |
|
| 868 | + } |
|
| 869 | + // on garde une ecriture decomposee pour permettre une simplification ulterieure si besoin |
|
| 870 | + // sans recours a preg_match |
|
| 871 | + // un implode(' ',..) est fait dans reinjecte_joint un peu plus bas |
|
| 872 | + $afrom[$t][$cle] = [ |
|
| 873 | + "\n" . |
|
| 874 | + ($from_type[$cle] ?? 'INNER') . ' JOIN', |
|
| 875 | + $from[$cle], |
|
| 876 | + "AS $cle", |
|
| 877 | + 'ON (', |
|
| 878 | + "$cle.$c", |
|
| 879 | + '=', |
|
| 880 | + "$t.$carr", |
|
| 881 | + ($and ? 'AND ' . $and : '') . |
|
| 882 | + ')' |
|
| 883 | + ]; |
|
| 884 | + if (isset($afrom[$cle])) { |
|
| 885 | + $afrom[$t] = $afrom[$t] + $afrom[$cle]; |
|
| 886 | + unset($afrom[$cle]); |
|
| 887 | + } |
|
| 888 | + $equiv[] = $carr; |
|
| 889 | + } else { |
|
| 890 | + unset($join[$cledef]); |
|
| 891 | + if (isset($where_simples[$cle_where_lie])) { |
|
| 892 | + unset($where_simples[$cle_where_lie]); |
|
| 893 | + unset($where[$cle_where_lie]); |
|
| 894 | + } |
|
| 895 | + } |
|
| 896 | + unset($from[$cle]); |
|
| 897 | + $k--; |
|
| 898 | + } |
|
| 899 | + |
|
| 900 | + if (count($afrom)) { |
|
| 901 | + // Regarder si la table principale ne sert finalement a rien comme dans |
|
| 902 | + //<BOUCLE3(MOTS){id_article}{id_mot}> class='on'</BOUCLE3> |
|
| 903 | + //<BOUCLE2(MOTS){id_article} />#TOTAL_BOUCLE<//B2> |
|
| 904 | + //<BOUCLE5(RUBRIQUES){id_mot}{tout} />#TOTAL_BOUCLE<//B5> |
|
| 905 | + // ou dans |
|
| 906 | + //<BOUCLE8(HIERARCHIE){id_rubrique}{tout}{type='Squelette'}{inverse}{0,1}{lang_select=non} />#TOTAL_BOUCLE<//B8> |
|
| 907 | + // qui comporte plusieurs jointures |
|
| 908 | + // ou dans |
|
| 909 | + // <BOUCLE6(ARTICLES){id_mot=2}{statut==.*} />#TOTAL_BOUCLE<//B6> |
|
| 910 | + // <BOUCLE7(ARTICLES){id_mot>0}{statut?} />#TOTAL_BOUCLE<//B7> |
|
| 911 | + // penser a regarder aussi la clause orderby pour ne pas simplifier abusivement |
|
| 912 | + // <BOUCLE9(ARTICLES){recherche truc}{par titre}>#ID_ARTICLE</BOUCLE9> |
|
| 913 | + // penser a regarder aussi la clause groubpy pour ne pas simplifier abusivement |
|
| 914 | + // <BOUCLE10(EVENEMENTS){id_rubrique} />#TOTAL_BOUCLE<//B10> |
|
| 915 | + |
|
| 916 | + $t = key($from); |
|
| 917 | + $c = current($from); |
|
| 918 | + reset($from); |
|
| 919 | + $e = '/\b(' . "$t\\." . join('|' . $t . '\.', $equiv) . ')\b/'; |
|
| 920 | + if ( |
|
| 921 | + !( |
|
| 922 | + strpos($t, ' ') |
|
| 923 | + // jointure des le depart cf boucle_doc |
|
| 924 | + || calculer_jointnul($t, $select, $e) |
|
| 925 | + || calculer_jointnul($t, $join, $e) |
|
| 926 | + || calculer_jointnul($t, $where, $e) |
|
| 927 | + || calculer_jointnul($t, $orderby, $e) |
|
| 928 | + || calculer_jointnul($t, $groupby, $e) || calculer_jointnul($t, $having, $e) |
|
| 929 | + ) |
|
| 930 | + && count($afrom[$t]) |
|
| 931 | + ) { |
|
| 932 | + $nfrom = reset($afrom[$t]); |
|
| 933 | + $nt = array_key_first($afrom[$t]); |
|
| 934 | + unset($from[$t]); |
|
| 935 | + $from[$nt] = $nfrom[1]; |
|
| 936 | + unset($afrom[$t][$nt]); |
|
| 937 | + $afrom[$nt] = $afrom[$t]; |
|
| 938 | + unset($afrom[$t]); |
|
| 939 | + $e = '/\b' . preg_quote($nfrom[6]) . '\b/'; |
|
| 940 | + $t = $nfrom[4]; |
|
| 941 | + $alias = ''; |
|
| 942 | + // verifier que les deux cles sont homonymes, sinon installer un alias dans le select |
|
| 943 | + $oldcle = explode('.', $nfrom[6]); |
|
| 944 | + $oldcle = end($oldcle); |
|
| 945 | + $newcle = explode('.', $nfrom[4]); |
|
| 946 | + $newcle = end($newcle); |
|
| 947 | + if ($newcle != $oldcle) { |
|
| 948 | + // si l'ancienne cle etait deja dans le select avec un AS |
|
| 949 | + // reprendre simplement ce AS |
|
| 950 | + $as = '/\b' . preg_quote($nfrom[6]) . '\s+(AS\s+\w+)\b/'; |
|
| 951 | + if (preg_match($as, implode(',', $select), $m)) { |
|
| 952 | + $alias = ''; |
|
| 953 | + } else { |
|
| 954 | + $alias = ', ' . $nfrom[4] . " AS $oldcle"; |
|
| 955 | + } |
|
| 956 | + } |
|
| 957 | + $select = remplacer_jointnul($t . $alias, $select, $e); |
|
| 958 | + $join = remplacer_jointnul($t, $join, $e); |
|
| 959 | + $where = remplacer_jointnul($t, $where, $e); |
|
| 960 | + $having = remplacer_jointnul($t, $having, $e); |
|
| 961 | + $groupby = remplacer_jointnul($t, $groupby, $e); |
|
| 962 | + $orderby = remplacer_jointnul($t, $orderby, $e); |
|
| 963 | + } |
|
| 964 | + $from = reinjecte_joint($afrom, $from); |
|
| 965 | + } |
|
| 966 | + if (empty($GLOBALS['debug']) || !is_array($GLOBALS['debug'])) { |
|
| 967 | + $wasdebug = empty($GLOBALS['debug']) ? false : $GLOBALS['debug']; |
|
| 968 | + $GLOBALS['debug'] = []; |
|
| 969 | + if ($wasdebug) { |
|
| 970 | + $GLOBALS['debug']['debug'] = true; |
|
| 971 | + } |
|
| 972 | + } |
|
| 973 | + $GLOBALS['debug']['aucasou'] = [$table, $id, $serveur, $requeter]; |
|
| 974 | + $r = sql_select( |
|
| 975 | + $select, |
|
| 976 | + $from, |
|
| 977 | + $where, |
|
| 978 | + $groupby, |
|
| 979 | + array_filter($orderby), |
|
| 980 | + $limit, |
|
| 981 | + $having, |
|
| 982 | + $serveur, |
|
| 983 | + $requeter |
|
| 984 | + ); |
|
| 985 | + unset($GLOBALS['debug']['aucasou']); |
|
| 986 | + |
|
| 987 | + return $r; |
|
| 988 | 988 | } |
| 989 | 989 | |
| 990 | 990 | /** |
@@ -995,79 +995,79 @@ discard block |
||
| 995 | 995 | * @return string |
| 996 | 996 | */ |
| 997 | 997 | function calculer_where_to_string($v, $join = 'AND') { |
| 998 | - if (empty($v)) { |
|
| 999 | - return ''; |
|
| 1000 | - } |
|
| 1001 | - |
|
| 1002 | - if (!is_array($v)) { |
|
| 1003 | - return $v; |
|
| 1004 | - } else { |
|
| 1005 | - $exp = ''; |
|
| 1006 | - if (strtoupper($join) === 'AND') { |
|
| 1007 | - return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | - } else { |
|
| 1009 | - return $exp . join($join, $v); |
|
| 1010 | - } |
|
| 1011 | - } |
|
| 998 | + if (empty($v)) { |
|
| 999 | + return ''; |
|
| 1000 | + } |
|
| 1001 | + |
|
| 1002 | + if (!is_array($v)) { |
|
| 1003 | + return $v; |
|
| 1004 | + } else { |
|
| 1005 | + $exp = ''; |
|
| 1006 | + if (strtoupper($join) === 'AND') { |
|
| 1007 | + return $exp . join(" $join ", array_map('calculer_where_to_string', $v)); |
|
| 1008 | + } else { |
|
| 1009 | + return $exp . join($join, $v); |
|
| 1010 | + } |
|
| 1011 | + } |
|
| 1012 | 1012 | } |
| 1013 | 1013 | |
| 1014 | 1014 | |
| 1015 | 1015 | //condition suffisante (mais non necessaire) pour qu'une table soit utile |
| 1016 | 1016 | |
| 1017 | 1017 | function calculer_jointnul($cle, $exp, $equiv = '') { |
| 1018 | - if (!is_array($exp)) { |
|
| 1019 | - if ($equiv) { |
|
| 1020 | - $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | - } |
|
| 1022 | - |
|
| 1023 | - return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | - } else { |
|
| 1025 | - foreach ($exp as $v) { |
|
| 1026 | - if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | - return true; |
|
| 1028 | - } |
|
| 1029 | - } |
|
| 1030 | - |
|
| 1031 | - return false; |
|
| 1032 | - } |
|
| 1018 | + if (!is_array($exp)) { |
|
| 1019 | + if ($equiv) { |
|
| 1020 | + $exp = preg_replace($equiv, '', $exp); |
|
| 1021 | + } |
|
| 1022 | + |
|
| 1023 | + return preg_match("/\\b$cle\\./", $exp); |
|
| 1024 | + } else { |
|
| 1025 | + foreach ($exp as $v) { |
|
| 1026 | + if (calculer_jointnul($cle, $v, $equiv)) { |
|
| 1027 | + return true; |
|
| 1028 | + } |
|
| 1029 | + } |
|
| 1030 | + |
|
| 1031 | + return false; |
|
| 1032 | + } |
|
| 1033 | 1033 | } |
| 1034 | 1034 | |
| 1035 | 1035 | function reinjecte_joint($afrom, $from) { |
| 1036 | - $from_synth = []; |
|
| 1037 | - foreach ($from as $k => $v) { |
|
| 1038 | - $from_synth[$k] = $from[$k]; |
|
| 1039 | - if (isset($afrom[$k])) { |
|
| 1040 | - foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | - $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | - } |
|
| 1043 | - $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | - unset($afrom[$k]); |
|
| 1045 | - } |
|
| 1046 | - } |
|
| 1047 | - |
|
| 1048 | - return $from_synth; |
|
| 1036 | + $from_synth = []; |
|
| 1037 | + foreach ($from as $k => $v) { |
|
| 1038 | + $from_synth[$k] = $from[$k]; |
|
| 1039 | + if (isset($afrom[$k])) { |
|
| 1040 | + foreach ($afrom[$k] as $kk => $vv) { |
|
| 1041 | + $afrom[$k][$kk] = implode(' ', $afrom[$k][$kk]); |
|
| 1042 | + } |
|
| 1043 | + $from_synth["$k@"] = implode(' ', $afrom[$k]); |
|
| 1044 | + unset($afrom[$k]); |
|
| 1045 | + } |
|
| 1046 | + } |
|
| 1047 | + |
|
| 1048 | + return $from_synth; |
|
| 1049 | 1049 | } |
| 1050 | 1050 | |
| 1051 | 1051 | function remplacer_jointnul($cle, $exp, $equiv = '') { |
| 1052 | - if (!is_array($exp)) { |
|
| 1053 | - return preg_replace($equiv, $cle, $exp); |
|
| 1054 | - } else { |
|
| 1055 | - foreach ($exp as $k => $v) { |
|
| 1056 | - $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | - } |
|
| 1058 | - |
|
| 1059 | - return $exp; |
|
| 1060 | - } |
|
| 1052 | + if (!is_array($exp)) { |
|
| 1053 | + return preg_replace($equiv, $cle, $exp); |
|
| 1054 | + } else { |
|
| 1055 | + foreach ($exp as $k => $v) { |
|
| 1056 | + $exp[$k] = remplacer_jointnul($cle, $v, $equiv); |
|
| 1057 | + } |
|
| 1058 | + |
|
| 1059 | + return $exp; |
|
| 1060 | + } |
|
| 1061 | 1061 | } |
| 1062 | 1062 | |
| 1063 | 1063 | // calcul du nom du squelette |
| 1064 | 1064 | function calculer_nom_fonction_squel($skel, $mime_type = 'html', string $connect = '') { |
| 1065 | - // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | - if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | - $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | - } |
|
| 1069 | - |
|
| 1070 | - return $mime_type |
|
| 1071 | - . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | - . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1065 | + // ne pas doublonner les squelette selon qu'ils sont calcules depuis ecrire/ ou depuis la racine |
|
| 1066 | + if (($l = strlen(_DIR_RACINE)) && strncmp($skel, _DIR_RACINE, $l) == 0) { |
|
| 1067 | + $skel = substr($skel, strlen(_DIR_RACINE)); |
|
| 1068 | + } |
|
| 1069 | + |
|
| 1070 | + return $mime_type |
|
| 1071 | + . (!$connect ? '' : preg_replace('/\W/', '_', $connect)) . '_' |
|
| 1072 | + . md5($GLOBALS['spip_version_code'] . ' * ' . $skel . (isset($GLOBALS['marqueur_skel']) ? '*' . $GLOBALS['marqueur_skel'] : '')); |
|
| 1073 | 1073 | } |
@@ -14,8 +14,8 @@ discard block |
||
| 14 | 14 | define('_ECRIRE_INC_VERSION', '1'); |
| 15 | 15 | |
| 16 | 16 | if (!defined('_DIR_RESTREINT_ABS')) { |
| 17 | - /** le nom du repertoire ecrire/ */ |
|
| 18 | - define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 17 | + /** le nom du repertoire ecrire/ */ |
|
| 18 | + define('_DIR_RESTREINT_ABS', 'ecrire/'); |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | /** Chemin relatif pour aller dans ecrire |
@@ -36,26 +36,26 @@ discard block |
||
| 36 | 36 | # Par defaut ces 4 noms seront suffixes par _DIR_RACINE (cf plus bas) |
| 37 | 37 | # mais on peut les mettre ailleurs et changer completement les noms |
| 38 | 38 | if (!defined('_NOM_TEMPORAIRES_INACCESSIBLES')) { |
| 39 | - /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 40 | - define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 39 | + /** Nom du repertoire des fichiers Temporaires Inaccessibles par http:// */ |
|
| 40 | + define('_NOM_TEMPORAIRES_INACCESSIBLES', 'tmp/'); |
|
| 41 | 41 | } |
| 42 | 42 | if (!defined('_NOM_TEMPORAIRES_ACCESSIBLES')) { |
| 43 | - /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 44 | - define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 43 | + /** Nom du repertoire des fichiers Temporaires Accessibles par http:// */ |
|
| 44 | + define('_NOM_TEMPORAIRES_ACCESSIBLES', 'local/'); |
|
| 45 | 45 | } |
| 46 | 46 | if (!defined('_NOM_PERMANENTS_INACCESSIBLES')) { |
| 47 | - /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 48 | - define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 47 | + /** Nom du repertoire des fichiers Permanents Inaccessibles par http:// */ |
|
| 48 | + define('_NOM_PERMANENTS_INACCESSIBLES', 'config/'); |
|
| 49 | 49 | } |
| 50 | 50 | if (!defined('_NOM_PERMANENTS_ACCESSIBLES')) { |
| 51 | - /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 52 | - define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 51 | + /** Nom du repertoire des fichiers Permanents Accessibles par http:// */ |
|
| 52 | + define('_NOM_PERMANENTS_ACCESSIBLES', 'IMG/'); |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | // Icones |
| 56 | 56 | if (!defined('_NOM_IMG_PACK')) { |
| 57 | - /** Nom du dossier images */ |
|
| 58 | - define('_NOM_IMG_PACK', 'images/'); |
|
| 57 | + /** Nom du dossier images */ |
|
| 58 | + define('_NOM_IMG_PACK', 'images/'); |
|
| 59 | 59 | } |
| 60 | 60 | /** le chemin http (relatif) vers les images standard */ |
| 61 | 61 | define('_DIR_IMG_PACK', (_DIR_RACINE . 'prive/' . _NOM_IMG_PACK)); |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | define('_ROOT_IMG_PACK', dirname(__DIR__, 3) . DIRECTORY_SEPARATOR . 'prive' . DIRECTORY_SEPARATOR . _NOM_IMG_PACK); |
| 65 | 65 | |
| 66 | 66 | if (!defined('_JAVASCRIPT')) { |
| 67 | - /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 68 | - // utilisable avec #CHEMIN et find_in_path |
|
| 69 | - define('_JAVASCRIPT', 'javascript/'); |
|
| 67 | + /** Nom du repertoire des bibliotheques JavaScript */ |
|
| 68 | + // utilisable avec #CHEMIN et find_in_path |
|
| 69 | + define('_JAVASCRIPT', 'javascript/'); |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** le nom du repertoire des bibliotheques JavaScript du prive */ |
@@ -74,35 +74,35 @@ discard block |
||
| 74 | 74 | |
| 75 | 75 | /** Le nom du fichier de personnalisation */ |
| 76 | 76 | if (!defined('_NOM_CONFIG')) { |
| 77 | - define('_NOM_CONFIG', 'mes_options'); |
|
| 77 | + define('_NOM_CONFIG', 'mes_options'); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | // Son emplacement absolu si on le trouve |
| 81 | 81 | if (@file_exists($f = _ROOT_RACINE . _NOM_PERMANENTS_INACCESSIBLES . _NOM_CONFIG . '.php')) { |
| 82 | - /** Emplacement absolu du fichier d'option */ |
|
| 83 | - define('_FILE_OPTIONS', $f); |
|
| 82 | + /** Emplacement absolu du fichier d'option */ |
|
| 83 | + define('_FILE_OPTIONS', $f); |
|
| 84 | 84 | } else { |
| 85 | - define('_FILE_OPTIONS', ''); |
|
| 85 | + define('_FILE_OPTIONS', ''); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | if (!defined('MODULES_IDIOMES')) { |
| 89 | - /** |
|
| 90 | - * Modules par défaut pour la traduction. |
|
| 91 | - * |
|
| 92 | - * Constante utilisée par le compilateur et le décompilateur |
|
| 93 | - * sa valeur etant traitée par inc_traduire_dist |
|
| 94 | - */ |
|
| 95 | - define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 89 | + /** |
|
| 90 | + * Modules par défaut pour la traduction. |
|
| 91 | + * |
|
| 92 | + * Constante utilisée par le compilateur et le décompilateur |
|
| 93 | + * sa valeur etant traitée par inc_traduire_dist |
|
| 94 | + */ |
|
| 95 | + define('MODULES_IDIOMES', 'public|spip|ecrire'); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | if (!defined('_IS_CLI')) { |
| 99 | - define( |
|
| 100 | - '_IS_CLI', |
|
| 101 | - !isset($_SERVER['HTTP_HOST']) |
|
| 102 | - && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 103 | - && !empty($_SERVER['argv']) |
|
| 104 | - && empty($_SERVER['REQUEST_METHOD']) |
|
| 105 | - ); |
|
| 99 | + define( |
|
| 100 | + '_IS_CLI', |
|
| 101 | + !isset($_SERVER['HTTP_HOST']) |
|
| 102 | + && !strlen((string) $_SERVER['DOCUMENT_ROOT']) |
|
| 103 | + && !empty($_SERVER['argv']) |
|
| 104 | + && empty($_SERVER['REQUEST_METHOD']) |
|
| 105 | + ); |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | // Definir les niveaux de log |
@@ -27,71 +27,71 @@ discard block |
||
| 27 | 27 | * Nom de la fonction, ou false. |
| 28 | 28 | */ |
| 29 | 29 | function charger_fonction($nom, $dossier = 'exec', $continue = false) { |
| 30 | - static $echecs = []; |
|
| 31 | - |
|
| 32 | - if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 33 | - $dossier .= '/'; |
|
| 34 | - } |
|
| 35 | - $f = str_replace('/', '_', $dossier) . $nom; |
|
| 36 | - |
|
| 37 | - if (function_exists($f)) { |
|
| 38 | - return $f; |
|
| 39 | - } |
|
| 40 | - if (function_exists($g = $f . '_dist')) { |
|
| 41 | - return $g; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - if (isset($echecs[$f])) { |
|
| 45 | - return $echecs[$f]; |
|
| 46 | - } |
|
| 47 | - // Sinon charger le fichier de declaration si plausible |
|
| 48 | - |
|
| 49 | - if (!preg_match(',^\w+$,', $f)) { |
|
| 50 | - if ($continue) { |
|
| 51 | - return false; |
|
| 52 | - } //appel interne, on passe |
|
| 53 | - include_spip('inc/minipres'); |
|
| 54 | - echo minipres(); |
|
| 55 | - exit; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // passer en minuscules (cf les balises de formulaires) |
|
| 59 | - // et inclure le fichier |
|
| 60 | - if ( |
|
| 61 | - !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 62 | - && strlen(dirname($dossier)) |
|
| 63 | - && dirname($dossier) != '.' |
|
| 64 | - ) { |
|
| 65 | - include_spip(substr($dossier, 0, -1)); |
|
| 66 | - } |
|
| 67 | - if (function_exists($f)) { |
|
| 68 | - return $f; |
|
| 69 | - } |
|
| 70 | - if (function_exists($g)) { |
|
| 71 | - return $g; |
|
| 72 | - } |
|
| 73 | - |
|
| 74 | - if ($continue) { |
|
| 75 | - return $echecs[$f] = false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // Echec : message d'erreur |
|
| 79 | - spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 80 | - ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 81 | - |
|
| 82 | - include_spip('inc/minipres'); |
|
| 83 | - include_spip('inc/filtres_mini'); |
|
| 84 | - echo minipres( |
|
| 85 | - _T('forum_titre_erreur'), |
|
| 86 | - $inc ? |
|
| 87 | - _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 88 | - . '<br />' |
|
| 89 | - . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 90 | - : |
|
| 91 | - _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 92 | - ['all_inline' => true,'status' => 404] |
|
| 93 | - ); |
|
| 94 | - exit; |
|
| 30 | + static $echecs = []; |
|
| 31 | + |
|
| 32 | + if (strlen($dossier) && !str_ends_with($dossier, '/')) { |
|
| 33 | + $dossier .= '/'; |
|
| 34 | + } |
|
| 35 | + $f = str_replace('/', '_', $dossier) . $nom; |
|
| 36 | + |
|
| 37 | + if (function_exists($f)) { |
|
| 38 | + return $f; |
|
| 39 | + } |
|
| 40 | + if (function_exists($g = $f . '_dist')) { |
|
| 41 | + return $g; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + if (isset($echecs[$f])) { |
|
| 45 | + return $echecs[$f]; |
|
| 46 | + } |
|
| 47 | + // Sinon charger le fichier de declaration si plausible |
|
| 48 | + |
|
| 49 | + if (!preg_match(',^\w+$,', $f)) { |
|
| 50 | + if ($continue) { |
|
| 51 | + return false; |
|
| 52 | + } //appel interne, on passe |
|
| 53 | + include_spip('inc/minipres'); |
|
| 54 | + echo minipres(); |
|
| 55 | + exit; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // passer en minuscules (cf les balises de formulaires) |
|
| 59 | + // et inclure le fichier |
|
| 60 | + if ( |
|
| 61 | + !($inc = include_spip($dossier . ($d = strtolower($nom)))) |
|
| 62 | + && strlen(dirname($dossier)) |
|
| 63 | + && dirname($dossier) != '.' |
|
| 64 | + ) { |
|
| 65 | + include_spip(substr($dossier, 0, -1)); |
|
| 66 | + } |
|
| 67 | + if (function_exists($f)) { |
|
| 68 | + return $f; |
|
| 69 | + } |
|
| 70 | + if (function_exists($g)) { |
|
| 71 | + return $g; |
|
| 72 | + } |
|
| 73 | + |
|
| 74 | + if ($continue) { |
|
| 75 | + return $echecs[$f] = false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // Echec : message d'erreur |
|
| 79 | + spip_log("fonction $nom ($f ou $g) indisponible" . |
|
| 80 | + ($inc ? '' : " (fichier $d absent de $dossier)")); |
|
| 81 | + |
|
| 82 | + include_spip('inc/minipres'); |
|
| 83 | + include_spip('inc/filtres_mini'); |
|
| 84 | + echo minipres( |
|
| 85 | + _T('forum_titre_erreur'), |
|
| 86 | + $inc ? |
|
| 87 | + _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($f) . '</code>']) |
|
| 88 | + . '<br />' |
|
| 89 | + . _T('fonction_introuvable', ['fonction' => '<code>' . spip_htmlentities($g) . '</code>']) |
|
| 90 | + : |
|
| 91 | + _T('fichier_introuvable', ['fichier' => '<code>' . spip_htmlentities($d) . '</code>']), |
|
| 92 | + ['all_inline' => true,'status' => 404] |
|
| 93 | + ); |
|
| 94 | + exit; |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | /** |
@@ -101,17 +101,17 @@ discard block |
||
| 101 | 101 | * @return bool |
| 102 | 102 | */ |
| 103 | 103 | function include_once_check($file) { |
| 104 | - if (file_exists($file)) { |
|
| 105 | - include_once $file; |
|
| 104 | + if (file_exists($file)) { |
|
| 105 | + include_once $file; |
|
| 106 | 106 | |
| 107 | - return true; |
|
| 108 | - } |
|
| 109 | - $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 110 | - $crash = ($crash ?: []); |
|
| 111 | - $crash[$file] = true; |
|
| 112 | - ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 107 | + return true; |
|
| 108 | + } |
|
| 109 | + $crash = (isset($GLOBALS['meta']['message_crash_plugins']) ? unserialize($GLOBALS['meta']['message_crash_plugins']) : ''); |
|
| 110 | + $crash = ($crash ?: []); |
|
| 111 | + $crash[$file] = true; |
|
| 112 | + ecrire_meta('message_crash_plugins', serialize($crash)); |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -135,7 +135,7 @@ discard block |
||
| 135 | 135 | * - string : chemin du fichier trouvé |
| 136 | 136 | **/ |
| 137 | 137 | function include_spip($f, $include = true) { |
| 138 | - return find_in_path($f . '.php', '', $include); |
|
| 138 | + return find_in_path($f . '.php', '', $include); |
|
| 139 | 139 | } |
| 140 | 140 | |
| 141 | 141 | /** |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | * - string : chemin du fichier trouvé |
| 156 | 156 | **/ |
| 157 | 157 | function require_spip($f) { |
| 158 | - return find_in_path($f . '.php', '', 'required'); |
|
| 158 | + return find_in_path($f . '.php', '', 'required'); |
|
| 159 | 159 | } |
| 160 | 160 | |
| 161 | 161 | |
@@ -165,27 +165,27 @@ discard block |
||
| 165 | 165 | * quand on a besoin dans le PHP de filtres/fonctions qui y sont definis |
| 166 | 166 | */ |
| 167 | 167 | function include_fichiers_fonctions() { |
| 168 | - static $done = false; |
|
| 169 | - if (!$done) { |
|
| 170 | - include_spip('inc/lang'); |
|
| 171 | - |
|
| 172 | - // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 173 | - // donc il faut l'inclure "en globals" |
|
| 174 | - if ($f = find_in_path('mes_fonctions.php')) { |
|
| 175 | - global $dossier_squelettes; |
|
| 176 | - include_once(_ROOT_CWD . $f); |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 180 | - // chargement optimise precompile |
|
| 181 | - include_once(_CACHE_PLUGINS_FCT); |
|
| 182 | - } |
|
| 183 | - if (test_espace_prive()) { |
|
| 184 | - include_spip('inc/filtres_ecrire'); |
|
| 185 | - } |
|
| 186 | - include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 187 | - $done = true; |
|
| 188 | - } |
|
| 168 | + static $done = false; |
|
| 169 | + if (!$done) { |
|
| 170 | + include_spip('inc/lang'); |
|
| 171 | + |
|
| 172 | + // NB: mes_fonctions peut initialiser $dossier_squelettes (old-style) |
|
| 173 | + // donc il faut l'inclure "en globals" |
|
| 174 | + if ($f = find_in_path('mes_fonctions.php')) { |
|
| 175 | + global $dossier_squelettes; |
|
| 176 | + include_once(_ROOT_CWD . $f); |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + if (@is_readable(_CACHE_PLUGINS_FCT)) { |
|
| 180 | + // chargement optimise precompile |
|
| 181 | + include_once(_CACHE_PLUGINS_FCT); |
|
| 182 | + } |
|
| 183 | + if (test_espace_prive()) { |
|
| 184 | + include_spip('inc/filtres_ecrire'); |
|
| 185 | + } |
|
| 186 | + include_spip('public/fonctions'); // charger les fichiers fonctions associes aux criteres, balises.. |
|
| 187 | + $done = true; |
|
| 188 | + } |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | |
@@ -198,59 +198,59 @@ discard block |
||
| 198 | 198 | * @return string |
| 199 | 199 | */ |
| 200 | 200 | function charger_fonction_url(string $quoi, string $type = '') { |
| 201 | - if ($type === 'defaut') { |
|
| 202 | - $objet = objet_type($quoi); |
|
| 203 | - if ( |
|
| 204 | - ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 205 | - || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 206 | - ) { |
|
| 207 | - return $f; |
|
| 208 | - } |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $url_type = $type; |
|
| 213 | - if (!$url_type) { |
|
| 214 | - $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 215 | - } |
|
| 216 | - |
|
| 217 | - // inclure le module d'url |
|
| 218 | - include_spip('urls/' . $url_type); |
|
| 219 | - |
|
| 220 | - switch ($quoi) { |
|
| 221 | - case 'page': |
|
| 222 | - if ( |
|
| 223 | - function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 224 | - || function_exists($f .= '_dist') |
|
| 225 | - // ou une fonction custom utilisateur independante du type d'url |
|
| 226 | - || function_exists($f = 'generer_url_page') |
|
| 227 | - || function_exists($f .= '_dist') |
|
| 228 | - ) { |
|
| 229 | - return $f; |
|
| 230 | - } |
|
| 231 | - // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 232 | - return ''; |
|
| 233 | - case 'objet': |
|
| 234 | - case 'decoder': |
|
| 235 | - default: |
|
| 236 | - $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 237 | - if ( |
|
| 238 | - function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 239 | - || function_exists($f .= '_dist') |
|
| 240 | - ) { |
|
| 241 | - return $f; |
|
| 242 | - } |
|
| 243 | - // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 244 | - // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 245 | - if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 246 | - return $f; |
|
| 247 | - } |
|
| 248 | - // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 249 | - if (!$type && $url_type !== 'page') { |
|
| 250 | - return charger_fonction_url($quoi, 'page'); |
|
| 251 | - } |
|
| 252 | - return ''; |
|
| 253 | - } |
|
| 201 | + if ($type === 'defaut') { |
|
| 202 | + $objet = objet_type($quoi); |
|
| 203 | + if ( |
|
| 204 | + ($f = charger_fonction('generer_' . $objet . '_url', 'urls', true)) |
|
| 205 | + || ($f = charger_fonction('generer_url_' . $objet, 'urls', true)) // deprecated |
|
| 206 | + ) { |
|
| 207 | + return $f; |
|
| 208 | + } |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $url_type = $type; |
|
| 213 | + if (!$url_type) { |
|
| 214 | + $url_type = $GLOBALS['type_urls'] ?? $GLOBALS['meta']['type_urls'] ?? 'page'; // sinon type "page" par défaut |
|
| 215 | + } |
|
| 216 | + |
|
| 217 | + // inclure le module d'url |
|
| 218 | + include_spip('urls/' . $url_type); |
|
| 219 | + |
|
| 220 | + switch ($quoi) { |
|
| 221 | + case 'page': |
|
| 222 | + if ( |
|
| 223 | + function_exists($f = "urls_{$url_type}_generer_url_page") |
|
| 224 | + || function_exists($f .= '_dist') |
|
| 225 | + // ou une fonction custom utilisateur independante du type d'url |
|
| 226 | + || function_exists($f = 'generer_url_page') |
|
| 227 | + || function_exists($f .= '_dist') |
|
| 228 | + ) { |
|
| 229 | + return $f; |
|
| 230 | + } |
|
| 231 | + // pas de compat ancienne version ici, c'est une nouvelle feature |
|
| 232 | + return ''; |
|
| 233 | + case 'objet': |
|
| 234 | + case 'decoder': |
|
| 235 | + default: |
|
| 236 | + $fquoi = ($quoi === 'objet' ? 'generer_url_objet' : 'decoder_url'); |
|
| 237 | + if ( |
|
| 238 | + function_exists($f = "urls_{$url_type}_{$fquoi}") |
|
| 239 | + || function_exists($f .= '_dist') |
|
| 240 | + ) { |
|
| 241 | + return $f; |
|
| 242 | + } |
|
| 243 | + // est-ce qu'on a une ancienne fonction urls_xxx_dist() ? |
|
| 244 | + // c'est un ancien module d'url, on appelle l'ancienne fonction qui fait tout |
|
| 245 | + if ($f = charger_fonction($url_type, 'urls', true)) { |
|
| 246 | + return $f; |
|
| 247 | + } |
|
| 248 | + // sinon on se rabat sur les urls page si ce n'est pas un type demande explicitement |
|
| 249 | + if (!$type && $url_type !== 'page') { |
|
| 250 | + return charger_fonction_url($quoi, 'page'); |
|
| 251 | + } |
|
| 252 | + return ''; |
|
| 253 | + } |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | |
@@ -261,7 +261,7 @@ discard block |
||
| 261 | 261 | * @return string |
| 262 | 262 | */ |
| 263 | 263 | function trouve_modele($nom) { |
| 264 | - return trouver_fond($nom, 'modeles/'); |
|
| 264 | + return trouver_fond($nom, 'modeles/'); |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | /** |
@@ -277,28 +277,28 @@ discard block |
||
| 277 | 277 | * @return array|string |
| 278 | 278 | */ |
| 279 | 279 | function trouver_fond($nom, $dir = '', $pathinfo = false) { |
| 280 | - $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 281 | - if (!$pathinfo) { |
|
| 282 | - return $f; |
|
| 283 | - } |
|
| 284 | - // renvoyer un tableau detaille si $pathinfo==true |
|
| 285 | - if ($f === null) { |
|
| 286 | - return [ |
|
| 287 | - 'extension' => _EXTENSION_SQUELETTES, |
|
| 288 | - 'filename' => '', |
|
| 289 | - 'fond' => '' |
|
| 290 | - ]; |
|
| 291 | - } |
|
| 292 | - $p = pathinfo($f); |
|
| 293 | - if (!isset($p['extension']) || !$p['extension']) { |
|
| 294 | - $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 295 | - } |
|
| 296 | - if (!isset($p['extension']) || !$p['filename']) { |
|
| 297 | - $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 298 | - } |
|
| 299 | - $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 300 | - |
|
| 301 | - return $p; |
|
| 280 | + $f = find_in_path($nom . '.' . _EXTENSION_SQUELETTES, $dir ? rtrim($dir, '/') . '/' : ''); |
|
| 281 | + if (!$pathinfo) { |
|
| 282 | + return $f; |
|
| 283 | + } |
|
| 284 | + // renvoyer un tableau detaille si $pathinfo==true |
|
| 285 | + if ($f === null) { |
|
| 286 | + return [ |
|
| 287 | + 'extension' => _EXTENSION_SQUELETTES, |
|
| 288 | + 'filename' => '', |
|
| 289 | + 'fond' => '' |
|
| 290 | + ]; |
|
| 291 | + } |
|
| 292 | + $p = pathinfo($f); |
|
| 293 | + if (!isset($p['extension']) || !$p['extension']) { |
|
| 294 | + $p['extension'] = _EXTENSION_SQUELETTES; |
|
| 295 | + } |
|
| 296 | + if (!isset($p['extension']) || !$p['filename']) { |
|
| 297 | + $p['filename'] = ($p['basename'] ? substr($p['basename'], 0, -strlen($p['extension']) - 1) : ''); |
|
| 298 | + } |
|
| 299 | + $p['fond'] = ($f ? substr($f, 0, -strlen($p['extension']) - 1) : ''); |
|
| 300 | + |
|
| 301 | + return $p; |
|
| 302 | 302 | } |
| 303 | 303 | |
| 304 | 304 | /** |
@@ -316,9 +316,9 @@ discard block |
||
| 316 | 316 | * Lien sur une icone d'aide |
| 317 | 317 | **/ |
| 318 | 318 | function aider($aide = '', $distante = false) { |
| 319 | - $aider = charger_fonction('aide', 'inc', true); |
|
| 319 | + $aider = charger_fonction('aide', 'inc', true); |
|
| 320 | 320 | |
| 321 | - return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 321 | + return $aider ? $aider($aide, '', [], $distante) : ''; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -339,19 +339,19 @@ discard block |
||
| 339 | 339 | * Nom de l'exec, sinon chaîne vide. |
| 340 | 340 | **/ |
| 341 | 341 | function tester_url_ecrire($nom) { |
| 342 | - static $exec = []; |
|
| 343 | - if (isset($exec[$nom])) { |
|
| 344 | - return $exec[$nom]; |
|
| 345 | - } |
|
| 346 | - // tester si c'est une page en squelette |
|
| 347 | - if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 348 | - return $exec[$nom] = 'fond'; |
|
| 349 | - } // echafaudage d'un fond ! |
|
| 350 | - elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 351 | - return $exec[$nom] = 'fond'; |
|
| 352 | - } |
|
| 353 | - // attention, il ne faut pas inclure l'exec ici |
|
| 354 | - // car sinon #URL_ECRIRE provoque des inclusions |
|
| 355 | - // et des define intrusifs potentiels |
|
| 356 | - return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 342 | + static $exec = []; |
|
| 343 | + if (isset($exec[$nom])) { |
|
| 344 | + return $exec[$nom]; |
|
| 345 | + } |
|
| 346 | + // tester si c'est une page en squelette |
|
| 347 | + if (trouver_fond($nom, 'prive/squelettes/contenu/')) { |
|
| 348 | + return $exec[$nom] = 'fond'; |
|
| 349 | + } // echafaudage d'un fond ! |
|
| 350 | + elseif (include_spip('public/styliser_par_z') && z_echafaudable($nom)) { |
|
| 351 | + return $exec[$nom] = 'fond'; |
|
| 352 | + } |
|
| 353 | + // attention, il ne faut pas inclure l'exec ici |
|
| 354 | + // car sinon #URL_ECRIRE provoque des inclusions |
|
| 355 | + // et des define intrusifs potentiels |
|
| 356 | + return $exec[$nom] = ((find_in_path("{$nom}.php", 'exec/') || charger_fonction($nom, 'exec', true)) ? $nom : ''); |
|
| 357 | 357 | } |
@@ -9,8 +9,8 @@ discard block |
||
| 9 | 9 | * @param string $ta Répertoire temporaire accessible |
| 10 | 10 | */ |
| 11 | 11 | function spip_initialisation($pi = null, $pa = null, $ti = null, $ta = null) { |
| 12 | - spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 13 | - spip_initialisation_suite(); |
|
| 12 | + spip_initialisation_core($pi, $pa, $ti, $ta); |
|
| 13 | + spip_initialisation_suite(); |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | /** |
@@ -30,313 +30,313 @@ discard block |
||
| 30 | 30 | * @param string $ta Répertoire temporaire accessible |
| 31 | 31 | */ |
| 32 | 32 | function spip_initialisation_core($pi = null, $pa = null, $ti = null, $ta = null) { |
| 33 | - static $too_late = 0; |
|
| 34 | - if ($too_late++) { |
|
| 35 | - return; |
|
| 36 | - } |
|
| 37 | - |
|
| 38 | - // Declaration des repertoires |
|
| 39 | - |
|
| 40 | - // le nom du repertoire plugins/ activables/desactivables |
|
| 41 | - if (!defined('_DIR_PLUGINS')) { |
|
| 42 | - define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 43 | - } |
|
| 44 | - |
|
| 45 | - // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 46 | - if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 47 | - define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // le nom du repertoire des librairies |
|
| 51 | - if (!defined('_DIR_LIB')) { |
|
| 52 | - define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // répertoire des libs via Composer |
|
| 56 | - if (!defined('_DIR_VENDOR')) { |
|
| 57 | - define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - if (!defined('_DIR_IMG')) { |
|
| 61 | - define('_DIR_IMG', $pa); |
|
| 62 | - } |
|
| 63 | - if (!defined('_DIR_LOGOS')) { |
|
| 64 | - define('_DIR_LOGOS', $pa); |
|
| 65 | - } |
|
| 66 | - if (!defined('_DIR_IMG_ICONES')) { |
|
| 67 | - define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - if (!defined('_DIR_DUMP')) { |
|
| 71 | - define('_DIR_DUMP', $ti . 'dump/'); |
|
| 72 | - } |
|
| 73 | - if (!defined('_DIR_SESSIONS')) { |
|
| 74 | - define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 75 | - } |
|
| 76 | - if (!defined('_DIR_TRANSFERT')) { |
|
| 77 | - define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 78 | - } |
|
| 79 | - if (!defined('_DIR_CACHE')) { |
|
| 80 | - define('_DIR_CACHE', $ti . 'cache/'); |
|
| 81 | - } |
|
| 82 | - if (!defined('_DIR_CACHE_XML')) { |
|
| 83 | - define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 84 | - } |
|
| 85 | - if (!defined('_DIR_SKELS')) { |
|
| 86 | - define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 87 | - } |
|
| 88 | - if (!defined('_DIR_AIDE')) { |
|
| 89 | - define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 90 | - } |
|
| 91 | - if (!defined('_DIR_TMP')) { |
|
| 92 | - define('_DIR_TMP', $ti); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (!defined('_DIR_VAR')) { |
|
| 96 | - define('_DIR_VAR', $ta); |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - if (!defined('_DIR_ETC')) { |
|
| 100 | - define('_DIR_ETC', $pi); |
|
| 101 | - } |
|
| 102 | - if (!defined('_DIR_CONNECT')) { |
|
| 103 | - define('_DIR_CONNECT', $pi); |
|
| 104 | - } |
|
| 105 | - if (!defined('_DIR_CHMOD')) { |
|
| 106 | - define('_DIR_CHMOD', $pi); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if (!isset($GLOBALS['test_dirs'])) { |
|
| 110 | - // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 111 | - // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 112 | - $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // Declaration des fichiers |
|
| 116 | - |
|
| 117 | - if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 118 | - define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 119 | - } |
|
| 120 | - if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 121 | - define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 122 | - } |
|
| 123 | - if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 124 | - define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 125 | - } |
|
| 126 | - if (!defined('_CACHE_PIPELINES')) { |
|
| 127 | - define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 128 | - } |
|
| 129 | - if (!defined('_CACHE_CHEMIN')) { |
|
| 130 | - define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 131 | - } |
|
| 132 | - |
|
| 133 | - # attention .php obligatoire pour ecrire_fichier_securise |
|
| 134 | - if (!defined('_FILE_META')) { |
|
| 135 | - define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 136 | - } |
|
| 137 | - if (!defined('_DIR_LOG')) { |
|
| 138 | - define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 139 | - } |
|
| 140 | - if (!defined('_FILE_LOG')) { |
|
| 141 | - define('_FILE_LOG', 'spip'); |
|
| 142 | - } |
|
| 143 | - if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 144 | - define('_FILE_LOG_SUFFIX', '.log'); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - // Le fichier de connexion a la base de donnees |
|
| 148 | - if (!defined('_FILE_CONNECT_INS')) { |
|
| 149 | - define('_FILE_CONNECT_INS', 'connect'); |
|
| 150 | - } |
|
| 151 | - if (!defined('_FILE_CONNECT')) { |
|
| 152 | - define( |
|
| 153 | - '_FILE_CONNECT', |
|
| 154 | - @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 155 | - ); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - // Le fichier de reglages des droits |
|
| 159 | - if (!defined('_FILE_CHMOD_INS')) { |
|
| 160 | - define('_FILE_CHMOD_INS', 'chmod'); |
|
| 161 | - } |
|
| 162 | - if (!defined('_FILE_CHMOD')) { |
|
| 163 | - define( |
|
| 164 | - '_FILE_CHMOD', |
|
| 165 | - @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 166 | - ); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - if (!defined('_FILE_LDAP')) { |
|
| 170 | - define('_FILE_LDAP', 'ldap.php'); |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 174 | - define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 175 | - } |
|
| 176 | - if (!defined('_FILE_CONNECT_TMP')) { |
|
| 177 | - define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 178 | - } |
|
| 179 | - if (!defined('_FILE_CHMOD_TMP')) { |
|
| 180 | - define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - // Definition des droits d'acces en ecriture |
|
| 184 | - if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 185 | - include_once _FILE_CHMOD; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Se mefier des fichiers mal remplis! |
|
| 189 | - if (!defined('_SPIP_CHMOD')) { |
|
| 190 | - define('_SPIP_CHMOD', 0777); |
|
| 191 | - } |
|
| 192 | - |
|
| 193 | - if (!defined('_DEFAULT_CHARSET')) { |
|
| 194 | - /** Le charset par défaut lors de l'installation */ |
|
| 195 | - define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 196 | - } |
|
| 197 | - if (!defined('_ROOT_PLUGINS')) { |
|
| 198 | - define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins' . DIRECTORY_SEPARATOR); |
|
| 199 | - } |
|
| 200 | - if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 201 | - define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist' . DIRECTORY_SEPARATOR); |
|
| 202 | - } |
|
| 203 | - if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 204 | - define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - // La taille des Log |
|
| 208 | - if (!defined('_MAX_LOG')) { |
|
| 209 | - define('_MAX_LOG', 100); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // Sommes-nous dans l'empire du Mal ? |
|
| 213 | - // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 214 | - if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 215 | - if (!defined('_OS_SERVEUR')) { |
|
| 216 | - define('_OS_SERVEUR', 'windows'); |
|
| 217 | - } |
|
| 218 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 219 | - define('_SPIP_LOCK_MODE', 1); |
|
| 220 | - } // utiliser le flock php |
|
| 221 | - } else { |
|
| 222 | - if (!defined('_OS_SERVEUR')) { |
|
| 223 | - define('_OS_SERVEUR', ''); |
|
| 224 | - } |
|
| 225 | - if (!defined('_SPIP_LOCK_MODE')) { |
|
| 226 | - define('_SPIP_LOCK_MODE', 1); |
|
| 227 | - } // utiliser le flock php |
|
| 228 | - #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // Langue par defaut |
|
| 232 | - if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 233 | - define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // |
|
| 237 | - // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 238 | - // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 239 | - // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 240 | - // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 241 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 242 | - |
|
| 243 | - // charger le path des plugins |
|
| 244 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 245 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - // *********** traiter les variables ************ |
|
| 249 | - |
|
| 250 | - // |
|
| 251 | - // Securite |
|
| 252 | - // |
|
| 253 | - |
|
| 254 | - // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 255 | - if (isset($_REQUEST['GLOBALS'])) { |
|
| 256 | - die(); |
|
| 257 | - } |
|
| 258 | - // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 259 | - spip_desinfecte($_GET); |
|
| 260 | - spip_desinfecte($_POST); |
|
| 261 | - spip_desinfecte($_COOKIE); |
|
| 262 | - spip_desinfecte($_REQUEST); |
|
| 263 | - |
|
| 264 | - // appliquer le cookie_prefix |
|
| 265 | - if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 266 | - include_spip('inc/cookie'); |
|
| 267 | - recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 268 | - } |
|
| 269 | - |
|
| 270 | - // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 271 | - if (isset($_SERVER['REQUEST_URI'])) { |
|
| 272 | - $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 273 | - } else { |
|
| 274 | - $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 275 | - if ( |
|
| 276 | - !empty($_SERVER['QUERY_STRING']) |
|
| 277 | - && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 278 | - ) { |
|
| 279 | - $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 284 | - if (!defined('_RENOUVELLE_ALEA')) { |
|
| 285 | - define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 286 | - } |
|
| 287 | - if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 288 | - define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - // charger les meta si possible et renouveller l'alea au besoin |
|
| 292 | - // charge aussi effacer_meta et ecrire_meta |
|
| 293 | - $inc_meta = charger_fonction('meta', 'inc'); |
|
| 294 | - $inc_meta(); |
|
| 295 | - |
|
| 296 | - // nombre de repertoires depuis la racine |
|
| 297 | - // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 298 | - // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 299 | - // le calcul est faux) |
|
| 300 | - if (!_DIR_RESTREINT) { |
|
| 301 | - $GLOBALS['profondeur_url'] = 1; |
|
| 302 | - } else { |
|
| 303 | - $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 304 | - $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 305 | - if ( |
|
| 306 | - !$uri_ref |
|
| 307 | - // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 308 | - // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 309 | - // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 310 | - // s'en remettre a l'adresse du site. alea jacta est. |
|
| 311 | - || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 312 | - ) { |
|
| 313 | - if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 314 | - $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 315 | - $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 316 | - } else { |
|
| 317 | - $uri_ref = ''; |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - if (!$uri || !$uri_ref) { |
|
| 321 | - $GLOBALS['profondeur_url'] = 0; |
|
| 322 | - } else { |
|
| 323 | - $GLOBALS['profondeur_url'] = max( |
|
| 324 | - 0, |
|
| 325 | - substr_count($uri[0], '/') |
|
| 326 | - - substr_count($uri_ref, '/') |
|
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 331 | - if (_FILE_CONNECT) { |
|
| 332 | - if ( |
|
| 333 | - verifier_visiteur() == '0minirezo' |
|
| 334 | - // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 335 | - && !isset($_COOKIE['spip_admin']) |
|
| 336 | - ) { |
|
| 337 | - clear_path_cache(); |
|
| 338 | - } |
|
| 339 | - } |
|
| 33 | + static $too_late = 0; |
|
| 34 | + if ($too_late++) { |
|
| 35 | + return; |
|
| 36 | + } |
|
| 37 | + |
|
| 38 | + // Declaration des repertoires |
|
| 39 | + |
|
| 40 | + // le nom du repertoire plugins/ activables/desactivables |
|
| 41 | + if (!defined('_DIR_PLUGINS')) { |
|
| 42 | + define('_DIR_PLUGINS', _DIR_RACINE . 'plugins/'); |
|
| 43 | + } |
|
| 44 | + |
|
| 45 | + // le nom du repertoire des extensions/ permanentes du core, toujours actives |
|
| 46 | + if (!defined('_DIR_PLUGINS_DIST')) { |
|
| 47 | + define('_DIR_PLUGINS_DIST', _DIR_RACINE . 'plugins-dist/'); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // le nom du repertoire des librairies |
|
| 51 | + if (!defined('_DIR_LIB')) { |
|
| 52 | + define('_DIR_LIB', _DIR_RACINE . 'lib/'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // répertoire des libs via Composer |
|
| 56 | + if (!defined('_DIR_VENDOR')) { |
|
| 57 | + define('_DIR_VENDOR', _DIR_RACINE . 'vendor/'); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + if (!defined('_DIR_IMG')) { |
|
| 61 | + define('_DIR_IMG', $pa); |
|
| 62 | + } |
|
| 63 | + if (!defined('_DIR_LOGOS')) { |
|
| 64 | + define('_DIR_LOGOS', $pa); |
|
| 65 | + } |
|
| 66 | + if (!defined('_DIR_IMG_ICONES')) { |
|
| 67 | + define('_DIR_IMG_ICONES', _DIR_LOGOS . 'icones/'); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + if (!defined('_DIR_DUMP')) { |
|
| 71 | + define('_DIR_DUMP', $ti . 'dump/'); |
|
| 72 | + } |
|
| 73 | + if (!defined('_DIR_SESSIONS')) { |
|
| 74 | + define('_DIR_SESSIONS', $ti . 'sessions/'); |
|
| 75 | + } |
|
| 76 | + if (!defined('_DIR_TRANSFERT')) { |
|
| 77 | + define('_DIR_TRANSFERT', $ti . 'upload/'); |
|
| 78 | + } |
|
| 79 | + if (!defined('_DIR_CACHE')) { |
|
| 80 | + define('_DIR_CACHE', $ti . 'cache/'); |
|
| 81 | + } |
|
| 82 | + if (!defined('_DIR_CACHE_XML')) { |
|
| 83 | + define('_DIR_CACHE_XML', _DIR_CACHE . 'xml/'); |
|
| 84 | + } |
|
| 85 | + if (!defined('_DIR_SKELS')) { |
|
| 86 | + define('_DIR_SKELS', _DIR_CACHE . 'skel/'); |
|
| 87 | + } |
|
| 88 | + if (!defined('_DIR_AIDE')) { |
|
| 89 | + define('_DIR_AIDE', _DIR_CACHE . 'aide/'); |
|
| 90 | + } |
|
| 91 | + if (!defined('_DIR_TMP')) { |
|
| 92 | + define('_DIR_TMP', $ti); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (!defined('_DIR_VAR')) { |
|
| 96 | + define('_DIR_VAR', $ta); |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + if (!defined('_DIR_ETC')) { |
|
| 100 | + define('_DIR_ETC', $pi); |
|
| 101 | + } |
|
| 102 | + if (!defined('_DIR_CONNECT')) { |
|
| 103 | + define('_DIR_CONNECT', $pi); |
|
| 104 | + } |
|
| 105 | + if (!defined('_DIR_CHMOD')) { |
|
| 106 | + define('_DIR_CHMOD', $pi); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if (!isset($GLOBALS['test_dirs'])) { |
|
| 110 | + // Pas $pi car il est bon de le mettre hors ecriture apres intstall |
|
| 111 | + // il sera rajoute automatiquement si besoin a l'etape 2 de l'install |
|
| 112 | + $GLOBALS['test_dirs'] = [$pa, $ti, $ta]; |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // Declaration des fichiers |
|
| 116 | + |
|
| 117 | + if (!defined('_CACHE_PLUGINS_PATH')) { |
|
| 118 | + define('_CACHE_PLUGINS_PATH', _DIR_CACHE . 'charger_plugins_chemins.php'); |
|
| 119 | + } |
|
| 120 | + if (!defined('_CACHE_PLUGINS_OPT')) { |
|
| 121 | + define('_CACHE_PLUGINS_OPT', _DIR_CACHE . 'charger_plugins_options.php'); |
|
| 122 | + } |
|
| 123 | + if (!defined('_CACHE_PLUGINS_FCT')) { |
|
| 124 | + define('_CACHE_PLUGINS_FCT', _DIR_CACHE . 'charger_plugins_fonctions.php'); |
|
| 125 | + } |
|
| 126 | + if (!defined('_CACHE_PIPELINES')) { |
|
| 127 | + define('_CACHE_PIPELINES', _DIR_CACHE . 'charger_pipelines.php'); |
|
| 128 | + } |
|
| 129 | + if (!defined('_CACHE_CHEMIN')) { |
|
| 130 | + define('_CACHE_CHEMIN', _DIR_CACHE . 'chemin.txt'); |
|
| 131 | + } |
|
| 132 | + |
|
| 133 | + # attention .php obligatoire pour ecrire_fichier_securise |
|
| 134 | + if (!defined('_FILE_META')) { |
|
| 135 | + define('_FILE_META', $ti . 'meta_cache.php'); |
|
| 136 | + } |
|
| 137 | + if (!defined('_DIR_LOG')) { |
|
| 138 | + define('_DIR_LOG', _DIR_TMP . 'log/'); |
|
| 139 | + } |
|
| 140 | + if (!defined('_FILE_LOG')) { |
|
| 141 | + define('_FILE_LOG', 'spip'); |
|
| 142 | + } |
|
| 143 | + if (!defined('_FILE_LOG_SUFFIX')) { |
|
| 144 | + define('_FILE_LOG_SUFFIX', '.log'); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + // Le fichier de connexion a la base de donnees |
|
| 148 | + if (!defined('_FILE_CONNECT_INS')) { |
|
| 149 | + define('_FILE_CONNECT_INS', 'connect'); |
|
| 150 | + } |
|
| 151 | + if (!defined('_FILE_CONNECT')) { |
|
| 152 | + define( |
|
| 153 | + '_FILE_CONNECT', |
|
| 154 | + @is_readable($f = _DIR_CONNECT . _FILE_CONNECT_INS . '.php') ? $f : false |
|
| 155 | + ); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + // Le fichier de reglages des droits |
|
| 159 | + if (!defined('_FILE_CHMOD_INS')) { |
|
| 160 | + define('_FILE_CHMOD_INS', 'chmod'); |
|
| 161 | + } |
|
| 162 | + if (!defined('_FILE_CHMOD')) { |
|
| 163 | + define( |
|
| 164 | + '_FILE_CHMOD', |
|
| 165 | + @is_readable($f = _DIR_CHMOD . _FILE_CHMOD_INS . '.php') ? $f : false |
|
| 166 | + ); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + if (!defined('_FILE_LDAP')) { |
|
| 170 | + define('_FILE_LDAP', 'ldap.php'); |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + if (!defined('_FILE_TMP_SUFFIX')) { |
|
| 174 | + define('_FILE_TMP_SUFFIX', '.tmp.php'); |
|
| 175 | + } |
|
| 176 | + if (!defined('_FILE_CONNECT_TMP')) { |
|
| 177 | + define('_FILE_CONNECT_TMP', _DIR_CONNECT . _FILE_CONNECT_INS . _FILE_TMP_SUFFIX); |
|
| 178 | + } |
|
| 179 | + if (!defined('_FILE_CHMOD_TMP')) { |
|
| 180 | + define('_FILE_CHMOD_TMP', _DIR_CHMOD . _FILE_CHMOD_INS . _FILE_TMP_SUFFIX); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + // Definition des droits d'acces en ecriture |
|
| 184 | + if (!defined('_SPIP_CHMOD') && _FILE_CHMOD) { |
|
| 185 | + include_once _FILE_CHMOD; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Se mefier des fichiers mal remplis! |
|
| 189 | + if (!defined('_SPIP_CHMOD')) { |
|
| 190 | + define('_SPIP_CHMOD', 0777); |
|
| 191 | + } |
|
| 192 | + |
|
| 193 | + if (!defined('_DEFAULT_CHARSET')) { |
|
| 194 | + /** Le charset par défaut lors de l'installation */ |
|
| 195 | + define('_DEFAULT_CHARSET', 'utf-8'); |
|
| 196 | + } |
|
| 197 | + if (!defined('_ROOT_PLUGINS')) { |
|
| 198 | + define('_ROOT_PLUGINS', _ROOT_RACINE . 'plugins' . DIRECTORY_SEPARATOR); |
|
| 199 | + } |
|
| 200 | + if (!defined('_ROOT_PLUGINS_DIST')) { |
|
| 201 | + define('_ROOT_PLUGINS_DIST', _ROOT_RACINE . 'plugins-dist' . DIRECTORY_SEPARATOR); |
|
| 202 | + } |
|
| 203 | + if (!defined('_ROOT_PLUGINS_SUPPL') && defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 204 | + define('_ROOT_PLUGINS_SUPPL', _ROOT_RACINE . str_replace(_DIR_RACINE, '', _DIR_PLUGINS_SUPPL)); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + // La taille des Log |
|
| 208 | + if (!defined('_MAX_LOG')) { |
|
| 209 | + define('_MAX_LOG', 100); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // Sommes-nous dans l'empire du Mal ? |
|
| 213 | + // (ou sous le signe du Pingouin, ascendant GNU ?) |
|
| 214 | + if (isset($_SERVER['SERVER_SOFTWARE']) && str_contains($_SERVER['SERVER_SOFTWARE'], '(Win')) { |
|
| 215 | + if (!defined('_OS_SERVEUR')) { |
|
| 216 | + define('_OS_SERVEUR', 'windows'); |
|
| 217 | + } |
|
| 218 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 219 | + define('_SPIP_LOCK_MODE', 1); |
|
| 220 | + } // utiliser le flock php |
|
| 221 | + } else { |
|
| 222 | + if (!defined('_OS_SERVEUR')) { |
|
| 223 | + define('_OS_SERVEUR', ''); |
|
| 224 | + } |
|
| 225 | + if (!defined('_SPIP_LOCK_MODE')) { |
|
| 226 | + define('_SPIP_LOCK_MODE', 1); |
|
| 227 | + } // utiliser le flock php |
|
| 228 | + #if (!defined('_SPIP_LOCK_MODE')) define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip mais link() est tres souvent interdite |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // Langue par defaut |
|
| 232 | + if (!defined('_LANGUE_PAR_DEFAUT')) { |
|
| 233 | + define('_LANGUE_PAR_DEFAUT', 'fr'); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // |
|
| 237 | + // Module de lecture/ecriture/suppression de fichiers utilisant flock() |
|
| 238 | + // (non surchargeable en l'etat ; attention si on utilise include_spip() |
|
| 239 | + // pour le rendre surchargeable, on va provoquer un reecriture |
|
| 240 | + // systematique du noyau ou une baisse de perfs => a etudier) |
|
| 241 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 242 | + |
|
| 243 | + // charger le path des plugins |
|
| 244 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 245 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + // *********** traiter les variables ************ |
|
| 249 | + |
|
| 250 | + // |
|
| 251 | + // Securite |
|
| 252 | + // |
|
| 253 | + |
|
| 254 | + // Ne pas se faire manger par un bug php qui accepte ?GLOBALS[truc]=toto |
|
| 255 | + if (isset($_REQUEST['GLOBALS'])) { |
|
| 256 | + die(); |
|
| 257 | + } |
|
| 258 | + // nettoyer les magic quotes \' et les caracteres nuls %00 |
|
| 259 | + spip_desinfecte($_GET); |
|
| 260 | + spip_desinfecte($_POST); |
|
| 261 | + spip_desinfecte($_COOKIE); |
|
| 262 | + spip_desinfecte($_REQUEST); |
|
| 263 | + |
|
| 264 | + // appliquer le cookie_prefix |
|
| 265 | + if ($GLOBALS['cookie_prefix'] != 'spip') { |
|
| 266 | + include_spip('inc/cookie'); |
|
| 267 | + recuperer_cookies_spip($GLOBALS['cookie_prefix']); |
|
| 268 | + } |
|
| 269 | + |
|
| 270 | + // Compatibilite avec serveurs ne fournissant pas $REQUEST_URI |
|
| 271 | + if (isset($_SERVER['REQUEST_URI'])) { |
|
| 272 | + $GLOBALS['REQUEST_URI'] = $_SERVER['REQUEST_URI']; |
|
| 273 | + } else { |
|
| 274 | + $GLOBALS['REQUEST_URI'] = (php_sapi_name() !== 'cli') ? $_SERVER['PHP_SELF'] : ''; |
|
| 275 | + if ( |
|
| 276 | + !empty($_SERVER['QUERY_STRING']) |
|
| 277 | + && !strpos($_SERVER['REQUEST_URI'], '?') |
|
| 278 | + ) { |
|
| 279 | + $GLOBALS['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING']; |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Duree de validite de l'alea pour les cookies et ce qui s'ensuit. |
|
| 284 | + if (!defined('_RENOUVELLE_ALEA')) { |
|
| 285 | + define('_RENOUVELLE_ALEA', 12 * 3600); |
|
| 286 | + } |
|
| 287 | + if (!defined('_DUREE_COOKIE_ADMIN')) { |
|
| 288 | + define('_DUREE_COOKIE_ADMIN', 14 * 24 * 3600); |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + // charger les meta si possible et renouveller l'alea au besoin |
|
| 292 | + // charge aussi effacer_meta et ecrire_meta |
|
| 293 | + $inc_meta = charger_fonction('meta', 'inc'); |
|
| 294 | + $inc_meta(); |
|
| 295 | + |
|
| 296 | + // nombre de repertoires depuis la racine |
|
| 297 | + // on compare a l'adresse de spip.php : $_SERVER["SCRIPT_NAME"] |
|
| 298 | + // ou a defaut celle donnee en meta ; (mais si celle-ci est fausse |
|
| 299 | + // le calcul est faux) |
|
| 300 | + if (!_DIR_RESTREINT) { |
|
| 301 | + $GLOBALS['profondeur_url'] = 1; |
|
| 302 | + } else { |
|
| 303 | + $uri = isset($_SERVER['REQUEST_URI']) ? explode('?', $_SERVER['REQUEST_URI']) : ''; |
|
| 304 | + $uri_ref = $_SERVER['SCRIPT_NAME']; |
|
| 305 | + if ( |
|
| 306 | + !$uri_ref |
|
| 307 | + // si on est appele avec un autre ti, on est sans doute en mutu |
|
| 308 | + // si jamais c'est de la mutu avec sous rep, on est perdu si on se fie |
|
| 309 | + // a spip.php qui est a la racine du spip, et vue qu'on sait pas se reperer |
|
| 310 | + // s'en remettre a l'adresse du site. alea jacta est. |
|
| 311 | + || $ti !== _NOM_TEMPORAIRES_INACCESSIBLES |
|
| 312 | + ) { |
|
| 313 | + if (isset($GLOBALS['meta']['adresse_site'])) { |
|
| 314 | + $uri_ref = parse_url($GLOBALS['meta']['adresse_site']); |
|
| 315 | + $uri_ref = ($uri_ref['path'] ?? '') . '/'; |
|
| 316 | + } else { |
|
| 317 | + $uri_ref = ''; |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + if (!$uri || !$uri_ref) { |
|
| 321 | + $GLOBALS['profondeur_url'] = 0; |
|
| 322 | + } else { |
|
| 323 | + $GLOBALS['profondeur_url'] = max( |
|
| 324 | + 0, |
|
| 325 | + substr_count($uri[0], '/') |
|
| 326 | + - substr_count($uri_ref, '/') |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + // s'il y a un cookie ou PHP_AUTH, initialiser visiteur_session |
|
| 331 | + if (_FILE_CONNECT) { |
|
| 332 | + if ( |
|
| 333 | + verifier_visiteur() == '0minirezo' |
|
| 334 | + // si c'est un admin sans cookie admin, il faut ignorer le cache chemin ! |
|
| 335 | + && !isset($_COOKIE['spip_admin']) |
|
| 336 | + ) { |
|
| 337 | + clear_path_cache(); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | 340 | } |
| 341 | 341 | |
| 342 | 342 | /** |
@@ -345,158 +345,158 @@ discard block |
||
| 345 | 345 | * |
| 346 | 346 | */ |
| 347 | 347 | function spip_initialisation_suite() { |
| 348 | - static $too_late = 0; |
|
| 349 | - if ($too_late++) { |
|
| 350 | - return; |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - // taille mini des login |
|
| 354 | - if (!defined('_LOGIN_TROP_COURT')) { |
|
| 355 | - define('_LOGIN_TROP_COURT', 4); |
|
| 356 | - } |
|
| 357 | - |
|
| 358 | - // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 359 | - #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 360 | - #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 361 | - #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 362 | - |
|
| 363 | - // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 364 | - #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 365 | - #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 366 | - #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 367 | - #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 368 | - |
|
| 369 | - if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 370 | - define('_PASS_LONGUEUR_MINI', 6); |
|
| 371 | - } |
|
| 372 | - |
|
| 373 | - // largeur maximale des images dans l'administration |
|
| 374 | - if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 375 | - define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 379 | - if (!defined('_IMG_QUALITE')) { |
|
| 380 | - define('_IMG_QUALITE', 85); |
|
| 381 | - } # valeur par defaut |
|
| 382 | - if (!defined('_IMG_GD_QUALITE')) { |
|
| 383 | - define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 384 | - } # surcharge pour la lib GD |
|
| 385 | - if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 386 | - define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 387 | - } # surcharge pour imagick en ligne de commande |
|
| 388 | - // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 389 | - if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 390 | - define('_IMG_IMAGICK_QUALITE', 75); |
|
| 391 | - } # surcharge pour imagick en PHP |
|
| 392 | - |
|
| 393 | - if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 394 | - define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 395 | - } // poids en octet |
|
| 396 | - |
|
| 397 | - // qq chaines standard |
|
| 398 | - if (!defined('_ACCESS_FILE_NAME')) { |
|
| 399 | - define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 400 | - } |
|
| 401 | - if (!defined('_AUTH_USER_FILE')) { |
|
| 402 | - define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 403 | - } |
|
| 404 | - if (!defined('_SPIP_DUMP')) { |
|
| 405 | - define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 406 | - } |
|
| 407 | - if (!defined('_CACHE_RUBRIQUES')) { |
|
| 408 | - /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 409 | - define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 410 | - } |
|
| 411 | - if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 412 | - /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 413 | - define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 414 | - } |
|
| 415 | - |
|
| 416 | - if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 417 | - /** |
|
| 418 | - * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 419 | - * @var int Nombre de caractères */ |
|
| 420 | - define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 424 | - define('_EXTENSION_SQUELETTES', 'html'); |
|
| 425 | - } |
|
| 426 | - |
|
| 427 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 428 | - /** Définit le doctype de l’espace privé */ |
|
| 429 | - define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 430 | - } |
|
| 431 | - if (!defined('_DOCTYPE_AIDE')) { |
|
| 432 | - /** Définit le doctype de l’aide en ligne */ |
|
| 433 | - define( |
|
| 434 | - '_DOCTYPE_AIDE', |
|
| 435 | - "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 436 | - ); |
|
| 437 | - } |
|
| 438 | - |
|
| 439 | - if (!defined('_SPIP_SCRIPT')) { |
|
| 440 | - /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 441 | - * le script de l'espace public, alias index.php */ |
|
| 442 | - define('_SPIP_SCRIPT', 'spip.php'); |
|
| 443 | - } |
|
| 444 | - if (!defined('_SPIP_PAGE')) { |
|
| 445 | - /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 446 | - define('_SPIP_PAGE', 'page'); |
|
| 447 | - } |
|
| 448 | - |
|
| 449 | - // le script de l'espace prive |
|
| 450 | - // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 451 | - // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 452 | - // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 453 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 454 | - if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 455 | - define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 456 | - } else { |
|
| 457 | - define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - |
|
| 462 | - if (!defined('_SPIP_AJAX')) { |
|
| 463 | - define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 464 | - ? 1 |
|
| 465 | - : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 466 | - } |
|
| 467 | - |
|
| 468 | - // La requete est-elle en ajax ? |
|
| 469 | - if (!defined('_AJAX')) { |
|
| 470 | - define( |
|
| 471 | - '_AJAX', |
|
| 472 | - ( |
|
| 473 | - isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 474 | - || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 475 | - || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 476 | - || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 477 | - ) |
|
| 478 | - && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 479 | - ); |
|
| 480 | - } |
|
| 481 | - |
|
| 482 | - # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 483 | - # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 484 | - # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 485 | - if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 486 | - define( |
|
| 487 | - '_IMG_GD_MAX_PIXELS', |
|
| 488 | - (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 489 | - ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 490 | - : 0 |
|
| 491 | - ); |
|
| 492 | - } |
|
| 493 | - |
|
| 494 | - // Protocoles a normaliser dans les chaines de langues |
|
| 495 | - if (!defined('_PROTOCOLES_STD')) { |
|
| 496 | - define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - init_var_mode(); |
|
| 348 | + static $too_late = 0; |
|
| 349 | + if ($too_late++) { |
|
| 350 | + return; |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + // taille mini des login |
|
| 354 | + if (!defined('_LOGIN_TROP_COURT')) { |
|
| 355 | + define('_LOGIN_TROP_COURT', 4); |
|
| 356 | + } |
|
| 357 | + |
|
| 358 | + // la taille maxi des logos (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 359 | + #if (!defined('_LOGO_MAX_SIZE')) define('_LOGO_MAX_SIZE', 0); # poids en ko |
|
| 360 | + #if (!defined('_LOGO_MAX_WIDTH')) define('_LOGO_MAX_WIDTH', 0); # largeur en pixels |
|
| 361 | + #if (!defined('_LOGO_MAX_HEIGHT')) define('_LOGO_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 362 | + |
|
| 363 | + // la taille maxi des images (0 : pas de limite) (pas de define par defaut, ce n'est pas utile) |
|
| 364 | + #if (!defined('_DOC_MAX_SIZE')) define('_DOC_MAX_SIZE', 0); # poids en ko |
|
| 365 | + #if (!defined('_IMG_MAX_SIZE')) define('_IMG_MAX_SIZE', 0); # poids en ko |
|
| 366 | + #if (!defined('_IMG_MAX_WIDTH')) define('_IMG_MAX_WIDTH', 0); # largeur en pixels |
|
| 367 | + #if (!defined('_IMG_MAX_HEIGHT')) define('_IMG_MAX_HEIGHT', 0); # hauteur en pixels |
|
| 368 | + |
|
| 369 | + if (!defined('_PASS_LONGUEUR_MINI')) { |
|
| 370 | + define('_PASS_LONGUEUR_MINI', 6); |
|
| 371 | + } |
|
| 372 | + |
|
| 373 | + // largeur maximale des images dans l'administration |
|
| 374 | + if (!defined('_IMG_ADMIN_MAX_WIDTH')) { |
|
| 375 | + define('_IMG_ADMIN_MAX_WIDTH', 768); |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + // Qualite des images calculees automatiquement. C'est un nombre entre 0 et 100, meme pour imagick (on ramene a 0..1 par la suite) |
|
| 379 | + if (!defined('_IMG_QUALITE')) { |
|
| 380 | + define('_IMG_QUALITE', 85); |
|
| 381 | + } # valeur par defaut |
|
| 382 | + if (!defined('_IMG_GD_QUALITE')) { |
|
| 383 | + define('_IMG_GD_QUALITE', _IMG_QUALITE); |
|
| 384 | + } # surcharge pour la lib GD |
|
| 385 | + if (!defined('_IMG_CONVERT_QUALITE')) { |
|
| 386 | + define('_IMG_CONVERT_QUALITE', _IMG_QUALITE); |
|
| 387 | + } # surcharge pour imagick en ligne de commande |
|
| 388 | + // Historiquement la valeur pour imagick semble differente. Si ca n'est pas necessaire, il serait preferable de garder _IMG_QUALITE |
|
| 389 | + if (!defined('_IMG_IMAGICK_QUALITE')) { |
|
| 390 | + define('_IMG_IMAGICK_QUALITE', 75); |
|
| 391 | + } # surcharge pour imagick en PHP |
|
| 392 | + |
|
| 393 | + if (!defined('_COPIE_LOCALE_MAX_SIZE')) { |
|
| 394 | + define('_COPIE_LOCALE_MAX_SIZE', 33_554_432); |
|
| 395 | + } // poids en octet |
|
| 396 | + |
|
| 397 | + // qq chaines standard |
|
| 398 | + if (!defined('_ACCESS_FILE_NAME')) { |
|
| 399 | + define('_ACCESS_FILE_NAME', '.htaccess'); |
|
| 400 | + } |
|
| 401 | + if (!defined('_AUTH_USER_FILE')) { |
|
| 402 | + define('_AUTH_USER_FILE', '.htpasswd'); |
|
| 403 | + } |
|
| 404 | + if (!defined('_SPIP_DUMP')) { |
|
| 405 | + define('_SPIP_DUMP', 'dump@nom_site@@[email protected]'); |
|
| 406 | + } |
|
| 407 | + if (!defined('_CACHE_RUBRIQUES')) { |
|
| 408 | + /** Fichier cache pour le navigateur de rubrique du bandeau */ |
|
| 409 | + define('_CACHE_RUBRIQUES', _DIR_TMP . 'menu-rubriques-cache.txt'); |
|
| 410 | + } |
|
| 411 | + if (!defined('_CACHE_RUBRIQUES_MAX')) { |
|
| 412 | + /** Nombre maxi de rubriques enfants affichées pour chaque rubrique du navigateur de rubrique du bandeau */ |
|
| 413 | + define('_CACHE_RUBRIQUES_MAX', 500); |
|
| 414 | + } |
|
| 415 | + |
|
| 416 | + if (!defined('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR')) { |
|
| 417 | + /** |
|
| 418 | + * Basculer les contextes ajax en fichier si la longueur d’url est trop grande |
|
| 419 | + * @var int Nombre de caractères */ |
|
| 420 | + define('_CACHE_CONTEXTES_AJAX_SUR_LONGUEUR', 2000); |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if (!defined('_EXTENSION_SQUELETTES')) { |
|
| 424 | + define('_EXTENSION_SQUELETTES', 'html'); |
|
| 425 | + } |
|
| 426 | + |
|
| 427 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 428 | + /** Définit le doctype de l’espace privé */ |
|
| 429 | + define('_DOCTYPE_ECRIRE', "<!DOCTYPE html>\n"); |
|
| 430 | + } |
|
| 431 | + if (!defined('_DOCTYPE_AIDE')) { |
|
| 432 | + /** Définit le doctype de l’aide en ligne */ |
|
| 433 | + define( |
|
| 434 | + '_DOCTYPE_AIDE', |
|
| 435 | + "<!DOCTYPE html PUBLIC '-//W3C//DTD HTML 4.01 Frameset//EN' 'http://www.w3.org/TR/1999/REC-html401-19991224/frameset.dtd'>" |
|
| 436 | + ); |
|
| 437 | + } |
|
| 438 | + |
|
| 439 | + if (!defined('_SPIP_SCRIPT')) { |
|
| 440 | + /** L'adresse de base du site ; on peut mettre '' si la racine est gerée par |
|
| 441 | + * le script de l'espace public, alias index.php */ |
|
| 442 | + define('_SPIP_SCRIPT', 'spip.php'); |
|
| 443 | + } |
|
| 444 | + if (!defined('_SPIP_PAGE')) { |
|
| 445 | + /** Argument page, personalisable en cas de conflit avec un autre script */ |
|
| 446 | + define('_SPIP_PAGE', 'page'); |
|
| 447 | + } |
|
| 448 | + |
|
| 449 | + // le script de l'espace prive |
|
| 450 | + // Mettre a "index.php" si DirectoryIndex ne le fait pas ou pb connexes: |
|
| 451 | + // les anciens IIS n'acceptent pas les POST sur ecrire/ (#419) |
|
| 452 | + // meme pb sur thttpd cf. https://forum.spip.net/fr_184153.html |
|
| 453 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 454 | + if (!empty($_SERVER['SERVER_SOFTWARE']) && preg_match(',IIS|thttpd,', $_SERVER['SERVER_SOFTWARE'])) { |
|
| 455 | + define('_SPIP_ECRIRE_SCRIPT', 'index.php'); |
|
| 456 | + } else { |
|
| 457 | + define('_SPIP_ECRIRE_SCRIPT', ''); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + |
|
| 462 | + if (!defined('_SPIP_AJAX')) { |
|
| 463 | + define('_SPIP_AJAX', ((!isset($_COOKIE['spip_accepte_ajax'])) |
|
| 464 | + ? 1 |
|
| 465 | + : (($_COOKIE['spip_accepte_ajax'] != -1) ? 1 : 0))); |
|
| 466 | + } |
|
| 467 | + |
|
| 468 | + // La requete est-elle en ajax ? |
|
| 469 | + if (!defined('_AJAX')) { |
|
| 470 | + define( |
|
| 471 | + '_AJAX', |
|
| 472 | + ( |
|
| 473 | + isset($_SERVER['HTTP_X_REQUESTED_WITH']) # ajax jQuery |
|
| 474 | + || !empty($_REQUEST['var_ajax_redir']) # redirection 302 apres ajax jQuer |
|
| 475 | + || !empty($_REQUEST['var_ajaxcharset']) # compat ascendante pour plugins |
|
| 476 | + || !empty($_REQUEST['var_ajax']) # forms ajax & inclure ajax de spip |
|
| 477 | + ) |
|
| 478 | + && empty($_REQUEST['var_noajax']) # horrible exception, car c'est pas parce que la requete est ajax jquery qu'il faut tuer tous les formulaires ajax qu'elle contient |
|
| 479 | + ); |
|
| 480 | + } |
|
| 481 | + |
|
| 482 | + # nombre de pixels maxi pour calcul de la vignette avec gd |
|
| 483 | + # au dela de 5500000 on considere que php n'est pas limite en memoire pour cette operation |
|
| 484 | + # les configurations limitees en memoire ont un seuil plutot vers 1MPixel |
|
| 485 | + if (!defined('_IMG_GD_MAX_PIXELS')) { |
|
| 486 | + define( |
|
| 487 | + '_IMG_GD_MAX_PIXELS', |
|
| 488 | + (isset($GLOBALS['meta']['max_taille_vignettes']) && $GLOBALS['meta']['max_taille_vignettes']) |
|
| 489 | + ? $GLOBALS['meta']['max_taille_vignettes'] |
|
| 490 | + : 0 |
|
| 491 | + ); |
|
| 492 | + } |
|
| 493 | + |
|
| 494 | + // Protocoles a normaliser dans les chaines de langues |
|
| 495 | + if (!defined('_PROTOCOLES_STD')) { |
|
| 496 | + define('_PROTOCOLES_STD', 'http|https|ftp|mailto|webcal'); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + init_var_mode(); |
|
| 500 | 500 | } |
| 501 | 501 | |
| 502 | 502 | /** |
@@ -530,134 +530,134 @@ discard block |
||
| 530 | 530 | * ` var_mode` (calcul ou recalcul). |
| 531 | 531 | */ |
| 532 | 532 | function init_var_mode() { |
| 533 | - static $done = false; |
|
| 534 | - if (!$done) { |
|
| 535 | - if (isset($_GET['var_mode'])) { |
|
| 536 | - $var_mode = explode(',', $_GET['var_mode']); |
|
| 537 | - // tout le monde peut calcul/recalcul |
|
| 538 | - if (!defined('_VAR_MODE')) { |
|
| 539 | - if (in_array('recalcul', $var_mode)) { |
|
| 540 | - define('_VAR_MODE', 'recalcul'); |
|
| 541 | - } elseif (in_array('calcul', $var_mode)) { |
|
| 542 | - define('_VAR_MODE', 'calcul'); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 546 | - if ($var_mode) { |
|
| 547 | - include_spip('inc/autoriser'); |
|
| 548 | - // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 549 | - if ( |
|
| 550 | - autoriser( |
|
| 551 | - ($_GET['var_mode'] == 'preview') |
|
| 552 | - ? 'previsualiser' |
|
| 553 | - : 'debug' |
|
| 554 | - ) |
|
| 555 | - ) { |
|
| 556 | - if (in_array('traduction', $var_mode)) { |
|
| 557 | - // forcer le calcul pour passer dans traduire |
|
| 558 | - if (!defined('_VAR_MODE')) { |
|
| 559 | - define('_VAR_MODE', 'calcul'); |
|
| 560 | - } |
|
| 561 | - // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 562 | - if (!defined('_VAR_NOCACHE')) { |
|
| 563 | - define('_VAR_NOCACHE', true); |
|
| 564 | - } |
|
| 565 | - $var_mode = array_diff($var_mode, ['traduction']); |
|
| 566 | - } |
|
| 567 | - if (in_array('preview', $var_mode)) { |
|
| 568 | - // basculer sur les criteres de preview dans les boucles |
|
| 569 | - if (!defined('_VAR_PREVIEW')) { |
|
| 570 | - define('_VAR_PREVIEW', true); |
|
| 571 | - } |
|
| 572 | - // forcer le calcul |
|
| 573 | - if (!defined('_VAR_MODE')) { |
|
| 574 | - define('_VAR_MODE', 'calcul'); |
|
| 575 | - } |
|
| 576 | - // et ne pas enregistrer de cache |
|
| 577 | - if (!defined('_VAR_NOCACHE')) { |
|
| 578 | - define('_VAR_NOCACHE', true); |
|
| 579 | - } |
|
| 580 | - $var_mode = array_diff($var_mode, ['preview']); |
|
| 581 | - } |
|
| 582 | - if (in_array('inclure', $var_mode)) { |
|
| 583 | - // forcer le compilo et ignorer les caches existants |
|
| 584 | - if (!defined('_VAR_MODE')) { |
|
| 585 | - define('_VAR_MODE', 'calcul'); |
|
| 586 | - } |
|
| 587 | - if (!defined('_VAR_INCLURE')) { |
|
| 588 | - define('_VAR_INCLURE', true); |
|
| 589 | - } |
|
| 590 | - // et ne pas enregistrer de cache |
|
| 591 | - if (!defined('_VAR_NOCACHE')) { |
|
| 592 | - define('_VAR_NOCACHE', true); |
|
| 593 | - } |
|
| 594 | - $var_mode = array_diff($var_mode, ['inclure']); |
|
| 595 | - } |
|
| 596 | - if (in_array('urls', $var_mode)) { |
|
| 597 | - // forcer le compilo et ignorer les caches existants |
|
| 598 | - if (!defined('_VAR_MODE')) { |
|
| 599 | - define('_VAR_MODE', 'calcul'); |
|
| 600 | - } |
|
| 601 | - if (!defined('_VAR_URLS')) { |
|
| 602 | - define('_VAR_URLS', true); |
|
| 603 | - } |
|
| 604 | - $var_mode = array_diff($var_mode, ['urls']); |
|
| 605 | - } |
|
| 606 | - if (in_array('images', $var_mode)) { |
|
| 607 | - // forcer le compilo et ignorer les caches existants |
|
| 608 | - if (!defined('_VAR_MODE')) { |
|
| 609 | - define('_VAR_MODE', 'calcul'); |
|
| 610 | - } |
|
| 611 | - // indiquer qu'on doit recalculer les images |
|
| 612 | - if (!defined('_VAR_IMAGES')) { |
|
| 613 | - define('_VAR_IMAGES', true); |
|
| 614 | - } |
|
| 615 | - $var_mode = array_diff($var_mode, ['images']); |
|
| 616 | - } |
|
| 617 | - if (in_array('debug', $var_mode)) { |
|
| 618 | - if (!defined('_VAR_MODE')) { |
|
| 619 | - define('_VAR_MODE', 'debug'); |
|
| 620 | - } |
|
| 621 | - // et ne pas enregistrer de cache |
|
| 622 | - if (!defined('_VAR_NOCACHE')) { |
|
| 623 | - define('_VAR_NOCACHE', true); |
|
| 624 | - } |
|
| 625 | - $var_mode = array_diff($var_mode, ['debug']); |
|
| 626 | - } |
|
| 627 | - if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 628 | - define('_VAR_MODE', reset($var_mode)); |
|
| 629 | - } |
|
| 630 | - if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 631 | - spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 632 | - . ' ' . _VAR_MODE); |
|
| 633 | - } |
|
| 634 | - } // pas autorise ? |
|
| 635 | - else { |
|
| 636 | - // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 637 | - if ( |
|
| 638 | - !$GLOBALS['visiteur_session'] |
|
| 639 | - && !empty($_SERVER['HTTP_HOST']) |
|
| 640 | - && !empty($_SERVER['REQUEST_METHOD']) |
|
| 641 | - && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 642 | - ) { |
|
| 643 | - $self = self('&', true); |
|
| 644 | - if (!str_contains($self, 'page=login')) { |
|
| 645 | - include_spip('inc/headers'); |
|
| 646 | - $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 647 | - redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - // sinon tant pis |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - if (!defined('_VAR_MODE')) { |
|
| 655 | - /** |
|
| 656 | - * Indique le mode de calcul ou d'affichage de la page. |
|
| 657 | - * @see init_var_mode() |
|
| 658 | - */ |
|
| 659 | - define('_VAR_MODE', false); |
|
| 660 | - } |
|
| 661 | - $done = true; |
|
| 662 | - } |
|
| 533 | + static $done = false; |
|
| 534 | + if (!$done) { |
|
| 535 | + if (isset($_GET['var_mode'])) { |
|
| 536 | + $var_mode = explode(',', $_GET['var_mode']); |
|
| 537 | + // tout le monde peut calcul/recalcul |
|
| 538 | + if (!defined('_VAR_MODE')) { |
|
| 539 | + if (in_array('recalcul', $var_mode)) { |
|
| 540 | + define('_VAR_MODE', 'recalcul'); |
|
| 541 | + } elseif (in_array('calcul', $var_mode)) { |
|
| 542 | + define('_VAR_MODE', 'calcul'); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + $var_mode = array_diff($var_mode, ['calcul', 'recalcul']); |
|
| 546 | + if ($var_mode) { |
|
| 547 | + include_spip('inc/autoriser'); |
|
| 548 | + // autoriser preview si preview seulement, et sinon autoriser debug |
|
| 549 | + if ( |
|
| 550 | + autoriser( |
|
| 551 | + ($_GET['var_mode'] == 'preview') |
|
| 552 | + ? 'previsualiser' |
|
| 553 | + : 'debug' |
|
| 554 | + ) |
|
| 555 | + ) { |
|
| 556 | + if (in_array('traduction', $var_mode)) { |
|
| 557 | + // forcer le calcul pour passer dans traduire |
|
| 558 | + if (!defined('_VAR_MODE')) { |
|
| 559 | + define('_VAR_MODE', 'calcul'); |
|
| 560 | + } |
|
| 561 | + // et ne pas enregistrer de cache pour ne pas trainer les surlignages sur d'autres pages |
|
| 562 | + if (!defined('_VAR_NOCACHE')) { |
|
| 563 | + define('_VAR_NOCACHE', true); |
|
| 564 | + } |
|
| 565 | + $var_mode = array_diff($var_mode, ['traduction']); |
|
| 566 | + } |
|
| 567 | + if (in_array('preview', $var_mode)) { |
|
| 568 | + // basculer sur les criteres de preview dans les boucles |
|
| 569 | + if (!defined('_VAR_PREVIEW')) { |
|
| 570 | + define('_VAR_PREVIEW', true); |
|
| 571 | + } |
|
| 572 | + // forcer le calcul |
|
| 573 | + if (!defined('_VAR_MODE')) { |
|
| 574 | + define('_VAR_MODE', 'calcul'); |
|
| 575 | + } |
|
| 576 | + // et ne pas enregistrer de cache |
|
| 577 | + if (!defined('_VAR_NOCACHE')) { |
|
| 578 | + define('_VAR_NOCACHE', true); |
|
| 579 | + } |
|
| 580 | + $var_mode = array_diff($var_mode, ['preview']); |
|
| 581 | + } |
|
| 582 | + if (in_array('inclure', $var_mode)) { |
|
| 583 | + // forcer le compilo et ignorer les caches existants |
|
| 584 | + if (!defined('_VAR_MODE')) { |
|
| 585 | + define('_VAR_MODE', 'calcul'); |
|
| 586 | + } |
|
| 587 | + if (!defined('_VAR_INCLURE')) { |
|
| 588 | + define('_VAR_INCLURE', true); |
|
| 589 | + } |
|
| 590 | + // et ne pas enregistrer de cache |
|
| 591 | + if (!defined('_VAR_NOCACHE')) { |
|
| 592 | + define('_VAR_NOCACHE', true); |
|
| 593 | + } |
|
| 594 | + $var_mode = array_diff($var_mode, ['inclure']); |
|
| 595 | + } |
|
| 596 | + if (in_array('urls', $var_mode)) { |
|
| 597 | + // forcer le compilo et ignorer les caches existants |
|
| 598 | + if (!defined('_VAR_MODE')) { |
|
| 599 | + define('_VAR_MODE', 'calcul'); |
|
| 600 | + } |
|
| 601 | + if (!defined('_VAR_URLS')) { |
|
| 602 | + define('_VAR_URLS', true); |
|
| 603 | + } |
|
| 604 | + $var_mode = array_diff($var_mode, ['urls']); |
|
| 605 | + } |
|
| 606 | + if (in_array('images', $var_mode)) { |
|
| 607 | + // forcer le compilo et ignorer les caches existants |
|
| 608 | + if (!defined('_VAR_MODE')) { |
|
| 609 | + define('_VAR_MODE', 'calcul'); |
|
| 610 | + } |
|
| 611 | + // indiquer qu'on doit recalculer les images |
|
| 612 | + if (!defined('_VAR_IMAGES')) { |
|
| 613 | + define('_VAR_IMAGES', true); |
|
| 614 | + } |
|
| 615 | + $var_mode = array_diff($var_mode, ['images']); |
|
| 616 | + } |
|
| 617 | + if (in_array('debug', $var_mode)) { |
|
| 618 | + if (!defined('_VAR_MODE')) { |
|
| 619 | + define('_VAR_MODE', 'debug'); |
|
| 620 | + } |
|
| 621 | + // et ne pas enregistrer de cache |
|
| 622 | + if (!defined('_VAR_NOCACHE')) { |
|
| 623 | + define('_VAR_NOCACHE', true); |
|
| 624 | + } |
|
| 625 | + $var_mode = array_diff($var_mode, ['debug']); |
|
| 626 | + } |
|
| 627 | + if (count($var_mode) && !defined('_VAR_MODE')) { |
|
| 628 | + define('_VAR_MODE', reset($var_mode)); |
|
| 629 | + } |
|
| 630 | + if (isset($GLOBALS['visiteur_session']['nom'])) { |
|
| 631 | + spip_log($GLOBALS['visiteur_session']['nom'] |
|
| 632 | + . ' ' . _VAR_MODE); |
|
| 633 | + } |
|
| 634 | + } // pas autorise ? |
|
| 635 | + else { |
|
| 636 | + // si on n'est pas connecte on se redirige, si on est pas en cli et pas deja en train de se loger |
|
| 637 | + if ( |
|
| 638 | + !$GLOBALS['visiteur_session'] |
|
| 639 | + && !empty($_SERVER['HTTP_HOST']) |
|
| 640 | + && !empty($_SERVER['REQUEST_METHOD']) |
|
| 641 | + && $_SERVER['REQUEST_METHOD'] === 'GET' |
|
| 642 | + ) { |
|
| 643 | + $self = self('&', true); |
|
| 644 | + if (!str_contains($self, 'page=login')) { |
|
| 645 | + include_spip('inc/headers'); |
|
| 646 | + $redirect = parametre_url(self('&', true), 'var_mode', $_GET['var_mode'], '&'); |
|
| 647 | + redirige_par_entete(generer_url_public('login', 'url=' . rawurlencode($redirect), true)); |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + // sinon tant pis |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + if (!defined('_VAR_MODE')) { |
|
| 655 | + /** |
|
| 656 | + * Indique le mode de calcul ou d'affichage de la page. |
|
| 657 | + * @see init_var_mode() |
|
| 658 | + */ |
|
| 659 | + define('_VAR_MODE', false); |
|
| 660 | + } |
|
| 661 | + $done = true; |
|
| 662 | + } |
|
| 663 | 663 | } |
@@ -13,61 +13,61 @@ discard block |
||
| 13 | 13 | * @param null|array $add List of «plugins» directories to add |
| 14 | 14 | */ |
| 15 | 15 | function spip_paths( |
| 16 | - null|array $add = null, |
|
| 16 | + null|array $add = null, |
|
| 17 | 17 | ): AggregatorInterface { |
| 18 | - static $paths = null; |
|
| 19 | - static $last_dossier_squelettes = null; |
|
| 20 | - |
|
| 21 | - $dossier_squelettes = $GLOBALS['dossier_squelettes'] ?? null; |
|
| 22 | - |
|
| 23 | - if ($paths === null) { |
|
| 24 | - $paths = new GroupAggregator(Group::cases(), _ROOT_CWD); |
|
| 25 | - $paths = $paths->with(Group::App, [ |
|
| 26 | - _DIR_RACINE, |
|
| 27 | - _DIR_RACINE . 'squelettes-dist/', |
|
| 28 | - _DIR_RACINE . 'prive/', |
|
| 29 | - _DIR_RESTREINT, |
|
| 30 | - ]); |
|
| 31 | - |
|
| 32 | - if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 33 | - $paths = $paths->with(Group::Templates, [_DIR_RACINE . 'squelettes']); |
|
| 34 | - } |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - if ($add !== null) { |
|
| 38 | - $paths = $paths->prepend(Group::Plugins, $add); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - if ($last_dossier_squelettes !== $dossier_squelettes) { |
|
| 42 | - // Et le(s) dossier(s) des squelettes nommes |
|
| 43 | - if ($dossier_squelettes !== '') { |
|
| 44 | - $ds = explode(':', $dossier_squelettes); |
|
| 45 | - foreach ($ds as $key => $directory) { |
|
| 46 | - if (!str_starts_with($directory, '/')) { |
|
| 47 | - $ds[$key] = _DIR_RACINE . $directory; |
|
| 48 | - } |
|
| 49 | - } |
|
| 50 | - $paths = $paths->with(Group::ExtraTemplates, $ds); |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - return $paths; |
|
| 18 | + static $paths = null; |
|
| 19 | + static $last_dossier_squelettes = null; |
|
| 20 | + |
|
| 21 | + $dossier_squelettes = $GLOBALS['dossier_squelettes'] ?? null; |
|
| 22 | + |
|
| 23 | + if ($paths === null) { |
|
| 24 | + $paths = new GroupAggregator(Group::cases(), _ROOT_CWD); |
|
| 25 | + $paths = $paths->with(Group::App, [ |
|
| 26 | + _DIR_RACINE, |
|
| 27 | + _DIR_RACINE . 'squelettes-dist/', |
|
| 28 | + _DIR_RACINE . 'prive/', |
|
| 29 | + _DIR_RESTREINT, |
|
| 30 | + ]); |
|
| 31 | + |
|
| 32 | + if (@is_dir(_DIR_RACINE . 'squelettes')) { |
|
| 33 | + $paths = $paths->with(Group::Templates, [_DIR_RACINE . 'squelettes']); |
|
| 34 | + } |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + if ($add !== null) { |
|
| 38 | + $paths = $paths->prepend(Group::Plugins, $add); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + if ($last_dossier_squelettes !== $dossier_squelettes) { |
|
| 42 | + // Et le(s) dossier(s) des squelettes nommes |
|
| 43 | + if ($dossier_squelettes !== '') { |
|
| 44 | + $ds = explode(':', $dossier_squelettes); |
|
| 45 | + foreach ($ds as $key => $directory) { |
|
| 46 | + if (!str_starts_with($directory, '/')) { |
|
| 47 | + $ds[$key] = _DIR_RACINE . $directory; |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | + $paths = $paths->with(Group::ExtraTemplates, $ds); |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + return $paths; |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | function spip_paths_loader(): Loader { |
| 58 | - static $loaders = []; |
|
| 59 | - static $cache = null; |
|
| 58 | + static $loaders = []; |
|
| 59 | + static $cache = null; |
|
| 60 | 60 | |
| 61 | - if ($cache === null) { |
|
| 62 | - $cache = new FlatFilesystem('paths', Path::makeAbsolute(_DIR_CACHE, _ROOT_CWD)); |
|
| 63 | - if (_request('var_mode')) { |
|
| 64 | - $cache->clear(); |
|
| 65 | - } |
|
| 66 | - } |
|
| 61 | + if ($cache === null) { |
|
| 62 | + $cache = new FlatFilesystem('paths', Path::makeAbsolute(_DIR_CACHE, _ROOT_CWD)); |
|
| 63 | + if (_request('var_mode')) { |
|
| 64 | + $cache->clear(); |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | 67 | |
| 68 | - $paths = spip_paths(); |
|
| 68 | + $paths = spip_paths(); |
|
| 69 | 69 | |
| 70 | - return $loaders[$paths->getHash()] ??= new Loader($paths, $cache); |
|
| 70 | + return $loaders[$paths->getHash()] ??= new Loader($paths, $cache); |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Liste des chemins, par ordre de priorité. |
| 103 | 103 | **/ |
| 104 | 104 | function _chemin(string|array|null $dir_path = null): array { |
| 105 | - if (is_array($dir_path) || strlen($dir_path)) { |
|
| 106 | - spip_paths(add: is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 107 | - } |
|
| 105 | + if (is_array($dir_path) || strlen($dir_path)) { |
|
| 106 | + spip_paths(add: is_array($dir_path) ? $dir_path : explode(':', $dir_path)); |
|
| 107 | + } |
|
| 108 | 108 | |
| 109 | - return creer_chemin(); |
|
| 109 | + return creer_chemin(); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | * @return array Liste de chemins |
| 116 | 116 | **/ |
| 117 | 117 | function creer_chemin(): array { |
| 118 | - $dirs = spip_paths()->getDirectories(); |
|
| 119 | - // canal historique: avec / sauf si '' |
|
| 120 | - return array_map(fn ($dir) => $dir === '' ? $dir : $dir . DIRECTORY_SEPARATOR, $dirs); |
|
| 118 | + $dirs = spip_paths()->getDirectories(); |
|
| 119 | + // canal historique: avec / sauf si '' |
|
| 120 | + return array_map(fn ($dir) => $dir === '' ? $dir : $dir . DIRECTORY_SEPARATOR, $dirs); |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | /** |
@@ -128,61 +128,61 @@ discard block |
||
| 128 | 128 | * @return string[] Nom des thèmes. |
| 129 | 129 | */ |
| 130 | 130 | function lister_themes_prives(): array { |
| 131 | - static $themes = null; |
|
| 132 | - if (is_null($themes)) { |
|
| 133 | - // si pas encore definie |
|
| 134 | - if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 135 | - define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 136 | - } |
|
| 137 | - $themes = [_SPIP_THEME_PRIVE]; |
|
| 138 | - // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 139 | - // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 140 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 141 | - if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 142 | - $prefs = unserialize($prefs); |
|
| 143 | - } else { |
|
| 144 | - $prefs = []; |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 148 | - if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 149 | - // placer le theme choisi en tete |
|
| 150 | - array_unshift($themes, $theme); |
|
| 151 | - } |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - return $themes; |
|
| 131 | + static $themes = null; |
|
| 132 | + if (is_null($themes)) { |
|
| 133 | + // si pas encore definie |
|
| 134 | + if (!defined('_SPIP_THEME_PRIVE')) { |
|
| 135 | + define('_SPIP_THEME_PRIVE', 'spip'); |
|
| 136 | + } |
|
| 137 | + $themes = [_SPIP_THEME_PRIVE]; |
|
| 138 | + // Lors d'une installation neuve, prefs n'est pas definie ; sinon, c'est un tableau sérialisé |
|
| 139 | + // FIXME: Aussitôt après une demande d'inscription, $prefs vaut une chaine statut_tmp; |
|
| 140 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 141 | + if (is_string($prefs) && stripos($prefs, 'a:') === 0) { |
|
| 142 | + $prefs = unserialize($prefs); |
|
| 143 | + } else { |
|
| 144 | + $prefs = []; |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $theme = $prefs['theme'] ?? $GLOBALS['theme_prive_defaut'] ?? null; |
|
| 148 | + if ($theme && $theme !== _SPIP_THEME_PRIVE) { |
|
| 149 | + // placer le theme choisi en tete |
|
| 150 | + array_unshift($themes, $theme); |
|
| 151 | + } |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + return $themes; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | function find_in_theme($file, $subdir = '', $include = false) { |
| 158 | - static $themefiles = []; |
|
| 159 | - if (isset($themefiles["$subdir$file"])) { |
|
| 160 | - return $themefiles["$subdir$file"]; |
|
| 161 | - } |
|
| 162 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 163 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 164 | - if ( |
|
| 165 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 166 | - && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 167 | - && ($f = find_in_theme("$file_svg_generique")) |
|
| 168 | - ) { |
|
| 169 | - if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 170 | - return $themefiles["$subdir$file"] = $fsize; |
|
| 171 | - } |
|
| 172 | - else { |
|
| 173 | - return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 174 | - } |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - $themes = lister_themes_prives(); |
|
| 178 | - foreach ($themes as $theme) { |
|
| 179 | - if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 180 | - return $themefiles["$subdir$file"] = $f; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 184 | - |
|
| 185 | - return $themefiles["$subdir$file"] = ''; |
|
| 158 | + static $themefiles = []; |
|
| 159 | + if (isset($themefiles["$subdir$file"])) { |
|
| 160 | + return $themefiles["$subdir$file"]; |
|
| 161 | + } |
|
| 162 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 163 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 164 | + if ( |
|
| 165 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $file, $m) |
|
| 166 | + && ($file_svg_generique = substr($file, 0, -strlen($m[0])) . '-xx.svg') |
|
| 167 | + && ($f = find_in_theme("$file_svg_generique")) |
|
| 168 | + ) { |
|
| 169 | + if (($fsize = substr($f, 0, -6) . $m[1] . '.svg') && file_exists($fsize)) { |
|
| 170 | + return $themefiles["$subdir$file"] = $fsize; |
|
| 171 | + } |
|
| 172 | + else { |
|
| 173 | + return $themefiles["$subdir$file"] = "$f?" . $m[1] . 'px'; |
|
| 174 | + } |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + $themes = lister_themes_prives(); |
|
| 178 | + foreach ($themes as $theme) { |
|
| 179 | + if ($f = find_in_path($file, "prive/themes/$theme/$subdir", $include)) { |
|
| 180 | + return $themefiles["$subdir$file"] = $f; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + spip_log("$file introuvable dans le theme prive " . reset($themes), 'theme'); |
|
| 184 | + |
|
| 185 | + return $themefiles["$subdir$file"] = ''; |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | |
@@ -206,31 +206,31 @@ discard block |
||
| 206 | 206 | * sinon chaîne vide. |
| 207 | 207 | **/ |
| 208 | 208 | function chemin_image($icone) { |
| 209 | - static $icone_renommer; |
|
| 210 | - if ($p = strpos($icone, '?')) { |
|
| 211 | - $icone = substr($icone, 0, $p); |
|
| 212 | - } |
|
| 213 | - // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 214 | - if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 215 | - return $icone; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 219 | - if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 220 | - return $f; |
|
| 221 | - } |
|
| 222 | - // sinon passer par le module de renommage |
|
| 223 | - if (is_null($icone_renommer)) { |
|
| 224 | - $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 225 | - } |
|
| 226 | - if ($icone_renommer) { |
|
| 227 | - [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 228 | - if (file_exists($icone)) { |
|
| 229 | - return $icone; |
|
| 230 | - } |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - return find_in_path($icone, _NOM_IMG_PACK); |
|
| 209 | + static $icone_renommer; |
|
| 210 | + if ($p = strpos($icone, '?')) { |
|
| 211 | + $icone = substr($icone, 0, $p); |
|
| 212 | + } |
|
| 213 | + // gerer le cas d'un double appel en evitant de refaire le travail inutilement |
|
| 214 | + if (str_contains($icone, '/') && file_exists($icone)) { |
|
| 215 | + return $icone; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // si c'est un nom d'image complet (article-24.png) essayer de le renvoyer direct |
|
| 219 | + if (preg_match(',[.](png|gif|jpg|webp|svg)$,', $icone) && ($f = find_in_theme("images/$icone"))) { |
|
| 220 | + return $f; |
|
| 221 | + } |
|
| 222 | + // sinon passer par le module de renommage |
|
| 223 | + if (is_null($icone_renommer)) { |
|
| 224 | + $icone_renommer = charger_fonction('icone_renommer', 'inc', true); |
|
| 225 | + } |
|
| 226 | + if ($icone_renommer) { |
|
| 227 | + [$icone, $fonction] = $icone_renommer($icone, ''); |
|
| 228 | + if (file_exists($icone)) { |
|
| 229 | + return $icone; |
|
| 230 | + } |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + return find_in_path($icone, _NOM_IMG_PACK); |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -262,38 +262,38 @@ discard block |
||
| 262 | 262 | **/ |
| 263 | 263 | function find_in_path(string $file, string $dirname = '', bool|string $include = false): ?string { |
| 264 | 264 | |
| 265 | - $loader = spip_paths_loader(); |
|
| 265 | + $loader = spip_paths_loader(); |
|
| 266 | 266 | |
| 267 | - if ($dirname) { |
|
| 268 | - $file = rtrim($dirname, '/') . '/' . $file; |
|
| 269 | - } |
|
| 267 | + if ($dirname) { |
|
| 268 | + $file = rtrim($dirname, '/') . '/' . $file; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - $path = $loader->get($file); |
|
| 272 | - // find in path retourne des chemins relatif, si possible |
|
| 273 | - if ($path !== null && str_starts_with($path, _ROOT_RACINE)) { |
|
| 274 | - $path = _DIR_RACINE . substr($path, strlen(_ROOT_RACINE)); |
|
| 275 | - } |
|
| 271 | + $path = $loader->get($file); |
|
| 272 | + // find in path retourne des chemins relatif, si possible |
|
| 273 | + if ($path !== null && str_starts_with($path, _ROOT_RACINE)) { |
|
| 274 | + $path = _DIR_RACINE . substr($path, strlen(_ROOT_RACINE)); |
|
| 275 | + } |
|
| 276 | 276 | |
| 277 | - if ($include === false) { |
|
| 278 | - return $path; |
|
| 279 | - } |
|
| 277 | + if ($include === false) { |
|
| 278 | + return $path; |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - if ($include === true) { |
|
| 282 | - if ($path === null) { |
|
| 283 | - return null; |
|
| 284 | - } |
|
| 285 | - return $loader->include($file) ? $path : null; |
|
| 286 | - } |
|
| 281 | + if ($include === true) { |
|
| 282 | + if ($path === null) { |
|
| 283 | + return null; |
|
| 284 | + } |
|
| 285 | + return $loader->include($file) ? $path : null; |
|
| 286 | + } |
|
| 287 | 287 | |
| 288 | - if ($include === 'required') { |
|
| 289 | - return $loader->require($file) ? $path : null; |
|
| 290 | - } |
|
| 288 | + if ($include === 'required') { |
|
| 289 | + return $loader->require($file) ? $path : null; |
|
| 290 | + } |
|
| 291 | 291 | |
| 292 | - throw new \InvalidArgumentException(sprintf('$include argument with "%s" value is incorrect.', $include)); |
|
| 292 | + throw new \InvalidArgumentException(sprintf('$include argument with "%s" value is incorrect.', $include)); |
|
| 293 | 293 | } |
| 294 | 294 | |
| 295 | 295 | function clear_path_cache() { |
| 296 | - spip_paths_loader()->getCache()->clear(); |
|
| 296 | + spip_paths_loader()->getCache()->clear(); |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | function load_path_cache() { |
@@ -320,31 +320,31 @@ discard block |
||
| 320 | 320 | * @return array |
| 321 | 321 | */ |
| 322 | 322 | function find_all_in_path($dir, $pattern, $recurs = false) { |
| 323 | - $liste_fichiers = []; |
|
| 324 | - $maxfiles = 10000; |
|
| 325 | - |
|
| 326 | - // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 327 | - // on a pas encore inclus flock.php |
|
| 328 | - if (!function_exists('preg_files')) { |
|
| 329 | - include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 330 | - } |
|
| 331 | - |
|
| 332 | - // Parcourir le chemin |
|
| 333 | - foreach (creer_chemin() as $d) { |
|
| 334 | - $f = $d . $dir; |
|
| 335 | - if (@is_dir($f)) { |
|
| 336 | - $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 337 | - foreach ($liste as $chemin) { |
|
| 338 | - $nom = basename($chemin); |
|
| 339 | - // ne prendre que les fichiers pas deja trouves |
|
| 340 | - // car find_in_path prend le premier qu'il trouve, |
|
| 341 | - // les autres sont donc masques |
|
| 342 | - if (!isset($liste_fichiers[$nom])) { |
|
| 343 | - $liste_fichiers[$nom] = $chemin; |
|
| 344 | - } |
|
| 345 | - } |
|
| 346 | - } |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - return $liste_fichiers; |
|
| 323 | + $liste_fichiers = []; |
|
| 324 | + $maxfiles = 10000; |
|
| 325 | + |
|
| 326 | + // cas borderline si dans mes_options on appelle redirige_par_entete qui utilise _T et charge un fichier de langue |
|
| 327 | + // on a pas encore inclus flock.php |
|
| 328 | + if (!function_exists('preg_files')) { |
|
| 329 | + include_once _ROOT_RESTREINT . 'inc/flock.php'; |
|
| 330 | + } |
|
| 331 | + |
|
| 332 | + // Parcourir le chemin |
|
| 333 | + foreach (creer_chemin() as $d) { |
|
| 334 | + $f = $d . $dir; |
|
| 335 | + if (@is_dir($f)) { |
|
| 336 | + $liste = preg_files($f, $pattern, $maxfiles - count($liste_fichiers), $recurs === true ? [] : $recurs); |
|
| 337 | + foreach ($liste as $chemin) { |
|
| 338 | + $nom = basename($chemin); |
|
| 339 | + // ne prendre que les fichiers pas deja trouves |
|
| 340 | + // car find_in_path prend le premier qu'il trouve, |
|
| 341 | + // les autres sont donc masques |
|
| 342 | + if (!isset($liste_fichiers[$nom])) { |
|
| 343 | + $liste_fichiers[$nom] = $chemin; |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | + } |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + return $liste_fichiers; |
|
| 350 | 350 | } |