@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Langue |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -39,35 +39,35 @@ discard block |
||
| 39 | 39 | **/ |
| 40 | 40 | function changer_langue($lang, $liste_langues = null) { |
| 41 | 41 | |
| 42 | - if (is_null($liste_langues)) { |
|
| 43 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | - } else { |
|
| 45 | - if (is_array($liste_langues)) { |
|
| 46 | - $liste_langues = implode(',', $liste_langues); |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | - |
|
| 51 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | - if (!$lang) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if ( |
|
| 59 | - strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | - or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | - and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | - ) { |
|
| 63 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | - |
|
| 67 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 42 | + if (is_null($liste_langues)) { |
|
| 43 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 44 | + } else { |
|
| 45 | + if (is_array($liste_langues)) { |
|
| 46 | + $liste_langues = implode(',', $liste_langues); |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 50 | + |
|
| 51 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 52 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 53 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 54 | + if (!$lang) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if ( |
|
| 59 | + strpos($liste_langues, (string) ",$lang,") !== false |
|
| 60 | + or ($lang = preg_replace(',_.*,', '', $lang) |
|
| 61 | + and str_contains($liste_langues, (string) ",$lang,")) |
|
| 62 | + ) { |
|
| 63 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 64 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 65 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 66 | + |
|
| 67 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | // |
@@ -80,9 +80,9 @@ discard block |
||
| 80 | 80 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 81 | 81 | |
| 82 | 82 | function choisir_traduction($trads, $lang = '') { |
| 83 | - $k = approcher_langue($trads, $lang); |
|
| 83 | + $k = approcher_langue($trads, $lang); |
|
| 84 | 84 | |
| 85 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 85 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | // retourne son 2e argument si c'est un index du premier |
@@ -90,21 +90,21 @@ discard block |
||
| 90 | 90 | // la langue X etant consideree comme une approche de X_Y |
| 91 | 91 | function approcher_langue($trads, $lang = '') { |
| 92 | 92 | |
| 93 | - if (!$lang) { |
|
| 94 | - $lang = $GLOBALS['spip_lang']; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - if (isset($trads[$lang])) { |
|
| 98 | - return $lang; |
|
| 99 | - } // cas des langues xx_yy |
|
| 100 | - else { |
|
| 101 | - $r = explode('_', $lang); |
|
| 102 | - if (isset($trads[$r[0]])) { |
|
| 103 | - return $r[0]; |
|
| 104 | - } |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - return ''; |
|
| 93 | + if (!$lang) { |
|
| 94 | + $lang = $GLOBALS['spip_lang']; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + if (isset($trads[$lang])) { |
|
| 98 | + return $lang; |
|
| 99 | + } // cas des langues xx_yy |
|
| 100 | + else { |
|
| 101 | + $r = explode('_', $lang); |
|
| 102 | + if (isset($trads[$r[0]])) { |
|
| 103 | + return $r[0]; |
|
| 104 | + } |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + return ''; |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |
@@ -119,10 +119,10 @@ discard block |
||
| 119 | 119 | * Nom de la langue, sinon son code. |
| 120 | 120 | **/ |
| 121 | 121 | function traduire_nom_langue($lang) { |
| 122 | - include_spip('inc/lang_liste'); |
|
| 123 | - include_spip('inc/charsets'); |
|
| 122 | + include_spip('inc/lang_liste'); |
|
| 123 | + include_spip('inc/charsets'); |
|
| 124 | 124 | |
| 125 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 125 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | // |
@@ -135,10 +135,10 @@ discard block |
||
| 135 | 135 | // hebreu a priori), 'droitier' sinon. |
| 136 | 136 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 137 | 137 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 138 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 138 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 139 | 139 | |
| 140 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | - $gaucher : $droitier; |
|
| 140 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 141 | + $gaucher : $droitier; |
|
| 142 | 142 | } |
| 143 | 143 | |
| 144 | 144 | // typo francaise ou anglaise ? |
@@ -147,29 +147,29 @@ discard block |
||
| 147 | 147 | // sinon determiner la typo en fonction de la langue courante |
| 148 | 148 | |
| 149 | 149 | function lang_typo($lang = '') { |
| 150 | - if (!$lang) { |
|
| 151 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | - } |
|
| 153 | - if ( |
|
| 154 | - $lang == 'eo' |
|
| 155 | - or $lang == 'fr' |
|
| 156 | - or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | - or $lang == 'cpf' |
|
| 158 | - ) { |
|
| 159 | - return 'fr'; |
|
| 160 | - } else { |
|
| 161 | - return 'en'; |
|
| 162 | - } |
|
| 150 | + if (!$lang) { |
|
| 151 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 152 | + } |
|
| 153 | + if ( |
|
| 154 | + $lang == 'eo' |
|
| 155 | + or $lang == 'fr' |
|
| 156 | + or strncmp($lang, 'fr_', 3) == 0 |
|
| 157 | + or $lang == 'cpf' |
|
| 158 | + ) { |
|
| 159 | + return 'fr'; |
|
| 160 | + } else { |
|
| 161 | + return 'en'; |
|
| 162 | + } |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 166 | 166 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 167 | 167 | function changer_typo($lang = '') { |
| 168 | - if ($lang) { |
|
| 169 | - $GLOBALS['lang_objet'] = $lang; |
|
| 170 | - } else { |
|
| 171 | - unset($GLOBALS['lang_objet']); |
|
| 172 | - } |
|
| 168 | + if ($lang) { |
|
| 169 | + $GLOBALS['lang_objet'] = $lang; |
|
| 170 | + } else { |
|
| 171 | + unset($GLOBALS['lang_objet']); |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | // |
@@ -179,58 +179,58 @@ discard block |
||
| 179 | 179 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 180 | 180 | // |
| 181 | 181 | function menu_langues($nom_select, $default = '') { |
| 182 | - include_spip('inc/actions'); |
|
| 183 | - |
|
| 184 | - $langues = liste_options_langues($nom_select); |
|
| 185 | - $ret = ''; |
|
| 186 | - if (!count($langues)) { |
|
| 187 | - return ''; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - if (!$default) { |
|
| 191 | - $default = $GLOBALS['spip_lang']; |
|
| 192 | - } |
|
| 193 | - foreach ($langues as $l) { |
|
| 194 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if (!test_espace_prive()) { |
|
| 199 | - $cible = self(); |
|
| 200 | - $base = ''; |
|
| 201 | - } else { |
|
| 202 | - $cible = self(); |
|
| 203 | - $base = spip_connect() ? 'base' : ''; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | - |
|
| 208 | - return generer_action_auteur( |
|
| 209 | - 'converser', |
|
| 210 | - $base, |
|
| 211 | - $cible, |
|
| 212 | - (select_langues($nom_select, $change, $ret) |
|
| 213 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | - " method='post'" |
|
| 215 | - ); |
|
| 182 | + include_spip('inc/actions'); |
|
| 183 | + |
|
| 184 | + $langues = liste_options_langues($nom_select); |
|
| 185 | + $ret = ''; |
|
| 186 | + if (!count($langues)) { |
|
| 187 | + return ''; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + if (!$default) { |
|
| 191 | + $default = $GLOBALS['spip_lang']; |
|
| 192 | + } |
|
| 193 | + foreach ($langues as $l) { |
|
| 194 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 195 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if (!test_espace_prive()) { |
|
| 199 | + $cible = self(); |
|
| 200 | + $base = ''; |
|
| 201 | + } else { |
|
| 202 | + $cible = self(); |
|
| 203 | + $base = spip_connect() ? 'base' : ''; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 207 | + |
|
| 208 | + return generer_action_auteur( |
|
| 209 | + 'converser', |
|
| 210 | + $base, |
|
| 211 | + $cible, |
|
| 212 | + (select_langues($nom_select, $change, $ret) |
|
| 213 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 214 | + " method='post'" |
|
| 215 | + ); |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | function select_langues($nom_select, $change, $options, $label = '') { |
| 219 | - static $cpt = 0; |
|
| 220 | - $id = 'menu_langues' . $cpt++; |
|
| 221 | - |
|
| 222 | - return |
|
| 223 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | - "<select name='$nom_select' id='$id' " |
|
| 225 | - . ((!test_espace_prive()) ? |
|
| 226 | - ("class='forml menu_langues'") : |
|
| 227 | - (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | - ("class='lang_ecrire'") : |
|
| 229 | - "class='fondl'")) |
|
| 230 | - . $change |
|
| 231 | - . ">\n" |
|
| 232 | - . $options |
|
| 233 | - . '</select>'; |
|
| 219 | + static $cpt = 0; |
|
| 220 | + $id = 'menu_langues' . $cpt++; |
|
| 221 | + |
|
| 222 | + return |
|
| 223 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 224 | + "<select name='$nom_select' id='$id' " |
|
| 225 | + . ((!test_espace_prive()) ? |
|
| 226 | + ("class='forml menu_langues'") : |
|
| 227 | + (($nom_select == 'var_lang_ecrire') ? |
|
| 228 | + ("class='lang_ecrire'") : |
|
| 229 | + "class='fondl'")) |
|
| 230 | + . $change |
|
| 231 | + . ">\n" |
|
| 232 | + . $options |
|
| 233 | + . '</select>'; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -252,34 +252,34 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function liste_options_langues($nom_select) { |
| 254 | 254 | |
| 255 | - switch ($nom_select) { |
|
| 256 | - # #MENU_LANG |
|
| 257 | - case 'var_lang': |
|
| 258 | - # menu de changement de la langue d'un article |
|
| 259 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | - case 'changer_lang': |
|
| 261 | - $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | - break; |
|
| 263 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | - # les langues presentes sous forme de fichiers de langue |
|
| 265 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | - case 'var_lang_ecrire': |
|
| 267 | - default: |
|
| 268 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | - init_langues(); |
|
| 270 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | - break; |
|
| 255 | + switch ($nom_select) { |
|
| 256 | + # #MENU_LANG |
|
| 257 | + case 'var_lang': |
|
| 258 | + # menu de changement de la langue d'un article |
|
| 259 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 260 | + case 'changer_lang': |
|
| 261 | + $langues = explode(',', $GLOBALS['meta']['langues_multilingue']); |
|
| 262 | + break; |
|
| 263 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 264 | + # les langues presentes sous forme de fichiers de langue |
|
| 265 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 266 | + case 'var_lang_ecrire': |
|
| 267 | + default: |
|
| 268 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 269 | + init_langues(); |
|
| 270 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 271 | + break; |
|
| 272 | 272 | |
| 273 | 273 | # dernier choix possible : toutes les langues = langues_proposees |
| 274 | 274 | # + langues_multilingues ; mais, ne sert pas |
| 275 | 275 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 276 | - } |
|
| 277 | - if (count($langues) <= 1) { |
|
| 278 | - return []; |
|
| 279 | - } |
|
| 280 | - sort($langues); |
|
| 276 | + } |
|
| 277 | + if (count($langues) <= 1) { |
|
| 278 | + return []; |
|
| 279 | + } |
|
| 280 | + sort($langues); |
|
| 281 | 281 | |
| 282 | - return $langues; |
|
| 282 | + return $langues; |
|
| 283 | 283 | } |
| 284 | 284 | |
| 285 | 285 | |
@@ -294,39 +294,39 @@ discard block |
||
| 294 | 294 | **/ |
| 295 | 295 | function verifier_lang_url() { |
| 296 | 296 | |
| 297 | - // quelle langue est demandee ? |
|
| 298 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | - } |
|
| 302 | - if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | - } |
|
| 305 | - if (isset($_GET['lang'])) { |
|
| 306 | - $lang_demandee = $_GET['lang']; |
|
| 307 | - } |
|
| 308 | - |
|
| 309 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | - if ( |
|
| 311 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | - and changer_langue($lang_demandee) |
|
| 313 | - and $lang_demandee != @$_GET['lang'] |
|
| 314 | - ) { |
|
| 315 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | - // ici on a besoin des var_truc |
|
| 317 | - foreach ($_GET as $var => $val) { |
|
| 318 | - if (!strncmp('var_', $var, 4)) { |
|
| 319 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - include_spip('inc/headers'); |
|
| 323 | - redirige_par_entete($destination); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | - // (pour criteres {lang}). |
|
| 329 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 297 | + // quelle langue est demandee ? |
|
| 298 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 299 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 300 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 301 | + } |
|
| 302 | + if (!test_espace_prive() and isset($_COOKIE['spip_lang'])) { |
|
| 303 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 304 | + } |
|
| 305 | + if (isset($_GET['lang'])) { |
|
| 306 | + $lang_demandee = $_GET['lang']; |
|
| 307 | + } |
|
| 308 | + |
|
| 309 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 310 | + if ( |
|
| 311 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 312 | + and changer_langue($lang_demandee) |
|
| 313 | + and $lang_demandee != @$_GET['lang'] |
|
| 314 | + ) { |
|
| 315 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 316 | + // ici on a besoin des var_truc |
|
| 317 | + foreach ($_GET as $var => $val) { |
|
| 318 | + if (!strncmp('var_', $var, 4)) { |
|
| 319 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + include_spip('inc/headers'); |
|
| 323 | + redirige_par_entete($destination); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 327 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 328 | + // (pour criteres {lang}). |
|
| 329 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 330 | 330 | } |
| 331 | 331 | |
| 332 | 332 | |
@@ -344,22 +344,22 @@ discard block |
||
| 344 | 344 | * La langue sélectionnée |
| 345 | 345 | **/ |
| 346 | 346 | function utiliser_langue_site($liste_langues = null) { |
| 347 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | - if ( |
|
| 349 | - isset($GLOBALS['meta']['langue_site']) |
|
| 350 | - // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | - // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | - and (!isset($GLOBALS['spip_lang']) |
|
| 353 | - or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | - ) { |
|
| 355 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | - } |
|
| 357 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - return $GLOBALS['spip_lang']; |
|
| 347 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 348 | + if ( |
|
| 349 | + isset($GLOBALS['meta']['langue_site']) |
|
| 350 | + // et si spip_langue est pas encore définie (ce que va faire changer_langue()) |
|
| 351 | + // ou qu'elle n'est pas identique à la langue du site |
|
| 352 | + and (!isset($GLOBALS['spip_lang']) |
|
| 353 | + or $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 354 | + ) { |
|
| 355 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 356 | + } |
|
| 357 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 358 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 359 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + return $GLOBALS['spip_lang']; |
|
| 363 | 363 | } |
| 364 | 364 | |
| 365 | 365 | /** |
@@ -378,35 +378,35 @@ discard block |
||
| 378 | 378 | **/ |
| 379 | 379 | function utiliser_langue_visiteur($liste_langues = null) { |
| 380 | 380 | |
| 381 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | - if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | - } |
|
| 385 | - |
|
| 386 | - $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | - if (isset($_COOKIE[$l])) { |
|
| 388 | - if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | - return $l; |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - |
|
| 393 | - if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | - if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | - return $l; |
|
| 396 | - } |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | - foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | - if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | - if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | - return $l; |
|
| 404 | - } |
|
| 405 | - } |
|
| 406 | - } |
|
| 407 | - } |
|
| 408 | - |
|
| 409 | - return utiliser_langue_site($liste_langues); |
|
| 381 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 382 | + if (is_null($liste_langues) and !test_espace_prive() and !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 383 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 384 | + } |
|
| 385 | + |
|
| 386 | + $l = (!test_espace_prive() ? 'spip_lang' : 'spip_lang_ecrire'); |
|
| 387 | + if (isset($_COOKIE[$l])) { |
|
| 388 | + if (changer_langue($l = $_COOKIE[$l], $liste_langues)) { |
|
| 389 | + return $l; |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + |
|
| 393 | + if (isset($GLOBALS['visiteur_session']['lang'])) { |
|
| 394 | + if (changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues)) { |
|
| 395 | + return $l; |
|
| 396 | + } |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 400 | + foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 401 | + if (preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r)) { |
|
| 402 | + if (changer_langue($l = strtolower($r[1]), $liste_langues)) { |
|
| 403 | + return $l; |
|
| 404 | + } |
|
| 405 | + } |
|
| 406 | + } |
|
| 407 | + } |
|
| 408 | + |
|
| 409 | + return utiliser_langue_site($liste_langues); |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -416,7 +416,7 @@ discard block |
||
| 416 | 416 | * @return int |
| 417 | 417 | */ |
| 418 | 418 | function match_langue($chaine) { |
| 419 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 419 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | /** |
@@ -434,36 +434,36 @@ discard block |
||
| 434 | 434 | **/ |
| 435 | 435 | function init_langues() { |
| 436 | 436 | |
| 437 | - // liste des langues dans les meta, sauf a l'install |
|
| 438 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | - |
|
| 440 | - $tout = []; |
|
| 441 | - if (!$all_langs) { |
|
| 442 | - // trouver tous les modules lang/spip_xx.php |
|
| 443 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | - foreach ($modules as $name => $path) { |
|
| 445 | - if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | - if (match_langue($regs[1])) { |
|
| 447 | - $tout[] = $regs[1]; |
|
| 448 | - } |
|
| 449 | - } |
|
| 450 | - } |
|
| 451 | - sort($tout); |
|
| 452 | - $tout = join(',', $tout); |
|
| 453 | - // Si les langues n'ont pas change, ne rien faire |
|
| 454 | - if ($tout != $all_langs) { |
|
| 455 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | - include_spip('inc/meta'); |
|
| 457 | - ecrire_meta('langues_proposees', $tout); |
|
| 458 | - } |
|
| 459 | - } |
|
| 460 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | - (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | - ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | - ecrire_meta('langue_site', $tout); |
|
| 466 | - } |
|
| 437 | + // liste des langues dans les meta, sauf a l'install |
|
| 438 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 439 | + |
|
| 440 | + $tout = []; |
|
| 441 | + if (!$all_langs) { |
|
| 442 | + // trouver tous les modules lang/spip_xx.php |
|
| 443 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 444 | + foreach ($modules as $name => $path) { |
|
| 445 | + if (preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs)) { |
|
| 446 | + if (match_langue($regs[1])) { |
|
| 447 | + $tout[] = $regs[1]; |
|
| 448 | + } |
|
| 449 | + } |
|
| 450 | + } |
|
| 451 | + sort($tout); |
|
| 452 | + $tout = join(',', $tout); |
|
| 453 | + // Si les langues n'ont pas change, ne rien faire |
|
| 454 | + if ($tout != $all_langs) { |
|
| 455 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 456 | + include_spip('inc/meta'); |
|
| 457 | + ecrire_meta('langues_proposees', $tout); |
|
| 458 | + } |
|
| 459 | + } |
|
| 460 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 461 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 462 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 463 | + (!$all_langs or (strpos(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,") !== false)) |
|
| 464 | + ? _LANGUE_PAR_DEFAUT : substr($all_langs, 0, strpos($all_langs, ',')); |
|
| 465 | + ecrire_meta('langue_site', $tout); |
|
| 466 | + } |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | /** |
@@ -477,10 +477,10 @@ discard block |
||
| 477 | 477 | * Code html de la balise <html> |
| 478 | 478 | **/ |
| 479 | 479 | function html_lang_attributes() { |
| 480 | - $lang = $GLOBALS['spip_lang']; |
|
| 481 | - $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 480 | + $lang = $GLOBALS['spip_lang']; |
|
| 481 | + $dir = ($GLOBALS['spip_lang_rtl'] ? 'rtl' : 'ltr'); |
|
| 482 | 482 | |
| 483 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 483 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | |
@@ -494,7 +494,7 @@ discard block |
||
| 494 | 494 | * @return string |
| 495 | 495 | */ |
| 496 | 496 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 497 | - return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 497 | + return ($spip_lang <> 'he') ? $spip_lang_rtl : ''; |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,44 +69,44 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - $mot = null; |
|
| 73 | - $get = null; |
|
| 74 | - $hash = null; |
|
| 75 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | - return $lien; |
|
| 77 | - } |
|
| 78 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | - $r = array_pad($r, 3, ''); |
|
| 72 | + $mot = null; |
|
| 73 | + $get = null; |
|
| 74 | + $hash = null; |
|
| 75 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 76 | + return $lien; |
|
| 77 | + } |
|
| 78 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 79 | + $r = array_pad($r, 3, ''); |
|
| 80 | 80 | |
| 81 | - return $r[1] . resolve_path($r[2]); |
|
| 82 | - } |
|
| 81 | + return $r[1] . resolve_path($r[2]); |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - # L'url site spip est un lien absolu aussi |
|
| 85 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | - return $lien; |
|
| 87 | - } |
|
| 84 | + # L'url site spip est un lien absolu aussi |
|
| 85 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 86 | + return $lien; |
|
| 87 | + } |
|
| 88 | 88 | |
| 89 | - # lien relatif, il faut verifier l'url de base |
|
| 90 | - # commencer par virer la chaine de get de l'url de base |
|
| 91 | - $dir = '/'; |
|
| 92 | - $debut = ''; |
|
| 93 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | - $debut = $regs[1]; |
|
| 95 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | - $mot = $regs[3]; |
|
| 97 | - $get = $regs[4] ?? ''; |
|
| 98 | - $hash = $regs[5] ?? ''; |
|
| 99 | - } |
|
| 100 | - switch (substr($lien, 0, 1)) { |
|
| 101 | - case '/': |
|
| 102 | - return $debut . resolve_path($lien); |
|
| 103 | - case '#': |
|
| 104 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | - case '': |
|
| 106 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | - default: |
|
| 108 | - return $debut . resolve_path($dir . $lien); |
|
| 109 | - } |
|
| 89 | + # lien relatif, il faut verifier l'url de base |
|
| 90 | + # commencer par virer la chaine de get de l'url de base |
|
| 91 | + $dir = '/'; |
|
| 92 | + $debut = ''; |
|
| 93 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 94 | + $debut = $regs[1]; |
|
| 95 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 96 | + $mot = $regs[3]; |
|
| 97 | + $get = $regs[4] ?? ''; |
|
| 98 | + $hash = $regs[5] ?? ''; |
|
| 99 | + } |
|
| 100 | + switch (substr($lien, 0, 1)) { |
|
| 101 | + case '/': |
|
| 102 | + return $debut . resolve_path($lien); |
|
| 103 | + case '#': |
|
| 104 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 105 | + case '': |
|
| 106 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 107 | + default: |
|
| 108 | + return $debut . resolve_path($dir . $lien); |
|
| 109 | + } |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | |
@@ -129,15 +129,15 @@ discard block |
||
| 129 | 129 | * @return string texte ou URL (en absolus) |
| 130 | 130 | **/ |
| 131 | 131 | function url_absolue($url, $base = '') { |
| 132 | - $url = trim((string) $url); |
|
| 133 | - if (strlen($url = trim($url)) == 0) { |
|
| 134 | - return ''; |
|
| 135 | - } |
|
| 136 | - if (!$base) { |
|
| 137 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | - } |
|
| 132 | + $url = trim((string) $url); |
|
| 133 | + if (strlen($url = trim($url)) == 0) { |
|
| 134 | + return ''; |
|
| 135 | + } |
|
| 136 | + if (!$base) { |
|
| 137 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 138 | + } |
|
| 139 | 139 | |
| 140 | - return suivre_lien($base, $url); |
|
| 140 | + return suivre_lien($base, $url); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | /** |
@@ -148,7 +148,7 @@ discard block |
||
| 148 | 148 | * @return string |
| 149 | 149 | */ |
| 150 | 150 | function protocole_implicite($url_absolue) { |
| 151 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 151 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -159,16 +159,16 @@ discard block |
||
| 159 | 159 | */ |
| 160 | 160 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 161 | 161 | |
| 162 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | - $protocole = $m[1]; |
|
| 164 | - if ( |
|
| 165 | - in_array($protocole, $protocoles_autorises) |
|
| 166 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | - ) { |
|
| 168 | - return true; |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - return false; |
|
| 162 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 163 | + $protocole = $m[1]; |
|
| 164 | + if ( |
|
| 165 | + in_array($protocole, $protocoles_autorises) |
|
| 166 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 167 | + ) { |
|
| 168 | + return true; |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + return false; |
|
| 172 | 172 | } |
| 173 | 173 | |
| 174 | 174 | /** |
@@ -185,27 +185,27 @@ discard block |
||
| 185 | 185 | * @return string texte avec des URLs absolues |
| 186 | 186 | **/ |
| 187 | 187 | function liens_absolus($texte, $base = '') { |
| 188 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | - if (!function_exists('extraire_attribut')) { |
|
| 190 | - include_spip('inc/filtres'); |
|
| 191 | - } |
|
| 192 | - foreach ($liens as $lien) { |
|
| 193 | - foreach (['href', 'src'] as $attr) { |
|
| 194 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | - if (strlen($href) > 0) { |
|
| 196 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 188 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 189 | + if (!function_exists('extraire_attribut')) { |
|
| 190 | + include_spip('inc/filtres'); |
|
| 191 | + } |
|
| 192 | + foreach ($liens as $lien) { |
|
| 193 | + foreach (['href', 'src'] as $attr) { |
|
| 194 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 195 | + if (strlen($href) > 0) { |
|
| 196 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | - return $texte; |
|
| 208 | + return $texte; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -221,11 +221,11 @@ discard block |
||
| 221 | 221 | * @return string texte ou URL (en absolus) |
| 222 | 222 | **/ |
| 223 | 223 | function abs_url($texte, $base = '') { |
| 224 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | - return url_absolue($texte, $base); |
|
| 226 | - } else { |
|
| 227 | - return liens_absolus($texte, $base); |
|
| 228 | - } |
|
| 224 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 225 | + return url_absolue($texte, $base); |
|
| 226 | + } else { |
|
| 227 | + return liens_absolus($texte, $base); |
|
| 228 | + } |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return string |
| 239 | 239 | */ |
| 240 | 240 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 241 | - if (is_null($flags)) { |
|
| 242 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | - } |
|
| 241 | + if (is_null($flags)) { |
|
| 242 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 245 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | /** |
@@ -255,9 +255,9 @@ discard block |
||
| 255 | 255 | * @return string |
| 256 | 256 | */ |
| 257 | 257 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 258 | - if (is_null($flags)) { |
|
| 259 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | - } |
|
| 258 | + if (is_null($flags)) { |
|
| 259 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 262 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 263 | 263 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** l'adresse du repertoire de telechargement et de decompactage des plugins */ |
| 24 | 24 | if (!defined('_DIR_PLUGINS_AUTO')) { |
| 25 | - define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 25 | + define('_DIR_PLUGINS_AUTO', _DIR_PLUGINS . 'auto/'); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #include_spip('inc/texte'); // ????? Appelle public/parametrer trop tot avant la reconstruction du chemin des plugins. |
@@ -47,27 +47,27 @@ discard block |
||
| 47 | 47 | * @return array |
| 48 | 48 | **/ |
| 49 | 49 | function liste_plugin_files($dir_plugins = null) { |
| 50 | - static $plugin_files = []; |
|
| 51 | - if (is_null($dir_plugins)) { |
|
| 52 | - $dir_plugins = _DIR_PLUGINS; |
|
| 53 | - } |
|
| 54 | - if ( |
|
| 55 | - !isset($plugin_files[$dir_plugins]) |
|
| 56 | - or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | - ) { |
|
| 58 | - $plugin_files[$dir_plugins] = []; |
|
| 59 | - foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | - $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - sort($plugin_files[$dir_plugins]); |
|
| 64 | - // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | - // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | - $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return $plugin_files[$dir_plugins]; |
|
| 50 | + static $plugin_files = []; |
|
| 51 | + if (is_null($dir_plugins)) { |
|
| 52 | + $dir_plugins = _DIR_PLUGINS; |
|
| 53 | + } |
|
| 54 | + if ( |
|
| 55 | + !isset($plugin_files[$dir_plugins]) |
|
| 56 | + or (is_countable($plugin_files[$dir_plugins]) ? count($plugin_files[$dir_plugins]) : 0) == 0 |
|
| 57 | + ) { |
|
| 58 | + $plugin_files[$dir_plugins] = []; |
|
| 59 | + foreach (fast_find_plugin_dirs($dir_plugins) as $plugin) { |
|
| 60 | + $plugin_files[$dir_plugins][] = substr($plugin, strlen($dir_plugins)); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + sort($plugin_files[$dir_plugins]); |
|
| 64 | + // et on lit le XML de tous les plugins pour le mettre en cache |
|
| 65 | + // et en profiter pour nettoyer ceux qui n'existent plus du cache |
|
| 66 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 67 | + $get_infos($plugin_files[$dir_plugins], false, $dir_plugins, true); |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return $plugin_files[$dir_plugins]; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -83,45 +83,45 @@ discard block |
||
| 83 | 83 | * Liste complète des répeertoires |
| 84 | 84 | **/ |
| 85 | 85 | function fast_find_plugin_dirs($dir, $max_prof = 100) { |
| 86 | - $fichiers = []; |
|
| 87 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | - if ($dir == '') { |
|
| 91 | - $dir = '.'; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if (!is_dir($dir)) { |
|
| 95 | - return $fichiers; |
|
| 96 | - } |
|
| 97 | - if (is_plugin_dir($dir, '')) { |
|
| 98 | - $fichiers[] = $dir; |
|
| 99 | - |
|
| 100 | - return $fichiers; |
|
| 101 | - } |
|
| 102 | - if ($max_prof <= 0) { |
|
| 103 | - return $fichiers; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $subdirs = []; |
|
| 107 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | - while (($f = readdir($d)) !== false) { |
|
| 109 | - if ( |
|
| 110 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | - and $f != 'CVS' |
|
| 112 | - and is_dir($f = "$dir/$f") |
|
| 113 | - ) { |
|
| 114 | - $subdirs[] = $f; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - closedir($d); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - foreach ($subdirs as $d) { |
|
| 121 | - $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $fichiers; |
|
| 86 | + $fichiers = []; |
|
| 87 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 88 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 89 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 90 | + if ($dir == '') { |
|
| 91 | + $dir = '.'; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if (!is_dir($dir)) { |
|
| 95 | + return $fichiers; |
|
| 96 | + } |
|
| 97 | + if (is_plugin_dir($dir, '')) { |
|
| 98 | + $fichiers[] = $dir; |
|
| 99 | + |
|
| 100 | + return $fichiers; |
|
| 101 | + } |
|
| 102 | + if ($max_prof <= 0) { |
|
| 103 | + return $fichiers; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $subdirs = []; |
|
| 107 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 108 | + while (($f = readdir($d)) !== false) { |
|
| 109 | + if ( |
|
| 110 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 111 | + and $f != 'CVS' |
|
| 112 | + and is_dir($f = "$dir/$f") |
|
| 113 | + ) { |
|
| 114 | + $subdirs[] = $f; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + closedir($d); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + foreach ($subdirs as $d) { |
|
| 121 | + $fichiers = array_merge($fichiers, fast_find_plugin_dirs("$d/", $max_prof - 1)); |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $fichiers; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -142,27 +142,27 @@ discard block |
||
| 142 | 142 | **/ |
| 143 | 143 | function is_plugin_dir($dir, $dir_plugins = null) { |
| 144 | 144 | |
| 145 | - if (is_array($dir)) { |
|
| 146 | - foreach ($dir as $k => $d) { |
|
| 147 | - if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | - unset($dir[$k]); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - return $dir; |
|
| 153 | - } |
|
| 154 | - if (is_null($dir_plugins)) { |
|
| 155 | - $dir_plugins = _DIR_PLUGINS; |
|
| 156 | - } |
|
| 157 | - $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | - |
|
| 159 | - foreach ($search as $s) { |
|
| 160 | - if (file_exists($s)) { |
|
| 161 | - return $dir; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - return ''; |
|
| 145 | + if (is_array($dir)) { |
|
| 146 | + foreach ($dir as $k => $d) { |
|
| 147 | + if (!is_plugin_dir($d, $dir_plugins)) { |
|
| 148 | + unset($dir[$k]); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + return $dir; |
|
| 153 | + } |
|
| 154 | + if (is_null($dir_plugins)) { |
|
| 155 | + $dir_plugins = _DIR_PLUGINS; |
|
| 156 | + } |
|
| 157 | + $search = ["$dir_plugins$dir/paquet.xml"]; |
|
| 158 | + |
|
| 159 | + foreach ($search as $s) { |
|
| 160 | + if (file_exists($s)) { |
|
| 161 | + return $dir; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + return ''; |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** Regexp d'extraction des informations d'un intervalle de compatibilité */ |
@@ -189,51 +189,51 @@ discard block |
||
| 189 | 189 | **/ |
| 190 | 190 | function plugin_version_compatible($intervalle, $version, $avec_quoi = '') { |
| 191 | 191 | |
| 192 | - if (!strlen($intervalle)) { |
|
| 193 | - return true; |
|
| 194 | - } |
|
| 195 | - if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | - return false; |
|
| 197 | - } |
|
| 198 | - // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | - // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | - $minimum = $regs[1]; |
|
| 201 | - $maximum = $regs[2]; |
|
| 202 | - |
|
| 203 | - // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | - // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | - // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | - // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | - // entre plugins) |
|
| 208 | - if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | - if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | - // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - $minimum_inc = $intervalle[0] == '['; |
|
| 217 | - $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | - |
|
| 219 | - if (strlen($minimum)) { |
|
| 220 | - if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | - return false; |
|
| 222 | - } |
|
| 223 | - if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | - return false; |
|
| 225 | - } |
|
| 226 | - } |
|
| 227 | - if (strlen($maximum)) { |
|
| 228 | - if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | - return false; |
|
| 230 | - } |
|
| 231 | - if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | - return false; |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - return true; |
|
| 192 | + if (!strlen($intervalle)) { |
|
| 193 | + return true; |
|
| 194 | + } |
|
| 195 | + if (!preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 196 | + return false; |
|
| 197 | + } |
|
| 198 | + // Extraction des bornes et traitement de * pour la borne sup : |
|
| 199 | + // -- on autorise uniquement les ecritures 3.0.*, 3.* |
|
| 200 | + $minimum = $regs[1]; |
|
| 201 | + $maximum = $regs[2]; |
|
| 202 | + |
|
| 203 | + // si une version SPIP de compatibilité a été définie (dans |
|
| 204 | + // mes_options.php, sous la forme : define('_DEV_VERSION_SPIP_COMPAT', '3.1.0'); |
|
| 205 | + // on l'utilise (phase de dev, de test...) mais *que* en cas de comparaison |
|
| 206 | + // avec la version de SPIP (ne nuit donc pas aux tests de necessite |
|
| 207 | + // entre plugins) |
|
| 208 | + if (defined('_DEV_VERSION_SPIP_COMPAT') and $avec_quoi == 'spip' and $version !== _DEV_VERSION_SPIP_COMPAT) { |
|
| 209 | + if (plugin_version_compatible($intervalle, _DEV_VERSION_SPIP_COMPAT, $avec_quoi)) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + // si pas de compatibilite avec _DEV_VERSION_SPIP_COMPAT, on essaye quand meme avec la vrai version |
|
| 213 | + // cas du plugin qui n'est compatible qu'avec cette nouvelle version |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + $minimum_inc = $intervalle[0] == '['; |
|
| 217 | + $maximum_inc = substr($intervalle, -1) == ']'; |
|
| 218 | + |
|
| 219 | + if (strlen($minimum)) { |
|
| 220 | + if ($minimum_inc and spip_version_compare($version, $minimum, '<')) { |
|
| 221 | + return false; |
|
| 222 | + } |
|
| 223 | + if (!$minimum_inc and spip_version_compare($version, $minimum, '<=')) { |
|
| 224 | + return false; |
|
| 225 | + } |
|
| 226 | + } |
|
| 227 | + if (strlen($maximum)) { |
|
| 228 | + if ($maximum_inc and spip_version_compare($version, $maximum, '>')) { |
|
| 229 | + return false; |
|
| 230 | + } |
|
| 231 | + if (!$maximum_inc and spip_version_compare($version, $maximum, '>=')) { |
|
| 232 | + return false; |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + return true; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -250,62 +250,62 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function liste_plugin_valides($liste_plug, $force = false) { |
| 253 | - $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | - $infos = [ |
|
| 256 | - // lister les extensions qui sont automatiquement actives |
|
| 257 | - '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | - '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | - ]; |
|
| 260 | - |
|
| 261 | - // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | - // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | - $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | - $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | - $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | - $liste_non_classee = [ |
|
| 267 | - 'SPIP' => [ |
|
| 268 | - 'nom' => 'SPIP', |
|
| 269 | - 'etat' => 'stable', |
|
| 270 | - 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | - 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | - 'dir' => '', |
|
| 273 | - ] |
|
| 274 | - ]; |
|
| 275 | - |
|
| 276 | - $invalides = []; |
|
| 277 | - foreach ($liste_ext as $plug) { |
|
| 278 | - if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | - plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - foreach ($liste_plug as $plug) { |
|
| 283 | - if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | - if (is_array($r)) { |
|
| 286 | - $invalides = array_merge($invalides, $r); |
|
| 287 | - } |
|
| 288 | - } |
|
| 289 | - } |
|
| 290 | - |
|
| 291 | - if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | - $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | - foreach ($liste_plug as $plug) { |
|
| 294 | - if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | - $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | - if (is_array($r)) { |
|
| 297 | - $invalides = array_merge($invalides, $r); |
|
| 298 | - } |
|
| 299 | - } |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - |
|
| 303 | - plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | - |
|
| 305 | - // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | - $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | - |
|
| 308 | - return [$infos, $liste_non_classee, $invalides]; |
|
| 253 | + $liste_ext = liste_plugin_files(_DIR_PLUGINS_DIST); |
|
| 254 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 255 | + $infos = [ |
|
| 256 | + // lister les extensions qui sont automatiquement actives |
|
| 257 | + '_DIR_PLUGINS_DIST' => $get_infos($liste_ext, $force, _DIR_PLUGINS_DIST), |
|
| 258 | + '_DIR_PLUGINS' => $get_infos($liste_plug, $force, _DIR_PLUGINS) |
|
| 259 | + ]; |
|
| 260 | + |
|
| 261 | + // creer une premiere liste non ordonnee mais qui ne retient |
|
| 262 | + // que les plugins valides, et dans leur derniere version en cas de doublon |
|
| 263 | + $infos['_DIR_RESTREINT'][''] = $get_infos('./', $force, _DIR_RESTREINT); |
|
| 264 | + $infos['_DIR_RESTREINT']['SPIP']['version'] = $GLOBALS['spip_version_branche']; |
|
| 265 | + $infos['_DIR_RESTREINT']['SPIP']['chemin'] = []; |
|
| 266 | + $liste_non_classee = [ |
|
| 267 | + 'SPIP' => [ |
|
| 268 | + 'nom' => 'SPIP', |
|
| 269 | + 'etat' => 'stable', |
|
| 270 | + 'version' => $GLOBALS['spip_version_branche'], |
|
| 271 | + 'dir_type' => '_DIR_RESTREINT', |
|
| 272 | + 'dir' => '', |
|
| 273 | + ] |
|
| 274 | + ]; |
|
| 275 | + |
|
| 276 | + $invalides = []; |
|
| 277 | + foreach ($liste_ext as $plug) { |
|
| 278 | + if (isset($infos['_DIR_PLUGINS_DIST'][$plug])) { |
|
| 279 | + plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_DIST'); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + foreach ($liste_plug as $plug) { |
|
| 283 | + if (isset($infos['_DIR_PLUGINS'][$plug])) { |
|
| 284 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS'); |
|
| 285 | + if (is_array($r)) { |
|
| 286 | + $invalides = array_merge($invalides, $r); |
|
| 287 | + } |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | + |
|
| 291 | + if (defined('_DIR_PLUGINS_SUPPL') and _DIR_PLUGINS_SUPPL) { |
|
| 292 | + $infos['_DIR_PLUGINS_SUPPL'] = $get_infos($liste_plug, false, _DIR_PLUGINS_SUPPL); |
|
| 293 | + foreach ($liste_plug as $plug) { |
|
| 294 | + if (isset($infos['_DIR_PLUGINS_SUPPL'][$plug])) { |
|
| 295 | + $r = plugin_valide_resume($liste_non_classee, $plug, $infos, '_DIR_PLUGINS_SUPPL'); |
|
| 296 | + if (is_array($r)) { |
|
| 297 | + $invalides = array_merge($invalides, $r); |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + |
|
| 303 | + plugin_fixer_procure($liste_non_classee, $infos); |
|
| 304 | + |
|
| 305 | + // les plugins qui sont dans $liste_non_classee ne sont pas invalides (on a trouve un autre version valide) |
|
| 306 | + $invalides = array_diff_key($invalides, $liste_non_classee); |
|
| 307 | + |
|
| 308 | + return [$infos, $liste_non_classee, $invalides]; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -325,38 +325,38 @@ discard block |
||
| 325 | 325 | * array description short si on ne le retient pas (pour memorisation dans une table des erreurs) |
| 326 | 326 | */ |
| 327 | 327 | function plugin_valide_resume(&$liste, $plug, $infos, $dir_type) { |
| 328 | - $i = $infos[$dir_type][$plug]; |
|
| 329 | - // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | - $short_desc = [ |
|
| 331 | - 'dir' => $plug, |
|
| 332 | - 'dir_type' => $dir_type |
|
| 333 | - ]; |
|
| 334 | - if (empty($i['prefix'])) { |
|
| 335 | - // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | - $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | - return [$plug => $short_desc]; |
|
| 338 | - } |
|
| 339 | - |
|
| 340 | - $p = strtoupper($i['prefix']); |
|
| 341 | - $short_desc['nom'] = $i['nom']; |
|
| 342 | - $short_desc['etat'] = $i['etat']; |
|
| 343 | - $short_desc['version'] = $i['version']; |
|
| 344 | - |
|
| 345 | - if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | - $short_desc['erreur'] = $i['erreur']; |
|
| 347 | - return [$p => $short_desc]; |
|
| 348 | - } |
|
| 349 | - if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | - return [$p => $short_desc]; |
|
| 351 | - } |
|
| 352 | - if ( |
|
| 353 | - !isset($liste[$p]) |
|
| 354 | - or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | - ) { |
|
| 356 | - $liste[$p] = $short_desc; |
|
| 357 | - } |
|
| 358 | - // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | - return $p; |
|
| 328 | + $i = $infos[$dir_type][$plug]; |
|
| 329 | + // minimum syndical pour afficher si le xml avait des erreurs éventuelles |
|
| 330 | + $short_desc = [ |
|
| 331 | + 'dir' => $plug, |
|
| 332 | + 'dir_type' => $dir_type |
|
| 333 | + ]; |
|
| 334 | + if (empty($i['prefix'])) { |
|
| 335 | + // erreur xml ? mais sans connaissance du prefix, on retourne le chemin… |
|
| 336 | + $short_desc['erreur'] = $i['erreur'] ?? ['?']; |
|
| 337 | + return [$plug => $short_desc]; |
|
| 338 | + } |
|
| 339 | + |
|
| 340 | + $p = strtoupper($i['prefix']); |
|
| 341 | + $short_desc['nom'] = $i['nom']; |
|
| 342 | + $short_desc['etat'] = $i['etat']; |
|
| 343 | + $short_desc['version'] = $i['version']; |
|
| 344 | + |
|
| 345 | + if (isset($i['erreur']) and $i['erreur']) { |
|
| 346 | + $short_desc['erreur'] = $i['erreur']; |
|
| 347 | + return [$p => $short_desc]; |
|
| 348 | + } |
|
| 349 | + if (!plugin_version_compatible($i['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 350 | + return [$p => $short_desc]; |
|
| 351 | + } |
|
| 352 | + if ( |
|
| 353 | + !isset($liste[$p]) |
|
| 354 | + or spip_version_compare($i['version'], $liste[$p]['version'], '>') |
|
| 355 | + ) { |
|
| 356 | + $liste[$p] = $short_desc; |
|
| 357 | + } |
|
| 358 | + // ok le plugin etait deja dans la liste ou on a choisi une version plus recente |
|
| 359 | + return $p; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -372,47 +372,47 @@ discard block |
||
| 372 | 372 | * @param array $infos |
| 373 | 373 | */ |
| 374 | 374 | function plugin_fixer_procure(&$liste, &$infos) { |
| 375 | - foreach ($liste as $p => $resume) { |
|
| 376 | - $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | - if (isset($i['procure']) and $i['procure']) { |
|
| 378 | - foreach ($i['procure'] as $procure) { |
|
| 379 | - $p = strtoupper($procure['nom']); |
|
| 380 | - $dir = $resume['dir']; |
|
| 381 | - if ($dir) { |
|
| 382 | - $dir .= '/'; |
|
| 383 | - } |
|
| 384 | - $dir .= 'procure:' . $procure['nom']; |
|
| 385 | - |
|
| 386 | - $procure['etat'] = '?'; |
|
| 387 | - $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | - $procure['dir'] = $dir; |
|
| 389 | - |
|
| 390 | - // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | - // on ajoute cette version a la liste |
|
| 392 | - if ( |
|
| 393 | - !isset($liste[$p]) |
|
| 394 | - or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | - ) { |
|
| 396 | - $liste[$p] = $procure; |
|
| 397 | - |
|
| 398 | - // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | - $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | - 'prefix' => $procure['nom'], |
|
| 401 | - 'nom' => $procure['nom'], |
|
| 402 | - 'etat' => $procure['etat'], |
|
| 403 | - 'version' => $procure['version'], |
|
| 404 | - 'chemin' => [], |
|
| 405 | - 'necessite' => [], |
|
| 406 | - 'utilise' => [], |
|
| 407 | - 'lib' => [], |
|
| 408 | - 'menu' => [], |
|
| 409 | - 'onglet' => [], |
|
| 410 | - 'procure' => [], |
|
| 411 | - ]; |
|
| 412 | - } |
|
| 413 | - } |
|
| 414 | - } |
|
| 415 | - } |
|
| 375 | + foreach ($liste as $p => $resume) { |
|
| 376 | + $i = $infos[$resume['dir_type']][$resume['dir']]; |
|
| 377 | + if (isset($i['procure']) and $i['procure']) { |
|
| 378 | + foreach ($i['procure'] as $procure) { |
|
| 379 | + $p = strtoupper($procure['nom']); |
|
| 380 | + $dir = $resume['dir']; |
|
| 381 | + if ($dir) { |
|
| 382 | + $dir .= '/'; |
|
| 383 | + } |
|
| 384 | + $dir .= 'procure:' . $procure['nom']; |
|
| 385 | + |
|
| 386 | + $procure['etat'] = '?'; |
|
| 387 | + $procure['dir_type'] = $resume['dir_type']; |
|
| 388 | + $procure['dir'] = $dir; |
|
| 389 | + |
|
| 390 | + // si ce plugin n'est pas deja procure, ou dans une version plus ancienne |
|
| 391 | + // on ajoute cette version a la liste |
|
| 392 | + if ( |
|
| 393 | + !isset($liste[$p]) |
|
| 394 | + or spip_version_compare($procure['version'], $liste[$p]['version'], '>') |
|
| 395 | + ) { |
|
| 396 | + $liste[$p] = $procure; |
|
| 397 | + |
|
| 398 | + // on fournit une information minimale pour ne pas perturber la compilation |
|
| 399 | + $infos[$resume['dir_type']][$dir] = [ |
|
| 400 | + 'prefix' => $procure['nom'], |
|
| 401 | + 'nom' => $procure['nom'], |
|
| 402 | + 'etat' => $procure['etat'], |
|
| 403 | + 'version' => $procure['version'], |
|
| 404 | + 'chemin' => [], |
|
| 405 | + 'necessite' => [], |
|
| 406 | + 'utilise' => [], |
|
| 407 | + 'lib' => [], |
|
| 408 | + 'menu' => [], |
|
| 409 | + 'onglet' => [], |
|
| 410 | + 'procure' => [], |
|
| 411 | + ]; |
|
| 412 | + } |
|
| 413 | + } |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -426,20 +426,20 @@ discard block |
||
| 426 | 426 | * @return array |
| 427 | 427 | */ |
| 428 | 428 | function liste_chemin_plugin($liste, $dir_plugins = _DIR_PLUGINS) { |
| 429 | - foreach ($liste as $prefix => $infos) { |
|
| 430 | - if ( |
|
| 431 | - !$dir_plugins |
|
| 432 | - or ( |
|
| 433 | - defined($infos['dir_type']) |
|
| 434 | - and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | - ) { |
|
| 436 | - $liste[$prefix] = $infos['dir']; |
|
| 437 | - } else { |
|
| 438 | - unset($liste[$prefix]); |
|
| 439 | - } |
|
| 440 | - } |
|
| 441 | - |
|
| 442 | - return $liste; |
|
| 429 | + foreach ($liste as $prefix => $infos) { |
|
| 430 | + if ( |
|
| 431 | + !$dir_plugins |
|
| 432 | + or ( |
|
| 433 | + defined($infos['dir_type']) |
|
| 434 | + and constant($infos['dir_type']) == $dir_plugins) |
|
| 435 | + ) { |
|
| 436 | + $liste[$prefix] = $infos['dir']; |
|
| 437 | + } else { |
|
| 438 | + unset($liste[$prefix]); |
|
| 439 | + } |
|
| 440 | + } |
|
| 441 | + |
|
| 442 | + return $liste; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | /** |
@@ -454,9 +454,9 @@ discard block |
||
| 454 | 454 | * @return array |
| 455 | 455 | */ |
| 456 | 456 | function liste_chemin_plugin_actifs($dir_plugins = _DIR_PLUGINS) { |
| 457 | - include_spip('plugins/installer'); |
|
| 457 | + include_spip('plugins/installer'); |
|
| 458 | 458 | |
| 459 | - return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 459 | + return liste_chemin_plugin(liste_plugin_actifs(), $dir_plugins); |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | /** |
@@ -487,54 +487,54 @@ discard block |
||
| 487 | 487 | * qui n'ont pas satisfait leurs dépendances |
| 488 | 488 | **/ |
| 489 | 489 | function plugin_trier($infos, $liste_non_classee) { |
| 490 | - $toute_la_liste = $liste_non_classee; |
|
| 491 | - $liste = $ordre = []; |
|
| 492 | - $count = 0; |
|
| 493 | - |
|
| 494 | - while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | - #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | - $count = $c; |
|
| 497 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | - $plug = $resume['dir']; |
|
| 499 | - $dir_type = $resume['dir_type']; |
|
| 500 | - $info1 = $infos[$dir_type][$plug]; |
|
| 501 | - // si des plugins sont necessaires, |
|
| 502 | - // on ne peut inserer qu'apres eux |
|
| 503 | - foreach ($info1['necessite'] as $need) { |
|
| 504 | - $nom = strtoupper($need['nom']); |
|
| 505 | - $compat = $need['compatibilite'] ?? ''; |
|
| 506 | - if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | - $info1 = false; |
|
| 508 | - break; |
|
| 509 | - } |
|
| 510 | - } |
|
| 511 | - if (!$info1) { |
|
| 512 | - continue; |
|
| 513 | - } |
|
| 514 | - // idem si des plugins sont utiles, |
|
| 515 | - // sauf si ils sont de toute facon absents de la liste |
|
| 516 | - foreach ($info1['utilise'] as $need) { |
|
| 517 | - $nom = strtoupper($need['nom']); |
|
| 518 | - $compat = $need['compatibilite'] ?? ''; |
|
| 519 | - if (isset($toute_la_liste[$nom])) { |
|
| 520 | - if ( |
|
| 521 | - !isset($liste[$nom]) or |
|
| 522 | - !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | - ) { |
|
| 524 | - $info1 = false; |
|
| 525 | - break; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - } |
|
| 529 | - if ($info1) { |
|
| 530 | - $ordre[$p] = $info1; |
|
| 531 | - $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | - unset($liste_non_classee[$p]); |
|
| 533 | - } |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - |
|
| 537 | - return [$liste, $ordre, $liste_non_classee]; |
|
| 490 | + $toute_la_liste = $liste_non_classee; |
|
| 491 | + $liste = $ordre = []; |
|
| 492 | + $count = 0; |
|
| 493 | + |
|
| 494 | + while ($c = count($liste_non_classee) and $c != $count) { // tant qu'il reste des plugins a classer, et qu'on ne stagne pas |
|
| 495 | + #echo "tour::";var_dump($liste_non_classee); |
|
| 496 | + $count = $c; |
|
| 497 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 498 | + $plug = $resume['dir']; |
|
| 499 | + $dir_type = $resume['dir_type']; |
|
| 500 | + $info1 = $infos[$dir_type][$plug]; |
|
| 501 | + // si des plugins sont necessaires, |
|
| 502 | + // on ne peut inserer qu'apres eux |
|
| 503 | + foreach ($info1['necessite'] as $need) { |
|
| 504 | + $nom = strtoupper($need['nom']); |
|
| 505 | + $compat = $need['compatibilite'] ?? ''; |
|
| 506 | + if (!isset($liste[$nom]) or !plugin_version_compatible($compat, $liste[$nom]['version'])) { |
|
| 507 | + $info1 = false; |
|
| 508 | + break; |
|
| 509 | + } |
|
| 510 | + } |
|
| 511 | + if (!$info1) { |
|
| 512 | + continue; |
|
| 513 | + } |
|
| 514 | + // idem si des plugins sont utiles, |
|
| 515 | + // sauf si ils sont de toute facon absents de la liste |
|
| 516 | + foreach ($info1['utilise'] as $need) { |
|
| 517 | + $nom = strtoupper($need['nom']); |
|
| 518 | + $compat = $need['compatibilite'] ?? ''; |
|
| 519 | + if (isset($toute_la_liste[$nom])) { |
|
| 520 | + if ( |
|
| 521 | + !isset($liste[$nom]) or |
|
| 522 | + !plugin_version_compatible($compat, $liste[$nom]['version']) |
|
| 523 | + ) { |
|
| 524 | + $info1 = false; |
|
| 525 | + break; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + } |
|
| 529 | + if ($info1) { |
|
| 530 | + $ordre[$p] = $info1; |
|
| 531 | + $liste[$p] = $liste_non_classee[$p]; |
|
| 532 | + unset($liste_non_classee[$p]); |
|
| 533 | + } |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + |
|
| 537 | + return [$liste, $ordre, $liste_non_classee]; |
|
| 538 | 538 | } |
| 539 | 539 | |
| 540 | 540 | /** |
@@ -551,40 +551,40 @@ discard block |
||
| 551 | 551 | * Répertoire (plugins, plugins-dist, ...) => Couples (prefixes => infos completes) des plugins qu'ils contiennent |
| 552 | 552 | **/ |
| 553 | 553 | function plugins_erreurs($liste_non_classee, $liste, $infos, $msg = []) { |
| 554 | - static $erreurs = []; |
|
| 555 | - |
|
| 556 | - if (!is_array($liste)) { |
|
| 557 | - $liste = []; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | - $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | - |
|
| 563 | - foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | - $dir_type = $resume['dir_type']; |
|
| 565 | - $plug = $resume['dir']; |
|
| 566 | - $k = $infos[$dir_type][$plug]; |
|
| 567 | - |
|
| 568 | - $plug = constant($dir_type) . $plug; |
|
| 569 | - if (!isset($msg[$p])) { |
|
| 570 | - if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | - $msg[$p] = [$resume['erreur']]; |
|
| 572 | - } |
|
| 573 | - elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | - $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | - } |
|
| 576 | - elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | - $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | - } |
|
| 579 | - } else { |
|
| 580 | - foreach ($msg[$p] as $c => $l) { |
|
| 581 | - $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - $erreurs[$plug] = $msg[$p]; |
|
| 585 | - } |
|
| 586 | - |
|
| 587 | - ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 554 | + static $erreurs = []; |
|
| 555 | + |
|
| 556 | + if (!is_array($liste)) { |
|
| 557 | + $liste = []; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + // les plugins en erreur ne sont pas actifs ; ils ne doivent pas être dans la liste |
|
| 561 | + $liste = array_diff_key($liste, $liste_non_classee); |
|
| 562 | + |
|
| 563 | + foreach ($liste_non_classee as $p => $resume) { |
|
| 564 | + $dir_type = $resume['dir_type']; |
|
| 565 | + $plug = $resume['dir']; |
|
| 566 | + $k = $infos[$dir_type][$plug]; |
|
| 567 | + |
|
| 568 | + $plug = constant($dir_type) . $plug; |
|
| 569 | + if (!isset($msg[$p])) { |
|
| 570 | + if (isset($resume['erreur']) and $resume['erreur']) { |
|
| 571 | + $msg[$p] = [$resume['erreur']]; |
|
| 572 | + } |
|
| 573 | + elseif (!plugin_version_compatible($k['compatibilite'], $GLOBALS['spip_version_branche'], 'spip')) { |
|
| 574 | + $msg[$p] = [plugin_message_incompatibilite($k['compatibilite'], $GLOBALS['spip_version_branche'], 'SPIP', 'necessite')]; |
|
| 575 | + } |
|
| 576 | + elseif (!$msg[$p] = plugin_necessite($k['necessite'], $liste, 'necessite')) { |
|
| 577 | + $msg[$p] = plugin_necessite($k['utilise'], $liste, 'utilise'); |
|
| 578 | + } |
|
| 579 | + } else { |
|
| 580 | + foreach ($msg[$p] as $c => $l) { |
|
| 581 | + $msg[$p][$c] = plugin_controler_lib($l['nom'], $l['lien']); |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + $erreurs[$plug] = $msg[$p]; |
|
| 585 | + } |
|
| 586 | + |
|
| 587 | + ecrire_meta('plugin_erreur_activation', serialize($erreurs)); |
|
| 588 | 588 | } |
| 589 | 589 | |
| 590 | 590 | /** |
@@ -599,25 +599,25 @@ discard block |
||
| 599 | 599 | * - Liste des erreurs ou code HTML des erreurs |
| 600 | 600 | **/ |
| 601 | 601 | function plugin_donne_erreurs($raw = false, $raz = true) { |
| 602 | - if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | - return $raw ? [] : ''; |
|
| 604 | - } |
|
| 605 | - $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | - // Compat ancienne version |
|
| 607 | - if (!$list) { |
|
| 608 | - $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | - } elseif (!$raw) { |
|
| 610 | - foreach ($list as $plug => $msg) { |
|
| 611 | - $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | - . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | - } |
|
| 614 | - $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | - } |
|
| 616 | - if ($raz) { |
|
| 617 | - effacer_meta('plugin_erreur_activation'); |
|
| 618 | - } |
|
| 619 | - |
|
| 620 | - return $list; |
|
| 602 | + if (!isset($GLOBALS['meta']['plugin_erreur_activation'])) { |
|
| 603 | + return $raw ? [] : ''; |
|
| 604 | + } |
|
| 605 | + $list = @unserialize($GLOBALS['meta']['plugin_erreur_activation']); |
|
| 606 | + // Compat ancienne version |
|
| 607 | + if (!$list) { |
|
| 608 | + $list = $raw ? [] : $GLOBALS['meta']['plugin_erreur_activation']; |
|
| 609 | + } elseif (!$raw) { |
|
| 610 | + foreach ($list as $plug => $msg) { |
|
| 611 | + $list[$plug] = '<li>' . _T('plugin_impossible_activer', ['plugin' => $plug]) |
|
| 612 | + . '<ul><li>' . implode('</li><li>', $msg) . '</li></ul></li>'; |
|
| 613 | + } |
|
| 614 | + $list = '<ul>' . join("\n", $list) . '</ul>'; |
|
| 615 | + } |
|
| 616 | + if ($raz) { |
|
| 617 | + effacer_meta('plugin_erreur_activation'); |
|
| 618 | + } |
|
| 619 | + |
|
| 620 | + return $list; |
|
| 621 | 621 | } |
| 622 | 622 | |
| 623 | 623 | /** |
@@ -637,21 +637,21 @@ discard block |
||
| 637 | 637 | * |
| 638 | 638 | **/ |
| 639 | 639 | function plugin_necessite($n, $liste, $balise = 'necessite') { |
| 640 | - $msg = []; |
|
| 641 | - foreach ($n as $need) { |
|
| 642 | - $id = strtoupper($need['nom']); |
|
| 643 | - $r = plugin_controler_necessite( |
|
| 644 | - $liste, |
|
| 645 | - $id, |
|
| 646 | - $need['compatibilite'] ?? '', |
|
| 647 | - $balise |
|
| 648 | - ); |
|
| 649 | - if ($r) { |
|
| 650 | - $msg[] = $r; |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - |
|
| 654 | - return $msg; |
|
| 640 | + $msg = []; |
|
| 641 | + foreach ($n as $need) { |
|
| 642 | + $id = strtoupper($need['nom']); |
|
| 643 | + $r = plugin_controler_necessite( |
|
| 644 | + $liste, |
|
| 645 | + $id, |
|
| 646 | + $need['compatibilite'] ?? '', |
|
| 647 | + $balise |
|
| 648 | + ); |
|
| 649 | + if ($r) { |
|
| 650 | + $msg[] = $r; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + |
|
| 654 | + return $msg; |
|
| 655 | 655 | } |
| 656 | 656 | |
| 657 | 657 | /** |
@@ -673,19 +673,19 @@ discard block |
||
| 673 | 673 | * Message d'erreur lorsque la dépendance est absente. |
| 674 | 674 | **/ |
| 675 | 675 | function plugin_controler_necessite($liste, $nom, $intervalle, $balise) { |
| 676 | - if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | - return ''; |
|
| 678 | - } |
|
| 679 | - // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | - if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | - return ''; |
|
| 682 | - } |
|
| 683 | - return plugin_message_incompatibilite( |
|
| 684 | - $intervalle, |
|
| 685 | - (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | - $nom, |
|
| 687 | - $balise |
|
| 688 | - ); |
|
| 676 | + if (isset($liste[$nom]) and plugin_version_compatible($intervalle, $liste[$nom]['version'])) { |
|
| 677 | + return ''; |
|
| 678 | + } |
|
| 679 | + // Si l'on a un <utilise="plugin non actif" />, ne pas renvoyer d'erreur |
|
| 680 | + if ($balise === 'utilise' and !isset($liste[$nom])) { |
|
| 681 | + return ''; |
|
| 682 | + } |
|
| 683 | + return plugin_message_incompatibilite( |
|
| 684 | + $intervalle, |
|
| 685 | + (isset($liste[$nom]) ? $liste[$nom]['version'] : ''), |
|
| 686 | + $nom, |
|
| 687 | + $balise |
|
| 688 | + ); |
|
| 689 | 689 | } |
| 690 | 690 | |
| 691 | 691 | /** |
@@ -702,70 +702,70 @@ discard block |
||
| 702 | 702 | */ |
| 703 | 703 | function plugin_message_incompatibilite($intervalle, $version, $nom, $balise) { |
| 704 | 704 | |
| 705 | - // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | - // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | - $type = 'plugin'; |
|
| 708 | - if ($nom === 'SPIP') { |
|
| 709 | - $type = 'spip'; |
|
| 710 | - } elseif ($nom === 'PHP') { |
|
| 711 | - $type = 'php'; |
|
| 712 | - } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | - $type = 'extension_php'; |
|
| 714 | - [, $nom] = explode(':', $nom, 2); |
|
| 715 | - } |
|
| 716 | - |
|
| 717 | - if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | - $minimum = $regs[1]; |
|
| 719 | - $maximum = $regs[2]; |
|
| 720 | - |
|
| 721 | - $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | - $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | - |
|
| 724 | - if (strlen($minimum)) { |
|
| 725 | - if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | - 'plugin' => $nom, |
|
| 728 | - 'version' => ' ≥ ' . $minimum |
|
| 729 | - ]); |
|
| 730 | - } |
|
| 731 | - if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | - 'plugin' => $nom, |
|
| 734 | - 'version' => ' > ' . $minimum |
|
| 735 | - ]); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - |
|
| 739 | - if (strlen($maximum)) { |
|
| 740 | - if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | - return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | - 'plugin' => $nom, |
|
| 743 | - 'version' => ' ≤ ' . $maximum |
|
| 744 | - ]); |
|
| 745 | - } |
|
| 746 | - if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | - return _T("plugin_{$balise}_plugin", [ |
|
| 748 | - 'plugin' => $nom, |
|
| 749 | - 'version' => ' < ' . $maximum |
|
| 750 | - ]); |
|
| 751 | - } |
|
| 752 | - } |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | - // - un 'utilise' sans version. |
|
| 757 | - // - un 'php' sans version. |
|
| 758 | - return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 705 | + // prendre en compte les erreurs de dépendances à PHP |
|
| 706 | + // ou à une extension PHP avec des messages d'erreurs dédiés. |
|
| 707 | + $type = 'plugin'; |
|
| 708 | + if ($nom === 'SPIP') { |
|
| 709 | + $type = 'spip'; |
|
| 710 | + } elseif ($nom === 'PHP') { |
|
| 711 | + $type = 'php'; |
|
| 712 | + } elseif (strncmp($nom, 'PHP:', 4) === 0) { |
|
| 713 | + $type = 'extension_php'; |
|
| 714 | + [, $nom] = explode(':', $nom, 2); |
|
| 715 | + } |
|
| 716 | + |
|
| 717 | + if (preg_match(_EXTRAIRE_INTERVALLE, $intervalle, $regs)) { |
|
| 718 | + $minimum = $regs[1]; |
|
| 719 | + $maximum = $regs[2]; |
|
| 720 | + |
|
| 721 | + $minimum_inclus = $intervalle[0] == '['; |
|
| 722 | + $maximum_inclus = substr($intervalle, -1) == ']'; |
|
| 723 | + |
|
| 724 | + if (strlen($minimum)) { |
|
| 725 | + if ($minimum_inclus and spip_version_compare($version, $minimum, '<')) { |
|
| 726 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 727 | + 'plugin' => $nom, |
|
| 728 | + 'version' => ' ≥ ' . $minimum |
|
| 729 | + ]); |
|
| 730 | + } |
|
| 731 | + if (!$minimum_inclus and spip_version_compare($version, $minimum, '<=')) { |
|
| 732 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 733 | + 'plugin' => $nom, |
|
| 734 | + 'version' => ' > ' . $minimum |
|
| 735 | + ]); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + |
|
| 739 | + if (strlen($maximum)) { |
|
| 740 | + if ($maximum_inclus and spip_version_compare($version, $maximum, '>')) { |
|
| 741 | + return _T("plugin_{$balise}_{$type}", [ |
|
| 742 | + 'plugin' => $nom, |
|
| 743 | + 'version' => ' ≤ ' . $maximum |
|
| 744 | + ]); |
|
| 745 | + } |
|
| 746 | + if (!$maximum_inclus and spip_version_compare($version, $maximum, '>=')) { |
|
| 747 | + return _T("plugin_{$balise}_plugin", [ |
|
| 748 | + 'plugin' => $nom, |
|
| 749 | + 'version' => ' < ' . $maximum |
|
| 750 | + ]); |
|
| 751 | + } |
|
| 752 | + } |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // note : il ne peut pas y avoir d'erreur sur |
|
| 756 | + // - un 'utilise' sans version. |
|
| 757 | + // - un 'php' sans version. |
|
| 758 | + return _T("plugin_necessite_{$type}_sans_version", ['plugin' => $nom]); |
|
| 759 | 759 | } |
| 760 | 760 | |
| 761 | 761 | |
| 762 | 762 | function plugin_controler_lib($lib, $url) { |
| 763 | - /* Feature sortie du core, voir STP |
|
| 763 | + /* Feature sortie du core, voir STP |
|
| 764 | 764 | * if ($url) { |
| 765 | 765 | include_spip('inc/charger_plugin'); |
| 766 | 766 | $url = '<br />' . bouton_telechargement_plugin($url, 'lib'); |
| 767 | 767 | }*/ |
| 768 | - return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 768 | + return _T('plugin_necessite_lib', ['lib' => $lib]) . " <a href='$url'>$url</a>"; |
|
| 769 | 769 | } |
| 770 | 770 | |
| 771 | 771 | |
@@ -780,7 +780,7 @@ discard block |
||
| 780 | 780 | * true si il y a eu des modifications sur la liste des plugins actifs, false sinon |
| 781 | 781 | **/ |
| 782 | 782 | function actualise_plugins_actifs($pipe_recherche = false) { |
| 783 | - return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 783 | + return ecrire_plugin_actifs('', $pipe_recherche, 'force'); |
|
| 784 | 784 | } |
| 785 | 785 | |
| 786 | 786 | |
@@ -807,116 +807,116 @@ discard block |
||
| 807 | 807 | **/ |
| 808 | 808 | function ecrire_plugin_actifs($plugin, $pipe_recherche = false, $operation = 'raz') { |
| 809 | 809 | |
| 810 | - // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | - $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | - |
|
| 813 | - // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | - if (!$cache and !spip_connect()) { |
|
| 815 | - return false; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($operation != 'raz') { |
|
| 819 | - $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | - $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | - if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | - $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | - $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | - $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | - } |
|
| 826 | - // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | - // on les reinjecte ici |
|
| 828 | - if ( |
|
| 829 | - isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | - and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | - ) { |
|
| 832 | - $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | - } |
|
| 834 | - |
|
| 835 | - if ($operation == 'ajoute') { |
|
| 836 | - $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | - } elseif ($operation == 'enleve') { |
|
| 838 | - $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | - } else { |
|
| 840 | - $plugin = $plugin_valides; |
|
| 841 | - } |
|
| 842 | - } |
|
| 843 | - $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | - |
|
| 845 | - // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | - if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | - $plugin = $ajouter_dependances($plugin); |
|
| 848 | - } |
|
| 849 | - |
|
| 850 | - // recharger le xml des plugins a activer |
|
| 851 | - // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | - // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | - // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | - // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | - [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | - // trouver l'ordre d'activation |
|
| 857 | - [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | - if ($invalides or $reste) { |
|
| 859 | - plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | - } |
|
| 861 | - |
|
| 862 | - // Ignorer les plugins necessitant une lib absente |
|
| 863 | - // et preparer la meta d'entete Http |
|
| 864 | - $err = $msg = $header = []; |
|
| 865 | - foreach ($plugin_valides as $p => $resume) { |
|
| 866 | - // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | - if (!str_starts_with($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | - $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | - } |
|
| 870 | - if ($resume['dir']) { |
|
| 871 | - foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | - if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | - $err[$p] = $resume; |
|
| 874 | - $msg[$p][] = $l; |
|
| 875 | - unset($plugin_valides[$p]); |
|
| 876 | - } |
|
| 877 | - } |
|
| 878 | - } |
|
| 879 | - } |
|
| 880 | - if ($err) { |
|
| 881 | - plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | - } |
|
| 883 | - |
|
| 884 | - if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | - effacer_meta('message_crash_plugins'); |
|
| 886 | - } |
|
| 887 | - ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | - $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | - ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | - $header = strtolower(implode(',', $header)); |
|
| 891 | - if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | - ecrire_fichier( |
|
| 893 | - _DIR_VAR . 'config.txt', |
|
| 894 | - (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | - ); |
|
| 896 | - } else { |
|
| 897 | - @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | - } |
|
| 899 | - // generer charger_plugins_chemin.php |
|
| 900 | - plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | - // generer les fichiers |
|
| 902 | - // - charger_plugins_options.php |
|
| 903 | - // - charger_plugins_fonctions.php |
|
| 904 | - plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | - // charger les chemins des plugins et les fichiers d'options |
|
| 906 | - // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | - plugins_amorcer_plugins_actifs(); |
|
| 908 | - // mise a jour de la matrice des pipelines |
|
| 909 | - $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | - // generer le fichier _CACHE_PIPELINE |
|
| 911 | - pipeline_precompile($prepend_code); |
|
| 912 | - |
|
| 913 | - if (spip_connect()) { |
|
| 914 | - // lancer et initialiser les nouveaux crons ! |
|
| 915 | - include_spip('inc/genie'); |
|
| 916 | - genie_queue_watch_dist(); |
|
| 917 | - } |
|
| 918 | - |
|
| 919 | - return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 810 | + // creer le repertoire cache/ si necessaire ! (installation notamment) |
|
| 811 | + $cache = sous_repertoire(_DIR_CACHE, '', false, true); |
|
| 812 | + |
|
| 813 | + // Si on n'a ni cache accessible, ni connexion SQL, on ne peut pas faire grand chose encore. |
|
| 814 | + if (!$cache and !spip_connect()) { |
|
| 815 | + return false; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($operation != 'raz') { |
|
| 819 | + $plugin_valides = liste_chemin_plugin_actifs(); |
|
| 820 | + $plugin_valides = is_plugin_dir($plugin_valides); |
|
| 821 | + if (defined('_DIR_PLUGINS_SUPPL') && _DIR_PLUGINS_SUPPL) { |
|
| 822 | + $plugin_valides_supp = liste_chemin_plugin_actifs(_DIR_PLUGINS_SUPPL); |
|
| 823 | + $plugin_valides_supp = is_plugin_dir($plugin_valides_supp, _DIR_PLUGINS_SUPPL); |
|
| 824 | + $plugin_valides = array_merge($plugin_valides, $plugin_valides_supp); |
|
| 825 | + } |
|
| 826 | + // si des plugins sont en attentes (coches mais impossible a activer) |
|
| 827 | + // on les reinjecte ici |
|
| 828 | + if ( |
|
| 829 | + isset($GLOBALS['meta']['plugin_attente']) |
|
| 830 | + and $a = unserialize($GLOBALS['meta']['plugin_attente']) |
|
| 831 | + ) { |
|
| 832 | + $plugin_valides = $plugin_valides + liste_chemin_plugin($a); |
|
| 833 | + } |
|
| 834 | + |
|
| 835 | + if ($operation == 'ajoute') { |
|
| 836 | + $plugin = array_merge($plugin_valides, $plugin); |
|
| 837 | + } elseif ($operation == 'enleve') { |
|
| 838 | + $plugin = array_diff($plugin_valides, $plugin); |
|
| 839 | + } else { |
|
| 840 | + $plugin = $plugin_valides; |
|
| 841 | + } |
|
| 842 | + } |
|
| 843 | + $actifs_avant = $GLOBALS['meta']['plugin'] ?? ''; |
|
| 844 | + |
|
| 845 | + // si une fonction de gestion de dependances existe, l'appeler ici |
|
| 846 | + if ($ajouter_dependances = charger_fonction('ajouter_dependances', 'plugins', true)) { |
|
| 847 | + $plugin = $ajouter_dependances($plugin); |
|
| 848 | + } |
|
| 849 | + |
|
| 850 | + // recharger le xml des plugins a activer |
|
| 851 | + // on force le reload ici, meme si le fichier xml n'a pas change |
|
| 852 | + // pour ne pas rater l'ajout ou la suppression d'un fichier fonctions/options/administrations |
|
| 853 | + // pourra etre evite quand on ne supportera plus les plugin.xml |
|
| 854 | + // en deplacant la detection de ces fichiers dans la compilation ci dessous |
|
| 855 | + [$infos, $liste, $invalides] = liste_plugin_valides($plugin, true); |
|
| 856 | + // trouver l'ordre d'activation |
|
| 857 | + [$plugin_valides, $ordre, $reste] = plugin_trier($infos, $liste); |
|
| 858 | + if ($invalides or $reste) { |
|
| 859 | + plugins_erreurs(array_merge($invalides, $reste), $liste, $infos); |
|
| 860 | + } |
|
| 861 | + |
|
| 862 | + // Ignorer les plugins necessitant une lib absente |
|
| 863 | + // et preparer la meta d'entete Http |
|
| 864 | + $err = $msg = $header = []; |
|
| 865 | + foreach ($plugin_valides as $p => $resume) { |
|
| 866 | + // Les headers ne doivent pas indiquer les versions des extensions PHP, ni la version PHP |
|
| 867 | + if (!str_starts_with($p, 'PHP:') and $p !== 'PHP') { |
|
| 868 | + $header[] = $p . ($resume['version'] ? '(' . $resume['version'] . ')' : ''); |
|
| 869 | + } |
|
| 870 | + if ($resume['dir']) { |
|
| 871 | + foreach ($infos[$resume['dir_type']][$resume['dir']]['lib'] as $l) { |
|
| 872 | + if (!find_in_path($l['nom'], 'lib/')) { |
|
| 873 | + $err[$p] = $resume; |
|
| 874 | + $msg[$p][] = $l; |
|
| 875 | + unset($plugin_valides[$p]); |
|
| 876 | + } |
|
| 877 | + } |
|
| 878 | + } |
|
| 879 | + } |
|
| 880 | + if ($err) { |
|
| 881 | + plugins_erreurs($err, '', $infos, $msg); |
|
| 882 | + } |
|
| 883 | + |
|
| 884 | + if (isset($GLOBALS['meta']['message_crash_plugins'])) { |
|
| 885 | + effacer_meta('message_crash_plugins'); |
|
| 886 | + } |
|
| 887 | + ecrire_meta('plugin', serialize($plugin_valides)); |
|
| 888 | + $liste = array_diff_key($liste, $plugin_valides); |
|
| 889 | + ecrire_meta('plugin_attente', serialize($liste)); |
|
| 890 | + $header = strtolower(implode(',', $header)); |
|
| 891 | + if (!isset($GLOBALS['spip_header_silencieux']) or !$GLOBALS['spip_header_silencieux']) { |
|
| 892 | + ecrire_fichier( |
|
| 893 | + _DIR_VAR . 'config.txt', |
|
| 894 | + (defined('_HEADER_COMPOSED_BY') ? _HEADER_COMPOSED_BY : 'Composed-By: SPIP') . ' ' . $GLOBALS['spip_version_affichee'] . ' @ www.spip.net + ' . $header |
|
| 895 | + ); |
|
| 896 | + } else { |
|
| 897 | + @unlink(_DIR_VAR . 'config.txt'); |
|
| 898 | + } |
|
| 899 | + // generer charger_plugins_chemin.php |
|
| 900 | + plugins_precompile_chemin($plugin_valides, $ordre); |
|
| 901 | + // generer les fichiers |
|
| 902 | + // - charger_plugins_options.php |
|
| 903 | + // - charger_plugins_fonctions.php |
|
| 904 | + plugins_precompile_xxxtions($plugin_valides, $ordre); |
|
| 905 | + // charger les chemins des plugins et les fichiers d'options |
|
| 906 | + // (qui peuvent déclarer / utiliser des pipelines, ajouter d'autres chemins) |
|
| 907 | + plugins_amorcer_plugins_actifs(); |
|
| 908 | + // mise a jour de la matrice des pipelines |
|
| 909 | + $prepend_code = pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche); |
|
| 910 | + // generer le fichier _CACHE_PIPELINE |
|
| 911 | + pipeline_precompile($prepend_code); |
|
| 912 | + |
|
| 913 | + if (spip_connect()) { |
|
| 914 | + // lancer et initialiser les nouveaux crons ! |
|
| 915 | + include_spip('inc/genie'); |
|
| 916 | + genie_queue_watch_dist(); |
|
| 917 | + } |
|
| 918 | + |
|
| 919 | + return ($GLOBALS['meta']['plugin'] != $actifs_avant); |
|
| 920 | 920 | } |
| 921 | 921 | |
| 922 | 922 | /** |
@@ -935,74 +935,74 @@ discard block |
||
| 935 | 935 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 936 | 936 | **/ |
| 937 | 937 | function plugins_precompile_chemin($plugin_valides, $ordre) { |
| 938 | - $chemins = [ |
|
| 939 | - 'public' => [], |
|
| 940 | - 'prive' => [] |
|
| 941 | - ]; |
|
| 942 | - $contenu = ''; |
|
| 943 | - foreach ($ordre as $p => $info) { |
|
| 944 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | - if (isset($plugin_valides[$p])) { |
|
| 946 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | - $plug = $plugin_valides[$p]['dir']; |
|
| 948 | - // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | - // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | - |
|
| 951 | - $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | - |
|
| 953 | - $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | - if ( |
|
| 955 | - $prefix !== 'SPIP' |
|
| 956 | - and !str_contains($dir, ':') // exclure le cas des procure: |
|
| 957 | - ) { |
|
| 958 | - $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | - if (!$info['chemin']) { |
|
| 960 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | - if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | - $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | - } |
|
| 965 | - } |
|
| 966 | - else { |
|
| 967 | - foreach ($info['chemin'] as $chemin) { |
|
| 968 | - if ( |
|
| 969 | - !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | - $chemin['version'], |
|
| 971 | - $GLOBALS['spip_version_branche'], |
|
| 972 | - 'spip' |
|
| 973 | - ) |
|
| 974 | - ) { |
|
| 975 | - $dir = $chemin['path']; |
|
| 976 | - if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | - $dir = substr($dir, 1); |
|
| 978 | - } |
|
| 979 | - if (strlen($dir) and $dir == './') { |
|
| 980 | - $dir = ''; |
|
| 981 | - } |
|
| 982 | - if (strlen($dir)) { |
|
| 983 | - $dir = rtrim($dir, '/') . '/'; |
|
| 984 | - } |
|
| 985 | - if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | - $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | - } |
|
| 988 | - if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | - $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | - } |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - } |
|
| 996 | - } |
|
| 997 | - if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | - $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | - ',', |
|
| 1000 | - array_reverse($chemins['public']) |
|
| 1001 | - ) . "]);\n" |
|
| 1002 | - . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | - } |
|
| 1004 | - |
|
| 1005 | - ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 938 | + $chemins = [ |
|
| 939 | + 'public' => [], |
|
| 940 | + 'prive' => [] |
|
| 941 | + ]; |
|
| 942 | + $contenu = ''; |
|
| 943 | + foreach ($ordre as $p => $info) { |
|
| 944 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 945 | + if (isset($plugin_valides[$p])) { |
|
| 946 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 947 | + $plug = $plugin_valides[$p]['dir']; |
|
| 948 | + // definir le plugin, donc le path avant l'include du fichier options |
|
| 949 | + // permet de faire des include_spip pour attraper un inc_ du plugin |
|
| 950 | + |
|
| 951 | + $dir = $dir_type . ".'" . $plug . "/'"; |
|
| 952 | + |
|
| 953 | + $prefix = strtoupper(preg_replace(',\W,', '_', $info['prefix'])); |
|
| 954 | + if ( |
|
| 955 | + $prefix !== 'SPIP' |
|
| 956 | + and !str_contains($dir, ':') // exclure le cas des procure: |
|
| 957 | + ) { |
|
| 958 | + $contenu .= "define('_DIR_PLUGIN_$prefix',$dir);\n"; |
|
| 959 | + if (!$info['chemin']) { |
|
| 960 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix"; |
|
| 961 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix"; |
|
| 962 | + if (is_dir(constant($dir_type) . $plug . '/squelettes/')) { |
|
| 963 | + $chemins['public'][] = "_DIR_PLUGIN_{$prefix}.'squelettes/'"; |
|
| 964 | + } |
|
| 965 | + } |
|
| 966 | + else { |
|
| 967 | + foreach ($info['chemin'] as $chemin) { |
|
| 968 | + if ( |
|
| 969 | + !isset($chemin['version']) or plugin_version_compatible( |
|
| 970 | + $chemin['version'], |
|
| 971 | + $GLOBALS['spip_version_branche'], |
|
| 972 | + 'spip' |
|
| 973 | + ) |
|
| 974 | + ) { |
|
| 975 | + $dir = $chemin['path']; |
|
| 976 | + if (strlen($dir) and $dir[0] == '/') { |
|
| 977 | + $dir = substr($dir, 1); |
|
| 978 | + } |
|
| 979 | + if (strlen($dir) and $dir == './') { |
|
| 980 | + $dir = ''; |
|
| 981 | + } |
|
| 982 | + if (strlen($dir)) { |
|
| 983 | + $dir = rtrim($dir, '/') . '/'; |
|
| 984 | + } |
|
| 985 | + if (!isset($chemin['type']) or $chemin['type'] == 'public') { |
|
| 986 | + $chemins['public'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 987 | + } |
|
| 988 | + if (!isset($chemin['type']) or $chemin['type'] == 'prive') { |
|
| 989 | + $chemins['prive'][] = "_DIR_PLUGIN_$prefix" . (strlen($dir) ? ".'$dir'" : ''); |
|
| 990 | + } |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + } |
|
| 996 | + } |
|
| 997 | + if (count($chemins['public']) or count($chemins['prive'])) { |
|
| 998 | + $contenu .= 'if (_DIR_RESTREINT) _chemin([' . implode( |
|
| 999 | + ',', |
|
| 1000 | + array_reverse($chemins['public']) |
|
| 1001 | + ) . "]);\n" |
|
| 1002 | + . 'else _chemin([' . implode(',', array_reverse($chemins['prive'])) . "]);\n"; |
|
| 1003 | + } |
|
| 1004 | + |
|
| 1005 | + ecrire_fichier_php(_CACHE_PLUGINS_PATH, $contenu); |
|
| 1006 | 1006 | } |
| 1007 | 1007 | |
| 1008 | 1008 | /** |
@@ -1020,67 +1020,67 @@ discard block |
||
| 1020 | 1020 | * Couples (prefixe => infos complètes) des plugins qui seront actifs, dans l'ordre de leurs dépendances |
| 1021 | 1021 | **/ |
| 1022 | 1022 | function plugins_precompile_xxxtions($plugin_valides, $ordre) { |
| 1023 | - $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | - $boutons = []; |
|
| 1025 | - $onglets = []; |
|
| 1026 | - $sign = ''; |
|
| 1027 | - |
|
| 1028 | - foreach ($ordre as $p => $info) { |
|
| 1029 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | - if (isset($plugin_valides[$p])) { |
|
| 1031 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | - $dir = constant($dir_type); |
|
| 1034 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | - if ($info['menu']) { |
|
| 1036 | - $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | - } |
|
| 1038 | - if ($info['onglet']) { |
|
| 1039 | - $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | - } |
|
| 1041 | - foreach ($contenu as $charge => $v) { |
|
| 1042 | - // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | - // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | - // donc ni sa relecture, ni sa detection |
|
| 1045 | - if ( |
|
| 1046 | - !isset($info[$charge]) |
|
| 1047 | - and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | - and !str_contains($dir, ':') // exclure le cas des procure: |
|
| 1049 | - and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | - ) { |
|
| 1051 | - if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | - $info[$charge] = [$file]; |
|
| 1053 | - } |
|
| 1054 | - } |
|
| 1055 | - if (isset($info[$charge])) { |
|
| 1056 | - $files = $info[$charge]; |
|
| 1057 | - foreach ($files as $k => $file) { |
|
| 1058 | - // on genere un if file_exists devant chaque include |
|
| 1059 | - // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | - $file = trim($file); |
|
| 1061 | - if ( |
|
| 1062 | - !is_readable("$dir$plug/$file") |
|
| 1063 | - // uniquement pour les paquet.xml |
|
| 1064 | - and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | - ) { |
|
| 1066 | - unset($info[$charge][$k]); |
|
| 1067 | - } else { |
|
| 1068 | - $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | - $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | - } |
|
| 1071 | - } |
|
| 1072 | - } |
|
| 1073 | - } |
|
| 1074 | - $sign .= md5(serialize($info)); |
|
| 1075 | - } |
|
| 1076 | - } |
|
| 1077 | - |
|
| 1078 | - $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | - $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | - . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | - |
|
| 1082 | - ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | - ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1023 | + $contenu = ['options' => '', 'fonctions' => '']; |
|
| 1024 | + $boutons = []; |
|
| 1025 | + $onglets = []; |
|
| 1026 | + $sign = ''; |
|
| 1027 | + |
|
| 1028 | + foreach ($ordre as $p => $info) { |
|
| 1029 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1030 | + if (isset($plugin_valides[$p])) { |
|
| 1031 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1032 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1033 | + $dir = constant($dir_type); |
|
| 1034 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1035 | + if ($info['menu']) { |
|
| 1036 | + $boutons = array_merge($boutons, $info['menu']); |
|
| 1037 | + } |
|
| 1038 | + if ($info['onglet']) { |
|
| 1039 | + $onglets = array_merge($onglets, $info['onglet']); |
|
| 1040 | + } |
|
| 1041 | + foreach ($contenu as $charge => $v) { |
|
| 1042 | + // si pas declare/detecte a la lecture du paquet.xml, |
|
| 1043 | + // detecer a nouveau ici puisque son ajout ne provoque pas une modif du paquet.xml |
|
| 1044 | + // donc ni sa relecture, ni sa detection |
|
| 1045 | + if ( |
|
| 1046 | + !isset($info[$charge]) |
|
| 1047 | + and $dir // exclure le cas du plugin "SPIP" |
|
| 1048 | + and !str_contains($dir, ':') // exclure le cas des procure: |
|
| 1049 | + and file_exists("$dir$plug/paquet.xml") // uniquement pour les paquet.xml |
|
| 1050 | + ) { |
|
| 1051 | + if (is_readable("$dir$plug/" . ($file = $info['prefix'] . '_' . $charge . '.php'))) { |
|
| 1052 | + $info[$charge] = [$file]; |
|
| 1053 | + } |
|
| 1054 | + } |
|
| 1055 | + if (isset($info[$charge])) { |
|
| 1056 | + $files = $info[$charge]; |
|
| 1057 | + foreach ($files as $k => $file) { |
|
| 1058 | + // on genere un if file_exists devant chaque include |
|
| 1059 | + // pour pouvoir garder le meme niveau d'erreur general |
|
| 1060 | + $file = trim($file); |
|
| 1061 | + if ( |
|
| 1062 | + !is_readable("$dir$plug/$file") |
|
| 1063 | + // uniquement pour les paquet.xml |
|
| 1064 | + and file_exists("$dir$plug/paquet.xml") |
|
| 1065 | + ) { |
|
| 1066 | + unset($info[$charge][$k]); |
|
| 1067 | + } else { |
|
| 1068 | + $_file = $root_dir_type . ".'$plug/$file'"; |
|
| 1069 | + $contenu[$charge] .= "include_once_check($_file);\n"; |
|
| 1070 | + } |
|
| 1071 | + } |
|
| 1072 | + } |
|
| 1073 | + } |
|
| 1074 | + $sign .= md5(serialize($info)); |
|
| 1075 | + } |
|
| 1076 | + } |
|
| 1077 | + |
|
| 1078 | + $contenu['options'] = "define('_PLUGINS_HASH','" . md5($sign) . "');\n" . $contenu['options']; |
|
| 1079 | + $contenu['fonctions'] .= plugin_ongletbouton('boutons_plugins', $boutons) |
|
| 1080 | + . plugin_ongletbouton('onglets_plugins', $onglets); |
|
| 1081 | + |
|
| 1082 | + ecrire_fichier_php(_CACHE_PLUGINS_OPT, $contenu['options']); |
|
| 1083 | + ecrire_fichier_php(_CACHE_PLUGINS_FCT, $contenu['fonctions']); |
|
| 1084 | 1084 | } |
| 1085 | 1085 | |
| 1086 | 1086 | /** |
@@ -1099,24 +1099,24 @@ discard block |
||
| 1099 | 1099 | * @return string Code php |
| 1100 | 1100 | */ |
| 1101 | 1101 | function plugin_ongletbouton($nom, $val) { |
| 1102 | - if (!$val) { |
|
| 1103 | - $val = []; |
|
| 1104 | - } |
|
| 1105 | - |
|
| 1106 | - $val = serialize($val); |
|
| 1107 | - $md5 = md5($val); |
|
| 1108 | - |
|
| 1109 | - if (!defined("_UPDATED_$nom")) { |
|
| 1110 | - define("_UPDATED_$nom", $val); |
|
| 1111 | - define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | - } |
|
| 1113 | - $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | - |
|
| 1115 | - return |
|
| 1116 | - "if (!function_exists('$nom')) {\n" |
|
| 1117 | - . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | - . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | - . "}\n"; |
|
| 1102 | + if (!$val) { |
|
| 1103 | + $val = []; |
|
| 1104 | + } |
|
| 1105 | + |
|
| 1106 | + $val = serialize($val); |
|
| 1107 | + $md5 = md5($val); |
|
| 1108 | + |
|
| 1109 | + if (!defined("_UPDATED_$nom")) { |
|
| 1110 | + define("_UPDATED_$nom", $val); |
|
| 1111 | + define("_UPDATED_md5_$nom", $md5); |
|
| 1112 | + } |
|
| 1113 | + $val = "unserialize('" . str_replace("'", "\'", $val) . "')"; |
|
| 1114 | + |
|
| 1115 | + return |
|
| 1116 | + "if (!function_exists('$nom')) {\n" |
|
| 1117 | + . "function $nom(){return defined('_UPDATED_$nom')?unserialize(_UPDATED_$nom):$val;}\n" |
|
| 1118 | + . "function md5_$nom(){return defined('_UPDATED_md5_$nom')?_UPDATED_md5_$nom:'" . $md5 . "';}\n" |
|
| 1119 | + . "}\n"; |
|
| 1120 | 1120 | } |
| 1121 | 1121 | |
| 1122 | 1122 | /** |
@@ -1131,15 +1131,15 @@ discard block |
||
| 1131 | 1131 | **/ |
| 1132 | 1132 | function plugins_amorcer_plugins_actifs() { |
| 1133 | 1133 | |
| 1134 | - if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | - include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | - } |
|
| 1134 | + if (@is_readable(_CACHE_PLUGINS_PATH)) { |
|
| 1135 | + include_once(_CACHE_PLUGINS_PATH); |
|
| 1136 | + } |
|
| 1137 | 1137 | |
| 1138 | - if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | - include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | - } else { |
|
| 1141 | - spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | - } |
|
| 1138 | + if (@is_readable(_CACHE_PLUGINS_OPT)) { |
|
| 1139 | + include_once(_CACHE_PLUGINS_OPT); |
|
| 1140 | + } else { |
|
| 1141 | + spip_log('pipelines desactives: impossible de produire ' . _CACHE_PLUGINS_OPT); |
|
| 1142 | + } |
|
| 1143 | 1143 | } |
| 1144 | 1144 | |
| 1145 | 1145 | /** |
@@ -1162,140 +1162,140 @@ discard block |
||
| 1162 | 1162 | * Couples (nom du pipeline => Code PHP à insérer au début du pipeline) |
| 1163 | 1163 | **/ |
| 1164 | 1164 | function pipeline_matrice_precompile($plugin_valides, $ordre, $pipe_recherche) { |
| 1165 | - static $liste_pipe_manquants = []; |
|
| 1166 | - if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | - $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | - } |
|
| 1169 | - |
|
| 1170 | - $prepend_code = []; |
|
| 1171 | - |
|
| 1172 | - foreach ($ordre as $p => $info) { |
|
| 1173 | - // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | - if (isset($plugin_valides[$p])) { |
|
| 1175 | - $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | - $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | - $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | - $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | - if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | - foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | - $nom = $pipe['nom']; |
|
| 1182 | - if (isset($pipe['action'])) { |
|
| 1183 | - $action = $pipe['action']; |
|
| 1184 | - } else { |
|
| 1185 | - $action = $nom; |
|
| 1186 | - } |
|
| 1187 | - $nomlower = strtolower($nom); |
|
| 1188 | - if ( |
|
| 1189 | - $nomlower != $nom |
|
| 1190 | - and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | - and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | - ) { |
|
| 1193 | - $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | - unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | - } |
|
| 1196 | - $nom = $nomlower; |
|
| 1197 | - // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | - if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | - $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | - } |
|
| 1201 | - if ($action) { |
|
| 1202 | - if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | - $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | - ',(\|\||$),', |
|
| 1205 | - "|$prefix$action\\1", |
|
| 1206 | - $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | - 1 |
|
| 1208 | - ); |
|
| 1209 | - } |
|
| 1210 | - if (isset($pipe['inclure'])) { |
|
| 1211 | - $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | - "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | - } |
|
| 1214 | - } |
|
| 1215 | - } |
|
| 1216 | - } |
|
| 1217 | - if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | - if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | - $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | - } |
|
| 1221 | - foreach ($info['genie'] as $genie) { |
|
| 1222 | - $nom = $prefix . $genie['nom']; |
|
| 1223 | - $periode = max(60, intval($genie['periode'])); |
|
| 1224 | - if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | - $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | - } else { |
|
| 1227 | - spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | - } |
|
| 1229 | - } |
|
| 1230 | - } |
|
| 1231 | - if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | - if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | - $prepend_code['insert_head_css'] = ''; |
|
| 1234 | - } |
|
| 1235 | - if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | - $prepend_code['header_prive_css'] = ''; |
|
| 1237 | - } |
|
| 1238 | - foreach ($info['style'] as $style) { |
|
| 1239 | - if (isset($style['path']) and $style['path']) { |
|
| 1240 | - $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | - } else { |
|
| 1242 | - $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | - } |
|
| 1244 | - $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | - if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | - $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | - } |
|
| 1248 | - $code .= "/>';\n"; |
|
| 1249 | - if ($style['type'] != 'prive') { |
|
| 1250 | - $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | - } |
|
| 1252 | - if ($style['type'] != 'public') { |
|
| 1253 | - $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | - } |
|
| 1255 | - } |
|
| 1256 | - } |
|
| 1257 | - if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | - $prepend_code['insert_head'] = ''; |
|
| 1259 | - } |
|
| 1260 | - if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | - $prepend_code['header_prive'] = ''; |
|
| 1262 | - } |
|
| 1263 | - if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | - foreach ($info['script'] as $script) { |
|
| 1265 | - if (isset($script['path']) and $script['path']) { |
|
| 1266 | - $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | - } else { |
|
| 1268 | - $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | - } |
|
| 1270 | - $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | - if ($script['type'] != 'prive') { |
|
| 1272 | - $prepend_code['insert_head'] .= $code; |
|
| 1273 | - } |
|
| 1274 | - if ($script['type'] != 'public') { |
|
| 1275 | - $prepend_code['header_prive'] .= $code; |
|
| 1276 | - } |
|
| 1277 | - } |
|
| 1278 | - } |
|
| 1279 | - } |
|
| 1280 | - } |
|
| 1281 | - |
|
| 1282 | - $prepend_code['insert_head'] = |
|
| 1283 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | - . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | - . $prepend_code['insert_head']; |
|
| 1286 | - $prepend_code['header_prive'] = |
|
| 1287 | - "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | - . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | - . $prepend_code['header_prive']; |
|
| 1290 | - |
|
| 1291 | - // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | - foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | - if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | - $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | - } |
|
| 1296 | - } |
|
| 1297 | - |
|
| 1298 | - return $prepend_code; |
|
| 1165 | + static $liste_pipe_manquants = []; |
|
| 1166 | + if (($pipe_recherche) && (!in_array($pipe_recherche, $liste_pipe_manquants))) { |
|
| 1167 | + $liste_pipe_manquants[] = $pipe_recherche; |
|
| 1168 | + } |
|
| 1169 | + |
|
| 1170 | + $prepend_code = []; |
|
| 1171 | + |
|
| 1172 | + foreach ($ordre as $p => $info) { |
|
| 1173 | + // $ordre peur contenir des plugins en attente et non valides pour ce hit |
|
| 1174 | + if (isset($plugin_valides[$p])) { |
|
| 1175 | + $dir_type = $plugin_valides[$p]['dir_type']; |
|
| 1176 | + $root_dir_type = str_replace('_DIR_', '_ROOT_', $dir_type); |
|
| 1177 | + $plug = $plugin_valides[$p]['dir']; |
|
| 1178 | + $prefix = (($info['prefix'] == 'spip') ? '' : $info['prefix'] . '_'); |
|
| 1179 | + if (isset($info['pipeline']) and is_array($info['pipeline'])) { |
|
| 1180 | + foreach ($info['pipeline'] as $pipe) { |
|
| 1181 | + $nom = $pipe['nom']; |
|
| 1182 | + if (isset($pipe['action'])) { |
|
| 1183 | + $action = $pipe['action']; |
|
| 1184 | + } else { |
|
| 1185 | + $action = $nom; |
|
| 1186 | + } |
|
| 1187 | + $nomlower = strtolower($nom); |
|
| 1188 | + if ( |
|
| 1189 | + $nomlower != $nom |
|
| 1190 | + and isset($GLOBALS['spip_pipeline'][$nom]) |
|
| 1191 | + and !isset($GLOBALS['spip_pipeline'][$nomlower]) |
|
| 1192 | + ) { |
|
| 1193 | + $GLOBALS['spip_pipeline'][$nomlower] = $GLOBALS['spip_pipeline'][$nom]; |
|
| 1194 | + unset($GLOBALS['spip_pipeline'][$nom]); |
|
| 1195 | + } |
|
| 1196 | + $nom = $nomlower; |
|
| 1197 | + // une action vide est une declaration qui ne doit pas etre compilee ! |
|
| 1198 | + if (!isset($GLOBALS['spip_pipeline'][$nom])) { // creer le pipeline eventuel |
|
| 1199 | + $GLOBALS['spip_pipeline'][$nom] = ''; |
|
| 1200 | + } |
|
| 1201 | + if ($action) { |
|
| 1202 | + if (strpos($GLOBALS['spip_pipeline'][$nom], (string) "|$prefix$action") === false) { |
|
| 1203 | + $GLOBALS['spip_pipeline'][$nom] = preg_replace( |
|
| 1204 | + ',(\|\||$),', |
|
| 1205 | + "|$prefix$action\\1", |
|
| 1206 | + $GLOBALS['spip_pipeline'][$nom], |
|
| 1207 | + 1 |
|
| 1208 | + ); |
|
| 1209 | + } |
|
| 1210 | + if (isset($pipe['inclure'])) { |
|
| 1211 | + $GLOBALS['spip_matrice']["$prefix$action"] = |
|
| 1212 | + "$root_dir_type:$plug/" . $pipe['inclure']; |
|
| 1213 | + } |
|
| 1214 | + } |
|
| 1215 | + } |
|
| 1216 | + } |
|
| 1217 | + if (isset($info['genie']) and is_countable($info['genie']) ? count($info['genie']) : 0) { |
|
| 1218 | + if (!isset($prepend_code['taches_generales_cron'])) { |
|
| 1219 | + $prepend_code['taches_generales_cron'] = ''; |
|
| 1220 | + } |
|
| 1221 | + foreach ($info['genie'] as $genie) { |
|
| 1222 | + $nom = $prefix . $genie['nom']; |
|
| 1223 | + $periode = max(60, intval($genie['periode'])); |
|
| 1224 | + if (charger_fonction($nom, 'genie', true)) { |
|
| 1225 | + $prepend_code['taches_generales_cron'] .= "\$val['$nom'] = $periode;\n"; |
|
| 1226 | + } else { |
|
| 1227 | + spip_log("Fonction genie_$nom introuvable", _LOG_ERREUR); |
|
| 1228 | + } |
|
| 1229 | + } |
|
| 1230 | + } |
|
| 1231 | + if (isset($info['style']) and is_countable($info['style']) ? count($info['style']) : 0) { |
|
| 1232 | + if (!isset($prepend_code['insert_head_css'])) { |
|
| 1233 | + $prepend_code['insert_head_css'] = ''; |
|
| 1234 | + } |
|
| 1235 | + if (!isset($prepend_code['header_prive_css'])) { |
|
| 1236 | + $prepend_code['header_prive_css'] = ''; |
|
| 1237 | + } |
|
| 1238 | + foreach ($info['style'] as $style) { |
|
| 1239 | + if (isset($style['path']) and $style['path']) { |
|
| 1240 | + $code = "if (\$f=timestamp(direction_css(find_in_path('" . addslashes($style['path']) . "')))) "; |
|
| 1241 | + } else { |
|
| 1242 | + $code = "if (\$f='" . addslashes($style['url']) . "') "; |
|
| 1243 | + } |
|
| 1244 | + $code .= "\$val .= '<link rel=\"stylesheet\" href=\"'.\$f.'\" type=\"text/css\""; |
|
| 1245 | + if (isset($style['media']) and strlen($style['media'])) { |
|
| 1246 | + $code .= ' media="' . addslashes($style['media']) . '"'; |
|
| 1247 | + } |
|
| 1248 | + $code .= "/>';\n"; |
|
| 1249 | + if ($style['type'] != 'prive') { |
|
| 1250 | + $prepend_code['insert_head_css'] .= $code; |
|
| 1251 | + } |
|
| 1252 | + if ($style['type'] != 'public') { |
|
| 1253 | + $prepend_code['header_prive_css'] .= $code; |
|
| 1254 | + } |
|
| 1255 | + } |
|
| 1256 | + } |
|
| 1257 | + if (!isset($prepend_code['insert_head'])) { |
|
| 1258 | + $prepend_code['insert_head'] = ''; |
|
| 1259 | + } |
|
| 1260 | + if (!isset($prepend_code['header_prive'])) { |
|
| 1261 | + $prepend_code['header_prive'] = ''; |
|
| 1262 | + } |
|
| 1263 | + if (isset($info['script']) and is_countable($info['script']) ? count($info['script']) : 0) { |
|
| 1264 | + foreach ($info['script'] as $script) { |
|
| 1265 | + if (isset($script['path']) and $script['path']) { |
|
| 1266 | + $code = "if (\$f=timestamp(find_in_path('" . addslashes($script['path']) . "'))) "; |
|
| 1267 | + } else { |
|
| 1268 | + $code = "if (\$f='" . addslashes($script['url']) . "') "; |
|
| 1269 | + } |
|
| 1270 | + $code .= "\$val .= '<script src=\"'.\$f.'\" type=\"text/javascript\"></script>';\n"; |
|
| 1271 | + if ($script['type'] != 'prive') { |
|
| 1272 | + $prepend_code['insert_head'] .= $code; |
|
| 1273 | + } |
|
| 1274 | + if ($script['type'] != 'public') { |
|
| 1275 | + $prepend_code['header_prive'] .= $code; |
|
| 1276 | + } |
|
| 1277 | + } |
|
| 1278 | + } |
|
| 1279 | + } |
|
| 1280 | + } |
|
| 1281 | + |
|
| 1282 | + $prepend_code['insert_head'] = |
|
| 1283 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines.php');\n" |
|
| 1284 | + . "\$val = minipipe('f_jQuery', \$val);\n" |
|
| 1285 | + . $prepend_code['insert_head']; |
|
| 1286 | + $prepend_code['header_prive'] = |
|
| 1287 | + "include_once_check(_DIR_RESTREINT . 'inc/pipelines_ecrire.php');\n" |
|
| 1288 | + . "\$val = minipipe('f_jQuery_prive', \$val);\n" |
|
| 1289 | + . $prepend_code['header_prive']; |
|
| 1290 | + |
|
| 1291 | + // on ajoute les pipe qui ont ete recenses manquants |
|
| 1292 | + foreach ($liste_pipe_manquants as $add_pipe) { |
|
| 1293 | + if (!isset($GLOBALS['spip_pipeline'][$add_pipe])) { |
|
| 1294 | + $GLOBALS['spip_pipeline'][$add_pipe] = ''; |
|
| 1295 | + } |
|
| 1296 | + } |
|
| 1297 | + |
|
| 1298 | + return $prepend_code; |
|
| 1299 | 1299 | } |
| 1300 | 1300 | |
| 1301 | 1301 | /** |
@@ -1322,62 +1322,62 @@ discard block |
||
| 1322 | 1322 | **/ |
| 1323 | 1323 | function pipeline_precompile($prepend_code = []) { |
| 1324 | 1324 | |
| 1325 | - $all_pipes = $all_pipes_end = ''; |
|
| 1326 | - if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | - $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | - unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | - $all_pipes = trim(array_shift($a)); |
|
| 1330 | - if ($all_pipes) { |
|
| 1331 | - $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | - } |
|
| 1333 | - if (count($a)) { |
|
| 1334 | - $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - $content = ''; |
|
| 1338 | - foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | - $s_inc = ''; |
|
| 1340 | - $s_call = ''; |
|
| 1341 | - if ($all_pipes) { |
|
| 1342 | - $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | - } |
|
| 1344 | - if ($all_pipes_end) { |
|
| 1345 | - $pipeline .= $all_pipes_end; |
|
| 1346 | - } |
|
| 1347 | - $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | - // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | - foreach ($pipe as $fonc) { |
|
| 1350 | - $fonc = trim($fonc); |
|
| 1351 | - $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | - if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | - $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | - $file = "'$file'"; |
|
| 1355 | - // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | - if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | - $dir = $regs[1]; |
|
| 1358 | - $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | - if (defined($root_dir)) { |
|
| 1360 | - $dir = $root_dir; |
|
| 1361 | - } |
|
| 1362 | - $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | - $file = str_replace("''.", '', $file); |
|
| 1364 | - $file = str_replace(constant($dir), '', $file); |
|
| 1365 | - } |
|
| 1366 | - $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | - } |
|
| 1368 | - } |
|
| 1369 | - if (strlen($s_inc)) { |
|
| 1370 | - $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | - } |
|
| 1372 | - $content .= "// Pipeline $action \n" |
|
| 1373 | - . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | - . $s_inc |
|
| 1375 | - . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | - . $s_call |
|
| 1377 | - . "return \$val;\n}\n"; |
|
| 1378 | - } |
|
| 1379 | - ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | - clear_path_cache(); |
|
| 1325 | + $all_pipes = $all_pipes_end = ''; |
|
| 1326 | + if (!empty($GLOBALS['spip_pipeline']['all'])) { |
|
| 1327 | + $a = explode('||', $GLOBALS['spip_pipeline']['all'], 2); |
|
| 1328 | + unset($GLOBALS['spip_pipeline']['all']); |
|
| 1329 | + $all_pipes = trim(array_shift($a)); |
|
| 1330 | + if ($all_pipes) { |
|
| 1331 | + $all_pipes = '|' . ltrim($all_pipes, '|'); |
|
| 1332 | + } |
|
| 1333 | + if (count($a)) { |
|
| 1334 | + $all_pipes_end = '||' . array_shift($a); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + $content = ''; |
|
| 1338 | + foreach ($GLOBALS['spip_pipeline'] as $action => $pipeline) { |
|
| 1339 | + $s_inc = ''; |
|
| 1340 | + $s_call = ''; |
|
| 1341 | + if ($all_pipes) { |
|
| 1342 | + $pipeline = preg_replace(',(\|\||$),', "$all_pipes\\1", $pipeline, 1); |
|
| 1343 | + } |
|
| 1344 | + if ($all_pipes_end) { |
|
| 1345 | + $pipeline .= $all_pipes_end; |
|
| 1346 | + } |
|
| 1347 | + $pipe = array_filter(explode('|', $pipeline)); |
|
| 1348 | + // Eclater le pipeline en filtres et appliquer chaque filtre |
|
| 1349 | + foreach ($pipe as $fonc) { |
|
| 1350 | + $fonc = trim($fonc); |
|
| 1351 | + $s_call .= '$val = minipipe(\'' . $fonc . '\', $val);' . "\n"; |
|
| 1352 | + if (isset($GLOBALS['spip_matrice'][$fonc])) { |
|
| 1353 | + $file = $GLOBALS['spip_matrice'][$fonc]; |
|
| 1354 | + $file = "'$file'"; |
|
| 1355 | + // si un _DIR_XXX: est dans la chaine, on extrait la constante |
|
| 1356 | + if (preg_match(',(_(DIR|ROOT)_[A-Z_]+):,Ums', $file, $regs)) { |
|
| 1357 | + $dir = $regs[1]; |
|
| 1358 | + $root_dir = str_replace('_DIR_', '_ROOT_', $dir); |
|
| 1359 | + if (defined($root_dir)) { |
|
| 1360 | + $dir = $root_dir; |
|
| 1361 | + } |
|
| 1362 | + $file = str_replace($regs[0], "'." . $dir . ".'", $file); |
|
| 1363 | + $file = str_replace("''.", '', $file); |
|
| 1364 | + $file = str_replace(constant($dir), '', $file); |
|
| 1365 | + } |
|
| 1366 | + $s_inc .= "include_once_check($file);\n"; |
|
| 1367 | + } |
|
| 1368 | + } |
|
| 1369 | + if (strlen($s_inc)) { |
|
| 1370 | + $s_inc = "static \$inc=null;\nif (!\$inc){\n$s_inc\$inc=true;\n}\n"; |
|
| 1371 | + } |
|
| 1372 | + $content .= "// Pipeline $action \n" |
|
| 1373 | + . "function execute_pipeline_$action(&\$val){\n" |
|
| 1374 | + . $s_inc |
|
| 1375 | + . ((isset($prepend_code[$action]) and strlen($prepend_code[$action])) ? trim($prepend_code[$action]) . "\n" : '') |
|
| 1376 | + . $s_call |
|
| 1377 | + . "return \$val;\n}\n"; |
|
| 1378 | + } |
|
| 1379 | + ecrire_fichier_php(_CACHE_PIPELINES, $content); |
|
| 1380 | + clear_path_cache(); |
|
| 1381 | 1381 | } |
| 1382 | 1382 | |
| 1383 | 1383 | |
@@ -1390,12 +1390,12 @@ discard block |
||
| 1390 | 1390 | * true si le plugin est actif, false sinon |
| 1391 | 1391 | **/ |
| 1392 | 1392 | function plugin_est_installe($plug_path) { |
| 1393 | - $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | - if (!$plugin_installes) { |
|
| 1395 | - return false; |
|
| 1396 | - } |
|
| 1393 | + $plugin_installes = isset($GLOBALS['meta']['plugin_installes']) ? unserialize($GLOBALS['meta']['plugin_installes']) : []; |
|
| 1394 | + if (!$plugin_installes) { |
|
| 1395 | + return false; |
|
| 1396 | + } |
|
| 1397 | 1397 | |
| 1398 | - return in_array($plug_path, $plugin_installes); |
|
| 1398 | + return in_array($plug_path, $plugin_installes); |
|
| 1399 | 1399 | } |
| 1400 | 1400 | |
| 1401 | 1401 | |
@@ -1408,46 +1408,46 @@ discard block |
||
| 1408 | 1408 | * @uses plugins_installer_dist() |
| 1409 | 1409 | **/ |
| 1410 | 1410 | function plugin_installes_meta() { |
| 1411 | - if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | - // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | - spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | - } |
|
| 1415 | - |
|
| 1416 | - $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | - $meta_plug_installes = []; |
|
| 1418 | - foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | - if ($plug = $resume['dir']) { |
|
| 1420 | - $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | - if ($infos) { |
|
| 1422 | - if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | - $meta_plug_installes[] = $plug; |
|
| 1424 | - } |
|
| 1425 | - if (is_array($infos)) { |
|
| 1426 | - [$ok, $trace] = $infos['install_test']; |
|
| 1427 | - $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | - $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | - if (_IS_CLI) { |
|
| 1430 | - include_spip('inc/filtres'); |
|
| 1431 | - $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | - $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | - echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | - $trace, |
|
| 1435 | - "\n"; |
|
| 1436 | - } |
|
| 1437 | - else { |
|
| 1438 | - include_spip('inc/filtres_boites'); |
|
| 1439 | - echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | - . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | - . $trace |
|
| 1442 | - . "<div class='result'>$result</div>" |
|
| 1443 | - . boite_fermer() |
|
| 1444 | - . '</div>'; |
|
| 1445 | - } |
|
| 1446 | - } |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - } |
|
| 1450 | - ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1411 | + if (isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1412 | + // attendre eventuellement l'invalidation du cache opcode |
|
| 1413 | + spip_attend_invalidation_opcode_cache($GLOBALS['fichier_php_compile_recent']); |
|
| 1414 | + } |
|
| 1415 | + |
|
| 1416 | + $installer_plugins = charger_fonction('installer', 'plugins'); |
|
| 1417 | + $meta_plug_installes = []; |
|
| 1418 | + foreach (unserialize($GLOBALS['meta']['plugin']) as $prefix => $resume) { |
|
| 1419 | + if ($plug = $resume['dir']) { |
|
| 1420 | + $infos = $installer_plugins($plug, 'install', $resume['dir_type']); |
|
| 1421 | + if ($infos) { |
|
| 1422 | + if (!is_array($infos) or $infos['install_test'][0]) { |
|
| 1423 | + $meta_plug_installes[] = $plug; |
|
| 1424 | + } |
|
| 1425 | + if (is_array($infos)) { |
|
| 1426 | + [$ok, $trace] = $infos['install_test']; |
|
| 1427 | + $titre = _T('plugin_titre_installation', ['plugin' => typo($infos['nom'])]); |
|
| 1428 | + $result = ($ok ? ((isset($infos['upgrade']) && $infos['upgrade']) ? _T('plugin_info_upgrade_ok') : _T('plugin_info_install_ok')) : _T('avis_operation_echec')); |
|
| 1429 | + if (_IS_CLI) { |
|
| 1430 | + include_spip('inc/filtres'); |
|
| 1431 | + $trace = ltrim(textebrut($trace) . "\n" . $result); |
|
| 1432 | + $trace = ' ' . str_replace("\n", "\n ", $trace); |
|
| 1433 | + echo "\n" . ($ok ? 'OK ' : '/!\ ') . textebrut($titre) . "\n", |
|
| 1434 | + $trace, |
|
| 1435 | + "\n"; |
|
| 1436 | + } |
|
| 1437 | + else { |
|
| 1438 | + include_spip('inc/filtres_boites'); |
|
| 1439 | + echo "<div class='install-plugins svp_retour'>" |
|
| 1440 | + . boite_ouvrir($titre, ($ok ? 'success' : 'error')) |
|
| 1441 | + . $trace |
|
| 1442 | + . "<div class='result'>$result</div>" |
|
| 1443 | + . boite_fermer() |
|
| 1444 | + . '</div>'; |
|
| 1445 | + } |
|
| 1446 | + } |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + } |
|
| 1450 | + ecrire_meta('plugin_installes', serialize($meta_plug_installes), 'non'); |
|
| 1451 | 1451 | } |
| 1452 | 1452 | |
| 1453 | 1453 | /** |
@@ -1461,29 +1461,29 @@ discard block |
||
| 1461 | 1461 | * Commentaire : code écrit en tout début de fichier, après la balise PHP ouvrante |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function ecrire_fichier_php($nom, $contenu, $comment = '') { |
| 1464 | - if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | - $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | - // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | - // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | - if (file_exists($nom)) { |
|
| 1472 | - if (substr($nom, -4) == '.php') { |
|
| 1473 | - $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | - } |
|
| 1475 | - else { |
|
| 1476 | - $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | - } |
|
| 1478 | - file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | - if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | - @unlink($fichier_tmp); |
|
| 1482 | - return; |
|
| 1483 | - } |
|
| 1484 | - @unlink($fichier_tmp); |
|
| 1485 | - } |
|
| 1486 | - ecrire_fichier($nom, $contenu); |
|
| 1487 | - $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | - spip_clear_opcode_cache(realpath($nom)); |
|
| 1464 | + if (!isset($GLOBALS['fichier_php_compile_recent'])) { |
|
| 1465 | + $GLOBALS['fichier_php_compile_recent'] = 0; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + $contenu = '<' . '?php' . "\n" . $comment . "\nif (defined('_ECRIRE_INC_VERSION')) {\n" . $contenu . "}\n?" . '>'; |
|
| 1469 | + // si un fichier existe deja on verifie que son contenu change avant de l'ecraser |
|
| 1470 | + // si pas de modif on ne touche pas au fichier initial |
|
| 1471 | + if (file_exists($nom)) { |
|
| 1472 | + if (substr($nom, -4) == '.php') { |
|
| 1473 | + $fichier_tmp = substr($nom, 0, -4) . '.tmp.php'; |
|
| 1474 | + } |
|
| 1475 | + else { |
|
| 1476 | + $fichier_tmp = $nom . '.tmp'; |
|
| 1477 | + } |
|
| 1478 | + file_put_contents($fichier_tmp, $contenu); |
|
| 1479 | + if (md5_file($nom) == md5_file($fichier_tmp)) { |
|
| 1480 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1481 | + @unlink($fichier_tmp); |
|
| 1482 | + return; |
|
| 1483 | + } |
|
| 1484 | + @unlink($fichier_tmp); |
|
| 1485 | + } |
|
| 1486 | + ecrire_fichier($nom, $contenu); |
|
| 1487 | + $GLOBALS['fichier_php_compile_recent'] = max($GLOBALS['fichier_php_compile_recent'], filemtime($nom)); |
|
| 1488 | + spip_clear_opcode_cache(realpath($nom)); |
|
| 1489 | 1489 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -47,24 +47,24 @@ discard block |
||
| 47 | 47 | * - false si l'arbre xml ne peut être créé ou est vide |
| 48 | 48 | **/ |
| 49 | 49 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 50 | - $contenu = ''; |
|
| 51 | - if (tester_url_absolue($fichier)) { |
|
| 52 | - include_spip('inc/distant'); |
|
| 53 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | - $contenu = $contenu['page'] ?? ''; |
|
| 55 | - } else { |
|
| 56 | - lire_fichier($fichier, $contenu); |
|
| 57 | - } |
|
| 58 | - $arbre = []; |
|
| 59 | - if ($contenu) { |
|
| 60 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | - } |
|
| 50 | + $contenu = ''; |
|
| 51 | + if (tester_url_absolue($fichier)) { |
|
| 52 | + include_spip('inc/distant'); |
|
| 53 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 54 | + $contenu = $contenu['page'] ?? ''; |
|
| 55 | + } else { |
|
| 56 | + lire_fichier($fichier, $contenu); |
|
| 57 | + } |
|
| 58 | + $arbre = []; |
|
| 59 | + if ($contenu) { |
|
| 60 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 61 | + } |
|
| 62 | 62 | |
| 63 | - return count($arbre) ? $arbre : false; |
|
| 63 | + return count($arbre) ? $arbre : false; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 67 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,150 +83,150 @@ discard block |
||
| 83 | 83 | * - false si l'arbre xml ne peut être créé ou est vide |
| 84 | 84 | **/ |
| 85 | 85 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 86 | - $out = []; |
|
| 87 | - // enlever les commentaires |
|
| 88 | - $charset = 'AUTO'; |
|
| 89 | - if ($clean === true) { |
|
| 90 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | - $charset = $regs[2]; |
|
| 92 | - } |
|
| 93 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | - include_spip('inc/charsets'); |
|
| 96 | - $clean = $charset; |
|
| 97 | - //$texte = importer_charset($texte,$charset); |
|
| 98 | - } |
|
| 99 | - if (is_string($clean)) { |
|
| 100 | - $charset = $clean; |
|
| 101 | - } |
|
| 102 | - $txt = $texte; |
|
| 86 | + $out = []; |
|
| 87 | + // enlever les commentaires |
|
| 88 | + $charset = 'AUTO'; |
|
| 89 | + if ($clean === true) { |
|
| 90 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 91 | + $charset = $regs[2]; |
|
| 92 | + } |
|
| 93 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 94 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 95 | + include_spip('inc/charsets'); |
|
| 96 | + $clean = $charset; |
|
| 97 | + //$texte = importer_charset($texte,$charset); |
|
| 98 | + } |
|
| 99 | + if (is_string($clean)) { |
|
| 100 | + $charset = $clean; |
|
| 101 | + } |
|
| 102 | + $txt = $texte; |
|
| 103 | 103 | |
| 104 | - // tant qu'il y a des tags |
|
| 105 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | - // tag ouvrant |
|
| 108 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 104 | + // tant qu'il y a des tags |
|
| 105 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 106 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 107 | + // tag ouvrant |
|
| 108 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 109 | 109 | |
| 110 | - // $before doit etre vide ou des espaces uniquements! |
|
| 111 | - $before = trim($chars[0]); |
|
| 110 | + // $before doit etre vide ou des espaces uniquements! |
|
| 111 | + $before = trim($chars[0]); |
|
| 112 | 112 | |
| 113 | - if (strlen($before) > 0) { |
|
| 114 | - return importer_charset($texte, $charset); |
|
| 115 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 113 | + if (strlen($before) > 0) { |
|
| 114 | + return importer_charset($texte, $charset); |
|
| 115 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 116 | 116 | |
| 117 | - $tag = rtrim($chars[1]); |
|
| 118 | - $txt = $chars[2]; |
|
| 117 | + $tag = rtrim($chars[1]); |
|
| 118 | + $txt = $chars[2]; |
|
| 119 | 119 | |
| 120 | - if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | - return importer_charset($texte, $charset); |
|
| 122 | - }//$texte; |
|
| 123 | - if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | - $out[$tag][] = ''; |
|
| 126 | - } else { |
|
| 127 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | - $closing_tag = reset($closing_tag); |
|
| 129 | - // tag fermant |
|
| 130 | - $ncclos = strlen("</$closing_tag>"); |
|
| 131 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | - if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | - $nclose = 0; |
|
| 134 | - $nopen = 0; |
|
| 135 | - $d = 0; |
|
| 136 | - while ( |
|
| 137 | - $p !== false |
|
| 138 | - and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | - and (($nopen += preg_match_all( |
|
| 140 | - '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | - $morceau, |
|
| 142 | - $matches, |
|
| 143 | - PREG_SET_ORDER |
|
| 144 | - )) > $nclose) |
|
| 145 | - ) { |
|
| 146 | - $nclose++; |
|
| 147 | - $d = $p + $ncclos; |
|
| 148 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - if ($p === false) { |
|
| 152 | - if ($strict) { |
|
| 153 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 120 | + if (strncmp($tag, '![CDATA[', 8) == 0) { |
|
| 121 | + return importer_charset($texte, $charset); |
|
| 122 | + }//$texte; |
|
| 123 | + if (substr($tag, -1) == '/') { // self closing tag |
|
| 124 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 125 | + $out[$tag][] = ''; |
|
| 126 | + } else { |
|
| 127 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 128 | + $closing_tag = reset($closing_tag); |
|
| 129 | + // tag fermant |
|
| 130 | + $ncclos = strlen("</$closing_tag>"); |
|
| 131 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 132 | + if ($p !== false and (strpos($txt, '<') < $p)) { |
|
| 133 | + $nclose = 0; |
|
| 134 | + $nopen = 0; |
|
| 135 | + $d = 0; |
|
| 136 | + while ( |
|
| 137 | + $p !== false |
|
| 138 | + and ($morceau = substr($txt, $d, $p - $d)) |
|
| 139 | + and (($nopen += preg_match_all( |
|
| 140 | + '{<' . preg_quote($closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 141 | + $morceau, |
|
| 142 | + $matches, |
|
| 143 | + PREG_SET_ORDER |
|
| 144 | + )) > $nclose) |
|
| 145 | + ) { |
|
| 146 | + $nclose++; |
|
| 147 | + $d = $p + $ncclos; |
|
| 148 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + if ($p === false) { |
|
| 152 | + if ($strict) { |
|
| 153 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 154 | 154 | |
| 155 | - return $out; |
|
| 156 | - } else { |
|
| 157 | - return importer_charset($texte, $charset); |
|
| 158 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | - } |
|
| 160 | - $content = substr($txt, 0, $p); |
|
| 161 | - $txt = substr($txt, $p + $ncclos); |
|
| 162 | - if ($profondeur == 0 or !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 163 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | - }//$content; |
|
| 165 | - else { |
|
| 166 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | - } |
|
| 171 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | - return $out; |
|
| 173 | - } else { |
|
| 174 | - return importer_charset($texte, $charset); |
|
| 175 | - }//$texte; |
|
| 155 | + return $out; |
|
| 156 | + } else { |
|
| 157 | + return importer_charset($texte, $charset); |
|
| 158 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 159 | + } |
|
| 160 | + $content = substr($txt, 0, $p); |
|
| 161 | + $txt = substr($txt, $p + $ncclos); |
|
| 162 | + if ($profondeur == 0 or !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 163 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 164 | + }//$content; |
|
| 165 | + else { |
|
| 166 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 170 | + } |
|
| 171 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 172 | + return $out; |
|
| 173 | + } else { |
|
| 174 | + return importer_charset($texte, $charset); |
|
| 175 | + }//$texte; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 179 | - $s = ''; |
|
| 180 | - if (is_array($arbre)) { |
|
| 181 | - foreach ($arbre as $tag => $feuille) { |
|
| 182 | - if (is_array($feuille)) { |
|
| 183 | - if ($tag !== intval($tag)) { |
|
| 184 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | - if (strlen($f)) { |
|
| 186 | - $tagf = explode(' ', $tag); |
|
| 187 | - $tagf = $tagf[0]; |
|
| 188 | - $s .= "<$tag>$f</$tagf>"; |
|
| 189 | - } else { |
|
| 190 | - $s .= "<$tag />"; |
|
| 191 | - } |
|
| 192 | - } else { |
|
| 193 | - $s .= spip_xml_aplatit($feuille); |
|
| 194 | - } |
|
| 195 | - $s .= $separateur; |
|
| 196 | - } else { |
|
| 197 | - $s .= "$feuille$separateur"; |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 179 | + $s = ''; |
|
| 180 | + if (is_array($arbre)) { |
|
| 181 | + foreach ($arbre as $tag => $feuille) { |
|
| 182 | + if (is_array($feuille)) { |
|
| 183 | + if ($tag !== intval($tag)) { |
|
| 184 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 185 | + if (strlen($f)) { |
|
| 186 | + $tagf = explode(' ', $tag); |
|
| 187 | + $tagf = $tagf[0]; |
|
| 188 | + $s .= "<$tag>$f</$tagf>"; |
|
| 189 | + } else { |
|
| 190 | + $s .= "<$tag />"; |
|
| 191 | + } |
|
| 192 | + } else { |
|
| 193 | + $s .= spip_xml_aplatit($feuille); |
|
| 194 | + } |
|
| 195 | + $s .= $separateur; |
|
| 196 | + } else { |
|
| 197 | + $s .= "$feuille$separateur"; |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | 201 | |
| 202 | - return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 202 | + return strlen($separateur) ? substr($s, 0, -strlen($separateur)) : $s; |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | function spip_xml_tagname($tag) { |
| 206 | - if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | - return $reg[1]; |
|
| 208 | - } |
|
| 206 | + if (preg_match(',^([a-z][\w:]*),i', $tag, $reg)) { |
|
| 207 | + return $reg[1]; |
|
| 208 | + } |
|
| 209 | 209 | |
| 210 | - return ''; |
|
| 210 | + return ''; |
|
| 211 | 211 | } |
| 212 | 212 | |
| 213 | 213 | function spip_xml_decompose_tag($tag) { |
| 214 | - $tagname = spip_xml_tagname($tag); |
|
| 215 | - $liste = []; |
|
| 216 | - $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | - $p = strpos($tag, '='); |
|
| 218 | - while ($p !== false) { |
|
| 219 | - $attr = trim(substr($tag, 0, $p)); |
|
| 220 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | - $quote = $tag[0]; |
|
| 222 | - $p = strpos($tag, $quote, 1); |
|
| 223 | - $cont = substr($tag, 1, $p - 1); |
|
| 224 | - $liste[$attr] = $cont; |
|
| 225 | - $tag = substr($tag, $p + 1); |
|
| 226 | - $p = strpos($tag, '='); |
|
| 227 | - } |
|
| 214 | + $tagname = spip_xml_tagname($tag); |
|
| 215 | + $liste = []; |
|
| 216 | + $tag = ltrim(strpbrk($tag, " \n\t")); |
|
| 217 | + $p = strpos($tag, '='); |
|
| 218 | + while ($p !== false) { |
|
| 219 | + $attr = trim(substr($tag, 0, $p)); |
|
| 220 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 221 | + $quote = $tag[0]; |
|
| 222 | + $p = strpos($tag, $quote, 1); |
|
| 223 | + $cont = substr($tag, 1, $p - 1); |
|
| 224 | + $liste[$attr] = $cont; |
|
| 225 | + $tag = substr($tag, $p + 1); |
|
| 226 | + $p = strpos($tag, '='); |
|
| 227 | + } |
|
| 228 | 228 | |
| 229 | - return [$tagname, $liste]; |
|
| 229 | + return [$tagname, $liste]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 250 | 250 | **/ |
| 251 | 251 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 252 | - if ($init) { |
|
| 253 | - $matches = []; |
|
| 254 | - } |
|
| 255 | - if (is_array($arbre) && count($arbre)) { |
|
| 256 | - foreach (array_keys($arbre) as $tag) { |
|
| 257 | - if (preg_match($regexp, $tag)) { |
|
| 258 | - $matches[$tag] = &$arbre[$tag]; |
|
| 259 | - } |
|
| 260 | - if (is_array($arbre[$tag])) { |
|
| 261 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 252 | + if ($init) { |
|
| 253 | + $matches = []; |
|
| 254 | + } |
|
| 255 | + if (is_array($arbre) && count($arbre)) { |
|
| 256 | + foreach (array_keys($arbre) as $tag) { |
|
| 257 | + if (preg_match($regexp, $tag)) { |
|
| 258 | + $matches[$tag] = &$arbre[$tag]; |
|
| 259 | + } |
|
| 260 | + if (is_array($arbre[$tag])) { |
|
| 261 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 262 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 269 | 269 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | * @return void |
| 29 | 29 | */ |
| 30 | 30 | function inc_config_dist() { |
| 31 | - actualise_metas(liste_metas()); |
|
| 31 | + actualise_metas(liste_metas()); |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | /** |
@@ -45,34 +45,34 @@ discard block |
||
| 45 | 45 | * Liste (table, casier, sous_casier) |
| 46 | 46 | */ |
| 47 | 47 | function expliquer_config($cfg) { |
| 48 | - // par defaut, sur la table des meta |
|
| 49 | - $table = 'meta'; |
|
| 50 | - $casier = null; |
|
| 51 | - $sous_casier = []; |
|
| 52 | - $cfg = explode('/', $cfg); |
|
| 53 | - |
|
| 54 | - // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | - if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | - array_shift($cfg); |
|
| 57 | - $table = array_shift($cfg); |
|
| 58 | - if (!isset($GLOBALS[$table])) { |
|
| 59 | - lire_metas($table); |
|
| 60 | - } |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | - if (count($cfg)) { |
|
| 65 | - // pas sur un appel vide '' |
|
| 66 | - if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | - $casier = $c; |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - if (count($cfg)) { |
|
| 72 | - $sous_casier = $cfg; |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return [$table, $casier, $sous_casier]; |
|
| 48 | + // par defaut, sur la table des meta |
|
| 49 | + $table = 'meta'; |
|
| 50 | + $casier = null; |
|
| 51 | + $sous_casier = []; |
|
| 52 | + $cfg = explode('/', $cfg); |
|
| 53 | + |
|
| 54 | + // si le premier argument est vide, c'est une syntaxe /table/ ou un appel vide '' |
|
| 55 | + if (!reset($cfg) and count($cfg) > 1) { |
|
| 56 | + array_shift($cfg); |
|
| 57 | + $table = array_shift($cfg); |
|
| 58 | + if (!isset($GLOBALS[$table])) { |
|
| 59 | + lire_metas($table); |
|
| 60 | + } |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 64 | + if (count($cfg)) { |
|
| 65 | + // pas sur un appel vide '' |
|
| 66 | + if ('' !== ($c = array_shift($cfg))) { |
|
| 67 | + $casier = $c; |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + if (count($cfg)) { |
|
| 72 | + $sous_casier = $cfg; |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return [$table, $casier, $sous_casier]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | /** |
@@ -100,65 +100,65 @@ discard block |
||
| 100 | 100 | * Contenu de la configuration obtenue |
| 101 | 101 | */ |
| 102 | 102 | function lire_config($cfg = '', $def = null, $unserialize = true) { |
| 103 | - // lire le stockage sous la forme /table/valeur |
|
| 104 | - // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | - // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | - |
|
| 107 | - // traiter en priorite le cas simple et frequent |
|
| 108 | - // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | - if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | - $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | - ((!$unserialize |
|
| 112 | - // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | - or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | - // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | - or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | - or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | - : $def; |
|
| 118 | - |
|
| 119 | - return $r; |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - // Brancher sur methodes externes si besoin |
|
| 123 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | - $methode = substr($cfg, 0, $p); |
|
| 125 | - $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | - |
|
| 127 | - return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | - |
|
| 132 | - if (!isset($GLOBALS[$table])) { |
|
| 133 | - return $def; |
|
| 134 | - } |
|
| 135 | - |
|
| 136 | - $r = $GLOBALS[$table]; |
|
| 137 | - |
|
| 138 | - // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | - if (!$casier) { |
|
| 140 | - return $unserialize ? $r : serialize($r); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - // casier principal : |
|
| 144 | - // le deserializer si demande |
|
| 145 | - // ou si on a besoin |
|
| 146 | - // d'un sous casier |
|
| 147 | - $r = $r[$casier] ?? null; |
|
| 148 | - if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | - $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | - } |
|
| 151 | - |
|
| 152 | - // aller chercher le sous_casier |
|
| 153 | - while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | - $r = $r[$casier] ?? null; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($r)) { |
|
| 158 | - return $def; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $r; |
|
| 103 | + // lire le stockage sous la forme /table/valeur |
|
| 104 | + // ou valeur qui est en fait implicitement /meta/valeur |
|
| 105 | + // ou casier/valeur qui est en fait implicitement /meta/casier/valeur |
|
| 106 | + |
|
| 107 | + // traiter en priorite le cas simple et frequent |
|
| 108 | + // de lecture direct $GLOBALS['meta']['truc'], si $cfg ne contient ni / ni : |
|
| 109 | + if ($cfg and strpbrk($cfg, '/:') === false) { |
|
| 110 | + $r = isset($GLOBALS['meta'][$cfg]) ? |
|
| 111 | + ((!$unserialize |
|
| 112 | + // ne pas essayer de deserialiser autre chose qu'une chaine |
|
| 113 | + or !is_string($GLOBALS['meta'][$cfg]) |
|
| 114 | + // ne pas essayer de deserialiser si ce n'est visiblement pas une chaine serializee |
|
| 115 | + or !str_contains($GLOBALS['meta'][$cfg], ':') |
|
| 116 | + or ($t = @unserialize($GLOBALS['meta'][$cfg])) === false) ? $GLOBALS['meta'][$cfg] : $t) |
|
| 117 | + : $def; |
|
| 118 | + |
|
| 119 | + return $r; |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + // Brancher sur methodes externes si besoin |
|
| 123 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 124 | + $methode = substr($cfg, 0, $p); |
|
| 125 | + $lire_config = charger_fonction($methode, 'lire_config'); |
|
| 126 | + |
|
| 127 | + return $lire_config(substr($cfg, $p + 2), $def, $unserialize); |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 131 | + |
|
| 132 | + if (!isset($GLOBALS[$table])) { |
|
| 133 | + return $def; |
|
| 134 | + } |
|
| 135 | + |
|
| 136 | + $r = $GLOBALS[$table]; |
|
| 137 | + |
|
| 138 | + // si on a demande #CONFIG{/meta,'',0} |
|
| 139 | + if (!$casier) { |
|
| 140 | + return $unserialize ? $r : serialize($r); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + // casier principal : |
|
| 144 | + // le deserializer si demande |
|
| 145 | + // ou si on a besoin |
|
| 146 | + // d'un sous casier |
|
| 147 | + $r = $r[$casier] ?? null; |
|
| 148 | + if (($unserialize or is_countable($sous_casier) ? count($sous_casier) : 0) and $r and is_string($r)) { |
|
| 149 | + $r = (($t = @unserialize($r)) === false ? $r : $t); |
|
| 150 | + } |
|
| 151 | + |
|
| 152 | + // aller chercher le sous_casier |
|
| 153 | + while (!is_null($r) and $casier = array_shift($sous_casier)) { |
|
| 154 | + $r = $r[$casier] ?? null; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($r)) { |
|
| 158 | + return $def; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $r; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -172,7 +172,7 @@ discard block |
||
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | 174 | function lire_config_metapack_dist($cfg = '', $def = null, $unserialize = true) { |
| 175 | - return lire_config($cfg, $def, $unserialize); |
|
| 175 | + return lire_config($cfg, $def, $unserialize); |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -184,144 +184,144 @@ discard block |
||
| 184 | 184 | * @return bool |
| 185 | 185 | */ |
| 186 | 186 | function ecrire_config($cfg, $store) { |
| 187 | - // Brancher sur methodes externes si besoin |
|
| 188 | - if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | - $methode = substr($cfg, 0, $p); |
|
| 190 | - $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | - |
|
| 192 | - return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | - // il faut au moins un casier pour ecrire |
|
| 197 | - if (!$casier) { |
|
| 198 | - return false; |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - // trouvons ou creons le pointeur sur le casier |
|
| 202 | - $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | - if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | - if ($st === null) { |
|
| 205 | - // ne rien creer si c'est une demande d'effacement |
|
| 206 | - if ($store === null) { |
|
| 207 | - return false; |
|
| 208 | - } |
|
| 209 | - $st = []; |
|
| 210 | - } else { |
|
| 211 | - $st = unserialize($st); |
|
| 212 | - if ($st === false) { |
|
| 213 | - // ne rien creer si c'est une demande d'effacement |
|
| 214 | - if ($store === null) { |
|
| 215 | - return false; |
|
| 216 | - } |
|
| 217 | - $st = []; |
|
| 218 | - } |
|
| 219 | - } |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - $has_planes = false; |
|
| 223 | - // si on a affaire a un sous caiser |
|
| 224 | - // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | - if ($c = $sous_casier) { |
|
| 226 | - $sc = &$st; |
|
| 227 | - $pointeurs = []; |
|
| 228 | - while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | - // creer l'entree si elle n'existe pas |
|
| 230 | - if (!isset($sc[$cc])) { |
|
| 231 | - // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | - // ne rien creer mais sortir |
|
| 233 | - if (is_null($store)) { |
|
| 234 | - return false; |
|
| 235 | - } |
|
| 236 | - $sc[$cc] = []; |
|
| 237 | - } |
|
| 238 | - $pointeurs[$cc] = &$sc; |
|
| 239 | - $sc = &$sc[$cc]; |
|
| 240 | - } |
|
| 241 | - |
|
| 242 | - // si c'est une demande d'effacement |
|
| 243 | - if (is_null($store)) { |
|
| 244 | - $c = $sous_casier; |
|
| 245 | - $sous = array_pop($c); |
|
| 246 | - // effacer, et remonter pour effacer les parents vides |
|
| 247 | - do { |
|
| 248 | - unset($pointeurs[$sous][$sous]); |
|
| 249 | - } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | - |
|
| 251 | - // si on a vide tous les sous casiers, |
|
| 252 | - // et que le casier est vide |
|
| 253 | - // vider aussi la meta |
|
| 254 | - if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | - $st = null; |
|
| 256 | - } |
|
| 257 | - } // dans tous les autres cas, on ecrase |
|
| 258 | - else { |
|
| 259 | - if ( |
|
| 260 | - defined('_MYSQL_NOPLANES') |
|
| 261 | - and _MYSQL_NOPLANES |
|
| 262 | - and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | - and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | - ) { |
|
| 265 | - // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | - // @see utf8_noplanes |
|
| 267 | - $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | - // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | - if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | - if (!function_exists('utf8_noplanes')) { |
|
| 271 | - include_spip('inc/charsets'); |
|
| 272 | - } |
|
| 273 | - if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | - $has_planes = true; |
|
| 275 | - } |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $sc = $store; |
|
| 280 | - } |
|
| 281 | - |
|
| 282 | - // Maintenant que $st est modifiee |
|
| 283 | - // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | - $store = $st; |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - if (is_null($store)) { |
|
| 288 | - if (is_null($st) and !$sous_casier) { |
|
| 289 | - return false; |
|
| 290 | - } // la config n'existait deja pas ! |
|
| 291 | - effacer_meta($casier, $table); |
|
| 292 | - supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | - } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | - else { |
|
| 295 | - if (!isset($GLOBALS[$table])) { |
|
| 296 | - installer_table_meta($table); |
|
| 297 | - } |
|
| 298 | - // si ce n'est pas une chaine |
|
| 299 | - // il faut serializer |
|
| 300 | - if (!is_string($store)) { |
|
| 301 | - $serialized_store = serialize($store); |
|
| 302 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | - // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | - // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | - if ($has_planes) { |
|
| 306 | - $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | - if ($check_store !== $serialized_store) { |
|
| 308 | - array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | - if (is_string($value)) { |
|
| 310 | - $value = utf8_noplanes($value); |
|
| 311 | - } |
|
| 312 | - }); |
|
| 313 | - $serialized_store = serialize($store); |
|
| 314 | - ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - else { |
|
| 319 | - ecrire_meta($casier, $store, null, $table); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - |
|
| 323 | - // verifier que lire_config($cfg)==$store ? |
|
| 324 | - return true; |
|
| 187 | + // Brancher sur methodes externes si besoin |
|
| 188 | + if ($cfg and $p = strpos($cfg, '::')) { |
|
| 189 | + $methode = substr($cfg, 0, $p); |
|
| 190 | + $ecrire_config = charger_fonction($methode, 'ecrire_config'); |
|
| 191 | + |
|
| 192 | + return $ecrire_config(substr($cfg, $p + 2), $store); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + [$table, $casier, $sous_casier] = expliquer_config($cfg); |
|
| 196 | + // il faut au moins un casier pour ecrire |
|
| 197 | + if (!$casier) { |
|
| 198 | + return false; |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + // trouvons ou creons le pointeur sur le casier |
|
| 202 | + $st = $GLOBALS[$table][$casier] ?? null; |
|
| 203 | + if (!is_array($st) and ($sous_casier or is_array($store))) { |
|
| 204 | + if ($st === null) { |
|
| 205 | + // ne rien creer si c'est une demande d'effacement |
|
| 206 | + if ($store === null) { |
|
| 207 | + return false; |
|
| 208 | + } |
|
| 209 | + $st = []; |
|
| 210 | + } else { |
|
| 211 | + $st = unserialize($st); |
|
| 212 | + if ($st === false) { |
|
| 213 | + // ne rien creer si c'est une demande d'effacement |
|
| 214 | + if ($store === null) { |
|
| 215 | + return false; |
|
| 216 | + } |
|
| 217 | + $st = []; |
|
| 218 | + } |
|
| 219 | + } |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + $has_planes = false; |
|
| 223 | + // si on a affaire a un sous caiser |
|
| 224 | + // il faut ecrire au bon endroit sans perdre les autres sous casier freres |
|
| 225 | + if ($c = $sous_casier) { |
|
| 226 | + $sc = &$st; |
|
| 227 | + $pointeurs = []; |
|
| 228 | + while (is_countable($c) ? count($c) : 0 and $cc = array_shift($c)) { |
|
| 229 | + // creer l'entree si elle n'existe pas |
|
| 230 | + if (!isset($sc[$cc])) { |
|
| 231 | + // si on essaye d'effacer une config qui n'existe pas |
|
| 232 | + // ne rien creer mais sortir |
|
| 233 | + if (is_null($store)) { |
|
| 234 | + return false; |
|
| 235 | + } |
|
| 236 | + $sc[$cc] = []; |
|
| 237 | + } |
|
| 238 | + $pointeurs[$cc] = &$sc; |
|
| 239 | + $sc = &$sc[$cc]; |
|
| 240 | + } |
|
| 241 | + |
|
| 242 | + // si c'est une demande d'effacement |
|
| 243 | + if (is_null($store)) { |
|
| 244 | + $c = $sous_casier; |
|
| 245 | + $sous = array_pop($c); |
|
| 246 | + // effacer, et remonter pour effacer les parents vides |
|
| 247 | + do { |
|
| 248 | + unset($pointeurs[$sous][$sous]); |
|
| 249 | + } while ($sous = array_pop($c) and !(is_countable($pointeurs[$sous][$sous]) ? count($pointeurs[$sous][$sous]) : 0)); |
|
| 250 | + |
|
| 251 | + // si on a vide tous les sous casiers, |
|
| 252 | + // et que le casier est vide |
|
| 253 | + // vider aussi la meta |
|
| 254 | + if (!$sous and !(is_countable($st) ? count($st) : 0)) { |
|
| 255 | + $st = null; |
|
| 256 | + } |
|
| 257 | + } // dans tous les autres cas, on ecrase |
|
| 258 | + else { |
|
| 259 | + if ( |
|
| 260 | + defined('_MYSQL_NOPLANES') |
|
| 261 | + and _MYSQL_NOPLANES |
|
| 262 | + and !empty($GLOBALS['meta']['charset_sql_connexion']) |
|
| 263 | + and $GLOBALS['meta']['charset_sql_connexion'] == 'utf8' |
|
| 264 | + ) { |
|
| 265 | + // detecter si la valeur qu'on veut ecrire a des planes |
|
| 266 | + // @see utf8_noplanes |
|
| 267 | + $serialized_store = (is_string($store) ? $store : serialize($store)); |
|
| 268 | + // un preg_match rapide pour voir si ca vaut le coup de lancer utf8_noplanes |
|
| 269 | + if (preg_match(',[\xF0-\xF4],ms', $serialized_store)) { |
|
| 270 | + if (!function_exists('utf8_noplanes')) { |
|
| 271 | + include_spip('inc/charsets'); |
|
| 272 | + } |
|
| 273 | + if ($serialized_store !== utf8_noplanes($serialized_store)) { |
|
| 274 | + $has_planes = true; |
|
| 275 | + } |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $sc = $store; |
|
| 280 | + } |
|
| 281 | + |
|
| 282 | + // Maintenant que $st est modifiee |
|
| 283 | + // reprenons la comme valeur a stocker dans le casier principal |
|
| 284 | + $store = $st; |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + if (is_null($store)) { |
|
| 288 | + if (is_null($st) and !$sous_casier) { |
|
| 289 | + return false; |
|
| 290 | + } // la config n'existait deja pas ! |
|
| 291 | + effacer_meta($casier, $table); |
|
| 292 | + supprimer_table_meta($table); // supprimons la table (si elle est bien vide) |
|
| 293 | + } // les meta ne peuvent etre que des chaines : il faut serializer le reste |
|
| 294 | + else { |
|
| 295 | + if (!isset($GLOBALS[$table])) { |
|
| 296 | + installer_table_meta($table); |
|
| 297 | + } |
|
| 298 | + // si ce n'est pas une chaine |
|
| 299 | + // il faut serializer |
|
| 300 | + if (!is_string($store)) { |
|
| 301 | + $serialized_store = serialize($store); |
|
| 302 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 303 | + // et dans ce cas il faut verifier que l'ecriture en base a bien eu lieu a l'identique si il y a des planes dans la chaine |
|
| 304 | + // car sinon ca casse le serialize PHP - par exemple si on est en mysql utf8 (non mb4) |
|
| 305 | + if ($has_planes) { |
|
| 306 | + $check_store = sql_getfetsel('valeur', 'spip_' . $table, 'nom=' . sql_quote($casier)); |
|
| 307 | + if ($check_store !== $serialized_store) { |
|
| 308 | + array_walk_recursive($store, function (&$value, $key) { |
|
| 309 | + if (is_string($value)) { |
|
| 310 | + $value = utf8_noplanes($value); |
|
| 311 | + } |
|
| 312 | + }); |
|
| 313 | + $serialized_store = serialize($store); |
|
| 314 | + ecrire_meta($casier, $serialized_store, null, $table); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + else { |
|
| 319 | + ecrire_meta($casier, $store, null, $table); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + |
|
| 323 | + // verifier que lire_config($cfg)==$store ? |
|
| 324 | + return true; |
|
| 325 | 325 | } |
| 326 | 326 | |
| 327 | 327 | |
@@ -335,14 +335,14 @@ discard block |
||
| 335 | 335 | * @return bool |
| 336 | 336 | */ |
| 337 | 337 | function ecrire_config_metapack_dist($cfg, $store) { |
| 338 | - // cas particulier en metapack:: |
|
| 339 | - // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | - // intacte en sortie ... |
|
| 341 | - if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | - $store = serialize($store); |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return ecrire_config($cfg, $store); |
|
| 338 | + // cas particulier en metapack:: |
|
| 339 | + // si on ecrit une chaine deja serializee, il faut la reserializer pour la rendre |
|
| 340 | + // intacte en sortie ... |
|
| 341 | + if (is_string($store) and strpos($store, ':') and unserialize($store)) { |
|
| 342 | + $store = serialize($store); |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return ecrire_config($cfg, $store); |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -352,9 +352,9 @@ discard block |
||
| 352 | 352 | * @return bool |
| 353 | 353 | */ |
| 354 | 354 | function effacer_config($cfg) { |
| 355 | - ecrire_config($cfg, null); |
|
| 355 | + ecrire_config($cfg, null); |
|
| 356 | 356 | |
| 357 | - return true; |
|
| 357 | + return true; |
|
| 358 | 358 | } |
| 359 | 359 | |
| 360 | 360 | /** |
@@ -371,58 +371,58 @@ discard block |
||
| 371 | 371 | * Couples nom de la `meta` => valeur par défaut |
| 372 | 372 | */ |
| 373 | 373 | function liste_metas() { |
| 374 | - return pipeline('configurer_liste_metas', [ |
|
| 375 | - 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | - 'slogan_site' => '', |
|
| 377 | - 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | - 'descriptif_site' => '', |
|
| 379 | - 'activer_logos' => 'oui', |
|
| 380 | - 'activer_logos_survol' => 'non', |
|
| 381 | - 'articles_surtitre' => 'non', |
|
| 382 | - 'articles_soustitre' => 'non', |
|
| 383 | - 'articles_descriptif' => 'non', |
|
| 384 | - 'articles_chapeau' => 'non', |
|
| 385 | - 'articles_texte' => 'oui', |
|
| 386 | - 'articles_ps' => 'non', |
|
| 387 | - 'articles_redac' => 'non', |
|
| 388 | - 'post_dates' => 'non', |
|
| 389 | - 'articles_urlref' => 'non', |
|
| 390 | - 'articles_redirection' => 'non', |
|
| 391 | - 'creer_preview' => 'non', |
|
| 392 | - 'taille_preview' => 150, |
|
| 393 | - 'articles_modif' => 'non', |
|
| 394 | - |
|
| 395 | - 'rubriques_descriptif' => 'non', |
|
| 396 | - 'rubriques_texte' => 'oui', |
|
| 397 | - |
|
| 398 | - 'accepter_inscriptions' => 'non', |
|
| 399 | - 'accepter_visiteurs' => 'non', |
|
| 400 | - 'prevenir_auteurs' => 'non', |
|
| 401 | - 'suivi_edito' => 'non', |
|
| 402 | - 'adresse_suivi' => '', |
|
| 403 | - 'adresse_suivi_inscription' => '', |
|
| 404 | - 'adresse_neuf' => '', |
|
| 405 | - 'jours_neuf' => '', |
|
| 406 | - 'quoi_de_neuf' => 'non', |
|
| 407 | - 'preview' => ',0minirezo,1comite,', |
|
| 408 | - |
|
| 409 | - 'syndication_integrale' => 'oui', |
|
| 410 | - 'charset' => _DEFAULT_CHARSET, |
|
| 411 | - 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | - |
|
| 413 | - 'multi_rubriques' => 'non', |
|
| 414 | - 'multi_secteurs' => 'non', |
|
| 415 | - 'gerer_trad' => 'non', |
|
| 416 | - 'langues_multilingue' => '', |
|
| 417 | - |
|
| 418 | - 'version_html_max' => 'html4', |
|
| 419 | - |
|
| 420 | - 'type_urls' => 'page', |
|
| 421 | - |
|
| 422 | - 'email_envoi' => '', |
|
| 423 | - 'email_webmaster' => '', |
|
| 424 | - 'auto_compress_http' => 'non', |
|
| 425 | - ]); |
|
| 374 | + return pipeline('configurer_liste_metas', [ |
|
| 375 | + 'nom_site' => _T('info_mon_site_spip'), |
|
| 376 | + 'slogan_site' => '', |
|
| 377 | + 'adresse_site' => preg_replace(',/$,', '', url_de_base()), |
|
| 378 | + 'descriptif_site' => '', |
|
| 379 | + 'activer_logos' => 'oui', |
|
| 380 | + 'activer_logos_survol' => 'non', |
|
| 381 | + 'articles_surtitre' => 'non', |
|
| 382 | + 'articles_soustitre' => 'non', |
|
| 383 | + 'articles_descriptif' => 'non', |
|
| 384 | + 'articles_chapeau' => 'non', |
|
| 385 | + 'articles_texte' => 'oui', |
|
| 386 | + 'articles_ps' => 'non', |
|
| 387 | + 'articles_redac' => 'non', |
|
| 388 | + 'post_dates' => 'non', |
|
| 389 | + 'articles_urlref' => 'non', |
|
| 390 | + 'articles_redirection' => 'non', |
|
| 391 | + 'creer_preview' => 'non', |
|
| 392 | + 'taille_preview' => 150, |
|
| 393 | + 'articles_modif' => 'non', |
|
| 394 | + |
|
| 395 | + 'rubriques_descriptif' => 'non', |
|
| 396 | + 'rubriques_texte' => 'oui', |
|
| 397 | + |
|
| 398 | + 'accepter_inscriptions' => 'non', |
|
| 399 | + 'accepter_visiteurs' => 'non', |
|
| 400 | + 'prevenir_auteurs' => 'non', |
|
| 401 | + 'suivi_edito' => 'non', |
|
| 402 | + 'adresse_suivi' => '', |
|
| 403 | + 'adresse_suivi_inscription' => '', |
|
| 404 | + 'adresse_neuf' => '', |
|
| 405 | + 'jours_neuf' => '', |
|
| 406 | + 'quoi_de_neuf' => 'non', |
|
| 407 | + 'preview' => ',0minirezo,1comite,', |
|
| 408 | + |
|
| 409 | + 'syndication_integrale' => 'oui', |
|
| 410 | + 'charset' => _DEFAULT_CHARSET, |
|
| 411 | + 'dir_img' => substr(_DIR_IMG, strlen(_DIR_RACINE)), |
|
| 412 | + |
|
| 413 | + 'multi_rubriques' => 'non', |
|
| 414 | + 'multi_secteurs' => 'non', |
|
| 415 | + 'gerer_trad' => 'non', |
|
| 416 | + 'langues_multilingue' => '', |
|
| 417 | + |
|
| 418 | + 'version_html_max' => 'html4', |
|
| 419 | + |
|
| 420 | + 'type_urls' => 'page', |
|
| 421 | + |
|
| 422 | + 'email_envoi' => '', |
|
| 423 | + 'email_webmaster' => '', |
|
| 424 | + 'auto_compress_http' => 'non', |
|
| 425 | + ]); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | /** |
@@ -433,43 +433,43 @@ discard block |
||
| 433 | 433 | * @return void |
| 434 | 434 | */ |
| 435 | 435 | function actualise_metas($liste_meta) { |
| 436 | - $meta_serveur = |
|
| 437 | - [ |
|
| 438 | - 'version_installee', |
|
| 439 | - 'adresse_site', |
|
| 440 | - 'alea_ephemere_ancien', |
|
| 441 | - 'alea_ephemere', |
|
| 442 | - 'alea_ephemere_date', |
|
| 443 | - 'langue_site', |
|
| 444 | - 'langues_proposees', |
|
| 445 | - 'date_calcul_rubriques', |
|
| 446 | - 'derniere_modif', |
|
| 447 | - 'optimiser_table', |
|
| 448 | - 'drapeau_edition', |
|
| 449 | - 'creer_preview', |
|
| 450 | - 'taille_preview', |
|
| 451 | - 'creer_htpasswd', |
|
| 452 | - 'creer_htaccess', |
|
| 453 | - 'gd_formats_read', |
|
| 454 | - 'gd_formats', |
|
| 455 | - 'netpbm_formats', |
|
| 456 | - 'formats_graphiques', |
|
| 457 | - 'image_process', |
|
| 458 | - 'plugin_header', |
|
| 459 | - 'plugin' |
|
| 460 | - ]; |
|
| 461 | - // verifier le impt=non |
|
| 462 | - sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | - |
|
| 464 | - foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | - if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | - ecrire_meta($nom, $valeur); |
|
| 467 | - } |
|
| 468 | - } |
|
| 469 | - |
|
| 470 | - include_spip('inc/rubriques'); |
|
| 471 | - $langues = calculer_langues_utilisees(); |
|
| 472 | - ecrire_meta('langues_utilisees', $langues); |
|
| 436 | + $meta_serveur = |
|
| 437 | + [ |
|
| 438 | + 'version_installee', |
|
| 439 | + 'adresse_site', |
|
| 440 | + 'alea_ephemere_ancien', |
|
| 441 | + 'alea_ephemere', |
|
| 442 | + 'alea_ephemere_date', |
|
| 443 | + 'langue_site', |
|
| 444 | + 'langues_proposees', |
|
| 445 | + 'date_calcul_rubriques', |
|
| 446 | + 'derniere_modif', |
|
| 447 | + 'optimiser_table', |
|
| 448 | + 'drapeau_edition', |
|
| 449 | + 'creer_preview', |
|
| 450 | + 'taille_preview', |
|
| 451 | + 'creer_htpasswd', |
|
| 452 | + 'creer_htaccess', |
|
| 453 | + 'gd_formats_read', |
|
| 454 | + 'gd_formats', |
|
| 455 | + 'netpbm_formats', |
|
| 456 | + 'formats_graphiques', |
|
| 457 | + 'image_process', |
|
| 458 | + 'plugin_header', |
|
| 459 | + 'plugin' |
|
| 460 | + ]; |
|
| 461 | + // verifier le impt=non |
|
| 462 | + sql_updateq('spip_meta', ['impt' => 'non'], sql_in('nom', $meta_serveur)); |
|
| 463 | + |
|
| 464 | + foreach ($liste_meta as $nom => $valeur) { |
|
| 465 | + if (empty($GLOBALS['meta'][$nom])) { |
|
| 466 | + ecrire_meta($nom, $valeur); |
|
| 467 | + } |
|
| 468 | + } |
|
| 469 | + |
|
| 470 | + include_spip('inc/rubriques'); |
|
| 471 | + $langues = calculer_langues_utilisees(); |
|
| 472 | + ecrire_meta('langues_utilisees', $langues); |
|
| 473 | 473 | } |
| 474 | 474 | |
| 475 | 475 | |
@@ -491,18 +491,18 @@ discard block |
||
| 491 | 491 | */ |
| 492 | 492 | function appliquer_modifs_config($purger_skel = false) { |
| 493 | 493 | |
| 494 | - foreach (liste_metas() as $i => $v) { |
|
| 495 | - if (($x = _request($i)) !== null) { |
|
| 496 | - ecrire_meta($i, $x); |
|
| 497 | - } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | - ecrire_meta($i, $v); |
|
| 499 | - } |
|
| 500 | - } |
|
| 501 | - |
|
| 502 | - if ($purger_skel) { |
|
| 503 | - include_spip('inc/invalideur'); |
|
| 504 | - purger_repertoire(_DIR_SKELS); |
|
| 505 | - } |
|
| 494 | + foreach (liste_metas() as $i => $v) { |
|
| 495 | + if (($x = _request($i)) !== null) { |
|
| 496 | + ecrire_meta($i, $x); |
|
| 497 | + } elseif (!isset($GLOBALS['meta'][$i])) { |
|
| 498 | + ecrire_meta($i, $v); |
|
| 499 | + } |
|
| 500 | + } |
|
| 501 | + |
|
| 502 | + if ($purger_skel) { |
|
| 503 | + include_spip('inc/invalideur'); |
|
| 504 | + purger_repertoire(_DIR_SKELS); |
|
| 505 | + } |
|
| 506 | 506 | } |
| 507 | 507 | |
| 508 | 508 | /** |
@@ -513,21 +513,21 @@ discard block |
||
| 513 | 513 | * @return string |
| 514 | 514 | */ |
| 515 | 515 | function appliquer_adresse_site($adresse_site) { |
| 516 | - if ($adresse_site !== null) { |
|
| 517 | - if (!strlen($adresse_site)) { |
|
| 518 | - $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | - $adresse_site = url_de_base(); |
|
| 520 | - } |
|
| 521 | - $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 516 | + if ($adresse_site !== null) { |
|
| 517 | + if (!strlen($adresse_site)) { |
|
| 518 | + $GLOBALS['profondeur_url'] = _DIR_RESTREINT ? 0 : 1; |
|
| 519 | + $adresse_site = url_de_base(); |
|
| 520 | + } |
|
| 521 | + $adresse_site = preg_replace(',/?\s*$,', '', $adresse_site); |
|
| 522 | 522 | |
| 523 | - if (!tester_url_absolue($adresse_site)) { |
|
| 524 | - $adresse_site = "http://$adresse_site"; |
|
| 525 | - } |
|
| 523 | + if (!tester_url_absolue($adresse_site)) { |
|
| 524 | + $adresse_site = "http://$adresse_site"; |
|
| 525 | + } |
|
| 526 | 526 | |
| 527 | - $adresse_site = entites_html($adresse_site); |
|
| 527 | + $adresse_site = entites_html($adresse_site); |
|
| 528 | 528 | |
| 529 | - ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | - } |
|
| 529 | + ecrire_meta('adresse_site', $adresse_site); |
|
| 530 | + } |
|
| 531 | 531 | |
| 532 | - return $adresse_site; |
|
| 532 | + return $adresse_site; |
|
| 533 | 533 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,9 +43,9 @@ discard block |
||
| 43 | 43 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 44 | 44 | */ |
| 45 | 45 | function generer_action_auteur($action, $arg = '', $redirect = '', $mode = false, $att = '', $public = false) { |
| 46 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 46 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 47 | 47 | |
| 48 | - return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 48 | + return $securiser_action($action, $arg, $redirect, $mode, $att, $public); |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | 51 | /** |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | * Code HTML du formulaire |
| 79 | 79 | */ |
| 80 | 80 | function redirige_action_auteur($action, $arg, $ret, $gra = '', $mode = false, $atts = '', $public = false) { |
| 81 | - $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 81 | + $r = ($public ? _DIR_RESTREINT_ABS : _DIR_RESTREINT) . generer_url_ecrire($ret, $gra, true, true); |
|
| 82 | 82 | |
| 83 | - return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 83 | + return generer_action_auteur($action, $arg, $r, $mode, $atts, $public); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -105,9 +105,9 @@ discard block |
||
| 105 | 105 | * URL, code HTML du formulaire ou tableau (action, arg, hash) |
| 106 | 106 | */ |
| 107 | 107 | function redirige_action_post($action, $arg, $ret, $gra, $corps, $att = '') { |
| 108 | - $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 108 | + $r = _DIR_RESTREINT . generer_url_ecrire($ret, $gra, false, true); |
|
| 109 | 109 | |
| 110 | - return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 110 | + return generer_action_auteur($action, $arg, $r, $corps, $att . " method='post'"); |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | |
@@ -124,26 +124,26 @@ discard block |
||
| 124 | 124 | * passer "text/html" comme $content_type |
| 125 | 125 | */ |
| 126 | 126 | function ajax_retour($corps, $content_type = null): void { |
| 127 | - $xml = false; |
|
| 128 | - if (is_null($content_type) or $content_type === true) { |
|
| 129 | - $xml = true; |
|
| 130 | - $content_type = 'text/html'; |
|
| 131 | - } elseif (!$content_type or !is_string($content_type) or !str_contains($content_type, '/')) { |
|
| 132 | - $content_type = 'text/html'; |
|
| 133 | - } |
|
| 127 | + $xml = false; |
|
| 128 | + if (is_null($content_type) or $content_type === true) { |
|
| 129 | + $xml = true; |
|
| 130 | + $content_type = 'text/html'; |
|
| 131 | + } elseif (!$content_type or !is_string($content_type) or !str_contains($content_type, '/')) { |
|
| 132 | + $content_type = 'text/html'; |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - $e = ''; |
|
| 136 | - if ( |
|
| 137 | - isset($_COOKIE['spip_admin']) |
|
| 138 | - and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 139 | - ) { |
|
| 140 | - $e = erreur_squelette(); |
|
| 141 | - } |
|
| 135 | + $e = ''; |
|
| 136 | + if ( |
|
| 137 | + isset($_COOKIE['spip_admin']) |
|
| 138 | + and ((_request('var_mode') == 'debug') or !empty($GLOBALS['tableau_des_temps'])) |
|
| 139 | + ) { |
|
| 140 | + $e = erreur_squelette(); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - $c = $GLOBALS['meta']['charset']; |
|
| 144 | - header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 145 | - $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 146 | - $fin = ''; |
|
| 143 | + $c = $GLOBALS['meta']['charset']; |
|
| 144 | + header('Content-Type: ' . $content_type . '; charset=' . $c); |
|
| 145 | + $debut = (($xml and strlen(trim($corps))) ? '<' . "?xml version='1.0' encoding='" . $c . "'?" . ">\n" : ''); |
|
| 146 | + $fin = ''; |
|
| 147 | 147 | |
| 148 | - echo $debut, $corps, $fin, $e; |
|
| 148 | + echo $debut, $corps, $fin, $e; |
|
| 149 | 149 | } |
@@ -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/boutons'); |
@@ -39,33 +39,33 @@ discard block |
||
| 39 | 39 | * contexte |
| 40 | 40 | **/ |
| 41 | 41 | function definir_barre_contexte($contexte = null) { |
| 42 | - if (is_null($contexte)) { |
|
| 43 | - $contexte = $_GET; |
|
| 44 | - } elseif (is_string($contexte)) { |
|
| 45 | - $contexte = unserialize($contexte); |
|
| 46 | - } |
|
| 47 | - if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | - if (!function_exists('trouver_objet_exec')) { |
|
| 49 | - include_spip('inc/pipelines_ecrire'); |
|
| 50 | - } |
|
| 51 | - if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | - $_id = $e['id_table_objet']; |
|
| 53 | - if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | - $table = $e['table_objet_sql']; |
|
| 55 | - $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | - if (isset($row['id_rubrique'])) { |
|
| 57 | - $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | - if (isset($row['id_secteur'])) { |
|
| 59 | - $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | - } |
|
| 61 | - } elseif (isset($row['id_groupe'])) { |
|
| 62 | - // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | - $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | - } |
|
| 65 | - } |
|
| 66 | - } |
|
| 67 | - } |
|
| 68 | - return $contexte; |
|
| 42 | + if (is_null($contexte)) { |
|
| 43 | + $contexte = $_GET; |
|
| 44 | + } elseif (is_string($contexte)) { |
|
| 45 | + $contexte = unserialize($contexte); |
|
| 46 | + } |
|
| 47 | + if (!isset($contexte['id_rubrique']) and isset($contexte['exec'])) { |
|
| 48 | + if (!function_exists('trouver_objet_exec')) { |
|
| 49 | + include_spip('inc/pipelines_ecrire'); |
|
| 50 | + } |
|
| 51 | + if ($e = trouver_objet_exec($contexte['exec'])) { |
|
| 52 | + $_id = $e['id_table_objet']; |
|
| 53 | + if (isset($contexte[$_id]) and $id = intval($contexte[$_id])) { |
|
| 54 | + $table = $e['table_objet_sql']; |
|
| 55 | + $row = sql_fetsel('*', $table, "$_id=" . intval($id)); |
|
| 56 | + if (isset($row['id_rubrique'])) { |
|
| 57 | + $contexte['id_rubrique'] = $row['id_rubrique']; |
|
| 58 | + if (isset($row['id_secteur'])) { |
|
| 59 | + $contexte['id_secteur'] = $row['id_secteur']; |
|
| 60 | + } |
|
| 61 | + } elseif (isset($row['id_groupe'])) { |
|
| 62 | + // TODO supprimer ce bloc quand https://core.spip.net/issues/3844 sera réalisé |
|
| 63 | + $contexte['id_groupe'] = $row['id_groupe']; |
|
| 64 | + } |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + } |
|
| 68 | + return $contexte; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -81,89 +81,89 @@ discard block |
||
| 81 | 81 | * @return array |
| 82 | 82 | */ |
| 83 | 83 | function definir_barre_boutons($contexte = [], $icones = true, $autorise = true) { |
| 84 | - include_spip('inc/autoriser'); |
|
| 85 | - $boutons_admin = []; |
|
| 84 | + include_spip('inc/autoriser'); |
|
| 85 | + $boutons_admin = []; |
|
| 86 | 86 | |
| 87 | - // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | - $liste_boutons = []; |
|
| 87 | + // les boutons du core, issus de ecrire/paquet.xml |
|
| 88 | + $liste_boutons = []; |
|
| 89 | 89 | |
| 90 | - // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | - if ( |
|
| 92 | - function_exists('boutons_plugins') |
|
| 93 | - and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | - ) { |
|
| 95 | - $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | - } |
|
| 90 | + // ajouter les boutons issus des plugin via paquet.xml |
|
| 91 | + if ( |
|
| 92 | + function_exists('boutons_plugins') |
|
| 93 | + and is_array($liste_boutons_plugins = boutons_plugins()) |
|
| 94 | + ) { |
|
| 95 | + $liste_boutons = &$liste_boutons_plugins; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - foreach ($liste_boutons as $id => $infos) { |
|
| 99 | - $parent = ''; |
|
| 100 | - // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | - if ( |
|
| 102 | - !isset($infos['parent']) |
|
| 103 | - or !($parent = $infos['parent']) |
|
| 104 | - or !$autorise |
|
| 105 | - or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | - ) { |
|
| 107 | - if ( |
|
| 108 | - $parent |
|
| 109 | - and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | - and isset($boutons_admin[$parent]) |
|
| 111 | - ) { |
|
| 112 | - $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | - if ($position < 0) { |
|
| 114 | - $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | - } |
|
| 116 | - $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | - + [ |
|
| 118 | - $id => new Bouton( |
|
| 119 | - ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | - $infos['titre'], // titre |
|
| 121 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | - ) |
|
| 124 | - ] |
|
| 125 | - + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | - } |
|
| 127 | - if ( |
|
| 128 | - !$parent |
|
| 129 | - // provisoire, eviter les vieux boutons |
|
| 130 | - and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | - and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | - ) { |
|
| 133 | - $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | - $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | - + [ |
|
| 136 | - $id => new Bouton( |
|
| 137 | - ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | - $infos['titre'], // titre |
|
| 139 | - (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | - ) |
|
| 142 | - ] |
|
| 143 | - + array_slice($boutons_admin, $position, 100); |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - } |
|
| 147 | - $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 98 | + foreach ($liste_boutons as $id => $infos) { |
|
| 99 | + $parent = ''; |
|
| 100 | + // les boutons principaux ne sont pas soumis a autorisation |
|
| 101 | + if ( |
|
| 102 | + !isset($infos['parent']) |
|
| 103 | + or !($parent = $infos['parent']) |
|
| 104 | + or !$autorise |
|
| 105 | + or autoriser('menu', "_$id", 0, null, ['contexte' => $contexte]) |
|
| 106 | + ) { |
|
| 107 | + if ( |
|
| 108 | + $parent |
|
| 109 | + and $parent = preg_replace(',^bando_,', 'menu_', $parent) |
|
| 110 | + and isset($boutons_admin[$parent]) |
|
| 111 | + ) { |
|
| 112 | + $position = (isset($infos['position']) and strlen($infos['position'])) ? intval($infos['position']) : count($boutons_admin[$parent]->sousmenu); |
|
| 113 | + if ($position < 0) { |
|
| 114 | + $position = count($boutons_admin[$parent]->sousmenu) + 1 + $position; |
|
| 115 | + } |
|
| 116 | + $boutons_admin[$parent]->sousmenu = array_slice($boutons_admin[$parent]->sousmenu, 0, $position) |
|
| 117 | + + [ |
|
| 118 | + $id => new Bouton( |
|
| 119 | + ($icones and !empty($infos['icone'])) ? find_in_theme($infos['icone']) : '', // icone |
|
| 120 | + $infos['titre'], // titre |
|
| 121 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 122 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 123 | + ) |
|
| 124 | + ] |
|
| 125 | + + array_slice($boutons_admin[$parent]->sousmenu, $position, 100); |
|
| 126 | + } |
|
| 127 | + if ( |
|
| 128 | + !$parent |
|
| 129 | + // provisoire, eviter les vieux boutons |
|
| 130 | + and (!in_array($id, ['forum', 'statistiques_visites'])) |
|
| 131 | + and (!$autorise or autoriser('menugrandeentree', "_$id", 0, null, ['contexte' => $contexte])) |
|
| 132 | + ) { |
|
| 133 | + $position = (isset($infos['position']) and $infos['position']) ? $infos['position'] : count($boutons_admin); |
|
| 134 | + $boutons_admin = array_slice($boutons_admin, 0, $position) |
|
| 135 | + + [ |
|
| 136 | + $id => new Bouton( |
|
| 137 | + ($icones and isset($infos['icone']) and $infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 138 | + $infos['titre'], // titre |
|
| 139 | + (isset($infos['action']) and $infos['action']) ? $infos['action'] : null, |
|
| 140 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : null |
|
| 141 | + ) |
|
| 142 | + ] |
|
| 143 | + + array_slice($boutons_admin, $position, 100); |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + } |
|
| 147 | + $boutons_admin = pipeline('ajouter_menus', $boutons_admin); |
|
| 148 | 148 | |
| 149 | - // définir les favoris et positions d’origine |
|
| 150 | - if ($boutons_admin) { |
|
| 151 | - $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | - $i = 1; |
|
| 153 | - foreach ($boutons_admin as $key => $menu) { |
|
| 154 | - $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | - $menu->position = $i++; |
|
| 156 | - if ($menu->sousmenu) { |
|
| 157 | - $j = 1; |
|
| 158 | - foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | - $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | - $bouton->position = $j++; |
|
| 161 | - } |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - } |
|
| 149 | + // définir les favoris et positions d’origine |
|
| 150 | + if ($boutons_admin) { |
|
| 151 | + $menus_favoris = obtenir_menus_favoris(); |
|
| 152 | + $i = 1; |
|
| 153 | + foreach ($boutons_admin as $key => $menu) { |
|
| 154 | + $menu->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 155 | + $menu->position = $i++; |
|
| 156 | + if ($menu->sousmenu) { |
|
| 157 | + $j = 1; |
|
| 158 | + foreach ($menu->sousmenu as $key => $bouton) { |
|
| 159 | + $bouton->favori = (int) table_valeur($menus_favoris, $key, false); |
|
| 160 | + $bouton->position = $j++; |
|
| 161 | + } |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + } |
|
| 165 | 165 | |
| 166 | - return $boutons_admin; |
|
| 166 | + return $boutons_admin; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -175,22 +175,22 @@ discard block |
||
| 175 | 175 | * @return Bouton[] |
| 176 | 176 | */ |
| 177 | 177 | function trier_boutons_enfants_par_alpha($menus, $avec_favoris = false) { |
| 178 | - foreach ($menus as $menu) { |
|
| 179 | - if ($menu->sousmenu) { |
|
| 180 | - $libelles = $isfavoris = $favoris = []; |
|
| 181 | - foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | - $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | - $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | - $favoris[$key] = $item->favori; |
|
| 185 | - } |
|
| 186 | - if ($avec_favoris) { |
|
| 187 | - array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | - } else { |
|
| 189 | - array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | - } |
|
| 191 | - } |
|
| 192 | - } |
|
| 193 | - return $menus; |
|
| 178 | + foreach ($menus as $menu) { |
|
| 179 | + if ($menu->sousmenu) { |
|
| 180 | + $libelles = $isfavoris = $favoris = []; |
|
| 181 | + foreach ($menu->sousmenu as $key => $item) { |
|
| 182 | + $libelles[$key] = strtolower(translitteration(_T($item->libelle))); |
|
| 183 | + $isfavoris[$key] = (bool) $item->favori; |
|
| 184 | + $favoris[$key] = $item->favori; |
|
| 185 | + } |
|
| 186 | + if ($avec_favoris) { |
|
| 187 | + array_multisort($isfavoris, SORT_DESC, $favoris, SORT_ASC, $libelles, SORT_ASC, $menu->sousmenu); |
|
| 188 | + } else { |
|
| 189 | + array_multisort($libelles, SORT_ASC, $menu->sousmenu); |
|
| 190 | + } |
|
| 191 | + } |
|
| 192 | + } |
|
| 193 | + return $menus; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | /** |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | * @return Bouton[] |
| 202 | 202 | */ |
| 203 | 203 | function trier_boutons_enfants_par_favoris_alpha($menus) { |
| 204 | - return trier_boutons_enfants_par_alpha($menus, true); |
|
| 204 | + return trier_boutons_enfants_par_alpha($menus, true); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -214,23 +214,23 @@ discard block |
||
| 214 | 214 | * @return string |
| 215 | 215 | */ |
| 216 | 216 | function bandeau_creer_url($url, $args = '', $contexte = null) { |
| 217 | - if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | - $url = generer_url_ecrire($url, $args, true); |
|
| 219 | - // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | - // &truc=@machin@ |
|
| 221 | - // @machin@ etant remplace par _request('machin') |
|
| 222 | - $url = str_replace('&', '&', $url); |
|
| 223 | - while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | - if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | - $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | - } |
|
| 227 | - $val = _request($matches[2], $contexte); |
|
| 228 | - $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | - } |
|
| 230 | - $url = str_replace('&', '&', $url); |
|
| 231 | - } |
|
| 217 | + if (!preg_match(',[\/\?],', $url)) { |
|
| 218 | + $url = generer_url_ecrire($url, $args, true); |
|
| 219 | + // recuperer les parametres du contexte demande par l'url sous la forme |
|
| 220 | + // &truc=@machin@ |
|
| 221 | + // @machin@ etant remplace par _request('machin') |
|
| 222 | + $url = str_replace('&', '&', $url); |
|
| 223 | + while (preg_match(',[&?]([a-z_]+)=@([a-z_]+)@,i', $url, $matches)) { |
|
| 224 | + if ($matches[2] == 'id_secteur' and !isset($contexte['id_secteur']) and isset($contexte['id_rubrique'])) { |
|
| 225 | + $contexte['id_secteur'] = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($contexte['id_rubrique'])); |
|
| 226 | + } |
|
| 227 | + $val = _request($matches[2], $contexte); |
|
| 228 | + $url = parametre_url($url, $matches[1], $val ?: '', '&'); |
|
| 229 | + } |
|
| 230 | + $url = str_replace('&', '&', $url); |
|
| 231 | + } |
|
| 232 | 232 | |
| 233 | - return $url; |
|
| 233 | + return $url; |
|
| 234 | 234 | } |
| 235 | 235 | |
| 236 | 236 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | * Code HTML du bandeau |
| 241 | 241 | */ |
| 242 | 242 | function inc_bandeau_dist() { |
| 243 | - return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 243 | + return recuperer_fond('prive/squelettes/inclure/barre-nav', $_GET); |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | |
@@ -249,13 +249,13 @@ discard block |
||
| 249 | 249 | * @return array |
| 250 | 250 | */ |
| 251 | 251 | function obtenir_menus_favoris() { |
| 252 | - if ( |
|
| 253 | - isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | - and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | - and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | - ) { |
|
| 257 | - return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | - } |
|
| 259 | - $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | - return $definir_menus_favoris(); |
|
| 252 | + if ( |
|
| 253 | + isset($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 254 | + and is_array($GLOBALS['visiteur_session']['prefs']['menus_favoris']) |
|
| 255 | + and $GLOBALS['visiteur_session']['prefs']['menus_favoris'] |
|
| 256 | + ) { |
|
| 257 | + return $GLOBALS['visiteur_session']['prefs']['menus_favoris']; |
|
| 258 | + } |
|
| 259 | + $definir_menus_favoris = charger_fonction('definir_menus_favoris', 'inc'); |
|
| 260 | + return $definir_menus_favoris(); |
|
| 261 | 261 | } |
@@ -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 | /** |
@@ -40,20 +40,20 @@ discard block |
||
| 40 | 40 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 41 | 41 | */ |
| 42 | 42 | function find_langs_in_path($file, $dirname = 'lang') { |
| 43 | - static $dirs = []; |
|
| 44 | - $liste = []; |
|
| 45 | - foreach (creer_chemin() as $dir) { |
|
| 46 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | - } |
|
| 49 | - if ($dirs[$a]) { |
|
| 50 | - if (is_readable($a .= $file)) { |
|
| 51 | - $liste[] = $a; |
|
| 52 | - } |
|
| 53 | - } |
|
| 54 | - } |
|
| 43 | + static $dirs = []; |
|
| 44 | + $liste = []; |
|
| 45 | + foreach (creer_chemin() as $dir) { |
|
| 46 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 47 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 48 | + } |
|
| 49 | + if ($dirs[$a]) { |
|
| 50 | + if (is_readable($a .= $file)) { |
|
| 51 | + $liste[] = $a; |
|
| 52 | + } |
|
| 53 | + } |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | - return array_reverse($liste); |
|
| 56 | + return array_reverse($liste); |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -68,23 +68,23 @@ discard block |
||
| 68 | 68 | * Liste des fichiers touvés pour ce module et cette langue. |
| 69 | 69 | **/ |
| 70 | 70 | function chercher_module_lang($module, $lang = '') { |
| 71 | - if ($lang) { |
|
| 72 | - $lang = '_' . $lang; |
|
| 73 | - } |
|
| 71 | + if ($lang) { |
|
| 72 | + $lang = '_' . $lang; |
|
| 73 | + } |
|
| 74 | 74 | |
| 75 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | - if ( |
|
| 77 | - $f = ($module == 'local' |
|
| 78 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | - ) { |
|
| 81 | - return is_array($f) ? $f : [$f]; |
|
| 82 | - } |
|
| 75 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 76 | + if ( |
|
| 77 | + $f = ($module == 'local' |
|
| 78 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 79 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 80 | + ) { |
|
| 81 | + return is_array($f) ? $f : [$f]; |
|
| 82 | + } |
|
| 83 | 83 | |
| 84 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | - return (($module == 'local') or strpos($module, '/')) |
|
| 86 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | - : false; |
|
| 84 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 85 | + return (($module == 'local') or strpos($module, '/')) |
|
| 86 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 87 | + : false; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -106,33 +106,33 @@ discard block |
||
| 106 | 106 | * @return void |
| 107 | 107 | **/ |
| 108 | 108 | function charger_langue($lang, $module = 'spip') { |
| 109 | - static $langs = []; |
|
| 110 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | - if (!isset($langs[$lang])) { |
|
| 112 | - $langs[$lang] = []; |
|
| 113 | - if ($lang) { |
|
| 114 | - $langs[$lang][] = $lang; |
|
| 115 | - if (strpos($lang, '_') !== false) { |
|
| 116 | - $l = explode('_', $lang); |
|
| 117 | - $langs[$lang][] = reset($l); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | - } |
|
| 123 | - foreach ($langs[$lang] as $l) { |
|
| 124 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | - surcharger_langue($fichiers_lang); |
|
| 128 | - if ($l !== $lang) { |
|
| 129 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | - } |
|
| 131 | - $GLOBALS['lang_' . $var] = $l; |
|
| 132 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | - break; |
|
| 134 | - } |
|
| 135 | - } |
|
| 109 | + static $langs = []; |
|
| 110 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 111 | + if (!isset($langs[$lang])) { |
|
| 112 | + $langs[$lang] = []; |
|
| 113 | + if ($lang) { |
|
| 114 | + $langs[$lang][] = $lang; |
|
| 115 | + if (strpos($lang, '_') !== false) { |
|
| 116 | + $l = explode('_', $lang); |
|
| 117 | + $langs[$lang][] = reset($l); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 121 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 122 | + } |
|
| 123 | + foreach ($langs[$lang] as $l) { |
|
| 124 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 125 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 126 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 127 | + surcharger_langue($fichiers_lang); |
|
| 128 | + if ($l !== $lang) { |
|
| 129 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 130 | + } |
|
| 131 | + $GLOBALS['lang_' . $var] = $l; |
|
| 132 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 133 | + break; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -145,21 +145,21 @@ discard block |
||
| 145 | 145 | * @return array<string, string> |
| 146 | 146 | */ |
| 147 | 147 | function lire_fichier_langue(string $fichier): array { |
| 148 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | - $idx_lang = include $fichier; |
|
| 152 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | - if (!is_array($idx_lang)) { |
|
| 154 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | - } else { |
|
| 157 | - $idx_lang = []; |
|
| 158 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | - } |
|
| 160 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | - } |
|
| 162 | - return $idx_lang; |
|
| 148 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 149 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 151 | + $idx_lang = include $fichier; |
|
| 152 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 153 | + if (!is_array($idx_lang)) { |
|
| 154 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 155 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 156 | + } else { |
|
| 157 | + $idx_lang = []; |
|
| 158 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 159 | + } |
|
| 160 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 161 | + } |
|
| 162 | + return $idx_lang; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | /** |
@@ -179,29 +179,29 @@ discard block |
||
| 179 | 179 | * Liste des chemins de fichiers de langue à surcharger. |
| 180 | 180 | **/ |
| 181 | 181 | function surcharger_langue($fichiers) { |
| 182 | - static $surcharges = []; |
|
| 183 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | - return; |
|
| 185 | - } |
|
| 182 | + static $surcharges = []; |
|
| 183 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 184 | + return; |
|
| 185 | + } |
|
| 186 | 186 | |
| 187 | - if (!is_array($fichiers)) { |
|
| 188 | - $fichiers = [$fichiers]; |
|
| 189 | - } |
|
| 190 | - if (!count($fichiers)) { |
|
| 191 | - return; |
|
| 192 | - } |
|
| 193 | - foreach ($fichiers as $fichier) { |
|
| 194 | - if (!isset($surcharges[$fichier])) { |
|
| 195 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | - } |
|
| 197 | - if (is_array($surcharges[$fichier])) { |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | - $surcharges[$fichier] |
|
| 202 | - ); |
|
| 203 | - } |
|
| 204 | - } |
|
| 187 | + if (!is_array($fichiers)) { |
|
| 188 | + $fichiers = [$fichiers]; |
|
| 189 | + } |
|
| 190 | + if (!count($fichiers)) { |
|
| 191 | + return; |
|
| 192 | + } |
|
| 193 | + foreach ($fichiers as $fichier) { |
|
| 194 | + if (!isset($surcharges[$fichier])) { |
|
| 195 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 196 | + } |
|
| 197 | + if (is_array($surcharges[$fichier])) { |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 199 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 200 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 201 | + $surcharges[$fichier] |
|
| 202 | + ); |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -242,99 +242,99 @@ discard block |
||
| 242 | 242 | * - Description : traduction et description (texte, module, langue) |
| 243 | 243 | **/ |
| 244 | 244 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 245 | - static $deja_vu = []; |
|
| 246 | - static $local = []; |
|
| 245 | + static $deja_vu = []; |
|
| 246 | + static $local = []; |
|
| 247 | 247 | |
| 248 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | - } |
|
| 248 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 249 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 250 | + } |
|
| 251 | 251 | |
| 252 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | - if (strpos($ori, ':')) { |
|
| 254 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | - $modules = explode('|', $modules); |
|
| 256 | - $ori_complet = $ori; |
|
| 257 | - } else { |
|
| 258 | - $modules = ['spip', 'ecrire']; |
|
| 259 | - $code = $ori; |
|
| 260 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | - } |
|
| 252 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 253 | + if (strpos($ori, ':')) { |
|
| 254 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 255 | + $modules = explode('|', $modules); |
|
| 256 | + $ori_complet = $ori; |
|
| 257 | + } else { |
|
| 258 | + $modules = ['spip', 'ecrire']; |
|
| 259 | + $code = $ori; |
|
| 260 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - $desc = new Description(); |
|
| 263 | + $desc = new Description(); |
|
| 264 | 264 | |
| 265 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | - foreach ($modules as $module) { |
|
| 267 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 265 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 266 | + foreach ($modules as $module) { |
|
| 267 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 268 | 268 | |
| 269 | - if (empty($GLOBALS[$var])) { |
|
| 270 | - charger_langue($lang, $module); |
|
| 271 | - // surcharges persos -- on cherche |
|
| 272 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | - if (!isset($local['local_' . $lang])) { |
|
| 274 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | - $GLOBALS['idx_lang'] = $var; |
|
| 276 | - // ... (lang/)local_xx.php |
|
| 277 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | - } |
|
| 279 | - if ($local['local_' . $lang]) { |
|
| 280 | - surcharger_langue($local['local_' . $lang]); |
|
| 281 | - } |
|
| 282 | - // ... puis (lang/)local.php |
|
| 283 | - if (!isset($local['local'])) { |
|
| 284 | - $local['local'] = chercher_module_lang('local'); |
|
| 285 | - } |
|
| 286 | - if ($local['local']) { |
|
| 287 | - surcharger_langue($local['local']); |
|
| 288 | - } |
|
| 289 | - } |
|
| 269 | + if (empty($GLOBALS[$var])) { |
|
| 270 | + charger_langue($lang, $module); |
|
| 271 | + // surcharges persos -- on cherche |
|
| 272 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 273 | + if (!isset($local['local_' . $lang])) { |
|
| 274 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 275 | + $GLOBALS['idx_lang'] = $var; |
|
| 276 | + // ... (lang/)local_xx.php |
|
| 277 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 278 | + } |
|
| 279 | + if ($local['local_' . $lang]) { |
|
| 280 | + surcharger_langue($local['local_' . $lang]); |
|
| 281 | + } |
|
| 282 | + // ... puis (lang/)local.php |
|
| 283 | + if (!isset($local['local'])) { |
|
| 284 | + $local['local'] = chercher_module_lang('local'); |
|
| 285 | + } |
|
| 286 | + if ($local['local']) { |
|
| 287 | + surcharger_langue($local['local']); |
|
| 288 | + } |
|
| 289 | + } |
|
| 290 | 290 | |
| 291 | - if (isset($GLOBALS[$var][$code])) { |
|
| 292 | - $desc->code = $code; |
|
| 293 | - $desc->module = $module; |
|
| 294 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | - break; |
|
| 297 | - } |
|
| 298 | - } |
|
| 291 | + if (isset($GLOBALS[$var][$code])) { |
|
| 292 | + $desc->code = $code; |
|
| 293 | + $desc->module = $module; |
|
| 294 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 295 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 296 | + break; |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | 299 | |
| 300 | - if (!$desc->corrections) { |
|
| 301 | - $desc->corrections = true; |
|
| 302 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | - if ( |
|
| 305 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | - ) { |
|
| 308 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | - } else { |
|
| 311 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | - } |
|
| 313 | - } |
|
| 300 | + if (!$desc->corrections) { |
|
| 301 | + $desc->corrections = true; |
|
| 302 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 303 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 304 | + if ( |
|
| 305 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 306 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 307 | + ) { |
|
| 308 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 309 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 310 | + } else { |
|
| 311 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 312 | + } |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | - } |
|
| 315 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 316 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 317 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 318 | + } |
|
| 319 | 319 | |
| 320 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | - if ( |
|
| 323 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | - ) { |
|
| 326 | - include_spip('inc/charsets'); |
|
| 327 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | - } |
|
| 329 | - } |
|
| 320 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 321 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 322 | + if ( |
|
| 323 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 324 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 325 | + ) { |
|
| 326 | + include_spip('inc/charsets'); |
|
| 327 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - if (_request('var_mode') == 'traduction') { |
|
| 332 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | - } else { |
|
| 334 | - $deja_vu[$lang][$ori] = $desc; |
|
| 335 | - } |
|
| 331 | + if (_request('var_mode') == 'traduction') { |
|
| 332 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 333 | + } else { |
|
| 334 | + $deja_vu[$lang][$ori] = $desc; |
|
| 335 | + } |
|
| 336 | 336 | |
| 337 | - return $raw ? $desc : $desc->texte; |
|
| 337 | + return $raw ? $desc : $desc->texte; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | /** |
@@ -346,23 +346,23 @@ discard block |
||
| 346 | 346 | * @return Description |
| 347 | 347 | */ |
| 348 | 348 | function definir_details_traduction($desc, $modules) { |
| 349 | - if (!$desc->mode and $desc->texte) { |
|
| 350 | - // ne pas modifier 2 fois l'affichage |
|
| 351 | - $desc->mode = 'traduction'; |
|
| 352 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | - $desc->texte = '<span ' |
|
| 354 | - . 'lang=' . $desc->langue |
|
| 355 | - . ' class=' . $classe |
|
| 356 | - . ' data-module=' . $desc->module |
|
| 357 | - . ' data-code=' . $desc->code |
|
| 358 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | - . $desc->texte |
|
| 360 | - . '</span>'; |
|
| 361 | - $desc->texte = str_replace( |
|
| 362 | - ["$desc->module:", "$desc->module|"], |
|
| 363 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | - $desc->texte |
|
| 365 | - ); |
|
| 366 | - } |
|
| 367 | - return $desc; |
|
| 349 | + if (!$desc->mode and $desc->texte) { |
|
| 350 | + // ne pas modifier 2 fois l'affichage |
|
| 351 | + $desc->mode = 'traduction'; |
|
| 352 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 353 | + $desc->texte = '<span ' |
|
| 354 | + . 'lang=' . $desc->langue |
|
| 355 | + . ' class=' . $classe |
|
| 356 | + . ' data-module=' . $desc->module |
|
| 357 | + . ' data-code=' . $desc->code |
|
| 358 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 359 | + . $desc->texte |
|
| 360 | + . '</span>'; |
|
| 361 | + $desc->texte = str_replace( |
|
| 362 | + ["$desc->module:", "$desc->module|"], |
|
| 363 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 364 | + $desc->texte |
|
| 365 | + ); |
|
| 366 | + } |
|
| 367 | + return $desc; |
|
| 368 | 368 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | defined('_RECHERCHE_LOCK_KEY') || define('_RECHERCHE_LOCK_KEY', 'fulltext'); |
@@ -35,198 +35,198 @@ discard block |
||
| 35 | 35 | * @return array Couples (type d'objet => Couples (champ => score)) |
| 36 | 36 | */ |
| 37 | 37 | function liste_des_champs() { |
| 38 | - static $liste = null; |
|
| 39 | - if (is_null($liste)) { |
|
| 40 | - $liste = []; |
|
| 41 | - // recuperer les tables_objets_sql declarees |
|
| 42 | - include_spip('base/objets'); |
|
| 43 | - $tables_objets = lister_tables_objets_sql(); |
|
| 44 | - foreach ($tables_objets as $t => $infos) { |
|
| 45 | - if ($infos['rechercher_champs']) { |
|
| 46 | - $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - // puis passer dans le pipeline |
|
| 50 | - $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - return $liste; |
|
| 38 | + static $liste = null; |
|
| 39 | + if (is_null($liste)) { |
|
| 40 | + $liste = []; |
|
| 41 | + // recuperer les tables_objets_sql declarees |
|
| 42 | + include_spip('base/objets'); |
|
| 43 | + $tables_objets = lister_tables_objets_sql(); |
|
| 44 | + foreach ($tables_objets as $t => $infos) { |
|
| 45 | + if ($infos['rechercher_champs']) { |
|
| 46 | + $liste[$infos['type']] = $infos['rechercher_champs']; |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + // puis passer dans le pipeline |
|
| 50 | + $liste = pipeline('rechercher_liste_des_champs', $liste); |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + return $liste; |
|
| 54 | 54 | } |
| 55 | 55 | |
| 56 | 56 | |
| 57 | 57 | // Recherche des auteurs et mots-cles associes |
| 58 | 58 | // en ne regardant que le titre ou le nom |
| 59 | 59 | function liste_des_jointures() { |
| 60 | - static $liste = null; |
|
| 61 | - if (is_null($liste)) { |
|
| 62 | - $liste = []; |
|
| 63 | - // recuperer les tables_objets_sql declarees |
|
| 64 | - include_spip('base/objets'); |
|
| 65 | - $tables_objets = lister_tables_objets_sql(); |
|
| 66 | - foreach ($tables_objets as $t => $infos) { |
|
| 67 | - if ($infos['rechercher_jointures']) { |
|
| 68 | - $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - // puis passer dans le pipeline |
|
| 72 | - $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - return $liste; |
|
| 60 | + static $liste = null; |
|
| 61 | + if (is_null($liste)) { |
|
| 62 | + $liste = []; |
|
| 63 | + // recuperer les tables_objets_sql declarees |
|
| 64 | + include_spip('base/objets'); |
|
| 65 | + $tables_objets = lister_tables_objets_sql(); |
|
| 66 | + foreach ($tables_objets as $t => $infos) { |
|
| 67 | + if ($infos['rechercher_jointures']) { |
|
| 68 | + $liste[$infos['type']] = $infos['rechercher_jointures']; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + // puis passer dans le pipeline |
|
| 72 | + $liste = pipeline('rechercher_liste_des_jointures', $liste); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + return $liste; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | function expression_recherche($recherche, $options) { |
| 79 | - // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | - // (meme si utilisee dans plusieurs boucles) |
|
| 81 | - static $expression = []; |
|
| 82 | - $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | - if (isset($expression[$key])) { |
|
| 84 | - return $expression[$key]; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | - if ($u and !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | - $options['preg_flags'] .= $u; |
|
| 90 | - } |
|
| 91 | - include_spip('inc/charsets'); |
|
| 92 | - $recherche = trim($recherche); |
|
| 93 | - |
|
| 94 | - // retirer les + de +truc et les * de truc* |
|
| 95 | - $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | - $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | - |
|
| 98 | - $is_preg = false; |
|
| 99 | - if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | - // c'est une preg |
|
| 101 | - $recherche_trans = translitteration($recherche); |
|
| 102 | - $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | - $is_preg = true; |
|
| 104 | - } else { |
|
| 105 | - // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | - // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | - // 'une', 'des' ...) |
|
| 108 | - |
|
| 109 | - // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | - $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | - |
|
| 112 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | - // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | - foreach ($matches as $match) { |
|
| 116 | - $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | - $word = trim($word, '"'); |
|
| 118 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - |
|
| 122 | - if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | - $is_preg = true; |
|
| 124 | - |
|
| 125 | - $recherche_inter = '|'; |
|
| 126 | - $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | - $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | - $petits_mots = true; |
|
| 129 | - foreach ($recherche_mots as $mot) { |
|
| 130 | - if (strlen($mot) >= $min_long) { |
|
| 131 | - // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | - $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | - $petits_mots = false; |
|
| 134 | - } |
|
| 135 | - } |
|
| 136 | - $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | - |
|
| 138 | - // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | - // comporte des mots de moins de quatre lettres |
|
| 140 | - $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | - if (!$recherche or $petits_mots) { |
|
| 142 | - $recherche = preg_quote($recherche_org); |
|
| 143 | - } |
|
| 144 | - $recherche_trans = translitteration($recherche); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | - // ou si l'expression reguliere est invalide |
|
| 152 | - if ( |
|
| 153 | - !$is_preg |
|
| 154 | - or (@preg_match($preg, '') === false) |
|
| 155 | - ) { |
|
| 156 | - $methode = 'LIKE'; |
|
| 157 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | - |
|
| 159 | - // echapper les % et _ |
|
| 160 | - $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | - |
|
| 162 | - // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | - $recherche = preg_quote($recherche, '/'); |
|
| 164 | - $recherche_trans = translitteration($recherche); |
|
| 165 | - $recherche_mod = $recherche_trans; |
|
| 166 | - |
|
| 167 | - // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | - // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | - // corriger le like dans le $q |
|
| 170 | - if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | - foreach ($matches as $match) { |
|
| 172 | - $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | - $word = trim($word, '"'); |
|
| 174 | - $q = str_replace($match, $word, $q); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - // corriger la regexp |
|
| 178 | - if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | - foreach ($matches as $match) { |
|
| 180 | - $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | - $word = trim($word, '"'); |
|
| 182 | - $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | - } |
|
| 184 | - } |
|
| 185 | - $q = sql_quote( |
|
| 186 | - '%' |
|
| 187 | - . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | - . '%' |
|
| 189 | - ); |
|
| 190 | - |
|
| 191 | - $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | - } else { |
|
| 193 | - $methode = 'REGEXP'; |
|
| 194 | - $q = sql_quote(trim($recherche, '/')); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | - // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | - $q_t = $q; |
|
| 200 | - for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | - $char = spip_substr($q, $i, 1); |
|
| 202 | - if ( |
|
| 203 | - !is_ascii($char) |
|
| 204 | - and $char_t = translitteration($char) |
|
| 205 | - and $char_t !== $char |
|
| 206 | - ) { |
|
| 207 | - // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | - // mais c'est un pis aller cf #4354 |
|
| 209 | - $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | - } |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - $q = $q_t; |
|
| 214 | - |
|
| 215 | - // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | - // les plus frequents qui peuvent etre accentues |
|
| 217 | - // (oui c'est tres dicustable...) |
|
| 218 | - if ( |
|
| 219 | - isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | - and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | - ) { |
|
| 222 | - $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | - // si il reste au moins un char significatif... |
|
| 224 | - if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | - $q = $q_t; |
|
| 226 | - } |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - return $expression[$key] = [$methode, $q, $preg]; |
|
| 79 | + // ne calculer qu'une seule fois l'expression par hit |
|
| 80 | + // (meme si utilisee dans plusieurs boucles) |
|
| 81 | + static $expression = []; |
|
| 82 | + $key = serialize([$recherche, $options['preg_flags']]); |
|
| 83 | + if (isset($expression[$key])) { |
|
| 84 | + return $expression[$key]; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 88 | + if ($u and !str_contains($options['preg_flags'], (string) $u)) { |
|
| 89 | + $options['preg_flags'] .= $u; |
|
| 90 | + } |
|
| 91 | + include_spip('inc/charsets'); |
|
| 92 | + $recherche = trim($recherche); |
|
| 93 | + |
|
| 94 | + // retirer les + de +truc et les * de truc* |
|
| 95 | + $recherche = preg_replace(',(^|\s)\+(\w),Uims', '$1$2', $recherche); |
|
| 96 | + $recherche = preg_replace(',(\w)\*($|\s),Uims', '$1$2', $recherche); |
|
| 97 | + |
|
| 98 | + $is_preg = false; |
|
| 99 | + if (substr($recherche, 0, 1) == '/' and substr($recherche, -1, 1) == '/' and strlen($recherche) > 2) { |
|
| 100 | + // c'est une preg |
|
| 101 | + $recherche_trans = translitteration($recherche); |
|
| 102 | + $preg = $recherche_trans . $options['preg_flags']; |
|
| 103 | + $is_preg = true; |
|
| 104 | + } else { |
|
| 105 | + // s'il y a plusieurs mots il faut les chercher tous : oblige REGEXP, |
|
| 106 | + // sauf ceux de moins de 4 lettres (on supprime ainsi 'le', 'les', 'un', |
|
| 107 | + // 'une', 'des' ...) |
|
| 108 | + |
|
| 109 | + // attention : plusieurs mots entre guillemets sont a rechercher tels quels |
|
| 110 | + $recherche_trans = $recherche_mod = $recherche_org = $recherche; |
|
| 111 | + |
|
| 112 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 113 | + // -> on remplace les espaces par un \x1 et on enleve les guillemets |
|
| 114 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 115 | + foreach ($matches as $match) { |
|
| 116 | + $word = preg_replace(',\s+,Uims', "\x1", $match); |
|
| 117 | + $word = trim($word, '"'); |
|
| 118 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + |
|
| 122 | + if (preg_match(',\s+,' . $u, $recherche_mod)) { |
|
| 123 | + $is_preg = true; |
|
| 124 | + |
|
| 125 | + $recherche_inter = '|'; |
|
| 126 | + $recherche_mots = explode(' ', $recherche_mod); |
|
| 127 | + $min_long = defined('_RECHERCHE_MIN_CAR') ? _RECHERCHE_MIN_CAR : 4; |
|
| 128 | + $petits_mots = true; |
|
| 129 | + foreach ($recherche_mots as $mot) { |
|
| 130 | + if (strlen($mot) >= $min_long) { |
|
| 131 | + // echapper les caracteres de regexp qui sont eventuellement dans la recherche |
|
| 132 | + $recherche_inter .= preg_quote($mot) . ' '; |
|
| 133 | + $petits_mots = false; |
|
| 134 | + } |
|
| 135 | + } |
|
| 136 | + $recherche_inter = str_replace("\x1", '\s', $recherche_inter); |
|
| 137 | + |
|
| 138 | + // mais on cherche quand même l'expression complète, même si elle |
|
| 139 | + // comporte des mots de moins de quatre lettres |
|
| 140 | + $recherche = trim(preg_replace(',\s+,' . $u, '|', $recherche_inter), '|'); |
|
| 141 | + if (!$recherche or $petits_mots) { |
|
| 142 | + $recherche = preg_quote($recherche_org); |
|
| 143 | + } |
|
| 144 | + $recherche_trans = translitteration($recherche); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $preg = '/' . str_replace('/', '\\/', $recherche_trans) . '/' . $options['preg_flags']; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Si la chaine est inactive, on va utiliser LIKE pour aller plus vite |
|
| 151 | + // ou si l'expression reguliere est invalide |
|
| 152 | + if ( |
|
| 153 | + !$is_preg |
|
| 154 | + or (@preg_match($preg, '') === false) |
|
| 155 | + ) { |
|
| 156 | + $methode = 'LIKE'; |
|
| 157 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 158 | + |
|
| 159 | + // echapper les % et _ |
|
| 160 | + $q = str_replace(['%', '_'], ['\%', '\_'], trim($recherche)); |
|
| 161 | + |
|
| 162 | + // eviter les parentheses et autres caractères qui interferent avec pcre par la suite (dans le preg_match_all) s'il y a des reponses |
|
| 163 | + $recherche = preg_quote($recherche, '/'); |
|
| 164 | + $recherche_trans = translitteration($recherche); |
|
| 165 | + $recherche_mod = $recherche_trans; |
|
| 166 | + |
|
| 167 | + // les expressions entre " " sont un mot a chercher tel quel |
|
| 168 | + // -> on remplace les espaces par un _ et on enleve les guillemets |
|
| 169 | + // corriger le like dans le $q |
|
| 170 | + if (preg_match(',["][^"]+["],Uims', $q, $matches)) { |
|
| 171 | + foreach ($matches as $match) { |
|
| 172 | + $word = preg_replace(',\s+,Uims', '_', $match); |
|
| 173 | + $word = trim($word, '"'); |
|
| 174 | + $q = str_replace($match, $word, $q); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + // corriger la regexp |
|
| 178 | + if (preg_match(',["][^"]+["],Uims', $recherche_mod, $matches)) { |
|
| 179 | + foreach ($matches as $match) { |
|
| 180 | + $word = preg_replace(',\s+,Uims', '[\s]', $match); |
|
| 181 | + $word = trim($word, '"'); |
|
| 182 | + $recherche_mod = str_replace($match, $word, $recherche_mod); |
|
| 183 | + } |
|
| 184 | + } |
|
| 185 | + $q = sql_quote( |
|
| 186 | + '%' |
|
| 187 | + . preg_replace(',\s+,' . $u, '%', $q) |
|
| 188 | + . '%' |
|
| 189 | + ); |
|
| 190 | + |
|
| 191 | + $preg = '/' . preg_replace(',\s+,' . $u, '.+', trim($recherche_mod)) . '/' . $options['preg_flags']; |
|
| 192 | + } else { |
|
| 193 | + $methode = 'REGEXP'; |
|
| 194 | + $q = sql_quote(trim($recherche, '/')); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + // tous les caracteres transliterables de $q sont remplaces par un joker |
|
| 198 | + // permet de matcher en SQL meme si on est sensible aux accents (SQLite) |
|
| 199 | + $q_t = $q; |
|
| 200 | + for ($i = 0; $i < spip_strlen($q); $i++) { |
|
| 201 | + $char = spip_substr($q, $i, 1); |
|
| 202 | + if ( |
|
| 203 | + !is_ascii($char) |
|
| 204 | + and $char_t = translitteration($char) |
|
| 205 | + and $char_t !== $char |
|
| 206 | + ) { |
|
| 207 | + // on utilise ..?.? car le char utf peut etre encode sur 1, 2 ou 3 bytes |
|
| 208 | + // mais c'est un pis aller cf #4354 |
|
| 209 | + $q_t = str_replace($char, $is_preg ? '..?.?' : '_', $q_t); |
|
| 210 | + } |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + $q = $q_t; |
|
| 214 | + |
|
| 215 | + // fix : SQLite 3 est sensible aux accents, on jokerise les caracteres |
|
| 216 | + // les plus frequents qui peuvent etre accentues |
|
| 217 | + // (oui c'est tres dicustable...) |
|
| 218 | + if ( |
|
| 219 | + isset($GLOBALS['connexions'][$options['serveur'] ?: 0]['type']) |
|
| 220 | + and strncmp($GLOBALS['connexions'][$options['serveur'] ?: 0]['type'], 'sqlite', 6) == 0 |
|
| 221 | + ) { |
|
| 222 | + $q_t = strtr($q, 'aeuioc', $is_preg ? '......' : '______'); |
|
| 223 | + // si il reste au moins un char significatif... |
|
| 224 | + if (preg_match(",[^'%_.],", $q_t)) { |
|
| 225 | + $q = $q_t; |
|
| 226 | + } |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + return $expression[$key] = [$methode, $q, $preg]; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | |
@@ -253,142 +253,142 @@ discard block |
||
| 253 | 253 | * @return array |
| 254 | 254 | */ |
| 255 | 255 | function recherche_en_base($recherche = '', $tables = null, $options = [], $serveur = '') { |
| 256 | - include_spip('base/abstract_sql'); |
|
| 257 | - |
|
| 258 | - if (!is_array($tables)) { |
|
| 259 | - $liste = liste_des_champs(); |
|
| 260 | - |
|
| 261 | - if ( |
|
| 262 | - is_string($tables) |
|
| 263 | - and $tables != '' |
|
| 264 | - ) { |
|
| 265 | - $toutes = []; |
|
| 266 | - foreach (explode(',', $tables) as $t) { |
|
| 267 | - $t = trim($t); |
|
| 268 | - if (isset($liste[$t])) { |
|
| 269 | - $toutes[$t] = $liste[$t]; |
|
| 270 | - } |
|
| 271 | - } |
|
| 272 | - $tables = $toutes; |
|
| 273 | - unset($toutes); |
|
| 274 | - } else { |
|
| 275 | - $tables = $liste; |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - if (!strlen($recherche) or !count($tables)) { |
|
| 280 | - return []; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - include_spip('inc/autoriser'); |
|
| 284 | - |
|
| 285 | - // options par defaut |
|
| 286 | - $options = array_merge( |
|
| 287 | - [ |
|
| 288 | - 'preg_flags' => 'UimsS', |
|
| 289 | - 'toutvoir' => false, |
|
| 290 | - 'champs' => false, |
|
| 291 | - 'score' => false, |
|
| 292 | - 'matches' => false, |
|
| 293 | - 'jointures' => false, |
|
| 294 | - 'serveur' => $serveur |
|
| 295 | - ], |
|
| 296 | - $options |
|
| 297 | - ); |
|
| 298 | - |
|
| 299 | - $results = []; |
|
| 300 | - |
|
| 301 | - // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | - // pour recuperer les couples (id_objet, score) |
|
| 303 | - // Le resultat est au format { |
|
| 304 | - // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | - // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | - // } |
|
| 307 | - |
|
| 308 | - include_spip('inc/recherche_to_array'); |
|
| 309 | - |
|
| 310 | - foreach ($tables as $table => $champs) { |
|
| 311 | - # lock via memoization, si dispo |
|
| 312 | - if (function_exists('cache_lock')) { |
|
| 313 | - cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | - } |
|
| 315 | - |
|
| 316 | - spip_timer('rech'); |
|
| 317 | - |
|
| 318 | - # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | - $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | - $results[$table] = $to_array( |
|
| 321 | - $recherche, |
|
| 322 | - array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | - ); |
|
| 324 | - ##var_dump($results[$table]); |
|
| 325 | - |
|
| 326 | - |
|
| 327 | - spip_log( |
|
| 328 | - "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | - 'recherche' |
|
| 330 | - ); |
|
| 331 | - |
|
| 332 | - if (isset($lock)) { |
|
| 333 | - cache_unlock($lock); |
|
| 334 | - } |
|
| 335 | - } |
|
| 336 | - |
|
| 337 | - return $results; |
|
| 256 | + include_spip('base/abstract_sql'); |
|
| 257 | + |
|
| 258 | + if (!is_array($tables)) { |
|
| 259 | + $liste = liste_des_champs(); |
|
| 260 | + |
|
| 261 | + if ( |
|
| 262 | + is_string($tables) |
|
| 263 | + and $tables != '' |
|
| 264 | + ) { |
|
| 265 | + $toutes = []; |
|
| 266 | + foreach (explode(',', $tables) as $t) { |
|
| 267 | + $t = trim($t); |
|
| 268 | + if (isset($liste[$t])) { |
|
| 269 | + $toutes[$t] = $liste[$t]; |
|
| 270 | + } |
|
| 271 | + } |
|
| 272 | + $tables = $toutes; |
|
| 273 | + unset($toutes); |
|
| 274 | + } else { |
|
| 275 | + $tables = $liste; |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + if (!strlen($recherche) or !count($tables)) { |
|
| 280 | + return []; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + include_spip('inc/autoriser'); |
|
| 284 | + |
|
| 285 | + // options par defaut |
|
| 286 | + $options = array_merge( |
|
| 287 | + [ |
|
| 288 | + 'preg_flags' => 'UimsS', |
|
| 289 | + 'toutvoir' => false, |
|
| 290 | + 'champs' => false, |
|
| 291 | + 'score' => false, |
|
| 292 | + 'matches' => false, |
|
| 293 | + 'jointures' => false, |
|
| 294 | + 'serveur' => $serveur |
|
| 295 | + ], |
|
| 296 | + $options |
|
| 297 | + ); |
|
| 298 | + |
|
| 299 | + $results = []; |
|
| 300 | + |
|
| 301 | + // Utiliser l'iterateur (DATA:recherche) |
|
| 302 | + // pour recuperer les couples (id_objet, score) |
|
| 303 | + // Le resultat est au format { |
|
| 304 | + // id1 = { 'score' => x, attrs => { } }, |
|
| 305 | + // id2 = { 'score' => x, attrs => { } }, |
|
| 306 | + // } |
|
| 307 | + |
|
| 308 | + include_spip('inc/recherche_to_array'); |
|
| 309 | + |
|
| 310 | + foreach ($tables as $table => $champs) { |
|
| 311 | + # lock via memoization, si dispo |
|
| 312 | + if (function_exists('cache_lock')) { |
|
| 313 | + cache_lock($lock = _RECHERCHE_LOCK_KEY . ' ' . $table . ' ' . $recherche); |
|
| 314 | + } |
|
| 315 | + |
|
| 316 | + spip_timer('rech'); |
|
| 317 | + |
|
| 318 | + # TODO : ici plutot charger un iterateur via l'API iterateurs |
|
| 319 | + $to_array = charger_fonction('recherche_to_array', 'inc'); |
|
| 320 | + $results[$table] = $to_array( |
|
| 321 | + $recherche, |
|
| 322 | + array_merge($options, ['table' => $table, 'champs' => $champs]) |
|
| 323 | + ); |
|
| 324 | + ##var_dump($results[$table]); |
|
| 325 | + |
|
| 326 | + |
|
| 327 | + spip_log( |
|
| 328 | + "recherche $table ($recherche) : " . (is_countable($results[$table]) ? count($results[$table]) : 0) . ' resultats ' . spip_timer('rech'), |
|
| 329 | + 'recherche' |
|
| 330 | + ); |
|
| 331 | + |
|
| 332 | + if (isset($lock)) { |
|
| 333 | + cache_unlock($lock); |
|
| 334 | + } |
|
| 335 | + } |
|
| 336 | + |
|
| 337 | + return $results; |
|
| 338 | 338 | } |
| 339 | 339 | |
| 340 | 340 | |
| 341 | 341 | // Effectue une recherche sur toutes les tables de la base de donnees |
| 342 | 342 | function remplace_en_base($recherche = '', $remplace = null, $tables = null, $options = []) { |
| 343 | - include_spip('inc/modifier'); |
|
| 344 | - |
|
| 345 | - // options par defaut |
|
| 346 | - $options = array_merge( |
|
| 347 | - [ |
|
| 348 | - 'preg_flags' => 'UimsS', |
|
| 349 | - 'toutmodifier' => false |
|
| 350 | - ], |
|
| 351 | - $options |
|
| 352 | - ); |
|
| 353 | - $options['champs'] = true; |
|
| 354 | - |
|
| 355 | - |
|
| 356 | - if (!is_array($tables)) { |
|
| 357 | - $tables = liste_des_champs(); |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | - |
|
| 362 | - $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | - |
|
| 364 | - foreach ($results as $table => $r) { |
|
| 365 | - $_id_table = id_table_objet($table); |
|
| 366 | - foreach ($r as $id => $x) { |
|
| 367 | - if ( |
|
| 368 | - $options['toutmodifier'] |
|
| 369 | - or autoriser('modifier', $table, $id) |
|
| 370 | - ) { |
|
| 371 | - $modifs = []; |
|
| 372 | - foreach ($x['champs'] as $key => $val) { |
|
| 373 | - if ($key == $_id_table) { |
|
| 374 | - continue; |
|
| 375 | - } |
|
| 376 | - $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | - if ($repl <> $val) { |
|
| 378 | - $modifs[$key] = $repl; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - if ($modifs) { |
|
| 382 | - objet_modifier_champs( |
|
| 383 | - $table, |
|
| 384 | - $id, |
|
| 385 | - [ |
|
| 386 | - 'champs' => array_keys($modifs), |
|
| 387 | - ], |
|
| 388 | - $modifs |
|
| 389 | - ); |
|
| 390 | - } |
|
| 391 | - } |
|
| 392 | - } |
|
| 393 | - } |
|
| 343 | + include_spip('inc/modifier'); |
|
| 344 | + |
|
| 345 | + // options par defaut |
|
| 346 | + $options = array_merge( |
|
| 347 | + [ |
|
| 348 | + 'preg_flags' => 'UimsS', |
|
| 349 | + 'toutmodifier' => false |
|
| 350 | + ], |
|
| 351 | + $options |
|
| 352 | + ); |
|
| 353 | + $options['champs'] = true; |
|
| 354 | + |
|
| 355 | + |
|
| 356 | + if (!is_array($tables)) { |
|
| 357 | + $tables = liste_des_champs(); |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + $results = recherche_en_base($recherche, $tables, $options); |
|
| 361 | + |
|
| 362 | + $preg = '/' . str_replace('/', '\\/', $recherche) . '/' . $options['preg_flags']; |
|
| 363 | + |
|
| 364 | + foreach ($results as $table => $r) { |
|
| 365 | + $_id_table = id_table_objet($table); |
|
| 366 | + foreach ($r as $id => $x) { |
|
| 367 | + if ( |
|
| 368 | + $options['toutmodifier'] |
|
| 369 | + or autoriser('modifier', $table, $id) |
|
| 370 | + ) { |
|
| 371 | + $modifs = []; |
|
| 372 | + foreach ($x['champs'] as $key => $val) { |
|
| 373 | + if ($key == $_id_table) { |
|
| 374 | + continue; |
|
| 375 | + } |
|
| 376 | + $repl = preg_replace($preg, $remplace, $val); |
|
| 377 | + if ($repl <> $val) { |
|
| 378 | + $modifs[$key] = $repl; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + if ($modifs) { |
|
| 382 | + objet_modifier_champs( |
|
| 383 | + $table, |
|
| 384 | + $id, |
|
| 385 | + [ |
|
| 386 | + 'champs' => array_keys($modifs), |
|
| 387 | + ], |
|
| 388 | + $modifs |
|
| 389 | + ); |
|
| 390 | + } |
|
| 391 | + } |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | 394 | } |