@@ -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 |
| 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 = call_user_func_array($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 = call_user_func_array($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 = (isset($valeurs['_meta_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 = (isset($valeurs['_meta_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']) |
|
| 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']) |
|
| 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 | - list($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 | + list($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 | - list($table, $casier, $prefixe, $stockage) = cvtconf_definir_configurer_conteneur($form, $valeurs); |
|
| 252 | + list($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] = (isset($meta[$prefixe . $k]) ? $meta[$prefixe . $k] : null); |
|
| 267 | - } |
|
| 268 | - } |
|
| 264 | + foreach ($valeurs as $k => $v) { |
|
| 265 | + if (substr($k, 0, 1) !== '_') { |
|
| 266 | + $valeurs[$k] = (isset($meta[$prefixe . $k]) ? $meta[$prefixe . $k] : null); |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | ) { |
| 39 | 39 | // Pour tous les formulaires CONFIGURER, ayant une fonction charger ou pas, on teste si autorisé |
| 40 | 40 | include_spip('inc/autoriser'); |
| 41 | - if (!autoriser('configurer', '_' . substr($form, 11))) { |
|
| 41 | + if (!autoriser('configurer', '_'.substr($form, 11))) { |
|
| 42 | 42 | return false; |
| 43 | 43 | } |
| 44 | 44 | |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | and !charger_fonction('traiter', "formulaires/$form/", true) // sans fonction traiter() |
| 73 | 73 | ) { |
| 74 | 74 | $trace = cvtconf_formulaires_configurer_enregistre($form, $flux['args']['args']); |
| 75 | - $flux['data'] = ['message_ok' => _T('config_info_enregistree') . $trace, 'editable' => true]; |
|
| 75 | + $flux['data'] = ['message_ok' => _T('config_info_enregistree').$trace, 'editable' => true]; |
|
| 76 | 76 | } |
| 77 | 77 | |
| 78 | 78 | return $flux; |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | $prefixe = $valeurs['_meta_prefixe']; |
| 147 | 147 | } |
| 148 | 148 | if (isset($valeurs['_meta_stockage'])) { |
| 149 | - $stockage = $valeurs['_meta_stockage'] . '::'; |
|
| 149 | + $stockage = $valeurs['_meta_stockage'].'::'; |
|
| 150 | 150 | } |
| 151 | 151 | |
| 152 | 152 | // si on indique juste une table, il faut vider les autres proprietes |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | |
| 172 | 172 | // sinon cas analyse du squelette |
| 173 | 173 | if ( |
| 174 | - $f = find_in_path($form . '.' . _EXTENSION_SQUELETTES, 'formulaires/') |
|
| 174 | + $f = find_in_path($form.'.'._EXTENSION_SQUELETTES, 'formulaires/') |
|
| 175 | 175 | and lire_fichier($f, $contenu) |
| 176 | 176 | ) { |
| 177 | 177 | for ($i = 0; $i < 2; $i++) { |
@@ -228,14 +228,14 @@ discard block |
||
| 228 | 228 | lire_metas($table); |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 231 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 232 | 232 | $table = ($table) ? "/$table/" : ''; |
| 233 | - $casier = ($casier) ? rtrim($casier, '/') . '/' : ''; // slash final, sinon rien |
|
| 233 | + $casier = ($casier) ? rtrim($casier, '/').'/' : ''; // slash final, sinon rien |
|
| 234 | 234 | |
| 235 | 235 | foreach ($store as $k => $v) { |
| 236 | 236 | ecrire_config("$stockage$table$prefixe$casier$k", $v); |
| 237 | 237 | if (_request('var_mode') == 'configurer' and autoriser('webmestre')) { |
| 238 | - $trace .= "<br />table $table : " . $prefixe . $k . " = $v;"; |
|
| 238 | + $trace .= "<br />table $table : ".$prefixe.$k." = $v;"; |
|
| 239 | 239 | } |
| 240 | 240 | } |
| 241 | 241 | |
@@ -252,7 +252,7 @@ discard block |
||
| 252 | 252 | list($table, $casier, $prefixe, $stockage) = cvtconf_definir_configurer_conteneur($form, $valeurs); |
| 253 | 253 | |
| 254 | 254 | $table = ($table) ? "/$table/" : ''; |
| 255 | - $prefixe = ($prefixe ? $prefixe . '_' : ''); |
|
| 255 | + $prefixe = ($prefixe ? $prefixe.'_' : ''); |
|
| 256 | 256 | if ($casier) { |
| 257 | 257 | $meta = lire_config("$stockage$table$prefixe$casier"); |
| 258 | 258 | $prefixe = ''; |
@@ -263,7 +263,7 @@ discard block |
||
| 263 | 263 | |
| 264 | 264 | foreach ($valeurs as $k => $v) { |
| 265 | 265 | if (substr($k, 0, 1) !== '_') { |
| 266 | - $valeurs[$k] = (isset($meta[$prefixe . $k]) ? $meta[$prefixe . $k] : null); |
|
| 266 | + $valeurs[$k] = (isset($meta[$prefixe.$k]) ? $meta[$prefixe.$k] : null); |
|
| 267 | 267 | } |
| 268 | 268 | } |
| 269 | 269 | } |
@@ -18,18 +18,18 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | if (!defined('_ACTIVER_PUCE_RAPIDE')) { |
| 25 | - /** |
|
| 26 | - * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | - * |
|
| 28 | - * Peut ralentir un site sur des listes très longues. |
|
| 29 | - * |
|
| 30 | - * @var bool |
|
| 31 | - **/ |
|
| 32 | - define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 25 | + /** |
|
| 26 | + * Activer le changement rapide de statut sur les listes d'objets ? |
|
| 27 | + * |
|
| 28 | + * Peut ralentir un site sur des listes très longues. |
|
| 29 | + * |
|
| 30 | + * @var bool |
|
| 31 | + **/ |
|
| 32 | + define('_ACTIVER_PUCE_RAPIDE', true); |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | /** |
@@ -57,31 +57,31 @@ discard block |
||
| 57 | 57 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 58 | 58 | */ |
| 59 | 59 | function inc_puce_statut_dist( |
| 60 | - $id_objet, |
|
| 61 | - $statut, |
|
| 62 | - $id_parent, |
|
| 63 | - $type, |
|
| 64 | - $ajax = false, |
|
| 65 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 60 | + $id_objet, |
|
| 61 | + $statut, |
|
| 62 | + $id_parent, |
|
| 63 | + $type, |
|
| 64 | + $ajax = false, |
|
| 65 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 66 | 66 | ) { |
| 67 | - static $f_puce_statut = []; |
|
| 68 | - $type = objet_type($type); |
|
| 69 | - // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | - if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | - $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | - } |
|
| 73 | - if ($f_puce_statut[$type]) { |
|
| 74 | - return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | - } |
|
| 76 | - |
|
| 77 | - // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | - // composer une puce, avec si possible changement rapide |
|
| 79 | - elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | - return $puce; |
|
| 81 | - } // sinon fausse puce avec le type de l'image |
|
| 82 | - else { |
|
| 83 | - return http_img_pack("$type-16.png", ''); |
|
| 84 | - } |
|
| 67 | + static $f_puce_statut = []; |
|
| 68 | + $type = objet_type($type); |
|
| 69 | + // cas prioritaire : fonction perso, qui permet aussi de gerer les cas historiques |
|
| 70 | + if (!isset($f_puce_statut[$type]) or is_null($f_puce_statut[$type])) { |
|
| 71 | + $f_puce_statut[$type] = charger_fonction($type, 'puce_statut', true); |
|
| 72 | + } |
|
| 73 | + if ($f_puce_statut[$type]) { |
|
| 74 | + return $f_puce_statut[$type]($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide); |
|
| 75 | + } |
|
| 76 | + |
|
| 77 | + // si statut_image trouve quelque chose (et '' est quelque chose) |
|
| 78 | + // composer une puce, avec si possible changement rapide |
|
| 79 | + elseif (!is_null($puce = puce_statut_changement_rapide($id_objet, $statut, $id_parent, $type, $ajax, $menu_rapide))) { |
|
| 80 | + return $puce; |
|
| 81 | + } // sinon fausse puce avec le type de l'image |
|
| 82 | + else { |
|
| 83 | + return http_img_pack("$type-16.png", ''); |
|
| 84 | + } |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -110,41 +110,41 @@ discard block |
||
| 110 | 110 | * null si pas capable de déterminer l'image |
| 111 | 111 | */ |
| 112 | 112 | function statut_image($objet, $statut) { |
| 113 | - $src = null; |
|
| 114 | - $table = table_objet_sql($objet); |
|
| 115 | - $desc = lister_tables_objets_sql($table); |
|
| 116 | - if (isset($desc['statut_images'])) { |
|
| 117 | - // si une declaration statut_images |
|
| 118 | - // mais rien pour le statut demande, ne rien afficher |
|
| 119 | - $src = ''; |
|
| 120 | - if (isset($desc['statut_images'][$statut])) { |
|
| 121 | - $src = $desc['statut_images'][$statut]; |
|
| 122 | - } // sinon image par defaut ? |
|
| 123 | - elseif (isset($desc['statut_images'][0])) { |
|
| 124 | - $src = $desc['statut_images'][0]; |
|
| 125 | - } |
|
| 126 | - } else { |
|
| 127 | - switch ($statut) { |
|
| 128 | - case 'prepa': |
|
| 129 | - $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | - break; |
|
| 131 | - case 'prop': |
|
| 132 | - $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | - break; |
|
| 134 | - case 'publie': |
|
| 135 | - $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | - break; |
|
| 137 | - case 'refuse': |
|
| 138 | - $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | - break; |
|
| 140 | - case 'poubelle': |
|
| 141 | - case 'poub': |
|
| 142 | - $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | - break; |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - return $src; |
|
| 113 | + $src = null; |
|
| 114 | + $table = table_objet_sql($objet); |
|
| 115 | + $desc = lister_tables_objets_sql($table); |
|
| 116 | + if (isset($desc['statut_images'])) { |
|
| 117 | + // si une declaration statut_images |
|
| 118 | + // mais rien pour le statut demande, ne rien afficher |
|
| 119 | + $src = ''; |
|
| 120 | + if (isset($desc['statut_images'][$statut])) { |
|
| 121 | + $src = $desc['statut_images'][$statut]; |
|
| 122 | + } // sinon image par defaut ? |
|
| 123 | + elseif (isset($desc['statut_images'][0])) { |
|
| 124 | + $src = $desc['statut_images'][0]; |
|
| 125 | + } |
|
| 126 | + } else { |
|
| 127 | + switch ($statut) { |
|
| 128 | + case 'prepa': |
|
| 129 | + $src = 'puce-preparer-xx.svg?12px'; |
|
| 130 | + break; |
|
| 131 | + case 'prop': |
|
| 132 | + $src = 'puce-proposer-xx.svg?12px'; |
|
| 133 | + break; |
|
| 134 | + case 'publie': |
|
| 135 | + $src = 'puce-publier-xx.svg?12px'; |
|
| 136 | + break; |
|
| 137 | + case 'refuse': |
|
| 138 | + $src = 'puce-refuser-xx.svg?12px'; |
|
| 139 | + break; |
|
| 140 | + case 'poubelle': |
|
| 141 | + case 'poub': |
|
| 142 | + $src = 'puce-supprimer-xx.svg?12px'; |
|
| 143 | + break; |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + return $src; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -172,40 +172,40 @@ discard block |
||
| 172 | 172 | * @return string |
| 173 | 173 | */ |
| 174 | 174 | function statut_titre($objet, $statut) { |
| 175 | - $titre = ''; |
|
| 176 | - $table = table_objet_sql($objet); |
|
| 177 | - $desc = lister_tables_objets_sql($table); |
|
| 178 | - if (isset($desc['statut_titres'])) { |
|
| 179 | - // si une declaration statut_titres |
|
| 180 | - // mais rien pour le statut demande, ne rien afficher |
|
| 181 | - if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | - $titre = $desc['statut_titres'][$statut]; |
|
| 183 | - } // sinon image par defaut ? |
|
| 184 | - elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | - $titre = $desc['statut_titres'][0]; |
|
| 186 | - } |
|
| 187 | - } else { |
|
| 188 | - switch ($statut) { |
|
| 189 | - case 'prepa': |
|
| 190 | - $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | - break; |
|
| 192 | - case 'prop': |
|
| 193 | - $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | - break; |
|
| 195 | - case 'publie': |
|
| 196 | - $titre = 'texte_statut_publie'; |
|
| 197 | - break; |
|
| 198 | - case 'refuse': |
|
| 199 | - $titre = 'texte_statut_refuse'; |
|
| 200 | - break; |
|
| 201 | - case 'poubelle': |
|
| 202 | - case 'poub': |
|
| 203 | - $titre = 'texte_statut_poubelle'; |
|
| 204 | - break; |
|
| 205 | - } |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return $titre ? _T($titre) : ''; |
|
| 175 | + $titre = ''; |
|
| 176 | + $table = table_objet_sql($objet); |
|
| 177 | + $desc = lister_tables_objets_sql($table); |
|
| 178 | + if (isset($desc['statut_titres'])) { |
|
| 179 | + // si une declaration statut_titres |
|
| 180 | + // mais rien pour le statut demande, ne rien afficher |
|
| 181 | + if (isset($desc['statut_titres'][$statut])) { |
|
| 182 | + $titre = $desc['statut_titres'][$statut]; |
|
| 183 | + } // sinon image par defaut ? |
|
| 184 | + elseif (isset($desc['statut_titres'][0])) { |
|
| 185 | + $titre = $desc['statut_titres'][0]; |
|
| 186 | + } |
|
| 187 | + } else { |
|
| 188 | + switch ($statut) { |
|
| 189 | + case 'prepa': |
|
| 190 | + $titre = 'texte_statut_en_cours_redaction'; |
|
| 191 | + break; |
|
| 192 | + case 'prop': |
|
| 193 | + $titre = 'texte_statut_propose_evaluation'; |
|
| 194 | + break; |
|
| 195 | + case 'publie': |
|
| 196 | + $titre = 'texte_statut_publie'; |
|
| 197 | + break; |
|
| 198 | + case 'refuse': |
|
| 199 | + $titre = 'texte_statut_refuse'; |
|
| 200 | + break; |
|
| 201 | + case 'poubelle': |
|
| 202 | + case 'poub': |
|
| 203 | + $titre = 'texte_statut_poubelle'; |
|
| 204 | + break; |
|
| 205 | + } |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return $titre ? _T($titre) : ''; |
|
| 209 | 209 | } |
| 210 | 210 | |
| 211 | 211 | |
@@ -225,37 +225,37 @@ discard block |
||
| 225 | 225 | * @return string |
| 226 | 226 | */ |
| 227 | 227 | function statut_texte_instituer($objet, $statut) { |
| 228 | - $texte = ''; |
|
| 229 | - $table = table_objet_sql($objet); |
|
| 230 | - $desc = lister_tables_objets_sql($table); |
|
| 231 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | - // si une declaration statut_titres |
|
| 233 | - // mais rien pour le statut demande, ne rien afficher |
|
| 234 | - if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | - $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | - } |
|
| 237 | - } else { |
|
| 238 | - switch ($statut) { |
|
| 239 | - case 'prepa': |
|
| 240 | - $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | - break; |
|
| 242 | - case 'prop': |
|
| 243 | - $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | - break; |
|
| 245 | - case 'publie': |
|
| 246 | - $texte = 'texte_statut_publie'; |
|
| 247 | - break; |
|
| 248 | - case 'refuse': |
|
| 249 | - $texte = 'texte_statut_refuse'; |
|
| 250 | - break; |
|
| 251 | - case 'poubelle': |
|
| 252 | - case 'poub': |
|
| 253 | - $texte = 'texte_statut_poubelle'; |
|
| 254 | - break; |
|
| 255 | - } |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - return $texte ? _T($texte) : ''; |
|
| 228 | + $texte = ''; |
|
| 229 | + $table = table_objet_sql($objet); |
|
| 230 | + $desc = lister_tables_objets_sql($table); |
|
| 231 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 232 | + // si une declaration statut_titres |
|
| 233 | + // mais rien pour le statut demande, ne rien afficher |
|
| 234 | + if (isset($desc['statut_textes_instituer'][$statut])) { |
|
| 235 | + $texte = $desc['statut_textes_instituer'][$statut]; |
|
| 236 | + } |
|
| 237 | + } else { |
|
| 238 | + switch ($statut) { |
|
| 239 | + case 'prepa': |
|
| 240 | + $texte = 'texte_statut_en_cours_redaction'; |
|
| 241 | + break; |
|
| 242 | + case 'prop': |
|
| 243 | + $texte = 'texte_statut_propose_evaluation'; |
|
| 244 | + break; |
|
| 245 | + case 'publie': |
|
| 246 | + $texte = 'texte_statut_publie'; |
|
| 247 | + break; |
|
| 248 | + case 'refuse': |
|
| 249 | + $texte = 'texte_statut_refuse'; |
|
| 250 | + break; |
|
| 251 | + case 'poubelle': |
|
| 252 | + case 'poub': |
|
| 253 | + $texte = 'texte_statut_poubelle'; |
|
| 254 | + break; |
|
| 255 | + } |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + return $texte ? _T($texte) : ''; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -275,16 +275,16 @@ discard block |
||
| 275 | 275 | * @return string |
| 276 | 276 | */ |
| 277 | 277 | function puce_statut_auteur_dist($id, $statut, $id_parent, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 278 | - $img = statut_image('auteur', $statut); |
|
| 279 | - if (!$img) { |
|
| 280 | - return ''; |
|
| 281 | - } |
|
| 282 | - $alt = statut_titre('auteur', $statut); |
|
| 278 | + $img = statut_image('auteur', $statut); |
|
| 279 | + if (!$img) { |
|
| 280 | + return ''; |
|
| 281 | + } |
|
| 282 | + $alt = statut_titre('auteur', $statut); |
|
| 283 | 283 | |
| 284 | - $fond = ''; |
|
| 285 | - $titre = ''; |
|
| 284 | + $fond = ''; |
|
| 285 | + $titre = ''; |
|
| 286 | 286 | |
| 287 | - /* |
|
| 287 | + /* |
|
| 288 | 288 | if ($type != 'auteur') { |
| 289 | 289 | $img2 = chemin_image('del-16.png'); |
| 290 | 290 | $titre = _T('titre_image_redacteur'); |
@@ -294,12 +294,12 @@ discard block |
||
| 294 | 294 | } |
| 295 | 295 | */ |
| 296 | 296 | |
| 297 | - return http_img_pack($img, $alt, $fond, $alt); |
|
| 297 | + return http_img_pack($img, $alt, $fond, $alt); |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | |
| 301 | 301 | function puce_statut_rubrique_dist($id, $statut, $id_rubrique, $type, $ajax = '', $menu_rapide = _ACTIVER_PUCE_RAPIDE) { |
| 302 | - return http_img_pack('rubrique-16.png', ''); |
|
| 302 | + return http_img_pack('rubrique-16.png', ''); |
|
| 303 | 303 | } |
| 304 | 304 | |
| 305 | 305 | /** |
@@ -323,110 +323,110 @@ discard block |
||
| 323 | 323 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 324 | 324 | **/ |
| 325 | 325 | function puce_statut_changement_rapide( |
| 326 | - $id, |
|
| 327 | - $statut, |
|
| 328 | - $id_rubrique, |
|
| 329 | - $type = 'article', |
|
| 330 | - $ajax = false, |
|
| 331 | - $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 326 | + $id, |
|
| 327 | + $statut, |
|
| 328 | + $id_rubrique, |
|
| 329 | + $type = 'article', |
|
| 330 | + $ajax = false, |
|
| 331 | + $menu_rapide = _ACTIVER_PUCE_RAPIDE |
|
| 332 | 332 | ) { |
| 333 | - $src = statut_image($type, $statut); |
|
| 334 | - if (!$src) { |
|
| 335 | - return $src; |
|
| 336 | - } |
|
| 337 | - |
|
| 338 | - if ( |
|
| 339 | - !$id |
|
| 340 | - or !_SPIP_AJAX |
|
| 341 | - or !$menu_rapide |
|
| 342 | - ) { |
|
| 343 | - $ajax_node = ''; |
|
| 344 | - } else { |
|
| 345 | - $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | - } |
|
| 347 | - |
|
| 348 | - |
|
| 349 | - $t = statut_titre($type, $statut); |
|
| 350 | - $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | - |
|
| 352 | - if (!$ajax_node) { |
|
| 353 | - return $inser_puce; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - $table = table_objet_sql($type); |
|
| 357 | - $desc = lister_tables_objets_sql($table); |
|
| 358 | - if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | - return $inser_puce; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if (!function_exists('autoriser')) { |
|
| 363 | - include_spip('inc/autoriser'); |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | - if ($id_rubrique) { |
|
| 368 | - if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | - return $inser_puce; |
|
| 370 | - } |
|
| 371 | - } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | - else { |
|
| 373 | - if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | - return $inser_puce; |
|
| 375 | - } |
|
| 376 | - } |
|
| 377 | - |
|
| 378 | - $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | - if (!isset($coord[$statut])) { |
|
| 380 | - return $inser_puce; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | - ; |
|
| 385 | - $margin = 0; /* marge a gauche + droite */ |
|
| 386 | - $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | - ; |
|
| 388 | - $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | - |
|
| 390 | - if ($ajax) { |
|
| 391 | - $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 392 | - $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | - . $inser_puce |
|
| 394 | - . '</span>' |
|
| 395 | - . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | - $i = 0; |
|
| 397 | - foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | - $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | - } |
|
| 400 | - $out .= '</span>'; |
|
| 401 | - |
|
| 402 | - return $out; |
|
| 403 | - } else { |
|
| 404 | - $nom = 'puce_statut_'; |
|
| 405 | - $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | - $lang_dir = lang_dir(lang_typo()); |
|
| 407 | - |
|
| 408 | - return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | - . $inser_puce |
|
| 410 | - . '</span>'; |
|
| 411 | - } |
|
| 333 | + $src = statut_image($type, $statut); |
|
| 334 | + if (!$src) { |
|
| 335 | + return $src; |
|
| 336 | + } |
|
| 337 | + |
|
| 338 | + if ( |
|
| 339 | + !$id |
|
| 340 | + or !_SPIP_AJAX |
|
| 341 | + or !$menu_rapide |
|
| 342 | + ) { |
|
| 343 | + $ajax_node = ''; |
|
| 344 | + } else { |
|
| 345 | + $ajax_node = " class='imgstatut$type$id'"; |
|
| 346 | + } |
|
| 347 | + |
|
| 348 | + |
|
| 349 | + $t = statut_titre($type, $statut); |
|
| 350 | + $inser_puce = http_img_pack($src, $t, $ajax_node, $t); |
|
| 351 | + |
|
| 352 | + if (!$ajax_node) { |
|
| 353 | + return $inser_puce; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + $table = table_objet_sql($type); |
|
| 357 | + $desc = lister_tables_objets_sql($table); |
|
| 358 | + if (!isset($desc['statut_textes_instituer'])) { |
|
| 359 | + return $inser_puce; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if (!function_exists('autoriser')) { |
|
| 363 | + include_spip('inc/autoriser'); |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + // cas ou l'on a un parent connu (devrait disparaitre au profit du second cas plus generique) |
|
| 367 | + if ($id_rubrique) { |
|
| 368 | + if (!autoriser('publierdans', 'rubrique', $id_rubrique)) { |
|
| 369 | + return $inser_puce; |
|
| 370 | + } |
|
| 371 | + } // si pas d'id_rubrique fourni, tester directement instituer type avec le statut publie |
|
| 372 | + else { |
|
| 373 | + if (!autoriser('instituer', $type, $id, null, ['statut' => 'publie'])) { |
|
| 374 | + return $inser_puce; |
|
| 375 | + } |
|
| 376 | + } |
|
| 377 | + |
|
| 378 | + $coord = array_flip(array_keys($desc['statut_textes_instituer'])); |
|
| 379 | + if (!isset($coord[$statut])) { |
|
| 380 | + return $inser_puce; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + $unit = 18/*widh de img*/ + 0/*padding*/ |
|
| 384 | + ; |
|
| 385 | + $margin = 0; /* marge a gauche + droite */ |
|
| 386 | + $zero = 0 /*border*/ + $margin / 2 + 0 /*padding*/ |
|
| 387 | + ; |
|
| 388 | + $clip = $zero + ($unit * $coord[$statut]); |
|
| 389 | + |
|
| 390 | + if ($ajax) { |
|
| 391 | + $width = $unit * count($desc['statut_textes_instituer']) + $margin; |
|
| 392 | + $out = "<span class='puce_objet_fixe $type'>" |
|
| 393 | + . $inser_puce |
|
| 394 | + . '</span>' |
|
| 395 | + . "<span class='puce_objet_popup $type statutdecal$type$id' style='width:{$width}px;margin-left:-{$clip}px;'>"; |
|
| 396 | + $i = 0; |
|
| 397 | + foreach ($desc['statut_textes_instituer'] as $s => $t) { |
|
| 398 | + $out .= afficher_script_statut($id, $type, -$zero - $i++ * $unit, statut_image($type, $s), $s, _T($t)); |
|
| 399 | + } |
|
| 400 | + $out .= '</span>'; |
|
| 401 | + |
|
| 402 | + return $out; |
|
| 403 | + } else { |
|
| 404 | + $nom = 'puce_statut_'; |
|
| 405 | + $action = generer_url_ecrire('puce_statut', '', true); |
|
| 406 | + $lang_dir = lang_dir(lang_typo()); |
|
| 407 | + |
|
| 408 | + return "<span class='puce_objet $type' id='$nom$type$id' dir='$lang_dir' data-puce-nom='$nom' data-puce-type='$type' data-puce-id='$id' data-puce-action='$action'>" |
|
| 409 | + . $inser_puce |
|
| 410 | + . '</span>'; |
|
| 411 | + } |
|
| 412 | 412 | } |
| 413 | 413 | |
| 414 | 414 | |
| 415 | 415 | function afficher_script_statut($id, $type, $n, $img, $statut, $titre, $act = '') { |
| 416 | - $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | - $t = supprimer_tags($titre); |
|
| 416 | + $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
|
| 417 | + $t = supprimer_tags($titre); |
|
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
| 423 | 423 | // La couleur du statut |
| 424 | 424 | |
| 425 | 425 | function puce_statut($statut, $atts = '') { |
| 426 | - $src = statut_image('article', $statut); |
|
| 427 | - if (!$src) { |
|
| 428 | - return ''; |
|
| 429 | - } |
|
| 426 | + $src = statut_image('article', $statut); |
|
| 427 | + if (!$src) { |
|
| 428 | + return ''; |
|
| 429 | + } |
|
| 430 | 430 | |
| 431 | - return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 431 | + return http_img_pack($src, statut_titre('article', $statut), $atts); |
|
| 432 | 432 | } |
@@ -416,7 +416,7 @@ |
||
| 416 | 416 | $h = generer_action_auteur('instituer_objet', "$type-$id-$statut"); |
| 417 | 417 | $t = supprimer_tags($titre); |
| 418 | 418 | |
| 419 | - return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>" . http_img_pack($img, $t) . '</a>'; |
|
| 419 | + return "<a href=\"#\" data-puce-id=\"$id\" data-puce-type=\"$type\" data-puce-decal=\"$n\" data-puce-action=\"$h\" title=\"$t\"$act>".http_img_pack($img, $t).'</a>'; |
|
| 420 | 420 | } |
| 421 | 421 | |
| 422 | 422 | // compat |
@@ -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,64 +54,64 @@ 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 | - $neuf = false; |
|
| 58 | - |
|
| 59 | - // Compat avec l'ancienne signature |
|
| 60 | - if (is_string($infos)) { |
|
| 61 | - $infos = ['statut_ancien' => $infos]; |
|
| 62 | - } |
|
| 63 | - if (!isset($infos['statut_ancien'])) { |
|
| 64 | - $infos['statut_ancien'] = ''; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // On recherche quels statuts tester |
|
| 68 | - if ( |
|
| 69 | - isset($infos['objet']) |
|
| 70 | - and include_spip('inc/filtres') |
|
| 71 | - and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | - and is_array($declaration_statut) |
|
| 73 | - ) { |
|
| 74 | - foreach ($declaration_statut as $champ_statut) { |
|
| 75 | - if ($champ_statut['champ'] == 'statut') { |
|
| 76 | - $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | - break; // stop on a trouvé le bon champ |
|
| 78 | - } |
|
| 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) { // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 110 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - $langues = calculer_langues_utilisees(); |
|
| 114 | - ecrire_meta('langues_utilisees', $langues); |
|
| 57 | + $neuf = false; |
|
| 58 | + |
|
| 59 | + // Compat avec l'ancienne signature |
|
| 60 | + if (is_string($infos)) { |
|
| 61 | + $infos = ['statut_ancien' => $infos]; |
|
| 62 | + } |
|
| 63 | + if (!isset($infos['statut_ancien'])) { |
|
| 64 | + $infos['statut_ancien'] = ''; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // On recherche quels statuts tester |
|
| 68 | + if ( |
|
| 69 | + isset($infos['objet']) |
|
| 70 | + and include_spip('inc/filtres') |
|
| 71 | + and $declaration_statut = objet_info($infos['objet'], 'statut') |
|
| 72 | + and is_array($declaration_statut) |
|
| 73 | + ) { |
|
| 74 | + foreach ($declaration_statut as $champ_statut) { |
|
| 75 | + if ($champ_statut['champ'] == 'statut') { |
|
| 76 | + $statuts_publies = array_map('trim', explode(',', $champ_statut['publie'])); |
|
| 77 | + break; // stop on a trouvé le bon champ |
|
| 78 | + } |
|
| 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) { // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 110 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + $langues = calculer_langues_utilisees(); |
|
| 114 | + ecrire_meta('langues_utilisees', $langues); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | |
@@ -129,22 +129,22 @@ discard block |
||
| 129 | 129 | * true si le statut change effectivement |
| 130 | 130 | */ |
| 131 | 131 | function publier_branche_rubrique($id_rubrique) { |
| 132 | - $id_pred = $id_rubrique; |
|
| 133 | - while (true) { |
|
| 134 | - sql_updateq( |
|
| 135 | - 'spip_rubriques', |
|
| 136 | - ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 137 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 138 | - ); |
|
| 139 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 140 | - if (!$id_parent) { |
|
| 141 | - break; |
|
| 142 | - } |
|
| 143 | - $id_rubrique = $id_parent; |
|
| 144 | - } |
|
| 132 | + $id_pred = $id_rubrique; |
|
| 133 | + while (true) { |
|
| 134 | + sql_updateq( |
|
| 135 | + 'spip_rubriques', |
|
| 136 | + ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
|
| 137 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 138 | + ); |
|
| 139 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 140 | + if (!$id_parent) { |
|
| 141 | + break; |
|
| 142 | + } |
|
| 143 | + $id_rubrique = $id_parent; |
|
| 144 | + } |
|
| 145 | 145 | |
| 146 | 146 | # spip_log(" publier_branche_rubrique($id_rubrique $id_pred"); |
| 147 | - return $id_pred != $id_rubrique; |
|
| 147 | + return $id_pred != $id_rubrique; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -162,20 +162,20 @@ discard block |
||
| 162 | 162 | * true si le statut change effectivement |
| 163 | 163 | */ |
| 164 | 164 | function depublier_branche_rubrique_if($id_rubrique) { |
| 165 | - $date = date('Y-m-d H:i:s'); // figer la date |
|
| 166 | - |
|
| 167 | - # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 168 | - $id_pred = $id_rubrique; |
|
| 169 | - while ($id_pred) { |
|
| 170 | - if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 171 | - return $id_pred != $id_rubrique; |
|
| 172 | - } |
|
| 173 | - // passer au parent si on a depublie |
|
| 174 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 175 | - $id_pred = $r['id_parent']; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return $id_pred != $id_rubrique; |
|
| 165 | + $date = date('Y-m-d H:i:s'); // figer la date |
|
| 166 | + |
|
| 167 | + # spip_log("depublier_branche_rubrique($id_rubrique ?"); |
|
| 168 | + $id_pred = $id_rubrique; |
|
| 169 | + while ($id_pred) { |
|
| 170 | + if (!depublier_rubrique_if($id_pred, $date)) { |
|
| 171 | + return $id_pred != $id_rubrique; |
|
| 172 | + } |
|
| 173 | + // passer au parent si on a depublie |
|
| 174 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 175 | + $id_pred = $r['id_parent']; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return $id_pred != $id_rubrique; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | /** |
@@ -192,61 +192,61 @@ discard block |
||
| 192 | 192 | * true si la rubrique a été dépubliée |
| 193 | 193 | */ |
| 194 | 194 | function depublier_rubrique_if($id_rubrique, $date = null) { |
| 195 | - if (is_null($date)) { |
|
| 196 | - $date = date('Y-m-d H:i:s'); |
|
| 197 | - } |
|
| 198 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 199 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 200 | - |
|
| 201 | - if (!$id_rubrique = intval($id_rubrique)) { |
|
| 202 | - return false; |
|
| 203 | - } |
|
| 204 | - |
|
| 205 | - // verifier qu'elle existe et est bien publiee |
|
| 206 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 207 | - if (!$r or $r['statut'] !== 'publie') { |
|
| 208 | - return false; |
|
| 209 | - } |
|
| 210 | - |
|
| 211 | - // On met le nombre de chaque type d'enfants dans un tableau |
|
| 212 | - // Le type de l'objet est au pluriel |
|
| 213 | - $compte = [ |
|
| 214 | - 'articles' => sql_countsel( |
|
| 215 | - 'spip_articles', |
|
| 216 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 217 | - ), |
|
| 218 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 219 | - 'documents' => sql_countsel( |
|
| 220 | - 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 221 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | - ) |
|
| 223 | - ]; |
|
| 224 | - |
|
| 225 | - // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 226 | - $compte = pipeline( |
|
| 227 | - 'objet_compte_enfants', |
|
| 228 | - [ |
|
| 229 | - 'args' => [ |
|
| 230 | - 'objet' => 'rubrique', |
|
| 231 | - 'id_objet' => $id_rubrique, |
|
| 232 | - 'statut' => 'publie', |
|
| 233 | - 'date' => $date |
|
| 234 | - ], |
|
| 235 | - 'data' => $compte |
|
| 236 | - ] |
|
| 237 | - ); |
|
| 238 | - |
|
| 239 | - // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 240 | - foreach ($compte as $objet => $n) { |
|
| 241 | - if ($n) { |
|
| 242 | - return false; |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 195 | + if (is_null($date)) { |
|
| 196 | + $date = date('Y-m-d H:i:s'); |
|
| 197 | + } |
|
| 198 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 199 | + ' AND date <= ' . sql_quote($date) : ''; |
|
| 200 | + |
|
| 201 | + if (!$id_rubrique = intval($id_rubrique)) { |
|
| 202 | + return false; |
|
| 203 | + } |
|
| 204 | + |
|
| 205 | + // verifier qu'elle existe et est bien publiee |
|
| 206 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 207 | + if (!$r or $r['statut'] !== 'publie') { |
|
| 208 | + return false; |
|
| 209 | + } |
|
| 210 | + |
|
| 211 | + // On met le nombre de chaque type d'enfants dans un tableau |
|
| 212 | + // Le type de l'objet est au pluriel |
|
| 213 | + $compte = [ |
|
| 214 | + 'articles' => sql_countsel( |
|
| 215 | + 'spip_articles', |
|
| 216 | + 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 217 | + ), |
|
| 218 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 219 | + 'documents' => sql_countsel( |
|
| 220 | + 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
|
| 221 | + 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | + ) |
|
| 223 | + ]; |
|
| 224 | + |
|
| 225 | + // On passe le tableau des comptes dans un pipeline pour que les plugins puissent ajouter (ou retirer) des enfants |
|
| 226 | + $compte = pipeline( |
|
| 227 | + 'objet_compte_enfants', |
|
| 228 | + [ |
|
| 229 | + 'args' => [ |
|
| 230 | + 'objet' => 'rubrique', |
|
| 231 | + 'id_objet' => $id_rubrique, |
|
| 232 | + 'statut' => 'publie', |
|
| 233 | + 'date' => $date |
|
| 234 | + ], |
|
| 235 | + 'data' => $compte |
|
| 236 | + ] |
|
| 237 | + ); |
|
| 238 | + |
|
| 239 | + // S'il y a au moins un enfant de n'importe quoi, on ne dépublie pas |
|
| 240 | + foreach ($compte as $objet => $n) { |
|
| 241 | + if ($n) { |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 247 | 247 | |
| 248 | 248 | # spip_log("depublier_rubrique $id_pred"); |
| 249 | - return true; |
|
| 249 | + return true; |
|
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | |
@@ -269,18 +269,18 @@ discard block |
||
| 269 | 269 | **/ |
| 270 | 270 | function calculer_rubriques() { |
| 271 | 271 | |
| 272 | - calculer_rubriques_publiees(); |
|
| 272 | + calculer_rubriques_publiees(); |
|
| 273 | 273 | |
| 274 | - // Apres chaque (de)publication |
|
| 275 | - // recalculer les langues utilisees sur le site |
|
| 276 | - $langues = calculer_langues_utilisees(); |
|
| 277 | - ecrire_meta('langues_utilisees', $langues); |
|
| 274 | + // Apres chaque (de)publication |
|
| 275 | + // recalculer les langues utilisees sur le site |
|
| 276 | + $langues = calculer_langues_utilisees(); |
|
| 277 | + ecrire_meta('langues_utilisees', $langues); |
|
| 278 | 278 | |
| 279 | - // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 280 | - ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 279 | + // Sauver la date de la derniere mise a jour (pour menu_rubriques) |
|
| 280 | + ecrire_meta('date_calcul_rubriques', date('U')); |
|
| 281 | 281 | |
| 282 | - // on calcule la date du prochain article post-date |
|
| 283 | - calculer_prochain_postdate(); |
|
| 282 | + // on calcule la date du prochain article post-date |
|
| 283 | + calculer_prochain_postdate(); |
|
| 284 | 284 | } |
| 285 | 285 | |
| 286 | 286 | |
@@ -297,61 +297,61 @@ discard block |
||
| 297 | 297 | **/ |
| 298 | 298 | function calculer_rubriques_publiees() { |
| 299 | 299 | |
| 300 | - // Mettre les compteurs a zero |
|
| 301 | - sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 302 | - |
|
| 303 | - // |
|
| 304 | - // Publier et dater les rubriques qui ont un article publie |
|
| 305 | - // |
|
| 306 | - |
|
| 307 | - // Afficher les articles post-dates ? |
|
| 308 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 309 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | - |
|
| 311 | - $r = sql_select( |
|
| 312 | - 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 313 | - 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 314 | - "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 315 | - 'R.id_rubrique' |
|
| 316 | - ); |
|
| 317 | - while ($row = sql_fetch($r)) { |
|
| 318 | - sql_updateq( |
|
| 319 | - 'spip_rubriques', |
|
| 320 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 321 | - 'id_rubrique=' . intval($row['id']) |
|
| 322 | - ); |
|
| 323 | - } |
|
| 324 | - |
|
| 325 | - // point d'entree pour permettre a des plugins de gerer le statut |
|
| 326 | - // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 327 | - // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 328 | - // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 329 | - // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 330 | - pipeline('calculer_rubriques', null); |
|
| 331 | - |
|
| 332 | - |
|
| 333 | - // Les rubriques qui ont une rubrique fille plus recente |
|
| 334 | - // on tourne tant que les donnees remontent vers la racine. |
|
| 335 | - do { |
|
| 336 | - $continuer = false; |
|
| 337 | - $r = sql_select( |
|
| 338 | - 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 339 | - 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 340 | - "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 341 | - 'R.id_rubrique' |
|
| 342 | - ); |
|
| 343 | - while ($row = sql_fetch($r)) { |
|
| 344 | - sql_updateq( |
|
| 345 | - 'spip_rubriques', |
|
| 346 | - ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 347 | - 'id_rubrique=' . intval($row['id']) |
|
| 348 | - ); |
|
| 349 | - $continuer = true; |
|
| 350 | - } |
|
| 351 | - } while ($continuer); |
|
| 352 | - |
|
| 353 | - // Enregistrement des modifs |
|
| 354 | - sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 300 | + // Mettre les compteurs a zero |
|
| 301 | + sql_updateq('spip_rubriques', ['date_tmp' => '0000-00-00 00:00:00', 'statut_tmp' => 'prepa']); |
|
| 302 | + |
|
| 303 | + // |
|
| 304 | + // Publier et dater les rubriques qui ont un article publie |
|
| 305 | + // |
|
| 306 | + |
|
| 307 | + // Afficher les articles post-dates ? |
|
| 308 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 309 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | + |
|
| 311 | + $r = sql_select( |
|
| 312 | + 'R.id_rubrique AS id, max(A.date) AS date_h', |
|
| 313 | + 'spip_rubriques AS R JOIN spip_articles AS A ON R.id_rubrique = A.id_rubrique', |
|
| 314 | + "A.date>R.date_tmp AND A.statut='publie' $postdates ", |
|
| 315 | + 'R.id_rubrique' |
|
| 316 | + ); |
|
| 317 | + while ($row = sql_fetch($r)) { |
|
| 318 | + sql_updateq( |
|
| 319 | + 'spip_rubriques', |
|
| 320 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 321 | + 'id_rubrique=' . intval($row['id']) |
|
| 322 | + ); |
|
| 323 | + } |
|
| 324 | + |
|
| 325 | + // point d'entree pour permettre a des plugins de gerer le statut |
|
| 326 | + // autrement (par ex: toute rubrique est publiee des sa creation) |
|
| 327 | + // Ce pipeline fait ce qu'il veut, mais s'il touche aux statuts/dates |
|
| 328 | + // c'est statut_tmp/date_tmp qu'il doit modifier |
|
| 329 | + // [C'est un trigger... a renommer en trig_calculer_rubriques ?] |
|
| 330 | + pipeline('calculer_rubriques', null); |
|
| 331 | + |
|
| 332 | + |
|
| 333 | + // Les rubriques qui ont une rubrique fille plus recente |
|
| 334 | + // on tourne tant que les donnees remontent vers la racine. |
|
| 335 | + do { |
|
| 336 | + $continuer = false; |
|
| 337 | + $r = sql_select( |
|
| 338 | + 'R.id_rubrique AS id, max(SR.date_tmp) AS date_h', |
|
| 339 | + 'spip_rubriques AS R JOIN spip_rubriques AS SR ON R.id_rubrique = SR.id_parent', |
|
| 340 | + "(SR.date_tmp>R.date_tmp OR R.statut_tmp<>'publie') AND SR.statut_tmp='publie' ", |
|
| 341 | + 'R.id_rubrique' |
|
| 342 | + ); |
|
| 343 | + while ($row = sql_fetch($r)) { |
|
| 344 | + sql_updateq( |
|
| 345 | + 'spip_rubriques', |
|
| 346 | + ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
|
| 347 | + 'id_rubrique=' . intval($row['id']) |
|
| 348 | + ); |
|
| 349 | + $continuer = true; |
|
| 350 | + } |
|
| 351 | + } while ($continuer); |
|
| 352 | + |
|
| 353 | + // Enregistrement des modifs |
|
| 354 | + sql_update('spip_rubriques', ['date' => 'date_tmp', 'statut' => 'statut_tmp']); |
|
| 355 | 355 | } |
| 356 | 356 | |
| 357 | 357 | /** |
@@ -366,123 +366,123 @@ discard block |
||
| 366 | 366 | * @return void |
| 367 | 367 | **/ |
| 368 | 368 | function propager_les_secteurs() { |
| 369 | - // Profondeur 0 |
|
| 370 | - // Toutes les rubriques racines sont de profondeur 0 |
|
| 371 | - // et fixer les id_secteur des rubriques racines |
|
| 372 | - sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 373 | - // Toute rubrique non racine est de profondeur >0 |
|
| 374 | - sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 375 | - |
|
| 376 | - // securite : pas plus d'iteration que de rubriques dans la base |
|
| 377 | - $maxiter = sql_countsel('spip_rubriques'); |
|
| 378 | - |
|
| 379 | - // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 380 | - // on fait profondeur par profondeur |
|
| 381 | - |
|
| 382 | - $prof = 0; |
|
| 383 | - do { |
|
| 384 | - $continuer = false; |
|
| 385 | - |
|
| 386 | - // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 387 | - // on fixe le profondeur $prof+1 |
|
| 388 | - |
|
| 389 | - // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 390 | - // on teste A.profondeur > $prof+1 car : |
|
| 391 | - // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 392 | - // - si A.profondeur = $prof+1 c'est bon |
|
| 393 | - // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 394 | - $maxiter2 = $maxiter; |
|
| 395 | - while ( |
|
| 396 | - $maxiter2-- |
|
| 397 | - and $rows = sql_allfetsel( |
|
| 398 | - 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 399 | - 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 400 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | - '', |
|
| 402 | - 'R.id_secteur', |
|
| 403 | - '0,100' |
|
| 404 | - ) |
|
| 405 | - ) { |
|
| 406 | - $id_secteur = null; |
|
| 407 | - $ids = []; |
|
| 408 | - while ($row = array_shift($rows)) { |
|
| 409 | - if ($row['id_secteur'] !== $id_secteur) { |
|
| 410 | - if (count($ids)) { |
|
| 411 | - sql_updateq( |
|
| 412 | - 'spip_rubriques', |
|
| 413 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 414 | - sql_in('id_rubrique', $ids) |
|
| 415 | - ); |
|
| 416 | - } |
|
| 417 | - $id_secteur = $row['id_secteur']; |
|
| 418 | - $ids = []; |
|
| 419 | - } |
|
| 420 | - $ids[] = $row['id']; |
|
| 421 | - } |
|
| 422 | - if (count($ids)) { |
|
| 423 | - sql_updateq( |
|
| 424 | - 'spip_rubriques', |
|
| 425 | - ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 426 | - sql_in('id_rubrique', $ids) |
|
| 427 | - ); |
|
| 428 | - } |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - |
|
| 432 | - // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 433 | - $maxiter2 = $maxiter; |
|
| 434 | - while ( |
|
| 435 | - $maxiter2-- |
|
| 436 | - and $rows = sql_allfetsel( |
|
| 437 | - 'id_rubrique as id', |
|
| 438 | - 'spip_rubriques', |
|
| 439 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 440 | - 'zzz.id_rubrique', |
|
| 441 | - 'spip_rubriques AS zzz', |
|
| 442 | - 'zzz.profondeur=' . intval($prof) |
|
| 443 | - ) . ')', |
|
| 444 | - '', |
|
| 445 | - '', |
|
| 446 | - '0,100' |
|
| 447 | - ) |
|
| 448 | - ) { |
|
| 449 | - $rows = array_column($rows, 'id'); |
|
| 450 | - sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 454 | - // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 455 | - // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 456 | - // on arrete les frais |
|
| 457 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 458 | - $prof++; |
|
| 459 | - $continuer = true; |
|
| 460 | - } |
|
| 461 | - } while ($continuer and $maxiter--); |
|
| 462 | - |
|
| 463 | - // loger si la table des rubriques semble foireuse |
|
| 464 | - // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 465 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 466 | - spip_log( |
|
| 467 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | - _LOG_CRITIQUE |
|
| 469 | - ); |
|
| 470 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | - } |
|
| 472 | - |
|
| 473 | - // reparer les articles |
|
| 474 | - $r = sql_select( |
|
| 475 | - 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | - 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | - ); |
|
| 479 | - |
|
| 480 | - while ($row = sql_fetch($r)) { |
|
| 481 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | - } |
|
| 483 | - |
|
| 484 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | - pipeline('trig_propager_les_secteurs', ''); |
|
| 369 | + // Profondeur 0 |
|
| 370 | + // Toutes les rubriques racines sont de profondeur 0 |
|
| 371 | + // et fixer les id_secteur des rubriques racines |
|
| 372 | + sql_update('spip_rubriques', ['id_secteur' => 'id_rubrique', 'profondeur' => 0], 'id_parent=0'); |
|
| 373 | + // Toute rubrique non racine est de profondeur >0 |
|
| 374 | + sql_updateq('spip_rubriques', ['profondeur' => 1], 'id_parent<>0 AND profondeur=0'); |
|
| 375 | + |
|
| 376 | + // securite : pas plus d'iteration que de rubriques dans la base |
|
| 377 | + $maxiter = sql_countsel('spip_rubriques'); |
|
| 378 | + |
|
| 379 | + // reparer les rubriques qui n'ont pas l'id_secteur de leur parent |
|
| 380 | + // on fait profondeur par profondeur |
|
| 381 | + |
|
| 382 | + $prof = 0; |
|
| 383 | + do { |
|
| 384 | + $continuer = false; |
|
| 385 | + |
|
| 386 | + // Par recursivite : si toutes les rubriques de profondeur $prof sont bonnes |
|
| 387 | + // on fixe le profondeur $prof+1 |
|
| 388 | + |
|
| 389 | + // Toutes les rubriques dont le parent est de profondeur $prof ont une profondeur $prof+1 |
|
| 390 | + // on teste A.profondeur > $prof+1 car : |
|
| 391 | + // - toutes les rubriques de profondeur 0 à $prof sont bonnes |
|
| 392 | + // - si A.profondeur = $prof+1 c'est bon |
|
| 393 | + // - cela nous protege de la boucle infinie en cas de reference circulaire dans les rubriques |
|
| 394 | + $maxiter2 = $maxiter; |
|
| 395 | + while ( |
|
| 396 | + $maxiter2-- |
|
| 397 | + and $rows = sql_allfetsel( |
|
| 398 | + 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
|
| 399 | + 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
|
| 400 | + 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | + '', |
|
| 402 | + 'R.id_secteur', |
|
| 403 | + '0,100' |
|
| 404 | + ) |
|
| 405 | + ) { |
|
| 406 | + $id_secteur = null; |
|
| 407 | + $ids = []; |
|
| 408 | + while ($row = array_shift($rows)) { |
|
| 409 | + if ($row['id_secteur'] !== $id_secteur) { |
|
| 410 | + if (count($ids)) { |
|
| 411 | + sql_updateq( |
|
| 412 | + 'spip_rubriques', |
|
| 413 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 414 | + sql_in('id_rubrique', $ids) |
|
| 415 | + ); |
|
| 416 | + } |
|
| 417 | + $id_secteur = $row['id_secteur']; |
|
| 418 | + $ids = []; |
|
| 419 | + } |
|
| 420 | + $ids[] = $row['id']; |
|
| 421 | + } |
|
| 422 | + if (count($ids)) { |
|
| 423 | + sql_updateq( |
|
| 424 | + 'spip_rubriques', |
|
| 425 | + ['id_secteur' => $id_secteur, 'profondeur' => $prof + 1], |
|
| 426 | + sql_in('id_rubrique', $ids) |
|
| 427 | + ); |
|
| 428 | + } |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + |
|
| 432 | + // Toutes les rubriques de profondeur $prof+1 qui n'ont pas un parent de profondeur $prof sont decalees |
|
| 433 | + $maxiter2 = $maxiter; |
|
| 434 | + while ( |
|
| 435 | + $maxiter2-- |
|
| 436 | + and $rows = sql_allfetsel( |
|
| 437 | + 'id_rubrique as id', |
|
| 438 | + 'spip_rubriques', |
|
| 439 | + 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 440 | + 'zzz.id_rubrique', |
|
| 441 | + 'spip_rubriques AS zzz', |
|
| 442 | + 'zzz.profondeur=' . intval($prof) |
|
| 443 | + ) . ')', |
|
| 444 | + '', |
|
| 445 | + '', |
|
| 446 | + '0,100' |
|
| 447 | + ) |
|
| 448 | + ) { |
|
| 449 | + $rows = array_column($rows, 'id'); |
|
| 450 | + sql_updateq('spip_rubriques', ['profondeur' => $prof + 2], sql_in('id_rubrique', $rows)); |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // ici on a fini de valider $prof+1, toutes les rubriques de prondeur 0 a $prof+1 sont OK |
|
| 454 | + // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
|
| 455 | + // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
|
| 456 | + // on arrete les frais |
|
| 457 | + if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 458 | + $prof++; |
|
| 459 | + $continuer = true; |
|
| 460 | + } |
|
| 461 | + } while ($continuer and $maxiter--); |
|
| 462 | + |
|
| 463 | + // loger si la table des rubriques semble foireuse |
|
| 464 | + // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
|
| 465 | + if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 466 | + spip_log( |
|
| 467 | + 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | + _LOG_CRITIQUE |
|
| 469 | + ); |
|
| 470 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 471 | + } |
|
| 472 | + |
|
| 473 | + // reparer les articles |
|
| 474 | + $r = sql_select( |
|
| 475 | + 'A.id_article AS id, R.id_secteur AS secteur', |
|
| 476 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 477 | + 'A.id_rubrique = R.id_rubrique AND A.id_secteur <> R.id_secteur' |
|
| 478 | + ); |
|
| 479 | + |
|
| 480 | + while ($row = sql_fetch($r)) { |
|
| 481 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 482 | + } |
|
| 483 | + |
|
| 484 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 485 | + pipeline('trig_propager_les_secteurs', ''); |
|
| 486 | 486 | } |
| 487 | 487 | |
| 488 | 488 | |
@@ -497,23 +497,23 @@ discard block |
||
| 497 | 497 | * true si un changement a eu lieu |
| 498 | 498 | **/ |
| 499 | 499 | function calculer_langues_rubriques_etape() { |
| 500 | - $s = sql_select( |
|
| 501 | - 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | - 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | - "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | - ); |
|
| 505 | - |
|
| 506 | - $t = false; |
|
| 507 | - while ($row = sql_fetch($s)) { |
|
| 508 | - $id_rubrique = $row['id_rubrique']; |
|
| 509 | - $t = sql_updateq( |
|
| 510 | - 'spip_rubriques', |
|
| 511 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | - ); |
|
| 514 | - } |
|
| 515 | - |
|
| 516 | - return $t; |
|
| 500 | + $s = sql_select( |
|
| 501 | + 'A.id_rubrique AS id_rubrique, R.lang AS lang', |
|
| 502 | + 'spip_rubriques AS A, spip_rubriques AS R', |
|
| 503 | + "A.id_parent = R.id_rubrique AND A.langue_choisie != 'oui' AND R.lang<>'' AND R.lang<>A.lang" |
|
| 504 | + ); |
|
| 505 | + |
|
| 506 | + $t = false; |
|
| 507 | + while ($row = sql_fetch($s)) { |
|
| 508 | + $id_rubrique = $row['id_rubrique']; |
|
| 509 | + $t = sql_updateq( |
|
| 510 | + 'spip_rubriques', |
|
| 511 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 512 | + 'id_rubrique=' . intval($id_rubrique) |
|
| 513 | + ); |
|
| 514 | + } |
|
| 515 | + |
|
| 516 | + return $t; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -533,38 +533,38 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function calculer_langues_rubriques() { |
| 535 | 535 | |
| 536 | - // rubriques (recursivite) |
|
| 537 | - sql_updateq( |
|
| 538 | - 'spip_rubriques', |
|
| 539 | - ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | - "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | - ); |
|
| 542 | - while (calculer_langues_rubriques_etape()) { |
|
| 543 | - ; |
|
| 544 | - } |
|
| 545 | - |
|
| 546 | - // articles |
|
| 547 | - $s = sql_select( |
|
| 548 | - 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | - 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | - "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" |
|
| 551 | - ); |
|
| 552 | - while ($row = sql_fetch($s)) { |
|
| 553 | - $id_article = $row['id_article']; |
|
| 554 | - sql_updateq( |
|
| 555 | - 'spip_articles', |
|
| 556 | - ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | - 'id_article=' . intval($id_article) |
|
| 558 | - ); |
|
| 559 | - } |
|
| 560 | - |
|
| 561 | - if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | - $langues = calculer_langues_utilisees(); |
|
| 563 | - ecrire_meta('langues_utilisees', $langues); |
|
| 564 | - } |
|
| 565 | - |
|
| 566 | - // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | - pipeline('trig_calculer_langues_rubriques', ''); |
|
| 536 | + // rubriques (recursivite) |
|
| 537 | + sql_updateq( |
|
| 538 | + 'spip_rubriques', |
|
| 539 | + ['lang' => $GLOBALS['meta']['langue_site'], 'langue_choisie' => 'non'], |
|
| 540 | + "id_parent=0 AND langue_choisie != 'oui'" |
|
| 541 | + ); |
|
| 542 | + while (calculer_langues_rubriques_etape()) { |
|
| 543 | + ; |
|
| 544 | + } |
|
| 545 | + |
|
| 546 | + // articles |
|
| 547 | + $s = sql_select( |
|
| 548 | + 'A.id_article AS id_article, R.lang AS lang', |
|
| 549 | + 'spip_articles AS A, spip_rubriques AS R', |
|
| 550 | + "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" |
|
| 551 | + ); |
|
| 552 | + while ($row = sql_fetch($s)) { |
|
| 553 | + $id_article = $row['id_article']; |
|
| 554 | + sql_updateq( |
|
| 555 | + 'spip_articles', |
|
| 556 | + ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
|
| 557 | + 'id_article=' . intval($id_article) |
|
| 558 | + ); |
|
| 559 | + } |
|
| 560 | + |
|
| 561 | + if ($GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 562 | + $langues = calculer_langues_utilisees(); |
|
| 563 | + ecrire_meta('langues_utilisees', $langues); |
|
| 564 | + } |
|
| 565 | + |
|
| 566 | + // avertir les plugins qui peuvent faire leur mises a jour egalement |
|
| 567 | + pipeline('trig_calculer_langues_rubriques', ''); |
|
| 568 | 568 | } |
| 569 | 569 | |
| 570 | 570 | |
@@ -581,80 +581,80 @@ discard block |
||
| 581 | 581 | * Liste des langues utilisées séparées par des virgules |
| 582 | 582 | **/ |
| 583 | 583 | function calculer_langues_utilisees($serveur = '') { |
| 584 | - include_spip('public/interfaces'); |
|
| 585 | - include_spip('public/compiler'); |
|
| 586 | - include_spip('public/composer'); |
|
| 587 | - include_spip('public/phraser_html'); |
|
| 588 | - $langues = []; |
|
| 589 | - |
|
| 590 | - $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | - |
|
| 592 | - include_spip('base/objets'); |
|
| 593 | - $tables = lister_tables_objets_sql(); |
|
| 594 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | - |
|
| 596 | - foreach (array_keys($tables) as $t) { |
|
| 597 | - $desc = $trouver_table($t, $serveur); |
|
| 598 | - // c'est une table avec des langues |
|
| 599 | - if ( |
|
| 600 | - $desc['exist'] |
|
| 601 | - and isset($desc['field']['lang']) |
|
| 602 | - and isset($desc['field']['langue_choisie']) |
|
| 603 | - ) { |
|
| 604 | - $boucle = new Boucle(); |
|
| 605 | - $boucle->show = $desc; |
|
| 606 | - $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | - $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | - $boucle->id_table = $desc['table_objet']; |
|
| 609 | - $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | - $boucle->sql_serveur = $serveur; |
|
| 611 | - $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | - $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | - $boucle->separateur[] = ','; |
|
| 614 | - $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | - $boucle->iterateur = 'sql'; |
|
| 616 | - |
|
| 617 | - $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | - $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | - $boucle->descr['gram'] = 'html'; |
|
| 620 | - |
|
| 621 | - $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | - |
|
| 623 | - if ( |
|
| 624 | - isset($desc['statut']) |
|
| 625 | - and $desc['statut'] |
|
| 626 | - ) { |
|
| 627 | - $boucles = [ |
|
| 628 | - 'calculer_langues_utilisees' => $boucle, |
|
| 629 | - ]; |
|
| 630 | - // generer un nom de fonction "anonyme" unique |
|
| 631 | - do { |
|
| 632 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 633 | - } while (function_exists($functionname)); |
|
| 634 | - $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | - $res = ''; |
|
| 638 | - eval($code); |
|
| 639 | - $res = explode(',', $res); |
|
| 640 | - foreach ($res as $lang) { |
|
| 641 | - $langues[$lang] = 1; |
|
| 642 | - } |
|
| 643 | - } else { |
|
| 644 | - $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | - while ($row = sql_fetch($res)) { |
|
| 646 | - $langues[$row['lang']] = 1; |
|
| 647 | - } |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - } |
|
| 651 | - |
|
| 652 | - $langues = array_filter(array_keys($langues)); |
|
| 653 | - sort($langues); |
|
| 654 | - $langues = join(',', $langues); |
|
| 655 | - spip_log("langues utilisees: $langues"); |
|
| 656 | - |
|
| 657 | - return $langues; |
|
| 584 | + include_spip('public/interfaces'); |
|
| 585 | + include_spip('public/compiler'); |
|
| 586 | + include_spip('public/composer'); |
|
| 587 | + include_spip('public/phraser_html'); |
|
| 588 | + $langues = []; |
|
| 589 | + |
|
| 590 | + $langues[$GLOBALS['meta']['langue_site']] = 1; |
|
| 591 | + |
|
| 592 | + include_spip('base/objets'); |
|
| 593 | + $tables = lister_tables_objets_sql(); |
|
| 594 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 595 | + |
|
| 596 | + foreach (array_keys($tables) as $t) { |
|
| 597 | + $desc = $trouver_table($t, $serveur); |
|
| 598 | + // c'est une table avec des langues |
|
| 599 | + if ( |
|
| 600 | + $desc['exist'] |
|
| 601 | + and isset($desc['field']['lang']) |
|
| 602 | + and isset($desc['field']['langue_choisie']) |
|
| 603 | + ) { |
|
| 604 | + $boucle = new Boucle(); |
|
| 605 | + $boucle->show = $desc; |
|
| 606 | + $boucle->nom = 'calculer_langues_utilisees'; |
|
| 607 | + $boucle->id_boucle = $desc['table_objet']; |
|
| 608 | + $boucle->id_table = $desc['table_objet']; |
|
| 609 | + $boucle->primary = $desc['key']['PRIMARY KEY'] ?? ''; |
|
| 610 | + $boucle->sql_serveur = $serveur; |
|
| 611 | + $boucle->select[] = 'DISTINCT lang'; |
|
| 612 | + $boucle->from[$desc['table_objet']] = $t; |
|
| 613 | + $boucle->separateur[] = ','; |
|
| 614 | + $boucle->return = '$Pile[$SP][\'lang\']'; |
|
| 615 | + $boucle->iterateur = 'sql'; |
|
| 616 | + |
|
| 617 | + $boucle->descr['nom'] = 'calculer_langues_utilisees'; // eviter notice php |
|
| 618 | + $boucle->descr['sourcefile'] = 'internal'; |
|
| 619 | + $boucle->descr['gram'] = 'html'; |
|
| 620 | + |
|
| 621 | + $boucle = pipeline('pre_boucle', $boucle); |
|
| 622 | + |
|
| 623 | + if ( |
|
| 624 | + isset($desc['statut']) |
|
| 625 | + and $desc['statut'] |
|
| 626 | + ) { |
|
| 627 | + $boucles = [ |
|
| 628 | + 'calculer_langues_utilisees' => $boucle, |
|
| 629 | + ]; |
|
| 630 | + // generer un nom de fonction "anonyme" unique |
|
| 631 | + do { |
|
| 632 | + $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 633 | + } while (function_exists($functionname)); |
|
| 634 | + $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
|
| 635 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | + $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 637 | + $res = ''; |
|
| 638 | + eval($code); |
|
| 639 | + $res = explode(',', $res); |
|
| 640 | + foreach ($res as $lang) { |
|
| 641 | + $langues[$lang] = 1; |
|
| 642 | + } |
|
| 643 | + } else { |
|
| 644 | + $res = sql_select(implode(',', $boucle->select), $boucle->from); |
|
| 645 | + while ($row = sql_fetch($res)) { |
|
| 646 | + $langues[$row['lang']] = 1; |
|
| 647 | + } |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + } |
|
| 651 | + |
|
| 652 | + $langues = array_filter(array_keys($langues)); |
|
| 653 | + sort($langues); |
|
| 654 | + $langues = join(',', $langues); |
|
| 655 | + spip_log("langues utilisees: $langues"); |
|
| 656 | + |
|
| 657 | + return $langues; |
|
| 658 | 658 | } |
| 659 | 659 | |
| 660 | 660 | /** |
@@ -671,9 +671,9 @@ discard block |
||
| 671 | 671 | * incluant les rubriques noeuds et toutes leurs descendances |
| 672 | 672 | */ |
| 673 | 673 | function calcul_branche_in($id) { |
| 674 | - $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 674 | + $calcul_branche_in = charger_fonction('calcul_branche_in', 'inc'); |
|
| 675 | 675 | |
| 676 | - return $calcul_branche_in($id); |
|
| 676 | + return $calcul_branche_in($id); |
|
| 677 | 677 | } |
| 678 | 678 | |
| 679 | 679 | /** |
@@ -691,9 +691,9 @@ discard block |
||
| 691 | 691 | * incluant les rubriques transmises et toutes leurs parentées |
| 692 | 692 | */ |
| 693 | 693 | function calcul_hierarchie_in($id, $tout = true) { |
| 694 | - $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 694 | + $calcul_hierarchie_in = charger_fonction('calcul_hierarchie_in', 'inc'); |
|
| 695 | 695 | |
| 696 | - return $calcul_hierarchie_in($id, $tout); |
|
| 696 | + return $calcul_hierarchie_in($id, $tout); |
|
| 697 | 697 | } |
| 698 | 698 | |
| 699 | 699 | |
@@ -714,40 +714,40 @@ discard block |
||
| 714 | 714 | * incluant les rubriques noeuds et toutes leurs descendances |
| 715 | 715 | */ |
| 716 | 716 | function inc_calcul_branche_in_dist($id) { |
| 717 | - static $b = []; |
|
| 718 | - |
|
| 719 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | - if (!is_array($id)) { |
|
| 721 | - $id = explode(',', $id); |
|
| 722 | - } |
|
| 723 | - $id = join(',', array_map('intval', $id)); |
|
| 724 | - if (isset($b[$id])) { |
|
| 725 | - return $b[$id]; |
|
| 726 | - } |
|
| 727 | - |
|
| 728 | - // Notre branche commence par la rubrique de depart |
|
| 729 | - $branche = $r = $id; |
|
| 730 | - |
|
| 731 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | - $maxiter = 10000; |
|
| 734 | - while ( |
|
| 735 | - $maxiter-- and $filles = sql_allfetsel( |
|
| 736 | - 'id_rubrique', |
|
| 737 | - 'spip_rubriques', |
|
| 738 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | - ) |
|
| 740 | - ) { |
|
| 741 | - $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | - $branche .= ',' . $r; |
|
| 743 | - } |
|
| 744 | - |
|
| 745 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | - if (strlen($branche) < 10000) { |
|
| 747 | - $b[$id] = $branche; |
|
| 748 | - } |
|
| 749 | - |
|
| 750 | - return $branche; |
|
| 717 | + static $b = []; |
|
| 718 | + |
|
| 719 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 720 | + if (!is_array($id)) { |
|
| 721 | + $id = explode(',', $id); |
|
| 722 | + } |
|
| 723 | + $id = join(',', array_map('intval', $id)); |
|
| 724 | + if (isset($b[$id])) { |
|
| 725 | + return $b[$id]; |
|
| 726 | + } |
|
| 727 | + |
|
| 728 | + // Notre branche commence par la rubrique de depart |
|
| 729 | + $branche = $r = $id; |
|
| 730 | + |
|
| 731 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 732 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 733 | + $maxiter = 10000; |
|
| 734 | + while ( |
|
| 735 | + $maxiter-- and $filles = sql_allfetsel( |
|
| 736 | + 'id_rubrique', |
|
| 737 | + 'spip_rubriques', |
|
| 738 | + sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | + ) |
|
| 740 | + ) { |
|
| 741 | + $r = join(',', array_column($filles, 'id_rubrique')); |
|
| 742 | + $branche .= ',' . $r; |
|
| 743 | + } |
|
| 744 | + |
|
| 745 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 746 | + if (strlen($branche) < 10000) { |
|
| 747 | + $b[$id] = $branche; |
|
| 748 | + } |
|
| 749 | + |
|
| 750 | + return $branche; |
|
| 751 | 751 | } |
| 752 | 752 | |
| 753 | 753 | |
@@ -769,45 +769,45 @@ discard block |
||
| 769 | 769 | * incluant les rubriques transmises et toutes leurs parentées |
| 770 | 770 | */ |
| 771 | 771 | function inc_calcul_hierarchie_in_dist($id, $tout = true) { |
| 772 | - static $b = []; |
|
| 773 | - |
|
| 774 | - // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | - if (!is_array($id)) { |
|
| 776 | - $id = explode(',', $id); |
|
| 777 | - } |
|
| 778 | - $id = join(',', array_map('intval', $id)); |
|
| 779 | - |
|
| 780 | - if (isset($b[$id])) { |
|
| 781 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | - } |
|
| 784 | - |
|
| 785 | - $hier = ''; |
|
| 786 | - |
|
| 787 | - // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | - // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | - $ids_nouveaux_parents = $id; |
|
| 790 | - $maxiter = 10000; |
|
| 791 | - while ( |
|
| 792 | - $maxiter-- and $parents = sql_allfetsel( |
|
| 793 | - 'id_parent', |
|
| 794 | - 'spip_rubriques', |
|
| 795 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | - ) |
|
| 797 | - ) { |
|
| 798 | - $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | - } |
|
| 801 | - |
|
| 802 | - # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | - if (strlen($hier) < 10000) { |
|
| 804 | - $b[$id] = $hier; |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | - $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | - |
|
| 810 | - return $hier; |
|
| 772 | + static $b = []; |
|
| 773 | + |
|
| 774 | + // normaliser $id qui a pu arriver comme un array, comme un entier, ou comme une chaine NN,NN,NN |
|
| 775 | + if (!is_array($id)) { |
|
| 776 | + $id = explode(',', $id); |
|
| 777 | + } |
|
| 778 | + $id = join(',', array_map('intval', $id)); |
|
| 779 | + |
|
| 780 | + if (isset($b[$id])) { |
|
| 781 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 782 | + return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 783 | + } |
|
| 784 | + |
|
| 785 | + $hier = ''; |
|
| 786 | + |
|
| 787 | + // On ajoute une generation (les filles de la generation precedente) |
|
| 788 | + // jusqu'a epuisement, en se protegeant des references circulaires |
|
| 789 | + $ids_nouveaux_parents = $id; |
|
| 790 | + $maxiter = 10000; |
|
| 791 | + while ( |
|
| 792 | + $maxiter-- and $parents = sql_allfetsel( |
|
| 793 | + 'id_parent', |
|
| 794 | + 'spip_rubriques', |
|
| 795 | + sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 796 | + ) |
|
| 797 | + ) { |
|
| 798 | + $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
|
| 799 | + $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 800 | + } |
|
| 801 | + |
|
| 802 | + # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
|
| 803 | + if (strlen($hier) < 10000) { |
|
| 804 | + $b[$id] = $hier; |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + // Notre branche commence par la rubrique de depart si $tout=true |
|
| 808 | + $hier = $tout ? (strlen($hier) ? "$hier,$id" : $id) : $hier; |
|
| 809 | + |
|
| 810 | + return $hier; |
|
| 811 | 811 | } |
| 812 | 812 | |
| 813 | 813 | |
@@ -825,47 +825,47 @@ discard block |
||
| 825 | 825 | * @return void |
| 826 | 826 | **/ |
| 827 | 827 | function calculer_prochain_postdate($check = false) { |
| 828 | - include_spip('base/abstract_sql'); |
|
| 829 | - if ($check) { |
|
| 830 | - $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | - |
|
| 833 | - $r = sql_select( |
|
| 834 | - 'DISTINCT A.id_rubrique AS id', |
|
| 835 | - 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | - "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | - ); |
|
| 838 | - while ($row = sql_fetch($r)) { |
|
| 839 | - publier_branche_rubrique($row['id']); |
|
| 840 | - } |
|
| 841 | - |
|
| 842 | - pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | - } |
|
| 844 | - |
|
| 845 | - $t = sql_fetsel( |
|
| 846 | - 'date', |
|
| 847 | - 'spip_articles', |
|
| 848 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | - '', |
|
| 850 | - 'date', |
|
| 851 | - '1' |
|
| 852 | - ); |
|
| 853 | - |
|
| 854 | - if ($t) { |
|
| 855 | - $t = $t['date']; |
|
| 856 | - if ( |
|
| 857 | - !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | - or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | - ) { |
|
| 860 | - ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | - ecrire_meta('derniere_modif', time()); |
|
| 862 | - } |
|
| 863 | - } else { |
|
| 864 | - effacer_meta('date_prochain_postdate'); |
|
| 865 | - ecrire_meta('derniere_modif', time()); |
|
| 866 | - } |
|
| 867 | - |
|
| 868 | - spip_log("prochain postdate: $t"); |
|
| 828 | + include_spip('base/abstract_sql'); |
|
| 829 | + if ($check) { |
|
| 830 | + $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
|
| 831 | + 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | + |
|
| 833 | + $r = sql_select( |
|
| 834 | + 'DISTINCT A.id_rubrique AS id', |
|
| 835 | + 'spip_articles AS A LEFT JOIN spip_rubriques AS R ON A.id_rubrique=R.id_rubrique', |
|
| 836 | + "R.statut != 'publie' AND A.statut='publie'$postdates" |
|
| 837 | + ); |
|
| 838 | + while ($row = sql_fetch($r)) { |
|
| 839 | + publier_branche_rubrique($row['id']); |
|
| 840 | + } |
|
| 841 | + |
|
| 842 | + pipeline('trig_calculer_prochain_postdate', ''); |
|
| 843 | + } |
|
| 844 | + |
|
| 845 | + $t = sql_fetsel( |
|
| 846 | + 'date', |
|
| 847 | + 'spip_articles', |
|
| 848 | + "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | + '', |
|
| 850 | + 'date', |
|
| 851 | + '1' |
|
| 852 | + ); |
|
| 853 | + |
|
| 854 | + if ($t) { |
|
| 855 | + $t = $t['date']; |
|
| 856 | + if ( |
|
| 857 | + !isset($GLOBALS['meta']['date_prochain_postdate']) |
|
| 858 | + or $t <> $GLOBALS['meta']['date_prochain_postdate'] |
|
| 859 | + ) { |
|
| 860 | + ecrire_meta('date_prochain_postdate', strtotime($t)); |
|
| 861 | + ecrire_meta('derniere_modif', time()); |
|
| 862 | + } |
|
| 863 | + } else { |
|
| 864 | + effacer_meta('date_prochain_postdate'); |
|
| 865 | + ecrire_meta('derniere_modif', time()); |
|
| 866 | + } |
|
| 867 | + |
|
| 868 | + spip_log("prochain postdate: $t"); |
|
| 869 | 869 | } |
| 870 | 870 | |
| 871 | 871 | /** |
@@ -890,62 +890,62 @@ discard block |
||
| 890 | 890 | */ |
| 891 | 891 | function creer_rubrique_nommee($titre, $id_parent = 0, $serveur = '') { |
| 892 | 892 | |
| 893 | - // eclater l'arborescence demandee |
|
| 894 | - // echapper les </multi> et autres balises fermantes html |
|
| 895 | - $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | - $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | - include_spip('base/abstract_sql'); |
|
| 898 | - foreach ($arbo as $titre) { |
|
| 899 | - // retablir les </multi> et autres balises fermantes html |
|
| 900 | - $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | - $r = sql_getfetsel( |
|
| 902 | - 'id_rubrique', |
|
| 903 | - 'spip_rubriques', |
|
| 904 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | - $groupby = [], |
|
| 906 | - $orderby = [], |
|
| 907 | - $limit = '', |
|
| 908 | - $having = [], |
|
| 909 | - $serveur |
|
| 910 | - ); |
|
| 911 | - if ($r !== null) { |
|
| 912 | - $id_parent = $r; |
|
| 913 | - } else { |
|
| 914 | - $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | - 'titre' => $titre, |
|
| 916 | - 'id_parent' => $id_parent, |
|
| 917 | - 'statut' => 'prepa' |
|
| 918 | - ], $desc = [], $serveur); |
|
| 919 | - if ($id_parent > 0) { |
|
| 920 | - $data = sql_fetsel( |
|
| 921 | - 'id_secteur,lang', |
|
| 922 | - 'spip_rubriques', |
|
| 923 | - "id_rubrique=$id_parent", |
|
| 924 | - $groupby = [], |
|
| 925 | - $orderby = [], |
|
| 926 | - $limit = '', |
|
| 927 | - $having = [], |
|
| 928 | - $serveur |
|
| 929 | - ); |
|
| 930 | - $id_secteur = $data['id_secteur']; |
|
| 931 | - $lang = $data['lang']; |
|
| 932 | - } else { |
|
| 933 | - $id_secteur = $id_rubrique; |
|
| 934 | - $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | - } |
|
| 936 | - |
|
| 937 | - sql_updateq( |
|
| 938 | - 'spip_rubriques', |
|
| 939 | - ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | - $desc = '', |
|
| 942 | - $serveur |
|
| 943 | - ); |
|
| 944 | - |
|
| 945 | - // pour la recursion |
|
| 946 | - $id_parent = $id_rubrique; |
|
| 947 | - } |
|
| 948 | - } |
|
| 949 | - |
|
| 950 | - return intval($id_parent); |
|
| 893 | + // eclater l'arborescence demandee |
|
| 894 | + // echapper les </multi> et autres balises fermantes html |
|
| 895 | + $titre = preg_replace(',</([a-z][^>]*)>,ims', "<@\\1>", $titre); |
|
| 896 | + $arbo = explode('/', preg_replace(',^/,', '', $titre)); |
|
| 897 | + include_spip('base/abstract_sql'); |
|
| 898 | + foreach ($arbo as $titre) { |
|
| 899 | + // retablir les </multi> et autres balises fermantes html |
|
| 900 | + $titre = preg_replace(',<@([a-z][^>]*)>,ims', "</\\1>", $titre); |
|
| 901 | + $r = sql_getfetsel( |
|
| 902 | + 'id_rubrique', |
|
| 903 | + 'spip_rubriques', |
|
| 904 | + 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 905 | + $groupby = [], |
|
| 906 | + $orderby = [], |
|
| 907 | + $limit = '', |
|
| 908 | + $having = [], |
|
| 909 | + $serveur |
|
| 910 | + ); |
|
| 911 | + if ($r !== null) { |
|
| 912 | + $id_parent = $r; |
|
| 913 | + } else { |
|
| 914 | + $id_rubrique = sql_insertq('spip_rubriques', [ |
|
| 915 | + 'titre' => $titre, |
|
| 916 | + 'id_parent' => $id_parent, |
|
| 917 | + 'statut' => 'prepa' |
|
| 918 | + ], $desc = [], $serveur); |
|
| 919 | + if ($id_parent > 0) { |
|
| 920 | + $data = sql_fetsel( |
|
| 921 | + 'id_secteur,lang', |
|
| 922 | + 'spip_rubriques', |
|
| 923 | + "id_rubrique=$id_parent", |
|
| 924 | + $groupby = [], |
|
| 925 | + $orderby = [], |
|
| 926 | + $limit = '', |
|
| 927 | + $having = [], |
|
| 928 | + $serveur |
|
| 929 | + ); |
|
| 930 | + $id_secteur = $data['id_secteur']; |
|
| 931 | + $lang = $data['lang']; |
|
| 932 | + } else { |
|
| 933 | + $id_secteur = $id_rubrique; |
|
| 934 | + $lang = $GLOBALS['meta']['langue_site']; |
|
| 935 | + } |
|
| 936 | + |
|
| 937 | + sql_updateq( |
|
| 938 | + 'spip_rubriques', |
|
| 939 | + ['id_secteur' => $id_secteur, 'lang' => $lang], |
|
| 940 | + 'id_rubrique=' . intval($id_rubrique), |
|
| 941 | + $desc = '', |
|
| 942 | + $serveur |
|
| 943 | + ); |
|
| 944 | + |
|
| 945 | + // pour la recursion |
|
| 946 | + $id_parent = $id_rubrique; |
|
| 947 | + } |
|
| 948 | + } |
|
| 949 | + |
|
| 950 | + return intval($id_parent); |
|
| 951 | 951 | } |
@@ -134,9 +134,9 @@ discard block |
||
| 134 | 134 | sql_updateq( |
| 135 | 135 | 'spip_rubriques', |
| 136 | 136 | ['statut' => 'publie', 'date' => date('Y-m-d H:i:s')], |
| 137 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 137 | + 'id_rubrique='.intval($id_rubrique) |
|
| 138 | 138 | ); |
| 139 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique=' . intval($id_rubrique)); |
|
| 139 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques AS R', 'R.id_rubrique='.intval($id_rubrique)); |
|
| 140 | 140 | if (!$id_parent) { |
| 141 | 141 | break; |
| 142 | 142 | } |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | return $id_pred != $id_rubrique; |
| 172 | 172 | } |
| 173 | 173 | // passer au parent si on a depublie |
| 174 | - $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . intval($id_pred)); |
|
| 174 | + $r = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique='.intval($id_pred)); |
|
| 175 | 175 | $id_pred = $r['id_parent']; |
| 176 | 176 | } |
| 177 | 177 | |
@@ -196,14 +196,14 @@ discard block |
||
| 196 | 196 | $date = date('Y-m-d H:i:s'); |
| 197 | 197 | } |
| 198 | 198 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 199 | - ' AND date <= ' . sql_quote($date) : ''; |
|
| 199 | + ' AND date <= '.sql_quote($date) : ''; |
|
| 200 | 200 | |
| 201 | 201 | if (!$id_rubrique = intval($id_rubrique)) { |
| 202 | 202 | return false; |
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // verifier qu'elle existe et est bien publiee |
| 206 | - $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 206 | + $r = sql_fetsel('id_rubrique,statut', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 207 | 207 | if (!$r or $r['statut'] !== 'publie') { |
| 208 | 208 | return false; |
| 209 | 209 | } |
@@ -213,12 +213,12 @@ discard block |
||
| 213 | 213 | $compte = [ |
| 214 | 214 | 'articles' => sql_countsel( |
| 215 | 215 | 'spip_articles', |
| 216 | - 'id_rubrique=' . intval($id_rubrique) . " AND statut='publie'$postdates" |
|
| 216 | + 'id_rubrique='.intval($id_rubrique)." AND statut='publie'$postdates" |
|
| 217 | 217 | ), |
| 218 | - 'rubriques' => sql_countsel('spip_rubriques', 'id_parent=' . intval($id_rubrique) . " AND statut='publie'"), |
|
| 218 | + 'rubriques' => sql_countsel('spip_rubriques', 'id_parent='.intval($id_rubrique)." AND statut='publie'"), |
|
| 219 | 219 | 'documents' => sql_countsel( |
| 220 | 220 | 'spip_documents AS D JOIN spip_documents_liens AS L ON D.id_document=L.id_document', |
| 221 | - 'L.id_objet=' . intval($id_rubrique) . " AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 221 | + 'L.id_objet='.intval($id_rubrique)." AND L.objet='rubrique' and D.mode NOT IN('logoon', 'logooff') " |
|
| 222 | 222 | ) |
| 223 | 223 | ]; |
| 224 | 224 | |
@@ -243,7 +243,7 @@ discard block |
||
| 243 | 243 | } |
| 244 | 244 | } |
| 245 | 245 | |
| 246 | - sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique=' . intval($id_rubrique)); |
|
| 246 | + sql_updateq('spip_rubriques', ['statut' => 'prepa'], 'id_rubrique='.intval($id_rubrique)); |
|
| 247 | 247 | |
| 248 | 248 | # spip_log("depublier_rubrique $id_pred"); |
| 249 | 249 | return true; |
@@ -306,7 +306,7 @@ discard block |
||
| 306 | 306 | |
| 307 | 307 | // Afficher les articles post-dates ? |
| 308 | 308 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 309 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 309 | + 'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 310 | 310 | |
| 311 | 311 | $r = sql_select( |
| 312 | 312 | 'R.id_rubrique AS id, max(A.date) AS date_h', |
@@ -318,7 +318,7 @@ discard block |
||
| 318 | 318 | sql_updateq( |
| 319 | 319 | 'spip_rubriques', |
| 320 | 320 | ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
| 321 | - 'id_rubrique=' . intval($row['id']) |
|
| 321 | + 'id_rubrique='.intval($row['id']) |
|
| 322 | 322 | ); |
| 323 | 323 | } |
| 324 | 324 | |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | sql_updateq( |
| 345 | 345 | 'spip_rubriques', |
| 346 | 346 | ['statut_tmp' => 'publie', 'date_tmp' => $row['date_h']], |
| 347 | - 'id_rubrique=' . intval($row['id']) |
|
| 347 | + 'id_rubrique='.intval($row['id']) |
|
| 348 | 348 | ); |
| 349 | 349 | $continuer = true; |
| 350 | 350 | } |
@@ -397,7 +397,7 @@ discard block |
||
| 397 | 397 | and $rows = sql_allfetsel( |
| 398 | 398 | 'A.id_rubrique AS id, R.id_secteur AS id_secteur, R.profondeur+1 as profondeur', |
| 399 | 399 | 'spip_rubriques AS A JOIN spip_rubriques AS R ON A.id_parent = R.id_rubrique', |
| 400 | - 'R.profondeur=' . intval($prof) . ' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 400 | + 'R.profondeur='.intval($prof).' AND (A.id_secteur <> R.id_secteur OR A.profondeur > R.profondeur+1)', |
|
| 401 | 401 | '', |
| 402 | 402 | 'R.id_secteur', |
| 403 | 403 | '0,100' |
@@ -436,11 +436,11 @@ discard block |
||
| 436 | 436 | and $rows = sql_allfetsel( |
| 437 | 437 | 'id_rubrique as id', |
| 438 | 438 | 'spip_rubriques', |
| 439 | - 'profondeur=' . intval($prof + 1) . ' AND id_parent NOT IN (' . sql_get_select( |
|
| 439 | + 'profondeur='.intval($prof + 1).' AND id_parent NOT IN ('.sql_get_select( |
|
| 440 | 440 | 'zzz.id_rubrique', |
| 441 | 441 | 'spip_rubriques AS zzz', |
| 442 | - 'zzz.profondeur=' . intval($prof) |
|
| 443 | - ) . ')', |
|
| 442 | + 'zzz.profondeur='.intval($prof) |
|
| 443 | + ).')', |
|
| 444 | 444 | '', |
| 445 | 445 | '', |
| 446 | 446 | '0,100' |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | // si pas de rubrique a profondeur $prof+1 pas la peine de continuer |
| 455 | 455 | // si il reste des rubriques non vues, c'est une branche morte ou reference circulaire (base foireuse) |
| 456 | 456 | // on arrete les frais |
| 457 | - if (sql_countsel('spip_rubriques', 'profondeur=' . intval($prof + 1))) { |
|
| 457 | + if (sql_countsel('spip_rubriques', 'profondeur='.intval($prof + 1))) { |
|
| 458 | 458 | $prof++; |
| 459 | 459 | $continuer = true; |
| 460 | 460 | } |
@@ -462,12 +462,12 @@ discard block |
||
| 462 | 462 | |
| 463 | 463 | // loger si la table des rubriques semble foireuse |
| 464 | 464 | // et mettre un id_secteur=0 sur ces rubriques pour eviter toute selection par les boucles |
| 465 | - if (sql_countsel('spip_rubriques', 'profondeur>' . intval($prof + 1))) { |
|
| 465 | + if (sql_countsel('spip_rubriques', 'profondeur>'.intval($prof + 1))) { |
|
| 466 | 466 | spip_log( |
| 467 | - 'Les rubriques de profondeur>' . ($prof + 1) . ' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 467 | + 'Les rubriques de profondeur>'.($prof + 1).' semblent suspectes (branches morte ou reference circulaire dans les parents)', |
|
| 468 | 468 | _LOG_CRITIQUE |
| 469 | 469 | ); |
| 470 | - sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>' . intval($prof + 1)); |
|
| 470 | + sql_update('spip_rubriques', ['id_secteur' => 0], 'profondeur>'.intval($prof + 1)); |
|
| 471 | 471 | } |
| 472 | 472 | |
| 473 | 473 | // reparer les articles |
@@ -478,7 +478,7 @@ discard block |
||
| 478 | 478 | ); |
| 479 | 479 | |
| 480 | 480 | while ($row = sql_fetch($r)) { |
| 481 | - sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article=' . intval($row['id'])); |
|
| 481 | + sql_update('spip_articles', ['id_secteur' => $row['secteur']], 'id_article='.intval($row['id'])); |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | // avertir les plugins qui peuvent faire leur mises a jour egalement |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | $t = sql_updateq( |
| 510 | 510 | 'spip_rubriques', |
| 511 | 511 | ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
| 512 | - 'id_rubrique=' . intval($id_rubrique) |
|
| 512 | + 'id_rubrique='.intval($id_rubrique) |
|
| 513 | 513 | ); |
| 514 | 514 | } |
| 515 | 515 | |
@@ -554,7 +554,7 @@ discard block |
||
| 554 | 554 | sql_updateq( |
| 555 | 555 | 'spip_articles', |
| 556 | 556 | ['lang' => $row['lang'], 'langue_choisie' => 'non'], |
| 557 | - 'id_article=' . intval($id_article) |
|
| 557 | + 'id_article='.intval($id_article) |
|
| 558 | 558 | ); |
| 559 | 559 | } |
| 560 | 560 | |
@@ -629,11 +629,11 @@ discard block |
||
| 629 | 629 | ]; |
| 630 | 630 | // generer un nom de fonction "anonyme" unique |
| 631 | 631 | do { |
| 632 | - $functionname = 'f_calculer_langues_utilisees_' . $boucle->id_table . '_' . time() . '_' . rand(); |
|
| 632 | + $functionname = 'f_calculer_langues_utilisees_'.$boucle->id_table.'_'.time().'_'.rand(); |
|
| 633 | 633 | } while (function_exists($functionname)); |
| 634 | 634 | $code = calculer_boucle('calculer_langues_utilisees', $boucles); |
| 635 | - $code = '$SP=0; $command=array();$command["connect"] = $connect = "' . $serveur . '"; $Pile=array(0=>array());' . "\n" . $code; |
|
| 636 | - $code = 'function ' . $functionname . '(){' . $code . '};$res = ' . $functionname . '();'; |
|
| 635 | + $code = '$SP=0; $command=array();$command["connect"] = $connect = "'.$serveur.'"; $Pile=array(0=>array());'."\n".$code; |
|
| 636 | + $code = 'function '.$functionname.'(){'.$code.'};$res = '.$functionname.'();'; |
|
| 637 | 637 | $res = ''; |
| 638 | 638 | eval($code); |
| 639 | 639 | $res = explode(',', $res); |
@@ -735,11 +735,11 @@ discard block |
||
| 735 | 735 | $maxiter-- and $filles = sql_allfetsel( |
| 736 | 736 | 'id_rubrique', |
| 737 | 737 | 'spip_rubriques', |
| 738 | - sql_in('id_parent', $r) . ' AND ' . sql_in('id_rubrique', $r, 'NOT') |
|
| 738 | + sql_in('id_parent', $r).' AND '.sql_in('id_rubrique', $r, 'NOT') |
|
| 739 | 739 | ) |
| 740 | 740 | ) { |
| 741 | 741 | $r = join(',', array_column($filles, 'id_rubrique')); |
| 742 | - $branche .= ',' . $r; |
|
| 742 | + $branche .= ','.$r; |
|
| 743 | 743 | } |
| 744 | 744 | |
| 745 | 745 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -779,7 +779,7 @@ discard block |
||
| 779 | 779 | |
| 780 | 780 | if (isset($b[$id])) { |
| 781 | 781 | // Notre branche commence par la rubrique de depart si $tout=true |
| 782 | - return $tout ? (strlen($b[$id]) ? $b[$id] . ",$id" : $id) : $b[$id]; |
|
| 782 | + return $tout ? (strlen($b[$id]) ? $b[$id].",$id" : $id) : $b[$id]; |
|
| 783 | 783 | } |
| 784 | 784 | |
| 785 | 785 | $hier = ''; |
@@ -792,11 +792,11 @@ discard block |
||
| 792 | 792 | $maxiter-- and $parents = sql_allfetsel( |
| 793 | 793 | 'id_parent', |
| 794 | 794 | 'spip_rubriques', |
| 795 | - sql_in('id_rubrique', $ids_nouveaux_parents) . ' AND ' . sql_in('id_parent', $hier, 'NOT') |
|
| 795 | + sql_in('id_rubrique', $ids_nouveaux_parents).' AND '.sql_in('id_parent', $hier, 'NOT') |
|
| 796 | 796 | ) |
| 797 | 797 | ) { |
| 798 | 798 | $ids_nouveaux_parents = join(',', array_column($parents, 'id_parent')); |
| 799 | - $hier = $ids_nouveaux_parents . (strlen($hier) ? ',' . $hier : ''); |
|
| 799 | + $hier = $ids_nouveaux_parents.(strlen($hier) ? ','.$hier : ''); |
|
| 800 | 800 | } |
| 801 | 801 | |
| 802 | 802 | # securite pour ne pas plomber la conso memoire sur les sites prolifiques |
@@ -828,7 +828,7 @@ discard block |
||
| 828 | 828 | include_spip('base/abstract_sql'); |
| 829 | 829 | if ($check) { |
| 830 | 830 | $postdates = ($GLOBALS['meta']['post_dates'] == 'non') ? |
| 831 | - 'AND A.date <= ' . sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 831 | + 'AND A.date <= '.sql_quote(date('Y-m-d H:i:s')) : ''; |
|
| 832 | 832 | |
| 833 | 833 | $r = sql_select( |
| 834 | 834 | 'DISTINCT A.id_rubrique AS id', |
@@ -845,7 +845,7 @@ discard block |
||
| 845 | 845 | $t = sql_fetsel( |
| 846 | 846 | 'date', |
| 847 | 847 | 'spip_articles', |
| 848 | - "statut='publie' AND date > " . sql_quote(date('Y-m-d H:i:s')), |
|
| 848 | + "statut='publie' AND date > ".sql_quote(date('Y-m-d H:i:s')), |
|
| 849 | 849 | '', |
| 850 | 850 | 'date', |
| 851 | 851 | '1' |
@@ -901,7 +901,7 @@ discard block |
||
| 901 | 901 | $r = sql_getfetsel( |
| 902 | 902 | 'id_rubrique', |
| 903 | 903 | 'spip_rubriques', |
| 904 | - 'titre = ' . sql_quote($titre) . ' AND id_parent=' . intval($id_parent), |
|
| 904 | + 'titre = '.sql_quote($titre).' AND id_parent='.intval($id_parent), |
|
| 905 | 905 | $groupby = [], |
| 906 | 906 | $orderby = [], |
| 907 | 907 | $limit = '', |
@@ -937,7 +937,7 @@ discard block |
||
| 937 | 937 | sql_updateq( |
| 938 | 938 | 'spip_rubriques', |
| 939 | 939 | ['id_secteur' => $id_secteur, 'lang' => $lang], |
| 940 | - 'id_rubrique=' . intval($id_rubrique), |
|
| 940 | + 'id_rubrique='.intval($id_rubrique), |
|
| 941 | 941 | $desc = '', |
| 942 | 942 | $serveur |
| 943 | 943 | ); |
@@ -77,8 +77,7 @@ |
||
| 77 | 77 | break; // stop on a trouvé le bon champ |
| 78 | 78 | } |
| 79 | 79 | } |
| 80 | - } |
|
| 81 | - else { |
|
| 80 | + } else { |
|
| 82 | 81 | $statuts_publies = ['publie']; |
| 83 | 82 | } |
| 84 | 83 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -35,20 +35,20 @@ discard block |
||
| 35 | 35 | * @return string URL nettoyée |
| 36 | 36 | **/ |
| 37 | 37 | function resolve_path($url) { |
| 38 | - list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | - while ( |
|
| 40 | - preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | - or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | - or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | - ) { |
|
| 44 | - $url = str_replace($regs[0], '/', $url); |
|
| 45 | - } |
|
| 38 | + list($url, $query) = array_pad(explode('?', $url, 2), 2, null); |
|
| 39 | + while ( |
|
| 40 | + preg_match(',/\.?/,', $url, $regs) # supprime // et /./ |
|
| 41 | + or preg_match(',/[^/]*/\.\./,S', $url, $regs) # supprime /toto/../ |
|
| 42 | + or preg_match(',^/\.\./,S', $url, $regs) # supprime les /../ du haut |
|
| 43 | + ) { |
|
| 44 | + $url = str_replace($regs[0], '/', $url); |
|
| 45 | + } |
|
| 46 | 46 | |
| 47 | - if ($query) { |
|
| 48 | - $url .= '?' . $query; |
|
| 49 | - } |
|
| 47 | + if ($query) { |
|
| 48 | + $url .= '?' . $query; |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/' . preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -69,41 +69,41 @@ discard block |
||
| 69 | 69 | **/ |
| 70 | 70 | function suivre_lien($url, $lien) { |
| 71 | 71 | |
| 72 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 73 | - return $lien; |
|
| 74 | - } |
|
| 75 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 76 | - $r = array_pad($r, 3, null); |
|
| 72 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 73 | + return $lien; |
|
| 74 | + } |
|
| 75 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 76 | + $r = array_pad($r, 3, null); |
|
| 77 | 77 | |
| 78 | - return $r[1] . resolve_path($r[2]); |
|
| 79 | - } |
|
| 78 | + return $r[1] . resolve_path($r[2]); |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - # L'url site spip est un lien absolu aussi |
|
| 82 | - if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 83 | - return $lien; |
|
| 84 | - } |
|
| 81 | + # L'url site spip est un lien absolu aussi |
|
| 82 | + if (isset($GLOBALS['meta']['adresse_site']) and $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 83 | + return $lien; |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - # lien relatif, il faut verifier l'url de base |
|
| 87 | - # commencer par virer la chaine de get de l'url de base |
|
| 88 | - $dir = '/'; |
|
| 89 | - $debut = ''; |
|
| 90 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 91 | - $debut = $regs[1]; |
|
| 92 | - $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 93 | - $mot = $regs[3]; |
|
| 94 | - $get = isset($regs[4]) ? $regs[4] : ''; |
|
| 95 | - $hash = isset($regs[5]) ? $regs[5] : ''; |
|
| 96 | - } |
|
| 97 | - switch (substr($lien, 0, 1)) { |
|
| 98 | - case '/': |
|
| 99 | - return $debut . resolve_path($lien); |
|
| 100 | - case '#': |
|
| 101 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 102 | - case '': |
|
| 103 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 104 | - default: |
|
| 105 | - return $debut . resolve_path($dir . $lien); |
|
| 106 | - } |
|
| 86 | + # lien relatif, il faut verifier l'url de base |
|
| 87 | + # commencer par virer la chaine de get de l'url de base |
|
| 88 | + $dir = '/'; |
|
| 89 | + $debut = ''; |
|
| 90 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 91 | + $debut = $regs[1]; |
|
| 92 | + $dir = !strlen($regs[2]) ? '/' : $regs[2]; |
|
| 93 | + $mot = $regs[3]; |
|
| 94 | + $get = isset($regs[4]) ? $regs[4] : ''; |
|
| 95 | + $hash = isset($regs[5]) ? $regs[5] : ''; |
|
| 96 | + } |
|
| 97 | + switch (substr($lien, 0, 1)) { |
|
| 98 | + case '/': |
|
| 99 | + return $debut . resolve_path($lien); |
|
| 100 | + case '#': |
|
| 101 | + return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 102 | + case '': |
|
| 103 | + return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 104 | + default: |
|
| 105 | + return $debut . resolve_path($dir . $lien); |
|
| 106 | + } |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -126,14 +126,14 @@ discard block |
||
| 126 | 126 | * @return string Texte ou URL (en absolus) |
| 127 | 127 | **/ |
| 128 | 128 | function url_absolue($url, $base = '') { |
| 129 | - if (strlen($url = trim($url)) == 0) { |
|
| 130 | - return ''; |
|
| 131 | - } |
|
| 132 | - if (!$base) { |
|
| 133 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 134 | - } |
|
| 129 | + if (strlen($url = trim($url)) == 0) { |
|
| 130 | + return ''; |
|
| 131 | + } |
|
| 132 | + if (!$base) { |
|
| 133 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 134 | + } |
|
| 135 | 135 | |
| 136 | - return suivre_lien($base, $url); |
|
| 136 | + return suivre_lien($base, $url); |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | function protocole_implicite($url_absolue) { |
| 147 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | /** |
@@ -155,16 +155,16 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 157 | 157 | |
| 158 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 159 | - $protocole = $m[1]; |
|
| 160 | - if ( |
|
| 161 | - in_array($protocole, $protocoles_autorises) |
|
| 162 | - or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 163 | - ) { |
|
| 164 | - return true; |
|
| 165 | - } |
|
| 166 | - } |
|
| 167 | - return false; |
|
| 158 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 159 | + $protocole = $m[1]; |
|
| 160 | + if ( |
|
| 161 | + in_array($protocole, $protocoles_autorises) |
|
| 162 | + or in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 163 | + ) { |
|
| 164 | + return true; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | + return false; |
|
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | /** |
@@ -181,27 +181,27 @@ discard block |
||
| 181 | 181 | * @return string Texte avec des URLs absolues |
| 182 | 182 | **/ |
| 183 | 183 | function liens_absolus($texte, $base = '') { |
| 184 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 185 | - if (!function_exists('extraire_attribut')) { |
|
| 186 | - include_spip('inc/filtres'); |
|
| 187 | - } |
|
| 188 | - foreach ($liens as $lien) { |
|
| 189 | - foreach (['href', 'src'] as $attr) { |
|
| 190 | - $href = extraire_attribut($lien[0], $attr); |
|
| 191 | - if (strlen($href) > 0) { |
|
| 192 | - if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 193 | - $abs = url_absolue($href, $base); |
|
| 194 | - if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 195 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 196 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - } |
|
| 201 | - } |
|
| 202 | - } |
|
| 184 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 185 | + if (!function_exists('extraire_attribut')) { |
|
| 186 | + include_spip('inc/filtres'); |
|
| 187 | + } |
|
| 188 | + foreach ($liens as $lien) { |
|
| 189 | + foreach (['href', 'src'] as $attr) { |
|
| 190 | + $href = extraire_attribut($lien[0], $attr); |
|
| 191 | + if (strlen($href) > 0) { |
|
| 192 | + if (!preg_match(';^((?:[a-z]{3,7}:)?//);iS', $href)) { |
|
| 193 | + $abs = url_absolue($href, $base); |
|
| 194 | + if (rtrim($href, '/') !== rtrim($abs, '/') and !preg_match('/^#/', $href)) { |
|
| 195 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 196 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + } |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $texte; |
|
| 204 | + return $texte; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | |
@@ -217,11 +217,11 @@ discard block |
||
| 217 | 217 | * @return string Texte ou URL (en absolus) |
| 218 | 218 | **/ |
| 219 | 219 | function abs_url($texte, $base = '') { |
| 220 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 221 | - return url_absolue($texte, $base); |
|
| 222 | - } else { |
|
| 223 | - return liens_absolus($texte, $base); |
|
| 224 | - } |
|
| 220 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 221 | + return url_absolue($texte, $base); |
|
| 222 | + } else { |
|
| 223 | + return liens_absolus($texte, $base); |
|
| 224 | + } |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -234,11 +234,11 @@ discard block |
||
| 234 | 234 | * @return string |
| 235 | 235 | */ |
| 236 | 236 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 237 | - if (is_null($flags)) { |
|
| 238 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 239 | - } |
|
| 237 | + if (is_null($flags)) { |
|
| 238 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 239 | + } |
|
| 240 | 240 | |
| 241 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 241 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -251,9 +251,9 @@ discard block |
||
| 251 | 251 | * @return string |
| 252 | 252 | */ |
| 253 | 253 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 254 | - if (is_null($flags)) { |
|
| 255 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 256 | - } |
|
| 254 | + if (is_null($flags)) { |
|
| 255 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 258 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 259 | 259 | } |
@@ -45,10 +45,10 @@ discard block |
||
| 45 | 45 | } |
| 46 | 46 | |
| 47 | 47 | if ($query) { |
| 48 | - $url .= '?' . $query; |
|
| 48 | + $url .= '?'.$query; |
|
| 49 | 49 | } |
| 50 | 50 | |
| 51 | - return '/' . preg_replace(',^/,S', '', $url); |
|
| 51 | + return '/'.preg_replace(',^/,S', '', $url); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 76 | 76 | $r = array_pad($r, 3, null); |
| 77 | 77 | |
| 78 | - return $r[1] . resolve_path($r[2]); |
|
| 78 | + return $r[1].resolve_path($r[2]); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | # L'url site spip est un lien absolu aussi |
@@ -96,13 +96,13 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | switch (substr($lien, 0, 1)) { |
| 98 | 98 | case '/': |
| 99 | - return $debut . resolve_path($lien); |
|
| 99 | + return $debut.resolve_path($lien); |
|
| 100 | 100 | case '#': |
| 101 | - return $debut . resolve_path($dir . $mot . $get . $lien); |
|
| 101 | + return $debut.resolve_path($dir.$mot.$get.$lien); |
|
| 102 | 102 | case '': |
| 103 | - return $debut . resolve_path($dir . $mot . $get . $hash); |
|
| 103 | + return $debut.resolve_path($dir.$mot.$get.$hash); |
|
| 104 | 104 | default: |
| 105 | - return $debut . resolve_path($dir . $lien); |
|
| 105 | + return $debut.resolve_path($dir.$lien); |
|
| 106 | 106 | } |
| 107 | 107 | } |
| 108 | 108 | |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | return ''; |
| 131 | 131 | } |
| 132 | 132 | if (!$base) { |
| 133 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | return suivre_lien($base, $url); |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @param array $protocoles_autorises |
| 154 | 154 | * @return bool |
| 155 | 155 | */ |
| 156 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 156 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 157 | 157 | |
| 158 | 158 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 159 | 159 | $protocole = $m[1]; |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,58 +120,58 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 124 | - $var_G = ($G / 255); |
|
| 125 | - $var_B = ($B / 255); |
|
| 126 | - |
|
| 127 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 130 | - |
|
| 131 | - $L = ($var_Max + $var_Min) / 2; |
|
| 132 | - |
|
| 133 | - if ($del_Max == 0) { |
|
| 134 | - //This is a gray, no chroma... |
|
| 135 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 136 | - $S = 0; |
|
| 137 | - } else { |
|
| 138 | - // Chromatic data... |
|
| 139 | - if ($L < 0.5) { |
|
| 140 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 141 | - } else { |
|
| 142 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 146 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - |
|
| 149 | - if ($var_R == $var_Max) { |
|
| 150 | - $H = $del_B - $del_G; |
|
| 151 | - } else { |
|
| 152 | - if ($var_G == $var_Max) { |
|
| 153 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 154 | - } else { |
|
| 155 | - if ($var_B == $var_Max) { |
|
| 156 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ($H < 0) { |
|
| 162 | - $H += 1; |
|
| 163 | - } |
|
| 164 | - if ($H > 1) { |
|
| 165 | - $H -= 1; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - $ret = []; |
|
| 170 | - $ret['h'] = $H; |
|
| 171 | - $ret['s'] = $S; |
|
| 172 | - $ret['l'] = $L; |
|
| 173 | - |
|
| 174 | - return $ret; |
|
| 123 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 124 | + $var_G = ($G / 255); |
|
| 125 | + $var_B = ($B / 255); |
|
| 126 | + |
|
| 127 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 130 | + |
|
| 131 | + $L = ($var_Max + $var_Min) / 2; |
|
| 132 | + |
|
| 133 | + if ($del_Max == 0) { |
|
| 134 | + //This is a gray, no chroma... |
|
| 135 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 136 | + $S = 0; |
|
| 137 | + } else { |
|
| 138 | + // Chromatic data... |
|
| 139 | + if ($L < 0.5) { |
|
| 140 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 141 | + } else { |
|
| 142 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 146 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + |
|
| 149 | + if ($var_R == $var_Max) { |
|
| 150 | + $H = $del_B - $del_G; |
|
| 151 | + } else { |
|
| 152 | + if ($var_G == $var_Max) { |
|
| 153 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 154 | + } else { |
|
| 155 | + if ($var_B == $var_Max) { |
|
| 156 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ($H < 0) { |
|
| 162 | + $H += 1; |
|
| 163 | + } |
|
| 164 | + if ($H > 1) { |
|
| 165 | + $H -= 1; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + $ret = []; |
|
| 170 | + $ret['h'] = $H; |
|
| 171 | + $ret['s'] = $S; |
|
| 172 | + $ret['l'] = $L; |
|
| 173 | + |
|
| 174 | + return $ret; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -187,52 +187,52 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 190 | - // helper |
|
| 191 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | - if ($vH < 0) { |
|
| 193 | - $vH += 1; |
|
| 194 | - } |
|
| 195 | - if ($vH > 1) { |
|
| 196 | - $vH -= 1; |
|
| 197 | - } |
|
| 198 | - if ((6 * $vH) < 1) { |
|
| 199 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 200 | - } |
|
| 201 | - if ((2 * $vH) < 1) { |
|
| 202 | - return ($v2); |
|
| 203 | - } |
|
| 204 | - if ((3 * $vH) < 2) { |
|
| 205 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - return ($v1); |
|
| 209 | - }; |
|
| 210 | - |
|
| 211 | - if ($S == 0) { |
|
| 212 | - // HSV values = 0 -> 1 |
|
| 213 | - $R = $L * 255; |
|
| 214 | - $G = $L * 255; |
|
| 215 | - $B = $L * 255; |
|
| 216 | - } else { |
|
| 217 | - if ($L < 0.5) { |
|
| 218 | - $var_2 = $L * (1 + $S); |
|
| 219 | - } else { |
|
| 220 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 221 | - } |
|
| 222 | - |
|
| 223 | - $var_1 = 2 * $L - $var_2; |
|
| 224 | - |
|
| 225 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 226 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 227 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - $ret = []; |
|
| 231 | - $ret['r'] = floor($R); |
|
| 232 | - $ret['g'] = floor($G); |
|
| 233 | - $ret['b'] = floor($B); |
|
| 234 | - |
|
| 235 | - return $ret; |
|
| 190 | + // helper |
|
| 191 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | + if ($vH < 0) { |
|
| 193 | + $vH += 1; |
|
| 194 | + } |
|
| 195 | + if ($vH > 1) { |
|
| 196 | + $vH -= 1; |
|
| 197 | + } |
|
| 198 | + if ((6 * $vH) < 1) { |
|
| 199 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 200 | + } |
|
| 201 | + if ((2 * $vH) < 1) { |
|
| 202 | + return ($v2); |
|
| 203 | + } |
|
| 204 | + if ((3 * $vH) < 2) { |
|
| 205 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + return ($v1); |
|
| 209 | + }; |
|
| 210 | + |
|
| 211 | + if ($S == 0) { |
|
| 212 | + // HSV values = 0 -> 1 |
|
| 213 | + $R = $L * 255; |
|
| 214 | + $G = $L * 255; |
|
| 215 | + $B = $L * 255; |
|
| 216 | + } else { |
|
| 217 | + if ($L < 0.5) { |
|
| 218 | + $var_2 = $L * (1 + $S); |
|
| 219 | + } else { |
|
| 220 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 221 | + } |
|
| 222 | + |
|
| 223 | + $var_1 = 2 * $L - $var_2; |
|
| 224 | + |
|
| 225 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 226 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 227 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + $ret = []; |
|
| 231 | + $ret['r'] = floor($R); |
|
| 232 | + $ret['g'] = floor($G); |
|
| 233 | + $ret['b'] = floor($B); |
|
| 234 | + |
|
| 235 | + return $ret; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | /** |
@@ -249,11 +249,11 @@ discard block |
||
| 249 | 249 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 250 | 250 | */ |
| 251 | 251 | function statut_effacer_images_temporaires($stat) { |
| 252 | - static $statut = false; // par defaut on grave toute les images |
|
| 253 | - if ($stat === 'get') { |
|
| 254 | - return $statut; |
|
| 255 | - } |
|
| 256 | - $statut = $stat ? true : false; |
|
| 252 | + static $statut = false; // par defaut on grave toute les images |
|
| 253 | + if ($stat === 'get') { |
|
| 254 | + return $statut; |
|
| 255 | + } |
|
| 256 | + $statut = $stat ? true : false; |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | |
@@ -306,232 +306,232 @@ discard block |
||
| 306 | 306 | * - array : tableau décrivant de l'image |
| 307 | 307 | */ |
| 308 | 308 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 309 | - static $images_recalcul = []; |
|
| 310 | - if (strlen($img) == 0) { |
|
| 311 | - return false; |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - $source = trim(extraire_attribut($img, 'src')); |
|
| 315 | - if (strlen($source) < 1) { |
|
| 316 | - $source = $img; |
|
| 317 | - $img = "<img src='$source' />"; |
|
| 318 | - } # gerer img src="data:....base64" |
|
| 319 | - elseif ( |
|
| 320 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 321 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 322 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 323 | - ) { |
|
| 324 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 325 | - if (!file_exists($local)) { |
|
| 326 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 327 | - } |
|
| 328 | - $source = $local; |
|
| 329 | - $img = inserer_attribut($img, 'src', $source); |
|
| 330 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 331 | - $img = inserer_attribut($img, 'width', ''); |
|
| 332 | - $img = inserer_attribut($img, 'height', ''); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // les protocoles web prennent au moins 3 lettres |
|
| 336 | - if (tester_url_absolue($source)) { |
|
| 337 | - include_spip('inc/distant'); |
|
| 338 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 339 | - if (!$fichier) { |
|
| 340 | - return ''; |
|
| 341 | - } |
|
| 342 | - } else { |
|
| 343 | - // enlever le timestamp eventuel |
|
| 344 | - if (strpos($source, '?') !== false) { |
|
| 345 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 346 | - } |
|
| 347 | - if ( |
|
| 348 | - strpos($source, '?') !== false |
|
| 349 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 350 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 351 | - ) { |
|
| 352 | - $source = $f; |
|
| 353 | - } |
|
| 354 | - $fichier = $source; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $terminaison_dest = ''; |
|
| 358 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 359 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 360 | - } |
|
| 361 | - |
|
| 362 | - if ( |
|
| 363 | - $forcer_format !== false |
|
| 364 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 365 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 366 | - ) { |
|
| 367 | - $terminaison_dest = $forcer_format; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - if (!$terminaison_dest) { |
|
| 371 | - return false; |
|
| 372 | - } |
|
| 373 | - |
|
| 374 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 375 | - $fichier_dest = $nom_fichier; |
|
| 376 | - if ( |
|
| 377 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 378 | - or @file_exists($f = $fichier) |
|
| 379 | - ) { |
|
| 380 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 381 | - // au lieu de faire un acces disque sur le fichier |
|
| 382 | - list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img); |
|
| 383 | - $date_src = @filemtime($f); |
|
| 384 | - } elseif ( |
|
| 385 | - @file_exists($f = "$fichier.src") |
|
| 386 | - and lire_fichier($f, $valeurs) |
|
| 387 | - and $valeurs = unserialize($valeurs) |
|
| 388 | - and isset($valeurs['hauteur_dest']) |
|
| 389 | - and isset($valeurs['largeur_dest']) |
|
| 390 | - ) { |
|
| 391 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 392 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 393 | - $date_src = $valeurs['date']; |
|
| 394 | - } // pas de fichier source par la |
|
| 395 | - else { |
|
| 396 | - return false; |
|
| 397 | - } |
|
| 398 | - |
|
| 399 | - // pas de taille mesurable |
|
| 400 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 401 | - return false; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - // les images calculees dependent du chemin du fichier source |
|
| 405 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 406 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 407 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 408 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 409 | - // alors que ca concerne peu de site au final |
|
| 410 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 411 | - $identifiant = $fichier; |
|
| 412 | - |
|
| 413 | - // cas general : |
|
| 414 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 415 | - // cas particulier de reduire : |
|
| 416 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 417 | - $cache = 'cache-gd2'; |
|
| 418 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 419 | - list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 420 | - list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 421 | - $ret['largeur_dest'] = $destWidth; |
|
| 422 | - $ret['hauteur_dest'] = $destHeight; |
|
| 423 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 424 | - $cache = 'cache-vignettes'; |
|
| 425 | - $fichier_dest = basename($fichier_dest); |
|
| 426 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 427 | - // on garde la terminaison initiale car image simplement copiee |
|
| 428 | - // et on postfixe son nom avec un md5 du path |
|
| 429 | - $terminaison_dest = $terminaison; |
|
| 430 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 431 | - } else { |
|
| 432 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 433 | - } |
|
| 434 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 435 | - $cache = sous_repertoire($cache, $effet); |
|
| 436 | - } else { |
|
| 437 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 438 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 439 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 440 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 441 | - } |
|
| 442 | - |
|
| 443 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 444 | - |
|
| 445 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 446 | - |
|
| 447 | - $creer = true; |
|
| 448 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 449 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 450 | - $images_recalcul[$fichier_dest] = true; |
|
| 451 | - } else { |
|
| 452 | - if (@file_exists($f = $fichier_dest)) { |
|
| 453 | - if (filemtime($f) >= $date_src) { |
|
| 454 | - $creer = false; |
|
| 455 | - } |
|
| 456 | - } else { |
|
| 457 | - if ( |
|
| 458 | - @file_exists($f = "$fichier_dest.src") |
|
| 459 | - and lire_fichier($f, $valeurs) |
|
| 460 | - and $valeurs = unserialize($valeurs) |
|
| 461 | - and $valeurs['date'] >= $date_src |
|
| 462 | - ) { |
|
| 463 | - $creer = false; |
|
| 464 | - } |
|
| 465 | - } |
|
| 466 | - } |
|
| 467 | - if ($creer) { |
|
| 468 | - if (!@file_exists($fichier)) { |
|
| 469 | - if (!@file_exists("$fichier.src")) { |
|
| 470 | - spip_log("Image absente : $fichier"); |
|
| 471 | - |
|
| 472 | - return false; |
|
| 473 | - } |
|
| 474 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 475 | - reconstruire_image_intermediaire($fichier); |
|
| 476 | - } |
|
| 477 | - } |
|
| 478 | - |
|
| 479 | - if ($creer) { |
|
| 480 | - spip_log( |
|
| 481 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 482 | - 'images' . _LOG_DEBUG |
|
| 483 | - ); |
|
| 484 | - } |
|
| 485 | - |
|
| 486 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 487 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 488 | - $ret['fichier'] = $fichier; |
|
| 489 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 490 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 491 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 492 | - $ret['format_dest'] = $terminaison_dest; |
|
| 493 | - $ret['date_src'] = $date_src; |
|
| 494 | - $ret['creer'] = $creer; |
|
| 495 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 496 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 497 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 498 | - $ret['tag'] = $img; |
|
| 499 | - if ($fonction_creation) { |
|
| 500 | - $ret['reconstruction'] = $fonction_creation; |
|
| 501 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 502 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 503 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 504 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 505 | - } |
|
| 506 | - |
|
| 507 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 508 | - 'args' => [ |
|
| 509 | - 'img' => $img, |
|
| 510 | - 'effet' => $effet, |
|
| 511 | - 'forcer_format' => $forcer_format, |
|
| 512 | - 'fonction_creation' => $fonction_creation, |
|
| 513 | - 'find_in_path' => $find_in_path, |
|
| 514 | - ], |
|
| 515 | - 'data' => $ret |
|
| 516 | - ]); |
|
| 517 | - |
|
| 518 | - // une globale pour le debug en cas de crash memoire |
|
| 519 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 520 | - |
|
| 521 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 522 | - if ($term_fonction === 'svg') { |
|
| 523 | - if ($creer and !$support_svg) { |
|
| 524 | - process_image_svg_identite($ret); |
|
| 525 | - $ret['creer'] = false; |
|
| 526 | - } |
|
| 527 | - } |
|
| 528 | - else { |
|
| 529 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 530 | - return false; |
|
| 531 | - } |
|
| 532 | - } |
|
| 533 | - |
|
| 534 | - return $ret; |
|
| 309 | + static $images_recalcul = []; |
|
| 310 | + if (strlen($img) == 0) { |
|
| 311 | + return false; |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + $source = trim(extraire_attribut($img, 'src')); |
|
| 315 | + if (strlen($source) < 1) { |
|
| 316 | + $source = $img; |
|
| 317 | + $img = "<img src='$source' />"; |
|
| 318 | + } # gerer img src="data:....base64" |
|
| 319 | + elseif ( |
|
| 320 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 321 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 322 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 323 | + ) { |
|
| 324 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 325 | + if (!file_exists($local)) { |
|
| 326 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 327 | + } |
|
| 328 | + $source = $local; |
|
| 329 | + $img = inserer_attribut($img, 'src', $source); |
|
| 330 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 331 | + $img = inserer_attribut($img, 'width', ''); |
|
| 332 | + $img = inserer_attribut($img, 'height', ''); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // les protocoles web prennent au moins 3 lettres |
|
| 336 | + if (tester_url_absolue($source)) { |
|
| 337 | + include_spip('inc/distant'); |
|
| 338 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 339 | + if (!$fichier) { |
|
| 340 | + return ''; |
|
| 341 | + } |
|
| 342 | + } else { |
|
| 343 | + // enlever le timestamp eventuel |
|
| 344 | + if (strpos($source, '?') !== false) { |
|
| 345 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 346 | + } |
|
| 347 | + if ( |
|
| 348 | + strpos($source, '?') !== false |
|
| 349 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 350 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 351 | + ) { |
|
| 352 | + $source = $f; |
|
| 353 | + } |
|
| 354 | + $fichier = $source; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $terminaison_dest = ''; |
|
| 358 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 359 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 360 | + } |
|
| 361 | + |
|
| 362 | + if ( |
|
| 363 | + $forcer_format !== false |
|
| 364 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 365 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 366 | + ) { |
|
| 367 | + $terminaison_dest = $forcer_format; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + if (!$terminaison_dest) { |
|
| 371 | + return false; |
|
| 372 | + } |
|
| 373 | + |
|
| 374 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 375 | + $fichier_dest = $nom_fichier; |
|
| 376 | + if ( |
|
| 377 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 378 | + or @file_exists($f = $fichier) |
|
| 379 | + ) { |
|
| 380 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 381 | + // au lieu de faire un acces disque sur le fichier |
|
| 382 | + list($ret['hauteur'], $ret['largeur']) = taille_image($find_in_path ? $f : $img); |
|
| 383 | + $date_src = @filemtime($f); |
|
| 384 | + } elseif ( |
|
| 385 | + @file_exists($f = "$fichier.src") |
|
| 386 | + and lire_fichier($f, $valeurs) |
|
| 387 | + and $valeurs = unserialize($valeurs) |
|
| 388 | + and isset($valeurs['hauteur_dest']) |
|
| 389 | + and isset($valeurs['largeur_dest']) |
|
| 390 | + ) { |
|
| 391 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 392 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 393 | + $date_src = $valeurs['date']; |
|
| 394 | + } // pas de fichier source par la |
|
| 395 | + else { |
|
| 396 | + return false; |
|
| 397 | + } |
|
| 398 | + |
|
| 399 | + // pas de taille mesurable |
|
| 400 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 401 | + return false; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + // les images calculees dependent du chemin du fichier source |
|
| 405 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 406 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 407 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 408 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 409 | + // alors que ca concerne peu de site au final |
|
| 410 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 411 | + $identifiant = $fichier; |
|
| 412 | + |
|
| 413 | + // cas general : |
|
| 414 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 415 | + // cas particulier de reduire : |
|
| 416 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 417 | + $cache = 'cache-gd2'; |
|
| 418 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 419 | + list(, $maxWidth, $maxHeight) = explode('-', $effet); |
|
| 420 | + list($destWidth, $destHeight) = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 421 | + $ret['largeur_dest'] = $destWidth; |
|
| 422 | + $ret['hauteur_dest'] = $destHeight; |
|
| 423 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 424 | + $cache = 'cache-vignettes'; |
|
| 425 | + $fichier_dest = basename($fichier_dest); |
|
| 426 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 427 | + // on garde la terminaison initiale car image simplement copiee |
|
| 428 | + // et on postfixe son nom avec un md5 du path |
|
| 429 | + $terminaison_dest = $terminaison; |
|
| 430 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 431 | + } else { |
|
| 432 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 433 | + } |
|
| 434 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 435 | + $cache = sous_repertoire($cache, $effet); |
|
| 436 | + } else { |
|
| 437 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 438 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 439 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 440 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 441 | + } |
|
| 442 | + |
|
| 443 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 444 | + |
|
| 445 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 446 | + |
|
| 447 | + $creer = true; |
|
| 448 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 449 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 450 | + $images_recalcul[$fichier_dest] = true; |
|
| 451 | + } else { |
|
| 452 | + if (@file_exists($f = $fichier_dest)) { |
|
| 453 | + if (filemtime($f) >= $date_src) { |
|
| 454 | + $creer = false; |
|
| 455 | + } |
|
| 456 | + } else { |
|
| 457 | + if ( |
|
| 458 | + @file_exists($f = "$fichier_dest.src") |
|
| 459 | + and lire_fichier($f, $valeurs) |
|
| 460 | + and $valeurs = unserialize($valeurs) |
|
| 461 | + and $valeurs['date'] >= $date_src |
|
| 462 | + ) { |
|
| 463 | + $creer = false; |
|
| 464 | + } |
|
| 465 | + } |
|
| 466 | + } |
|
| 467 | + if ($creer) { |
|
| 468 | + if (!@file_exists($fichier)) { |
|
| 469 | + if (!@file_exists("$fichier.src")) { |
|
| 470 | + spip_log("Image absente : $fichier"); |
|
| 471 | + |
|
| 472 | + return false; |
|
| 473 | + } |
|
| 474 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 475 | + reconstruire_image_intermediaire($fichier); |
|
| 476 | + } |
|
| 477 | + } |
|
| 478 | + |
|
| 479 | + if ($creer) { |
|
| 480 | + spip_log( |
|
| 481 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 482 | + 'images' . _LOG_DEBUG |
|
| 483 | + ); |
|
| 484 | + } |
|
| 485 | + |
|
| 486 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 487 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 488 | + $ret['fichier'] = $fichier; |
|
| 489 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 490 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 491 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 492 | + $ret['format_dest'] = $terminaison_dest; |
|
| 493 | + $ret['date_src'] = $date_src; |
|
| 494 | + $ret['creer'] = $creer; |
|
| 495 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 496 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 497 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 498 | + $ret['tag'] = $img; |
|
| 499 | + if ($fonction_creation) { |
|
| 500 | + $ret['reconstruction'] = $fonction_creation; |
|
| 501 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 502 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 503 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 504 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 505 | + } |
|
| 506 | + |
|
| 507 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 508 | + 'args' => [ |
|
| 509 | + 'img' => $img, |
|
| 510 | + 'effet' => $effet, |
|
| 511 | + 'forcer_format' => $forcer_format, |
|
| 512 | + 'fonction_creation' => $fonction_creation, |
|
| 513 | + 'find_in_path' => $find_in_path, |
|
| 514 | + ], |
|
| 515 | + 'data' => $ret |
|
| 516 | + ]); |
|
| 517 | + |
|
| 518 | + // une globale pour le debug en cas de crash memoire |
|
| 519 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 520 | + |
|
| 521 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 522 | + if ($term_fonction === 'svg') { |
|
| 523 | + if ($creer and !$support_svg) { |
|
| 524 | + process_image_svg_identite($ret); |
|
| 525 | + $ret['creer'] = false; |
|
| 526 | + } |
|
| 527 | + } |
|
| 528 | + else { |
|
| 529 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 530 | + return false; |
|
| 531 | + } |
|
| 532 | + } |
|
| 533 | + |
|
| 534 | + return $ret; |
|
| 535 | 535 | } |
| 536 | 536 | |
| 537 | 537 | |
@@ -540,53 +540,53 @@ discard block |
||
| 540 | 540 | * @return array |
| 541 | 541 | */ |
| 542 | 542 | function _image_extensions_acceptees_en_entree() { |
| 543 | - static $extensions = null; |
|
| 544 | - if (empty($extensions)) { |
|
| 545 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 546 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 547 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 548 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 549 | - $extensions = array_map('trim', $extensions); |
|
| 550 | - $extensions = array_filter($extensions); |
|
| 551 | - $extensions = array_unique($extensions); |
|
| 552 | - if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 553 | - } |
|
| 554 | - } |
|
| 555 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 556 | - } |
|
| 557 | - |
|
| 558 | - return $extensions; |
|
| 543 | + static $extensions = null; |
|
| 544 | + if (empty($extensions)) { |
|
| 545 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 546 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 547 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 548 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 549 | + $extensions = array_map('trim', $extensions); |
|
| 550 | + $extensions = array_filter($extensions); |
|
| 551 | + $extensions = array_unique($extensions); |
|
| 552 | + if (in_array('jpg', $extensions)) { $extensions[] = 'jpeg'; |
|
| 553 | + } |
|
| 554 | + } |
|
| 555 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 556 | + } |
|
| 557 | + |
|
| 558 | + return $extensions; |
|
| 559 | 559 | } |
| 560 | 560 | |
| 561 | 561 | /** |
| 562 | 562 | * @return array|string[]|null |
| 563 | 563 | */ |
| 564 | 564 | function _image_extensions_acceptees_en_sortie() { |
| 565 | - static $extensions = null; |
|
| 566 | - if (empty($extensions)) { |
|
| 567 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 568 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 569 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 570 | - $extensions = array_diff($extensions, ['gif']); |
|
| 571 | - } |
|
| 572 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 573 | - $extensions = array_diff($extensions, ['webp']); |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $extensions; |
|
| 565 | + static $extensions = null; |
|
| 566 | + if (empty($extensions)) { |
|
| 567 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 568 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 569 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 570 | + $extensions = array_diff($extensions, ['gif']); |
|
| 571 | + } |
|
| 572 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 573 | + $extensions = array_diff($extensions, ['webp']); |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $extensions; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | function _image_extension_normalisee($extension) { |
| 581 | - $extension = strtolower($extension); |
|
| 582 | - if ($extension === 'jpeg') { |
|
| 583 | - $extension = 'jpg'; |
|
| 584 | - } |
|
| 585 | - return $extension; |
|
| 581 | + $extension = strtolower($extension); |
|
| 582 | + if ($extension === 'jpeg') { |
|
| 583 | + $extension = 'jpg'; |
|
| 584 | + } |
|
| 585 | + return $extension; |
|
| 586 | 586 | } |
| 587 | 587 | |
| 588 | 588 | function _image_extensions_conservent_transparence() { |
| 589 | - return ['png', 'webp']; |
|
| 589 | + return ['png', 'webp']; |
|
| 590 | 590 | } |
| 591 | 591 | |
| 592 | 592 | |
@@ -596,12 +596,12 @@ discard block |
||
| 596 | 596 | * @return string |
| 597 | 597 | */ |
| 598 | 598 | function _image_trouver_extension($path) { |
| 599 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 600 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 601 | - $terminaison = strtolower($regs[1]); |
|
| 602 | - return $terminaison; |
|
| 603 | - } |
|
| 604 | - return ''; |
|
| 599 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 600 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 601 | + $terminaison = strtolower($regs[1]); |
|
| 602 | + return $terminaison; |
|
| 603 | + } |
|
| 604 | + return ''; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | /** |
@@ -612,33 +612,33 @@ discard block |
||
| 612 | 612 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 613 | 613 | */ |
| 614 | 614 | function _image_trouver_extension_pertinente($path) { |
| 615 | - $path = supprimer_timestamp($path); |
|
| 616 | - $terminaison = _image_trouver_extension($path); |
|
| 617 | - if ($terminaison == 'jpg') { |
|
| 618 | - $terminaison = 'jpeg'; |
|
| 619 | - } |
|
| 620 | - |
|
| 621 | - if (!file_exists($path)) { |
|
| 622 | - return $terminaison; |
|
| 623 | - } |
|
| 624 | - |
|
| 625 | - if (!$info = @spip_getimagesize($path)) { |
|
| 626 | - return $terminaison; |
|
| 627 | - } |
|
| 628 | - |
|
| 629 | - if (isset($info['mime'])) { |
|
| 630 | - $mime = $info['mime']; |
|
| 631 | - } |
|
| 632 | - else { |
|
| 633 | - $mime = image_type_to_mime_type($info[2]); |
|
| 634 | - } |
|
| 635 | - |
|
| 636 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 637 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 638 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 639 | - $terminaison = $_terminaison; |
|
| 640 | - } |
|
| 641 | - return $terminaison; |
|
| 615 | + $path = supprimer_timestamp($path); |
|
| 616 | + $terminaison = _image_trouver_extension($path); |
|
| 617 | + if ($terminaison == 'jpg') { |
|
| 618 | + $terminaison = 'jpeg'; |
|
| 619 | + } |
|
| 620 | + |
|
| 621 | + if (!file_exists($path)) { |
|
| 622 | + return $terminaison; |
|
| 623 | + } |
|
| 624 | + |
|
| 625 | + if (!$info = @spip_getimagesize($path)) { |
|
| 626 | + return $terminaison; |
|
| 627 | + } |
|
| 628 | + |
|
| 629 | + if (isset($info['mime'])) { |
|
| 630 | + $mime = $info['mime']; |
|
| 631 | + } |
|
| 632 | + else { |
|
| 633 | + $mime = image_type_to_mime_type($info[2]); |
|
| 634 | + } |
|
| 635 | + |
|
| 636 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 637 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 638 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 639 | + $terminaison = $_terminaison; |
|
| 640 | + } |
|
| 641 | + return $terminaison; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -646,36 +646,36 @@ discard block |
||
| 646 | 646 | * @return string |
| 647 | 647 | */ |
| 648 | 648 | function _image_trouver_extension_depuis_mime($mime) { |
| 649 | - switch (strtolower($mime)) { |
|
| 650 | - case 'image/png': |
|
| 651 | - case 'image/x-png': |
|
| 652 | - $terminaison = 'png'; |
|
| 653 | - break; |
|
| 654 | - |
|
| 655 | - case 'image/jpg': |
|
| 656 | - case 'image/jpeg': |
|
| 657 | - case 'image/pjpeg': |
|
| 658 | - $terminaison = 'jpeg'; |
|
| 659 | - break; |
|
| 660 | - |
|
| 661 | - case 'image/gif': |
|
| 662 | - $terminaison = 'gif'; |
|
| 663 | - break; |
|
| 664 | - |
|
| 665 | - case 'image/webp': |
|
| 666 | - case 'image/x-webp': |
|
| 667 | - $terminaison = 'webp'; |
|
| 668 | - break; |
|
| 669 | - |
|
| 670 | - case 'image/svg+xml': |
|
| 671 | - $terminaison = 'svg'; |
|
| 672 | - break; |
|
| 673 | - |
|
| 674 | - default: |
|
| 675 | - $terminaison = ''; |
|
| 676 | - } |
|
| 677 | - |
|
| 678 | - return $terminaison; |
|
| 649 | + switch (strtolower($mime)) { |
|
| 650 | + case 'image/png': |
|
| 651 | + case 'image/x-png': |
|
| 652 | + $terminaison = 'png'; |
|
| 653 | + break; |
|
| 654 | + |
|
| 655 | + case 'image/jpg': |
|
| 656 | + case 'image/jpeg': |
|
| 657 | + case 'image/pjpeg': |
|
| 658 | + $terminaison = 'jpeg'; |
|
| 659 | + break; |
|
| 660 | + |
|
| 661 | + case 'image/gif': |
|
| 662 | + $terminaison = 'gif'; |
|
| 663 | + break; |
|
| 664 | + |
|
| 665 | + case 'image/webp': |
|
| 666 | + case 'image/x-webp': |
|
| 667 | + $terminaison = 'webp'; |
|
| 668 | + break; |
|
| 669 | + |
|
| 670 | + case 'image/svg+xml': |
|
| 671 | + $terminaison = 'svg'; |
|
| 672 | + break; |
|
| 673 | + |
|
| 674 | + default: |
|
| 675 | + $terminaison = ''; |
|
| 676 | + } |
|
| 677 | + |
|
| 678 | + return $terminaison; |
|
| 679 | 679 | } |
| 680 | 680 | |
| 681 | 681 | |
@@ -695,18 +695,18 @@ discard block |
||
| 695 | 695 | * Une ressource de type Image GD. |
| 696 | 696 | */ |
| 697 | 697 | function _imagecreatefrom_func(string $func, string $filename) { |
| 698 | - if (!function_exists($func)) { |
|
| 699 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 700 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 701 | - return null; |
|
| 702 | - } |
|
| 703 | - $img = @$func($filename); |
|
| 704 | - if (!$img) { |
|
| 705 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 706 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 707 | - $img = imagecreate(10, 10); |
|
| 708 | - } |
|
| 709 | - return $img; |
|
| 698 | + if (!function_exists($func)) { |
|
| 699 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 700 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 701 | + return null; |
|
| 702 | + } |
|
| 703 | + $img = @$func($filename); |
|
| 704 | + if (!$img) { |
|
| 705 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 706 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 707 | + $img = imagecreate(10, 10); |
|
| 708 | + } |
|
| 709 | + return $img; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | * Une ressource de type Image GD. |
| 723 | 723 | */ |
| 724 | 724 | function _imagecreatefromjpeg($filename) { |
| 725 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 725 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 726 | 726 | } |
| 727 | 727 | |
| 728 | 728 | /** |
@@ -738,7 +738,7 @@ discard block |
||
| 738 | 738 | * Une ressource de type Image GD. |
| 739 | 739 | */ |
| 740 | 740 | function _imagecreatefrompng($filename) { |
| 741 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 741 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | /** |
@@ -754,7 +754,7 @@ discard block |
||
| 754 | 754 | * Une ressource de type Image GD. |
| 755 | 755 | */ |
| 756 | 756 | function _imagecreatefromgif($filename) { |
| 757 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 757 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 758 | 758 | } |
| 759 | 759 | |
| 760 | 760 | |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | * Une ressource de type Image GD. |
| 772 | 772 | */ |
| 773 | 773 | function _imagecreatefromwebp($filename) { |
| 774 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 774 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | /** |
@@ -789,24 +789,24 @@ discard block |
||
| 789 | 789 | * - true si une image est bien retournée. |
| 790 | 790 | */ |
| 791 | 791 | function _image_imagepng($img, $fichier) { |
| 792 | - if (!function_exists('imagepng')) { |
|
| 793 | - return false; |
|
| 794 | - } |
|
| 795 | - $tmp = $fichier . '.tmp'; |
|
| 796 | - $ret = imagepng($img, $tmp); |
|
| 797 | - if (file_exists($tmp)) { |
|
| 798 | - $taille_test = getimagesize($tmp); |
|
| 799 | - if ($taille_test[0] < 1) { |
|
| 800 | - return false; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 804 | - @rename($tmp, $fichier); |
|
| 805 | - |
|
| 806 | - return $ret; |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - return false; |
|
| 792 | + if (!function_exists('imagepng')) { |
|
| 793 | + return false; |
|
| 794 | + } |
|
| 795 | + $tmp = $fichier . '.tmp'; |
|
| 796 | + $ret = imagepng($img, $tmp); |
|
| 797 | + if (file_exists($tmp)) { |
|
| 798 | + $taille_test = getimagesize($tmp); |
|
| 799 | + if ($taille_test[0] < 1) { |
|
| 800 | + return false; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 804 | + @rename($tmp, $fichier); |
|
| 805 | + |
|
| 806 | + return $ret; |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + return false; |
|
| 810 | 810 | } |
| 811 | 811 | |
| 812 | 812 | /** |
@@ -824,24 +824,24 @@ discard block |
||
| 824 | 824 | * - true si une image est bien retournée. |
| 825 | 825 | */ |
| 826 | 826 | function _image_imagegif($img, $fichier) { |
| 827 | - if (!function_exists('imagegif')) { |
|
| 828 | - return false; |
|
| 829 | - } |
|
| 830 | - $tmp = $fichier . '.tmp'; |
|
| 831 | - $ret = imagegif($img, $tmp); |
|
| 832 | - if (file_exists($tmp)) { |
|
| 833 | - $taille_test = getimagesize($tmp); |
|
| 834 | - if ($taille_test[0] < 1) { |
|
| 835 | - return false; |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 839 | - @rename($tmp, $fichier); |
|
| 840 | - |
|
| 841 | - return $ret; |
|
| 842 | - } |
|
| 843 | - |
|
| 844 | - return false; |
|
| 827 | + if (!function_exists('imagegif')) { |
|
| 828 | + return false; |
|
| 829 | + } |
|
| 830 | + $tmp = $fichier . '.tmp'; |
|
| 831 | + $ret = imagegif($img, $tmp); |
|
| 832 | + if (file_exists($tmp)) { |
|
| 833 | + $taille_test = getimagesize($tmp); |
|
| 834 | + if ($taille_test[0] < 1) { |
|
| 835 | + return false; |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 839 | + @rename($tmp, $fichier); |
|
| 840 | + |
|
| 841 | + return $ret; |
|
| 842 | + } |
|
| 843 | + |
|
| 844 | + return false; |
|
| 845 | 845 | } |
| 846 | 846 | |
| 847 | 847 | /** |
@@ -864,29 +864,29 @@ discard block |
||
| 864 | 864 | * - true si une image est bien retournée. |
| 865 | 865 | */ |
| 866 | 866 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 867 | - if (!function_exists('imagejpeg')) { |
|
| 868 | - return false; |
|
| 869 | - } |
|
| 870 | - $tmp = $fichier . '.tmp'; |
|
| 867 | + if (!function_exists('imagejpeg')) { |
|
| 868 | + return false; |
|
| 869 | + } |
|
| 870 | + $tmp = $fichier . '.tmp'; |
|
| 871 | 871 | |
| 872 | - // Enable interlancing |
|
| 873 | - imageinterlace($img, true); |
|
| 872 | + // Enable interlancing |
|
| 873 | + imageinterlace($img, true); |
|
| 874 | 874 | |
| 875 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 875 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 876 | 876 | |
| 877 | - if (file_exists($tmp)) { |
|
| 878 | - $taille_test = getimagesize($tmp); |
|
| 879 | - if ($taille_test[0] < 1) { |
|
| 880 | - return false; |
|
| 881 | - } |
|
| 877 | + if (file_exists($tmp)) { |
|
| 878 | + $taille_test = getimagesize($tmp); |
|
| 879 | + if ($taille_test[0] < 1) { |
|
| 880 | + return false; |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 884 | - @rename($tmp, $fichier); |
|
| 883 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 884 | + @rename($tmp, $fichier); |
|
| 885 | 885 | |
| 886 | - return $ret; |
|
| 887 | - } |
|
| 886 | + return $ret; |
|
| 887 | + } |
|
| 888 | 888 | |
| 889 | - return false; |
|
| 889 | + return false; |
|
| 890 | 890 | } |
| 891 | 891 | |
| 892 | 892 | /** |
@@ -904,9 +904,9 @@ discard block |
||
| 904 | 904 | * true si le fichier a bien été créé ; false sinon. |
| 905 | 905 | */ |
| 906 | 906 | function _image_imageico($img, $fichier) { |
| 907 | - $gd_image_array = [$img]; |
|
| 907 | + $gd_image_array = [$img]; |
|
| 908 | 908 | |
| 909 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 909 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | |
@@ -925,24 +925,24 @@ discard block |
||
| 925 | 925 | * - true si une image est bien retournée. |
| 926 | 926 | */ |
| 927 | 927 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 928 | - if (!function_exists('imagewebp')) { |
|
| 929 | - return false; |
|
| 930 | - } |
|
| 931 | - $tmp = $fichier . '.tmp'; |
|
| 932 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 933 | - if (file_exists($tmp)) { |
|
| 934 | - $taille_test = getimagesize($tmp); |
|
| 935 | - if ($taille_test[0] < 1) { |
|
| 936 | - return false; |
|
| 937 | - } |
|
| 938 | - |
|
| 939 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 940 | - @rename($tmp, $fichier); |
|
| 941 | - |
|
| 942 | - return $ret; |
|
| 943 | - } |
|
| 944 | - |
|
| 945 | - return false; |
|
| 928 | + if (!function_exists('imagewebp')) { |
|
| 929 | + return false; |
|
| 930 | + } |
|
| 931 | + $tmp = $fichier . '.tmp'; |
|
| 932 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 933 | + if (file_exists($tmp)) { |
|
| 934 | + $taille_test = getimagesize($tmp); |
|
| 935 | + if ($taille_test[0] < 1) { |
|
| 936 | + return false; |
|
| 937 | + } |
|
| 938 | + |
|
| 939 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 940 | + @rename($tmp, $fichier); |
|
| 941 | + |
|
| 942 | + return $ret; |
|
| 943 | + } |
|
| 944 | + |
|
| 945 | + return false; |
|
| 946 | 946 | } |
| 947 | 947 | |
| 948 | 948 | /** |
@@ -962,35 +962,35 @@ discard block |
||
| 962 | 962 | */ |
| 963 | 963 | function _image_imagesvg($img, $fichier) { |
| 964 | 964 | |
| 965 | - $tmp = $fichier . '.tmp'; |
|
| 966 | - if (strpos($img, '<') === false) { |
|
| 967 | - $img = supprimer_timestamp($img); |
|
| 968 | - if (!file_exists($img)) { |
|
| 969 | - return false; |
|
| 970 | - } |
|
| 971 | - @copy($img, $tmp); |
|
| 972 | - if (filesize($tmp) == filesize($img)) { |
|
| 973 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 974 | - @rename($tmp, $fichier); |
|
| 975 | - return true; |
|
| 976 | - } |
|
| 977 | - return false; |
|
| 978 | - } |
|
| 979 | - |
|
| 980 | - file_put_contents($tmp, $img); |
|
| 981 | - if (file_exists($tmp)) { |
|
| 982 | - $taille_test = spip_getimagesize($tmp); |
|
| 983 | - if ($taille_test[0] < 1) { |
|
| 984 | - return false; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | - @rename($tmp, $fichier); |
|
| 989 | - |
|
| 990 | - return true; |
|
| 991 | - } |
|
| 992 | - |
|
| 993 | - return false; |
|
| 965 | + $tmp = $fichier . '.tmp'; |
|
| 966 | + if (strpos($img, '<') === false) { |
|
| 967 | + $img = supprimer_timestamp($img); |
|
| 968 | + if (!file_exists($img)) { |
|
| 969 | + return false; |
|
| 970 | + } |
|
| 971 | + @copy($img, $tmp); |
|
| 972 | + if (filesize($tmp) == filesize($img)) { |
|
| 973 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 974 | + @rename($tmp, $fichier); |
|
| 975 | + return true; |
|
| 976 | + } |
|
| 977 | + return false; |
|
| 978 | + } |
|
| 979 | + |
|
| 980 | + file_put_contents($tmp, $img); |
|
| 981 | + if (file_exists($tmp)) { |
|
| 982 | + $taille_test = spip_getimagesize($tmp); |
|
| 983 | + if ($taille_test[0] < 1) { |
|
| 984 | + return false; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | + @rename($tmp, $fichier); |
|
| 989 | + |
|
| 990 | + return true; |
|
| 991 | + } |
|
| 992 | + |
|
| 993 | + return false; |
|
| 994 | 994 | } |
| 995 | 995 | |
| 996 | 996 | |
@@ -1018,29 +1018,29 @@ discard block |
||
| 1018 | 1018 | * - false sinon. |
| 1019 | 1019 | */ |
| 1020 | 1020 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1021 | - if (is_null($fonction)) { |
|
| 1022 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1023 | - } |
|
| 1024 | - $ret = false; |
|
| 1025 | - #un flag pour reperer les images gravees |
|
| 1026 | - $lock = |
|
| 1027 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1028 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1029 | - if ( |
|
| 1030 | - function_exists($fonction) |
|
| 1031 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1032 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1033 | - && !$lock |
|
| 1034 | - ) { |
|
| 1035 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1036 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1037 | - list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']); |
|
| 1038 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1039 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1040 | - } |
|
| 1041 | - } |
|
| 1042 | - |
|
| 1043 | - return $ret; |
|
| 1021 | + if (is_null($fonction)) { |
|
| 1022 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1023 | + } |
|
| 1024 | + $ret = false; |
|
| 1025 | + #un flag pour reperer les images gravees |
|
| 1026 | + $lock = |
|
| 1027 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1028 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1029 | + if ( |
|
| 1030 | + function_exists($fonction) |
|
| 1031 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1032 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1033 | + && !$lock |
|
| 1034 | + ) { |
|
| 1035 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1036 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1037 | + list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']); |
|
| 1038 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1039 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1040 | + } |
|
| 1041 | + } |
|
| 1042 | + |
|
| 1043 | + return $ret; |
|
| 1044 | 1044 | } |
| 1045 | 1045 | |
| 1046 | 1046 | /** |
@@ -1053,27 +1053,27 @@ discard block |
||
| 1053 | 1053 | * Chemin vers le fichier manquant |
| 1054 | 1054 | **/ |
| 1055 | 1055 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1056 | - $reconstruire = []; |
|
| 1057 | - $fichier = $fichier_manquant; |
|
| 1058 | - while ( |
|
| 1059 | - strpos($fichier, '://') === false |
|
| 1060 | - and !@file_exists($fichier) |
|
| 1061 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1062 | - and $valeurs = unserialize($source) |
|
| 1063 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1064 | - ) { |
|
| 1065 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1066 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1067 | - } |
|
| 1068 | - while (count($reconstruire)) { |
|
| 1069 | - $r = array_pop($reconstruire); |
|
| 1070 | - $fonction = $r[0]; |
|
| 1071 | - $args = $r[1]; |
|
| 1072 | - call_user_func_array($fonction, $args); |
|
| 1073 | - } |
|
| 1074 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1075 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1076 | - ramasse_miettes($fichier_manquant); |
|
| 1056 | + $reconstruire = []; |
|
| 1057 | + $fichier = $fichier_manquant; |
|
| 1058 | + while ( |
|
| 1059 | + strpos($fichier, '://') === false |
|
| 1060 | + and !@file_exists($fichier) |
|
| 1061 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1062 | + and $valeurs = unserialize($source) |
|
| 1063 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1064 | + ) { |
|
| 1065 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1066 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1067 | + } |
|
| 1068 | + while (count($reconstruire)) { |
|
| 1069 | + $r = array_pop($reconstruire); |
|
| 1070 | + $fonction = $r[0]; |
|
| 1071 | + $args = $r[1]; |
|
| 1072 | + call_user_func_array($fonction, $args); |
|
| 1073 | + } |
|
| 1074 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1075 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1076 | + ramasse_miettes($fichier_manquant); |
|
| 1077 | 1077 | } |
| 1078 | 1078 | |
| 1079 | 1079 | /** |
@@ -1093,28 +1093,28 @@ discard block |
||
| 1093 | 1093 | * Chemin du fichier d'image calculé |
| 1094 | 1094 | **/ |
| 1095 | 1095 | function ramasse_miettes($fichier) { |
| 1096 | - if ( |
|
| 1097 | - strpos($fichier, '://') !== false |
|
| 1098 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1099 | - or !$valeurs = unserialize($source) |
|
| 1100 | - ) { |
|
| 1101 | - return; |
|
| 1102 | - } |
|
| 1103 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1104 | - while ( |
|
| 1105 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1106 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1107 | - and (lire_fichier( |
|
| 1108 | - $src = "$fichier.src", |
|
| 1109 | - $source |
|
| 1110 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1111 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1112 | - ) { |
|
| 1113 | - # on efface le fichier |
|
| 1114 | - spip_unlink($fichier); |
|
| 1115 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1116 | - #spip_unlink($src); |
|
| 1117 | - } |
|
| 1096 | + if ( |
|
| 1097 | + strpos($fichier, '://') !== false |
|
| 1098 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1099 | + or !$valeurs = unserialize($source) |
|
| 1100 | + ) { |
|
| 1101 | + return; |
|
| 1102 | + } |
|
| 1103 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1104 | + while ( |
|
| 1105 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1106 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1107 | + and (lire_fichier( |
|
| 1108 | + $src = "$fichier.src", |
|
| 1109 | + $source |
|
| 1110 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1111 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1112 | + ) { |
|
| 1113 | + # on efface le fichier |
|
| 1114 | + spip_unlink($fichier); |
|
| 1115 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1116 | + #spip_unlink($src); |
|
| 1117 | + } |
|
| 1118 | 1118 | } |
| 1119 | 1119 | |
| 1120 | 1120 | |
@@ -1139,71 +1139,71 @@ discard block |
||
| 1139 | 1139 | * Code HTML de l'image |
| 1140 | 1140 | **/ |
| 1141 | 1141 | function image_graver($img) { |
| 1142 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1143 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1144 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1145 | - |
|
| 1146 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1147 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1148 | - $fichier = substr($fichier, 0, $p); |
|
| 1149 | - } |
|
| 1150 | - if (strlen($fichier) < 1) { |
|
| 1151 | - $fichier = $img; |
|
| 1152 | - } |
|
| 1153 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1154 | - # et qu'il ne s'agit pas d'une URL |
|
| 1155 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1156 | - reconstruire_image_intermediaire($fichier); |
|
| 1157 | - } |
|
| 1158 | - ramasse_miettes($fichier); |
|
| 1159 | - |
|
| 1160 | - // ajouter le timestamp si besoin |
|
| 1161 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1162 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1163 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1164 | - } |
|
| 1165 | - |
|
| 1166 | - return $img; |
|
| 1142 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1143 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1144 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1145 | + |
|
| 1146 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1147 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1148 | + $fichier = substr($fichier, 0, $p); |
|
| 1149 | + } |
|
| 1150 | + if (strlen($fichier) < 1) { |
|
| 1151 | + $fichier = $img; |
|
| 1152 | + } |
|
| 1153 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1154 | + # et qu'il ne s'agit pas d'une URL |
|
| 1155 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1156 | + reconstruire_image_intermediaire($fichier); |
|
| 1157 | + } |
|
| 1158 | + ramasse_miettes($fichier); |
|
| 1159 | + |
|
| 1160 | + // ajouter le timestamp si besoin |
|
| 1161 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1162 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1163 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1164 | + } |
|
| 1165 | + |
|
| 1166 | + return $img; |
|
| 1167 | 1167 | } |
| 1168 | 1168 | |
| 1169 | 1169 | |
| 1170 | 1170 | if (!function_exists('imagepalettetotruecolor')) { |
| 1171 | - /** |
|
| 1172 | - * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1173 | - * |
|
| 1174 | - * @note Pour compatibilité avec PHP < 5.5 |
|
| 1175 | - * |
|
| 1176 | - * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1177 | - * |
|
| 1178 | - * @param ressource $img |
|
| 1179 | - * @return bool |
|
| 1180 | - * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1181 | - * - false si la transformation ne peut être faite. |
|
| 1182 | - **/ |
|
| 1183 | - function imagepalettetotruecolor(&$img) { |
|
| 1184 | - if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1185 | - return false; |
|
| 1186 | - } elseif (!imageistruecolor($img)) { |
|
| 1187 | - $w = imagesx($img); |
|
| 1188 | - $h = imagesy($img); |
|
| 1189 | - $img1 = imagecreatetruecolor($w, $h); |
|
| 1190 | - //Conserver la transparence si possible |
|
| 1191 | - if (function_exists('ImageCopyResampled')) { |
|
| 1192 | - if (function_exists('imageAntiAlias')) { |
|
| 1193 | - imageAntiAlias($img1, true); |
|
| 1194 | - } |
|
| 1195 | - @imagealphablending($img1, false); |
|
| 1196 | - @imagesavealpha($img1, true); |
|
| 1197 | - @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1198 | - } else { |
|
| 1199 | - imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1200 | - } |
|
| 1201 | - |
|
| 1202 | - $img = $img1; |
|
| 1203 | - } |
|
| 1204 | - |
|
| 1205 | - return true; |
|
| 1206 | - } |
|
| 1171 | + /** |
|
| 1172 | + * Transforme une image à palette indexée (256 couleurs max) en "vraies" couleurs RGB |
|
| 1173 | + * |
|
| 1174 | + * @note Pour compatibilité avec PHP < 5.5 |
|
| 1175 | + * |
|
| 1176 | + * @link http://php.net/manual/fr/function.imagepalettetotruecolor.php |
|
| 1177 | + * |
|
| 1178 | + * @param ressource $img |
|
| 1179 | + * @return bool |
|
| 1180 | + * - true si l'image est déjà en vrai RGB ou peut être transformée |
|
| 1181 | + * - false si la transformation ne peut être faite. |
|
| 1182 | + **/ |
|
| 1183 | + function imagepalettetotruecolor(&$img) { |
|
| 1184 | + if (!$img or !function_exists('imagecreatetruecolor')) { |
|
| 1185 | + return false; |
|
| 1186 | + } elseif (!imageistruecolor($img)) { |
|
| 1187 | + $w = imagesx($img); |
|
| 1188 | + $h = imagesy($img); |
|
| 1189 | + $img1 = imagecreatetruecolor($w, $h); |
|
| 1190 | + //Conserver la transparence si possible |
|
| 1191 | + if (function_exists('ImageCopyResampled')) { |
|
| 1192 | + if (function_exists('imageAntiAlias')) { |
|
| 1193 | + imageAntiAlias($img1, true); |
|
| 1194 | + } |
|
| 1195 | + @imagealphablending($img1, false); |
|
| 1196 | + @imagesavealpha($img1, true); |
|
| 1197 | + @ImageCopyResampled($img1, $img, 0, 0, 0, 0, $w, $h, $w, $h); |
|
| 1198 | + } else { |
|
| 1199 | + imagecopy($img1, $img, 0, 0, 0, 0, $w, $h); |
|
| 1200 | + } |
|
| 1201 | + |
|
| 1202 | + $img = $img1; |
|
| 1203 | + } |
|
| 1204 | + |
|
| 1205 | + return true; |
|
| 1206 | + } |
|
| 1207 | 1207 | } |
| 1208 | 1208 | |
| 1209 | 1209 | /** |
@@ -1230,32 +1230,32 @@ discard block |
||
| 1230 | 1230 | * Code html modifié de la balise. |
| 1231 | 1231 | **/ |
| 1232 | 1232 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1233 | - if ($style === false) { |
|
| 1234 | - $style = extraire_attribut($tag, 'style'); |
|
| 1235 | - } |
|
| 1236 | - |
|
| 1237 | - // enlever le width et height du style |
|
| 1238 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1239 | - if ($style and $style[0] == ';') { |
|
| 1240 | - $style = substr($style, 1); |
|
| 1241 | - } |
|
| 1242 | - |
|
| 1243 | - // mettre des attributs de width et height sur les images, |
|
| 1244 | - // ca accelere le rendu du navigateur |
|
| 1245 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1246 | - // quand on a desactive l'affichage des images. |
|
| 1247 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1248 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1249 | - |
|
| 1250 | - // attributs deprecies. Transformer en CSS |
|
| 1251 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1252 | - $style = "margin:${espace}px;" . $style; |
|
| 1253 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1254 | - } |
|
| 1255 | - |
|
| 1256 | - $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 1257 | - |
|
| 1258 | - return $tag; |
|
| 1233 | + if ($style === false) { |
|
| 1234 | + $style = extraire_attribut($tag, 'style'); |
|
| 1235 | + } |
|
| 1236 | + |
|
| 1237 | + // enlever le width et height du style |
|
| 1238 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1239 | + if ($style and $style[0] == ';') { |
|
| 1240 | + $style = substr($style, 1); |
|
| 1241 | + } |
|
| 1242 | + |
|
| 1243 | + // mettre des attributs de width et height sur les images, |
|
| 1244 | + // ca accelere le rendu du navigateur |
|
| 1245 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1246 | + // quand on a desactive l'affichage des images. |
|
| 1247 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1248 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1249 | + |
|
| 1250 | + // attributs deprecies. Transformer en CSS |
|
| 1251 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1252 | + $style = "margin:${espace}px;" . $style; |
|
| 1253 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1254 | + } |
|
| 1255 | + |
|
| 1256 | + $tag = inserer_attribut($tag, 'style', $style, true, $style ? false : true); |
|
| 1257 | + |
|
| 1258 | + return $tag; |
|
| 1259 | 1259 | } |
| 1260 | 1260 | |
| 1261 | 1261 | |
@@ -1281,72 +1281,72 @@ discard block |
||
| 1281 | 1281 | * Retourne le code HTML de l'image |
| 1282 | 1282 | **/ |
| 1283 | 1283 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1284 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1285 | - |
|
| 1286 | - // fermer les tags img pas bien fermes; |
|
| 1287 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1288 | - |
|
| 1289 | - // le style |
|
| 1290 | - $style = $valeurs['style']; |
|
| 1291 | - if (isset($surcharge['style'])) { |
|
| 1292 | - $style = $surcharge['style']; |
|
| 1293 | - unset($surcharge['style']); |
|
| 1294 | - } |
|
| 1295 | - |
|
| 1296 | - // traiter specifiquement la largeur et la hauteur |
|
| 1297 | - $width = $valeurs['largeur']; |
|
| 1298 | - if (isset($surcharge['width'])) { |
|
| 1299 | - $width = $surcharge['width']; |
|
| 1300 | - unset($surcharge['width']); |
|
| 1301 | - } |
|
| 1302 | - $height = $valeurs['hauteur']; |
|
| 1303 | - if (isset($surcharge['height'])) { |
|
| 1304 | - $height = $surcharge['height']; |
|
| 1305 | - unset($surcharge['height']); |
|
| 1306 | - } |
|
| 1307 | - |
|
| 1308 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1309 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1310 | - // on remplace toute les ref a src dans le tag |
|
| 1311 | - $src = extraire_attribut($tag, 'src'); |
|
| 1312 | - if (isset($surcharge['src'])) { |
|
| 1313 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1314 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1315 | - // pas garanti comme methode, mais mieux que rien |
|
| 1316 | - if (strpos($src, '&') !== false) { |
|
| 1317 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1318 | - } |
|
| 1319 | - $src = $surcharge['src']; |
|
| 1320 | - unset($surcharge['src']); |
|
| 1321 | - } |
|
| 1322 | - |
|
| 1323 | - $class = $valeurs['class']; |
|
| 1324 | - if (isset($surcharge['class'])) { |
|
| 1325 | - $class = $surcharge['class']; |
|
| 1326 | - unset($surcharge['class']); |
|
| 1327 | - } |
|
| 1328 | - if (strlen($class)) { |
|
| 1329 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1330 | - } |
|
| 1331 | - |
|
| 1332 | - if (count($surcharge)) { |
|
| 1333 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1334 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1335 | - } |
|
| 1336 | - } |
|
| 1337 | - |
|
| 1338 | - $tag = pipeline( |
|
| 1339 | - 'image_ecrire_tag_finir', |
|
| 1340 | - [ |
|
| 1341 | - 'args' => [ |
|
| 1342 | - 'valeurs' => $valeurs, |
|
| 1343 | - 'surcharge' => $surcharge, |
|
| 1344 | - ], |
|
| 1345 | - 'data' => $tag |
|
| 1346 | - ] |
|
| 1347 | - ); |
|
| 1348 | - |
|
| 1349 | - return $tag; |
|
| 1284 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1285 | + |
|
| 1286 | + // fermer les tags img pas bien fermes; |
|
| 1287 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1288 | + |
|
| 1289 | + // le style |
|
| 1290 | + $style = $valeurs['style']; |
|
| 1291 | + if (isset($surcharge['style'])) { |
|
| 1292 | + $style = $surcharge['style']; |
|
| 1293 | + unset($surcharge['style']); |
|
| 1294 | + } |
|
| 1295 | + |
|
| 1296 | + // traiter specifiquement la largeur et la hauteur |
|
| 1297 | + $width = $valeurs['largeur']; |
|
| 1298 | + if (isset($surcharge['width'])) { |
|
| 1299 | + $width = $surcharge['width']; |
|
| 1300 | + unset($surcharge['width']); |
|
| 1301 | + } |
|
| 1302 | + $height = $valeurs['hauteur']; |
|
| 1303 | + if (isset($surcharge['height'])) { |
|
| 1304 | + $height = $surcharge['height']; |
|
| 1305 | + unset($surcharge['height']); |
|
| 1306 | + } |
|
| 1307 | + |
|
| 1308 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1309 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1310 | + // on remplace toute les ref a src dans le tag |
|
| 1311 | + $src = extraire_attribut($tag, 'src'); |
|
| 1312 | + if (isset($surcharge['src'])) { |
|
| 1313 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1314 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1315 | + // pas garanti comme methode, mais mieux que rien |
|
| 1316 | + if (strpos($src, '&') !== false) { |
|
| 1317 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1318 | + } |
|
| 1319 | + $src = $surcharge['src']; |
|
| 1320 | + unset($surcharge['src']); |
|
| 1321 | + } |
|
| 1322 | + |
|
| 1323 | + $class = $valeurs['class']; |
|
| 1324 | + if (isset($surcharge['class'])) { |
|
| 1325 | + $class = $surcharge['class']; |
|
| 1326 | + unset($surcharge['class']); |
|
| 1327 | + } |
|
| 1328 | + if (strlen($class)) { |
|
| 1329 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1330 | + } |
|
| 1331 | + |
|
| 1332 | + if (count($surcharge)) { |
|
| 1333 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1334 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1335 | + } |
|
| 1336 | + } |
|
| 1337 | + |
|
| 1338 | + $tag = pipeline( |
|
| 1339 | + 'image_ecrire_tag_finir', |
|
| 1340 | + [ |
|
| 1341 | + 'args' => [ |
|
| 1342 | + 'valeurs' => $valeurs, |
|
| 1343 | + 'surcharge' => $surcharge, |
|
| 1344 | + ], |
|
| 1345 | + 'data' => $tag |
|
| 1346 | + ] |
|
| 1347 | + ); |
|
| 1348 | + |
|
| 1349 | + return $tag; |
|
| 1350 | 1350 | } |
| 1351 | 1351 | |
| 1352 | 1352 | /** |
@@ -1369,257 +1369,257 @@ discard block |
||
| 1369 | 1369 | * Description de l'image, sinon null. |
| 1370 | 1370 | **/ |
| 1371 | 1371 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1372 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1373 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1374 | - $image = $valeurs['fichier']; |
|
| 1375 | - $format = $valeurs['format_source']; |
|
| 1376 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1377 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1378 | - |
|
| 1379 | - $format_sortie = $valeurs['format_dest']; |
|
| 1380 | - |
|
| 1381 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1382 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1383 | - } |
|
| 1384 | - |
|
| 1385 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1386 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1387 | - return; |
|
| 1388 | - } |
|
| 1389 | - $destination = "$destdir/$destfile"; |
|
| 1390 | - |
|
| 1391 | - // calculer la taille |
|
| 1392 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1393 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1394 | - list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1395 | - } |
|
| 1396 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1397 | - $destWidth = $maxWidth; |
|
| 1398 | - $destHeight = $maxHeight; |
|
| 1399 | - } else { |
|
| 1400 | - spip_log("echec $process sur $image"); |
|
| 1401 | - |
|
| 1402 | - return; |
|
| 1403 | - } |
|
| 1404 | - |
|
| 1405 | - $vignette = ''; |
|
| 1406 | - |
|
| 1407 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1408 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1409 | - $vignette = $destination . '.' . $format; |
|
| 1410 | - @copy($image, $vignette); |
|
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1414 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1415 | - $format_sortie = 'svg'; |
|
| 1416 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1417 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1418 | - _image_gd_output($svg, $valeurs); |
|
| 1419 | - } |
|
| 1420 | - } |
|
| 1421 | - |
|
| 1422 | - // imagemagick en ligne de commande |
|
| 1423 | - elseif ($process == 'convert') { |
|
| 1424 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1425 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1426 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1427 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1428 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1429 | - } |
|
| 1430 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1431 | - $commande = str_replace( |
|
| 1432 | - ['%x', '%y', '%src', '%dest'], |
|
| 1433 | - [ |
|
| 1434 | - $destWidth, |
|
| 1435 | - $destHeight, |
|
| 1436 | - escapeshellcmd($image), |
|
| 1437 | - escapeshellcmd($vignette) |
|
| 1438 | - ], |
|
| 1439 | - _RESIZE_COMMAND |
|
| 1440 | - ); |
|
| 1441 | - spip_log($commande); |
|
| 1442 | - exec($commande); |
|
| 1443 | - if (!@file_exists($vignette)) { |
|
| 1444 | - spip_log("echec convert sur $vignette"); |
|
| 1445 | - |
|
| 1446 | - return; // echec commande |
|
| 1447 | - } |
|
| 1448 | - } |
|
| 1449 | - |
|
| 1450 | - // php5 imagemagick |
|
| 1451 | - elseif ($process == 'imagick') { |
|
| 1452 | - $vignette = "$destination." . $format_sortie; |
|
| 1453 | - |
|
| 1454 | - if (!class_exists('Imagick')) { |
|
| 1455 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1456 | - |
|
| 1457 | - return; |
|
| 1458 | - } |
|
| 1459 | - $imagick = new Imagick(); |
|
| 1460 | - $imagick->readImage($image); |
|
| 1461 | - $imagick->resizeImage( |
|
| 1462 | - $destWidth, |
|
| 1463 | - $destHeight, |
|
| 1464 | - Imagick::FILTER_LANCZOS, |
|
| 1465 | - 1 |
|
| 1466 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1467 | - $imagick->writeImage($vignette); |
|
| 1468 | - |
|
| 1469 | - if (!@file_exists($vignette)) { |
|
| 1470 | - spip_log("echec imagick sur $vignette"); |
|
| 1471 | - |
|
| 1472 | - return; |
|
| 1473 | - } |
|
| 1474 | - } |
|
| 1475 | - |
|
| 1476 | - // netpbm |
|
| 1477 | - elseif ($process == 'netpbm') { |
|
| 1478 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1479 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1480 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1481 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1482 | - return; |
|
| 1483 | - } |
|
| 1484 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1485 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1486 | - if ($format == 'jpg') { |
|
| 1487 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1488 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1489 | - if (!($s = @filesize($vignette))) { |
|
| 1490 | - spip_unlink($vignette); |
|
| 1491 | - } |
|
| 1492 | - if (!@file_exists($vignette)) { |
|
| 1493 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1494 | - |
|
| 1495 | - return; |
|
| 1496 | - } |
|
| 1497 | - } else { |
|
| 1498 | - if ($format == 'gif') { |
|
| 1499 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1500 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1501 | - if (!($s = @filesize($vignette))) { |
|
| 1502 | - spip_unlink($vignette); |
|
| 1503 | - } |
|
| 1504 | - if (!@file_exists($vignette)) { |
|
| 1505 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1506 | - |
|
| 1507 | - return; |
|
| 1508 | - } |
|
| 1509 | - } else { |
|
| 1510 | - if ($format == 'png') { |
|
| 1511 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1512 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1513 | - if (!($s = @filesize($vignette))) { |
|
| 1514 | - spip_unlink($vignette); |
|
| 1515 | - } |
|
| 1516 | - if (!@file_exists($vignette)) { |
|
| 1517 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1518 | - |
|
| 1519 | - return; |
|
| 1520 | - } |
|
| 1521 | - } |
|
| 1522 | - } |
|
| 1523 | - } |
|
| 1524 | - } |
|
| 1525 | - |
|
| 1526 | - // gd ou gd2 |
|
| 1527 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1528 | - if (!function_exists('gd_info')) { |
|
| 1529 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1530 | - |
|
| 1531 | - return; |
|
| 1532 | - } |
|
| 1533 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1534 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1535 | - |
|
| 1536 | - return; |
|
| 1537 | - } |
|
| 1538 | - $destFormat = $format_sortie; |
|
| 1539 | - if (!$destFormat) { |
|
| 1540 | - spip_log("pas de format pour $image"); |
|
| 1541 | - |
|
| 1542 | - return; |
|
| 1543 | - } |
|
| 1544 | - |
|
| 1545 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1546 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1547 | - return ''; |
|
| 1548 | - } |
|
| 1549 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1550 | - if (!$srcImage) { |
|
| 1551 | - spip_log('echec gd1/gd2'); |
|
| 1552 | - |
|
| 1553 | - return; |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - // Initialisation de l'image destination |
|
| 1557 | - $destImage = null; |
|
| 1558 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1559 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1560 | - } |
|
| 1561 | - if (!$destImage) { |
|
| 1562 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1563 | - } |
|
| 1564 | - |
|
| 1565 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1566 | - $ok = false; |
|
| 1567 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1568 | - if ($format == 'gif') { |
|
| 1569 | - // Si un GIF est transparent, |
|
| 1570 | - // fabriquer un PNG transparent |
|
| 1571 | - $transp = imagecolortransparent($srcImage); |
|
| 1572 | - if ($transp > 0) { |
|
| 1573 | - $destFormat = 'png'; |
|
| 1574 | - } |
|
| 1575 | - } |
|
| 1576 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1577 | - // Conserver la transparence |
|
| 1578 | - if (function_exists('imageAntiAlias')) { |
|
| 1579 | - imageAntiAlias($destImage, true); |
|
| 1580 | - } |
|
| 1581 | - @imagealphablending($destImage, false); |
|
| 1582 | - @imagesavealpha($destImage, true); |
|
| 1583 | - } |
|
| 1584 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1585 | - } |
|
| 1586 | - if (!$ok) { |
|
| 1587 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1588 | - } |
|
| 1589 | - |
|
| 1590 | - // Sauvegarde de l'image destination |
|
| 1591 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1592 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1593 | - _image_gd_output($destImage, $valeurs); |
|
| 1594 | - |
|
| 1595 | - if ($srcImage) { |
|
| 1596 | - ImageDestroy($srcImage); |
|
| 1597 | - } |
|
| 1598 | - ImageDestroy($destImage); |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1602 | - $size = [$destWidth, $destHeight]; |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1606 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1607 | - if ($size[0] < 1) { |
|
| 1608 | - $size[0] = $destWidth; |
|
| 1609 | - } |
|
| 1610 | - if ($size[1] < 1) { |
|
| 1611 | - $size[1] = $destHeight; |
|
| 1612 | - } |
|
| 1613 | - |
|
| 1614 | - $retour['width'] = $largeur = $size[0]; |
|
| 1615 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1616 | - |
|
| 1617 | - $retour['fichier'] = $vignette; |
|
| 1618 | - $retour['format'] = $format; |
|
| 1619 | - $retour['date'] = @filemtime($vignette); |
|
| 1620 | - |
|
| 1621 | - // renvoyer l'image |
|
| 1622 | - return $retour; |
|
| 1372 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1373 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1374 | + $image = $valeurs['fichier']; |
|
| 1375 | + $format = $valeurs['format_source']; |
|
| 1376 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1377 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1378 | + |
|
| 1379 | + $format_sortie = $valeurs['format_dest']; |
|
| 1380 | + |
|
| 1381 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1382 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1383 | + } |
|
| 1384 | + |
|
| 1385 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1386 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1387 | + return; |
|
| 1388 | + } |
|
| 1389 | + $destination = "$destdir/$destfile"; |
|
| 1390 | + |
|
| 1391 | + // calculer la taille |
|
| 1392 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1393 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1394 | + list($destWidth, $destHeight) = _image_ratio($valeurs['largeur'], $valeurs['hauteur'], $maxWidth, $maxHeight); |
|
| 1395 | + } |
|
| 1396 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1397 | + $destWidth = $maxWidth; |
|
| 1398 | + $destHeight = $maxHeight; |
|
| 1399 | + } else { |
|
| 1400 | + spip_log("echec $process sur $image"); |
|
| 1401 | + |
|
| 1402 | + return; |
|
| 1403 | + } |
|
| 1404 | + |
|
| 1405 | + $vignette = ''; |
|
| 1406 | + |
|
| 1407 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1408 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1409 | + $vignette = $destination . '.' . $format; |
|
| 1410 | + @copy($image, $vignette); |
|
| 1411 | + } |
|
| 1412 | + |
|
| 1413 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1414 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1415 | + $format_sortie = 'svg'; |
|
| 1416 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1417 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1418 | + _image_gd_output($svg, $valeurs); |
|
| 1419 | + } |
|
| 1420 | + } |
|
| 1421 | + |
|
| 1422 | + // imagemagick en ligne de commande |
|
| 1423 | + elseif ($process == 'convert') { |
|
| 1424 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1425 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1426 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1427 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1428 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1429 | + } |
|
| 1430 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1431 | + $commande = str_replace( |
|
| 1432 | + ['%x', '%y', '%src', '%dest'], |
|
| 1433 | + [ |
|
| 1434 | + $destWidth, |
|
| 1435 | + $destHeight, |
|
| 1436 | + escapeshellcmd($image), |
|
| 1437 | + escapeshellcmd($vignette) |
|
| 1438 | + ], |
|
| 1439 | + _RESIZE_COMMAND |
|
| 1440 | + ); |
|
| 1441 | + spip_log($commande); |
|
| 1442 | + exec($commande); |
|
| 1443 | + if (!@file_exists($vignette)) { |
|
| 1444 | + spip_log("echec convert sur $vignette"); |
|
| 1445 | + |
|
| 1446 | + return; // echec commande |
|
| 1447 | + } |
|
| 1448 | + } |
|
| 1449 | + |
|
| 1450 | + // php5 imagemagick |
|
| 1451 | + elseif ($process == 'imagick') { |
|
| 1452 | + $vignette = "$destination." . $format_sortie; |
|
| 1453 | + |
|
| 1454 | + if (!class_exists('Imagick')) { |
|
| 1455 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1456 | + |
|
| 1457 | + return; |
|
| 1458 | + } |
|
| 1459 | + $imagick = new Imagick(); |
|
| 1460 | + $imagick->readImage($image); |
|
| 1461 | + $imagick->resizeImage( |
|
| 1462 | + $destWidth, |
|
| 1463 | + $destHeight, |
|
| 1464 | + Imagick::FILTER_LANCZOS, |
|
| 1465 | + 1 |
|
| 1466 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1467 | + $imagick->writeImage($vignette); |
|
| 1468 | + |
|
| 1469 | + if (!@file_exists($vignette)) { |
|
| 1470 | + spip_log("echec imagick sur $vignette"); |
|
| 1471 | + |
|
| 1472 | + return; |
|
| 1473 | + } |
|
| 1474 | + } |
|
| 1475 | + |
|
| 1476 | + // netpbm |
|
| 1477 | + elseif ($process == 'netpbm') { |
|
| 1478 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1479 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1480 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1481 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1482 | + return; |
|
| 1483 | + } |
|
| 1484 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1485 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1486 | + if ($format == 'jpg') { |
|
| 1487 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1488 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1489 | + if (!($s = @filesize($vignette))) { |
|
| 1490 | + spip_unlink($vignette); |
|
| 1491 | + } |
|
| 1492 | + if (!@file_exists($vignette)) { |
|
| 1493 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1494 | + |
|
| 1495 | + return; |
|
| 1496 | + } |
|
| 1497 | + } else { |
|
| 1498 | + if ($format == 'gif') { |
|
| 1499 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1500 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1501 | + if (!($s = @filesize($vignette))) { |
|
| 1502 | + spip_unlink($vignette); |
|
| 1503 | + } |
|
| 1504 | + if (!@file_exists($vignette)) { |
|
| 1505 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1506 | + |
|
| 1507 | + return; |
|
| 1508 | + } |
|
| 1509 | + } else { |
|
| 1510 | + if ($format == 'png') { |
|
| 1511 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1512 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1513 | + if (!($s = @filesize($vignette))) { |
|
| 1514 | + spip_unlink($vignette); |
|
| 1515 | + } |
|
| 1516 | + if (!@file_exists($vignette)) { |
|
| 1517 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1518 | + |
|
| 1519 | + return; |
|
| 1520 | + } |
|
| 1521 | + } |
|
| 1522 | + } |
|
| 1523 | + } |
|
| 1524 | + } |
|
| 1525 | + |
|
| 1526 | + // gd ou gd2 |
|
| 1527 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1528 | + if (!function_exists('gd_info')) { |
|
| 1529 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1530 | + |
|
| 1531 | + return; |
|
| 1532 | + } |
|
| 1533 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1534 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1535 | + |
|
| 1536 | + return; |
|
| 1537 | + } |
|
| 1538 | + $destFormat = $format_sortie; |
|
| 1539 | + if (!$destFormat) { |
|
| 1540 | + spip_log("pas de format pour $image"); |
|
| 1541 | + |
|
| 1542 | + return; |
|
| 1543 | + } |
|
| 1544 | + |
|
| 1545 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1546 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1547 | + return ''; |
|
| 1548 | + } |
|
| 1549 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1550 | + if (!$srcImage) { |
|
| 1551 | + spip_log('echec gd1/gd2'); |
|
| 1552 | + |
|
| 1553 | + return; |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + // Initialisation de l'image destination |
|
| 1557 | + $destImage = null; |
|
| 1558 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1559 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1560 | + } |
|
| 1561 | + if (!$destImage) { |
|
| 1562 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1563 | + } |
|
| 1564 | + |
|
| 1565 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1566 | + $ok = false; |
|
| 1567 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1568 | + if ($format == 'gif') { |
|
| 1569 | + // Si un GIF est transparent, |
|
| 1570 | + // fabriquer un PNG transparent |
|
| 1571 | + $transp = imagecolortransparent($srcImage); |
|
| 1572 | + if ($transp > 0) { |
|
| 1573 | + $destFormat = 'png'; |
|
| 1574 | + } |
|
| 1575 | + } |
|
| 1576 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1577 | + // Conserver la transparence |
|
| 1578 | + if (function_exists('imageAntiAlias')) { |
|
| 1579 | + imageAntiAlias($destImage, true); |
|
| 1580 | + } |
|
| 1581 | + @imagealphablending($destImage, false); |
|
| 1582 | + @imagesavealpha($destImage, true); |
|
| 1583 | + } |
|
| 1584 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1585 | + } |
|
| 1586 | + if (!$ok) { |
|
| 1587 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1588 | + } |
|
| 1589 | + |
|
| 1590 | + // Sauvegarde de l'image destination |
|
| 1591 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1592 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1593 | + _image_gd_output($destImage, $valeurs); |
|
| 1594 | + |
|
| 1595 | + if ($srcImage) { |
|
| 1596 | + ImageDestroy($srcImage); |
|
| 1597 | + } |
|
| 1598 | + ImageDestroy($destImage); |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1602 | + $size = [$destWidth, $destHeight]; |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1606 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1607 | + if ($size[0] < 1) { |
|
| 1608 | + $size[0] = $destWidth; |
|
| 1609 | + } |
|
| 1610 | + if ($size[1] < 1) { |
|
| 1611 | + $size[1] = $destHeight; |
|
| 1612 | + } |
|
| 1613 | + |
|
| 1614 | + $retour['width'] = $largeur = $size[0]; |
|
| 1615 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1616 | + |
|
| 1617 | + $retour['fichier'] = $vignette; |
|
| 1618 | + $retour['format'] = $format; |
|
| 1619 | + $retour['date'] = @filemtime($vignette); |
|
| 1620 | + |
|
| 1621 | + // renvoyer l'image |
|
| 1622 | + return $retour; |
|
| 1623 | 1623 | } |
| 1624 | 1624 | |
| 1625 | 1625 | /** |
@@ -1639,25 +1639,25 @@ discard block |
||
| 1639 | 1639 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1640 | 1640 | **/ |
| 1641 | 1641 | function _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1642 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1643 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1644 | - |
|
| 1645 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1646 | - $destWidth = $srcWidth; |
|
| 1647 | - $destHeight = $srcHeight; |
|
| 1648 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1649 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1650 | - $destHeight = $maxHeight; |
|
| 1651 | - } else { |
|
| 1652 | - $destWidth = $maxWidth; |
|
| 1653 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1654 | - } |
|
| 1655 | - |
|
| 1656 | - return [ |
|
| 1657 | - intval(round($destWidth)), |
|
| 1658 | - intval(round($destHeight)), |
|
| 1659 | - max($ratioWidth, $ratioHeight) |
|
| 1660 | - ]; |
|
| 1642 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1643 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1644 | + |
|
| 1645 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1646 | + $destWidth = $srcWidth; |
|
| 1647 | + $destHeight = $srcHeight; |
|
| 1648 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1649 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1650 | + $destHeight = $maxHeight; |
|
| 1651 | + } else { |
|
| 1652 | + $destWidth = $maxWidth; |
|
| 1653 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1654 | + } |
|
| 1655 | + |
|
| 1656 | + return [ |
|
| 1657 | + intval(round($destWidth)), |
|
| 1658 | + intval(round($destHeight)), |
|
| 1659 | + max($ratioWidth, $ratioHeight) |
|
| 1660 | + ]; |
|
| 1661 | 1661 | } |
| 1662 | 1662 | |
| 1663 | 1663 | /** |
@@ -1677,25 +1677,25 @@ discard block |
||
| 1677 | 1677 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1678 | 1678 | **/ |
| 1679 | 1679 | function ratio_passe_partout($srcWidth, $srcHeight, $maxWidth, $maxHeight) { |
| 1680 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1681 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1682 | - |
|
| 1683 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1684 | - $destWidth = $srcWidth; |
|
| 1685 | - $destHeight = $srcHeight; |
|
| 1686 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1687 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1688 | - $destHeight = $maxHeight; |
|
| 1689 | - } else { |
|
| 1690 | - $destWidth = $maxWidth; |
|
| 1691 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1692 | - } |
|
| 1693 | - |
|
| 1694 | - return [ |
|
| 1695 | - intval(round($destWidth)), |
|
| 1696 | - intval(round($destHeight)), |
|
| 1697 | - min($ratioWidth, $ratioHeight) |
|
| 1698 | - ]; |
|
| 1680 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1681 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1682 | + |
|
| 1683 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1684 | + $destWidth = $srcWidth; |
|
| 1685 | + $destHeight = $srcHeight; |
|
| 1686 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1687 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1688 | + $destHeight = $maxHeight; |
|
| 1689 | + } else { |
|
| 1690 | + $destWidth = $maxWidth; |
|
| 1691 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1692 | + } |
|
| 1693 | + |
|
| 1694 | + return [ |
|
| 1695 | + intval(round($destWidth)), |
|
| 1696 | + intval(round($destHeight)), |
|
| 1697 | + min($ratioWidth, $ratioHeight) |
|
| 1698 | + ]; |
|
| 1699 | 1699 | } |
| 1700 | 1700 | |
| 1701 | 1701 | |
@@ -1708,12 +1708,12 @@ discard block |
||
| 1708 | 1708 | * @return string |
| 1709 | 1709 | */ |
| 1710 | 1710 | function process_image_svg_identite($image) { |
| 1711 | - if ($image['creer']) { |
|
| 1712 | - $source = $image['fichier']; |
|
| 1713 | - _image_gd_output($source, $image); |
|
| 1714 | - } |
|
| 1711 | + if ($image['creer']) { |
|
| 1712 | + $source = $image['fichier']; |
|
| 1713 | + _image_gd_output($source, $image); |
|
| 1714 | + } |
|
| 1715 | 1715 | |
| 1716 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1716 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1717 | 1717 | } |
| 1718 | 1718 | |
| 1719 | 1719 | |
@@ -1746,111 +1746,111 @@ discard block |
||
| 1746 | 1746 | * Code HTML de la balise img produite |
| 1747 | 1747 | **/ |
| 1748 | 1748 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1749 | - $image = false; |
|
| 1750 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1751 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1752 | - } |
|
| 1753 | - # determiner le format de sortie |
|
| 1754 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1755 | - if ($process == 'netpbm') { |
|
| 1756 | - $format_sortie = 'jpg'; |
|
| 1757 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1758 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1759 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1760 | - $gd_formats = formats_image_acceptables(true); |
|
| 1761 | - if ( |
|
| 1762 | - is_array($image) |
|
| 1763 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1764 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1765 | - ) |
|
| 1766 | - ) { |
|
| 1767 | - if ($image['format_source'] == 'jpg') { |
|
| 1768 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1769 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1770 | - { |
|
| 1771 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1772 | - } |
|
| 1773 | - // Choisir le format destination |
|
| 1774 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1775 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1776 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1777 | - # pas *ecrire* |
|
| 1778 | - $format_sortie = ''; |
|
| 1779 | - foreach ($formats_sortie as $fmt) { |
|
| 1780 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1781 | - $format_sortie = $fmt; |
|
| 1782 | - break; |
|
| 1783 | - } |
|
| 1784 | - } |
|
| 1785 | - $image = false; |
|
| 1786 | - } |
|
| 1787 | - } |
|
| 1788 | - |
|
| 1789 | - if (!is_array($image)) { |
|
| 1790 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1791 | - } |
|
| 1792 | - |
|
| 1793 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1794 | - spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1795 | - // on peut resizer en mode html si on dispose des elements |
|
| 1796 | - if ( |
|
| 1797 | - $srcw = extraire_attribut($img, 'width') |
|
| 1798 | - and $srch = extraire_attribut($img, 'height') |
|
| 1799 | - ) { |
|
| 1800 | - list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1801 | - |
|
| 1802 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1803 | - } |
|
| 1804 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1805 | - // sous la forme style='max-width: NNpx;' |
|
| 1806 | - return inserer_attribut( |
|
| 1807 | - $img, |
|
| 1808 | - 'style', |
|
| 1809 | - "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1810 | - ); |
|
| 1811 | - } |
|
| 1812 | - |
|
| 1813 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1814 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1815 | - if ($image['creer']) { |
|
| 1816 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1820 | - } |
|
| 1821 | - |
|
| 1822 | - if ($image['creer'] == false && !$force) { |
|
| 1823 | - return _image_ecrire_tag( |
|
| 1824 | - $image, |
|
| 1825 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1826 | - ); |
|
| 1827 | - } |
|
| 1828 | - |
|
| 1829 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1830 | - $destWidth = $image['largeur_dest']; |
|
| 1831 | - $destHeight = $image['hauteur_dest']; |
|
| 1832 | - $logo = $image['fichier']; |
|
| 1833 | - $date = $image['date_src']; |
|
| 1834 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1835 | - |
|
| 1836 | - if ($preview && $preview['fichier']) { |
|
| 1837 | - $logo = $preview['fichier']; |
|
| 1838 | - $destWidth = $preview['width']; |
|
| 1839 | - $destHeight = $preview['height']; |
|
| 1840 | - $date = $preview['date']; |
|
| 1841 | - } |
|
| 1842 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1843 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1844 | - // quand on fait supprimer/reuploader un logo |
|
| 1845 | - // (pas de filemtime si SAFE MODE) |
|
| 1846 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1847 | - |
|
| 1848 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1849 | - } |
|
| 1850 | - else { |
|
| 1851 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1852 | - return $img; |
|
| 1853 | - } |
|
| 1749 | + $image = false; |
|
| 1750 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1751 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1752 | + } |
|
| 1753 | + # determiner le format de sortie |
|
| 1754 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1755 | + if ($process == 'netpbm') { |
|
| 1756 | + $format_sortie = 'jpg'; |
|
| 1757 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1758 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1759 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1760 | + $gd_formats = formats_image_acceptables(true); |
|
| 1761 | + if ( |
|
| 1762 | + is_array($image) |
|
| 1763 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1764 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1765 | + ) |
|
| 1766 | + ) { |
|
| 1767 | + if ($image['format_source'] == 'jpg') { |
|
| 1768 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1769 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1770 | + { |
|
| 1771 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1772 | + } |
|
| 1773 | + // Choisir le format destination |
|
| 1774 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1775 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1776 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1777 | + # pas *ecrire* |
|
| 1778 | + $format_sortie = ''; |
|
| 1779 | + foreach ($formats_sortie as $fmt) { |
|
| 1780 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1781 | + $format_sortie = $fmt; |
|
| 1782 | + break; |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + $image = false; |
|
| 1786 | + } |
|
| 1787 | + } |
|
| 1788 | + |
|
| 1789 | + if (!is_array($image)) { |
|
| 1790 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1791 | + } |
|
| 1792 | + |
|
| 1793 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1794 | + spip_log("image_reduire_src:pas de version locale de $img"); |
|
| 1795 | + // on peut resizer en mode html si on dispose des elements |
|
| 1796 | + if ( |
|
| 1797 | + $srcw = extraire_attribut($img, 'width') |
|
| 1798 | + and $srch = extraire_attribut($img, 'height') |
|
| 1799 | + ) { |
|
| 1800 | + list($w, $h) = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1801 | + |
|
| 1802 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1803 | + } |
|
| 1804 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1805 | + // sous la forme style='max-width: NNpx;' |
|
| 1806 | + return inserer_attribut( |
|
| 1807 | + $img, |
|
| 1808 | + 'style', |
|
| 1809 | + "max-width: ${taille}px; max-height: ${taille_y}px" |
|
| 1810 | + ); |
|
| 1811 | + } |
|
| 1812 | + |
|
| 1813 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1814 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1815 | + if ($image['creer']) { |
|
| 1816 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1820 | + } |
|
| 1821 | + |
|
| 1822 | + if ($image['creer'] == false && !$force) { |
|
| 1823 | + return _image_ecrire_tag( |
|
| 1824 | + $image, |
|
| 1825 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1826 | + ); |
|
| 1827 | + } |
|
| 1828 | + |
|
| 1829 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1830 | + $destWidth = $image['largeur_dest']; |
|
| 1831 | + $destHeight = $image['hauteur_dest']; |
|
| 1832 | + $logo = $image['fichier']; |
|
| 1833 | + $date = $image['date_src']; |
|
| 1834 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1835 | + |
|
| 1836 | + if ($preview && $preview['fichier']) { |
|
| 1837 | + $logo = $preview['fichier']; |
|
| 1838 | + $destWidth = $preview['width']; |
|
| 1839 | + $destHeight = $preview['height']; |
|
| 1840 | + $date = $preview['date']; |
|
| 1841 | + } |
|
| 1842 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1843 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1844 | + // quand on fait supprimer/reuploader un logo |
|
| 1845 | + // (pas de filemtime si SAFE MODE) |
|
| 1846 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1847 | + |
|
| 1848 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1849 | + } |
|
| 1850 | + else { |
|
| 1851 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1852 | + return $img; |
|
| 1853 | + } |
|
| 1854 | 1854 | } |
| 1855 | 1855 | |
| 1856 | 1856 | /** |
@@ -1865,145 +1865,145 @@ discard block |
||
| 1865 | 1865 | */ |
| 1866 | 1866 | class phpthumb_functions { |
| 1867 | 1867 | |
| 1868 | - /** |
|
| 1869 | - * Retourne la couleur d'un pixel dans une image |
|
| 1870 | - * |
|
| 1871 | - * @param ressource $img |
|
| 1872 | - * @param int $x |
|
| 1873 | - * @param int $y |
|
| 1874 | - * @return array|bool |
|
| 1875 | - */ |
|
| 1876 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1877 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1878 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1879 | - } |
|
| 1880 | - return false; |
|
| 1881 | - } |
|
| 1882 | - |
|
| 1883 | - /** |
|
| 1884 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1885 | - * |
|
| 1886 | - * @param int $number |
|
| 1887 | - * @param int $minbytes |
|
| 1888 | - * @return string |
|
| 1889 | - */ |
|
| 1890 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1891 | - $intstring = ''; |
|
| 1892 | - while ($number > 0) { |
|
| 1893 | - $intstring = $intstring . chr($number & 255); |
|
| 1894 | - $number >>= 8; |
|
| 1895 | - } |
|
| 1896 | - |
|
| 1897 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1898 | - } |
|
| 1899 | - |
|
| 1900 | - /** |
|
| 1901 | - * Transforme une ressource GD en image au format ICO |
|
| 1902 | - * |
|
| 1903 | - * @param array $gd_image_array |
|
| 1904 | - * Tableau de ressources d'images GD |
|
| 1905 | - * @return string |
|
| 1906 | - * Image au format ICO |
|
| 1907 | - */ |
|
| 1908 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1909 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1910 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1911 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1912 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1913 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1914 | - |
|
| 1915 | - $icXOR[$key] = ''; |
|
| 1916 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1917 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1918 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1919 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1920 | - $r = $argb['red']; |
|
| 1921 | - $g = $argb['green']; |
|
| 1922 | - $b = $argb['blue']; |
|
| 1923 | - |
|
| 1924 | - if ($bpp[$key] == 32) { |
|
| 1925 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1926 | - } elseif ($bpp[$key] == 24) { |
|
| 1927 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1928 | - } |
|
| 1929 | - |
|
| 1930 | - if ($a < 128) { |
|
| 1931 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1932 | - } else { |
|
| 1933 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - // mask bits are 32-bit aligned per scanline |
|
| 1937 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1938 | - $icANDmask[$key][$y] .= '0'; |
|
| 1939 | - } |
|
| 1940 | - } |
|
| 1941 | - $icAND[$key] = ''; |
|
| 1942 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1943 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1944 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1945 | - } |
|
| 1946 | - } |
|
| 1947 | - } |
|
| 1948 | - |
|
| 1949 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1950 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1951 | - |
|
| 1952 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1953 | - $BitmapInfoHeader[$key] = ''; |
|
| 1954 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1955 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1956 | - // The biHeight member specifies the combined |
|
| 1957 | - // height of the XOR and AND masks. |
|
| 1958 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1959 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1960 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1961 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1962 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1963 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1964 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1965 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1966 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1967 | - } |
|
| 1968 | - |
|
| 1969 | - |
|
| 1970 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1971 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1972 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1973 | - |
|
| 1974 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1975 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1976 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1977 | - |
|
| 1978 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1979 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1980 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1981 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1982 | - |
|
| 1983 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1984 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1985 | - |
|
| 1986 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1987 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1988 | - $dwBytesInRes, |
|
| 1989 | - 4 |
|
| 1990 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1991 | - |
|
| 1992 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1993 | - $dwImageOffset, |
|
| 1994 | - 4 |
|
| 1995 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1996 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1997 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1998 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1999 | - } |
|
| 2000 | - |
|
| 2001 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 2002 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 2003 | - $icondata .= $icXOR[$key]; |
|
| 2004 | - $icondata .= $icAND[$key]; |
|
| 2005 | - } |
|
| 2006 | - |
|
| 2007 | - return $icondata; |
|
| 2008 | - } |
|
| 1868 | + /** |
|
| 1869 | + * Retourne la couleur d'un pixel dans une image |
|
| 1870 | + * |
|
| 1871 | + * @param ressource $img |
|
| 1872 | + * @param int $x |
|
| 1873 | + * @param int $y |
|
| 1874 | + * @return array|bool |
|
| 1875 | + */ |
|
| 1876 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1877 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1878 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1879 | + } |
|
| 1880 | + return false; |
|
| 1881 | + } |
|
| 1882 | + |
|
| 1883 | + /** |
|
| 1884 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1885 | + * |
|
| 1886 | + * @param int $number |
|
| 1887 | + * @param int $minbytes |
|
| 1888 | + * @return string |
|
| 1889 | + */ |
|
| 1890 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1891 | + $intstring = ''; |
|
| 1892 | + while ($number > 0) { |
|
| 1893 | + $intstring = $intstring . chr($number & 255); |
|
| 1894 | + $number >>= 8; |
|
| 1895 | + } |
|
| 1896 | + |
|
| 1897 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1898 | + } |
|
| 1899 | + |
|
| 1900 | + /** |
|
| 1901 | + * Transforme une ressource GD en image au format ICO |
|
| 1902 | + * |
|
| 1903 | + * @param array $gd_image_array |
|
| 1904 | + * Tableau de ressources d'images GD |
|
| 1905 | + * @return string |
|
| 1906 | + * Image au format ICO |
|
| 1907 | + */ |
|
| 1908 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1909 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1910 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1911 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1912 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1913 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1914 | + |
|
| 1915 | + $icXOR[$key] = ''; |
|
| 1916 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1917 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1918 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1919 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1920 | + $r = $argb['red']; |
|
| 1921 | + $g = $argb['green']; |
|
| 1922 | + $b = $argb['blue']; |
|
| 1923 | + |
|
| 1924 | + if ($bpp[$key] == 32) { |
|
| 1925 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1926 | + } elseif ($bpp[$key] == 24) { |
|
| 1927 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1928 | + } |
|
| 1929 | + |
|
| 1930 | + if ($a < 128) { |
|
| 1931 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1932 | + } else { |
|
| 1933 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + // mask bits are 32-bit aligned per scanline |
|
| 1937 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1938 | + $icANDmask[$key][$y] .= '0'; |
|
| 1939 | + } |
|
| 1940 | + } |
|
| 1941 | + $icAND[$key] = ''; |
|
| 1942 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1943 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1944 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1945 | + } |
|
| 1946 | + } |
|
| 1947 | + } |
|
| 1948 | + |
|
| 1949 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1950 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1951 | + |
|
| 1952 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1953 | + $BitmapInfoHeader[$key] = ''; |
|
| 1954 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1955 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1956 | + // The biHeight member specifies the combined |
|
| 1957 | + // height of the XOR and AND masks. |
|
| 1958 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1959 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1960 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1961 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1962 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1963 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1964 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1965 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1966 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1967 | + } |
|
| 1968 | + |
|
| 1969 | + |
|
| 1970 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1971 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1972 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1973 | + |
|
| 1974 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1975 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1976 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1977 | + |
|
| 1978 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1979 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1980 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1981 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1982 | + |
|
| 1983 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1984 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1985 | + |
|
| 1986 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1987 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1988 | + $dwBytesInRes, |
|
| 1989 | + 4 |
|
| 1990 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1991 | + |
|
| 1992 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1993 | + $dwImageOffset, |
|
| 1994 | + 4 |
|
| 1995 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1996 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1997 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1998 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1999 | + } |
|
| 2000 | + |
|
| 2001 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 2002 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 2003 | + $icondata .= $icXOR[$key]; |
|
| 2004 | + $icondata .= $icAND[$key]; |
|
| 2005 | + } |
|
| 2006 | + |
|
| 2007 | + return $icondata; |
|
| 2008 | + } |
|
| 2009 | 2009 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | $blue = dechex($blue); |
| 44 | 44 | |
| 45 | 45 | if (strlen($red) == 1) { |
| 46 | - $red = '0' . $red; |
|
| 46 | + $red = '0'.$red; |
|
| 47 | 47 | } |
| 48 | 48 | if (strlen($green) == 1) { |
| 49 | - $green = '0' . $green; |
|
| 49 | + $green = '0'.$green; |
|
| 50 | 50 | } |
| 51 | 51 | if (strlen($blue) == 1) { |
| 52 | - $blue = '0' . $blue; |
|
| 52 | + $blue = '0'.$blue; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -124,9 +124,9 @@ discard block |
||
| 124 | 124 | $var_G = ($G / 255); |
| 125 | 125 | $var_B = ($B / 255); |
| 126 | 126 | |
| 127 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 127 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 128 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 129 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 130 | 130 | |
| 131 | 131 | $L = ($var_Max + $var_Min) / 2; |
| 132 | 132 | |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 190 | 190 | // helper |
| 191 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 191 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 192 | 192 | if ($vH < 0) { |
| 193 | 193 | $vH += 1; |
| 194 | 194 | } |
@@ -318,10 +318,10 @@ discard block |
||
| 318 | 318 | } # gerer img src="data:....base64" |
| 319 | 319 | elseif ( |
| 320 | 320 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 321 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 321 | + and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]) |
|
| 322 | 322 | and in_array($extension, _image_extensions_acceptees_en_entree()) |
| 323 | 323 | ) { |
| 324 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 324 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 325 | 325 | if (!file_exists($local)) { |
| 326 | 326 | ecrire_fichier($local, base64_decode($regs[2])); |
| 327 | 327 | } |
@@ -335,7 +335,7 @@ discard block |
||
| 335 | 335 | // les protocoles web prennent au moins 3 lettres |
| 336 | 336 | if (tester_url_absolue($source)) { |
| 337 | 337 | include_spip('inc/distant'); |
| 338 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 338 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 339 | 339 | if (!$fichier) { |
| 340 | 340 | return ''; |
| 341 | 341 | } |
@@ -427,9 +427,9 @@ discard block |
||
| 427 | 427 | // on garde la terminaison initiale car image simplement copiee |
| 428 | 428 | // et on postfixe son nom avec un md5 du path |
| 429 | 429 | $terminaison_dest = $terminaison; |
| 430 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 430 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 431 | 431 | } else { |
| 432 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 432 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 433 | 433 | } |
| 434 | 434 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 435 | 435 | $cache = sous_repertoire($cache, $effet); |
@@ -440,7 +440,7 @@ discard block |
||
| 440 | 440 | $fichier_dest = substr($fichier_dest, 2); |
| 441 | 441 | } |
| 442 | 442 | |
| 443 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 443 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 444 | 444 | |
| 445 | 445 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 446 | 446 | |
@@ -478,15 +478,15 @@ discard block |
||
| 478 | 478 | |
| 479 | 479 | if ($creer) { |
| 480 | 480 | spip_log( |
| 481 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 482 | - 'images' . _LOG_DEBUG |
|
| 481 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 482 | + 'images'._LOG_DEBUG |
|
| 483 | 483 | ); |
| 484 | 484 | } |
| 485 | 485 | |
| 486 | 486 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 487 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 487 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 488 | 488 | $ret['fichier'] = $fichier; |
| 489 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 489 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 490 | 490 | $ret['fichier_dest'] = $fichier_dest; |
| 491 | 491 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 492 | 492 | $ret['format_dest'] = $terminaison_dest; |
@@ -635,7 +635,7 @@ discard block |
||
| 635 | 635 | |
| 636 | 636 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 637 | 637 | if ($_terminaison and $_terminaison !== $terminaison) { |
| 638 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 638 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 639 | 639 | $terminaison = $_terminaison; |
| 640 | 640 | } |
| 641 | 641 | return $terminaison; |
@@ -792,7 +792,7 @@ discard block |
||
| 792 | 792 | if (!function_exists('imagepng')) { |
| 793 | 793 | return false; |
| 794 | 794 | } |
| 795 | - $tmp = $fichier . '.tmp'; |
|
| 795 | + $tmp = $fichier.'.tmp'; |
|
| 796 | 796 | $ret = imagepng($img, $tmp); |
| 797 | 797 | if (file_exists($tmp)) { |
| 798 | 798 | $taille_test = getimagesize($tmp); |
@@ -827,7 +827,7 @@ discard block |
||
| 827 | 827 | if (!function_exists('imagegif')) { |
| 828 | 828 | return false; |
| 829 | 829 | } |
| 830 | - $tmp = $fichier . '.tmp'; |
|
| 830 | + $tmp = $fichier.'.tmp'; |
|
| 831 | 831 | $ret = imagegif($img, $tmp); |
| 832 | 832 | if (file_exists($tmp)) { |
| 833 | 833 | $taille_test = getimagesize($tmp); |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | if (!function_exists('imagejpeg')) { |
| 868 | 868 | return false; |
| 869 | 869 | } |
| 870 | - $tmp = $fichier . '.tmp'; |
|
| 870 | + $tmp = $fichier.'.tmp'; |
|
| 871 | 871 | |
| 872 | 872 | // Enable interlancing |
| 873 | 873 | imageinterlace($img, true); |
@@ -928,7 +928,7 @@ discard block |
||
| 928 | 928 | if (!function_exists('imagewebp')) { |
| 929 | 929 | return false; |
| 930 | 930 | } |
| 931 | - $tmp = $fichier . '.tmp'; |
|
| 931 | + $tmp = $fichier.'.tmp'; |
|
| 932 | 932 | $ret = imagewebp($img, $tmp, $qualite); |
| 933 | 933 | if (file_exists($tmp)) { |
| 934 | 934 | $taille_test = getimagesize($tmp); |
@@ -962,7 +962,7 @@ discard block |
||
| 962 | 962 | */ |
| 963 | 963 | function _image_imagesvg($img, $fichier) { |
| 964 | 964 | |
| 965 | - $tmp = $fichier . '.tmp'; |
|
| 965 | + $tmp = $fichier.'.tmp'; |
|
| 966 | 966 | if (strpos($img, '<') === false) { |
| 967 | 967 | $img = supprimer_timestamp($img); |
| 968 | 968 | if (!file_exists($img)) { |
@@ -1019,13 +1019,13 @@ discard block |
||
| 1019 | 1019 | */ |
| 1020 | 1020 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1021 | 1021 | if (is_null($fonction)) { |
| 1022 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1022 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1023 | 1023 | } |
| 1024 | 1024 | $ret = false; |
| 1025 | 1025 | #un flag pour reperer les images gravees |
| 1026 | 1026 | $lock = |
| 1027 | 1027 | !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
| 1028 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')); |
|
| 1028 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src')); |
|
| 1029 | 1029 | if ( |
| 1030 | 1030 | function_exists($fonction) |
| 1031 | 1031 | && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
@@ -1036,7 +1036,7 @@ discard block |
||
| 1036 | 1036 | // dans tous les cas mettre a jour la taille de l'image finale |
| 1037 | 1037 | list($valeurs['hauteur_dest'], $valeurs['largeur_dest']) = taille_image($valeurs['fichier_dest']); |
| 1038 | 1038 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
| 1039 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1039 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1040 | 1040 | } |
| 1041 | 1041 | } |
| 1042 | 1042 | |
@@ -1249,7 +1249,7 @@ discard block |
||
| 1249 | 1249 | |
| 1250 | 1250 | // attributs deprecies. Transformer en CSS |
| 1251 | 1251 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1252 | - $style = "margin:${espace}px;" . $style; |
|
| 1252 | + $style = "margin:${espace}px;".$style; |
|
| 1253 | 1253 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1254 | 1254 | } |
| 1255 | 1255 | |
@@ -1374,7 +1374,7 @@ discard block |
||
| 1374 | 1374 | $image = $valeurs['fichier']; |
| 1375 | 1375 | $format = $valeurs['format_source']; |
| 1376 | 1376 | $destdir = dirname($valeurs['fichier_dest']); |
| 1377 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1377 | + $destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1378 | 1378 | |
| 1379 | 1379 | $format_sortie = $valeurs['format_dest']; |
| 1380 | 1380 | |
@@ -1406,14 +1406,14 @@ discard block |
||
| 1406 | 1406 | |
| 1407 | 1407 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1408 | 1408 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1409 | - $vignette = $destination . '.' . $format; |
|
| 1409 | + $vignette = $destination.'.'.$format; |
|
| 1410 | 1410 | @copy($image, $vignette); |
| 1411 | 1411 | } |
| 1412 | 1412 | |
| 1413 | 1413 | elseif ($valeurs['format_source'] === 'svg') { |
| 1414 | 1414 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1415 | 1415 | $format_sortie = 'svg'; |
| 1416 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1416 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1417 | 1417 | $valeurs['fichier_dest'] = $vignette; |
| 1418 | 1418 | _image_gd_output($svg, $valeurs); |
| 1419 | 1419 | } |
@@ -1425,9 +1425,9 @@ discard block |
||
| 1425 | 1425 | define('_CONVERT_COMMAND', 'convert'); |
| 1426 | 1426 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 1427 | 1427 | if (!defined('_RESIZE_COMMAND')) { |
| 1428 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1428 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest'); |
|
| 1429 | 1429 | } |
| 1430 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1430 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1431 | 1431 | $commande = str_replace( |
| 1432 | 1432 | ['%x', '%y', '%src', '%dest'], |
| 1433 | 1433 | [ |
@@ -1443,13 +1443,13 @@ discard block |
||
| 1443 | 1443 | if (!@file_exists($vignette)) { |
| 1444 | 1444 | spip_log("echec convert sur $vignette"); |
| 1445 | 1445 | |
| 1446 | - return; // echec commande |
|
| 1446 | + return; // echec commande |
|
| 1447 | 1447 | } |
| 1448 | 1448 | } |
| 1449 | 1449 | |
| 1450 | 1450 | // php5 imagemagick |
| 1451 | 1451 | elseif ($process == 'imagick') { |
| 1452 | - $vignette = "$destination." . $format_sortie; |
|
| 1452 | + $vignette = "$destination.".$format_sortie; |
|
| 1453 | 1453 | |
| 1454 | 1454 | if (!class_exists('Imagick')) { |
| 1455 | 1455 | spip_log('Classe Imagick absente !', _LOG_ERREUR); |
@@ -1463,7 +1463,7 @@ discard block |
||
| 1463 | 1463 | $destHeight, |
| 1464 | 1464 | Imagick::FILTER_LANCZOS, |
| 1465 | 1465 | 1 |
| 1466 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1466 | + ); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1467 | 1467 | $imagick->writeImage($vignette); |
| 1468 | 1468 | |
| 1469 | 1469 | if (!@file_exists($vignette)) { |
@@ -1481,11 +1481,11 @@ discard block |
||
| 1481 | 1481 | if (_PNMSCALE_COMMAND == '') { |
| 1482 | 1482 | return; |
| 1483 | 1483 | } |
| 1484 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1484 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1485 | 1485 | $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
| 1486 | 1486 | if ($format == 'jpg') { |
| 1487 | 1487 | $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
| 1488 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1488 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1489 | 1489 | if (!($s = @filesize($vignette))) { |
| 1490 | 1490 | spip_unlink($vignette); |
| 1491 | 1491 | } |
@@ -1497,7 +1497,7 @@ discard block |
||
| 1497 | 1497 | } else { |
| 1498 | 1498 | if ($format == 'gif') { |
| 1499 | 1499 | $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
| 1500 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1500 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1501 | 1501 | if (!($s = @filesize($vignette))) { |
| 1502 | 1502 | spip_unlink($vignette); |
| 1503 | 1503 | } |
@@ -1509,7 +1509,7 @@ discard block |
||
| 1509 | 1509 | } else { |
| 1510 | 1510 | if ($format == 'png') { |
| 1511 | 1511 | $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
| 1512 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1512 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1513 | 1513 | if (!($s = @filesize($vignette))) { |
| 1514 | 1514 | spip_unlink($vignette); |
| 1515 | 1515 | } |
@@ -1531,7 +1531,7 @@ discard block |
||
| 1531 | 1531 | return; |
| 1532 | 1532 | } |
| 1533 | 1533 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1534 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1534 | + spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels'); |
|
| 1535 | 1535 | |
| 1536 | 1536 | return; |
| 1537 | 1537 | } |
@@ -1843,7 +1843,7 @@ discard block |
||
| 1843 | 1843 | // de l'image, de facon a tromper le cache du navigateur |
| 1844 | 1844 | // quand on fait supprimer/reuploader un logo |
| 1845 | 1845 | // (pas de filemtime si SAFE MODE) |
| 1846 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1846 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1847 | 1847 | |
| 1848 | 1848 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1849 | 1849 | } |
@@ -1890,7 +1890,7 @@ discard block |
||
| 1890 | 1890 | public static function LittleEndian2String($number, $minbytes = 1) { |
| 1891 | 1891 | $intstring = ''; |
| 1892 | 1892 | while ($number > 0) { |
| 1893 | - $intstring = $intstring . chr($number & 255); |
|
| 1893 | + $intstring = $intstring.chr($number & 255); |
|
| 1894 | 1894 | $number >>= 8; |
| 1895 | 1895 | } |
| 1896 | 1896 | |
@@ -1922,9 +1922,9 @@ discard block |
||
| 1922 | 1922 | $b = $argb['blue']; |
| 1923 | 1923 | |
| 1924 | 1924 | if ($bpp[$key] == 32) { |
| 1925 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1925 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1926 | 1926 | } elseif ($bpp[$key] == 24) { |
| 1927 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1927 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1928 | 1928 | } |
| 1929 | 1929 | |
| 1930 | 1930 | if ($a < 128) { |
@@ -1951,48 +1951,48 @@ discard block |
||
| 1951 | 1951 | |
| 1952 | 1952 | // BITMAPINFOHEADER - 40 bytes |
| 1953 | 1953 | $BitmapInfoHeader[$key] = ''; |
| 1954 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1955 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1954 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1955 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1956 | 1956 | // The biHeight member specifies the combined |
| 1957 | 1957 | // height of the XOR and AND masks. |
| 1958 | 1958 | $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
| 1959 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1960 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1961 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1962 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1963 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1964 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1965 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1966 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1959 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1960 | + $BitmapInfoHeader[$key] .= chr($bpp[$key])."\x00"; // wBitCount; |
|
| 1961 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1962 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1963 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1964 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1965 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1966 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1967 | 1967 | } |
| 1968 | 1968 | |
| 1969 | 1969 | |
| 1970 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1971 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1972 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1970 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1971 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1972 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1973 | 1973 | |
| 1974 | 1974 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1975 | 1975 | foreach ($gd_image_array as $key => $gd_image) { |
| 1976 | 1976 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1977 | 1977 | |
| 1978 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1979 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1980 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1981 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1978 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1979 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1980 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1981 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1982 | 1982 | |
| 1983 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1984 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1983 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1984 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1985 | 1985 | |
| 1986 | 1986 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1987 | 1987 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1988 | 1988 | $dwBytesInRes, |
| 1989 | 1989 | 4 |
| 1990 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1990 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1991 | 1991 | |
| 1992 | 1992 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1993 | 1993 | $dwImageOffset, |
| 1994 | 1994 | 4 |
| 1995 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1995 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1996 | 1996 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1997 | 1997 | $dwImageOffset += strlen($icXOR[$key]); |
| 1998 | 1998 | $dwImageOffset += strlen($icAND[$key]); |
@@ -524,8 +524,7 @@ discard block |
||
| 524 | 524 | process_image_svg_identite($ret); |
| 525 | 525 | $ret['creer'] = false; |
| 526 | 526 | } |
| 527 | - } |
|
| 528 | - else { |
|
| 527 | + } else { |
|
| 529 | 528 | if (!function_exists($ret['fonction_imagecreatefrom'])) { |
| 530 | 529 | return false; |
| 531 | 530 | } |
@@ -628,8 +627,7 @@ discard block |
||
| 628 | 627 | |
| 629 | 628 | if (isset($info['mime'])) { |
| 630 | 629 | $mime = $info['mime']; |
| 631 | - } |
|
| 632 | - else { |
|
| 630 | + } else { |
|
| 633 | 631 | $mime = image_type_to_mime_type($info[2]); |
| 634 | 632 | } |
| 635 | 633 | |
@@ -1408,9 +1406,7 @@ discard block |
||
| 1408 | 1406 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1409 | 1407 | $vignette = $destination . '.' . $format; |
| 1410 | 1408 | @copy($image, $vignette); |
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1409 | + } elseif ($valeurs['format_source'] === 'svg') { |
|
| 1414 | 1410 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1415 | 1411 | $format_sortie = 'svg'; |
| 1416 | 1412 | $vignette = $destination . '.' . $format_sortie; |
@@ -1846,8 +1842,7 @@ discard block |
||
| 1846 | 1842 | $date = test_espace_prive() ? ('?' . $date) : ''; |
| 1847 | 1843 | |
| 1848 | 1844 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1849 | - } |
|
| 1850 | - else { |
|
| 1845 | + } else { |
|
| 1851 | 1846 | # BMP, tiff ... les redacteurs osent tout! |
| 1852 | 1847 | return $img; |
| 1853 | 1848 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return string Code HTML |
| 26 | 26 | */ |
| 27 | 27 | function debut_grand_cadre() { |
| 28 | - return "\n<div class = 'table_page'>\n"; |
|
| 28 | + return "\n<div class = 'table_page'>\n"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return string Code HTML |
| 35 | 35 | */ |
| 36 | 36 | function fin_grand_cadre() { |
| 37 | - return "\n</div>"; |
|
| 37 | + return "\n</div>"; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Debut de la colonne de gauche |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string Code HTML |
| 50 | 50 | */ |
| 51 | 51 | function debut_gauche() { |
| 52 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string Code HTML |
| 59 | 59 | */ |
| 60 | 60 | function fin_gauche() { |
| 61 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string Code HTML |
| 68 | 68 | */ |
| 69 | 69 | function creer_colonne_droite() { |
| 70 | - static $deja_colonne_droite; |
|
| 71 | - if ($deja_colonne_droite) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 74 | - $deja_colonne_droite = true; |
|
| 70 | + static $deja_colonne_droite; |
|
| 71 | + if ($deja_colonne_droite) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | + $deja_colonne_droite = true; |
|
| 75 | 75 | |
| 76 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string Code HTML |
| 83 | 83 | */ |
| 84 | 84 | function debut_droite() { |
| 85 | - return liste_objets_bloques(_request('exec')) |
|
| 86 | - . creer_colonne_droite() |
|
| 87 | - . '</div>' |
|
| 88 | - . "\n<div id='contenu'>"; |
|
| 85 | + return liste_objets_bloques(_request('exec')) |
|
| 86 | + . creer_colonne_droite() |
|
| 87 | + . '</div>' |
|
| 88 | + . "\n<div id='contenu'>"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | * Code HTML |
| 108 | 108 | **/ |
| 109 | 109 | function liste_objets_bloques($exec, $contexte = [], $auteur = null) { |
| 110 | - $res = ''; |
|
| 111 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | - include_spip('inc/drapeau_edition'); |
|
| 113 | - if (is_null($auteur)) { |
|
| 114 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | - } |
|
| 116 | - if ( |
|
| 117 | - $en_cours = trouver_objet_exec($exec) |
|
| 118 | - and $en_cours['edition'] |
|
| 119 | - and $type = $en_cours['type'] |
|
| 120 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | - ) { |
|
| 123 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | - signale_edition($id, $auteur, $type); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | - if (count($objets_ouverts)) { |
|
| 130 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $res; |
|
| 110 | + $res = ''; |
|
| 111 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | + include_spip('inc/drapeau_edition'); |
|
| 113 | + if (is_null($auteur)) { |
|
| 114 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | + } |
|
| 116 | + if ( |
|
| 117 | + $en_cours = trouver_objet_exec($exec) |
|
| 118 | + and $en_cours['edition'] |
|
| 119 | + and $type = $en_cours['type'] |
|
| 120 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | + ) { |
|
| 123 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | + signale_edition($id, $auteur, $type); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | + if (count($objets_ouverts)) { |
|
| 130 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $res; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -145,20 +145,20 @@ discard block |
||
| 145 | 145 | * @return string Code HTML |
| 146 | 146 | **/ |
| 147 | 147 | function fin_page() { |
| 148 | - include_spip('inc/pipelines'); |
|
| 149 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | - and ((_request('var_mode') == 'debug') |
|
| 152 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | - and isset($_COOKIE['spip_admin']))); |
|
| 154 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | - . '</div>' |
|
| 157 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | - . ($debug ? erreur_squelette() : '') |
|
| 159 | - . "</body></html>\n"; |
|
| 160 | - |
|
| 161 | - return f_queue($t); |
|
| 148 | + include_spip('inc/pipelines'); |
|
| 149 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | + and ((_request('var_mode') == 'debug') |
|
| 152 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | + and isset($_COOKIE['spip_admin']))); |
|
| 154 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | + . '</div>' |
|
| 157 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | + . ($debug ? erreur_squelette() : '') |
|
| 159 | + . "</body></html>\n"; |
|
| 160 | + |
|
| 161 | + return f_queue($t); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return string Code HTML |
| 174 | 174 | **/ |
| 175 | 175 | function html_tests_js() { |
| 176 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | - define( |
|
| 179 | - '_TESTER_NOSCRIPT', |
|
| 180 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $rejouer = ''; |
|
| 187 | - if (defined('_SESSION_REJOUER')) { |
|
| 188 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 176 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | + define( |
|
| 179 | + '_TESTER_NOSCRIPT', |
|
| 180 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $rejouer = ''; |
|
| 187 | + if (defined('_SESSION_REJOUER')) { |
|
| 188 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -198,25 +198,25 @@ discard block |
||
| 198 | 198 | **/ |
| 199 | 199 | function info_maj_spip() { |
| 200 | 200 | |
| 201 | - $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 202 | - if (!$maj) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 201 | + $maj = isset($GLOBALS['meta']['info_maj_spip']) ? $GLOBALS['meta']['info_maj_spip'] : null; |
|
| 202 | + if (!$maj) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - $maj = explode('|', $maj); |
|
| 207 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 206 | + $maj = explode('|', $maj); |
|
| 207 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - if (!autoriser('webmestre')) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 212 | + if (!autoriser('webmestre')) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - array_shift($maj); |
|
| 217 | - $maj = implode('|', $maj); |
|
| 216 | + array_shift($maj); |
|
| 217 | + $maj = implode('|', $maj); |
|
| 218 | 218 | |
| 219 | - return "$maj<br />"; |
|
| 219 | + return "$maj<br />"; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,47 +227,47 @@ discard block |
||
| 227 | 227 | **/ |
| 228 | 228 | function info_copyright() { |
| 229 | 229 | |
| 230 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | - |
|
| 232 | - // |
|
| 233 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | - // |
|
| 235 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | - if ($vcs['vcs'] === 'GIT') { |
|
| 237 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | - } else { |
|
| 241 | - $url = ''; |
|
| 242 | - } |
|
| 243 | - // affichage "GIT [master: abcdef]" |
|
| 244 | - $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 245 | - if ($url) { |
|
| 246 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | - } |
|
| 248 | - if ($vcs['branch']) { |
|
| 249 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | - } |
|
| 251 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // et la version de l'ecran de securite |
|
| 255 | - $secu = defined('_ECRAN_SECURITE') |
|
| 256 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | - : ''; |
|
| 258 | - |
|
| 259 | - return _T( |
|
| 260 | - 'info_copyright', |
|
| 261 | - [ |
|
| 262 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | - 'lien_gpl' => |
|
| 264 | - "<a href='" . generer_url_ecrire( |
|
| 265 | - 'aide', |
|
| 266 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | - ] |
|
| 269 | - ) |
|
| 270 | - . $secu; |
|
| 230 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | + |
|
| 232 | + // |
|
| 233 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | + // |
|
| 235 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | + if ($vcs['vcs'] === 'GIT') { |
|
| 237 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | + } else { |
|
| 241 | + $url = ''; |
|
| 242 | + } |
|
| 243 | + // affichage "GIT [master: abcdef]" |
|
| 244 | + $commit = isset($vcs['commit_short']) ? $vcs['commit_short'] : $vcs['commit']; |
|
| 245 | + if ($url) { |
|
| 246 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | + } |
|
| 248 | + if ($vcs['branch']) { |
|
| 249 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | + } |
|
| 251 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // et la version de l'ecran de securite |
|
| 255 | + $secu = defined('_ECRAN_SECURITE') |
|
| 256 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | + : ''; |
|
| 258 | + |
|
| 259 | + return _T( |
|
| 260 | + 'info_copyright', |
|
| 261 | + [ |
|
| 262 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | + 'lien_gpl' => |
|
| 264 | + "<a href='" . generer_url_ecrire( |
|
| 265 | + 'aide', |
|
| 266 | + 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | + ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | + ] |
|
| 269 | + ) |
|
| 270 | + . $secu; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | * @return string Code HTML |
| 283 | 283 | **/ |
| 284 | 284 | function formulaire_recherche($page, $complement = '') { |
| 285 | - $recherche = _request('recherche'); |
|
| 286 | - $recherche_aff = entites_html($recherche); |
|
| 287 | - if (!strlen($recherche)) { |
|
| 288 | - $recherche_aff = _T('info_rechercher'); |
|
| 289 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | - } else { |
|
| 291 | - $onfocus = ''; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | - |
|
| 297 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 285 | + $recherche = _request('recherche'); |
|
| 286 | + $recherche_aff = entites_html($recherche); |
|
| 287 | + if (!strlen($recherche)) { |
|
| 288 | + $recherche_aff = _T('info_rechercher'); |
|
| 289 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | + } else { |
|
| 291 | + $onfocus = ''; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | + |
|
| 297 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 298 | 298 | } |
@@ -188,7 +188,7 @@ discard block |
||
| 188 | 188 | $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
| 189 | 189 | } |
| 190 | 190 | |
| 191 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 191 | + return $rejouer.(defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -234,9 +234,9 @@ discard block |
||
| 234 | 234 | // |
| 235 | 235 | if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
| 236 | 236 | if ($vcs['vcs'] === 'GIT') { |
| 237 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 237 | + $url = 'https://git.spip.net/spip/spip/commit/'.$vcs['commit']; |
|
| 238 | 238 | } elseif ($vcs['vcs'] === 'SVN') { |
| 239 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 239 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/'.$vcs['commit']; |
|
| 240 | 240 | } else { |
| 241 | 241 | $url = ''; |
| 242 | 242 | } |
@@ -246,14 +246,14 @@ discard block |
||
| 246 | 246 | $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
| 247 | 247 | } |
| 248 | 248 | if ($vcs['branch']) { |
| 249 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 249 | + $commit = $vcs['branch'].': '.$commit; |
|
| 250 | 250 | } |
| 251 | 251 | $version .= " {$vcs['vcs']} [$commit]"; |
| 252 | 252 | } |
| 253 | 253 | |
| 254 | 254 | // et la version de l'ecran de securite |
| 255 | 255 | $secu = defined('_ECRAN_SECURITE') |
| 256 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 256 | + ? '<br />'._T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | 257 | : ''; |
| 258 | 258 | |
| 259 | 259 | return _T( |
@@ -261,10 +261,10 @@ discard block |
||
| 261 | 261 | [ |
| 262 | 262 | 'spip' => "<b>SPIP $version</b> ", |
| 263 | 263 | 'lien_gpl' => |
| 264 | - "<a href='" . generer_url_ecrire( |
|
| 264 | + "<a href='".generer_url_ecrire( |
|
| 265 | 265 | 'aide', |
| 266 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 266 | + 'aide=licence&var_lang='.$GLOBALS['spip_lang'] |
|
| 267 | + )."' class=\"aide popin\">"._T('info_copyright_gpl').'</a>' |
|
| 268 | 268 | ] |
| 269 | 269 | ) |
| 270 | 270 | . $secu; |
@@ -291,8 +291,8 @@ discard block |
||
| 291 | 291 | $onfocus = ''; |
| 292 | 292 | } |
| 293 | 293 | |
| 294 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 294 | + $form = '<input type="text" size="10" value="'.$recherche_aff.'" name="recherche" class="recherche" accesskey="r"'.$onfocus.' />'; |
|
| 295 | + $form .= "<input type='image' src='".chemin_image('rechercher-20.png')."' name='submit' class='submit' alt='"._T('info_rechercher')."' />"; |
|
| 296 | 296 | |
| 297 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 297 | + return "<div class='spip_recherche'>".generer_form_ecrire($page, $form.$complement, " method='get'").'</div>'; |
|
| 298 | 298 | } |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | lire_fichier($file, $c); |
| 75 | 75 | $css .= $c; |
| 76 | 76 | } |
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 77 | + $css = "<style type='text/css'>".$css.'</style>'; |
|
| 78 | 78 | } else { |
| 79 | 79 | foreach ($files as $name) { |
| 80 | 80 | $file = direction_css(find_in_theme($name)); |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | define('_DOCTYPE_ECRIRE', ''); |
| 88 | 88 | } |
| 89 | 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 . |
|
| 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 | 98 | '</head> |
| 99 | -<body' . $onLoad . " class='minipres'> |
|
| 99 | +<body' . $onLoad." class='minipres'> |
|
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 102 | + $titre. |
|
| 103 | 103 | "</h1> |
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | $titre = ($titre == 'install') |
| 184 | 184 | ? _T('avis_espace_interdit') |
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 185 | + : $titre.' : '._T('info_acces_interdit'); |
|
| 186 | 186 | |
| 187 | 187 | $statut = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : ''; |
| 188 | 188 | $nom = isset($GLOBALS['visiteur_session']['nom']) ? $GLOBALS['visiteur_session']['nom'] : ''; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
| 202 | 202 | } |
| 203 | 203 | $corps = "<div class='boutons'>$corps</div>"; |
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 204 | + spip_log($nom." $titre ".$_SERVER['REQUEST_URI']); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | if (!_AJAX) { |
@@ -219,6 +219,6 @@ discard block |
||
| 219 | 219 | foreach ($_POST as $v => $c) { |
| 220 | 220 | $url = parametre_url($url, $v, $c, '&'); |
| 221 | 221 | } |
| 222 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 222 | + ajax_retour('<div>'.$titre.redirige_formulaire($url).'</div>', false); |
|
| 223 | 223 | } |
| 224 | 224 | } |
@@ -193,11 +193,9 @@ |
||
| 193 | 193 | |
| 194 | 194 | if ($statut and test_espace_prive()) { |
| 195 | 195 | $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 196 | + } elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | 197 | $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
| 199 | - } |
|
| 200 | - else { |
|
| 198 | + } else { |
|
| 201 | 199 | $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
| 202 | 200 | } |
| 203 | 201 | $corps = "<div class='boutons'>$corps</div>"; |
@@ -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('compacte')) { |
|
| 70 | - $file = compacte($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('compacte')) { |
|
| 70 | + $file = compacte($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,77 +148,77 @@ 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 = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : ''; |
|
| 188 | - $nom = isset($GLOBALS['visiteur_session']['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 | - return install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | - . $corps |
|
| 214 | - . install_fin_html(); |
|
| 215 | - } else { |
|
| 216 | - include_spip('inc/headers'); |
|
| 217 | - include_spip('inc/actions'); |
|
| 218 | - $url = self('&', true); |
|
| 219 | - foreach ($_POST as $v => $c) { |
|
| 220 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 221 | - } |
|
| 222 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 223 | - } |
|
| 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 = isset($GLOBALS['visiteur_session']['statut']) ? $GLOBALS['visiteur_session']['statut'] : ''; |
|
| 188 | + $nom = isset($GLOBALS['visiteur_session']['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 | + return install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | + . $corps |
|
| 214 | + . install_fin_html(); |
|
| 215 | + } else { |
|
| 216 | + include_spip('inc/headers'); |
|
| 217 | + include_spip('inc/actions'); |
|
| 218 | + $url = self('&', true); |
|
| 219 | + foreach ($_POST as $v => $c) { |
|
| 220 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 221 | + } |
|
| 222 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 223 | + } |
|
| 224 | 224 | } |
@@ -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 | /** |
@@ -25,51 +25,51 @@ discard block |
||
| 25 | 25 | * privée ou dans un de ses sous menus |
| 26 | 26 | */ |
| 27 | 27 | class Bouton { |
| 28 | - /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | - public $icone; |
|
| 30 | - |
|
| 31 | - /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | - public $libelle; |
|
| 33 | - |
|
| 34 | - /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | - public $url = null; |
|
| 36 | - |
|
| 37 | - /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | - public $urlArg = null; |
|
| 39 | - |
|
| 40 | - /** @var null|string URL du javascript */ |
|
| 41 | - public $url2 = null; |
|
| 42 | - |
|
| 43 | - /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | - public $target = null; |
|
| 45 | - |
|
| 46 | - /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | - public $sousmenu = null; |
|
| 48 | - |
|
| 49 | - /** |
|
| 50 | - * Définit un bouton |
|
| 51 | - * |
|
| 52 | - * @param string $icone |
|
| 53 | - * L'icone à mettre dans le bouton |
|
| 54 | - * @param string $libelle |
|
| 55 | - * Le nom de l'entrée i18n associé |
|
| 56 | - * @param null|string $url |
|
| 57 | - * L'URL de la page |
|
| 58 | - * @param null|string|array $urlArg |
|
| 59 | - * Arguments supplémentaires de l'URL |
|
| 60 | - * @param null|string $url2 |
|
| 61 | - * URL du javascript |
|
| 62 | - * @param null|mixed $target |
|
| 63 | - * Pour ouvrir une fenêtre à part |
|
| 64 | - */ |
|
| 65 | - public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | - $this->icone = $icone; |
|
| 67 | - $this->libelle = $libelle; |
|
| 68 | - $this->url = $url; |
|
| 69 | - $this->urlArg = $urlArg; |
|
| 70 | - $this->url2 = $url2; |
|
| 71 | - $this->target = $target; |
|
| 72 | - } |
|
| 28 | + /** @var string L'icone à mettre dans le bouton */ |
|
| 29 | + public $icone; |
|
| 30 | + |
|
| 31 | + /** @var string Le nom de l'entrée d'i18n associé */ |
|
| 32 | + public $libelle; |
|
| 33 | + |
|
| 34 | + /** @var null|string L'URL de la page (null => ?exec=nom) */ |
|
| 35 | + public $url = null; |
|
| 36 | + |
|
| 37 | + /** @var null|string|array Arguments supplementaires de l'URL */ |
|
| 38 | + public $urlArg = null; |
|
| 39 | + |
|
| 40 | + /** @var null|string URL du javascript */ |
|
| 41 | + public $url2 = null; |
|
| 42 | + |
|
| 43 | + /** @var null|string Pour ouvrir dans une fenetre a part */ |
|
| 44 | + public $target = null; |
|
| 45 | + |
|
| 46 | + /** @var null|mixed Sous-barre de boutons / onglets */ |
|
| 47 | + public $sousmenu = null; |
|
| 48 | + |
|
| 49 | + /** |
|
| 50 | + * Définit un bouton |
|
| 51 | + * |
|
| 52 | + * @param string $icone |
|
| 53 | + * L'icone à mettre dans le bouton |
|
| 54 | + * @param string $libelle |
|
| 55 | + * Le nom de l'entrée i18n associé |
|
| 56 | + * @param null|string $url |
|
| 57 | + * L'URL de la page |
|
| 58 | + * @param null|string|array $urlArg |
|
| 59 | + * Arguments supplémentaires de l'URL |
|
| 60 | + * @param null|string $url2 |
|
| 61 | + * URL du javascript |
|
| 62 | + * @param null|mixed $target |
|
| 63 | + * Pour ouvrir une fenêtre à part |
|
| 64 | + */ |
|
| 65 | + public function __construct($icone, $libelle, $url = null, $urlArg = null, $url2 = null, $target = null) { |
|
| 66 | + $this->icone = $icone; |
|
| 67 | + $this->libelle = $libelle; |
|
| 68 | + $this->url = $url; |
|
| 69 | + $this->urlArg = $urlArg; |
|
| 70 | + $this->url2 = $url2; |
|
| 71 | + $this->target = $target; |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | |
@@ -86,35 +86,35 @@ discard block |
||
| 86 | 86 | */ |
| 87 | 87 | function definir_barre_onglets($script) { |
| 88 | 88 | |
| 89 | - $onglets = []; |
|
| 90 | - $liste_onglets = []; |
|
| 91 | - |
|
| 92 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | - if (function_exists('onglets_plugins')) { |
|
| 94 | - $liste_onglets = onglets_plugins(); |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - |
|
| 98 | - foreach ($liste_onglets as $id => $infos) { |
|
| 99 | - if ( |
|
| 100 | - ($parent = $infos['parent']) |
|
| 101 | - && $parent == $script |
|
| 102 | - && autoriser('onglet', "_$id") |
|
| 103 | - ) { |
|
| 104 | - $onglets[$id] = new Bouton( |
|
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 107 | - (isset($infos['action']) and $infos['action']) |
|
| 108 | - ? generer_url_ecrire( |
|
| 109 | - $infos['action'], |
|
| 110 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | - ) |
|
| 112 | - : null |
|
| 113 | - ); |
|
| 114 | - } |
|
| 115 | - } |
|
| 116 | - |
|
| 117 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 89 | + $onglets = []; |
|
| 90 | + $liste_onglets = []; |
|
| 91 | + |
|
| 92 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 93 | + if (function_exists('onglets_plugins')) { |
|
| 94 | + $liste_onglets = onglets_plugins(); |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + |
|
| 98 | + foreach ($liste_onglets as $id => $infos) { |
|
| 99 | + if ( |
|
| 100 | + ($parent = $infos['parent']) |
|
| 101 | + && $parent == $script |
|
| 102 | + && autoriser('onglet', "_$id") |
|
| 103 | + ) { |
|
| 104 | + $onglets[$id] = new Bouton( |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | + (isset($infos['action']) and $infos['action']) |
|
| 108 | + ? generer_url_ecrire( |
|
| 109 | + $infos['action'], |
|
| 110 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 111 | + ) |
|
| 112 | + : null |
|
| 113 | + ); |
|
| 114 | + } |
|
| 115 | + } |
|
| 116 | + |
|
| 117 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -133,14 +133,14 @@ discard block |
||
| 133 | 133 | * @return string |
| 134 | 134 | */ |
| 135 | 135 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 136 | - include_spip('inc/presentation'); |
|
| 136 | + include_spip('inc/presentation'); |
|
| 137 | 137 | |
| 138 | - $res = ''; |
|
| 138 | + $res = ''; |
|
| 139 | 139 | |
| 140 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | - $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 142 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | - } |
|
| 140 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 141 | + $url = $onglet->url ? $onglet->url : generer_url_ecrire($exec); |
|
| 142 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 143 | + } |
|
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 146 | 146 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | && autoriser('onglet', "_$id") |
| 103 | 103 | ) { |
| 104 | 104 | $onglets[$id] = new Bouton( |
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | 107 | (isset($infos['action']) and $infos['action']) |
| 108 | 108 | ? generer_url_ecrire( |
| 109 | 109 | $infos['action'], |
@@ -142,5 +142,5 @@ discard block |
||
| 142 | 142 | $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class).$res.fin_onglet()); |
|
| 146 | 146 | } |
@@ -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 | /** |
@@ -26,41 +26,41 @@ discard block |
||
| 26 | 26 | * @return string Code HTML du cadre dépliable |
| 27 | 27 | **/ |
| 28 | 28 | function cadre_depliable($icone, $titre, $deplie, $contenu, $ids = '', $style_cadre = 'r') { |
| 29 | - $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | - |
|
| 31 | - return |
|
| 32 | - debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | - . debut_block_depliable($deplie, $ids) |
|
| 34 | - . "<div class='cadre_padding'>\n" |
|
| 35 | - . $contenu |
|
| 36 | - . "</div>\n" |
|
| 37 | - . fin_block() |
|
| 38 | - . fin_cadre(); |
|
| 29 | + $bouton = bouton_block_depliable($titre, $deplie, $ids); |
|
| 30 | + |
|
| 31 | + return |
|
| 32 | + debut_cadre($style_cadre, $icone, '', $bouton, '', '', false) |
|
| 33 | + . debut_block_depliable($deplie, $ids) |
|
| 34 | + . "<div class='cadre_padding'>\n" |
|
| 35 | + . $contenu |
|
| 36 | + . "</div>\n" |
|
| 37 | + . fin_block() |
|
| 38 | + . fin_cadre(); |
|
| 39 | 39 | } |
| 40 | 40 | |
| 41 | 41 | // https://code.spip.net/@block_parfois_visible |
| 42 | 42 | function block_parfois_visible($nom, $invite, $masque, $style = '', $visible = false) { |
| 43 | - return "\n" |
|
| 44 | - . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | - . debut_block_depliable($visible, $nom) |
|
| 46 | - . $masque |
|
| 47 | - . fin_block(); |
|
| 43 | + return "\n" |
|
| 44 | + . bouton_block_depliable($invite, $visible, $nom) |
|
| 45 | + . debut_block_depliable($visible, $nom) |
|
| 46 | + . $masque |
|
| 47 | + . fin_block(); |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | 50 | // https://code.spip.net/@debut_block_depliable |
| 51 | 51 | function debut_block_depliable($deplie, $id = '') { |
| 52 | - $class = ' blocdeplie'; |
|
| 53 | - // si on n'accepte pas js, ne pas fermer |
|
| 54 | - if (!$deplie) { |
|
| 55 | - $class = ' blocreplie'; |
|
| 56 | - } |
|
| 52 | + $class = ' blocdeplie'; |
|
| 53 | + // si on n'accepte pas js, ne pas fermer |
|
| 54 | + if (!$deplie) { |
|
| 55 | + $class = ' blocreplie'; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 58 | + return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@fin_block |
| 62 | 62 | function fin_block() { |
| 63 | - return "<div class='nettoyeur'></div>\n</div>"; |
|
| 63 | + return "<div class='nettoyeur'></div>\n</div>"; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | // $texte : texte du bouton |
@@ -68,32 +68,32 @@ discard block |
||
| 68 | 68 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 69 | 69 | // https://code.spip.net/@bouton_block_depliable |
| 70 | 70 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 71 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | - |
|
| 73 | - $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 74 | - if (strlen($ids)) { |
|
| 75 | - $cible = explode(',', $ids); |
|
| 76 | - $cible = '#' . implode(',#', $cible); |
|
| 77 | - } else { |
|
| 78 | - $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 82 | - |
|
| 83 | - return "<$b " |
|
| 84 | - . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 85 | - . "class='titrem$class'" |
|
| 86 | - . (($deplie === -1) |
|
| 87 | - ? '' |
|
| 88 | - : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | - ) |
|
| 90 | - . '>' |
|
| 91 | - // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | - . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | - . "$texte</$b>" |
|
| 94 | - . http_script(($deplie === 'incertain') |
|
| 95 | - ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | - : ''); |
|
| 71 | + $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 72 | + |
|
| 73 | + $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
|
| 74 | + if (strlen($ids)) { |
|
| 75 | + $cible = explode(',', $ids); |
|
| 76 | + $cible = '#' . implode(',#', $cible); |
|
| 77 | + } else { |
|
| 78 | + $cible = "#$bouton_id + div.bloc_depliable"; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + $b = (strpos($texte, '<h') === false ? 'h3' : 'div'); |
|
| 82 | + |
|
| 83 | + return "<$b " |
|
| 84 | + . ($bouton_id ? "id='$bouton_id' " : '') |
|
| 85 | + . "class='titrem$class'" |
|
| 86 | + . (($deplie === -1) |
|
| 87 | + ? '' |
|
| 88 | + : " onmouseover=\"jQuery(this).depliant('$cible');\"" |
|
| 89 | + ) |
|
| 90 | + . '>' |
|
| 91 | + // une ancre pour rendre accessible au clavier le depliage du sous bloc |
|
| 92 | + . "<a href='#' onclick=\"return jQuery(this).depliant_clicancre('$cible');\" class='titremancre'></a>" |
|
| 93 | + . "$texte</$b>" |
|
| 94 | + . http_script(($deplie === 'incertain') |
|
| 95 | + ? "jQuery(function($){if ($('$cible').is(':visible')) { $('#$bouton_id').addClass('deplie').removeClass('replie'); }});" |
|
| 96 | + : ''); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | // |
@@ -102,66 +102,66 @@ discard block |
||
| 102 | 102 | // https://code.spip.net/@verif_butineur |
| 103 | 103 | function verif_butineur() { |
| 104 | 104 | |
| 105 | - preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | - $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | - $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | - $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | - $GLOBALS['browser_barre'] = ''; |
|
| 111 | - |
|
| 112 | - if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 113 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | - $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | - } else { |
|
| 117 | - if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 118 | - preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 119 | - $GLOBALS['browser_name'] = 'Opera'; |
|
| 120 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | - } else { |
|
| 123 | - if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 124 | - preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 125 | - $GLOBALS['browser_name'] = 'MSIE'; |
|
| 126 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | - } else { |
|
| 129 | - if ( |
|
| 130 | - preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 131 | - preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 132 | - ) { |
|
| 133 | - $GLOBALS['browser_name'] = 'Safari'; |
|
| 134 | - $GLOBALS['browser_version'] = $match[1]; |
|
| 135 | - $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 136 | - } else { |
|
| 137 | - if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 138 | - // Numero de version pour Mozilla "authentique" |
|
| 139 | - if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 140 | - $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 141 | - } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 142 | - else { |
|
| 143 | - if ( |
|
| 144 | - strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 145 | - $GLOBALS['browser_description'], |
|
| 146 | - 'KHTML' |
|
| 147 | - ) |
|
| 148 | - ) { |
|
| 149 | - $GLOBALS['browser_rev'] = 1.4; |
|
| 150 | - } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 151 | - else { |
|
| 152 | - $GLOBALS['browser_rev'] = 1.0; |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 156 | - } |
|
| 157 | - } |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if (!$GLOBALS['browser_name']) { |
|
| 163 | - $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 164 | - } |
|
| 105 | + preg_match(',^([A-Za-z]+)/([0-9]+\.[0-9]+) (.*)$,', $_SERVER['HTTP_USER_AGENT'], $match); |
|
| 106 | + $GLOBALS['browser_name'] = $match[1]; |
|
| 107 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 108 | + $GLOBALS['browser_description'] = $match[3]; |
|
| 109 | + $GLOBALS['browser_layer'] = ' '; // compat avec vieux scripts qui testent la valeur |
|
| 110 | + $GLOBALS['browser_barre'] = ''; |
|
| 111 | + |
|
| 112 | + if (!preg_match(',opera,i', $GLOBALS['browser_description']) && preg_match(',opera,i', $GLOBALS['browser_name'])) { |
|
| 113 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 114 | + $GLOBALS['browser_version'] = $match[2]; |
|
| 115 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 116 | + } else { |
|
| 117 | + if (preg_match(',opera,i', $GLOBALS['browser_description'])) { |
|
| 118 | + preg_match(',Opera ([^\ ]*),i', $GLOBALS['browser_description'], $match); |
|
| 119 | + $GLOBALS['browser_name'] = 'Opera'; |
|
| 120 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 121 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 8.5); |
|
| 122 | + } else { |
|
| 123 | + if (preg_match(',msie,i', $GLOBALS['browser_description'])) { |
|
| 124 | + preg_match(',MSIE ([^;]*),i', $GLOBALS['browser_description'], $match); |
|
| 125 | + $GLOBALS['browser_name'] = 'MSIE'; |
|
| 126 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 127 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.5); |
|
| 128 | + } else { |
|
| 129 | + if ( |
|
| 130 | + preg_match(',KHTML,i', $GLOBALS['browser_description']) && |
|
| 131 | + preg_match(',Safari/([^;]*),', $GLOBALS['browser_description'], $match) |
|
| 132 | + ) { |
|
| 133 | + $GLOBALS['browser_name'] = 'Safari'; |
|
| 134 | + $GLOBALS['browser_version'] = $match[1]; |
|
| 135 | + $GLOBALS['browser_barre'] = ($GLOBALS['browser_version'] >= 5.0); |
|
| 136 | + } else { |
|
| 137 | + if (preg_match(',mozilla,i', $GLOBALS['browser_name']) and $GLOBALS['browser_version'] >= 5) { |
|
| 138 | + // Numero de version pour Mozilla "authentique" |
|
| 139 | + if (preg_match(',rv:([0-9]+\.[0-9]+),', $GLOBALS['browser_description'], $match)) { |
|
| 140 | + $GLOBALS['browser_rev'] = doubleval($match[1]); |
|
| 141 | + } // Autres Gecko => equivalents 1.4 par defaut (Galeon, etc.) |
|
| 142 | + else { |
|
| 143 | + if ( |
|
| 144 | + strpos($GLOBALS['browser_description'], 'Gecko') and !strpos( |
|
| 145 | + $GLOBALS['browser_description'], |
|
| 146 | + 'KHTML' |
|
| 147 | + ) |
|
| 148 | + ) { |
|
| 149 | + $GLOBALS['browser_rev'] = 1.4; |
|
| 150 | + } // Machins quelconques => equivalents 1.0 par defaut (Konqueror, etc.) |
|
| 151 | + else { |
|
| 152 | + $GLOBALS['browser_rev'] = 1.0; |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + $GLOBALS['browser_barre'] = $GLOBALS['browser_rev'] >= 1.3; |
|
| 156 | + } |
|
| 157 | + } |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if (!$GLOBALS['browser_name']) { |
|
| 163 | + $GLOBALS['browser_name'] = 'Mozilla'; |
|
| 164 | + } |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | verif_butineur(); |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | $class = ' blocreplie'; |
| 56 | 56 | } |
| 57 | 57 | |
| 58 | - return '<div ' . ($id ? "id='$id' " : '') . "class='bloc_depliable$class'>"; |
|
| 58 | + return '<div '.($id ? "id='$id' " : '')."class='bloc_depliable$class'>"; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | // https://code.spip.net/@fin_block |
@@ -68,12 +68,12 @@ discard block |
||
| 68 | 68 | // $ids : id des div lies au bouton (facultatif, par defaut c'est le div.bloc_depliable qui suit) |
| 69 | 69 | // https://code.spip.net/@bouton_block_depliable |
| 70 | 70 | function bouton_block_depliable($texte, $deplie, $ids = '') { |
| 71 | - $bouton_id = 'b' . substr(md5($texte . microtime()), 0, 8); |
|
| 71 | + $bouton_id = 'b'.substr(md5($texte.microtime()), 0, 8); |
|
| 72 | 72 | |
| 73 | 73 | $class = ($deplie === true) ? ' deplie' : (($deplie == -1) ? ' impliable' : ' replie'); |
| 74 | 74 | if (strlen($ids)) { |
| 75 | 75 | $cible = explode(',', $ids); |
| 76 | - $cible = '#' . implode(',#', $cible); |
|
| 76 | + $cible = '#'.implode(',#', $cible); |
|
| 77 | 77 | } else { |
| 78 | 78 | $cible = "#$bouton_id + div.bloc_depliable"; |
| 79 | 79 | } |