@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | |
| 22 | 22 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 23 | - return; |
|
| 23 | + return; |
|
| 24 | 24 | } |
| 25 | 25 | |
| 26 | 26 | include_spip('inc/config'); |
@@ -32,31 +32,31 @@ discard block |
||
| 32 | 32 | * @return array|false |
| 33 | 33 | */ |
| 34 | 34 | function cvtconf_formulaire_charger($flux) { |
| 35 | - if ( |
|
| 36 | - $form = $flux['args']['form'] |
|
| 37 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | - ) { |
|
| 39 | - // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | - include_spip('inc/autoriser'); |
|
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | - return false; |
|
| 43 | - } |
|
| 35 | + if ( |
|
| 36 | + $form = $flux['args']['form'] |
|
| 37 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 38 | + ) { |
|
| 39 | + // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
|
| 40 | + include_spip('inc/autoriser'); |
|
| 41 | + if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 42 | + return false; |
|
| 43 | + } |
|
| 44 | 44 | |
| 45 | - // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | - if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | - $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | - $flux['data']['editable'] = true; |
|
| 49 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | - if (!_AJAX) { |
|
| 51 | - var_dump($flux['data']); |
|
| 52 | - } |
|
| 53 | - // reinjecter pour la trace au traitement |
|
| 54 | - $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - } |
|
| 45 | + // S'il n'y a pas de fonction charger(), on génère un contexte automatiquement |
|
| 46 | + if (!charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 47 | + $flux['data'] = cvtconf_formulaires_configurer_recense($form); |
|
| 48 | + $flux['data']['editable'] = true; |
|
| 49 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 50 | + if (!_AJAX) { |
|
| 51 | + var_dump($flux['data']); |
|
| 52 | + } |
|
| 53 | + // reinjecter pour la trace au traitement |
|
| 54 | + $flux['data']['_hidden'] = "<input type='hidden' name='var_mode' value='configurer' />"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | - return $flux; |
|
| 59 | + return $flux; |
|
| 60 | 60 | } |
| 61 | 61 | |
| 62 | 62 | /** |
@@ -66,16 +66,16 @@ discard block |
||
| 66 | 66 | * @return array |
| 67 | 67 | */ |
| 68 | 68 | function cvtconf_formulaire_traiter($flux) { |
| 69 | - if ( |
|
| 70 | - $form = $flux['args']['form'] |
|
| 71 | - and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | - and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | - ) { |
|
| 74 | - $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | - } |
|
| 69 | + if ( |
|
| 70 | + $form = $flux['args']['form'] |
|
| 71 | + and strncmp($form, 'configurer_', 11) == 0 // un #FORMULAIRE_CONFIGURER_XXX |
|
| 72 | + and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
|
| 73 | + ) { |
|
| 74 | + $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - return $flux; |
|
| 78 | + return $flux; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -91,32 +91,32 @@ discard block |
||
| 91 | 91 | * @return string |
| 92 | 92 | */ |
| 93 | 93 | function cvtconf_formulaires_configurer_enregistre($form, $args) { |
| 94 | - $valeurs = []; |
|
| 95 | - // charger les valeurs |
|
| 96 | - // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | - // qui prend alors la main sur l'auto detection |
|
| 98 | - if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | - $valeurs = $charger_valeurs(...$args); |
|
| 100 | - } |
|
| 101 | - $valeurs = pipeline( |
|
| 102 | - 'formulaire_charger', |
|
| 103 | - [ |
|
| 104 | - 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | - 'data' => $valeurs |
|
| 106 | - ] |
|
| 107 | - ); |
|
| 108 | - // ne pas stocker editable ! |
|
| 109 | - unset($valeurs['editable']); |
|
| 94 | + $valeurs = []; |
|
| 95 | + // charger les valeurs |
|
| 96 | + // ce qui permet de prendre en charge une fonction charger() existante |
|
| 97 | + // qui prend alors la main sur l'auto detection |
|
| 98 | + if ($charger_valeurs = charger_fonction('charger', "formulaires/$form/", true)) { |
|
| 99 | + $valeurs = $charger_valeurs(...$args); |
|
| 100 | + } |
|
| 101 | + $valeurs = pipeline( |
|
| 102 | + 'formulaire_charger', |
|
| 103 | + [ |
|
| 104 | + 'args' => ['form' => $form, 'args' => $args, 'je_suis_poste' => false], |
|
| 105 | + 'data' => $valeurs |
|
| 106 | + ] |
|
| 107 | + ); |
|
| 108 | + // ne pas stocker editable ! |
|
| 109 | + unset($valeurs['editable']); |
|
| 110 | 110 | |
| 111 | - // recuperer les valeurs postees |
|
| 112 | - $store = []; |
|
| 113 | - foreach ($valeurs as $k => $v) { |
|
| 114 | - if (substr($k, 0, 1) !== '_') { |
|
| 115 | - $store[$k] = _request($k); |
|
| 116 | - } |
|
| 117 | - } |
|
| 111 | + // recuperer les valeurs postees |
|
| 112 | + $store = []; |
|
| 113 | + foreach ($valeurs as $k => $v) { |
|
| 114 | + if (substr($k, 0, 1) !== '_') { |
|
| 115 | + $store[$k] = _request($k); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 119 | + return cvtconf_configurer_stocker($form, $valeurs, $store); |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -132,31 +132,31 @@ discard block |
||
| 132 | 132 | * @return array |
| 133 | 133 | */ |
| 134 | 134 | function cvtconf_definir_configurer_conteneur($form, $valeurs) { |
| 135 | - // stocker en base |
|
| 136 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | - $casier = substr($form, 11); |
|
| 138 | - $table = 'meta'; |
|
| 139 | - $prefixe = ''; |
|
| 140 | - $stockage = ''; |
|
| 135 | + // stocker en base |
|
| 136 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 137 | + $casier = substr($form, 11); |
|
| 138 | + $table = 'meta'; |
|
| 139 | + $prefixe = ''; |
|
| 140 | + $stockage = ''; |
|
| 141 | 141 | |
| 142 | - if (isset($valeurs['_meta_casier'])) { |
|
| 143 | - $casier = $valeurs['_meta_casier']; |
|
| 144 | - } |
|
| 145 | - if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | - $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | - } |
|
| 148 | - if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | - } |
|
| 142 | + if (isset($valeurs['_meta_casier'])) { |
|
| 143 | + $casier = $valeurs['_meta_casier']; |
|
| 144 | + } |
|
| 145 | + if (isset($valeurs['_meta_prefixe'])) { |
|
| 146 | + $prefixe = $valeurs['_meta_prefixe']; |
|
| 147 | + } |
|
| 148 | + if (isset($valeurs['_meta_stockage'])) { |
|
| 149 | + $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 150 | + } |
|
| 151 | 151 | |
| 152 | - // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | - // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | - if (isset($valeurs['_meta_table'])) { |
|
| 155 | - $table = $valeurs['_meta_table']; |
|
| 156 | - $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | - } |
|
| 152 | + // si on indique juste une table, il faut vider les autres proprietes |
|
| 153 | + // car par defaut on utilise ni casier ni prefixe dans ce cas |
|
| 154 | + if (isset($valeurs['_meta_table'])) { |
|
| 155 | + $table = $valeurs['_meta_table']; |
|
| 156 | + $casier = ($valeurs['_meta_casier'] ?? ''); |
|
| 157 | + } |
|
| 158 | 158 | |
| 159 | - return [$table, $casier, $prefixe, $stockage]; |
|
| 159 | + return [$table, $casier, $prefixe, $stockage]; |
|
| 160 | 160 | } |
| 161 | 161 | |
| 162 | 162 | /** |
@@ -167,48 +167,48 @@ discard block |
||
| 167 | 167 | * @return array |
| 168 | 168 | */ |
| 169 | 169 | function cvtconf_formulaires_configurer_recense($form) { |
| 170 | - $valeurs = ['editable' => ' ']; |
|
| 170 | + $valeurs = ['editable' => ' ']; |
|
| 171 | 171 | |
| 172 | - // sinon cas analyse du squelette |
|
| 173 | - if ( |
|
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | - and lire_fichier($f, $contenu) |
|
| 176 | - ) { |
|
| 177 | - for ($i = 0; $i < 2; $i++) { |
|
| 178 | - // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | - // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | - if ($i == 1) { |
|
| 181 | - $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | - } |
|
| 172 | + // sinon cas analyse du squelette |
|
| 173 | + if ( |
|
| 174 | + $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | + and lire_fichier($f, $contenu) |
|
| 176 | + ) { |
|
| 177 | + for ($i = 0; $i < 2; $i++) { |
|
| 178 | + // a la seconde iteration, evaluer le fond avec les valeurs deja trouvees |
|
| 179 | + // permet de trouver aussi les name="#GET{truc}" |
|
| 180 | + if ($i == 1) { |
|
| 181 | + $contenu = recuperer_fond("formulaires/$form", $valeurs); |
|
| 182 | + } |
|
| 183 | 183 | |
| 184 | - $balises = array_merge( |
|
| 185 | - extraire_balises($contenu, 'input'), |
|
| 186 | - extraire_balises($contenu, 'textarea'), |
|
| 187 | - extraire_balises($contenu, 'select') |
|
| 188 | - ); |
|
| 184 | + $balises = array_merge( |
|
| 185 | + extraire_balises($contenu, 'input'), |
|
| 186 | + extraire_balises($contenu, 'textarea'), |
|
| 187 | + extraire_balises($contenu, 'select') |
|
| 188 | + ); |
|
| 189 | 189 | |
| 190 | - foreach ($balises as $b) { |
|
| 191 | - if ( |
|
| 192 | - $n = extraire_attribut($b, 'name') |
|
| 193 | - and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | - and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | - and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | - ) { |
|
| 197 | - $valeurs[$r[1]] = ''; |
|
| 198 | - // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | - // en input hidden dans le squelette |
|
| 200 | - if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | - $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 206 | - } |
|
| 190 | + foreach ($balises as $b) { |
|
| 191 | + if ( |
|
| 192 | + $n = extraire_attribut($b, 'name') |
|
| 193 | + and preg_match(',^([\w\-]+)(\[\w*\])?$,', $n, $r) |
|
| 194 | + and !in_array($n, ['formulaire_action', 'formulaire_action_args', 'formulaire_action_sign']) |
|
| 195 | + and extraire_attribut($b, 'type') !== 'submit' |
|
| 196 | + ) { |
|
| 197 | + $valeurs[$r[1]] = ''; |
|
| 198 | + // recuperer les valeurs _meta_xx qui peuvent etre fournies |
|
| 199 | + // en input hidden dans le squelette |
|
| 200 | + if (strncmp($r[1], '_meta_', 6) == 0) { |
|
| 201 | + $valeurs[$r[1]] = extraire_attribut($b, 'value'); |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | 207 | |
| 208 | 208 | |
| 209 | - cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 209 | + cvtconf_configurer_lire_meta($form, $valeurs); |
|
| 210 | 210 | |
| 211 | - return $valeurs; |
|
| 211 | + return $valeurs; |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -220,26 +220,26 @@ discard block |
||
| 220 | 220 | * @return string |
| 221 | 221 | */ |
| 222 | 222 | function cvtconf_configurer_stocker($form, $valeurs, $store) { |
| 223 | - $trace = ''; |
|
| 224 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | - // stocker en base |
|
| 226 | - // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | - if (!isset($GLOBALS[$table])) { |
|
| 228 | - lire_metas($table); |
|
| 229 | - } |
|
| 223 | + $trace = ''; |
|
| 224 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 225 | + // stocker en base |
|
| 226 | + // par defaut, dans un casier serialize dans spip_meta (idem CFG) |
|
| 227 | + if (!isset($GLOBALS[$table])) { |
|
| 228 | + lire_metas($table); |
|
| 229 | + } |
|
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | - $table = ($table) ? "/$table/" : ''; |
|
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 231 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 232 | + $table = ($table) ? "/$table/" : ''; |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | - foreach ($store as $k => $v) { |
|
| 236 | - ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | - if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | - } |
|
| 240 | - } |
|
| 235 | + foreach ($store as $k => $v) { |
|
| 236 | + ecrire_config("$stockage$table$prefixe$casier$k", $v); |
|
| 237 | + if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
|
| 238 | + $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 239 | + } |
|
| 240 | + } |
|
| 241 | 241 | |
| 242 | - return $trace; |
|
| 242 | + return $trace; |
|
| 243 | 243 | } |
| 244 | 244 | |
| 245 | 245 | /** |
@@ -249,21 +249,21 @@ discard block |
||
| 249 | 249 | * @param array $valeurs |
| 250 | 250 | */ |
| 251 | 251 | function cvtconf_configurer_lire_meta($form, &$valeurs) { |
| 252 | - [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + [$table, $casier, $prefixe, $stockage] = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 253 | 253 | |
| 254 | - $table = ($table) ? "/$table/" : ''; |
|
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | - if ($casier) { |
|
| 257 | - $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | - $prefixe = ''; |
|
| 259 | - } else { |
|
| 260 | - $table = rtrim($table, '/'); |
|
| 261 | - $meta = lire_config("$stockage$table"); |
|
| 262 | - } |
|
| 254 | + $table = ($table) ? "/$table/" : ''; |
|
| 255 | + $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 256 | + if ($casier) { |
|
| 257 | + $meta = lire_config("$stockage$table$prefixe$casier"); |
|
| 258 | + $prefixe = ''; |
|
| 259 | + } else { |
|
| 260 | + $table = rtrim($table, '/'); |
|
| 261 | + $meta = lire_config("$stockage$table"); |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - foreach ($valeurs as $k => $v) { |
|
| 265 | - if (substr($k, 0, 1) !== '_') { |
|
| 266 | - $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = ($meta[$prefixe . $k] ?? null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 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 | include_spip('inc/charsets'); |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function exporter_csv_champ($champ) { |
| 35 | - #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | - #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | - #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | - $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | - $champ = str_replace('"', '""', $champ); |
|
| 35 | + #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | + #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | + #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | + $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | + $champ = str_replace('"', '""', $champ); |
|
| 40 | 40 | |
| 41 | - return '"' . $champ . '"'; |
|
| 41 | + return '"' . $champ . '"'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | 57 | function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) { |
| 58 | - if ($callback) { |
|
| 59 | - $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 60 | - } |
|
| 61 | - $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | - if ($importer_charset) { |
|
| 63 | - $output = str_replace('’', '\'', $output); |
|
| 64 | - $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | - } |
|
| 66 | - return $output; |
|
| 58 | + if ($callback) { |
|
| 59 | + $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 60 | + } |
|
| 61 | + $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | + if ($importer_charset) { |
|
| 63 | + $output = str_replace('’', '\'', $output); |
|
| 64 | + $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | + } |
|
| 66 | + return $output; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | 77 | function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) { |
| 78 | - return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 78 | + return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -101,101 +101,101 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function inc_exporter_csv_dist($titre, $resource, $options = []) { |
| 103 | 103 | |
| 104 | - // support ancienne syntaxe |
|
| 105 | - // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | - if (is_string($options)) { |
|
| 107 | - $args = func_get_args(); |
|
| 108 | - $options = []; |
|
| 109 | - foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | - if (!empty($args[$k])) { |
|
| 111 | - $options[$option] = $args[$k]; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $default_options = [ |
|
| 117 | - 'delim' => ', ', |
|
| 118 | - 'entetes' => null, |
|
| 119 | - 'envoyer' => true, |
|
| 120 | - 'charset' => null, |
|
| 121 | - 'callback' => null, |
|
| 122 | - ]; |
|
| 123 | - $options = array_merge($default_options, $options); |
|
| 124 | - |
|
| 125 | - $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | - |
|
| 127 | - if ($options['delim'] == 'TAB') { |
|
| 128 | - $options['delim'] = "\t"; |
|
| 129 | - } |
|
| 130 | - if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | - $options['delim'] = ','; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $charset = $GLOBALS['meta']['charset']; |
|
| 135 | - $importer_charset = null; |
|
| 136 | - if ($options['delim'] == ',') { |
|
| 137 | - $extension = 'csv'; |
|
| 138 | - } else { |
|
| 139 | - $extension = 'xls'; |
|
| 140 | - # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | - $charset = 'iso-8859-1'; |
|
| 142 | - } |
|
| 143 | - // mais si une option charset est explicite, elle a la priorite |
|
| 144 | - if (!empty($options['charset'])) { |
|
| 145 | - $charset = $options['charset']; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | - |
|
| 150 | - $filename = "$filename.$extension"; |
|
| 151 | - |
|
| 152 | - $output = ''; |
|
| 153 | - $nb = 0; |
|
| 154 | - if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | - $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | - } |
|
| 157 | - // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | - $nb++; |
|
| 159 | - |
|
| 160 | - if ($options['envoyer']) { |
|
| 161 | - $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | - header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | - header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | - |
|
| 165 | - // Vider tous les tampons |
|
| 166 | - $level = @ob_get_level(); |
|
| 167 | - while ($level--) { |
|
| 168 | - @ob_end_flush(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | - // sinon on ecrit directement sur stdout |
|
| 174 | - if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | - $fichier = 'php://output'; |
|
| 176 | - } |
|
| 177 | - else { |
|
| 178 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $fp = fopen($fichier, 'w'); |
|
| 182 | - $length = fwrite($fp, $output); |
|
| 183 | - |
|
| 184 | - while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | - $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | - $length += fwrite($fp, $output); |
|
| 187 | - $nb++; |
|
| 188 | - } |
|
| 189 | - fclose($fp); |
|
| 190 | - |
|
| 191 | - if ($options['envoyer']) { |
|
| 192 | - if ($options['envoyer'] === 'attachment') { |
|
| 193 | - header("Content-Length: $length"); |
|
| 194 | - readfile($fichier); |
|
| 195 | - } |
|
| 196 | - // si on a envoye inline, c'est deja tout bon |
|
| 197 | - exit; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $fichier; |
|
| 104 | + // support ancienne syntaxe |
|
| 105 | + // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | + if (is_string($options)) { |
|
| 107 | + $args = func_get_args(); |
|
| 108 | + $options = []; |
|
| 109 | + foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | + if (!empty($args[$k])) { |
|
| 111 | + $options[$option] = $args[$k]; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $default_options = [ |
|
| 117 | + 'delim' => ', ', |
|
| 118 | + 'entetes' => null, |
|
| 119 | + 'envoyer' => true, |
|
| 120 | + 'charset' => null, |
|
| 121 | + 'callback' => null, |
|
| 122 | + ]; |
|
| 123 | + $options = array_merge($default_options, $options); |
|
| 124 | + |
|
| 125 | + $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | + |
|
| 127 | + if ($options['delim'] == 'TAB') { |
|
| 128 | + $options['delim'] = "\t"; |
|
| 129 | + } |
|
| 130 | + if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | + $options['delim'] = ','; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $charset = $GLOBALS['meta']['charset']; |
|
| 135 | + $importer_charset = null; |
|
| 136 | + if ($options['delim'] == ',') { |
|
| 137 | + $extension = 'csv'; |
|
| 138 | + } else { |
|
| 139 | + $extension = 'xls'; |
|
| 140 | + # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | + $charset = 'iso-8859-1'; |
|
| 142 | + } |
|
| 143 | + // mais si une option charset est explicite, elle a la priorite |
|
| 144 | + if (!empty($options['charset'])) { |
|
| 145 | + $charset = $options['charset']; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | + |
|
| 150 | + $filename = "$filename.$extension"; |
|
| 151 | + |
|
| 152 | + $output = ''; |
|
| 153 | + $nb = 0; |
|
| 154 | + if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | + $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | + } |
|
| 157 | + // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | + $nb++; |
|
| 159 | + |
|
| 160 | + if ($options['envoyer']) { |
|
| 161 | + $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | + header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | + header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | + |
|
| 165 | + // Vider tous les tampons |
|
| 166 | + $level = @ob_get_level(); |
|
| 167 | + while ($level--) { |
|
| 168 | + @ob_end_flush(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | + // sinon on ecrit directement sur stdout |
|
| 174 | + if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | + $fichier = 'php://output'; |
|
| 176 | + } |
|
| 177 | + else { |
|
| 178 | + $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $fp = fopen($fichier, 'w'); |
|
| 182 | + $length = fwrite($fp, $output); |
|
| 183 | + |
|
| 184 | + while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | + $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | + $length += fwrite($fp, $output); |
|
| 187 | + $nb++; |
|
| 188 | + } |
|
| 189 | + fclose($fp); |
|
| 190 | + |
|
| 191 | + if ($options['envoyer']) { |
|
| 192 | + if ($options['envoyer'] === 'attachment') { |
|
| 193 | + header("Content-Length: $length"); |
|
| 194 | + readfile($fichier); |
|
| 195 | + } |
|
| 196 | + // si on a envoye inline, c'est deja tout bon |
|
| 197 | + exit; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $fichier; |
|
| 201 | 201 | } |
@@ -17,17 +17,17 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_UPGRADE_TIME_OUT')) { |
| 24 | - /** |
|
| 25 | - * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 26 | - * avant que la durée d'exécution du script provoque un timeout |
|
| 27 | - * |
|
| 28 | - * @var int |
|
| 29 | - **/ |
|
| 30 | - define('_UPGRADE_TIME_OUT', 20); |
|
| 24 | + /** |
|
| 25 | + * Durée en secondes pour relancer les scripts de mises à jour, x secondes |
|
| 26 | + * avant que la durée d'exécution du script provoque un timeout |
|
| 27 | + * |
|
| 28 | + * @var int |
|
| 29 | + **/ |
|
| 30 | + define('_UPGRADE_TIME_OUT', 20); |
|
| 31 | 31 | } |
| 32 | 32 | |
| 33 | 33 | /** |
@@ -50,40 +50,40 @@ discard block |
||
| 50 | 50 | * @return void |
| 51 | 51 | */ |
| 52 | 52 | function base_upgrade_dist($titre = '', $reprise = '') { |
| 53 | - if (!$titre) { |
|
| 54 | - return; |
|
| 55 | - } // anti-testeur automatique |
|
| 56 | - if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 57 | - if (!is_numeric(_request('reinstall'))) { |
|
| 58 | - include_spip('base/create'); |
|
| 59 | - spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 60 | - creer_base(); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 64 | - // lancement de l'upgrade SPIP |
|
| 65 | - $res = maj_base(); |
|
| 66 | - |
|
| 67 | - if ($res) { |
|
| 68 | - // on arrete tout ici ! |
|
| 69 | - exit; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 73 | - |
|
| 74 | - // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 75 | - @spip_unlink(_CACHE_RUBRIQUES); |
|
| 76 | - @spip_unlink(_CACHE_PIPELINES); |
|
| 77 | - @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 78 | - @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 79 | - @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 80 | - @spip_unlink(_CACHE_CHEMIN); |
|
| 81 | - @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 82 | - |
|
| 83 | - include_spip('inc/auth'); |
|
| 84 | - auth_synchroniser_distant(); |
|
| 85 | - $config = charger_fonction('config', 'inc'); |
|
| 86 | - $config(); |
|
| 53 | + if (!$titre) { |
|
| 54 | + return; |
|
| 55 | + } // anti-testeur automatique |
|
| 56 | + if ($GLOBALS['spip_version_base'] != $GLOBALS['meta']['version_installee']) { |
|
| 57 | + if (!is_numeric(_request('reinstall'))) { |
|
| 58 | + include_spip('base/create'); |
|
| 59 | + spip_log('recree les tables eventuellement disparues', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 60 | + creer_base(); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + // quand on rentre par ici, c'est toujours une mise a jour de SPIP |
|
| 64 | + // lancement de l'upgrade SPIP |
|
| 65 | + $res = maj_base(); |
|
| 66 | + |
|
| 67 | + if ($res) { |
|
| 68 | + // on arrete tout ici ! |
|
| 69 | + exit; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + spip_log('Fin de mise a jour SQL. Debut m-a-j acces et config', 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 73 | + |
|
| 74 | + // supprimer quelques fichiers temporaires qui peuvent se retrouver invalides |
|
| 75 | + @spip_unlink(_CACHE_RUBRIQUES); |
|
| 76 | + @spip_unlink(_CACHE_PIPELINES); |
|
| 77 | + @spip_unlink(_CACHE_PLUGINS_PATH); |
|
| 78 | + @spip_unlink(_CACHE_PLUGINS_OPT); |
|
| 79 | + @spip_unlink(_CACHE_PLUGINS_FCT); |
|
| 80 | + @spip_unlink(_CACHE_CHEMIN); |
|
| 81 | + @spip_unlink(_DIR_TMP . 'plugin_xml_cache.gz'); |
|
| 82 | + |
|
| 83 | + include_spip('inc/auth'); |
|
| 84 | + auth_synchroniser_distant(); |
|
| 85 | + $config = charger_fonction('config', 'inc'); |
|
| 86 | + $config(); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -114,51 +114,51 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | function maj_base($version_cible = 0, $redirect = '', $debut_page = true) { |
| 116 | 116 | |
| 117 | - $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 118 | - |
|
| 119 | - spip_log( |
|
| 120 | - "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 121 | - 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 122 | - ); |
|
| 123 | - if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 124 | - sql_replace( |
|
| 125 | - 'spip_meta', |
|
| 126 | - [ |
|
| 127 | - 'nom' => 'version_installee', |
|
| 128 | - 'valeur' => $GLOBALS['spip_version_base'], |
|
| 129 | - 'impt' => 'non' |
|
| 130 | - ] |
|
| 131 | - ); |
|
| 132 | - return false; |
|
| 133 | - } |
|
| 134 | - if (!upgrade_test()) { |
|
| 135 | - return true; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 139 | - |
|
| 140 | - if ($version_installee < 2021_01_01_00) { |
|
| 141 | - include_spip('maj/legacy/v21'); |
|
| 142 | - include_spip('maj/legacy/v30'); |
|
| 143 | - include_spip('maj/legacy/v31'); |
|
| 144 | - include_spip('maj/legacy/v32'); |
|
| 145 | - include_spip('maj/legacy/v40'); |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - include_spip('maj/2021'); |
|
| 149 | - |
|
| 150 | - ksort($GLOBALS['maj']); |
|
| 151 | - $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 152 | - if ($res) { |
|
| 153 | - if (!is_array($res)) { |
|
| 154 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 155 | - } else { |
|
| 156 | - echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 157 | - echo install_fin_html(); |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - return $res; |
|
| 117 | + $version_installee = $GLOBALS['meta']['version_installee'] ?? null; |
|
| 118 | + |
|
| 119 | + spip_log( |
|
| 120 | + "Version anterieure: $version_installee. Courante: " . $GLOBALS['spip_version_base'], |
|
| 121 | + 'maj.' . _LOG_INFO_IMPORTANTE |
|
| 122 | + ); |
|
| 123 | + if (!$version_installee or ($GLOBALS['spip_version_base'] < $version_installee)) { |
|
| 124 | + sql_replace( |
|
| 125 | + 'spip_meta', |
|
| 126 | + [ |
|
| 127 | + 'nom' => 'version_installee', |
|
| 128 | + 'valeur' => $GLOBALS['spip_version_base'], |
|
| 129 | + 'impt' => 'non' |
|
| 130 | + ] |
|
| 131 | + ); |
|
| 132 | + return false; |
|
| 133 | + } |
|
| 134 | + if (!upgrade_test()) { |
|
| 135 | + return true; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + $cible = ($version_cible ?: $GLOBALS['spip_version_base']); |
|
| 139 | + |
|
| 140 | + if ($version_installee < 2021_01_01_00) { |
|
| 141 | + include_spip('maj/legacy/v21'); |
|
| 142 | + include_spip('maj/legacy/v30'); |
|
| 143 | + include_spip('maj/legacy/v31'); |
|
| 144 | + include_spip('maj/legacy/v32'); |
|
| 145 | + include_spip('maj/legacy/v40'); |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + include_spip('maj/2021'); |
|
| 149 | + |
|
| 150 | + ksort($GLOBALS['maj']); |
|
| 151 | + $res = maj_while($version_installee, $cible, $GLOBALS['maj'], 'version_installee', 'meta', $redirect, $debut_page); |
|
| 152 | + if ($res) { |
|
| 153 | + if (!is_array($res)) { |
|
| 154 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 155 | + } else { |
|
| 156 | + echo _T('avis_operation_echec') . ' ' . join(' ', $res); |
|
| 157 | + echo install_fin_html(); |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + return $res; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -200,53 +200,53 @@ discard block |
||
| 200 | 200 | */ |
| 201 | 201 | function maj_plugin($nom_meta_base_version, $version_cible, $maj, $table_meta = 'meta') { |
| 202 | 202 | |
| 203 | - if ($table_meta !== 'meta') { |
|
| 204 | - installer_table_meta($table_meta); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $current_version = null; |
|
| 208 | - |
|
| 209 | - if ( |
|
| 210 | - (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 211 | - || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 212 | - ) { |
|
| 213 | - // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 214 | - // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 215 | - if (isset($maj['create'])) { |
|
| 216 | - if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 217 | - // installation : on ne fait que l'operation create |
|
| 218 | - $maj = ['init' => $maj['create']]; |
|
| 219 | - // et on lui ajoute un appel a inc/config |
|
| 220 | - // pour creer les metas par defaut |
|
| 221 | - $config = charger_fonction('config', 'inc'); |
|
| 222 | - $maj[$version_cible] = [[$config]]; |
|
| 223 | - } |
|
| 224 | - // dans tous les cas enlever cet index du tableau |
|
| 225 | - unset($maj['create']); |
|
| 226 | - } |
|
| 227 | - // si init, deja dans le bon ordre |
|
| 228 | - if (!isset($maj['init'])) { |
|
| 229 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 230 | - uksort($maj, 'spip_version_compare'); |
|
| 231 | - } |
|
| 232 | - |
|
| 233 | - // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 234 | - // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 235 | - // ou define _REDIRECT_MAJ_PLUGIN |
|
| 236 | - $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 237 | - if (defined('_ECRIRE_INSTALL')) { |
|
| 238 | - $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 239 | - } |
|
| 240 | - |
|
| 241 | - $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 242 | - if ($res) { |
|
| 243 | - if (!is_array($res)) { |
|
| 244 | - spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 245 | - } else { |
|
| 246 | - echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 247 | - } |
|
| 248 | - } |
|
| 249 | - } |
|
| 203 | + if ($table_meta !== 'meta') { |
|
| 204 | + installer_table_meta($table_meta); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $current_version = null; |
|
| 208 | + |
|
| 209 | + if ( |
|
| 210 | + (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) |
|
| 211 | + || (!spip_version_compare($current_version = $GLOBALS[$table_meta][$nom_meta_base_version], $version_cible, '=')) |
|
| 212 | + ) { |
|
| 213 | + // $maj['create'] contient les directives propres a la premiere creation de base |
|
| 214 | + // c'est une operation derogatoire qui fait aboutir directement dans la version_cible |
|
| 215 | + if (isset($maj['create'])) { |
|
| 216 | + if (!isset($GLOBALS[$table_meta][$nom_meta_base_version])) { |
|
| 217 | + // installation : on ne fait que l'operation create |
|
| 218 | + $maj = ['init' => $maj['create']]; |
|
| 219 | + // et on lui ajoute un appel a inc/config |
|
| 220 | + // pour creer les metas par defaut |
|
| 221 | + $config = charger_fonction('config', 'inc'); |
|
| 222 | + $maj[$version_cible] = [[$config]]; |
|
| 223 | + } |
|
| 224 | + // dans tous les cas enlever cet index du tableau |
|
| 225 | + unset($maj['create']); |
|
| 226 | + } |
|
| 227 | + // si init, deja dans le bon ordre |
|
| 228 | + if (!isset($maj['init'])) { |
|
| 229 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 230 | + uksort($maj, 'spip_version_compare'); |
|
| 231 | + } |
|
| 232 | + |
|
| 233 | + // la redirection se fait par defaut sur la page d'administration des plugins |
|
| 234 | + // sauf lorsque nous sommes sur l'installation de SPIP |
|
| 235 | + // ou define _REDIRECT_MAJ_PLUGIN |
|
| 236 | + $redirect = (defined('_REDIRECT_MAJ_PLUGIN') ? _REDIRECT_MAJ_PLUGIN : generer_url_ecrire('admin_plugin')); |
|
| 237 | + if (defined('_ECRIRE_INSTALL')) { |
|
| 238 | + $redirect = parametre_url(generer_url_ecrire('install'), 'etape', _request('etape')); |
|
| 239 | + } |
|
| 240 | + |
|
| 241 | + $res = maj_while($current_version, $version_cible, $maj, $nom_meta_base_version, $table_meta, $redirect); |
|
| 242 | + if ($res) { |
|
| 243 | + if (!is_array($res)) { |
|
| 244 | + spip_log("Pb d'acces SQL a la mise a jour", 'maj.' . _LOG_ERREUR); |
|
| 245 | + } else { |
|
| 246 | + echo '<p>' . _T('avis_operation_echec') . ' ' . join(' ', $res) . '</p>'; |
|
| 247 | + } |
|
| 248 | + } |
|
| 249 | + } |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | /** |
@@ -263,17 +263,17 @@ discard block |
||
| 263 | 263 | * @return void |
| 264 | 264 | */ |
| 265 | 265 | function relance_maj($meta, $table, $redirect = '') { |
| 266 | - include_spip('inc/headers'); |
|
| 267 | - if (!$redirect) { |
|
| 268 | - // recuperer la valeur installee en cours |
|
| 269 | - // on la tronque numeriquement, elle ne sert pas reellement |
|
| 270 | - // sauf pour verifier que ce n'est pas oui ou non |
|
| 271 | - // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 272 | - $installee = intval($GLOBALS[$table][$meta]); |
|
| 273 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 274 | - } |
|
| 275 | - echo redirige_formulaire($redirect); |
|
| 276 | - exit(); |
|
| 266 | + include_spip('inc/headers'); |
|
| 267 | + if (!$redirect) { |
|
| 268 | + // recuperer la valeur installee en cours |
|
| 269 | + // on la tronque numeriquement, elle ne sert pas reellement |
|
| 270 | + // sauf pour verifier que ce n'est pas oui ou non |
|
| 271 | + // sinon is_numeric va echouer sur un numero de version 1.2.3 |
|
| 272 | + $installee = intval($GLOBALS[$table][$meta]); |
|
| 273 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 274 | + } |
|
| 275 | + echo redirige_formulaire($redirect); |
|
| 276 | + exit(); |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -286,28 +286,28 @@ discard block |
||
| 286 | 286 | * @return void |
| 287 | 287 | */ |
| 288 | 288 | function maj_debut_page($installee, $meta, $table) { |
| 289 | - static $done = false; |
|
| 290 | - if ($done) { |
|
| 291 | - return; |
|
| 292 | - } |
|
| 293 | - include_spip('inc/minipres'); |
|
| 294 | - if (function_exists('ini_set')) { |
|
| 295 | - @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | - } |
|
| 297 | - $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | - $titre = _T('titre_page_upgrade'); |
|
| 299 | - $balise_img = charger_filtre('balise_img'); |
|
| 300 | - $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | - echo(install_debut_html($titre)); |
|
| 302 | - // script de rechargement auto sur timeout |
|
| 303 | - $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | - echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | - echo "<div style='text-align: left'>\n"; |
|
| 306 | - if (ob_get_level()) { |
|
| 307 | - ob_flush(); |
|
| 308 | - } |
|
| 309 | - flush(); |
|
| 310 | - $done = true; |
|
| 289 | + static $done = false; |
|
| 290 | + if ($done) { |
|
| 291 | + return; |
|
| 292 | + } |
|
| 293 | + include_spip('inc/minipres'); |
|
| 294 | + if (function_exists('ini_set')) { |
|
| 295 | + @ini_set('zlib.output_compression', '0'); // pour permettre l'affichage au fur et a mesure |
|
| 296 | + } |
|
| 297 | + $timeout = _UPGRADE_TIME_OUT * 2; |
|
| 298 | + $titre = _T('titre_page_upgrade'); |
|
| 299 | + $balise_img = charger_filtre('balise_img'); |
|
| 300 | + $titre .= $balise_img(chemin_image('loader.svg'), '', 'loader'); |
|
| 301 | + echo(install_debut_html($titre)); |
|
| 302 | + // script de rechargement auto sur timeout |
|
| 303 | + $redirect = generer_url_ecrire('upgrade', "reinstall=$installee&meta=$meta&table=$table", true); |
|
| 304 | + echo http_script("window.setTimeout('location.href=\"" . $redirect . "\";'," . ($timeout * 1000) . ')'); |
|
| 305 | + echo "<div style='text-align: left'>\n"; |
|
| 306 | + if (ob_get_level()) { |
|
| 307 | + ob_flush(); |
|
| 308 | + } |
|
| 309 | + flush(); |
|
| 310 | + $done = true; |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | |
@@ -351,64 +351,64 @@ discard block |
||
| 351 | 351 | * - tableau vide sinon. |
| 352 | 352 | */ |
| 353 | 353 | function maj_while($installee, $cible, $maj, $meta = '', $table = 'meta', $redirect = '', $debut_page = false) { |
| 354 | - # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | - include_spip('base/create'); |
|
| 356 | - include_spip('base/abstract_sql'); |
|
| 357 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | - include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | - $n = 0; |
|
| 360 | - $time = time(); |
|
| 361 | - |
|
| 362 | - if (!defined('_TIME_OUT')) { |
|
| 363 | - /** |
|
| 364 | - * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | - * de mises à jour qui durent trop longtemps |
|
| 366 | - * |
|
| 367 | - * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | - * |
|
| 369 | - * @var int |
|
| 370 | - */ |
|
| 371 | - define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - foreach ($maj as $v => $operations) { |
|
| 375 | - // si une maj pour cette version |
|
| 376 | - if ( |
|
| 377 | - $v == 'init' or |
|
| 378 | - (spip_version_compare($v, $installee, '>') |
|
| 379 | - and spip_version_compare($v, $cible, '<=')) |
|
| 380 | - ) { |
|
| 381 | - if ($debut_page) { |
|
| 382 | - maj_debut_page($v, $meta, $table); |
|
| 383 | - } |
|
| 384 | - echo "MAJ $v"; |
|
| 385 | - $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 386 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 387 | - # echec sur une etape en cours ? |
|
| 388 | - # on sort |
|
| 389 | - if ($etape) { |
|
| 390 | - return [$v, $etape]; |
|
| 391 | - } |
|
| 392 | - $n = time() - $time; |
|
| 393 | - spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 394 | - if ($meta) { |
|
| 395 | - ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 396 | - } |
|
| 397 | - echo (_IS_CLI ? "\n" : '<br />'); |
|
| 398 | - } |
|
| 399 | - if (time() >= _TIME_OUT) { |
|
| 400 | - relance_maj($meta, $table, $redirect); |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - $trouver_table(''); // vider le cache des descriptions de table |
|
| 404 | - // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 405 | - // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 406 | - if ($meta) { |
|
| 407 | - ecrire_meta($meta, $cible, 'oui', $table); |
|
| 408 | - } |
|
| 409 | - spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 410 | - |
|
| 411 | - return []; |
|
| 354 | + # inclusions pour que les procedures d'upgrade disposent des fonctions de base |
|
| 355 | + include_spip('base/create'); |
|
| 356 | + include_spip('base/abstract_sql'); |
|
| 357 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 358 | + include_spip('inc/plugin'); // pour spip_version_compare |
|
| 359 | + $n = 0; |
|
| 360 | + $time = time(); |
|
| 361 | + |
|
| 362 | + if (!defined('_TIME_OUT')) { |
|
| 363 | + /** |
|
| 364 | + * Définir le timeout qui peut-être utilisé dans les fonctions |
|
| 365 | + * de mises à jour qui durent trop longtemps |
|
| 366 | + * |
|
| 367 | + * À utiliser tel que : `if (time() >= _TIME_OUT)` |
|
| 368 | + * |
|
| 369 | + * @var int |
|
| 370 | + */ |
|
| 371 | + define('_TIME_OUT', $time + _UPGRADE_TIME_OUT); |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + foreach ($maj as $v => $operations) { |
|
| 375 | + // si une maj pour cette version |
|
| 376 | + if ( |
|
| 377 | + $v == 'init' or |
|
| 378 | + (spip_version_compare($v, $installee, '>') |
|
| 379 | + and spip_version_compare($v, $cible, '<=')) |
|
| 380 | + ) { |
|
| 381 | + if ($debut_page) { |
|
| 382 | + maj_debut_page($v, $meta, $table); |
|
| 383 | + } |
|
| 384 | + echo "MAJ $v"; |
|
| 385 | + $etape = serie_alter($v, $operations, $meta, $table, $redirect); |
|
| 386 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 387 | + # echec sur une etape en cours ? |
|
| 388 | + # on sort |
|
| 389 | + if ($etape) { |
|
| 390 | + return [$v, $etape]; |
|
| 391 | + } |
|
| 392 | + $n = time() - $time; |
|
| 393 | + spip_log("$table $meta: $v en $n secondes", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 394 | + if ($meta) { |
|
| 395 | + ecrire_meta($meta, $installee = $v, 'oui', $table); |
|
| 396 | + } |
|
| 397 | + echo (_IS_CLI ? "\n" : '<br />'); |
|
| 398 | + } |
|
| 399 | + if (time() >= _TIME_OUT) { |
|
| 400 | + relance_maj($meta, $table, $redirect); |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + $trouver_table(''); // vider le cache des descriptions de table |
|
| 404 | + // indispensable pour les chgt de versions qui n'ecrivent pas en base |
|
| 405 | + // tant pis pour la redondance eventuelle avec ci-dessus |
|
| 406 | + if ($meta) { |
|
| 407 | + ecrire_meta($meta, $cible, 'oui', $table); |
|
| 408 | + } |
|
| 409 | + spip_log("MAJ terminee. $meta: $installee", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 410 | + |
|
| 411 | + return []; |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | /** |
@@ -431,53 +431,53 @@ discard block |
||
| 431 | 431 | * @return int |
| 432 | 432 | */ |
| 433 | 433 | function serie_alter($serie, $q = [], $meta = '', $table = 'meta', $redirect = '') { |
| 434 | - $meta2 = $meta . '_maj_' . $serie; |
|
| 435 | - $etape = 0; |
|
| 436 | - if (isset($GLOBALS[$table][$meta2])) { |
|
| 437 | - $etape = intval($GLOBALS[$table][$meta2]); |
|
| 438 | - } |
|
| 439 | - foreach ($q as $i => $r) { |
|
| 440 | - if ($i >= $etape) { |
|
| 441 | - $msg = "maj $table $meta2 etape $i"; |
|
| 442 | - if ( |
|
| 443 | - is_array($r) |
|
| 444 | - and function_exists($f = array_shift($r)) |
|
| 445 | - ) { |
|
| 446 | - // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 447 | - spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | - // pour les fonctions atomiques sql_xx |
|
| 449 | - // on enregistre le meta avant de lancer la fonction, |
|
| 450 | - // de maniere a eviter de boucler sur timeout |
|
| 451 | - // mais pour les fonctions complexes, |
|
| 452 | - // il faut les rejouer jusqu'a achevement. |
|
| 453 | - // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 454 | - if (strncmp($f, 'sql_', 4) == 0) { |
|
| 455 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 456 | - } |
|
| 457 | - echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 458 | - $f(...$r); |
|
| 459 | - // si temps imparti depasse, on relance sans ecrire en meta |
|
| 460 | - // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 461 | - if (time() >= _TIME_OUT) { |
|
| 462 | - relance_maj($meta, $table, $redirect); |
|
| 463 | - } |
|
| 464 | - ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 465 | - spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 466 | - } else { |
|
| 467 | - if (!is_array($r)) { |
|
| 468 | - spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 469 | - } else { |
|
| 470 | - spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 471 | - } |
|
| 472 | - // en cas d'erreur serieuse, on s'arrete |
|
| 473 | - // mais on permet de passer par dessus en rechargeant la page. |
|
| 474 | - return $i + 1; |
|
| 475 | - } |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - effacer_meta($meta2, $table); |
|
| 479 | - |
|
| 480 | - return 0; |
|
| 434 | + $meta2 = $meta . '_maj_' . $serie; |
|
| 435 | + $etape = 0; |
|
| 436 | + if (isset($GLOBALS[$table][$meta2])) { |
|
| 437 | + $etape = intval($GLOBALS[$table][$meta2]); |
|
| 438 | + } |
|
| 439 | + foreach ($q as $i => $r) { |
|
| 440 | + if ($i >= $etape) { |
|
| 441 | + $msg = "maj $table $meta2 etape $i"; |
|
| 442 | + if ( |
|
| 443 | + is_array($r) |
|
| 444 | + and function_exists($f = array_shift($r)) |
|
| 445 | + ) { |
|
| 446 | + // note: $r (arguments de la fonction $f) peut avoir des données tabulaires |
|
| 447 | + spip_log("$msg: $f " . @join(',', $r), 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 448 | + // pour les fonctions atomiques sql_xx |
|
| 449 | + // on enregistre le meta avant de lancer la fonction, |
|
| 450 | + // de maniere a eviter de boucler sur timeout |
|
| 451 | + // mais pour les fonctions complexes, |
|
| 452 | + // il faut les rejouer jusqu'a achevement. |
|
| 453 | + // C'est a elle d'assurer qu'elles progressent a chaque rappel |
|
| 454 | + if (strncmp($f, 'sql_', 4) == 0) { |
|
| 455 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 456 | + } |
|
| 457 | + echo (_IS_CLI ? '.' : " <span title='$i'>.</span>"); |
|
| 458 | + $f(...$r); |
|
| 459 | + // si temps imparti depasse, on relance sans ecrire en meta |
|
| 460 | + // car on est peut etre sorti sur timeout si c'est une fonction longue |
|
| 461 | + if (time() >= _TIME_OUT) { |
|
| 462 | + relance_maj($meta, $table, $redirect); |
|
| 463 | + } |
|
| 464 | + ecrire_meta($meta2, $i + 1, 'non', $table); |
|
| 465 | + spip_log("$meta2: ok", 'maj.' . _LOG_INFO_IMPORTANTE); |
|
| 466 | + } else { |
|
| 467 | + if (!is_array($r)) { |
|
| 468 | + spip_log("maj $i format incorrect", 'maj.' . _LOG_ERREUR); |
|
| 469 | + } else { |
|
| 470 | + spip_log("maj $i fonction $f non definie", 'maj.' . _LOG_ERREUR); |
|
| 471 | + } |
|
| 472 | + // en cas d'erreur serieuse, on s'arrete |
|
| 473 | + // mais on permet de passer par dessus en rechargeant la page. |
|
| 474 | + return $i + 1; |
|
| 475 | + } |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + effacer_meta($meta2, $table); |
|
| 479 | + |
|
| 480 | + return 0; |
|
| 481 | 481 | } |
| 482 | 482 | |
| 483 | 483 | /** |
@@ -486,16 +486,16 @@ discard block |
||
| 486 | 486 | * @return bool True si possible. |
| 487 | 487 | **/ |
| 488 | 488 | function upgrade_test() { |
| 489 | - sql_drop_table('spip_test', true); |
|
| 490 | - sql_create('spip_test', ['a' => 'int']); |
|
| 491 | - sql_alter('TABLE spip_test ADD b INT'); |
|
| 492 | - sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 493 | - $result = sql_select('b', 'spip_test'); |
|
| 494 | - // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 495 | - // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 496 | - // car cette table serait alors 'verouillee' |
|
| 497 | - $result = $result ? true : false; |
|
| 498 | - sql_alter('TABLE spip_test DROP b'); |
|
| 499 | - |
|
| 500 | - return $result; |
|
| 489 | + sql_drop_table('spip_test', true); |
|
| 490 | + sql_create('spip_test', ['a' => 'int']); |
|
| 491 | + sql_alter('TABLE spip_test ADD b INT'); |
|
| 492 | + sql_insertq('spip_test', ['b' => 1], ['field' => ['b' => 'int']]); |
|
| 493 | + $result = sql_select('b', 'spip_test'); |
|
| 494 | + // ne pas garder le resultat de la requete sinon sqlite3 |
|
| 495 | + // ne peut pas supprimer la table spip_test lors du sql_alter qui suit |
|
| 496 | + // car cette table serait alors 'verouillee' |
|
| 497 | + $result = $result ? true : false; |
|
| 498 | + sql_alter('TABLE spip_test DROP b'); |
|
| 499 | + |
|
| 500 | + return $result; |
|
| 501 | 501 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Minipres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/headers'); |
@@ -46,61 +46,61 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 48 | 48 | |
| 49 | - utiliser_langue_visiteur(); |
|
| 50 | - |
|
| 51 | - http_no_cache(); |
|
| 52 | - |
|
| 53 | - if ($titre == 'AUTO') { |
|
| 54 | - $titre = _T('info_installation_systeme_publication'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | - # lors de l'installation |
|
| 59 | - if (!headers_sent()) { |
|
| 60 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $css = ''; |
|
| 64 | - $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | - if ($all_inline) { |
|
| 66 | - // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | - foreach ($files as $name) { |
|
| 68 | - $file = direction_css(find_in_theme($name)); |
|
| 69 | - if (function_exists('minifier')) { |
|
| 70 | - $file = minifier($file); |
|
| 71 | - } else { |
|
| 72 | - $file = url_absolue_css($file); // precaution |
|
| 73 | - } |
|
| 74 | - lire_fichier($file, $c); |
|
| 75 | - $css .= $c; |
|
| 76 | - } |
|
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | - } else { |
|
| 79 | - foreach ($files as $name) { |
|
| 80 | - $file = direction_css(find_in_theme($name)); |
|
| 81 | - $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | - define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return _DOCTYPE_ECRIRE . |
|
| 91 | - html_lang_attributes() . |
|
| 92 | - "<head>\n" . |
|
| 93 | - '<title>' . |
|
| 94 | - textebrut($titre) . |
|
| 95 | - "</title>\n" . |
|
| 96 | - "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | - $css . |
|
| 98 | - '</head> |
|
| 49 | + utiliser_langue_visiteur(); |
|
| 50 | + |
|
| 51 | + http_no_cache(); |
|
| 52 | + |
|
| 53 | + if ($titre == 'AUTO') { |
|
| 54 | + $titre = _T('info_installation_systeme_publication'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | + # lors de l'installation |
|
| 59 | + if (!headers_sent()) { |
|
| 60 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $css = ''; |
|
| 64 | + $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | + if ($all_inline) { |
|
| 66 | + // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | + foreach ($files as $name) { |
|
| 68 | + $file = direction_css(find_in_theme($name)); |
|
| 69 | + if (function_exists('minifier')) { |
|
| 70 | + $file = minifier($file); |
|
| 71 | + } else { |
|
| 72 | + $file = url_absolue_css($file); // precaution |
|
| 73 | + } |
|
| 74 | + lire_fichier($file, $c); |
|
| 75 | + $css .= $c; |
|
| 76 | + } |
|
| 77 | + $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | + } else { |
|
| 79 | + foreach ($files as $name) { |
|
| 80 | + $file = direction_css(find_in_theme($name)); |
|
| 81 | + $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | + define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return _DOCTYPE_ECRIRE . |
|
| 91 | + html_lang_attributes() . |
|
| 92 | + "<head>\n" . |
|
| 93 | + '<title>' . |
|
| 94 | + textebrut($titre) . |
|
| 95 | + "</title>\n" . |
|
| 96 | + "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | + $css . |
|
| 98 | + '</head> |
|
| 99 | 99 | <body' . $onLoad . " class='minipres'> |
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 103 | - "</h1> |
|
| 102 | + $titre . |
|
| 103 | + "</h1> |
|
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string Code HTML |
| 111 | 111 | */ |
| 112 | 112 | function install_fin_html() { |
| 113 | - return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 113 | + return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -148,88 +148,88 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function minipres($titre = '', $corps = '', $options = []) { |
| 150 | 150 | |
| 151 | - // compat signature old |
|
| 152 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | - $args = func_get_args(); |
|
| 154 | - if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | - $options = ['onload' => $args[2]]; |
|
| 156 | - } |
|
| 157 | - if (isset($args[3])) { |
|
| 158 | - $options['all_inline'] = $args[3]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $options = array_merge([ |
|
| 162 | - 'onload' => '', |
|
| 163 | - 'all_inline' => false, |
|
| 164 | - ], $options); |
|
| 165 | - |
|
| 166 | - if (!defined('_AJAX')) { |
|
| 167 | - define('_AJAX', false); |
|
| 168 | - } // par securite |
|
| 169 | - if (!$titre) { |
|
| 170 | - if (!isset($options['status'])) { |
|
| 171 | - $options['status'] = 403; |
|
| 172 | - } |
|
| 173 | - if ( |
|
| 174 | - !$titre = _request('action') |
|
| 175 | - and !$titre = _request('exec') |
|
| 176 | - and !$titre = _request('page') |
|
| 177 | - ) { |
|
| 178 | - $titre = '?'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $titre = spip_htmlspecialchars($titre); |
|
| 182 | - |
|
| 183 | - $titre = ($titre == 'install') |
|
| 184 | - ? _T('avis_espace_interdit') |
|
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | - |
|
| 187 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | - |
|
| 190 | - if ($statut != '0minirezo') { |
|
| 191 | - $titre = _T('info_acces_interdit'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($statut and test_espace_prive()) { |
|
| 195 | - $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | - $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | - } |
|
| 200 | - else { |
|
| 201 | - $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | - } |
|
| 203 | - $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (!_AJAX) { |
|
| 208 | - if (isset($options['status'])) { |
|
| 209 | - http_response_code($options['status']); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | - . $corps |
|
| 214 | - . install_fin_html(); |
|
| 215 | - |
|
| 216 | - if ( |
|
| 217 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | - and empty($options['all_inline']) |
|
| 219 | - ) { |
|
| 220 | - define('_SET_HTML_BASE', true); |
|
| 221 | - include_spip('public/assembler'); |
|
| 222 | - $GLOBALS['html'] = true; |
|
| 223 | - page_base_href($html); |
|
| 224 | - } |
|
| 225 | - return $html; |
|
| 226 | - } else { |
|
| 227 | - include_spip('inc/headers'); |
|
| 228 | - include_spip('inc/actions'); |
|
| 229 | - $url = self('&', true); |
|
| 230 | - foreach ($_POST as $v => $c) { |
|
| 231 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | - } |
|
| 233 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | - } |
|
| 151 | + // compat signature old |
|
| 152 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | + $args = func_get_args(); |
|
| 154 | + if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | + $options = ['onload' => $args[2]]; |
|
| 156 | + } |
|
| 157 | + if (isset($args[3])) { |
|
| 158 | + $options['all_inline'] = $args[3]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $options = array_merge([ |
|
| 162 | + 'onload' => '', |
|
| 163 | + 'all_inline' => false, |
|
| 164 | + ], $options); |
|
| 165 | + |
|
| 166 | + if (!defined('_AJAX')) { |
|
| 167 | + define('_AJAX', false); |
|
| 168 | + } // par securite |
|
| 169 | + if (!$titre) { |
|
| 170 | + if (!isset($options['status'])) { |
|
| 171 | + $options['status'] = 403; |
|
| 172 | + } |
|
| 173 | + if ( |
|
| 174 | + !$titre = _request('action') |
|
| 175 | + and !$titre = _request('exec') |
|
| 176 | + and !$titre = _request('page') |
|
| 177 | + ) { |
|
| 178 | + $titre = '?'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $titre = spip_htmlspecialchars($titre); |
|
| 182 | + |
|
| 183 | + $titre = ($titre == 'install') |
|
| 184 | + ? _T('avis_espace_interdit') |
|
| 185 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | + |
|
| 187 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | + |
|
| 190 | + if ($statut != '0minirezo') { |
|
| 191 | + $titre = _T('info_acces_interdit'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($statut and test_espace_prive()) { |
|
| 195 | + $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | + } |
|
| 197 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | + $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | + } |
|
| 200 | + else { |
|
| 201 | + $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | + } |
|
| 203 | + $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (!_AJAX) { |
|
| 208 | + if (isset($options['status'])) { |
|
| 209 | + http_response_code($options['status']); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | + . $corps |
|
| 214 | + . install_fin_html(); |
|
| 215 | + |
|
| 216 | + if ( |
|
| 217 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | + and empty($options['all_inline']) |
|
| 219 | + ) { |
|
| 220 | + define('_SET_HTML_BASE', true); |
|
| 221 | + include_spip('public/assembler'); |
|
| 222 | + $GLOBALS['html'] = true; |
|
| 223 | + page_base_href($html); |
|
| 224 | + } |
|
| 225 | + return $html; |
|
| 226 | + } else { |
|
| 227 | + include_spip('inc/headers'); |
|
| 228 | + include_spip('inc/actions'); |
|
| 229 | + $url = self('&', true); |
|
| 230 | + foreach ($_POST as $v => $c) { |
|
| 231 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | + } |
|
| 233 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -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 | /** |
@@ -30,12 +30,12 @@ discard block |
||
| 30 | 30 | * @return string |
| 31 | 31 | */ |
| 32 | 32 | function set_spip_doc(?string $fichier): string { |
| 33 | - if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | - return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | - } else { |
|
| 36 | - // ex: fichier distant |
|
| 37 | - return $fichier ?? ''; |
|
| 38 | - } |
|
| 33 | + if ($fichier and strpos($fichier, (string) _DIR_IMG) === 0) { |
|
| 34 | + return substr($fichier, strlen(_DIR_IMG)); |
|
| 35 | + } else { |
|
| 36 | + // ex: fichier distant |
|
| 37 | + return $fichier ?? ''; |
|
| 38 | + } |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | /** |
@@ -47,26 +47,26 @@ discard block |
||
| 47 | 47 | * @return bool|string |
| 48 | 48 | */ |
| 49 | 49 | function get_spip_doc(?string $fichier) { |
| 50 | - if ($fichier === null) { |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - |
|
| 54 | - // fichier distant |
|
| 55 | - if (tester_url_absolue($fichier)) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - |
|
| 59 | - // gestion d'erreurs, fichier='' |
|
| 60 | - if (!strlen($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | - $fichier = _DIR_IMG . $fichier; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // fichier normal |
|
| 69 | - return $fichier; |
|
| 50 | + if ($fichier === null) { |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + |
|
| 54 | + // fichier distant |
|
| 55 | + if (tester_url_absolue($fichier)) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + |
|
| 59 | + // gestion d'erreurs, fichier='' |
|
| 60 | + if (!strlen($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + if (strncmp($fichier, _DIR_IMG, strlen(_DIR_IMG)) !== 0) { |
|
| 65 | + $fichier = _DIR_IMG . $fichier; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // fichier normal |
|
| 69 | + return $fichier; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -80,26 +80,26 @@ discard block |
||
| 80 | 80 | * @return string |
| 81 | 81 | */ |
| 82 | 82 | function creer_repertoire_documents($ext) { |
| 83 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | - |
|
| 85 | - if (!$ext or !$rep) { |
|
| 86 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | - exit; |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | - // par exemple acces_restreint |
|
| 92 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | - if ( |
|
| 94 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | - and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | - and $ext !== 'logo' |
|
| 97 | - ) { |
|
| 98 | - include_spip('inc/acces'); |
|
| 99 | - verifier_htaccess($rep); |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - return $rep; |
|
| 83 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 84 | + |
|
| 85 | + if (!$ext or !$rep) { |
|
| 86 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 87 | + exit; |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 91 | + // par exemple acces_restreint |
|
| 92 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 93 | + if ( |
|
| 94 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 95 | + and $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 96 | + and $ext !== 'logo' |
|
| 97 | + ) { |
|
| 98 | + include_spip('inc/acces'); |
|
| 99 | + verifier_htaccess($rep); |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + return $rep; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -108,22 +108,22 @@ discard block |
||
| 108 | 108 | * @param string $nom |
| 109 | 109 | */ |
| 110 | 110 | function effacer_repertoire_temporaire($nom) { |
| 111 | - if ($d = opendir($nom)) { |
|
| 112 | - while (($f = readdir($d)) !== false) { |
|
| 113 | - if (is_file("$nom/$f")) { |
|
| 114 | - spip_unlink("$nom/$f"); |
|
| 115 | - } else { |
|
| 116 | - if ( |
|
| 117 | - $f <> '.' and $f <> '..' |
|
| 118 | - and is_dir("$nom/$f") |
|
| 119 | - ) { |
|
| 120 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - closedir($d); |
|
| 126 | - @rmdir($nom); |
|
| 111 | + if ($d = opendir($nom)) { |
|
| 112 | + while (($f = readdir($d)) !== false) { |
|
| 113 | + if (is_file("$nom/$f")) { |
|
| 114 | + spip_unlink("$nom/$f"); |
|
| 115 | + } else { |
|
| 116 | + if ( |
|
| 117 | + $f <> '.' and $f <> '..' |
|
| 118 | + and is_dir("$nom/$f") |
|
| 119 | + ) { |
|
| 120 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + closedir($d); |
|
| 126 | + @rmdir($nom); |
|
| 127 | 127 | } |
| 128 | 128 | |
| 129 | 129 | // |
@@ -140,45 +140,45 @@ discard block |
||
| 140 | 140 | */ |
| 141 | 141 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 142 | 142 | |
| 143 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | - $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | - |
|
| 146 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | - $dest = translitteration($dest); |
|
| 149 | - $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | - |
|
| 151 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | - // pour les images transformees par rotation (action/documenter) |
|
| 153 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | - |
|
| 155 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | - if ( |
|
| 157 | - !function_exists('verifier_upload_autorise') |
|
| 158 | - or !$r = verifier_upload_autorise($dest) |
|
| 159 | - or $r['autozip'] |
|
| 160 | - ) { |
|
| 161 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | - break; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | - $ext = $m[1] . '.' . $ext; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | - return $source; |
|
| 173 | - } |
|
| 174 | - |
|
| 175 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | - $n = 0; |
|
| 177 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | - ; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - return deplacer_fichier_upload($source, $newFile); |
|
| 143 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 144 | + $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 145 | + |
|
| 146 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 147 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 148 | + $dest = translitteration($dest); |
|
| 149 | + $dest = preg_replace('/[^.=\w-]+/', '_', $dest); |
|
| 150 | + |
|
| 151 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 152 | + // pour les images transformees par rotation (action/documenter) |
|
| 153 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 154 | + |
|
| 155 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 156 | + if ( |
|
| 157 | + !function_exists('verifier_upload_autorise') |
|
| 158 | + or !$r = verifier_upload_autorise($dest) |
|
| 159 | + or $r['autozip'] |
|
| 160 | + ) { |
|
| 161 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 162 | + break; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 166 | + $ext = $m[1] . '.' . $ext; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 171 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 172 | + return $source; |
|
| 173 | + } |
|
| 174 | + |
|
| 175 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 176 | + $n = 0; |
|
| 177 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 178 | + ; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + return deplacer_fichier_upload($source, $newFile); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | /** |
@@ -193,28 +193,28 @@ discard block |
||
| 193 | 193 | * @return bool|string |
| 194 | 194 | */ |
| 195 | 195 | function determine_upload($type = '') { |
| 196 | - if (!function_exists('autoriser')) { |
|
| 197 | - include_spip('inc/autoriser'); |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - if ( |
|
| 201 | - !autoriser('chargerftp') |
|
| 202 | - or $type == 'logos' |
|
| 203 | - ) { # on ne le permet pas pour les logos |
|
| 204 | - return false; |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - $repertoire = _DIR_TRANSFERT; |
|
| 208 | - if (!@is_dir($repertoire)) { |
|
| 209 | - $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | - return $repertoire; |
|
| 215 | - } else { |
|
| 216 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | - } |
|
| 196 | + if (!function_exists('autoriser')) { |
|
| 197 | + include_spip('inc/autoriser'); |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + if ( |
|
| 201 | + !autoriser('chargerftp') |
|
| 202 | + or $type == 'logos' |
|
| 203 | + ) { # on ne le permet pas pour les logos |
|
| 204 | + return false; |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + $repertoire = _DIR_TRANSFERT; |
|
| 208 | + if (!@is_dir($repertoire)) { |
|
| 209 | + $repertoire = str_replace(_DIR_TMP, '', $repertoire); |
|
| 210 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 214 | + return $repertoire; |
|
| 215 | + } else { |
|
| 216 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 217 | + } |
|
| 218 | 218 | } |
| 219 | 219 | |
| 220 | 220 | /** |
@@ -233,35 +233,35 @@ discard block |
||
| 233 | 233 | * @return bool|mixed|string |
| 234 | 234 | */ |
| 235 | 235 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 236 | - // Securite |
|
| 237 | - if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | - } else { |
|
| 240 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | - } |
|
| 242 | - |
|
| 243 | - if ($move) { |
|
| 244 | - $ok = @rename($source, $dest); |
|
| 245 | - } else { |
|
| 246 | - $ok = @copy($source, $dest); |
|
| 247 | - } |
|
| 248 | - if (!$ok) { |
|
| 249 | - $ok = @move_uploaded_file($source, $dest); |
|
| 250 | - } |
|
| 251 | - if ($ok) { |
|
| 252 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | - } else { |
|
| 254 | - $f = @fopen($dest, 'w'); |
|
| 255 | - if ($f) { |
|
| 256 | - fclose($f); |
|
| 257 | - } else { |
|
| 258 | - include_spip('inc/flock'); |
|
| 259 | - raler_fichier($dest); |
|
| 260 | - } |
|
| 261 | - spip_unlink($dest); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - return $ok ? $dest : false; |
|
| 236 | + // Securite |
|
| 237 | + if (substr($dest, 0, strlen(_DIR_RACINE)) == _DIR_RACINE) { |
|
| 238 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen(_DIR_RACINE))); |
|
| 239 | + } else { |
|
| 240 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 241 | + } |
|
| 242 | + |
|
| 243 | + if ($move) { |
|
| 244 | + $ok = @rename($source, $dest); |
|
| 245 | + } else { |
|
| 246 | + $ok = @copy($source, $dest); |
|
| 247 | + } |
|
| 248 | + if (!$ok) { |
|
| 249 | + $ok = @move_uploaded_file($source, $dest); |
|
| 250 | + } |
|
| 251 | + if ($ok) { |
|
| 252 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 253 | + } else { |
|
| 254 | + $f = @fopen($dest, 'w'); |
|
| 255 | + if ($f) { |
|
| 256 | + fclose($f); |
|
| 257 | + } else { |
|
| 258 | + include_spip('inc/flock'); |
|
| 259 | + raler_fichier($dest); |
|
| 260 | + } |
|
| 261 | + spip_unlink($dest); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + return $ok ? $dest : false; |
|
| 265 | 265 | } |
| 266 | 266 | |
| 267 | 267 | |
@@ -285,60 +285,60 @@ discard block |
||
| 285 | 285 | */ |
| 286 | 286 | function check_upload_error($error, $msg = '', $return = false) { |
| 287 | 287 | |
| 288 | - if (!$error) { |
|
| 289 | - return false; |
|
| 290 | - } |
|
| 291 | - |
|
| 292 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | - |
|
| 294 | - switch ($error) { |
|
| 295 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | - return true; |
|
| 297 | - |
|
| 298 | - # on peut affiner les differents messages d'erreur |
|
| 299 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | - $msg = _T( |
|
| 301 | - 'upload_limit', |
|
| 302 | - ['max' => ini_get('upload_max_filesize')] |
|
| 303 | - ); |
|
| 304 | - break; |
|
| 305 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | - $msg = _T( |
|
| 307 | - 'upload_limit', |
|
| 308 | - ['max' => ini_get('upload_max_filesize')] |
|
| 309 | - ); |
|
| 310 | - break; |
|
| 311 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | - $msg = _T( |
|
| 313 | - 'upload_limit', |
|
| 314 | - ['max' => ini_get('upload_max_filesize')] |
|
| 315 | - ); |
|
| 316 | - break; |
|
| 317 | - |
|
| 318 | - default: /* autre */ |
|
| 319 | - if (!$msg) { |
|
| 320 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | - } |
|
| 323 | - break; |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - spip_log("erreur upload $error"); |
|
| 327 | - if ($return) { |
|
| 328 | - return $msg; |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - if (_request('iframe') == 'iframe') { |
|
| 332 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | - exit; |
|
| 334 | - } |
|
| 335 | - |
|
| 336 | - include_spip('inc/minipres'); |
|
| 337 | - echo minipres( |
|
| 338 | - $msg, |
|
| 339 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | - ); |
|
| 341 | - exit; |
|
| 288 | + if (!$error) { |
|
| 289 | + return false; |
|
| 290 | + } |
|
| 291 | + |
|
| 292 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 293 | + |
|
| 294 | + switch ($error) { |
|
| 295 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 296 | + return true; |
|
| 297 | + |
|
| 298 | + # on peut affiner les differents messages d'erreur |
|
| 299 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 300 | + $msg = _T( |
|
| 301 | + 'upload_limit', |
|
| 302 | + ['max' => ini_get('upload_max_filesize')] |
|
| 303 | + ); |
|
| 304 | + break; |
|
| 305 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 306 | + $msg = _T( |
|
| 307 | + 'upload_limit', |
|
| 308 | + ['max' => ini_get('upload_max_filesize')] |
|
| 309 | + ); |
|
| 310 | + break; |
|
| 311 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 312 | + $msg = _T( |
|
| 313 | + 'upload_limit', |
|
| 314 | + ['max' => ini_get('upload_max_filesize')] |
|
| 315 | + ); |
|
| 316 | + break; |
|
| 317 | + |
|
| 318 | + default: /* autre */ |
|
| 319 | + if (!$msg) { |
|
| 320 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 321 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 322 | + } |
|
| 323 | + break; |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + spip_log("erreur upload $error"); |
|
| 327 | + if ($return) { |
|
| 328 | + return $msg; |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + if (_request('iframe') == 'iframe') { |
|
| 332 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 333 | + exit; |
|
| 334 | + } |
|
| 335 | + |
|
| 336 | + include_spip('inc/minipres'); |
|
| 337 | + echo minipres( |
|
| 338 | + $msg, |
|
| 339 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode($GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 340 | + ); |
|
| 341 | + exit; |
|
| 342 | 342 | } |
| 343 | 343 | |
| 344 | 344 | /** |
@@ -355,24 +355,24 @@ discard block |
||
| 355 | 355 | * @return string |
| 356 | 356 | */ |
| 357 | 357 | function corriger_extension($ext) { |
| 358 | - $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | - switch ($ext) { |
|
| 360 | - case 'htm': |
|
| 361 | - $ext = 'html'; |
|
| 362 | - break; |
|
| 363 | - case 'jpeg': |
|
| 364 | - $ext = 'jpg'; |
|
| 365 | - break; |
|
| 366 | - case 'tiff': |
|
| 367 | - $ext = 'tif'; |
|
| 368 | - break; |
|
| 369 | - case 'aif': |
|
| 370 | - $ext = 'aiff'; |
|
| 371 | - break; |
|
| 372 | - case 'mpeg': |
|
| 373 | - $ext = 'mpg'; |
|
| 374 | - break; |
|
| 375 | - } |
|
| 376 | - |
|
| 377 | - return $ext; |
|
| 358 | + $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 359 | + switch ($ext) { |
|
| 360 | + case 'htm': |
|
| 361 | + $ext = 'html'; |
|
| 362 | + break; |
|
| 363 | + case 'jpeg': |
|
| 364 | + $ext = 'jpg'; |
|
| 365 | + break; |
|
| 366 | + case 'tiff': |
|
| 367 | + $ext = 'tif'; |
|
| 368 | + break; |
|
| 369 | + case 'aif': |
|
| 370 | + $ext = 'aiff'; |
|
| 371 | + break; |
|
| 372 | + case 'mpeg': |
|
| 373 | + $ext = 'mpg'; |
|
| 374 | + break; |
|
| 375 | + } |
|
| 376 | + |
|
| 377 | + return $ext; |
|
| 378 | 378 | } |
@@ -11,7 +11,7 @@ discard block |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | /** |
@@ -21,31 +21,31 @@ discard block |
||
| 21 | 21 | * @return array |
| 22 | 22 | */ |
| 23 | 23 | function plugins_extraire_boutons_dist($arbre) { |
| 24 | - $les_boutons = null; |
|
| 25 | - $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | - // recuperer les boutons et onglets si necessaire |
|
| 27 | - spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | - if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | - $ret['bouton'] = []; |
|
| 30 | - $ret['onglet'] = []; |
|
| 31 | - foreach ($les_boutons as $bouton => $val) { |
|
| 32 | - $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | - $type = reset($bouton); |
|
| 34 | - $bouton = end($bouton); |
|
| 35 | - if (isset($bouton['id'])) { |
|
| 36 | - $id = $bouton['id']; |
|
| 37 | - $val = reset($val); |
|
| 38 | - if (is_array($val)) { |
|
| 39 | - $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | - $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | - $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | - $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | - $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | - $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 24 | + $les_boutons = null; |
|
| 25 | + $ret = ['bouton' => [], 'onglet' => []]; |
|
| 26 | + // recuperer les boutons et onglets si necessaire |
|
| 27 | + spip_xml_match_nodes(',^(bouton|onglet)\s,', $arbre, $les_boutons); |
|
| 28 | + if (is_array($les_boutons) && count($les_boutons)) { |
|
| 29 | + $ret['bouton'] = []; |
|
| 30 | + $ret['onglet'] = []; |
|
| 31 | + foreach ($les_boutons as $bouton => $val) { |
|
| 32 | + $bouton = spip_xml_decompose_tag($bouton); |
|
| 33 | + $type = reset($bouton); |
|
| 34 | + $bouton = end($bouton); |
|
| 35 | + if (isset($bouton['id'])) { |
|
| 36 | + $id = $bouton['id']; |
|
| 37 | + $val = reset($val); |
|
| 38 | + if (is_array($val)) { |
|
| 39 | + $ret[$type][$id]['parent'] = $bouton['parent'] ?? ''; |
|
| 40 | + $ret[$type][$id]['position'] = $bouton['position'] ?? ''; |
|
| 41 | + $ret[$type][$id]['titre'] = isset($val['titre']) ? trim(spip_xml_aplatit($val['titre'])) : ''; |
|
| 42 | + $ret[$type][$id]['icone'] = isset($val['icone']) ? trim(end($val['icone'])) : ''; |
|
| 43 | + $ret[$type][$id]['action'] = isset($val['url']) ? trim(end($val['url'])) : ''; |
|
| 44 | + $ret[$type][$id]['parametres'] = isset($val['args']) ? trim(end($val['args'])) : ''; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return $ret; |
|
| 50 | + return $ret; |
|
| 51 | 51 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Notifications |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -33,16 +33,16 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function inc_notifications_dist($quoi, $id = 0, $options = []) { |
| 35 | 35 | |
| 36 | - // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | - // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | - pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 36 | + // charger les fichiers qui veulent ajouter des definitions |
|
| 37 | + // ou faire des trucs aussi dans le pipeline, ca fait deux api pour le prix d'une ... |
|
| 38 | + pipeline('notifications', ['args' => ['quoi' => $quoi, 'id' => $id, 'options' => $options]]); |
|
| 39 | 39 | |
| 40 | - if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | - spip_log("$notification($quoi,$id" |
|
| 42 | - . ($options ? ',' . serialize($options) : '') |
|
| 43 | - . ')', 'notifications'); |
|
| 44 | - $notification($quoi, $id, $options); |
|
| 45 | - } |
|
| 40 | + if ($notification = charger_fonction($quoi, 'notifications', true)) { |
|
| 41 | + spip_log("$notification($quoi,$id" |
|
| 42 | + . ($options ? ',' . serialize($options) : '') |
|
| 43 | + . ')', 'notifications'); |
|
| 44 | + $notification($quoi, $id, $options); |
|
| 45 | + } |
|
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | /** |
@@ -56,15 +56,15 @@ discard block |
||
| 56 | 56 | * @param array $exclure |
| 57 | 57 | */ |
| 58 | 58 | function notifications_nettoyer_emails(&$emails, $exclure = []) { |
| 59 | - // filtrer et unifier |
|
| 60 | - include_spip('inc/filtres'); |
|
| 61 | - $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 62 | - if ($exclure and count($exclure)) { |
|
| 63 | - // nettoyer les exclusions d'abord |
|
| 64 | - notifications_nettoyer_emails($exclure); |
|
| 65 | - // faire un diff |
|
| 66 | - $emails = array_diff($emails, $exclure); |
|
| 67 | - } |
|
| 59 | + // filtrer et unifier |
|
| 60 | + include_spip('inc/filtres'); |
|
| 61 | + $emails = array_unique(array_filter(array_map('email_valide', array_map('trim', $emails)))); |
|
| 62 | + if ($exclure and count($exclure)) { |
|
| 63 | + // nettoyer les exclusions d'abord |
|
| 64 | + notifications_nettoyer_emails($exclure); |
|
| 65 | + // faire un diff |
|
| 66 | + $emails = array_diff($emails, $exclure); |
|
| 67 | + } |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -79,90 +79,90 @@ discard block |
||
| 79 | 79 | * @param string $headers |
| 80 | 80 | */ |
| 81 | 81 | function notifications_envoyer_mails($emails, $texte, $sujet = '', $from = '', $headers = '') { |
| 82 | - // rien a faire si pas de texte ! |
|
| 83 | - if (!strlen($texte)) { |
|
| 84 | - return; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 88 | - if (!is_array($emails)) { |
|
| 89 | - $emails = explode(',', $emails); |
|
| 90 | - } |
|
| 91 | - |
|
| 92 | - notifications_nettoyer_emails($emails); |
|
| 93 | - |
|
| 94 | - // tester si le mail est deja en html |
|
| 95 | - if ( |
|
| 96 | - strpos($texte, '<') !== false // eviter les tests suivants si possible |
|
| 97 | - and $ttrim = trim($texte) |
|
| 98 | - and substr($ttrim, 0, 1) == '<' |
|
| 99 | - and substr($ttrim, -1, 1) == '>' |
|
| 100 | - and stripos($ttrim, '</html>') !== false |
|
| 101 | - ) { |
|
| 102 | - if (!strlen($sujet)) { |
|
| 103 | - // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 104 | - if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 105 | - $sujet = $m[1]; |
|
| 106 | - } else { |
|
| 107 | - // fallback, on prend le body si on le trouve |
|
| 108 | - if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 109 | - $ttrim = $m[1]; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // et on extrait la premiere ligne de vrai texte... |
|
| 113 | - // nettoyer le html et les retours chariots |
|
| 114 | - $ttrim = textebrut($ttrim); |
|
| 115 | - $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 116 | - $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 117 | - // decouper |
|
| 118 | - $ttrim = explode("\n", trim($ttrim)); |
|
| 119 | - // extraire la premiere ligne de texte brut |
|
| 120 | - $sujet = array_shift($ttrim); |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - // si besoin on ajoute le content-type dans les headers |
|
| 125 | - if (stripos($headers, 'Content-Type') === false) { |
|
| 126 | - $headers .= "Content-Type: text/html\n"; |
|
| 127 | - } |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // si le sujet est vide, extraire la premiere ligne du corps |
|
| 131 | - // du mail qui est donc du texte |
|
| 132 | - if (!strlen($sujet)) { |
|
| 133 | - // nettoyer un peu les retours chariots |
|
| 134 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 135 | - $texte = str_replace("\r", "\n", $texte); |
|
| 136 | - // decouper |
|
| 137 | - $texte = explode("\n", trim($texte)); |
|
| 138 | - // extraire la premiere ligne |
|
| 139 | - $sujet = array_shift($texte); |
|
| 140 | - $texte = trim(implode("\n", $texte)); |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 144 | - foreach ($emails as $email) { |
|
| 145 | - // passer dans un pipeline qui permet un ajout eventuel |
|
| 146 | - // (url de suivi des notifications par exemple) |
|
| 147 | - $envoi = pipeline( |
|
| 148 | - 'notifications_envoyer_mails', |
|
| 149 | - [ |
|
| 150 | - 'email' => $email, |
|
| 151 | - 'sujet' => $sujet, |
|
| 152 | - 'texte' => $texte, |
|
| 153 | - 'from' => $from, |
|
| 154 | - 'headers' => $headers, |
|
| 155 | - ] |
|
| 156 | - ); |
|
| 157 | - $email = $envoi['email']; |
|
| 158 | - |
|
| 159 | - job_queue_add( |
|
| 160 | - 'envoyer_mail', |
|
| 161 | - ">$email : " . $envoi['sujet'], |
|
| 162 | - [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 163 | - 'inc/' |
|
| 164 | - ); |
|
| 165 | - } |
|
| 82 | + // rien a faire si pas de texte ! |
|
| 83 | + if (!strlen($texte)) { |
|
| 84 | + return; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + // si on ne specifie qu'un email, le mettre dans un tableau |
|
| 88 | + if (!is_array($emails)) { |
|
| 89 | + $emails = explode(',', $emails); |
|
| 90 | + } |
|
| 91 | + |
|
| 92 | + notifications_nettoyer_emails($emails); |
|
| 93 | + |
|
| 94 | + // tester si le mail est deja en html |
|
| 95 | + if ( |
|
| 96 | + strpos($texte, '<') !== false // eviter les tests suivants si possible |
|
| 97 | + and $ttrim = trim($texte) |
|
| 98 | + and substr($ttrim, 0, 1) == '<' |
|
| 99 | + and substr($ttrim, -1, 1) == '>' |
|
| 100 | + and stripos($ttrim, '</html>') !== false |
|
| 101 | + ) { |
|
| 102 | + if (!strlen($sujet)) { |
|
| 103 | + // dans ce cas on ruse un peu : extraire le sujet du title |
|
| 104 | + if (preg_match(',<title>(.*)</title>,Uims', $texte, $m)) { |
|
| 105 | + $sujet = $m[1]; |
|
| 106 | + } else { |
|
| 107 | + // fallback, on prend le body si on le trouve |
|
| 108 | + if (preg_match(',<body[^>]*>(.*)</body>,Uims', $texte, $m)) { |
|
| 109 | + $ttrim = $m[1]; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // et on extrait la premiere ligne de vrai texte... |
|
| 113 | + // nettoyer le html et les retours chariots |
|
| 114 | + $ttrim = textebrut($ttrim); |
|
| 115 | + $ttrim = str_replace("\r\n", "\r", $ttrim); |
|
| 116 | + $ttrim = str_replace("\r", "\n", $ttrim); |
|
| 117 | + // decouper |
|
| 118 | + $ttrim = explode("\n", trim($ttrim)); |
|
| 119 | + // extraire la premiere ligne de texte brut |
|
| 120 | + $sujet = array_shift($ttrim); |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + // si besoin on ajoute le content-type dans les headers |
|
| 125 | + if (stripos($headers, 'Content-Type') === false) { |
|
| 126 | + $headers .= "Content-Type: text/html\n"; |
|
| 127 | + } |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // si le sujet est vide, extraire la premiere ligne du corps |
|
| 131 | + // du mail qui est donc du texte |
|
| 132 | + if (!strlen($sujet)) { |
|
| 133 | + // nettoyer un peu les retours chariots |
|
| 134 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 135 | + $texte = str_replace("\r", "\n", $texte); |
|
| 136 | + // decouper |
|
| 137 | + $texte = explode("\n", trim($texte)); |
|
| 138 | + // extraire la premiere ligne |
|
| 139 | + $sujet = array_shift($texte); |
|
| 140 | + $texte = trim(implode("\n", $texte)); |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); |
|
| 144 | + foreach ($emails as $email) { |
|
| 145 | + // passer dans un pipeline qui permet un ajout eventuel |
|
| 146 | + // (url de suivi des notifications par exemple) |
|
| 147 | + $envoi = pipeline( |
|
| 148 | + 'notifications_envoyer_mails', |
|
| 149 | + [ |
|
| 150 | + 'email' => $email, |
|
| 151 | + 'sujet' => $sujet, |
|
| 152 | + 'texte' => $texte, |
|
| 153 | + 'from' => $from, |
|
| 154 | + 'headers' => $headers, |
|
| 155 | + ] |
|
| 156 | + ); |
|
| 157 | + $email = $envoi['email']; |
|
| 158 | + |
|
| 159 | + job_queue_add( |
|
| 160 | + 'envoyer_mail', |
|
| 161 | + ">$email : " . $envoi['sujet'], |
|
| 162 | + [$email, $envoi['sujet'], $envoi['texte'], $envoi['from'], $envoi['headers']], |
|
| 163 | + 'inc/' |
|
| 164 | + ); |
|
| 165 | + } |
|
| 166 | 166 | } |
| 167 | 167 | |
| 168 | 168 | /** |
@@ -178,10 +178,10 @@ discard block |
||
| 178 | 178 | * @return string |
| 179 | 179 | */ |
| 180 | 180 | function email_notification_objet($id_objet, $type_objet, $modele) { |
| 181 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 182 | - $id_type = id_table_objet($type_objet); |
|
| 181 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 182 | + $id_type = id_table_objet($type_objet); |
|
| 183 | 183 | |
| 184 | - return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 184 | + return recuperer_fond($modele, [$id_type => $id_objet, 'id' => $id_objet]); |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | * @return string |
| 197 | 197 | */ |
| 198 | 198 | function email_notification_article($id_article, $modele) { |
| 199 | - $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 199 | + $envoyer_mail = charger_fonction('envoyer_mail', 'inc'); // pour nettoyer_titre_email |
|
| 200 | 200 | |
| 201 | - return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 201 | + return recuperer_fond($modele, ['id_article' => $id_article]); |
|
| 202 | 202 | } |
@@ -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 | |
@@ -54,65 +54,65 @@ discard block |
||
| 54 | 54 | * true si le statut change effectivement |
| 55 | 55 | **/ |
| 56 | 56 | function calculer_rubriques_if($id_rubrique, $modifs, $infos = [], $postdate = false) { |
| 57 | - $statuts_publies = null; |
|
| 58 | - $neuf = false; |
|
| 59 | - |
|
| 60 | - // Compat avec l'ancienne signature |
|
| 61 | - if (is_string($infos)) { |
|
| 62 | - $infos = ['statut_ancien' => $infos]; |
|
| 63 | - } |
|
| 64 | - if (!isset($infos['statut_ancien'])) { |
|
| 65 | - $infos['statut_ancien'] = ''; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // On recherche quels statuts tester |
|
| 69 | - if ( |
|
| 70 | - isset($infos['objet']) |
|
| 71 | - and include_spip('inc/filtres') |
|
| 72 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | - and is_array($declaration_statut) |
|
| 74 | - ) { |
|
| 75 | - foreach ($declaration_statut as $champ_statut) { |
|
| 76 | - if ($champ_statut['champ'] == 'statut') { |
|
| 77 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | - break; // stop on a trouvé le bon champ |
|
| 79 | - } |
|
| 80 | - } |
|
| 81 | - } else { |
|
| 82 | - $statuts_publies = ['publie']; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | - if ( |
|
| 87 | - isset($modifs['statut']) |
|
| 88 | - or isset($modifs['id_rubrique']) |
|
| 89 | - or ($postdate and strtotime($postdate) > time()) |
|
| 90 | - ) { |
|
| 91 | - $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | - } |
|
| 93 | - // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | - if ($postdate) { |
|
| 95 | - calculer_prochain_postdate(true); |
|
| 96 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | - } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | - $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | - } |
|
| 100 | - } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | - if ($postdate) { |
|
| 102 | - calculer_prochain_postdate(true); |
|
| 103 | - $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | - } else { |
|
| 105 | - $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - if ($neuf) { |
|
| 110 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | - } |
|
| 113 | - |
|
| 114 | - $langues = calculer_langues_utilisees(); |
|
| 115 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $statuts_publies = null; |
|
| 58 | + $neuf = false; |
|
| 59 | + |
|
| 60 | + // Compat avec l'ancienne signature |
|
| 61 | + if (is_string($infos)) { |
|
| 62 | + $infos = ['statut_ancien' => $infos]; |
|
| 63 | + } |
|
| 64 | + if (!isset($infos['statut_ancien'])) { |
|
| 65 | + $infos['statut_ancien'] = ''; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // On recherche quels statuts tester |
|
| 69 | + if ( |
|
| 70 | + isset($infos['objet']) |
|
| 71 | + and include_spip('inc/filtres') |
|
| 72 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 73 | + and is_array($declaration_statut) |
|
| 74 | + ) { |
|
| 75 | + foreach ($declaration_statut as $champ_statut) { |
|
| 76 | + if ($champ_statut['champ'] == 'statut') { |
|
| 77 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 78 | + break; // stop on a trouvé le bon champ |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | + } else { |
|
| 82 | + $statuts_publies = ['publie']; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + if (in_array($infos['statut_ancien'], $statuts_publies)) { |
|
| 86 | + if ( |
|
| 87 | + isset($modifs['statut']) |
|
| 88 | + or isset($modifs['id_rubrique']) |
|
| 89 | + or ($postdate and strtotime($postdate) > time()) |
|
| 90 | + ) { |
|
| 91 | + $neuf |= depublier_branche_rubrique_if($id_rubrique); |
|
| 92 | + } |
|
| 93 | + // ne publier que si c'est pas un postdate, ou si la date n'est pas dans le futur |
|
| 94 | + if ($postdate) { |
|
| 95 | + calculer_prochain_postdate(true); |
|
| 96 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 97 | + } elseif (isset($modifs['id_rubrique'])) { |
|
| 98 | + $neuf |= publier_branche_rubrique($modifs['id_rubrique']); |
|
| 99 | + } |
|
| 100 | + } elseif (isset($modifs['statut']) and in_array($modifs['statut'], $statuts_publies)) { |
|
| 101 | + if ($postdate) { |
|
| 102 | + calculer_prochain_postdate(true); |
|
| 103 | + $neuf |= (strtotime($postdate) <= time()); // par securite |
|
| 104 | + } else { |
|
| 105 | + $neuf |= publier_branche_rubrique($id_rubrique); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + if ($neuf) { |
|
| 110 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 111 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 112 | + } |
|
| 113 | + |
|
| 114 | + $langues = calculer_langues_utilisees(); |
|
| 115 | + ecrire_meta('langues_utilisees', $langues); |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | * true si le statut change effectivement |
| 131 | 131 | */ |
| 132 | 132 | function publier_branche_rubrique($id_rubrique) { |
| 133 | - $id_pred = $id_rubrique; |
|
| 134 | - while (true) { |
|
| 135 | - sql_updateq( |
|
| 136 | - 'spip_rubriques', |
|
| 137 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | - ); |
|
| 140 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | - if (!$id_parent) { |
|
| 142 | - break; |
|
| 143 | - } |
|
| 144 | - $id_rubrique = $id_parent; |
|
| 145 | - } |
|
| 133 | + $id_pred = $id_rubrique; |
|
| 134 | + while (true) { |
|
| 135 | + sql_updateq( |
|
| 136 | + 'spip_rubriques', |
|
| 137 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 138 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 139 | + ); |
|
| 140 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 141 | + if (!$id_parent) { |
|
| 142 | + break; |
|
| 143 | + } |
|
| 144 | + $id_rubrique = $id_parent; |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | 147 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 148 | - return $id_pred != $id_rubrique; |
|
| 148 | + return $id_pred != $id_rubrique; |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -163,20 +163,20 @@ discard block |
||
| 163 | 163 | * true si le statut change effectivement |
| 164 | 164 | */ |
| 165 | 165 | function depublier_branche_rubrique_if($id_rubrique) { |
| 166 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | - |
|
| 168 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | - $id_pred = $id_rubrique; |
|
| 170 | - while ($id_pred) { |
|
| 171 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | - return $id_pred != $id_rubrique; |
|
| 173 | - } |
|
| 174 | - // passer au parent si on a depublie |
|
| 175 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | - $id_pred = $r['id_parent']; |
|
| 177 | - } |
|
| 178 | - |
|
| 179 | - return $id_pred != $id_rubrique; |
|
| 166 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 167 | + |
|
| 168 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 169 | + $id_pred = $id_rubrique; |
|
| 170 | + while ($id_pred) { |
|
| 171 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 172 | + return $id_pred != $id_rubrique; |
|
| 173 | + } |
|
| 174 | + // passer au parent si on a depublie |
|
| 175 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 176 | + $id_pred = $r['id_parent']; |
|
| 177 | + } |
|
| 178 | + |
|
| 179 | + return $id_pred != $id_rubrique; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -193,61 +193,61 @@ discard block |
||
| 193 | 193 | * true si la rubrique a été dépubliée |
| 194 | 194 | */ |
| 195 | 195 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 196 | - if (is_null($date)) { |
|
| 197 | - $date = date('Y-m-d H:i:s'); |
|
| 198 | - } |
|
| 199 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | - |
|
| 202 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | - return false; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // verifier qu'elle existe et est bien publiee |
|
| 207 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | - return false; |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | - // Le type de l'objet est au pluriel |
|
| 214 | - $compte = [ |
|
| 215 | - 'articles' => sql_countsel( |
|
| 216 | - 'spip_articles', |
|
| 217 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | - ), |
|
| 219 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | - 'documents' => sql_countsel( |
|
| 221 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | - ) |
|
| 224 | - ]; |
|
| 225 | - |
|
| 226 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | - $compte = pipeline( |
|
| 228 | - 'objet_compte_enfants', |
|
| 229 | - [ |
|
| 230 | - 'args' => [ |
|
| 231 | - 'objet' => 'rubrique', |
|
| 232 | - 'id_objet' => $id_rubrique, |
|
| 233 | - 'statut' => 'publie', |
|
| 234 | - 'date' => $date |
|
| 235 | - ], |
|
| 236 | - 'data' => $compte |
|
| 237 | - ] |
|
| 238 | - ); |
|
| 239 | - |
|
| 240 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | - foreach ($compte as $objet => $n) { |
|
| 242 | - if ($n) { |
|
| 243 | - return false; |
|
| 244 | - } |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 196 | + if (is_null($date)) { |
|
| 197 | + $date = date('Y-m-d H:i:s'); |
|
| 198 | + } |
|
| 199 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 200 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 201 | + |
|
| 202 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 203 | + return false; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // verifier qu'elle existe et est bien publiee |
|
| 207 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 208 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 209 | + return false; |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 213 | + // Le type de l'objet est au pluriel |
|
| 214 | + $compte = [ |
|
| 215 | + 'articles' => sql_countsel( |
|
| 216 | + 'spip_articles', |
|
| 217 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 218 | + ), |
|
| 219 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 220 | + 'documents' => sql_countsel( |
|
| 221 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 222 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 223 | + ) |
|
| 224 | + ]; |
|
| 225 | + |
|
| 226 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 227 | + $compte = pipeline( |
|
| 228 | + 'objet_compte_enfants', |
|
| 229 | + [ |
|
| 230 | + 'args' => [ |
|
| 231 | + 'objet' => 'rubrique', |
|
| 232 | + 'id_objet' => $id_rubrique, |
|
| 233 | + 'statut' => 'publie', |
|
| 234 | + 'date' => $date |
|
| 235 | + ], |
|
| 236 | + 'data' => $compte |
|
| 237 | + ] |
|
| 238 | + ); |
|
| 239 | + |
|
| 240 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 241 | + foreach ($compte as $objet => $n) { |
|
| 242 | + if ($n) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 248 | 248 | |
| 249 | 249 | # spip_log("depublier_rubrique $id_pred"); |
| 250 | - return true; |
|
| 250 | + return true; |
|
| 251 | 251 | } |
| 252 | 252 | |
| 253 | 253 | |
@@ -270,18 +270,18 @@ discard block |
||
| 270 | 270 | **/ |
| 271 | 271 | function calculer_rubriques() { |
| 272 | 272 | |
| 273 | - calculer_rubriques_publiees(); |
|
| 273 | + calculer_rubriques_publiees(); |
|
| 274 | 274 | |
| 275 | - // Apres chaque (de)publication |
|
| 276 | - // recalculer les langues utilisees sur le site |
|
| 277 | - $langues = calculer_langues_utilisees(); |
|
| 278 | - ecrire_meta('langues_utilisees', $langues); |
|
| 275 | + // Apres chaque (de)publication |
|
| 276 | + // recalculer les langues utilisees sur le site |
|
| 277 | + $langues = calculer_langues_utilisees(); |
|
| 278 | + ecrire_meta('langues_utilisees', $langues); |
|
| 279 | 279 | |
| 280 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 280 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 281 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 282 | 282 | |
| 283 | - // on calcule la date du prochain article post-date |
|
| 284 | - calculer_prochain_postdate(); |
|
| 283 | + // on calcule la date du prochain article post-date |
|
| 284 | + calculer_prochain_postdate(); |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | |
@@ -298,61 +298,61 @@ discard block |
||
| 298 | 298 | **/ |
| 299 | 299 | function calculer_rubriques_publiees() { |
| 300 | 300 | |
| 301 | - // Mettre les compteurs a zero |
|
| 302 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | - |
|
| 304 | - // |
|
| 305 | - // Publier et dater les rubriques qui ont un article publie |
|
| 306 | - // |
|
| 307 | - |
|
| 308 | - // Afficher les articles post-dates ? |
|
| 309 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | - |
|
| 312 | - $r = sql_select( |
|
| 313 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | - 'R.id_rubrique' |
|
| 317 | - ); |
|
| 318 | - while ($row = sql_fetch($r)) { |
|
| 319 | - sql_updateq( |
|
| 320 | - 'spip_rubriques', |
|
| 321 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | - 'id_rubrique=' . intval($row['id']) |
|
| 323 | - ); |
|
| 324 | - } |
|
| 325 | - |
|
| 326 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | - pipeline('calculer_rubriques', null); |
|
| 332 | - |
|
| 333 | - |
|
| 334 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | - do { |
|
| 337 | - $continuer = false; |
|
| 338 | - $r = sql_select( |
|
| 339 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | - 'R.id_rubrique' |
|
| 343 | - ); |
|
| 344 | - while ($row = sql_fetch($r)) { |
|
| 345 | - sql_updateq( |
|
| 346 | - 'spip_rubriques', |
|
| 347 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | - 'id_rubrique=' . intval($row['id']) |
|
| 349 | - ); |
|
| 350 | - $continuer = true; |
|
| 351 | - } |
|
| 352 | - } while ($continuer); |
|
| 353 | - |
|
| 354 | - // Enregistrement des modifs |
|
| 355 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 301 | + // Mettre les compteurs a zero |
|
| 302 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 303 | + |
|
| 304 | + // |
|
| 305 | + // Publier et dater les rubriques qui ont un article publie |
|
| 306 | + // |
|
| 307 | + |
|
| 308 | + // Afficher les articles post-dates ? |
|
| 309 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 310 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 311 | + |
|
| 312 | + $r = sql_select( |
|
| 313 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 314 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 315 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 316 | + 'R.id_rubrique' |
|
| 317 | + ); |
|
| 318 | + while ($row = sql_fetch($r)) { |
|
| 319 | + sql_updateq( |
|
| 320 | + 'spip_rubriques', |
|
| 321 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 322 | + 'id_rubrique=' . intval($row['id']) |
|
| 323 | + ); |
|
| 324 | + } |
|
| 325 | + |
|
| 326 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 327 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 328 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 329 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 330 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 331 | + pipeline('calculer_rubriques', null); |
|
| 332 | + |
|
| 333 | + |
|
| 334 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 335 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 336 | + do { |
|
| 337 | + $continuer = false; |
|
| 338 | + $r = sql_select( |
|
| 339 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 340 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 341 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 342 | + 'R.id_rubrique' |
|
| 343 | + ); |
|
| 344 | + while ($row = sql_fetch($r)) { |
|
| 345 | + sql_updateq( |
|
| 346 | + 'spip_rubriques', |
|
| 347 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 348 | + 'id_rubrique=' . intval($row['id']) |
|
| 349 | + ); |
|
| 350 | + $continuer = true; |
|
| 351 | + } |
|
| 352 | + } while ($continuer); |
|
| 353 | + |
|
| 354 | + // Enregistrement des modifs |
|
| 355 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -367,123 +367,123 @@ discard block |
||
| 367 | 367 | * @return void |
| 368 | 368 | **/ |
| 369 | 369 | function propager_les_secteurs() { |
| 370 | - // Profondeur 0 |
|
| 371 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | - // et fixer les id_secteur des rubriques racines |
|
| 373 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | - // Toute rubrique non racine est de profondeur >0 |
|
| 375 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | - |
|
| 377 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | - |
|
| 380 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | - // on fait profondeur par profondeur |
|
| 382 | - |
|
| 383 | - $prof = 0; |
|
| 384 | - do { |
|
| 385 | - $continuer = false; |
|
| 386 | - |
|
| 387 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | - // on fixe le profondeur $prof+1 |
|
| 389 | - |
|
| 390 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | - // on teste A.profondeur > $prof+1 car : |
|
| 392 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | - $maxiter2 = $maxiter; |
|
| 396 | - while ( |
|
| 397 | - $maxiter2-- |
|
| 398 | - and $rows = sql_allfetsel( |
|
| 399 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | - '', |
|
| 403 | - 'R.id_secteur', |
|
| 404 | - '0,100' |
|
| 405 | - ) |
|
| 406 | - ) { |
|
| 407 | - $id_secteur = null; |
|
| 408 | - $ids = []; |
|
| 409 | - while ($row = array_shift($rows)) { |
|
| 410 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | - if (count($ids)) { |
|
| 412 | - sql_updateq( |
|
| 413 | - 'spip_rubriques', |
|
| 414 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | - sql_in('id_rubrique', $ids) |
|
| 416 | - ); |
|
| 417 | - } |
|
| 418 | - $id_secteur = $row['id_secteur']; |
|
| 419 | - $ids = []; |
|
| 420 | - } |
|
| 421 | - $ids[] = $row['id']; |
|
| 422 | - } |
|
| 423 | - if (count($ids)) { |
|
| 424 | - sql_updateq( |
|
| 425 | - 'spip_rubriques', |
|
| 426 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | - sql_in('id_rubrique', $ids) |
|
| 428 | - ); |
|
| 429 | - } |
|
| 430 | - } |
|
| 431 | - |
|
| 432 | - |
|
| 433 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | - $maxiter2 = $maxiter; |
|
| 435 | - while ( |
|
| 436 | - $maxiter2-- |
|
| 437 | - and $rows = sql_allfetsel( |
|
| 438 | - 'id_rubrique as id', |
|
| 439 | - 'spip_rubriques', |
|
| 440 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | - 'zzz.id_rubrique', |
|
| 442 | - 'spip_rubriques AS zzz', |
|
| 443 | - 'zzz.profondeur=' . intval($prof) |
|
| 444 | - ) . ')', |
|
| 445 | - '', |
|
| 446 | - '', |
|
| 447 | - '0,100' |
|
| 448 | - ) |
|
| 449 | - ) { |
|
| 450 | - $rows = array_column($rows, 'id'); |
|
| 451 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | - // on arrete les frais |
|
| 458 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | - $prof++; |
|
| 460 | - $continuer = true; |
|
| 461 | - } |
|
| 462 | - } while ($continuer and $maxiter--); |
|
| 463 | - |
|
| 464 | - // loger si la table des rubriques semble foireuse |
|
| 465 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | - spip_log( |
|
| 468 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | - _LOG_CRITIQUE |
|
| 470 | - ); |
|
| 471 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - // reparer les articles |
|
| 475 | - $r = sql_select( |
|
| 476 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | - ); |
|
| 480 | - |
|
| 481 | - while ($row = sql_fetch($r)) { |
|
| 482 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 370 | + // Profondeur 0 |
|
| 371 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 372 | + // et fixer les id_secteur des rubriques racines |
|
| 373 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 374 | + // Toute rubrique non racine est de profondeur >0 |
|
| 375 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 376 | + |
|
| 377 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 378 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 379 | + |
|
| 380 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 381 | + // on fait profondeur par profondeur |
|
| 382 | + |
|
| 383 | + $prof = 0; |
|
| 384 | + do { |
|
| 385 | + $continuer = false; |
|
| 386 | + |
|
| 387 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 388 | + // on fixe le profondeur $prof+1 |
|
| 389 | + |
|
| 390 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 391 | + // on teste A.profondeur > $prof+1 car : |
|
| 392 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 393 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 394 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 395 | + $maxiter2 = $maxiter; |
|
| 396 | + while ( |
|
| 397 | + $maxiter2-- |
|
| 398 | + and $rows = sql_allfetsel( |
|
| 399 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 400 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 401 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 402 | + '', |
|
| 403 | + 'R.id_secteur', |
|
| 404 | + '0,100' |
|
| 405 | + ) |
|
| 406 | + ) { |
|
| 407 | + $id_secteur = null; |
|
| 408 | + $ids = []; |
|
| 409 | + while ($row = array_shift($rows)) { |
|
| 410 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 411 | + if (count($ids)) { |
|
| 412 | + sql_updateq( |
|
| 413 | + 'spip_rubriques', |
|
| 414 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 415 | + sql_in('id_rubrique', $ids) |
|
| 416 | + ); |
|
| 417 | + } |
|
| 418 | + $id_secteur = $row['id_secteur']; |
|
| 419 | + $ids = []; |
|
| 420 | + } |
|
| 421 | + $ids[] = $row['id']; |
|
| 422 | + } |
|
| 423 | + if (count($ids)) { |
|
| 424 | + sql_updateq( |
|
| 425 | + 'spip_rubriques', |
|
| 426 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 427 | + sql_in('id_rubrique', $ids) |
|
| 428 | + ); |
|
| 429 | + } |
|
| 430 | + } |
|
| 431 | + |
|
| 432 | + |
|
| 433 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 434 | + $maxiter2 = $maxiter; |
|
| 435 | + while ( |
|
| 436 | + $maxiter2-- |
|
| 437 | + and $rows = sql_allfetsel( |
|
| 438 | + 'id_rubrique as id', |
|
| 439 | + 'spip_rubriques', |
|
| 440 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 441 | + 'zzz.id_rubrique', |
|
| 442 | + 'spip_rubriques AS zzz', |
|
| 443 | + 'zzz.profondeur=' . intval($prof) |
|
| 444 | + ) . ')', |
|
| 445 | + '', |
|
| 446 | + '', |
|
| 447 | + '0,100' |
|
| 448 | + ) |
|
| 449 | + ) { |
|
| 450 | + $rows = array_column($rows, 'id'); |
|
| 451 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 455 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 456 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 457 | + // on arrete les frais |
|
| 458 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 459 | + $prof++; |
|
| 460 | + $continuer = true; |
|
| 461 | + } |
|
| 462 | + } while ($continuer and $maxiter--); |
|
| 463 | + |
|
| 464 | + // loger si la table des rubriques semble foireuse |
|
| 465 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 466 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 467 | + spip_log( |
|
| 468 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 469 | + _LOG_CRITIQUE |
|
| 470 | + ); |
|
| 471 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + // reparer les articles |
|
| 475 | + $r = sql_select( |
|
| 476 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 477 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 478 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 479 | + ); |
|
| 480 | + |
|
| 481 | + while ($row = sql_fetch($r)) { |
|
| 482 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 486 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -498,23 +498,23 @@ discard block |
||
| 498 | 498 | * true si un changement a eu lieu |
| 499 | 499 | **/ |
| 500 | 500 | function calculer_langues_rubriques_etape() { |
| 501 | - $s = sql_select( |
|
| 502 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | - ); |
|
| 506 | - |
|
| 507 | - $t = false; |
|
| 508 | - while ($row = sql_fetch($s)) { |
|
| 509 | - $id_rubrique = $row['id_rubrique']; |
|
| 510 | - $t = sql_updateq( |
|
| 511 | - 'spip_rubriques', |
|
| 512 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | - ); |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - return $t; |
|
| 501 | + $s = sql_select( |
|
| 502 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 503 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 504 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 505 | + ); |
|
| 506 | + |
|
| 507 | + $t = false; |
|
| 508 | + while ($row = sql_fetch($s)) { |
|
| 509 | + $id_rubrique = $row['id_rubrique']; |
|
| 510 | + $t = sql_updateq( |
|
| 511 | + 'spip_rubriques', |
|
| 512 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 513 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 514 | + ); |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + return $t; |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -534,38 +534,38 @@ discard block |
||
| 534 | 534 | **/ |
| 535 | 535 | function calculer_langues_rubriques() { |
| 536 | 536 | |
| 537 | - // rubriques (recursivite) |
|
| 538 | - sql_updateq( |
|
| 539 | - 'spip_rubriques', |
|
| 540 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | - ); |
|
| 543 | - while (calculer_langues_rubriques_etape()) { |
|
| 544 | - ; |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // articles |
|
| 548 | - $s = sql_select( |
|
| 549 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | - "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 552 | - ); |
|
| 553 | - while ($row = sql_fetch($s)) { |
|
| 554 | - $id_article = $row['id_article']; |
|
| 555 | - sql_updateq( |
|
| 556 | - 'spip_articles', |
|
| 557 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | - 'id_article=' . intval($id_article) |
|
| 559 | - ); |
|
| 560 | - } |
|
| 561 | - |
|
| 562 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | - $langues = calculer_langues_utilisees(); |
|
| 564 | - ecrire_meta('langues_utilisees', $langues); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 537 | + // rubriques (recursivite) |
|
| 538 | + sql_updateq( |
|
| 539 | + 'spip_rubriques', |
|
| 540 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 541 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 542 | + ); |
|
| 543 | + while (calculer_langues_rubriques_etape()) { |
|
| 544 | + ; |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // articles |
|
| 548 | + $s = sql_select( |
|
| 549 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 550 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 551 | + "A.id_rubrique = R.id_rubrique AND A.langue_choisie != 'oui' AND (length(A.lang)=0 OR length(R.lang)>0) AND R.lang<>A.lang" |
|
| 552 | + ); |
|
| 553 | + while ($row = sql_fetch($s)) { |
|
| 554 | + $id_article = $row['id_article']; |
|
| 555 | + sql_updateq( |
|
| 556 | + 'spip_articles', |
|
| 557 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 558 | + 'id_article=' . intval($id_article) |
|
| 559 | + ); |
|
| 560 | + } |
|
| 561 | + |
|
| 562 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 563 | + $langues = calculer_langues_utilisees(); |
|
| 564 | + ecrire_meta('langues_utilisees', $langues); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 568 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 569 | 569 | } |
| 570 | 570 | |
| 571 | 571 | |
@@ -582,80 +582,80 @@ discard block |
||
| 582 | 582 | * Liste des langues utilisées séparées par des virgules |
| 583 | 583 | **/ |
| 584 | 584 | function calculer_langues_utilisees($serveur = '') { |
| 585 | - include_spip('public/interfaces'); |
|
| 586 | - include_spip('public/compiler'); |
|
| 587 | - include_spip('public/composer'); |
|
| 588 | - include_spip('public/phraser_html'); |
|
| 589 | - $langues = []; |
|
| 590 | - |
|
| 591 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | - |
|
| 593 | - include_spip('base/objets'); |
|
| 594 | - $tables = lister_tables_objets_sql(); |
|
| 595 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | - |
|
| 597 | - foreach (array_keys($tables) as $t) { |
|
| 598 | - $desc = $trouver_table($t, $serveur); |
|
| 599 | - // c'est une table avec des langues |
|
| 600 | - if ( |
|
| 601 | - $desc['exist'] |
|
| 602 | - and isset($desc['field']['lang']) |
|
| 603 | - and isset($desc['field']['langue_choisie']) |
|
| 604 | - ) { |
|
| 605 | - $boucle = new Boucle(); |
|
| 606 | - $boucle->show = $desc; |
|
| 607 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | - $boucle->id_table = $desc['table_objet']; |
|
| 610 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | - $boucle->sql_serveur = $serveur; |
|
| 612 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | - $boucle->separateur[] = ','; |
|
| 615 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | - $boucle->iterateur = 'sql'; |
|
| 617 | - |
|
| 618 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | - $boucle->descr['gram'] = 'html'; |
|
| 621 | - |
|
| 622 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | - |
|
| 624 | - if ( |
|
| 625 | - isset($desc['statut']) |
|
| 626 | - and $desc['statut'] |
|
| 627 | - ) { |
|
| 628 | - $boucles = [ |
|
| 629 | - 'calculer_langues_utilisees' => $boucle, |
|
| 630 | - ]; |
|
| 631 | - // generer un nom de fonction "anonyme" unique |
|
| 632 | - do { |
|
| 633 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | - } while (function_exists($functionname)); |
|
| 635 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | - $res = ''; |
|
| 639 | - eval($code); |
|
| 640 | - $res = explode(',', $res); |
|
| 641 | - foreach ($res as $lang) { |
|
| 642 | - $langues[$lang] = 1; |
|
| 643 | - } |
|
| 644 | - } else { |
|
| 645 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | - while ($row = sql_fetch($res)) { |
|
| 647 | - $langues[$row['lang']] = 1; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - $langues = array_filter(array_keys($langues)); |
|
| 654 | - sort($langues); |
|
| 655 | - $langues = join(',', $langues); |
|
| 656 | - spip_log("langues utilisees: $langues"); |
|
| 657 | - |
|
| 658 | - return $langues; |
|
| 585 | + include_spip('public/interfaces'); |
|
| 586 | + include_spip('public/compiler'); |
|
| 587 | + include_spip('public/composer'); |
|
| 588 | + include_spip('public/phraser_html'); |
|
| 589 | + $langues = []; |
|
| 590 | + |
|
| 591 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 592 | + |
|
| 593 | + include_spip('base/objets'); |
|
| 594 | + $tables = lister_tables_objets_sql(); |
|
| 595 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 596 | + |
|
| 597 | + foreach (array_keys($tables) as $t) { |
|
| 598 | + $desc = $trouver_table($t, $serveur); |
|
| 599 | + // c'est une table avec des langues |
|
| 600 | + if ( |
|
| 601 | + $desc['exist'] |
|
| 602 | + and isset($desc['field']['lang']) |
|
| 603 | + and isset($desc['field']['langue_choisie']) |
|
| 604 | + ) { |
|
| 605 | + $boucle = new Boucle(); |
|
| 606 | + $boucle->show = $desc; |
|
| 607 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 608 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 609 | + $boucle->id_table = $desc['table_objet']; |
|
| 610 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 611 | + $boucle->sql_serveur = $serveur; |
|
| 612 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 613 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 614 | + $boucle->separateur[] = ','; |
|
| 615 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 616 | + $boucle->iterateur = 'sql'; |
|
| 617 | + |
|
| 618 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 619 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 620 | + $boucle->descr['gram'] = 'html'; |
|
| 621 | + |
|
| 622 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 623 | + |
|
| 624 | + if ( |
|
| 625 | + isset($desc['statut']) |
|
| 626 | + and $desc['statut'] |
|
| 627 | + ) { |
|
| 628 | + $boucles = [ |
|
| 629 | + 'calculer_langues_utilisees' => $boucle, |
|
| 630 | + ]; |
|
| 631 | + // generer un nom de fonction "anonyme" unique |
|
| 632 | + do { |
|
| 633 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . random_int(0, mt_getrandmax()); |
|
| 634 | + } while (function_exists($functionname)); |
|
| 635 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 636 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 637 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 638 | + $res = ''; |
|
| 639 | + eval($code); |
|
| 640 | + $res = explode(',', $res); |
|
| 641 | + foreach ($res as $lang) { |
|
| 642 | + $langues[$lang] = 1; |
|
| 643 | + } |
|
| 644 | + } else { |
|
| 645 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 646 | + while ($row = sql_fetch($res)) { |
|
| 647 | + $langues[$row['lang']] = 1; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + $langues = array_filter(array_keys($langues)); |
|
| 654 | + sort($langues); |
|
| 655 | + $langues = join(',', $langues); |
|
| 656 | + spip_log("langues utilisees: $langues"); |
|
| 657 | + |
|
| 658 | + return $langues; |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | /** |
@@ -672,9 +672,9 @@ discard block |
||
| 672 | 672 | * incluant les rubriques noeuds et toutes leurs descendances |
| 673 | 673 | */ |
| 674 | 674 | function calcul_branche_in($id) { |
| 675 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 676 | 676 | |
| 677 | - return $calcul_branche_in($id); |
|
| 677 | + return $calcul_branche_in($id); |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -692,9 +692,9 @@ discard block |
||
| 692 | 692 | * incluant les rubriques transmises et toutes leurs parentées |
| 693 | 693 | */ |
| 694 | 694 | function calcul_hierarchie_in($id, $tout = true) { |
| 695 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 696 | 696 | |
| 697 | - return $calcul_hierarchie_in($id, $tout); |
|
| 697 | + return $calcul_hierarchie_in($id, $tout); |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -715,40 +715,40 @@ discard block |
||
| 715 | 715 | * incluant les rubriques noeuds et toutes leurs descendances |
| 716 | 716 | */ |
| 717 | 717 | function inc_calcul_branche_in_dist($id) { |
| 718 | - static $b = []; |
|
| 719 | - |
|
| 720 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | - if (!is_array($id)) { |
|
| 722 | - $id = explode(',', $id); |
|
| 723 | - } |
|
| 724 | - $id = join(',', array_map('intval', $id)); |
|
| 725 | - if (isset($b[$id])) { |
|
| 726 | - return $b[$id]; |
|
| 727 | - } |
|
| 728 | - |
|
| 729 | - // Notre branche commence par la rubrique de depart |
|
| 730 | - $branche = $r = $id; |
|
| 731 | - |
|
| 732 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | - $maxiter = 10000; |
|
| 735 | - while ( |
|
| 736 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | - 'id_rubrique', |
|
| 738 | - 'spip_rubriques', |
|
| 739 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | - ) |
|
| 741 | - ) { |
|
| 742 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | - $branche .= ',' . $r; |
|
| 744 | - } |
|
| 745 | - |
|
| 746 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | - if (strlen($branche) < 10000) { |
|
| 748 | - $b[$id] = $branche; |
|
| 749 | - } |
|
| 750 | - |
|
| 751 | - return $branche; |
|
| 718 | + static $b = []; |
|
| 719 | + |
|
| 720 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 721 | + if (!is_array($id)) { |
|
| 722 | + $id = explode(',', $id); |
|
| 723 | + } |
|
| 724 | + $id = join(',', array_map('intval', $id)); |
|
| 725 | + if (isset($b[$id])) { |
|
| 726 | + return $b[$id]; |
|
| 727 | + } |
|
| 728 | + |
|
| 729 | + // Notre branche commence par la rubrique de depart |
|
| 730 | + $branche = $r = $id; |
|
| 731 | + |
|
| 732 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 733 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 734 | + $maxiter = 10000; |
|
| 735 | + while ( |
|
| 736 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 737 | + 'id_rubrique', |
|
| 738 | + 'spip_rubriques', |
|
| 739 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 740 | + ) |
|
| 741 | + ) { |
|
| 742 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 743 | + $branche .= ',' . $r; |
|
| 744 | + } |
|
| 745 | + |
|
| 746 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 747 | + if (strlen($branche) < 10000) { |
|
| 748 | + $b[$id] = $branche; |
|
| 749 | + } |
|
| 750 | + |
|
| 751 | + return $branche; |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | |
@@ -770,45 +770,45 @@ discard block |
||
| 770 | 770 | * incluant les rubriques transmises et toutes leurs parentées |
| 771 | 771 | */ |
| 772 | 772 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 773 | - static $b = []; |
|
| 774 | - |
|
| 775 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | - if (!is_array($id)) { |
|
| 777 | - $id = explode(',', $id); |
|
| 778 | - } |
|
| 779 | - $id = join(',', array_map('intval', $id)); |
|
| 780 | - |
|
| 781 | - if (isset($b[$id])) { |
|
| 782 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | - } |
|
| 785 | - |
|
| 786 | - $hier = ''; |
|
| 787 | - |
|
| 788 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | - $ids_nouveaux_parents = $id; |
|
| 791 | - $maxiter = 10000; |
|
| 792 | - while ( |
|
| 793 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | - 'id_parent', |
|
| 795 | - 'spip_rubriques', |
|
| 796 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | - ) |
|
| 798 | - ) { |
|
| 799 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | - if (strlen($hier) < 10000) { |
|
| 805 | - $b[$id] = $hier; |
|
| 806 | - } |
|
| 807 | - |
|
| 808 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | - |
|
| 811 | - return $hier; |
|
| 773 | + static $b = []; |
|
| 774 | + |
|
| 775 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 776 | + if (!is_array($id)) { |
|
| 777 | + $id = explode(',', $id); |
|
| 778 | + } |
|
| 779 | + $id = join(',', array_map('intval', $id)); |
|
| 780 | + |
|
| 781 | + if (isset($b[$id])) { |
|
| 782 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 783 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 784 | + } |
|
| 785 | + |
|
| 786 | + $hier = ''; |
|
| 787 | + |
|
| 788 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 789 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 790 | + $ids_nouveaux_parents = $id; |
|
| 791 | + $maxiter = 10000; |
|
| 792 | + while ( |
|
| 793 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 794 | + 'id_parent', |
|
| 795 | + 'spip_rubriques', |
|
| 796 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 797 | + ) |
|
| 798 | + ) { |
|
| 799 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 800 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 804 | + if (strlen($hier) < 10000) { |
|
| 805 | + $b[$id] = $hier; |
|
| 806 | + } |
|
| 807 | + |
|
| 808 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 809 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 810 | + |
|
| 811 | + return $hier; |
|
| 812 | 812 | } |
| 813 | 813 | |
| 814 | 814 | |
@@ -826,47 +826,47 @@ discard block |
||
| 826 | 826 | * @return void |
| 827 | 827 | **/ |
| 828 | 828 | function calculer_prochain_postdate($check = false) { |
| 829 | - include_spip('base/abstract_sql'); |
|
| 830 | - if ($check) { |
|
| 831 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | - |
|
| 834 | - $r = sql_select( |
|
| 835 | - 'DISTINCT A.id_rubrique AS id', |
|
| 836 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | - ); |
|
| 839 | - while ($row = sql_fetch($r)) { |
|
| 840 | - publier_branche_rubrique($row['id']); |
|
| 841 | - } |
|
| 842 | - |
|
| 843 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | - } |
|
| 845 | - |
|
| 846 | - $t = sql_fetsel( |
|
| 847 | - 'date', |
|
| 848 | - 'spip_articles', |
|
| 849 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | - '', |
|
| 851 | - 'date', |
|
| 852 | - '1' |
|
| 853 | - ); |
|
| 854 | - |
|
| 855 | - if ($t) { |
|
| 856 | - $t = $t['date']; |
|
| 857 | - if ( |
|
| 858 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | - ) { |
|
| 861 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | - ecrire_meta('derniere_modif', time()); |
|
| 863 | - } |
|
| 864 | - } else { |
|
| 865 | - effacer_meta('date_prochain_postdate'); |
|
| 866 | - ecrire_meta('derniere_modif', time()); |
|
| 867 | - } |
|
| 868 | - |
|
| 869 | - spip_log("prochain postdate: $t"); |
|
| 829 | + include_spip('base/abstract_sql'); |
|
| 830 | + if ($check) { |
|
| 831 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 832 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 833 | + |
|
| 834 | + $r = sql_select( |
|
| 835 | + 'DISTINCT A.id_rubrique AS id', |
|
| 836 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 837 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 838 | + ); |
|
| 839 | + while ($row = sql_fetch($r)) { |
|
| 840 | + publier_branche_rubrique($row['id']); |
|
| 841 | + } |
|
| 842 | + |
|
| 843 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 844 | + } |
|
| 845 | + |
|
| 846 | + $t = sql_fetsel( |
|
| 847 | + 'date', |
|
| 848 | + 'spip_articles', |
|
| 849 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 850 | + '', |
|
| 851 | + 'date', |
|
| 852 | + '1' |
|
| 853 | + ); |
|
| 854 | + |
|
| 855 | + if ($t) { |
|
| 856 | + $t = $t['date']; |
|
| 857 | + if ( |
|
| 858 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 859 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 860 | + ) { |
|
| 861 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 862 | + ecrire_meta('derniere_modif', time()); |
|
| 863 | + } |
|
| 864 | + } else { |
|
| 865 | + effacer_meta('date_prochain_postdate'); |
|
| 866 | + ecrire_meta('derniere_modif', time()); |
|
| 867 | + } |
|
| 868 | + |
|
| 869 | + spip_log("prochain postdate: $t"); |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | /** |
@@ -891,62 +891,62 @@ discard block |
||
| 891 | 891 | */ |
| 892 | 892 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 893 | 893 | |
| 894 | - // eclater l'arborescence demandee |
|
| 895 | - // echapper les </multi> et autres balises fermantes html |
|
| 896 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | - include_spip('base/abstract_sql'); |
|
| 899 | - foreach ($arbo as $titre) { |
|
| 900 | - // retablir les </multi> et autres balises fermantes html |
|
| 901 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | - $r = sql_getfetsel( |
|
| 903 | - 'id_rubrique', |
|
| 904 | - 'spip_rubriques', |
|
| 905 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | - $groupby = [], |
|
| 907 | - $orderby = [], |
|
| 908 | - $limit = '', |
|
| 909 | - $having = [], |
|
| 910 | - $serveur |
|
| 911 | - ); |
|
| 912 | - if ($r !== null) { |
|
| 913 | - $id_parent = $r; |
|
| 914 | - } else { |
|
| 915 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | - 'titre' => $titre, |
|
| 917 | - 'id_parent' => $id_parent, |
|
| 918 | - 'statut' => 'prepa' |
|
| 919 | - ], $desc = [], $serveur); |
|
| 920 | - if ($id_parent > 0) { |
|
| 921 | - $data = sql_fetsel( |
|
| 922 | - 'id_secteur,lang', |
|
| 923 | - 'spip_rubriques', |
|
| 924 | - "id_rubrique=$id_parent", |
|
| 925 | - $groupby = [], |
|
| 926 | - $orderby = [], |
|
| 927 | - $limit = '', |
|
| 928 | - $having = [], |
|
| 929 | - $serveur |
|
| 930 | - ); |
|
| 931 | - $id_secteur = $data['id_secteur']; |
|
| 932 | - $lang = $data['lang']; |
|
| 933 | - } else { |
|
| 934 | - $id_secteur = $id_rubrique; |
|
| 935 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | - } |
|
| 937 | - |
|
| 938 | - sql_updateq( |
|
| 939 | - 'spip_rubriques', |
|
| 940 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | - [], |
|
| 943 | - $serveur |
|
| 944 | - ); |
|
| 945 | - |
|
| 946 | - // pour la recursion |
|
| 947 | - $id_parent = $id_rubrique; |
|
| 948 | - } |
|
| 949 | - } |
|
| 950 | - |
|
| 951 | - return intval($id_parent); |
|
| 894 | + // eclater l'arborescence demandee |
|
| 895 | + // echapper les </multi> et autres balises fermantes html |
|
| 896 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 897 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 898 | + include_spip('base/abstract_sql'); |
|
| 899 | + foreach ($arbo as $titre) { |
|
| 900 | + // retablir les </multi> et autres balises fermantes html |
|
| 901 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 902 | + $r = sql_getfetsel( |
|
| 903 | + 'id_rubrique', |
|
| 904 | + 'spip_rubriques', |
|
| 905 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 906 | + $groupby = [], |
|
| 907 | + $orderby = [], |
|
| 908 | + $limit = '', |
|
| 909 | + $having = [], |
|
| 910 | + $serveur |
|
| 911 | + ); |
|
| 912 | + if ($r !== null) { |
|
| 913 | + $id_parent = $r; |
|
| 914 | + } else { |
|
| 915 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 916 | + 'titre' => $titre, |
|
| 917 | + 'id_parent' => $id_parent, |
|
| 918 | + 'statut' => 'prepa' |
|
| 919 | + ], $desc = [], $serveur); |
|
| 920 | + if ($id_parent > 0) { |
|
| 921 | + $data = sql_fetsel( |
|
| 922 | + 'id_secteur,lang', |
|
| 923 | + 'spip_rubriques', |
|
| 924 | + "id_rubrique=$id_parent", |
|
| 925 | + $groupby = [], |
|
| 926 | + $orderby = [], |
|
| 927 | + $limit = '', |
|
| 928 | + $having = [], |
|
| 929 | + $serveur |
|
| 930 | + ); |
|
| 931 | + $id_secteur = $data['id_secteur']; |
|
| 932 | + $lang = $data['lang']; |
|
| 933 | + } else { |
|
| 934 | + $id_secteur = $id_rubrique; |
|
| 935 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 936 | + } |
|
| 937 | + |
|
| 938 | + sql_updateq( |
|
| 939 | + 'spip_rubriques', |
|
| 940 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 941 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 942 | + [], |
|
| 943 | + $serveur |
|
| 944 | + ); |
|
| 945 | + |
|
| 946 | + // pour la recursion |
|
| 947 | + $id_parent = $id_rubrique; |
|
| 948 | + } |
|
| 949 | + } |
|
| 950 | + |
|
| 951 | + return intval($id_parent); |
|
| 952 | 952 | } |
@@ -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 | include_spip('inc/presentation'); |
@@ -31,7 +31,7 @@ discard block |
||
| 31 | 31 | * @uses exec_puce_statut_args() |
| 32 | 32 | **/ |
| 33 | 33 | function exec_puce_statut_dist(): void { |
| 34 | - exec_puce_statut_args(_request('id'), _request('type')); |
|
| 34 | + exec_puce_statut_args(_request('id'), _request('type')); |
|
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | /** |
@@ -50,26 +50,26 @@ discard block |
||
| 50 | 50 | * Type d'objet |
| 51 | 51 | **/ |
| 52 | 52 | function exec_puce_statut_args($id, $type): void { |
| 53 | - $id = intval($id); |
|
| 54 | - if ( |
|
| 55 | - $table_objet_sql = table_objet_sql($type) |
|
| 56 | - and $d = lister_tables_objets_sql($table_objet_sql) |
|
| 57 | - and isset($d['statut_textes_instituer']) |
|
| 58 | - and $d['statut_textes_instituer'] |
|
| 59 | - ) { |
|
| 60 | - $prim = id_table_objet($type); |
|
| 61 | - if (isset($d['field']['id_rubrique'])) { |
|
| 62 | - $select = 'id_rubrique,statut'; |
|
| 63 | - } else { |
|
| 64 | - $select = '0 as id_rubrique,statut'; |
|
| 65 | - } |
|
| 66 | - $r = sql_fetsel($select, $table_objet_sql, "$prim=$id"); |
|
| 67 | - $statut = $r['statut']; |
|
| 68 | - $id_rubrique = $r['id_rubrique']; |
|
| 69 | - } else { |
|
| 70 | - $id_rubrique = $id; |
|
| 71 | - $statut = 'prop'; // arbitraire |
|
| 72 | - } |
|
| 73 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 74 | - ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true)); |
|
| 53 | + $id = intval($id); |
|
| 54 | + if ( |
|
| 55 | + $table_objet_sql = table_objet_sql($type) |
|
| 56 | + and $d = lister_tables_objets_sql($table_objet_sql) |
|
| 57 | + and isset($d['statut_textes_instituer']) |
|
| 58 | + and $d['statut_textes_instituer'] |
|
| 59 | + ) { |
|
| 60 | + $prim = id_table_objet($type); |
|
| 61 | + if (isset($d['field']['id_rubrique'])) { |
|
| 62 | + $select = 'id_rubrique,statut'; |
|
| 63 | + } else { |
|
| 64 | + $select = '0 as id_rubrique,statut'; |
|
| 65 | + } |
|
| 66 | + $r = sql_fetsel($select, $table_objet_sql, "$prim=$id"); |
|
| 67 | + $statut = $r['statut']; |
|
| 68 | + $id_rubrique = $r['id_rubrique']; |
|
| 69 | + } else { |
|
| 70 | + $id_rubrique = $id; |
|
| 71 | + $statut = 'prop'; // arbitraire |
|
| 72 | + } |
|
| 73 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 74 | + ajax_retour($puce_statut($id, $statut, $id_rubrique, $type, true)); |
|
| 75 | 75 | } |