@@ -18,11 +18,11 @@ 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('_DATA_SOURCE_MAX_SIZE')) { |
| 25 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | |
@@ -43,17 +43,17 @@ discard block |
||
| 43 | 43 | * Description de la boucle complétée des champs |
| 44 | 44 | */ |
| 45 | 45 | function iterateur_DATA_dist($b) { |
| 46 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | - $b->show = [ |
|
| 48 | - 'field' => [ |
|
| 49 | - 'cle' => 'STRING', |
|
| 50 | - 'valeur' => 'STRING', |
|
| 51 | - '*' => 'ALL' // Champ joker * |
|
| 52 | - ] |
|
| 53 | - ]; |
|
| 54 | - $b->select[] = '.valeur'; |
|
| 55 | - |
|
| 56 | - return $b; |
|
| 46 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 47 | + $b->show = [ |
|
| 48 | + 'field' => [ |
|
| 49 | + 'cle' => 'STRING', |
|
| 50 | + 'valeur' => 'STRING', |
|
| 51 | + '*' => 'ALL' // Champ joker * |
|
| 52 | + ] |
|
| 53 | + ]; |
|
| 54 | + $b->select[] = '.valeur'; |
|
| 55 | + |
|
| 56 | + return $b; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | |
@@ -68,7 +68,7 @@ discard block |
||
| 68 | 68 | * @return array |
| 69 | 69 | */ |
| 70 | 70 | function inc_file_to_array_dist($data) { |
| 71 | - return preg_split('/\r?\n/', $data); |
|
| 71 | + return preg_split('/\r?\n/', $data); |
|
| 72 | 72 | } |
| 73 | 73 | |
| 74 | 74 | /** |
@@ -77,9 +77,9 @@ discard block |
||
| 77 | 77 | * @return array |
| 78 | 78 | */ |
| 79 | 79 | function inc_plugins_to_array_dist() { |
| 80 | - include_spip('inc/plugin'); |
|
| 80 | + include_spip('inc/plugin'); |
|
| 81 | 81 | |
| 82 | - return liste_chemin_plugin_actifs(); |
|
| 82 | + return liste_chemin_plugin_actifs(); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | /** |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | * @return array |
| 90 | 90 | */ |
| 91 | 91 | function inc_xml_to_array_dist($data) { |
| 92 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 92 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 93 | 93 | } |
| 94 | 94 | |
| 95 | 95 | /** |
@@ -101,14 +101,14 @@ discard block |
||
| 101 | 101 | * |
| 102 | 102 | */ |
| 103 | 103 | function inc_object_to_array($object) { |
| 104 | - if (!is_object($object) && !is_array($object)) { |
|
| 105 | - return $object; |
|
| 106 | - } |
|
| 107 | - if (is_object($object)) { |
|
| 108 | - $object = get_object_vars($object); |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return array_map('inc_object_to_array', $object); |
|
| 104 | + if (!is_object($object) && !is_array($object)) { |
|
| 105 | + return $object; |
|
| 106 | + } |
|
| 107 | + if (is_object($object)) { |
|
| 108 | + $object = get_object_vars($object); |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return array_map('inc_object_to_array', $object); |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -118,20 +118,20 @@ discard block |
||
| 118 | 118 | * @return array|bool |
| 119 | 119 | */ |
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | - # sortir le connecteur de $data |
|
| 122 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | - $serveur = (string)$v[1]; |
|
| 124 | - $req = trim($v[2]); |
|
| 125 | - if ($s = sql_query($req, $serveur)) { |
|
| 126 | - $r = []; |
|
| 127 | - while ($t = sql_fetch($s)) { |
|
| 128 | - $r[] = $t; |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return $r; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return false; |
|
| 121 | + # sortir le connecteur de $data |
|
| 122 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 123 | + $serveur = (string)$v[1]; |
|
| 124 | + $req = trim($v[2]); |
|
| 125 | + if ($s = sql_query($req, $serveur)) { |
|
| 126 | + $r = []; |
|
| 127 | + while ($t = sql_fetch($s)) { |
|
| 128 | + $r[] = $t; |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return $r; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return false; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -141,13 +141,13 @@ discard block |
||
| 141 | 141 | * @return array|bool |
| 142 | 142 | */ |
| 143 | 143 | function inc_json_to_array_dist($data) { |
| 144 | - try { |
|
| 145 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | - } catch (JsonException $e) { |
|
| 147 | - $json = null; |
|
| 148 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | - } |
|
| 150 | - return is_array($json) ? (array) $json : []; |
|
| 144 | + try { |
|
| 145 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 146 | + } catch (JsonException $e) { |
|
| 147 | + $json = null; |
|
| 148 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 149 | + } |
|
| 150 | + return is_array($json) ? (array) $json : []; |
|
| 151 | 151 | } |
| 152 | 152 | |
| 153 | 153 | /** |
@@ -157,30 +157,30 @@ discard block |
||
| 157 | 157 | * @return array|bool |
| 158 | 158 | */ |
| 159 | 159 | function inc_csv_to_array_dist($data) { |
| 160 | - include_spip('inc/csv'); |
|
| 161 | - [$entete, $csv] = analyse_csv($data); |
|
| 162 | - array_unshift($csv, $entete); |
|
| 163 | - |
|
| 164 | - include_spip('inc/charsets'); |
|
| 165 | - $i = 1; |
|
| 166 | - foreach ($entete as $k => $v) { |
|
| 167 | - if (trim((string) $v) == '') { |
|
| 168 | - $v = 'col' . $i; |
|
| 169 | - } // reperer des eventuelles cases vides |
|
| 170 | - if (is_numeric($v) && $v < 0) { |
|
| 171 | - $v = '__' . $v; |
|
| 172 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | - if (is_numeric($v)) { |
|
| 174 | - $v = '_' . $v; |
|
| 175 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | - $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | - foreach ($csv as &$item) { |
|
| 178 | - $item[$v] = &$item[$k]; |
|
| 179 | - } |
|
| 180 | - $i++; |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - return $csv; |
|
| 160 | + include_spip('inc/csv'); |
|
| 161 | + [$entete, $csv] = analyse_csv($data); |
|
| 162 | + array_unshift($csv, $entete); |
|
| 163 | + |
|
| 164 | + include_spip('inc/charsets'); |
|
| 165 | + $i = 1; |
|
| 166 | + foreach ($entete as $k => $v) { |
|
| 167 | + if (trim((string) $v) == '') { |
|
| 168 | + $v = 'col' . $i; |
|
| 169 | + } // reperer des eventuelles cases vides |
|
| 170 | + if (is_numeric($v) && $v < 0) { |
|
| 171 | + $v = '__' . $v; |
|
| 172 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 173 | + if (is_numeric($v)) { |
|
| 174 | + $v = '_' . $v; |
|
| 175 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 176 | + $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
|
| 177 | + foreach ($csv as &$item) { |
|
| 178 | + $item[$v] = &$item[$k]; |
|
| 179 | + } |
|
| 180 | + $i++; |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + return $csv; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -190,13 +190,13 @@ discard block |
||
| 190 | 190 | * @return array|bool |
| 191 | 191 | */ |
| 192 | 192 | function inc_rss_to_array_dist($data) { |
| 193 | - $tableau = null; |
|
| 194 | - include_spip('inc/syndic'); |
|
| 195 | - if (is_array($rss = analyser_backend($data))) { |
|
| 196 | - $tableau = $rss; |
|
| 197 | - } |
|
| 193 | + $tableau = null; |
|
| 194 | + include_spip('inc/syndic'); |
|
| 195 | + if (is_array($rss = analyser_backend($data))) { |
|
| 196 | + $tableau = $rss; |
|
| 197 | + } |
|
| 198 | 198 | |
| 199 | - return $tableau; |
|
| 199 | + return $tableau; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -206,9 +206,9 @@ discard block |
||
| 206 | 206 | * @return array|bool |
| 207 | 207 | */ |
| 208 | 208 | function inc_atom_to_array_dist($data) { |
| 209 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 209 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 210 | 210 | |
| 211 | - return $rss_to_array($data); |
|
| 211 | + return $rss_to_array($data); |
|
| 212 | 212 | } |
| 213 | 213 | |
| 214 | 214 | /** |
@@ -219,12 +219,12 @@ discard block |
||
| 219 | 219 | * @return array|bool |
| 220 | 220 | */ |
| 221 | 221 | function inc_glob_to_array_dist($data) { |
| 222 | - $a = glob( |
|
| 223 | - $data, |
|
| 224 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | - ); |
|
| 222 | + $a = glob( |
|
| 223 | + $data, |
|
| 224 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 225 | + ); |
|
| 226 | 226 | |
| 227 | - return $a ?: []; |
|
| 227 | + return $a ?: []; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -235,14 +235,14 @@ discard block |
||
| 235 | 235 | * @throws Exception |
| 236 | 236 | */ |
| 237 | 237 | function inc_yaml_to_array_dist($data) { |
| 238 | - include_spip('inc/yaml-mini'); |
|
| 239 | - if (!function_exists('yaml_decode')) { |
|
| 240 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 238 | + include_spip('inc/yaml-mini'); |
|
| 239 | + if (!function_exists('yaml_decode')) { |
|
| 240 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 241 | 241 | |
| 242 | - return false; |
|
| 243 | - } |
|
| 242 | + return false; |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - return yaml_decode($data); |
|
| 245 | + return yaml_decode($data); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -269,23 +269,23 @@ discard block |
||
| 269 | 269 | * @return array|bool |
| 270 | 270 | */ |
| 271 | 271 | function inc_ls_to_array_dist($data) { |
| 272 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | - $a = $glob_to_array($data); |
|
| 274 | - foreach ($a as &$v) { |
|
| 275 | - $b = (array)@stat($v); |
|
| 276 | - foreach (array_keys($b) as $k) { |
|
| 277 | - if (is_numeric($k)) { |
|
| 278 | - unset($b[$k]); |
|
| 279 | - } |
|
| 280 | - } |
|
| 281 | - $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | - $v = array_merge( |
|
| 283 | - pathinfo((string) $v), |
|
| 284 | - $b |
|
| 285 | - ); |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - return $a; |
|
| 272 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 273 | + $a = $glob_to_array($data); |
|
| 274 | + foreach ($a as &$v) { |
|
| 275 | + $b = (array)@stat($v); |
|
| 276 | + foreach (array_keys($b) as $k) { |
|
| 277 | + if (is_numeric($k)) { |
|
| 278 | + unset($b[$k]); |
|
| 279 | + } |
|
| 280 | + } |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 282 | + $v = array_merge( |
|
| 283 | + pathinfo((string) $v), |
|
| 284 | + $b |
|
| 285 | + ); |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + return $a; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | /** |
@@ -295,21 +295,21 @@ discard block |
||
| 295 | 295 | * @return array|bool |
| 296 | 296 | */ |
| 297 | 297 | function XMLObjectToArray($object) { |
| 298 | - $xml_array = []; |
|
| 299 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | - $key .= '-' . uniqid(); |
|
| 302 | - } |
|
| 303 | - $vars = get_object_vars($object->current()); |
|
| 304 | - if (isset($vars['@attributes'])) { |
|
| 305 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | - $xml_array[$key][$k] = $v; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - $xml_array[$key][] = $object->hasChildren() |
|
| 310 | - ? XMLObjectToArray($object->current()) |
|
| 311 | - : (string) $object->current(); |
|
| 312 | - } |
|
| 313 | - |
|
| 314 | - return $xml_array; |
|
| 298 | + $xml_array = []; |
|
| 299 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 300 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 301 | + $key .= '-' . uniqid(); |
|
| 302 | + } |
|
| 303 | + $vars = get_object_vars($object->current()); |
|
| 304 | + if (isset($vars['@attributes'])) { |
|
| 305 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 306 | + $xml_array[$key][$k] = $v; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + $xml_array[$key][] = $object->hasChildren() |
|
| 310 | + ? XMLObjectToArray($object->current()) |
|
| 311 | + : (string) $object->current(); |
|
| 312 | + } |
|
| 313 | + |
|
| 314 | + return $xml_array; |
|
| 315 | 315 | } |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | function inc_sql_to_array_dist($data) { |
| 121 | 121 | # sortir le connecteur de $data |
| 122 | 122 | preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
| 123 | - $serveur = (string)$v[1]; |
|
| 123 | + $serveur = (string) $v[1]; |
|
| 124 | 124 | $req = trim($v[2]); |
| 125 | 125 | if ($s = sql_query($req, $serveur)) { |
| 126 | 126 | $r = []; |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
| 146 | 146 | } catch (JsonException $e) { |
| 147 | 147 | $json = null; |
| 148 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 148 | + spip_log('Failed to parse Json data : '.$e->getMessage(), _LOG_INFO); |
|
| 149 | 149 | } |
| 150 | 150 | return is_array($json) ? (array) $json : []; |
| 151 | 151 | } |
@@ -165,13 +165,13 @@ discard block |
||
| 165 | 165 | $i = 1; |
| 166 | 166 | foreach ($entete as $k => $v) { |
| 167 | 167 | if (trim((string) $v) == '') { |
| 168 | - $v = 'col' . $i; |
|
| 168 | + $v = 'col'.$i; |
|
| 169 | 169 | } // reperer des eventuelles cases vides |
| 170 | 170 | if (is_numeric($v) && $v < 0) { |
| 171 | - $v = '__' . $v; |
|
| 171 | + $v = '__'.$v; |
|
| 172 | 172 | } // ne pas risquer d'ecraser une cle numerique |
| 173 | 173 | if (is_numeric($v)) { |
| 174 | - $v = '_' . $v; |
|
| 174 | + $v = '_'.$v; |
|
| 175 | 175 | } // ne pas risquer d'ecraser une cle numerique |
| 176 | 176 | $v = strtolower(preg_replace(',\W+,', '_', (string) translitteration($v))); |
| 177 | 177 | foreach ($csv as &$item) { |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | * @return array|bool |
| 258 | 258 | */ |
| 259 | 259 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 260 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 260 | + return (array) preg_files($dir, $regexp, $limit); |
|
| 261 | 261 | } |
| 262 | 262 | |
| 263 | 263 | /** |
@@ -272,13 +272,13 @@ discard block |
||
| 272 | 272 | $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
| 273 | 273 | $a = $glob_to_array($data); |
| 274 | 274 | foreach ($a as &$v) { |
| 275 | - $b = (array)@stat($v); |
|
| 275 | + $b = (array) @stat($v); |
|
| 276 | 276 | foreach (array_keys($b) as $k) { |
| 277 | 277 | if (is_numeric($k)) { |
| 278 | 278 | unset($b[$k]); |
| 279 | 279 | } |
| 280 | 280 | } |
| 281 | - $b['file'] = preg_replace('`/$`', '', (string) $v) ; |
|
| 281 | + $b['file'] = preg_replace('`/$`', '', (string) $v); |
|
| 282 | 282 | $v = array_merge( |
| 283 | 283 | pathinfo((string) $v), |
| 284 | 284 | $b |
@@ -298,7 +298,7 @@ discard block |
||
| 298 | 298 | $xml_array = []; |
| 299 | 299 | for ($object->rewind(); $object->valid(); $object->next()) { |
| 300 | 300 | if (array_key_exists($key = $object->key(), $xml_array)) { |
| 301 | - $key .= '-' . uniqid(); |
|
| 301 | + $key .= '-'.uniqid(); |
|
| 302 | 302 | } |
| 303 | 303 | $vars = get_object_vars($object->current()); |
| 304 | 304 | if (isset($vars['@attributes'])) { |
@@ -15,10 +15,10 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Pipelines |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | if (test_espace_prive()) { |
| 21 | - include_spip('inc/pipelines_ecrire'); |
|
| 21 | + include_spip('inc/pipelines_ecrire'); |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,26 +44,26 @@ discard block |
||
| 44 | 44 | * @return string Contenu qui sera inséré dans le head HTML |
| 45 | 45 | **/ |
| 46 | 46 | function f_jQuery($texte) { |
| 47 | - $x = ''; |
|
| 48 | - $jquery_plugins = pipeline( |
|
| 49 | - 'jquery_plugins', |
|
| 50 | - [ |
|
| 51 | - 'javascript/jquery.js', |
|
| 52 | - 'javascript/jquery.form.js', |
|
| 53 | - 'javascript/jquery.autosave.js', |
|
| 54 | - 'javascript/jquery.placeholder-label.js', |
|
| 55 | - 'javascript/ajaxCallback.js', |
|
| 56 | - 'javascript/js.cookie.js', |
|
| 57 | - ] |
|
| 58 | - ); |
|
| 59 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | - $script = timestamp($script); |
|
| 62 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | - } |
|
| 64 | - } |
|
| 47 | + $x = ''; |
|
| 48 | + $jquery_plugins = pipeline( |
|
| 49 | + 'jquery_plugins', |
|
| 50 | + [ |
|
| 51 | + 'javascript/jquery.js', |
|
| 52 | + 'javascript/jquery.form.js', |
|
| 53 | + 'javascript/jquery.autosave.js', |
|
| 54 | + 'javascript/jquery.placeholder-label.js', |
|
| 55 | + 'javascript/ajaxCallback.js', |
|
| 56 | + 'javascript/js.cookie.js', |
|
| 57 | + ] |
|
| 58 | + ); |
|
| 59 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 60 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 61 | + $script = timestamp($script); |
|
| 62 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x . $texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -82,26 +82,26 @@ discard block |
||
| 82 | 82 | * @return string Contenu de la page envoyée au navigateur |
| 83 | 83 | **/ |
| 84 | 84 | function f_surligne($texte) { |
| 85 | - if (!$GLOBALS['html']) { |
|
| 86 | - return $texte; |
|
| 87 | - } |
|
| 88 | - $rech = _request('var_recherche'); |
|
| 89 | - if ( |
|
| 90 | - !$rech |
|
| 91 | - && (!defined('_SURLIGNE_RECHERCHE_REFERERS') || !_SURLIGNE_RECHERCHE_REFERERS || !isset($_SERVER['HTTP_REFERER'])) |
|
| 92 | - ) { |
|
| 93 | - return $texte; |
|
| 94 | - } |
|
| 95 | - include_spip('inc/surligne'); |
|
| 85 | + if (!$GLOBALS['html']) { |
|
| 86 | + return $texte; |
|
| 87 | + } |
|
| 88 | + $rech = _request('var_recherche'); |
|
| 89 | + if ( |
|
| 90 | + !$rech |
|
| 91 | + && (!defined('_SURLIGNE_RECHERCHE_REFERERS') || !_SURLIGNE_RECHERCHE_REFERERS || !isset($_SERVER['HTTP_REFERER'])) |
|
| 92 | + ) { |
|
| 93 | + return $texte; |
|
| 94 | + } |
|
| 95 | + include_spip('inc/surligne'); |
|
| 96 | 96 | |
| 97 | - if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 98 | - $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $_SERVER['HTTP_REFERER']); |
|
| 99 | - } |
|
| 100 | - if ($rech) { |
|
| 101 | - $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $rech); |
|
| 102 | - } |
|
| 97 | + if (isset($_SERVER['HTTP_REFERER'])) { |
|
| 98 | + $_SERVER['HTTP_REFERER'] = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $_SERVER['HTTP_REFERER']); |
|
| 99 | + } |
|
| 100 | + if ($rech) { |
|
| 101 | + $rech = preg_replace(',[^\w\,/#&;:-]+,', ' ', (string) $rech); |
|
| 102 | + } |
|
| 103 | 103 | |
| 104 | - return surligner_mots($texte, $rech); |
|
| 104 | + return surligner_mots($texte, $rech); |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -118,33 +118,33 @@ discard block |
||
| 118 | 118 | * @return string Contenu de la page envoyée au navigateur |
| 119 | 119 | **/ |
| 120 | 120 | function f_tidy($texte) { |
| 121 | - /** |
|
| 122 | - * Indentation à faire ? |
|
| 123 | - * |
|
| 124 | - * - true : actif. |
|
| 125 | - * - false par défaut. |
|
| 126 | - */ |
|
| 121 | + /** |
|
| 122 | + * Indentation à faire ? |
|
| 123 | + * |
|
| 124 | + * - true : actif. |
|
| 125 | + * - false par défaut. |
|
| 126 | + */ |
|
| 127 | 127 | |
| 128 | - if ( |
|
| 129 | - $GLOBALS['xhtml'] |
|
| 130 | - && $GLOBALS['html'] |
|
| 131 | - && strlen($texte) |
|
| 132 | - && !headers_sent() |
|
| 133 | - ) { |
|
| 134 | - # Compatibilite ascendante |
|
| 135 | - if (!is_string($GLOBALS['xhtml'])) { |
|
| 136 | - $GLOBALS['xhtml'] = 'tidy'; |
|
| 137 | - } |
|
| 128 | + if ( |
|
| 129 | + $GLOBALS['xhtml'] |
|
| 130 | + && $GLOBALS['html'] |
|
| 131 | + && strlen($texte) |
|
| 132 | + && !headers_sent() |
|
| 133 | + ) { |
|
| 134 | + # Compatibilite ascendante |
|
| 135 | + if (!is_string($GLOBALS['xhtml'])) { |
|
| 136 | + $GLOBALS['xhtml'] = 'tidy'; |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 140 | - spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 141 | - $f = charger_fonction('sax', 'xml'); |
|
| 142 | - } |
|
| 139 | + if (!$f = charger_fonction($GLOBALS['xhtml'], 'inc', true)) { |
|
| 140 | + spip_log("tidy absent, l'indenteur SPIP le remplace"); |
|
| 141 | + $f = charger_fonction('sax', 'xml'); |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | - return $f($texte); |
|
| 145 | - } |
|
| 144 | + return $f($texte); |
|
| 145 | + } |
|
| 146 | 146 | |
| 147 | - return $texte; |
|
| 147 | + return $texte; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | |
@@ -163,24 +163,24 @@ discard block |
||
| 163 | 163 | * @return string Contenu de la page envoyée au navigateur |
| 164 | 164 | **/ |
| 165 | 165 | function f_insert_head($texte) { |
| 166 | - if (!$GLOBALS['html']) { |
|
| 167 | - return $texte; |
|
| 168 | - } |
|
| 169 | - include_spip('public/admin'); // pour strripos |
|
| 166 | + if (!$GLOBALS['html']) { |
|
| 167 | + return $texte; |
|
| 168 | + } |
|
| 169 | + include_spip('public/admin'); // pour strripos |
|
| 170 | 170 | |
| 171 | - if ( |
|
| 172 | - !($pos = stripos($texte, '</head>')) |
|
| 173 | - && !($pos = stripos($texte, '<body>')) |
|
| 174 | - ) { |
|
| 175 | - $pos = 0; |
|
| 176 | - } |
|
| 171 | + if ( |
|
| 172 | + !($pos = stripos($texte, '</head>')) |
|
| 173 | + && !($pos = stripos($texte, '<body>')) |
|
| 174 | + ) { |
|
| 175 | + $pos = 0; |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 179 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 180 | - $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 181 | - } |
|
| 178 | + if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
|
| 179 | + $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 180 | + $texte = substr_replace($texte, $insert, $pos, 0); |
|
| 181 | + } |
|
| 182 | 182 | |
| 183 | - return $texte; |
|
| 183 | + return $texte; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | |
@@ -196,34 +196,34 @@ discard block |
||
| 196 | 196 | * @return string Contenu de la page envoyée au navigateur |
| 197 | 197 | **/ |
| 198 | 198 | function f_admin($texte) { |
| 199 | - if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 200 | - include_spip('inc/filtres'); // pour http_img_pack |
|
| 201 | - $x = "<div class='spip-previsu' " |
|
| 202 | - . http_style_background('preview-32.png', '', 32) |
|
| 203 | - . '>' |
|
| 204 | - . _T('previsualisation') |
|
| 205 | - . '</div>'; |
|
| 206 | - if (!$pos = stripos($texte, '</body>')) { |
|
| 207 | - $pos = strlen($texte); |
|
| 208 | - } |
|
| 209 | - $texte = substr_replace($texte, $x, $pos, 0); |
|
| 210 | - // pas de preview en fenetre enfant |
|
| 211 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 212 | - if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
|
| 213 | - $pos = -1; |
|
| 214 | - } |
|
| 215 | - $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 216 | - } |
|
| 199 | + if (defined('_VAR_PREVIEW') && _VAR_PREVIEW && $GLOBALS['html']) { |
|
| 200 | + include_spip('inc/filtres'); // pour http_img_pack |
|
| 201 | + $x = "<div class='spip-previsu' " |
|
| 202 | + . http_style_background('preview-32.png', '', 32) |
|
| 203 | + . '>' |
|
| 204 | + . _T('previsualisation') |
|
| 205 | + . '</div>'; |
|
| 206 | + if (!$pos = stripos($texte, '</body>')) { |
|
| 207 | + $pos = strlen($texte); |
|
| 208 | + } |
|
| 209 | + $texte = substr_replace($texte, $x, $pos, 0); |
|
| 210 | + // pas de preview en fenetre enfant |
|
| 211 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 212 | + if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
|
| 213 | + $pos = -1; |
|
| 214 | + } |
|
| 215 | + $texte = substr_replace($texte, $x, $pos + 1, 0); |
|
| 216 | + } |
|
| 217 | 217 | |
| 218 | - if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 219 | - include_spip('public/admin'); |
|
| 220 | - $texte = affiche_boutons_admin($texte); |
|
| 221 | - } |
|
| 222 | - if (_request('var_mode') == 'noajax') { |
|
| 223 | - $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 224 | - } |
|
| 218 | + if (isset($GLOBALS['affiche_boutons_admin']) && $GLOBALS['affiche_boutons_admin']) { |
|
| 219 | + include_spip('public/admin'); |
|
| 220 | + $texte = affiche_boutons_admin($texte); |
|
| 221 | + } |
|
| 222 | + if (_request('var_mode') == 'noajax') { |
|
| 223 | + $texte = preg_replace(',(class=[\'"][^\'"]*)ajax([^\'"]*[\'"]),Uims', "\\1\\2", $texte); |
|
| 224 | + } |
|
| 225 | 225 | |
| 226 | - return $texte; |
|
| 226 | + return $texte; |
|
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | /** |
@@ -241,11 +241,11 @@ discard block |
||
| 241 | 241 | * @return array $flux Description et contenu de l'inclusion |
| 242 | 242 | **/ |
| 243 | 243 | function f_recuperer_fond($flux) { |
| 244 | - if (!test_espace_prive()) { |
|
| 245 | - return $flux; |
|
| 246 | - } |
|
| 244 | + if (!test_espace_prive()) { |
|
| 245 | + return $flux; |
|
| 246 | + } |
|
| 247 | 247 | |
| 248 | - return f_afficher_blocs_ecrire($flux); |
|
| 248 | + return f_afficher_blocs_ecrire($flux); |
|
| 249 | 249 | } |
| 250 | 250 | |
| 251 | 251 | /** |
@@ -259,30 +259,30 @@ discard block |
||
| 259 | 259 | * @return string Contenu de la page envoyée au navigateur |
| 260 | 260 | */ |
| 261 | 261 | function f_queue($texte) { |
| 262 | - // eviter une inclusion si rien a faire |
|
| 263 | - if ( |
|
| 264 | - _request('action') == 'cron' |
|
| 265 | - || queue_sleep_time_to_next_job() > 0 |
|
| 266 | - || defined('_DEBUG_BLOCK_QUEUE') |
|
| 267 | - ) { |
|
| 268 | - return $texte; |
|
| 269 | - } |
|
| 262 | + // eviter une inclusion si rien a faire |
|
| 263 | + if ( |
|
| 264 | + _request('action') == 'cron' |
|
| 265 | + || queue_sleep_time_to_next_job() > 0 |
|
| 266 | + || defined('_DEBUG_BLOCK_QUEUE') |
|
| 267 | + ) { |
|
| 268 | + return $texte; |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - include_spip('inc/queue'); |
|
| 272 | - $code = queue_affichage_cron(); |
|
| 271 | + include_spip('inc/queue'); |
|
| 272 | + $code = queue_affichage_cron(); |
|
| 273 | 273 | |
| 274 | - // si rien a afficher |
|
| 275 | - // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 276 | - if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 277 | - return $texte; |
|
| 278 | - } |
|
| 274 | + // si rien a afficher |
|
| 275 | + // ou si on est pas dans une page html, on ne sait rien faire de mieux |
|
| 276 | + if (!$code || !isset($GLOBALS['html']) || !$GLOBALS['html']) { |
|
| 277 | + return $texte; |
|
| 278 | + } |
|
| 279 | 279 | |
| 280 | - // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 281 | - if (($p = strpos($texte, '</body>')) !== false) { |
|
| 282 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 283 | - } else { |
|
| 284 | - $texte .= $code; |
|
| 285 | - } |
|
| 280 | + // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
|
| 281 | + if (($p = strpos($texte, '</body>')) !== false) { |
|
| 282 | + $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 283 | + } else { |
|
| 284 | + $texte .= $code; |
|
| 285 | + } |
|
| 286 | 286 | |
| 287 | - return $texte; |
|
| 287 | + return $texte; |
|
| 288 | 288 | } |
@@ -63,7 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | } |
| 65 | 65 | |
| 66 | - return $x . $texte; |
|
| 66 | + return $x.$texte; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | if (!str_contains(substr($texte, 0, $pos), '<!-- insert_head -->')) { |
| 179 | - $insert = "\n" . pipeline('insert_head', '<!-- f_insert_head -->') . "\n"; |
|
| 179 | + $insert = "\n".pipeline('insert_head', '<!-- f_insert_head -->')."\n"; |
|
| 180 | 180 | $texte = substr_replace($texte, $insert, $pos, 0); |
| 181 | 181 | } |
| 182 | 182 | |
@@ -208,7 +208,7 @@ discard block |
||
| 208 | 208 | } |
| 209 | 209 | $texte = substr_replace($texte, $x, $pos, 0); |
| 210 | 210 | // pas de preview en fenetre enfant |
| 211 | - $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='" . addslashes((string) $GLOBALS['meta']['adresse_site']) . "';}</script>"; |
|
| 211 | + $x = "<script type='text/javascript'>const frameEl = window.frameElement;if (frameEl) {frameEl.sandbox='sandbox';window.location.href='".addslashes((string) $GLOBALS['meta']['adresse_site'])."';}</script>"; |
|
| 212 | 212 | if (!$pos = stripos($texte, '<head') || !$pos = strpos($texte, '>', $pos)) { |
| 213 | 213 | $pos = -1; |
| 214 | 214 | } |
@@ -279,7 +279,7 @@ discard block |
||
| 279 | 279 | |
| 280 | 280 | // inserer avant le </body> fermant si on peut, a la fin de la page sinon |
| 281 | 281 | if (($p = strpos($texte, '</body>')) !== false) { |
| 282 | - $texte = substr($texte, 0, $p) . $code . substr($texte, $p); |
|
| 282 | + $texte = substr($texte, 0, $p).$code.substr($texte, $p); |
|
| 283 | 283 | } else { |
| 284 | 284 | $texte .= $code; |
| 285 | 285 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -31,13 +31,13 @@ discard block |
||
| 31 | 31 | * @return string |
| 32 | 32 | */ |
| 33 | 33 | function exporter_csv_champ($champ) { |
| 34 | - #$champ = str_replace("\r", "\n", $champ); |
|
| 35 | - #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 36 | - #$champ = str_replace("\n", ", ", $champ); |
|
| 37 | - $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 38 | - $champ = str_replace('"', '""', $champ); |
|
| 34 | + #$champ = str_replace("\r", "\n", $champ); |
|
| 35 | + #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 36 | + #$champ = str_replace("\n", ", ", $champ); |
|
| 37 | + $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 38 | + $champ = str_replace('"', '""', $champ); |
|
| 39 | 39 | |
| 40 | - return '"' . $champ . '"'; |
|
| 40 | + return '"' . $champ . '"'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -54,15 +54,15 @@ discard block |
||
| 54 | 54 | * @return string |
| 55 | 55 | */ |
| 56 | 56 | function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) { |
| 57 | - if ($callback) { |
|
| 58 | - $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 59 | - } |
|
| 60 | - $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | - if ($importer_charset) { |
|
| 62 | - $output = str_replace('’', '\'', $output); |
|
| 63 | - $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 64 | - } |
|
| 65 | - return $output; |
|
| 57 | + if ($callback) { |
|
| 58 | + $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 59 | + } |
|
| 60 | + $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | + if ($importer_charset) { |
|
| 62 | + $output = str_replace('’', '\'', $output); |
|
| 63 | + $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 64 | + } |
|
| 65 | + return $output; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | * @return string |
| 75 | 75 | */ |
| 76 | 76 | function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) { |
| 77 | - return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 77 | + return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | /** |
@@ -104,107 +104,107 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | function inc_exporter_csv_dist($titre, $resource, $options = []) { |
| 106 | 106 | |
| 107 | - // support ancienne syntaxe |
|
| 108 | - // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 109 | - if (is_string($options)) { |
|
| 110 | - $args = func_get_args(); |
|
| 111 | - $options = []; |
|
| 112 | - foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 113 | - if (!empty($args[$k])) { |
|
| 114 | - $options[$option] = $args[$k]; |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - $default_options = [ |
|
| 120 | - 'fichier' => null, // par défaut = $titre |
|
| 121 | - 'extension' => null, // par défaut = choix auto |
|
| 122 | - 'delim' => ',', |
|
| 123 | - 'entetes' => null, |
|
| 124 | - 'envoyer' => true, |
|
| 125 | - 'charset' => null, |
|
| 126 | - 'callback' => null, |
|
| 127 | - ]; |
|
| 128 | - $options = array_merge($default_options, $options); |
|
| 129 | - |
|
| 130 | - // Délimiteur |
|
| 131 | - if ($options['delim'] == 'TAB') { |
|
| 132 | - $options['delim'] = "\t"; |
|
| 133 | - } |
|
| 134 | - if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 135 | - $options['delim'] = ','; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - // Nom du fichier : celui indiqué dans les options, sinon le titre |
|
| 139 | - // Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores |
|
| 140 | - $filename = $options['fichier'] ?? translitteration(textebrut(typo($titre))); |
|
| 141 | - $filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename)); |
|
| 142 | - $filename = rtrim($filename, '.'); |
|
| 143 | - |
|
| 144 | - // Extension : celle indiquée en option, sinon choisie selon le délimiteur |
|
| 145 | - // Normalisation : uniquement les charactères non spéciaux |
|
| 146 | - if (!empty($options['extension'])) { |
|
| 147 | - $options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension'])); |
|
| 148 | - } |
|
| 149 | - $extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls'); |
|
| 150 | - |
|
| 151 | - // Fichier |
|
| 152 | - $basename = "$filename.$extension"; |
|
| 153 | - |
|
| 154 | - // Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site |
|
| 155 | - // Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 156 | - $charset_site = $GLOBALS['meta']['charset']; |
|
| 157 | - $charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null); |
|
| 158 | - $charset = $options['charset'] ?? $charset_excel ?? $charset_site; |
|
| 159 | - $importer_charset = (($charset === $charset_site) ? null : $charset); |
|
| 160 | - |
|
| 161 | - $output = ''; |
|
| 162 | - $nb = 0; |
|
| 163 | - if (!empty($options['entetes']) && is_array($options['entetes'])) { |
|
| 164 | - $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 165 | - } |
|
| 166 | - // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 167 | - $nb++; |
|
| 168 | - |
|
| 169 | - if ($options['envoyer']) { |
|
| 170 | - $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 171 | - header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 172 | - header("Content-Disposition: $disposition; filename=$basename"); |
|
| 173 | - |
|
| 174 | - // Vider tous les tampons |
|
| 175 | - $level = @ob_get_level(); |
|
| 176 | - while ($level--) { |
|
| 177 | - @ob_end_flush(); |
|
| 178 | - } |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 182 | - // sinon on ecrit directement sur stdout |
|
| 183 | - if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
|
| 184 | - $fichier = 'php://output'; |
|
| 185 | - } |
|
| 186 | - else { |
|
| 187 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $fp = fopen($fichier, 'w'); |
|
| 191 | - $length = fwrite($fp, $output); |
|
| 192 | - |
|
| 193 | - while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 194 | - $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 195 | - $length += fwrite($fp, $output); |
|
| 196 | - $nb++; |
|
| 197 | - } |
|
| 198 | - fclose($fp); |
|
| 199 | - |
|
| 200 | - if ($options['envoyer']) { |
|
| 201 | - if ($options['envoyer'] === 'attachment') { |
|
| 202 | - header("Content-Length: $length"); |
|
| 203 | - readfile($fichier); |
|
| 204 | - } |
|
| 205 | - // si on a envoye inline, c'est deja tout bon |
|
| 206 | - exit; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return $fichier; |
|
| 107 | + // support ancienne syntaxe |
|
| 108 | + // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 109 | + if (is_string($options)) { |
|
| 110 | + $args = func_get_args(); |
|
| 111 | + $options = []; |
|
| 112 | + foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 113 | + if (!empty($args[$k])) { |
|
| 114 | + $options[$option] = $args[$k]; |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + $default_options = [ |
|
| 120 | + 'fichier' => null, // par défaut = $titre |
|
| 121 | + 'extension' => null, // par défaut = choix auto |
|
| 122 | + 'delim' => ',', |
|
| 123 | + 'entetes' => null, |
|
| 124 | + 'envoyer' => true, |
|
| 125 | + 'charset' => null, |
|
| 126 | + 'callback' => null, |
|
| 127 | + ]; |
|
| 128 | + $options = array_merge($default_options, $options); |
|
| 129 | + |
|
| 130 | + // Délimiteur |
|
| 131 | + if ($options['delim'] == 'TAB') { |
|
| 132 | + $options['delim'] = "\t"; |
|
| 133 | + } |
|
| 134 | + if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 135 | + $options['delim'] = ','; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + // Nom du fichier : celui indiqué dans les options, sinon le titre |
|
| 139 | + // Normalisation : uniquement les caractères non spéciaux, tirets, underscore et point + remplacer espaces par underscores |
|
| 140 | + $filename = $options['fichier'] ?? translitteration(textebrut(typo($titre))); |
|
| 141 | + $filename = preg_replace([',[^\w\-_\.\s]+,', ',\s+,'], ['', '_'], trim((string) $filename)); |
|
| 142 | + $filename = rtrim($filename, '.'); |
|
| 143 | + |
|
| 144 | + // Extension : celle indiquée en option, sinon choisie selon le délimiteur |
|
| 145 | + // Normalisation : uniquement les charactères non spéciaux |
|
| 146 | + if (!empty($options['extension'])) { |
|
| 147 | + $options['extension'] = preg_replace(',[^\w]+,', '', trim((string) $options['extension'])); |
|
| 148 | + } |
|
| 149 | + $extension = $options['extension'] ?? ($options['delim'] === ',' ? 'csv' : 'xls'); |
|
| 150 | + |
|
| 151 | + // Fichier |
|
| 152 | + $basename = "$filename.$extension"; |
|
| 153 | + |
|
| 154 | + // Charset : celui indiqué en option, sinon celui compatible excel si nécessaire, sinon celui du site |
|
| 155 | + // Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 156 | + $charset_site = $GLOBALS['meta']['charset']; |
|
| 157 | + $charset_excel = ($extension === 'xls' ? 'iso-8859-1' : null); |
|
| 158 | + $charset = $options['charset'] ?? $charset_excel ?? $charset_site; |
|
| 159 | + $importer_charset = (($charset === $charset_site) ? null : $charset); |
|
| 160 | + |
|
| 161 | + $output = ''; |
|
| 162 | + $nb = 0; |
|
| 163 | + if (!empty($options['entetes']) && is_array($options['entetes'])) { |
|
| 164 | + $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 165 | + } |
|
| 166 | + // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 167 | + $nb++; |
|
| 168 | + |
|
| 169 | + if ($options['envoyer']) { |
|
| 170 | + $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 171 | + header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 172 | + header("Content-Disposition: $disposition; filename=$basename"); |
|
| 173 | + |
|
| 174 | + // Vider tous les tampons |
|
| 175 | + $level = @ob_get_level(); |
|
| 176 | + while ($level--) { |
|
| 177 | + @ob_end_flush(); |
|
| 178 | + } |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 182 | + // sinon on ecrit directement sur stdout |
|
| 183 | + if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
|
| 184 | + $fichier = 'php://output'; |
|
| 185 | + } |
|
| 186 | + else { |
|
| 187 | + $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $fp = fopen($fichier, 'w'); |
|
| 191 | + $length = fwrite($fp, $output); |
|
| 192 | + |
|
| 193 | + while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 194 | + $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 195 | + $length += fwrite($fp, $output); |
|
| 196 | + $nb++; |
|
| 197 | + } |
|
| 198 | + fclose($fp); |
|
| 199 | + |
|
| 200 | + if ($options['envoyer']) { |
|
| 201 | + if ($options['envoyer'] === 'attachment') { |
|
| 202 | + header("Content-Length: $length"); |
|
| 203 | + readfile($fichier); |
|
| 204 | + } |
|
| 205 | + // si on a envoye inline, c'est deja tout bon |
|
| 206 | + exit; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return $fichier; |
|
| 210 | 210 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
| 38 | 38 | $champ = str_replace('"', '""', $champ); |
| 39 | 39 | |
| 40 | - return '"' . $champ . '"'; |
|
| 40 | + return '"'.$champ.'"'; |
|
| 41 | 41 | } |
| 42 | 42 | |
| 43 | 43 | /** |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | if ($callback) { |
| 58 | 58 | $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
| 59 | 59 | } |
| 60 | - $output = implode($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 60 | + $output = implode($delim, array_map('exporter_csv_champ', $ligne))."\r\n"; |
|
| 61 | 61 | if ($importer_charset) { |
| 62 | 62 | $output = str_replace('’', '\'', $output); |
| 63 | 63 | $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $fichier = 'php://output'; |
| 185 | 185 | } |
| 186 | 186 | else { |
| 187 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
|
| 187 | + $fichier = sous_repertoire(_DIR_CACHE, 'export').$basename; |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | $fp = fopen($fichier, 'w'); |
@@ -182,8 +182,7 @@ |
||
| 182 | 182 | // sinon on ecrit directement sur stdout |
| 183 | 183 | if ($options['envoyer'] && $options['envoyer'] !== 'attachment') { |
| 184 | 184 | $fichier = 'php://output'; |
| 185 | - } |
|
| 186 | - else { |
|
| 185 | + } else { |
|
| 187 | 186 | $fichier = sous_repertoire(_DIR_CACHE, 'export') . $basename; |
| 188 | 187 | } |
| 189 | 188 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -37,133 +37,133 @@ discard block |
||
| 37 | 37 | * @param int $status Code de redirection (301 ou 302) |
| 38 | 38 | **/ |
| 39 | 39 | function redirige_par_entete($url, $equiv = '', $status = 302) { |
| 40 | - if (!in_array($status, [301, 302])) { |
|
| 41 | - $status = 302; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $url = trim(strtr($url, "\n\r", ' ')); |
|
| 45 | - # si l'url de redirection est relative, on la passe en absolue |
|
| 46 | - if (!preg_match(',^(\w+:)?//,', $url)) { |
|
| 47 | - include_spip('inc/filtres_mini'); |
|
| 48 | - $url = url_absolue($url); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - if (defined('_AJAX') && _AJAX) { |
|
| 52 | - $url = parametre_url($url, 'var_ajax_redir', 1, '&'); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - // ne pas laisser passer n'importe quoi dans l'url |
|
| 56 | - $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 57 | - $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url); |
|
| 58 | - while (str_contains($url, '%0A')) { |
|
| 59 | - $url = str_replace('%0A', '', $url); |
|
| 60 | - } |
|
| 61 | - // interdire les url inline avec des pseudo-protocoles : |
|
| 62 | - if ( |
|
| 63 | - preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url) |
|
| 64 | - ) { |
|
| 65 | - $url = './'; |
|
| 66 | - } |
|
| 67 | - |
|
| 68 | - // Il n'y a que sous Apache que setcookie puis redirection fonctionne |
|
| 69 | - include_spip('inc/cookie'); |
|
| 70 | - if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 71 | - define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)'); |
|
| 72 | - } |
|
| 73 | - if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 74 | - define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx'); |
|
| 75 | - } |
|
| 76 | - if ( |
|
| 77 | - !$equiv && !spip_cookie_envoye() |
|
| 78 | - || ( |
|
| 79 | - !empty($_SERVER['SERVER_SOFTWARE']) |
|
| 80 | - && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 81 | - && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | - || !empty($_SERVER['SERVER_SIGNATURE']) |
|
| 83 | - && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 84 | - && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | - || function_exists('apache_getenv') |
|
| 86 | - || defined('_SERVER_APACHE') |
|
| 87 | - ) |
|
| 88 | - ) { |
|
| 89 | - @header('Location: ' . $url); |
|
| 90 | - $equiv = ''; |
|
| 91 | - } else { |
|
| 92 | - @header('Refresh: 0; url=' . $url); |
|
| 93 | - if (isset($GLOBALS['meta']['charset'])) { |
|
| 94 | - @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 95 | - } |
|
| 96 | - $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
|
| 97 | - } |
|
| 98 | - include_spip('inc/lang'); |
|
| 99 | - if ($status != 302) { |
|
| 100 | - http_response_code($status); |
|
| 101 | - } |
|
| 102 | - echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n", |
|
| 103 | - html_lang_attributes(), ' |
|
| 40 | + if (!in_array($status, [301, 302])) { |
|
| 41 | + $status = 302; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $url = trim(strtr($url, "\n\r", ' ')); |
|
| 45 | + # si l'url de redirection est relative, on la passe en absolue |
|
| 46 | + if (!preg_match(',^(\w+:)?//,', $url)) { |
|
| 47 | + include_spip('inc/filtres_mini'); |
|
| 48 | + $url = url_absolue($url); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + if (defined('_AJAX') && _AJAX) { |
|
| 52 | + $url = parametre_url($url, 'var_ajax_redir', 1, '&'); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + // ne pas laisser passer n'importe quoi dans l'url |
|
| 56 | + $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 57 | + $url = str_replace(["\r", "\n", ' '], ['%0D', '%0A', '%20'], $url); |
|
| 58 | + while (str_contains($url, '%0A')) { |
|
| 59 | + $url = str_replace('%0A', '', $url); |
|
| 60 | + } |
|
| 61 | + // interdire les url inline avec des pseudo-protocoles : |
|
| 62 | + if ( |
|
| 63 | + preg_match(',data:,i', $url) && preg_match('/base64\s*,/i', $url) || preg_match(',(javascript|mailto):,i', $url) |
|
| 64 | + ) { |
|
| 65 | + $url = './'; |
|
| 66 | + } |
|
| 67 | + |
|
| 68 | + // Il n'y a que sous Apache que setcookie puis redirection fonctionne |
|
| 69 | + include_spip('inc/cookie'); |
|
| 70 | + if (!defined('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 71 | + define('_SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE', '^(Apache|Cherokee|nginx)'); |
|
| 72 | + } |
|
| 73 | + if (!defined('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE')) { |
|
| 74 | + define('_SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE', 'Apache|Cherokee|nginx'); |
|
| 75 | + } |
|
| 76 | + if ( |
|
| 77 | + !$equiv && !spip_cookie_envoye() |
|
| 78 | + || ( |
|
| 79 | + !empty($_SERVER['SERVER_SOFTWARE']) |
|
| 80 | + && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 81 | + && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | + || !empty($_SERVER['SERVER_SIGNATURE']) |
|
| 83 | + && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
|
| 84 | + && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | + || function_exists('apache_getenv') |
|
| 86 | + || defined('_SERVER_APACHE') |
|
| 87 | + ) |
|
| 88 | + ) { |
|
| 89 | + @header('Location: ' . $url); |
|
| 90 | + $equiv = ''; |
|
| 91 | + } else { |
|
| 92 | + @header('Refresh: 0; url=' . $url); |
|
| 93 | + if (isset($GLOBALS['meta']['charset'])) { |
|
| 94 | + @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 95 | + } |
|
| 96 | + $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
|
| 97 | + } |
|
| 98 | + include_spip('inc/lang'); |
|
| 99 | + if ($status != 302) { |
|
| 100 | + http_response_code($status); |
|
| 101 | + } |
|
| 102 | + echo '<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">', "\n", |
|
| 103 | + html_lang_attributes(), ' |
|
| 104 | 104 | <head>', |
| 105 | - $equiv, ' |
|
| 105 | + $equiv, ' |
|
| 106 | 106 | <title>HTTP ' . $status . '</title> |
| 107 | 107 | ' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . ' |
| 108 | 108 | </head> |
| 109 | 109 | <body> |
| 110 | 110 | <h1>HTTP ' . $status . '</h1> |
| 111 | 111 | <a href="', |
| 112 | - quote_amp($url), |
|
| 113 | - '">', |
|
| 114 | - _T('navigateur_pas_redirige'), |
|
| 115 | - '</a></body></html>'; |
|
| 112 | + quote_amp($url), |
|
| 113 | + '">', |
|
| 114 | + _T('navigateur_pas_redirige'), |
|
| 115 | + '</a></body></html>'; |
|
| 116 | 116 | |
| 117 | - spip_log("redirige $status: $url"); |
|
| 117 | + spip_log("redirige $status: $url"); |
|
| 118 | 118 | |
| 119 | - exit; |
|
| 119 | + exit; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | function redirige_formulaire($url, $equiv = '', $format = 'message') { |
| 123 | - if ( |
|
| 124 | - !_AJAX |
|
| 125 | - && !headers_sent() |
|
| 126 | - && !_request('var_ajax') |
|
| 127 | - ) { |
|
| 128 | - redirige_par_entete(str_replace('&', '&', (string) $url), $equiv); |
|
| 129 | - } // si c'est une ancre, fixer simplement le window.location.hash |
|
| 130 | - elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) { |
|
| 131 | - return [ |
|
| 132 | - // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 133 | - "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>", |
|
| 134 | - // et rien dans le message ok |
|
| 135 | - '' |
|
| 136 | - ]; |
|
| 137 | - } else { |
|
| 138 | - // ne pas laisser passer n'importe quoi dans l'url |
|
| 139 | - $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 140 | - |
|
| 141 | - $url = strtr($url, "\n\r", ' '); |
|
| 142 | - # en theorie on devrait faire ca tout le temps, mais quand la chaine |
|
| 143 | - # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
|
| 144 | - if ($url[0] == '?') { |
|
| 145 | - $url = url_de_base() . $url; |
|
| 146 | - } |
|
| 147 | - $url = str_replace('&', '&', (string) $url); |
|
| 148 | - spip_log("redirige formulaire ajax: $url"); |
|
| 149 | - include_spip('inc/filtres'); |
|
| 150 | - if ($format == 'ajaxform') { |
|
| 151 | - return [ |
|
| 152 | - // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 153 | - '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 154 | - // et un message au cas ou |
|
| 155 | - '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 156 | - ]; |
|
| 157 | - } else // format message texte, tout en js inline |
|
| 158 | - { |
|
| 159 | - return |
|
| 160 | - // ie poste les formulaires dans une iframe, il faut donc rediriger son parent |
|
| 161 | - "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
|
| 162 | - . http_img_pack('loader.svg', '', " class='loader'") |
|
| 163 | - . '<br />' |
|
| 164 | - . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 165 | - } |
|
| 166 | - } |
|
| 123 | + if ( |
|
| 124 | + !_AJAX |
|
| 125 | + && !headers_sent() |
|
| 126 | + && !_request('var_ajax') |
|
| 127 | + ) { |
|
| 128 | + redirige_par_entete(str_replace('&', '&', (string) $url), $equiv); |
|
| 129 | + } // si c'est une ancre, fixer simplement le window.location.hash |
|
| 130 | + elseif ($format == 'ajaxform' && preg_match(',^#[0-9a-z\-_]+$,i', (string) $url)) { |
|
| 131 | + return [ |
|
| 132 | + // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 133 | + "<a href='$url' name='ajax_ancre' style='display:none;'>anchor</a>", |
|
| 134 | + // et rien dans le message ok |
|
| 135 | + '' |
|
| 136 | + ]; |
|
| 137 | + } else { |
|
| 138 | + // ne pas laisser passer n'importe quoi dans l'url |
|
| 139 | + $url = str_replace(['<', '"'], ['<', '"'], (string) $url); |
|
| 140 | + |
|
| 141 | + $url = strtr($url, "\n\r", ' '); |
|
| 142 | + # en theorie on devrait faire ca tout le temps, mais quand la chaine |
|
| 143 | + # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
|
| 144 | + if ($url[0] == '?') { |
|
| 145 | + $url = url_de_base() . $url; |
|
| 146 | + } |
|
| 147 | + $url = str_replace('&', '&', (string) $url); |
|
| 148 | + spip_log("redirige formulaire ajax: $url"); |
|
| 149 | + include_spip('inc/filtres'); |
|
| 150 | + if ($format == 'ajaxform') { |
|
| 151 | + return [ |
|
| 152 | + // on renvoie un lien masque qui sera traite par ajaxCallback.js |
|
| 153 | + '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 154 | + // et un message au cas ou |
|
| 155 | + '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 156 | + ]; |
|
| 157 | + } else // format message texte, tout en js inline |
|
| 158 | + { |
|
| 159 | + return |
|
| 160 | + // ie poste les formulaires dans une iframe, il faut donc rediriger son parent |
|
| 161 | + "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
|
| 162 | + . http_img_pack('loader.svg', '', " class='loader'") |
|
| 163 | + . '<br />' |
|
| 164 | + . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 165 | + } |
|
| 166 | + } |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | * @return void |
| 185 | 185 | **/ |
| 186 | 186 | function redirige_url_ecrire($script = '', $args = '', $equiv = '') { |
| 187 | - return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv); |
|
| 187 | + return redirige_par_entete(generer_url_ecrire($script, $args, true), $equiv); |
|
| 188 | 188 | } |
| 189 | 189 | /** |
| 190 | 190 | * Renvoie au client le header HTTP avec le message correspondant au code indiqué. |
@@ -199,27 +199,27 @@ discard block |
||
| 199 | 199 | * Code d'erreur |
| 200 | 200 | **/ |
| 201 | 201 | function http_status($status) { |
| 202 | - http_response_code($status); |
|
| 202 | + http_response_code($status); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | // Retourne ce qui va bien pour que le navigateur ne mette pas la page en cache |
| 206 | 206 | function http_no_cache() { |
| 207 | - if (headers_sent()) { |
|
| 208 | - spip_log('http_no_cache arrive trop tard'); |
|
| 209 | - |
|
| 210 | - return; |
|
| 211 | - } |
|
| 212 | - $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 213 | - |
|
| 214 | - // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 215 | - // il faudrait aussi pour Safari |
|
| 216 | - // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 217 | - // mais ca ne respecte pas |
|
| 218 | - // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 219 | - |
|
| 220 | - header("Content-Type: text/html; charset=$charset"); |
|
| 221 | - header('Expires: 0'); |
|
| 222 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 223 | - header('Cache-Control: no-cache, must-revalidate'); |
|
| 224 | - header('Pragma: no-cache'); |
|
| 207 | + if (headers_sent()) { |
|
| 208 | + spip_log('http_no_cache arrive trop tard'); |
|
| 209 | + |
|
| 210 | + return; |
|
| 211 | + } |
|
| 212 | + $charset = empty($GLOBALS['meta']['charset']) ? 'utf-8' : $GLOBALS['meta']['charset']; |
|
| 213 | + |
|
| 214 | + // selon http://developer.apple.com/internet/safari/faq.html#anchor5 |
|
| 215 | + // il faudrait aussi pour Safari |
|
| 216 | + // header("Cache-Control: post-check=0, pre-check=0", false) |
|
| 217 | + // mais ca ne respecte pas |
|
| 218 | + // http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9 |
|
| 219 | + |
|
| 220 | + header("Content-Type: text/html; charset=$charset"); |
|
| 221 | + header('Expires: 0'); |
|
| 222 | + header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 223 | + header('Cache-Control: no-cache, must-revalidate'); |
|
| 224 | + header('Pragma: no-cache'); |
|
| 225 | 225 | } |
@@ -78,20 +78,20 @@ discard block |
||
| 78 | 78 | || ( |
| 79 | 79 | !empty($_SERVER['SERVER_SOFTWARE']) |
| 80 | 80 | && _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE |
| 81 | - && preg_match('/' . _SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 81 | + && preg_match('/'._SERVEUR_SOFTWARE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', (string) $_SERVER['SERVER_SOFTWARE']) |
|
| 82 | 82 | || !empty($_SERVER['SERVER_SIGNATURE']) |
| 83 | 83 | && _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE |
| 84 | - && preg_match('/' . _SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE . '/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 84 | + && preg_match('/'._SERVEUR_SIGNATURE_ACCEPTE_LOCATION_APRES_COOKIE.'/i', (string) $_SERVER['SERVER_SIGNATURE']) |
|
| 85 | 85 | || function_exists('apache_getenv') |
| 86 | 86 | || defined('_SERVER_APACHE') |
| 87 | 87 | ) |
| 88 | 88 | ) { |
| 89 | - @header('Location: ' . $url); |
|
| 89 | + @header('Location: '.$url); |
|
| 90 | 90 | $equiv = ''; |
| 91 | 91 | } else { |
| 92 | - @header('Refresh: 0; url=' . $url); |
|
| 92 | + @header('Refresh: 0; url='.$url); |
|
| 93 | 93 | if (isset($GLOBALS['meta']['charset'])) { |
| 94 | - @header('Content-Type: text/html; charset=' . $GLOBALS['meta']['charset']); |
|
| 94 | + @header('Content-Type: text/html; charset='.$GLOBALS['meta']['charset']); |
|
| 95 | 95 | } |
| 96 | 96 | $equiv = "<meta http-equiv='Refresh' content='0; url=$url'>"; |
| 97 | 97 | } |
@@ -103,11 +103,11 @@ discard block |
||
| 103 | 103 | html_lang_attributes(), ' |
| 104 | 104 | <head>', |
| 105 | 105 | $equiv, ' |
| 106 | -<title>HTTP ' . $status . '</title> |
|
| 107 | -' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset=' . $GLOBALS['meta']['charset'] . '">' : '') . ' |
|
| 106 | +<title>HTTP ' . $status.'</title> |
|
| 107 | +' . ((isset($GLOBALS['meta']['charset'])) ? '<meta http-equiv="Content-Type" content="text/html;charset='.$GLOBALS['meta']['charset'].'">' : '').' |
|
| 108 | 108 | </head> |
| 109 | 109 | <body> |
| 110 | -<h1>HTTP ' . $status . '</h1> |
|
| 110 | +<h1>HTTP ' . $status.'</h1> |
|
| 111 | 111 | <a href="', |
| 112 | 112 | quote_amp($url), |
| 113 | 113 | '">', |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | # en theorie on devrait faire ca tout le temps, mais quand la chaine |
| 143 | 143 | # commence par ? c'est imperatif, sinon l'url finale n'est pas la bonne |
| 144 | 144 | if ($url[0] == '?') { |
| 145 | - $url = url_de_base() . $url; |
|
| 145 | + $url = url_de_base().$url; |
|
| 146 | 146 | } |
| 147 | 147 | $url = str_replace('&', '&', (string) $url); |
| 148 | 148 | spip_log("redirige formulaire ajax: $url"); |
@@ -150,9 +150,9 @@ discard block |
||
| 150 | 150 | if ($format == 'ajaxform') { |
| 151 | 151 | return [ |
| 152 | 152 | // on renvoie un lien masque qui sera traite par ajaxCallback.js |
| 153 | - '<a href="' . quote_amp($url) . '" name="ajax_redirect" style="display:none;">' . _T('navigateur_pas_redirige') . '</a>', |
|
| 153 | + '<a href="'.quote_amp($url).'" name="ajax_redirect" style="display:none;">'._T('navigateur_pas_redirige').'</a>', |
|
| 154 | 154 | // et un message au cas ou |
| 155 | - '<br /><a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>' |
|
| 155 | + '<br /><a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>' |
|
| 156 | 156 | ]; |
| 157 | 157 | } else // format message texte, tout en js inline |
| 158 | 158 | { |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | "<script type='text/javascript'>if (parent.window){parent.window.document.location.replace(\"$url\");} else {document.location.replace(\"$url\");}</script>" |
| 162 | 162 | . http_img_pack('loader.svg', '', " class='loader'") |
| 163 | 163 | . '<br />' |
| 164 | - . '<a href="' . quote_amp($url) . '">' . _T('navigateur_pas_redirige') . '</a>'; |
|
| 164 | + . '<a href="'.quote_amp($url).'">'._T('navigateur_pas_redirige').'</a>'; |
|
| 165 | 165 | } |
| 166 | 166 | } |
| 167 | 167 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | |
| 220 | 220 | header("Content-Type: text/html; charset=$charset"); |
| 221 | 221 | header('Expires: 0'); |
| 222 | - header('Last-Modified: ' . gmdate('D, d M Y H:i:s') . ' GMT'); |
|
| 222 | + header('Last-Modified: '.gmdate('D, d M Y H:i:s').' GMT'); |
|
| 223 | 223 | header('Cache-Control: no-cache, must-revalidate'); |
| 224 | 224 | header('Pragma: no-cache'); |
| 225 | 225 | } |
@@ -15,7 +15,7 @@ discard block |
||
| 15 | 15 | * @package SPIP\Core\Langue |
| 16 | 16 | **/ |
| 17 | 17 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 18 | - return; |
|
| 18 | + return; |
|
| 19 | 19 | } |
| 20 | 20 | |
| 21 | 21 | |
@@ -38,34 +38,34 @@ discard block |
||
| 38 | 38 | **/ |
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | - if (is_null($liste_langues)) { |
|
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | - } else { |
|
| 44 | - if (is_array($liste_langues)) { |
|
| 45 | - $liste_langues = implode(',', $liste_langues); |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | - |
|
| 50 | - // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | - // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | - $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | - if (!$lang) { |
|
| 54 | - return false; |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - if ( |
|
| 58 | - str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | - || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | - ) { |
|
| 61 | - $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | - $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | - $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | - |
|
| 65 | - return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | - } else { |
|
| 67 | - return false; |
|
| 68 | - } |
|
| 41 | + if (is_null($liste_langues)) { |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | + } else { |
|
| 44 | + if (is_array($liste_langues)) { |
|
| 45 | + $liste_langues = implode(',', $liste_langues); |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + $liste_langues = ',' . $liste_langues . ','; |
|
| 49 | + |
|
| 50 | + // Si la langue demandee n'existe pas, on essaie d'autres variantes |
|
| 51 | + // Exemple : 'pt-br' => 'pt_br' => 'pt' |
|
| 52 | + $lang = str_replace('-', '_', trim($lang)); |
|
| 53 | + if (!$lang) { |
|
| 54 | + return false; |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + if ( |
|
| 58 | + str_contains($liste_langues, (string) ",$lang,") |
|
| 59 | + || ($lang = preg_replace(',_.*,', '', $lang)) && str_contains($liste_langues, (string) ",$lang,") |
|
| 60 | + ) { |
|
| 61 | + $GLOBALS['spip_lang_rtl'] = lang_dir($lang, '', '_rtl'); |
|
| 62 | + $GLOBALS['spip_lang_right'] = $GLOBALS['spip_lang_rtl'] ? 'left' : 'right'; |
|
| 63 | + $GLOBALS['spip_lang_left'] = $GLOBALS['spip_lang_rtl'] ? 'right' : 'left'; |
|
| 64 | + |
|
| 65 | + return $GLOBALS['spip_lang'] = $lang; |
|
| 66 | + } else { |
|
| 67 | + return false; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | // |
@@ -78,9 +78,9 @@ discard block |
||
| 78 | 78 | // par exemple le francais pour l'espagnol, l'anglais pour l'allemand, etc. |
| 79 | 79 | |
| 80 | 80 | function choisir_traduction($trads, $lang = '') { |
| 81 | - $k = approcher_langue($trads, $lang); |
|
| 81 | + $k = approcher_langue($trads, $lang); |
|
| 82 | 82 | |
| 83 | - return $k ? $trads[$k] : array_shift($trads); |
|
| 83 | + return $k ? $trads[$k] : array_shift($trads); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | // retourne son 2e argument si c'est un index du premier |
@@ -88,21 +88,21 @@ discard block |
||
| 88 | 88 | // la langue X etant consideree comme une approche de X_Y |
| 89 | 89 | function approcher_langue($trads, $lang = '') { |
| 90 | 90 | |
| 91 | - if (!$lang) { |
|
| 92 | - $lang = $GLOBALS['spip_lang']; |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - if (isset($trads[$lang])) { |
|
| 96 | - return $lang; |
|
| 97 | - } // cas des langues xx_yy |
|
| 98 | - else { |
|
| 99 | - $r = explode('_', (string) $lang); |
|
| 100 | - if (isset($trads[$r[0]])) { |
|
| 101 | - return $r[0]; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - return ''; |
|
| 91 | + if (!$lang) { |
|
| 92 | + $lang = $GLOBALS['spip_lang']; |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + if (isset($trads[$lang])) { |
|
| 96 | + return $lang; |
|
| 97 | + } // cas des langues xx_yy |
|
| 98 | + else { |
|
| 99 | + $r = explode('_', (string) $lang); |
|
| 100 | + if (isset($trads[$r[0]])) { |
|
| 101 | + return $r[0]; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + return ''; |
|
| 106 | 106 | } |
| 107 | 107 | |
| 108 | 108 | /** |
@@ -117,10 +117,10 @@ discard block |
||
| 117 | 117 | * Nom de la langue, sinon son code. |
| 118 | 118 | **/ |
| 119 | 119 | function traduire_nom_langue($lang) { |
| 120 | - include_spip('inc/lang_liste'); |
|
| 121 | - include_spip('inc/charsets'); |
|
| 120 | + include_spip('inc/lang_liste'); |
|
| 121 | + include_spip('inc/charsets'); |
|
| 122 | 122 | |
| 123 | - return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 123 | + return html2unicode($GLOBALS['codes_langues'][$lang] ?? $lang); |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | // |
@@ -133,10 +133,10 @@ discard block |
||
| 133 | 133 | // hebreu a priori), 'droitier' sinon. |
| 134 | 134 | // C'est utilise par #LANG_DIR, #LANG_LEFT, #LANG_RIGHT. |
| 135 | 135 | function lang_dir($lang = '', $droitier = 'ltr', $gaucher = 'rtl') { |
| 136 | - static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 136 | + static $lang_rtl = ['ar', 'fa', 'ku', 'prs', 'ps', 'ur', 'he', 'heb', 'hbo', 'yi']; |
|
| 137 | 137 | |
| 138 | - return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | - $gaucher : $droitier; |
|
| 138 | + return in_array(($lang ?: $GLOBALS['spip_lang']), $lang_rtl) ? |
|
| 139 | + $gaucher : $droitier; |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // typo francaise ou anglaise ? |
@@ -145,29 +145,29 @@ discard block |
||
| 145 | 145 | // sinon determiner la typo en fonction de la langue courante |
| 146 | 146 | |
| 147 | 147 | function lang_typo($lang = '') { |
| 148 | - if (!$lang) { |
|
| 149 | - $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | - } |
|
| 151 | - if ( |
|
| 152 | - $lang == 'eo' |
|
| 153 | - || $lang == 'fr' |
|
| 154 | - || str_starts_with((string) $lang, 'fr_') |
|
| 155 | - || $lang == 'cpf' |
|
| 156 | - ) { |
|
| 157 | - return 'fr'; |
|
| 158 | - } else { |
|
| 159 | - return 'en'; |
|
| 160 | - } |
|
| 148 | + if (!$lang) { |
|
| 149 | + $lang = $GLOBALS['lang_objet'] ?? $GLOBALS['spip_lang']; |
|
| 150 | + } |
|
| 151 | + if ( |
|
| 152 | + $lang == 'eo' |
|
| 153 | + || $lang == 'fr' |
|
| 154 | + || str_starts_with((string) $lang, 'fr_') |
|
| 155 | + || $lang == 'cpf' |
|
| 156 | + ) { |
|
| 157 | + return 'fr'; |
|
| 158 | + } else { |
|
| 159 | + return 'en'; |
|
| 160 | + } |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | // gestion de la globale $lang_objet pour que les textes soient affiches |
| 164 | 164 | // avec les memes typo et direction dans l'espace prive que dans le public |
| 165 | 165 | function changer_typo($lang = '') { |
| 166 | - if ($lang) { |
|
| 167 | - $GLOBALS['lang_objet'] = $lang; |
|
| 168 | - } else { |
|
| 169 | - unset($GLOBALS['lang_objet']); |
|
| 170 | - } |
|
| 166 | + if ($lang) { |
|
| 167 | + $GLOBALS['lang_objet'] = $lang; |
|
| 168 | + } else { |
|
| 169 | + unset($GLOBALS['lang_objet']); |
|
| 170 | + } |
|
| 171 | 171 | } |
| 172 | 172 | |
| 173 | 173 | // |
@@ -177,56 +177,56 @@ discard block |
||
| 177 | 177 | // pour 'changer_lang' (langue de l'article, espace prive), c'est en Ajax |
| 178 | 178 | // |
| 179 | 179 | function menu_langues($nom_select, $default = '') { |
| 180 | - include_spip('inc/actions'); |
|
| 181 | - |
|
| 182 | - $langues = liste_options_langues($nom_select); |
|
| 183 | - $ret = ''; |
|
| 184 | - if ($langues === []) { |
|
| 185 | - return ''; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - if (!$default) { |
|
| 189 | - $default = $GLOBALS['spip_lang']; |
|
| 190 | - } |
|
| 191 | - foreach ($langues as $l) { |
|
| 192 | - $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | - } |
|
| 195 | - |
|
| 196 | - if (!test_espace_prive()) { |
|
| 197 | - $cible = self(); |
|
| 198 | - $base = ''; |
|
| 199 | - } else { |
|
| 200 | - $cible = self(); |
|
| 201 | - $base = spip_connect() ? 'base' : ''; |
|
| 202 | - } |
|
| 203 | - |
|
| 204 | - $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | - |
|
| 206 | - return generer_action_auteur( |
|
| 207 | - 'converser', |
|
| 208 | - $base, |
|
| 209 | - $cible, |
|
| 210 | - (select_langues($nom_select, $change, $ret) |
|
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | - " method='post'" |
|
| 213 | - ); |
|
| 180 | + include_spip('inc/actions'); |
|
| 181 | + |
|
| 182 | + $langues = liste_options_langues($nom_select); |
|
| 183 | + $ret = ''; |
|
| 184 | + if ($langues === []) { |
|
| 185 | + return ''; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + if (!$default) { |
|
| 189 | + $default = $GLOBALS['spip_lang']; |
|
| 190 | + } |
|
| 191 | + foreach ($langues as $l) { |
|
| 192 | + $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
|
| 193 | + $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 194 | + } |
|
| 195 | + |
|
| 196 | + if (!test_espace_prive()) { |
|
| 197 | + $cible = self(); |
|
| 198 | + $base = ''; |
|
| 199 | + } else { |
|
| 200 | + $cible = self(); |
|
| 201 | + $base = spip_connect() ? 'base' : ''; |
|
| 202 | + } |
|
| 203 | + |
|
| 204 | + $change = ' onchange="this.parentNode.parentNode.submit()"'; |
|
| 205 | + |
|
| 206 | + return generer_action_auteur( |
|
| 207 | + 'converser', |
|
| 208 | + $base, |
|
| 209 | + $cible, |
|
| 210 | + (select_langues($nom_select, $change, $ret) |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 212 | + " method='post'" |
|
| 213 | + ); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | - static $cpt = 0; |
|
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 219 | - |
|
| 220 | - return |
|
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | - "<select name='$nom_select' id='$id' " |
|
| 223 | - . ((test_espace_prive()) ? |
|
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 226 | - . $change |
|
| 227 | - . ">\n" |
|
| 228 | - . $options |
|
| 229 | - . '</select>'; |
|
| 217 | + static $cpt = 0; |
|
| 218 | + $id = 'menu_langues' . $cpt++; |
|
| 219 | + |
|
| 220 | + return |
|
| 221 | + "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 222 | + "<select name='$nom_select' id='$id' " |
|
| 223 | + . ((test_espace_prive()) ? |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | + ("class='forml menu_langues'")) |
|
| 226 | + . $change |
|
| 227 | + . ">\n" |
|
| 228 | + . $options |
|
| 229 | + . '</select>'; |
|
| 230 | 230 | } |
| 231 | 231 | |
| 232 | 232 | /** |
@@ -248,34 +248,34 @@ discard block |
||
| 248 | 248 | */ |
| 249 | 249 | function liste_options_langues($nom_select) { |
| 250 | 250 | |
| 251 | - switch ($nom_select) { |
|
| 252 | - # #MENU_LANG |
|
| 253 | - case 'var_lang': |
|
| 254 | - # menu de changement de la langue d'un article |
|
| 255 | - # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | - case 'changer_lang': |
|
| 257 | - $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | - break; |
|
| 259 | - # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | - # les langues presentes sous forme de fichiers de langue |
|
| 261 | - # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | - case 'var_lang_ecrire': |
|
| 263 | - default: |
|
| 264 | - $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | - init_langues(); |
|
| 266 | - $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | - break; |
|
| 251 | + switch ($nom_select) { |
|
| 252 | + # #MENU_LANG |
|
| 253 | + case 'var_lang': |
|
| 254 | + # menu de changement de la langue d'un article |
|
| 255 | + # les langues selectionnees dans la configuration "multilinguisme" |
|
| 256 | + case 'changer_lang': |
|
| 257 | + $langues = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 258 | + break; |
|
| 259 | + # menu de l'interface (privee, installation et panneau de login) |
|
| 260 | + # les langues presentes sous forme de fichiers de langue |
|
| 261 | + # on force la relecture du repertoire des langues pour etre synchrone. |
|
| 262 | + case 'var_lang_ecrire': |
|
| 263 | + default: |
|
| 264 | + $GLOBALS['meta']['langues_proposees'] = ''; |
|
| 265 | + init_langues(); |
|
| 266 | + $langues = explode(',', $GLOBALS['meta']['langues_proposees']); |
|
| 267 | + break; |
|
| 268 | 268 | |
| 269 | 269 | # dernier choix possible : toutes les langues = langues_proposees |
| 270 | 270 | # + langues_multilingues ; mais, ne sert pas |
| 271 | 271 | # $langues = explode(',', $GLOBALS['all_langs']); |
| 272 | - } |
|
| 273 | - if (count($langues) <= 1) { |
|
| 274 | - return []; |
|
| 275 | - } |
|
| 276 | - sort($langues); |
|
| 272 | + } |
|
| 273 | + if (count($langues) <= 1) { |
|
| 274 | + return []; |
|
| 275 | + } |
|
| 276 | + sort($langues); |
|
| 277 | 277 | |
| 278 | - return $langues; |
|
| 278 | + return $langues; |
|
| 279 | 279 | } |
| 280 | 280 | |
| 281 | 281 | |
@@ -290,39 +290,39 @@ discard block |
||
| 290 | 290 | **/ |
| 291 | 291 | function verifier_lang_url() { |
| 292 | 292 | |
| 293 | - // quelle langue est demandee ? |
|
| 294 | - $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | - if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | - $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | - } |
|
| 298 | - if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | - $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | - } |
|
| 301 | - if (isset($_GET['lang'])) { |
|
| 302 | - $lang_demandee = $_GET['lang']; |
|
| 303 | - } |
|
| 304 | - |
|
| 305 | - // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | - if ( |
|
| 307 | - $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | - && changer_langue($lang_demandee) |
|
| 309 | - && $lang_demandee != @$_GET['lang'] |
|
| 310 | - ) { |
|
| 311 | - $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | - // ici on a besoin des var_truc |
|
| 313 | - foreach ($_GET as $var => $val) { |
|
| 314 | - if (!strncmp('var_', $var, 4)) { |
|
| 315 | - $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - include_spip('inc/headers'); |
|
| 319 | - redirige_par_entete($destination); |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | - // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | - // (pour criteres {lang}). |
|
| 325 | - $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 293 | + // quelle langue est demandee ? |
|
| 294 | + $lang_demandee = (test_espace_prive() ? $GLOBALS['spip_lang'] : $GLOBALS['meta']['langue_site']); |
|
| 295 | + if (isset($_COOKIE['spip_lang_ecrire'])) { |
|
| 296 | + $lang_demandee = $_COOKIE['spip_lang_ecrire']; |
|
| 297 | + } |
|
| 298 | + if (!test_espace_prive() && isset($_COOKIE['spip_lang'])) { |
|
| 299 | + $lang_demandee = $_COOKIE['spip_lang']; |
|
| 300 | + } |
|
| 301 | + if (isset($_GET['lang'])) { |
|
| 302 | + $lang_demandee = $_GET['lang']; |
|
| 303 | + } |
|
| 304 | + |
|
| 305 | + // Renvoyer si besoin (et si la langue demandee existe) |
|
| 306 | + if ( |
|
| 307 | + $GLOBALS['spip_lang'] != $lang_demandee |
|
| 308 | + && changer_langue($lang_demandee) |
|
| 309 | + && $lang_demandee != @$_GET['lang'] |
|
| 310 | + ) { |
|
| 311 | + $destination = parametre_url(self(), 'lang', $lang_demandee, '&'); |
|
| 312 | + // ici on a besoin des var_truc |
|
| 313 | + foreach ($_GET as $var => $val) { |
|
| 314 | + if (!strncmp('var_', $var, 4)) { |
|
| 315 | + $destination = parametre_url($destination, $var, $val, '&'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + include_spip('inc/headers'); |
|
| 319 | + redirige_par_entete($destination); |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // Subtilite : si la langue demandee par cookie est la bonne |
|
| 323 | + // alors on fait comme si $lang etait passee dans l'URL |
|
| 324 | + // (pour criteres {lang}). |
|
| 325 | + $GLOBALS['lang'] = $_GET['lang'] = $GLOBALS['spip_lang']; |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | |
@@ -340,19 +340,19 @@ discard block |
||
| 340 | 340 | * La langue sélectionnée |
| 341 | 341 | **/ |
| 342 | 342 | function utiliser_langue_site($liste_langues = null) { |
| 343 | - // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | - if ( |
|
| 345 | - isset($GLOBALS['meta']['langue_site']) |
|
| 346 | - && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | - ) { |
|
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | - } |
|
| 350 | - // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | - if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | - spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | - } |
|
| 354 | - |
|
| 355 | - return $GLOBALS['spip_lang']; |
|
| 343 | + // s'il existe une langue du site (en gros tout le temps en théorie) |
|
| 344 | + if ( |
|
| 345 | + isset($GLOBALS['meta']['langue_site']) |
|
| 346 | + && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
|
| 347 | + ) { |
|
| 348 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 349 | + } |
|
| 350 | + // en theorie là, la globale est définie, sinon c'est un problème. |
|
| 351 | + if (!isset($GLOBALS['spip_lang'])) { |
|
| 352 | + spip_log('La globale spip_lang est indéfinie dans utiliser_langue_site() !', _LOG_ERREUR); |
|
| 353 | + } |
|
| 354 | + |
|
| 355 | + return $GLOBALS['spip_lang']; |
|
| 356 | 356 | } |
| 357 | 357 | |
| 358 | 358 | /** |
@@ -371,38 +371,38 @@ discard block |
||
| 371 | 371 | **/ |
| 372 | 372 | function utiliser_langue_visiteur($liste_langues = null) { |
| 373 | 373 | |
| 374 | - // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | - if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | - $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | - } |
|
| 378 | - |
|
| 379 | - $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | - if ( |
|
| 381 | - isset($_COOKIE[$l]) |
|
| 382 | - && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | - ) { |
|
| 384 | - return $l; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - if ( |
|
| 388 | - isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | - && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | - ) { |
|
| 391 | - return $l; |
|
| 392 | - } |
|
| 393 | - |
|
| 394 | - if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | - foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | - if ( |
|
| 397 | - preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | - && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | - ) { |
|
| 400 | - return $l; |
|
| 401 | - } |
|
| 402 | - } |
|
| 403 | - } |
|
| 404 | - |
|
| 405 | - return utiliser_langue_site($liste_langues); |
|
| 374 | + // si on est dans l'espace public et pas de $liste_langues : se limiter a la config langues_multilingue si définie |
|
| 375 | + if (is_null($liste_langues) && !test_espace_prive() && !empty($GLOBALS['meta']['langues_multilingue'])) { |
|
| 376 | + $liste_langues = $GLOBALS['meta']['langues_multilingue']; |
|
| 377 | + } |
|
| 378 | + |
|
| 379 | + $l = (test_espace_prive() ? 'spip_lang_ecrire' : 'spip_lang'); |
|
| 380 | + if ( |
|
| 381 | + isset($_COOKIE[$l]) |
|
| 382 | + && changer_langue($l = $_COOKIE[$l], $liste_langues) |
|
| 383 | + ) { |
|
| 384 | + return $l; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + if ( |
|
| 388 | + isset($GLOBALS['visiteur_session']['lang']) |
|
| 389 | + && changer_langue($l = $GLOBALS['visiteur_session']['lang'], $liste_langues) |
|
| 390 | + ) { |
|
| 391 | + return $l; |
|
| 392 | + } |
|
| 393 | + |
|
| 394 | + if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) { |
|
| 395 | + foreach (explode(',', (string) $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $s) { |
|
| 396 | + if ( |
|
| 397 | + preg_match('#^([a-z]{2,3})(-[a-z]{2,3})?(;q=[0-9.]+)?$#i', trim($s), $r) |
|
| 398 | + && changer_langue($l = strtolower($r[1]), $liste_langues) |
|
| 399 | + ) { |
|
| 400 | + return $l; |
|
| 401 | + } |
|
| 402 | + } |
|
| 403 | + } |
|
| 404 | + |
|
| 405 | + return utiliser_langue_site($liste_langues); |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -412,7 +412,7 @@ discard block |
||
| 412 | 412 | * @return int |
| 413 | 413 | */ |
| 414 | 414 | function match_langue($chaine) { |
| 415 | - return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 415 | + return preg_match('/^[a-z]{2,3}(_[a-z]{2,3}){0,2}$/', $chaine); |
|
| 416 | 416 | } |
| 417 | 417 | |
| 418 | 418 | /** |
@@ -430,38 +430,38 @@ discard block |
||
| 430 | 430 | **/ |
| 431 | 431 | function init_langues() { |
| 432 | 432 | |
| 433 | - // liste des langues dans les meta, sauf a l'install |
|
| 434 | - $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | - |
|
| 436 | - $tout = []; |
|
| 437 | - if (!$all_langs) { |
|
| 438 | - // trouver tous les modules lang/spip_xx.php |
|
| 439 | - $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | - foreach (array_keys($modules) as $name) { |
|
| 441 | - if ( |
|
| 442 | - preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | - && match_langue($regs[1]) |
|
| 444 | - ) { |
|
| 445 | - $tout[] = $regs[1]; |
|
| 446 | - } |
|
| 447 | - } |
|
| 448 | - sort($tout); |
|
| 449 | - $tout = implode(',', $tout); |
|
| 450 | - // Si les langues n'ont pas change, ne rien faire |
|
| 451 | - if ($tout != $all_langs) { |
|
| 452 | - $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | - include_spip('inc/meta'); |
|
| 454 | - ecrire_meta('langues_proposees', $tout); |
|
| 455 | - } |
|
| 456 | - } |
|
| 457 | - if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | - // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | - $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | - ? _LANGUE_PAR_DEFAUT |
|
| 462 | - : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | - ecrire_meta('langue_site', $tout); |
|
| 464 | - } |
|
| 433 | + // liste des langues dans les meta, sauf a l'install |
|
| 434 | + $all_langs = $GLOBALS['meta']['langues_proposees'] ?? ''; |
|
| 435 | + |
|
| 436 | + $tout = []; |
|
| 437 | + if (!$all_langs) { |
|
| 438 | + // trouver tous les modules lang/spip_xx.php |
|
| 439 | + $modules = find_all_in_path('lang/', '/spip_([a-z_]+)\.php$'); |
|
| 440 | + foreach (array_keys($modules) as $name) { |
|
| 441 | + if ( |
|
| 442 | + preg_match(',^spip_([a-z_]+)\.php$,', $name, $regs) |
|
| 443 | + && match_langue($regs[1]) |
|
| 444 | + ) { |
|
| 445 | + $tout[] = $regs[1]; |
|
| 446 | + } |
|
| 447 | + } |
|
| 448 | + sort($tout); |
|
| 449 | + $tout = implode(',', $tout); |
|
| 450 | + // Si les langues n'ont pas change, ne rien faire |
|
| 451 | + if ($tout != $all_langs) { |
|
| 452 | + $GLOBALS['meta']['langues_proposees'] = $tout; |
|
| 453 | + include_spip('inc/meta'); |
|
| 454 | + ecrire_meta('langues_proposees', $tout); |
|
| 455 | + } |
|
| 456 | + } |
|
| 457 | + if (!isset($GLOBALS['meta']['langue_site'])) { |
|
| 458 | + // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
|
| 459 | + $GLOBALS['meta']['langue_site'] = $tout = |
|
| 460 | + (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 461 | + ? _LANGUE_PAR_DEFAUT |
|
| 462 | + : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
|
| 463 | + ecrire_meta('langue_site', $tout); |
|
| 464 | + } |
|
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | /** |
@@ -475,10 +475,10 @@ discard block |
||
| 475 | 475 | * Code html de la balise <html> |
| 476 | 476 | **/ |
| 477 | 477 | function html_lang_attributes() { |
| 478 | - $lang = $GLOBALS['spip_lang']; |
|
| 479 | - $dir = lang_dir($lang); |
|
| 478 | + $lang = $GLOBALS['spip_lang']; |
|
| 479 | + $dir = lang_dir($lang); |
|
| 480 | 480 | |
| 481 | - return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 481 | + return "<html class='$dir $lang no-js' xmlns='http://www.w3.org/1999/xhtml' lang='$lang' dir='$dir'>\n"; |
|
| 482 | 482 | } |
| 483 | 483 | |
| 484 | 484 | |
@@ -492,7 +492,7 @@ discard block |
||
| 492 | 492 | * @return string |
| 493 | 493 | */ |
| 494 | 494 | function aide_lang_dir($spip_lang, $spip_lang_rtl) { |
| 495 | - return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 495 | + return ($spip_lang != 'he') ? $spip_lang_rtl : ''; |
|
| 496 | 496 | } |
| 497 | 497 | |
| 498 | 498 | |
@@ -39,13 +39,13 @@ discard block |
||
| 39 | 39 | function changer_langue($lang, $liste_langues = null) { |
| 40 | 40 | |
| 41 | 41 | if (is_null($liste_langues)) { |
| 42 | - $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '') . ',' . ($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 42 | + $liste_langues = ($GLOBALS['meta']['langues_proposees'] ?? '').','.($GLOBALS['meta']['langues_multilingue'] ?? ''); |
|
| 43 | 43 | } else { |
| 44 | 44 | if (is_array($liste_langues)) { |
| 45 | 45 | $liste_langues = implode(',', $liste_langues); |
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | - $liste_langues = ',' . $liste_langues . ','; |
|
| 48 | + $liste_langues = ','.$liste_langues.','; |
|
| 49 | 49 | |
| 50 | 50 | // Si la langue demandee n'existe pas, on essaie d'autres variantes |
| 51 | 51 | // Exemple : 'pt-br' => 'pt_br' => 'pt' |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | } |
| 191 | 191 | foreach ($langues as $l) { |
| 192 | 192 | $selected = ($l == $default) ? ' selected=\'selected\'' : ''; |
| 193 | - $ret .= "<option value='$l'$selected>[" . $l . '] ' . traduire_nom_langue($l) . "</option>\n"; |
|
| 193 | + $ret .= "<option value='$l'$selected>[".$l.'] '.traduire_nom_langue($l)."</option>\n"; |
|
| 194 | 194 | } |
| 195 | 195 | |
| 196 | 196 | if (!test_espace_prive()) { |
@@ -208,21 +208,20 @@ discard block |
||
| 208 | 208 | $base, |
| 209 | 209 | $cible, |
| 210 | 210 | (select_langues($nom_select, $change, $ret) |
| 211 | - . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='" . _T('bouton_changer') . "' /></div></noscript>"), |
|
| 211 | + . "<noscript><div style='display:inline'><input type='submit' class='fondo' value='"._T('bouton_changer')."' /></div></noscript>"), |
|
| 212 | 212 | " method='post'" |
| 213 | 213 | ); |
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | function select_langues($nom_select, $change, $options, $label = '') { |
| 217 | 217 | static $cpt = 0; |
| 218 | - $id = 'menu_langues' . $cpt++; |
|
| 218 | + $id = 'menu_langues'.$cpt++; |
|
| 219 | 219 | |
| 220 | 220 | return |
| 221 | - "<label for='$id'>" . ($label ?: _T('info_langues')) . '</label> ' . |
|
| 221 | + "<label for='$id'>".($label ?: _T('info_langues')).'</label> '. |
|
| 222 | 222 | "<select name='$nom_select' id='$id' " |
| 223 | 223 | . ((test_espace_prive()) ? |
| 224 | - (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : |
|
| 225 | - ("class='forml menu_langues'")) |
|
| 224 | + (($nom_select == 'var_lang_ecrire' ? "class='lang_ecrire'" : "class='fondl'")) : ("class='forml menu_langues'")) |
|
| 226 | 225 | . $change |
| 227 | 226 | . ">\n" |
| 228 | 227 | . $options |
@@ -345,7 +344,7 @@ discard block |
||
| 345 | 344 | isset($GLOBALS['meta']['langue_site']) |
| 346 | 345 | && (!isset($GLOBALS['spip_lang']) || $GLOBALS['spip_lang'] != $GLOBALS['meta']['langue_site']) |
| 347 | 346 | ) { |
| 348 | - return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues);//@:install |
|
| 347 | + return changer_langue($GLOBALS['meta']['langue_site'], $liste_langues); //@:install |
|
| 349 | 348 | } |
| 350 | 349 | // en theorie là, la globale est définie, sinon c'est un problème. |
| 351 | 350 | if (!isset($GLOBALS['spip_lang'])) { |
@@ -457,7 +456,7 @@ discard block |
||
| 457 | 456 | if (!isset($GLOBALS['meta']['langue_site'])) { |
| 458 | 457 | // Initialisation : le francais si dispo, sinon la premiere langue trouvee |
| 459 | 458 | $GLOBALS['meta']['langue_site'] = $tout = |
| 460 | - (!$all_langs || str_contains(',' . _LANGUE_PAR_DEFAUT . ',', (string) ",$all_langs,")) |
|
| 459 | + (!$all_langs || str_contains(','._LANGUE_PAR_DEFAUT.',', (string) ",$all_langs,")) |
|
| 461 | 460 | ? _LANGUE_PAR_DEFAUT |
| 462 | 461 | : substr((string) $all_langs, 0, strpos((string) $all_langs, ',')); |
| 463 | 462 | ecrire_meta('langue_site', $tout); |
@@ -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 | // |
@@ -20,52 +20,52 @@ discard block |
||
| 20 | 20 | |
| 21 | 21 | function produire_image_math($tex) { |
| 22 | 22 | |
| 23 | - switch ($GLOBALS['traiter_math']) { |
|
| 24 | - // Attention: mathml desactiv'e pour l'instant |
|
| 25 | - case 'mathml': |
|
| 26 | - $ext = '.xhtml'; |
|
| 27 | - $server = $GLOBALS['mathml_server']; |
|
| 28 | - break; |
|
| 29 | - case 'tex': |
|
| 30 | - $ext = '.png'; |
|
| 31 | - $server = $GLOBALS['tex_server']; |
|
| 32 | - break; |
|
| 33 | - default: |
|
| 34 | - return $tex; |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | - @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | - } |
|
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | - |
|
| 43 | - |
|
| 44 | - // Aller chercher l'image sur le serveur |
|
| 45 | - if (!@file_exists($fichier) && $server) { |
|
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | - include_spip('inc/distant'); |
|
| 48 | - recuperer_url($url, ['file' => $fichier]); |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - // Composer la reponse selon presence ou non de l'image |
|
| 53 | - $tex = entites_html($tex); |
|
| 54 | - if (@file_exists($fichier)) { |
|
| 55 | - // MathML |
|
| 56 | - if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | - return implode('', file($fichier)); |
|
| 58 | - } // TeX |
|
| 59 | - else { |
|
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | - $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | - |
|
| 63 | - return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | - } |
|
| 65 | - } else // pas de fichier |
|
| 66 | - { |
|
| 67 | - return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | - } |
|
| 23 | + switch ($GLOBALS['traiter_math']) { |
|
| 24 | + // Attention: mathml desactiv'e pour l'instant |
|
| 25 | + case 'mathml': |
|
| 26 | + $ext = '.xhtml'; |
|
| 27 | + $server = $GLOBALS['mathml_server']; |
|
| 28 | + break; |
|
| 29 | + case 'tex': |
|
| 30 | + $ext = '.png'; |
|
| 31 | + $server = $GLOBALS['tex_server']; |
|
| 32 | + break; |
|
| 33 | + default: |
|
| 34 | + return $tex; |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + // Regarder dans le repertoire local des images TeX et blocs MathML |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 39 | + @mkdir($dir_tex, _SPIP_CHMOD); |
|
| 40 | + } |
|
| 41 | + $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 42 | + |
|
| 43 | + |
|
| 44 | + // Aller chercher l'image sur le serveur |
|
| 45 | + if (!@file_exists($fichier) && $server) { |
|
| 46 | + spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 47 | + include_spip('inc/distant'); |
|
| 48 | + recuperer_url($url, ['file' => $fichier]); |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + // Composer la reponse selon presence ou non de l'image |
|
| 53 | + $tex = entites_html($tex); |
|
| 54 | + if (@file_exists($fichier)) { |
|
| 55 | + // MathML |
|
| 56 | + if ($GLOBALS['traiter_math'] == 'mathml') { |
|
| 57 | + return implode('', file($fichier)); |
|
| 58 | + } // TeX |
|
| 59 | + else { |
|
| 60 | + [, , , $size] = @spip_getimagesize($fichier); |
|
| 61 | + $alt = "alt=\"$tex\" title=\"$tex\""; |
|
| 62 | + |
|
| 63 | + return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
|
| 64 | + } |
|
| 65 | + } else // pas de fichier |
|
| 66 | + { |
|
| 67 | + return "<tt><span class='spip_code' dir='ltr'>$tex</span></tt>"; |
|
| 68 | + } |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | |
@@ -100,52 +100,52 @@ discard block |
||
| 100 | 100 | */ |
| 101 | 101 | function traiter_math($letexte, $source = '', $defaire_amp = false) { |
| 102 | 102 | |
| 103 | - $texte_a_voir = $letexte; |
|
| 104 | - while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | - if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | - $fin = strlen($texte_a_voir); |
|
| 107 | - } |
|
| 108 | - |
|
| 109 | - $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | - $texte_milieu = substr( |
|
| 111 | - $texte_a_voir, |
|
| 112 | - $debut + strlen('<math>'), |
|
| 113 | - $fin - $debut - strlen('<math>') |
|
| 114 | - ); |
|
| 115 | - $texte_fin = substr( |
|
| 116 | - $texte_a_voir, |
|
| 117 | - $fin + strlen('</math>'), |
|
| 118 | - strlen($texte_a_voir) |
|
| 119 | - ); |
|
| 120 | - |
|
| 121 | - // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | - while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | - $expression = $regs[1]; |
|
| 124 | - if ($defaire_amp) { |
|
| 125 | - $expression = str_replace('&', '&', $expression); |
|
| 126 | - } |
|
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | - . code_echappement($echap, $source) |
|
| 131 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - // Les simples $x^2$ en mode 'span' |
|
| 135 | - while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | - $expression = $regs[1]; |
|
| 137 | - if ($defaire_amp) { |
|
| 138 | - $expression = str_replace('&', '&', $expression); |
|
| 139 | - } |
|
| 140 | - $echap = produire_image_math($expression); |
|
| 141 | - $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | - $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | - . code_echappement($echap, $source) |
|
| 144 | - . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - return $texte_a_voir; |
|
| 103 | + $texte_a_voir = $letexte; |
|
| 104 | + while (($debut = strpos($texte_a_voir, '<math>')) !== false) { |
|
| 105 | + if (!$fin = strpos($texte_a_voir, '</math>')) { |
|
| 106 | + $fin = strlen($texte_a_voir); |
|
| 107 | + } |
|
| 108 | + |
|
| 109 | + $texte_debut = substr($texte_a_voir, 0, $debut); |
|
| 110 | + $texte_milieu = substr( |
|
| 111 | + $texte_a_voir, |
|
| 112 | + $debut + strlen('<math>'), |
|
| 113 | + $fin - $debut - strlen('<math>') |
|
| 114 | + ); |
|
| 115 | + $texte_fin = substr( |
|
| 116 | + $texte_a_voir, |
|
| 117 | + $fin + strlen('</math>'), |
|
| 118 | + strlen($texte_a_voir) |
|
| 119 | + ); |
|
| 120 | + |
|
| 121 | + // Les doubles $$x^2$$ en mode 'div' |
|
| 122 | + while ((preg_match(',[$][$]([^$]+)[$][$],', $texte_milieu, $regs))) { |
|
| 123 | + $expression = $regs[1]; |
|
| 124 | + if ($defaire_amp) { |
|
| 125 | + $expression = str_replace('&', '&', $expression); |
|
| 126 | + } |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 128 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 129 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 130 | + . code_echappement($echap, $source) |
|
| 131 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + // Les simples $x^2$ en mode 'span' |
|
| 135 | + while ((preg_match(',[$]([^$]+)[$],', $texte_milieu, $regs))) { |
|
| 136 | + $expression = $regs[1]; |
|
| 137 | + if ($defaire_amp) { |
|
| 138 | + $expression = str_replace('&', '&', $expression); |
|
| 139 | + } |
|
| 140 | + $echap = produire_image_math($expression); |
|
| 141 | + $pos = strpos($texte_milieu, (string) $regs[0]); |
|
| 142 | + $texte_milieu = substr($texte_milieu, 0, $pos) |
|
| 143 | + . code_echappement($echap, $source) |
|
| 144 | + . substr($texte_milieu, $pos + strlen($regs[0])); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + return $texte_a_voir; |
|
| 151 | 151 | } |
@@ -35,15 +35,15 @@ discard block |
||
| 35 | 35 | } |
| 36 | 36 | |
| 37 | 37 | // Regarder dans le repertoire local des images TeX et blocs MathML |
| 38 | - if (!@is_dir($dir_tex = _DIR_VAR . 'cache-TeX/')) { |
|
| 38 | + if (!@is_dir($dir_tex = _DIR_VAR.'cache-TeX/')) { |
|
| 39 | 39 | @mkdir($dir_tex, _SPIP_CHMOD); |
| 40 | 40 | } |
| 41 | - $fichier = $dir_tex . md5(trim((string) $tex)) . $ext; |
|
| 41 | + $fichier = $dir_tex.md5(trim((string) $tex)).$ext; |
|
| 42 | 42 | |
| 43 | 43 | |
| 44 | 44 | // Aller chercher l'image sur le serveur |
| 45 | 45 | if (!@file_exists($fichier) && $server) { |
| 46 | - spip_log($url = $server . '?' . rawurlencode((string) $tex)); |
|
| 46 | + spip_log($url = $server.'?'.rawurlencode((string) $tex)); |
|
| 47 | 47 | include_spip('inc/distant'); |
| 48 | 48 | recuperer_url($url, ['file' => $fichier]); |
| 49 | 49 | } |
@@ -57,7 +57,7 @@ discard block |
||
| 57 | 57 | return implode('', file($fichier)); |
| 58 | 58 | } // TeX |
| 59 | 59 | else { |
| 60 | - [, , , $size] = @spip_getimagesize($fichier); |
|
| 60 | + [,,, $size] = @spip_getimagesize($fichier); |
|
| 61 | 61 | $alt = "alt=\"$tex\" title=\"$tex\""; |
| 62 | 62 | |
| 63 | 63 | return "<img src=\"$fichier\" style=\"vertical-align:middle;\" $size $alt />"; |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | if ($defaire_amp) { |
| 125 | 125 | $expression = str_replace('&', '&', $expression); |
| 126 | 126 | } |
| 127 | - $echap = "\n<p class=\"spip\" style=\"text-align: center;\">" . produire_image_math($expression) . "</p>\n"; |
|
| 127 | + $echap = "\n<p class=\"spip\" style=\"text-align: center;\">".produire_image_math($expression)."</p>\n"; |
|
| 128 | 128 | $pos = strpos($texte_milieu, (string) $regs[0]); |
| 129 | 129 | $texte_milieu = substr($texte_milieu, 0, $pos) |
| 130 | 130 | . code_echappement($echap, $source) |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | . substr($texte_milieu, $pos + strlen($regs[0])); |
| 145 | 145 | } |
| 146 | 146 | |
| 147 | - $texte_a_voir = $texte_debut . $texte_milieu . $texte_fin; |
|
| 147 | + $texte_a_voir = $texte_debut.$texte_milieu.$texte_fin; |
|
| 148 | 148 | } |
| 149 | 149 | |
| 150 | 150 | return $texte_a_voir; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -38,28 +38,28 @@ discard block |
||
| 38 | 38 | * Tableau des champs et valeurs collectées |
| 39 | 39 | */ |
| 40 | 40 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 41 | - $c = $set; |
|
| 42 | - if (!$c) { |
|
| 43 | - $c = []; |
|
| 44 | - foreach ($include_list as $champ) { |
|
| 45 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | - $val = _request($champ); |
|
| 48 | - if ($tous || $val !== null) { |
|
| 49 | - $c[$champ] = $val; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - // on ajoute toujours la lang en saisie possible |
|
| 53 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | - if ($l = _request('changer_lang')) { |
|
| 55 | - $c['lang'] = $l; |
|
| 56 | - } |
|
| 57 | - } |
|
| 58 | - foreach ($exclude_list as $champ) { |
|
| 59 | - unset($c[$champ]); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $c; |
|
| 41 | + $c = $set; |
|
| 42 | + if (!$c) { |
|
| 43 | + $c = []; |
|
| 44 | + foreach ($include_list as $champ) { |
|
| 45 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 46 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 47 | + $val = _request($champ); |
|
| 48 | + if ($tous || $val !== null) { |
|
| 49 | + $c[$champ] = $val; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + // on ajoute toujours la lang en saisie possible |
|
| 53 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 54 | + if ($l = _request('changer_lang')) { |
|
| 55 | + $c['lang'] = $l; |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | + foreach ($exclude_list as $champ) { |
|
| 59 | + unset($c[$champ]); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $c; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | /** |
@@ -96,259 +96,259 @@ discard block |
||
| 96 | 96 | * - chaîne : texte d'un message d'erreur |
| 97 | 97 | */ |
| 98 | 98 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 99 | - if (!$id_objet = (int) $id_objet) { |
|
| 100 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | - |
|
| 102 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - include_spip('inc/filtres'); |
|
| 106 | - |
|
| 107 | - $table_objet = table_objet($objet, $serveur); |
|
| 108 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | - |
|
| 113 | - // Appels incomplets (sans $c) |
|
| 114 | - if (!is_array($c)) { |
|
| 115 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | - |
|
| 117 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | - // il faut passer par instituer_XX() |
|
| 123 | - // TODO: faut-il passer ces variables interdites |
|
| 124 | - // dans un fichier de description separe ? |
|
| 125 | - unset($c['statut']); |
|
| 126 | - unset($c['id_parent']); |
|
| 127 | - unset($c['id_rubrique']); |
|
| 128 | - unset($c['id_secteur']); |
|
| 129 | - |
|
| 130 | - // Gerer les champs non vides |
|
| 131 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 132 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | - if (isset($c[$champ]) && $c[$champ] === '') { |
|
| 134 | - $c[$champ] = $sinon; |
|
| 135 | - } |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - |
|
| 139 | - // N'accepter que les champs qui existent dans la table |
|
| 140 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | - // et dont la valeur n'est pas null |
|
| 142 | - $champs = array_filter($champs, static fn($var) => $var !== null); |
|
| 143 | - // TODO: ici aussi on peut valider les contenus |
|
| 144 | - // en fonction du type |
|
| 145 | - |
|
| 146 | - // Nettoyer les valeurs |
|
| 147 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 148 | - |
|
| 149 | - // On récupère l'état avant toute modification |
|
| 150 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 151 | - |
|
| 152 | - // Envoyer aux plugins |
|
| 153 | - $champs = pipeline( |
|
| 154 | - 'pre_edition', |
|
| 155 | - [ |
|
| 156 | - 'args' => [ |
|
| 157 | - 'table' => $spip_table_objet, // compatibilite |
|
| 158 | - 'table_objet' => $table_objet, |
|
| 159 | - 'spip_table_objet' => $spip_table_objet, |
|
| 160 | - 'desc' => $desc, |
|
| 161 | - 'type' => $objet, |
|
| 162 | - 'id_objet' => $id_objet, |
|
| 163 | - 'data' => $options['data'] ?? null, |
|
| 164 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 165 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 166 | - 'serveur' => $serveur, |
|
| 167 | - 'action' => $options['action'] ?? 'modifier' |
|
| 168 | - ], |
|
| 169 | - 'data' => $champs |
|
| 170 | - ] |
|
| 171 | - ); |
|
| 172 | - |
|
| 173 | - if (!$champs) { |
|
| 174 | - return false; |
|
| 175 | - } |
|
| 176 | - |
|
| 177 | - |
|
| 178 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | - include_spip('inc/config'); |
|
| 180 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 181 | - include_spip('inc/drapeau_edition'); |
|
| 182 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 183 | - } |
|
| 184 | - |
|
| 185 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 186 | - include_spip('inc/editer'); |
|
| 187 | - if (!isset($options['data']) || is_null($options['data'])) { |
|
| 188 | - $options['data'] = &$_POST; |
|
| 189 | - } |
|
| 190 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 191 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 192 | - // et gere l'interface |
|
| 193 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 194 | - if ($conflits) { |
|
| 195 | - return _T('titre_conflit_edition'); |
|
| 196 | - } |
|
| 197 | - |
|
| 198 | - if ($champs) { |
|
| 199 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 200 | - if (isset($champs['lang'])) { |
|
| 201 | - if ($changer_lang = $champs['lang']) { |
|
| 202 | - $id_rubrique = 0; |
|
| 203 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 204 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 205 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 206 | - } |
|
| 207 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 208 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 209 | - } |
|
| 210 | - // on laisse 'lang' dans $champs, |
|
| 211 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 212 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 213 | - // deja pris en compte |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - // la modif peut avoir lieu |
|
| 217 | - |
|
| 218 | - // faut-il ajouter date_modif ? |
|
| 219 | - if ( |
|
| 220 | - !empty($options['date_modif']) && !isset($champs[$options['date_modif']]) |
|
| 221 | - ) { |
|
| 222 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - // allez on commit la modif |
|
| 226 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 227 | - |
|
| 228 | - // on verifie si elle est bien passee |
|
| 229 | - $moof = sql_fetsel( |
|
| 230 | - array_keys($champs), |
|
| 231 | - $spip_table_objet, |
|
| 232 | - "$id_table_objet=" . (int) $id_objet, |
|
| 233 | - [], |
|
| 234 | - [], |
|
| 235 | - '', |
|
| 236 | - [], |
|
| 237 | - $serveur |
|
| 238 | - ); |
|
| 239 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 240 | - if ($moof != $champs) { |
|
| 241 | - $liste = []; |
|
| 242 | - foreach ($moof as $k => $v) { |
|
| 243 | - if ( |
|
| 244 | - $v !== $champs[$k] |
|
| 245 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 246 | - && (!is_numeric($v) || (int) $v !== (int) $champs[$k]) |
|
| 247 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 248 | - && (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 249 | - ) { |
|
| 250 | - $liste[] = $k; |
|
| 251 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 252 | - $conflits[$k]['save'] = $v; |
|
| 253 | - |
|
| 254 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 255 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 256 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 257 | - include_spip('inc/charsets'); |
|
| 258 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 259 | - array_pop($liste); |
|
| 260 | - } |
|
| 261 | - } |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 265 | - // c'est un cas exceptionnel |
|
| 266 | - if ($liste !== []) { |
|
| 267 | - spip_log( |
|
| 268 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | - 'modifier.' . _LOG_CRITIQUE |
|
| 270 | - ); |
|
| 271 | - |
|
| 272 | - return _T( |
|
| 273 | - 'erreur_technique_enregistrement_champs', |
|
| 274 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 275 | - ); |
|
| 276 | - } |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - // Invalider les caches |
|
| 280 | - if (isset($options['invalideur']) && $options['invalideur']) { |
|
| 281 | - include_spip('inc/invalideur'); |
|
| 282 | - if (is_array($options['invalideur'])) { |
|
| 283 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 284 | - } else { |
|
| 285 | - suivre_invalideur($options['invalideur']); |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - |
|
| 289 | - // Notifications, gestion des revisions... |
|
| 290 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 291 | - pipeline( |
|
| 292 | - 'post_edition', |
|
| 293 | - [ |
|
| 294 | - 'args' => [ |
|
| 295 | - 'table' => $spip_table_objet, |
|
| 296 | - 'table_objet' => $table_objet, |
|
| 297 | - 'spip_table_objet' => $spip_table_objet, |
|
| 298 | - 'desc' => $desc, |
|
| 299 | - 'type' => $objet, |
|
| 300 | - 'id_objet' => $id_objet, |
|
| 301 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 302 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 303 | - 'serveur' => $serveur, |
|
| 304 | - 'action' => $options['action'] ?? 'modifier' |
|
| 305 | - ], |
|
| 306 | - 'data' => $champs |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // Appeler une notification |
|
| 312 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 313 | - $notifications( |
|
| 314 | - "{$objet}_modifier", |
|
| 315 | - $id_objet, |
|
| 316 | - [ |
|
| 317 | - 'champs' => $champs, |
|
| 318 | - ] |
|
| 319 | - ); |
|
| 320 | - $notifications( |
|
| 321 | - 'objet_modifier', |
|
| 322 | - $id_objet, |
|
| 323 | - [ |
|
| 324 | - 'objet' => $objet, |
|
| 325 | - 'id_objet' => $id_objet, |
|
| 326 | - 'champs' => $champs, |
|
| 327 | - ] |
|
| 328 | - ); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // journaliser l'affaire |
|
| 332 | - // message a affiner :-) |
|
| 333 | - include_spip('inc/filtres_mini'); |
|
| 334 | - $qui = ''; |
|
| 335 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 336 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 337 | - } |
|
| 338 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 339 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 340 | - } |
|
| 341 | - if ($qui == '') { |
|
| 342 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 343 | - } |
|
| 344 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 345 | - '+', |
|
| 346 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 347 | - ) . ')'), [ |
|
| 348 | - 'faire' => 'modifier', |
|
| 349 | - 'quoi' => $objet, |
|
| 350 | - 'id' => $id_objet |
|
| 351 | - ]); |
|
| 352 | - |
|
| 353 | - return ''; |
|
| 99 | + if (!$id_objet = (int) $id_objet) { |
|
| 100 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 101 | + |
|
| 102 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + include_spip('inc/filtres'); |
|
| 106 | + |
|
| 107 | + $table_objet = table_objet($objet, $serveur); |
|
| 108 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 109 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 110 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 111 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 112 | + |
|
| 113 | + // Appels incomplets (sans $c) |
|
| 114 | + if (!is_array($c)) { |
|
| 115 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + |
|
| 117 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 121 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 122 | + // il faut passer par instituer_XX() |
|
| 123 | + // TODO: faut-il passer ces variables interdites |
|
| 124 | + // dans un fichier de description separe ? |
|
| 125 | + unset($c['statut']); |
|
| 126 | + unset($c['id_parent']); |
|
| 127 | + unset($c['id_rubrique']); |
|
| 128 | + unset($c['id_secteur']); |
|
| 129 | + |
|
| 130 | + // Gerer les champs non vides |
|
| 131 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 132 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 133 | + if (isset($c[$champ]) && $c[$champ] === '') { |
|
| 134 | + $c[$champ] = $sinon; |
|
| 135 | + } |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + |
|
| 139 | + // N'accepter que les champs qui existent dans la table |
|
| 140 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 141 | + // et dont la valeur n'est pas null |
|
| 142 | + $champs = array_filter($champs, static fn($var) => $var !== null); |
|
| 143 | + // TODO: ici aussi on peut valider les contenus |
|
| 144 | + // en fonction du type |
|
| 145 | + |
|
| 146 | + // Nettoyer les valeurs |
|
| 147 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 148 | + |
|
| 149 | + // On récupère l'état avant toute modification |
|
| 150 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 151 | + |
|
| 152 | + // Envoyer aux plugins |
|
| 153 | + $champs = pipeline( |
|
| 154 | + 'pre_edition', |
|
| 155 | + [ |
|
| 156 | + 'args' => [ |
|
| 157 | + 'table' => $spip_table_objet, // compatibilite |
|
| 158 | + 'table_objet' => $table_objet, |
|
| 159 | + 'spip_table_objet' => $spip_table_objet, |
|
| 160 | + 'desc' => $desc, |
|
| 161 | + 'type' => $objet, |
|
| 162 | + 'id_objet' => $id_objet, |
|
| 163 | + 'data' => $options['data'] ?? null, |
|
| 164 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 165 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 166 | + 'serveur' => $serveur, |
|
| 167 | + 'action' => $options['action'] ?? 'modifier' |
|
| 168 | + ], |
|
| 169 | + 'data' => $champs |
|
| 170 | + ] |
|
| 171 | + ); |
|
| 172 | + |
|
| 173 | + if (!$champs) { |
|
| 174 | + return false; |
|
| 175 | + } |
|
| 176 | + |
|
| 177 | + |
|
| 178 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 179 | + include_spip('inc/config'); |
|
| 180 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 181 | + include_spip('inc/drapeau_edition'); |
|
| 182 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 183 | + } |
|
| 184 | + |
|
| 185 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 186 | + include_spip('inc/editer'); |
|
| 187 | + if (!isset($options['data']) || is_null($options['data'])) { |
|
| 188 | + $options['data'] = &$_POST; |
|
| 189 | + } |
|
| 190 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 191 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 192 | + // et gere l'interface |
|
| 193 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 194 | + if ($conflits) { |
|
| 195 | + return _T('titre_conflit_edition'); |
|
| 196 | + } |
|
| 197 | + |
|
| 198 | + if ($champs) { |
|
| 199 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 200 | + if (isset($champs['lang'])) { |
|
| 201 | + if ($changer_lang = $champs['lang']) { |
|
| 202 | + $id_rubrique = 0; |
|
| 203 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 204 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 205 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 206 | + } |
|
| 207 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 208 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 209 | + } |
|
| 210 | + // on laisse 'lang' dans $champs, |
|
| 211 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 212 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 213 | + // deja pris en compte |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + // la modif peut avoir lieu |
|
| 217 | + |
|
| 218 | + // faut-il ajouter date_modif ? |
|
| 219 | + if ( |
|
| 220 | + !empty($options['date_modif']) && !isset($champs[$options['date_modif']]) |
|
| 221 | + ) { |
|
| 222 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + // allez on commit la modif |
|
| 226 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 227 | + |
|
| 228 | + // on verifie si elle est bien passee |
|
| 229 | + $moof = sql_fetsel( |
|
| 230 | + array_keys($champs), |
|
| 231 | + $spip_table_objet, |
|
| 232 | + "$id_table_objet=" . (int) $id_objet, |
|
| 233 | + [], |
|
| 234 | + [], |
|
| 235 | + '', |
|
| 236 | + [], |
|
| 237 | + $serveur |
|
| 238 | + ); |
|
| 239 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 240 | + if ($moof != $champs) { |
|
| 241 | + $liste = []; |
|
| 242 | + foreach ($moof as $k => $v) { |
|
| 243 | + if ( |
|
| 244 | + $v !== $champs[$k] |
|
| 245 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 246 | + && (!is_numeric($v) || (int) $v !== (int) $champs[$k]) |
|
| 247 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 248 | + && (strlen((string) $champs[$k]) || !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 249 | + ) { |
|
| 250 | + $liste[] = $k; |
|
| 251 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 252 | + $conflits[$k]['save'] = $v; |
|
| 253 | + |
|
| 254 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 255 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 256 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 257 | + include_spip('inc/charsets'); |
|
| 258 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 259 | + array_pop($liste); |
|
| 260 | + } |
|
| 261 | + } |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 265 | + // c'est un cas exceptionnel |
|
| 266 | + if ($liste !== []) { |
|
| 267 | + spip_log( |
|
| 268 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | + 'modifier.' . _LOG_CRITIQUE |
|
| 270 | + ); |
|
| 271 | + |
|
| 272 | + return _T( |
|
| 273 | + 'erreur_technique_enregistrement_champs', |
|
| 274 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + // Invalider les caches |
|
| 280 | + if (isset($options['invalideur']) && $options['invalideur']) { |
|
| 281 | + include_spip('inc/invalideur'); |
|
| 282 | + if (is_array($options['invalideur'])) { |
|
| 283 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 284 | + } else { |
|
| 285 | + suivre_invalideur($options['invalideur']); |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + |
|
| 289 | + // Notifications, gestion des revisions... |
|
| 290 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 291 | + pipeline( |
|
| 292 | + 'post_edition', |
|
| 293 | + [ |
|
| 294 | + 'args' => [ |
|
| 295 | + 'table' => $spip_table_objet, |
|
| 296 | + 'table_objet' => $table_objet, |
|
| 297 | + 'spip_table_objet' => $spip_table_objet, |
|
| 298 | + 'desc' => $desc, |
|
| 299 | + 'type' => $objet, |
|
| 300 | + 'id_objet' => $id_objet, |
|
| 301 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 302 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 303 | + 'serveur' => $serveur, |
|
| 304 | + 'action' => $options['action'] ?? 'modifier' |
|
| 305 | + ], |
|
| 306 | + 'data' => $champs |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // Appeler une notification |
|
| 312 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 313 | + $notifications( |
|
| 314 | + "{$objet}_modifier", |
|
| 315 | + $id_objet, |
|
| 316 | + [ |
|
| 317 | + 'champs' => $champs, |
|
| 318 | + ] |
|
| 319 | + ); |
|
| 320 | + $notifications( |
|
| 321 | + 'objet_modifier', |
|
| 322 | + $id_objet, |
|
| 323 | + [ |
|
| 324 | + 'objet' => $objet, |
|
| 325 | + 'id_objet' => $id_objet, |
|
| 326 | + 'champs' => $champs, |
|
| 327 | + ] |
|
| 328 | + ); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // journaliser l'affaire |
|
| 332 | + // message a affiner :-) |
|
| 333 | + include_spip('inc/filtres_mini'); |
|
| 334 | + $qui = ''; |
|
| 335 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 336 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 337 | + } |
|
| 338 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 339 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 340 | + } |
|
| 341 | + if ($qui == '') { |
|
| 342 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 343 | + } |
|
| 344 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 345 | + '+', |
|
| 346 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 347 | + ) . ')'), [ |
|
| 348 | + 'faire' => 'modifier', |
|
| 349 | + 'quoi' => $objet, |
|
| 350 | + 'id' => $id_objet |
|
| 351 | + ]); |
|
| 352 | + |
|
| 353 | + return ''; |
|
| 354 | 354 | } |
@@ -112,7 +112,7 @@ discard block |
||
| 112 | 112 | |
| 113 | 113 | // Appels incomplets (sans $c) |
| 114 | 114 | if (!is_array($c)) { |
| 115 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 115 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 116 | 116 | |
| 117 | 117 | return _T('erreur_technique_enregistrement_impossible'); |
| 118 | 118 | } |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | $champs = array_map('corriger_caracteres', $champs); |
| 148 | 148 | |
| 149 | 149 | // On récupère l'état avant toute modification |
| 150 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 150 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 151 | 151 | |
| 152 | 152 | // Envoyer aux plugins |
| 153 | 153 | $champs = pipeline( |
@@ -202,7 +202,7 @@ discard block |
||
| 202 | 202 | $id_rubrique = 0; |
| 203 | 203 | if (isset($desc['field']['id_rubrique'])) { |
| 204 | 204 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 205 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . (int) $id_objet); |
|
| 205 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".(int) $id_objet); |
|
| 206 | 206 | } |
| 207 | 207 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 208 | 208 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -223,13 +223,13 @@ discard block |
||
| 223 | 223 | } |
| 224 | 224 | |
| 225 | 225 | // allez on commit la modif |
| 226 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . (int) $id_objet, [], $serveur); |
|
| 226 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".(int) $id_objet, [], $serveur); |
|
| 227 | 227 | |
| 228 | 228 | // on verifie si elle est bien passee |
| 229 | 229 | $moof = sql_fetsel( |
| 230 | 230 | array_keys($champs), |
| 231 | 231 | $spip_table_objet, |
| 232 | - "$id_table_objet=" . (int) $id_objet, |
|
| 232 | + "$id_table_objet=".(int) $id_objet, |
|
| 233 | 233 | [], |
| 234 | 234 | [], |
| 235 | 235 | '', |
@@ -265,13 +265,13 @@ discard block |
||
| 265 | 265 | // c'est un cas exceptionnel |
| 266 | 266 | if ($liste !== []) { |
| 267 | 267 | spip_log( |
| 268 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 269 | - 'modifier.' . _LOG_CRITIQUE |
|
| 268 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 269 | + 'modifier.'._LOG_CRITIQUE |
|
| 270 | 270 | ); |
| 271 | 271 | |
| 272 | 272 | return _T( |
| 273 | 273 | 'erreur_technique_enregistrement_champs', |
| 274 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 274 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 275 | 275 | ); |
| 276 | 276 | } |
| 277 | 277 | } |
@@ -333,18 +333,18 @@ discard block |
||
| 333 | 333 | include_spip('inc/filtres_mini'); |
| 334 | 334 | $qui = ''; |
| 335 | 335 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 336 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 336 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 337 | 337 | } |
| 338 | 338 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 339 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 339 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 340 | 340 | } |
| 341 | 341 | if ($qui == '') { |
| 342 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 342 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 343 | 343 | } |
| 344 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . implode( |
|
| 344 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.implode( |
|
| 345 | 345 | '+', |
| 346 | 346 | array_diff(array_keys($champs), ['date_modif']) |
| 347 | - ) . ')'), [ |
|
| 347 | + ).')'), [ |
|
| 348 | 348 | 'faire' => 'modifier', |
| 349 | 349 | 'quoi' => $objet, |
| 350 | 350 | 'id' => $id_objet |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @package SPIP\Core\Drapeaux\Edition |
| 30 | 30 | **/ |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -44,46 +44,46 @@ discard block |
||
| 44 | 44 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 45 | 45 | **/ |
| 46 | 46 | function lire_tableau_edition() { |
| 47 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | - if (!$edition) { |
|
| 49 | - return []; |
|
| 50 | - } |
|
| 51 | - $changed = false; |
|
| 47 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | + if (!$edition) { |
|
| 49 | + return []; |
|
| 50 | + } |
|
| 51 | + $changed = false; |
|
| 52 | 52 | |
| 53 | - $bon_pour_le_service = time() - 3600; |
|
| 54 | - // parcourir le tableau et virer les vieux |
|
| 55 | - foreach ($edition as $objet => $data) { |
|
| 56 | - if (!is_array($data)) { |
|
| 57 | - unset($edition[$objet]); |
|
| 58 | - } // vieille version |
|
| 59 | - else { |
|
| 60 | - foreach ($data as $id => $tab) { |
|
| 61 | - if (!is_array($tab)) { |
|
| 62 | - unset($edition[$objet][$tab]); |
|
| 63 | - } // vieille version |
|
| 64 | - else { |
|
| 65 | - foreach ($tab as $n => $duo) { |
|
| 66 | - if (current($duo) < $bon_pour_le_service) { |
|
| 67 | - unset($edition[$objet][$id][$n]); |
|
| 68 | - $changed = true; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - if (!$edition[$objet][$id]) { |
|
| 73 | - unset($edition[$objet][$id]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if (!$edition[$objet]) { |
|
| 78 | - unset($edition[$objet]); |
|
| 79 | - } |
|
| 80 | - } |
|
| 53 | + $bon_pour_le_service = time() - 3600; |
|
| 54 | + // parcourir le tableau et virer les vieux |
|
| 55 | + foreach ($edition as $objet => $data) { |
|
| 56 | + if (!is_array($data)) { |
|
| 57 | + unset($edition[$objet]); |
|
| 58 | + } // vieille version |
|
| 59 | + else { |
|
| 60 | + foreach ($data as $id => $tab) { |
|
| 61 | + if (!is_array($tab)) { |
|
| 62 | + unset($edition[$objet][$tab]); |
|
| 63 | + } // vieille version |
|
| 64 | + else { |
|
| 65 | + foreach ($tab as $n => $duo) { |
|
| 66 | + if (current($duo) < $bon_pour_le_service) { |
|
| 67 | + unset($edition[$objet][$id][$n]); |
|
| 68 | + $changed = true; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + if (!$edition[$objet][$id]) { |
|
| 73 | + unset($edition[$objet][$id]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if (!$edition[$objet]) { |
|
| 78 | + unset($edition[$objet]); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if ($changed) { |
|
| 83 | - ecrire_tableau_edition($edition); |
|
| 84 | - } |
|
| 82 | + if ($changed) { |
|
| 83 | + ecrire_tableau_edition($edition); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $edition; |
|
| 86 | + return $edition; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 97 | 97 | **/ |
| 98 | 98 | function ecrire_tableau_edition($edition) { |
| 99 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 99 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -116,22 +116,22 @@ discard block |
||
| 116 | 116 | * Type d'objet édité |
| 117 | 117 | */ |
| 118 | 118 | function signale_edition($id, $auteur, $type = 'article') { |
| 119 | - include_spip('base/objets'); |
|
| 120 | - include_spip('inc/filtres'); |
|
| 121 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 119 | + include_spip('base/objets'); |
|
| 120 | + include_spip('inc/filtres'); |
|
| 121 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $edition = lire_tableau_edition(); |
|
| 125 | + $edition = lire_tableau_edition(); |
|
| 126 | 126 | |
| 127 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 127 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 129 | 129 | |
| 130 | - if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | - $edition[$type][$id] = []; |
|
| 132 | - } |
|
| 133 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | - ecrire_tableau_edition($edition); |
|
| 130 | + if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | + $edition[$type][$id] = []; |
|
| 132 | + } |
|
| 133 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | + ecrire_tableau_edition($edition); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function qui_edite($id, $type = 'article') { |
| 150 | 150 | |
| 151 | - $edition = lire_tableau_edition(); |
|
| 151 | + $edition = lire_tableau_edition(); |
|
| 152 | 152 | |
| 153 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 153 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -164,23 +164,23 @@ discard block |
||
| 164 | 164 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 165 | 165 | */ |
| 166 | 166 | function mention_qui_edite($id, $type = 'article'): array { |
| 167 | - $modif = qui_edite($id, $type); |
|
| 168 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 167 | + $modif = qui_edite($id, $type); |
|
| 168 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 169 | 169 | |
| 170 | - if ($modif) { |
|
| 171 | - $quand = 0; |
|
| 172 | - foreach ($modif as $duo) { |
|
| 173 | - $auteurs[] = typo(key($duo)); |
|
| 174 | - $quand = max($quand, current($duo)); |
|
| 175 | - } |
|
| 170 | + if ($modif) { |
|
| 171 | + $quand = 0; |
|
| 172 | + foreach ($modif as $duo) { |
|
| 173 | + $auteurs[] = typo(key($duo)); |
|
| 174 | + $quand = max($quand, current($duo)); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | - return [ |
|
| 179 | - 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | - ]; |
|
| 182 | - } |
|
| 183 | - return []; |
|
| 177 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | + return [ |
|
| 179 | + 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | + ]; |
|
| 182 | + } |
|
| 183 | + return []; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 195 | 195 | */ |
| 196 | 196 | function liste_drapeau_edition($id_auteur) { |
| 197 | - $edition = lire_tableau_edition(); |
|
| 198 | - $objets_ouverts = []; |
|
| 197 | + $edition = lire_tableau_edition(); |
|
| 198 | + $objets_ouverts = []; |
|
| 199 | 199 | |
| 200 | - foreach ($edition as $objet => $data) { |
|
| 201 | - foreach ($data as $id => $auteurs) { |
|
| 202 | - if ( |
|
| 203 | - isset($auteurs[$id_auteur]) |
|
| 204 | - && is_array($auteurs[$id_auteur]) |
|
| 205 | - && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | - ) { |
|
| 207 | - $objets_ouverts[] = [ |
|
| 208 | - 'objet' => $objet, |
|
| 209 | - 'id_objet' => $id, |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 200 | + foreach ($edition as $objet => $data) { |
|
| 201 | + foreach ($data as $id => $auteurs) { |
|
| 202 | + if ( |
|
| 203 | + isset($auteurs[$id_auteur]) |
|
| 204 | + && is_array($auteurs[$id_auteur]) |
|
| 205 | + && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | + ) { |
|
| 207 | + $objets_ouverts[] = [ |
|
| 208 | + 'objet' => $objet, |
|
| 209 | + 'id_objet' => $id, |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return $objets_ouverts; |
|
| 215 | + return $objets_ouverts; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * @return void |
| 226 | 226 | */ |
| 227 | 227 | function debloquer_tous($id_auteur) { |
| 228 | - $edition = lire_tableau_edition(); |
|
| 229 | - foreach ($edition as $objet => $data) { |
|
| 230 | - foreach ($data as $id => $auteurs) { |
|
| 231 | - if (isset($auteurs[$id_auteur])) { |
|
| 232 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | - ecrire_tableau_edition($edition); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 228 | + $edition = lire_tableau_edition(); |
|
| 229 | + foreach ($edition as $objet => $data) { |
|
| 230 | + foreach ($data as $id => $auteurs) { |
|
| 231 | + if (isset($auteurs[$id_auteur])) { |
|
| 232 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | + ecrire_tableau_edition($edition); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,19 +251,19 @@ discard block |
||
| 251 | 251 | * @return void |
| 252 | 252 | */ |
| 253 | 253 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 254 | - $edition = lire_tableau_edition(); |
|
| 254 | + $edition = lire_tableau_edition(); |
|
| 255 | 255 | |
| 256 | - foreach ($edition as $objet => $data) { |
|
| 257 | - if ($objet == $type) { |
|
| 258 | - foreach ($data as $id => $auteurs) { |
|
| 259 | - if ( |
|
| 260 | - $id == $id_objet |
|
| 261 | - && isset($auteurs[$id_auteur]) |
|
| 262 | - ) { |
|
| 263 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | - ecrire_tableau_edition($edition); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 256 | + foreach ($edition as $objet => $data) { |
|
| 257 | + if ($objet == $type) { |
|
| 258 | + foreach ($data as $id => $auteurs) { |
|
| 259 | + if ( |
|
| 260 | + $id == $id_objet |
|
| 261 | + && isset($auteurs[$id_auteur]) |
|
| 262 | + ) { |
|
| 263 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | + ecrire_tableau_edition($edition); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | */ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -29,12 +29,12 @@ discard block |
||
| 29 | 29 | * @return string |
| 30 | 30 | */ |
| 31 | 31 | function set_spip_doc(?string $fichier): string { |
| 32 | - if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 33 | - return substr($fichier, strlen((string) _DIR_IMG)); |
|
| 34 | - } else { |
|
| 35 | - // ex: fichier distant |
|
| 36 | - return $fichier ?? ''; |
|
| 37 | - } |
|
| 32 | + if ($fichier && str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 33 | + return substr($fichier, strlen((string) _DIR_IMG)); |
|
| 34 | + } else { |
|
| 35 | + // ex: fichier distant |
|
| 36 | + return $fichier ?? ''; |
|
| 37 | + } |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | /** |
@@ -46,26 +46,26 @@ discard block |
||
| 46 | 46 | * @return bool|string |
| 47 | 47 | */ |
| 48 | 48 | function get_spip_doc(?string $fichier) { |
| 49 | - if ($fichier === null) { |
|
| 50 | - return false; |
|
| 51 | - } |
|
| 52 | - |
|
| 53 | - // fichier distant |
|
| 54 | - if (tester_url_absolue($fichier)) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // gestion d'erreurs, fichier='' |
|
| 59 | - if (!strlen($fichier)) { |
|
| 60 | - return false; |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 64 | - $fichier = _DIR_IMG . $fichier; |
|
| 65 | - } |
|
| 66 | - |
|
| 67 | - // fichier normal |
|
| 68 | - return $fichier; |
|
| 49 | + if ($fichier === null) { |
|
| 50 | + return false; |
|
| 51 | + } |
|
| 52 | + |
|
| 53 | + // fichier distant |
|
| 54 | + if (tester_url_absolue($fichier)) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // gestion d'erreurs, fichier='' |
|
| 59 | + if (!strlen($fichier)) { |
|
| 60 | + return false; |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
|
| 64 | + $fichier = _DIR_IMG . $fichier; |
|
| 65 | + } |
|
| 66 | + |
|
| 67 | + // fichier normal |
|
| 68 | + return $fichier; |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | /** |
@@ -79,26 +79,26 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function creer_repertoire_documents($ext) { |
| 82 | - $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 83 | - |
|
| 84 | - if (!$ext || !$rep) { |
|
| 85 | - spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 86 | - exit; |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 90 | - // par exemple acces_restreint |
|
| 91 | - // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 92 | - if ( |
|
| 93 | - isset($GLOBALS['meta']['creer_htaccess']) |
|
| 94 | - && $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 95 | - && $ext !== 'logo' |
|
| 96 | - ) { |
|
| 97 | - include_spip('inc/acces'); |
|
| 98 | - verifier_htaccess($rep); |
|
| 99 | - } |
|
| 100 | - |
|
| 101 | - return $rep; |
|
| 82 | + $rep = sous_repertoire(_DIR_IMG, $ext); |
|
| 83 | + |
|
| 84 | + if (!$ext || !$rep) { |
|
| 85 | + spip_log("creer_repertoire_documents '$rep' interdit"); |
|
| 86 | + exit; |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 90 | + // par exemple acces_restreint |
|
| 91 | + // sauf pour logo/ utilise pour stocker les logoon et logooff |
|
| 92 | + if ( |
|
| 93 | + isset($GLOBALS['meta']['creer_htaccess']) |
|
| 94 | + && $GLOBALS['meta']['creer_htaccess'] == 'oui' |
|
| 95 | + && $ext !== 'logo' |
|
| 96 | + ) { |
|
| 97 | + include_spip('inc/acces'); |
|
| 98 | + verifier_htaccess($rep); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + return $rep; |
|
| 102 | 102 | } |
| 103 | 103 | |
| 104 | 104 | /** |
@@ -107,19 +107,19 @@ discard block |
||
| 107 | 107 | * @param string $nom |
| 108 | 108 | */ |
| 109 | 109 | function effacer_repertoire_temporaire($nom) { |
| 110 | - if ($d = opendir($nom)) { |
|
| 111 | - while (($f = readdir($d)) !== false) { |
|
| 112 | - if (is_file("$nom/$f")) { |
|
| 113 | - spip_unlink("$nom/$f"); |
|
| 114 | - } else { |
|
| 115 | - if ($f != '.' && $f != '..' && is_dir("$nom/$f")) { |
|
| 116 | - effacer_repertoire_temporaire("$nom/$f"); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - closedir($d); |
|
| 122 | - @rmdir($nom); |
|
| 110 | + if ($d = opendir($nom)) { |
|
| 111 | + while (($f = readdir($d)) !== false) { |
|
| 112 | + if (is_file("$nom/$f")) { |
|
| 113 | + spip_unlink("$nom/$f"); |
|
| 114 | + } else { |
|
| 115 | + if ($f != '.' && $f != '..' && is_dir("$nom/$f")) { |
|
| 116 | + effacer_repertoire_temporaire("$nom/$f"); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + closedir($d); |
|
| 122 | + @rmdir($nom); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | // |
@@ -136,44 +136,44 @@ discard block |
||
| 136 | 136 | */ |
| 137 | 137 | function copier_document($ext, $orig, $source, $subdir = null) { |
| 138 | 138 | |
| 139 | - $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 140 | - $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 141 | - |
|
| 142 | - $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 143 | - $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 144 | - $dest = translitteration($dest); |
|
| 145 | - $dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest); |
|
| 146 | - |
|
| 147 | - // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 148 | - // pour les images transformees par rotation (action/documenter) |
|
| 149 | - $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 150 | - |
|
| 151 | - while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 152 | - if ( |
|
| 153 | - !function_exists('verifier_upload_autorise') |
|
| 154 | - || !($r = verifier_upload_autorise($dest)) |
|
| 155 | - || !empty($r['autozip']) |
|
| 156 | - ) { |
|
| 157 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 158 | - break; |
|
| 159 | - } else { |
|
| 160 | - $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | - $ext = $m[1] . '.' . $ext; |
|
| 162 | - } |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | - return $source; |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | - $n = 0; |
|
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | - ; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - return deplacer_fichier_upload($source, $newFile); |
|
| 139 | + $orig = preg_replace(',\.\.+,', '.', $orig); // pas de .. dans le nom du doc |
|
| 140 | + $dir = creer_repertoire_documents($subdir ?: $ext); |
|
| 141 | + |
|
| 142 | + $dest = preg_replace('/<[^>]*>/', '', basename($orig)); |
|
| 143 | + $dest = preg_replace('/\.([^.]+)$/', '', $dest); |
|
| 144 | + $dest = translitteration($dest); |
|
| 145 | + $dest = preg_replace('/[^.=\w-]+/', '_', (string) $dest); |
|
| 146 | + |
|
| 147 | + // ne pas accepter de noms de la forme -r90.jpg qui sont reserves |
|
| 148 | + // pour les images transformees par rotation (action/documenter) |
|
| 149 | + $dest = preg_replace(',-r(90|180|270)$,', '', $dest); |
|
| 150 | + |
|
| 151 | + while (preg_match(',\.(\w+)$,', $dest, $m)) { |
|
| 152 | + if ( |
|
| 153 | + !function_exists('verifier_upload_autorise') |
|
| 154 | + || !($r = verifier_upload_autorise($dest)) |
|
| 155 | + || !empty($r['autozip']) |
|
| 156 | + ) { |
|
| 157 | + $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 158 | + break; |
|
| 159 | + } else { |
|
| 160 | + $dest = substr($dest, 0, -strlen($m[0])); |
|
| 161 | + $ext = $m[1] . '.' . $ext; |
|
| 162 | + } |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // Si le document "source" est deja au bon endroit, ne rien faire |
|
| 166 | + if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 167 | + return $source; |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + // sinon tourner jusqu'a trouver un numero correct |
|
| 171 | + $n = 0; |
|
| 172 | + while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 173 | + ; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + return deplacer_fichier_upload($source, $newFile); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | /** |
@@ -188,28 +188,28 @@ discard block |
||
| 188 | 188 | * @return bool|string |
| 189 | 189 | */ |
| 190 | 190 | function determine_upload($type = '') { |
| 191 | - if (!function_exists('autoriser')) { |
|
| 192 | - include_spip('inc/autoriser'); |
|
| 193 | - } |
|
| 194 | - |
|
| 195 | - if ( |
|
| 196 | - !autoriser('chargerftp') |
|
| 197 | - || $type == 'logos' |
|
| 198 | - ) { # on ne le permet pas pour les logos |
|
| 199 | - return false; |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $repertoire = _DIR_TRANSFERT; |
|
| 203 | - if (!@is_dir($repertoire)) { |
|
| 204 | - $repertoire = str_replace(_DIR_TMP, '', (string) $repertoire); |
|
| 205 | - $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | - return $repertoire; |
|
| 210 | - } else { |
|
| 211 | - return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | - } |
|
| 191 | + if (!function_exists('autoriser')) { |
|
| 192 | + include_spip('inc/autoriser'); |
|
| 193 | + } |
|
| 194 | + |
|
| 195 | + if ( |
|
| 196 | + !autoriser('chargerftp') |
|
| 197 | + || $type == 'logos' |
|
| 198 | + ) { # on ne le permet pas pour les logos |
|
| 199 | + return false; |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $repertoire = _DIR_TRANSFERT; |
|
| 203 | + if (!@is_dir($repertoire)) { |
|
| 204 | + $repertoire = str_replace(_DIR_TMP, '', (string) $repertoire); |
|
| 205 | + $repertoire = sous_repertoire(_DIR_TMP, $repertoire); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + if (!$GLOBALS['visiteur_session']['restreint']) { |
|
| 209 | + return $repertoire; |
|
| 210 | + } else { |
|
| 211 | + return sous_repertoire($repertoire, $GLOBALS['visiteur_session']['login']); |
|
| 212 | + } |
|
| 213 | 213 | } |
| 214 | 214 | |
| 215 | 215 | /** |
@@ -228,31 +228,31 @@ discard block |
||
| 228 | 228 | * @return bool|mixed|string |
| 229 | 229 | */ |
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | - // Securite |
|
| 232 | - if (str_starts_with($dest, (string) _DIR_RACINE)) { |
|
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | - } else { |
|
| 235 | - $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | - } |
|
| 237 | - |
|
| 238 | - $ok = $move ? @rename($source, $dest) : @copy($source, $dest); |
|
| 239 | - if (!$ok) { |
|
| 240 | - $ok = @move_uploaded_file($source, $dest); |
|
| 241 | - } |
|
| 242 | - if ($ok) { |
|
| 243 | - @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 244 | - } else { |
|
| 245 | - $f = @fopen($dest, 'w'); |
|
| 246 | - if ($f) { |
|
| 247 | - fclose($f); |
|
| 248 | - } else { |
|
| 249 | - include_spip('inc/flock'); |
|
| 250 | - raler_fichier($dest); |
|
| 251 | - } |
|
| 252 | - spip_unlink($dest); |
|
| 253 | - } |
|
| 254 | - |
|
| 255 | - return $ok ? $dest : false; |
|
| 231 | + // Securite |
|
| 232 | + if (str_starts_with($dest, (string) _DIR_RACINE)) { |
|
| 233 | + $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | + } else { |
|
| 235 | + $dest = preg_replace(',\.\.+,', '.', $dest); |
|
| 236 | + } |
|
| 237 | + |
|
| 238 | + $ok = $move ? @rename($source, $dest) : @copy($source, $dest); |
|
| 239 | + if (!$ok) { |
|
| 240 | + $ok = @move_uploaded_file($source, $dest); |
|
| 241 | + } |
|
| 242 | + if ($ok) { |
|
| 243 | + @chmod($dest, _SPIP_CHMOD & ~0111); |
|
| 244 | + } else { |
|
| 245 | + $f = @fopen($dest, 'w'); |
|
| 246 | + if ($f) { |
|
| 247 | + fclose($f); |
|
| 248 | + } else { |
|
| 249 | + include_spip('inc/flock'); |
|
| 250 | + raler_fichier($dest); |
|
| 251 | + } |
|
| 252 | + spip_unlink($dest); |
|
| 253 | + } |
|
| 254 | + |
|
| 255 | + return $ok ? $dest : false; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | |
@@ -276,60 +276,60 @@ discard block |
||
| 276 | 276 | */ |
| 277 | 277 | function check_upload_error($error, $msg = '', $return = false) { |
| 278 | 278 | |
| 279 | - if (!$error) { |
|
| 280 | - return false; |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 284 | - |
|
| 285 | - switch ($error) { |
|
| 286 | - case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 287 | - return true; |
|
| 288 | - |
|
| 289 | - # on peut affiner les differents messages d'erreur |
|
| 290 | - case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 291 | - $msg = _T( |
|
| 292 | - 'upload_limit', |
|
| 293 | - ['max' => ini_get('upload_max_filesize')] |
|
| 294 | - ); |
|
| 295 | - break; |
|
| 296 | - case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 297 | - $msg = _T( |
|
| 298 | - 'upload_limit', |
|
| 299 | - ['max' => ini_get('upload_max_filesize')] |
|
| 300 | - ); |
|
| 301 | - break; |
|
| 302 | - case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 303 | - $msg = _T( |
|
| 304 | - 'upload_limit', |
|
| 305 | - ['max' => ini_get('upload_max_filesize')] |
|
| 306 | - ); |
|
| 307 | - break; |
|
| 308 | - |
|
| 309 | - default: /* autre */ |
|
| 310 | - if (!$msg) { |
|
| 311 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | - } |
|
| 314 | - break; |
|
| 315 | - } |
|
| 316 | - |
|
| 317 | - spip_log("erreur upload $error"); |
|
| 318 | - if ($return) { |
|
| 319 | - return $msg; |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - if (_request('iframe') == 'iframe') { |
|
| 323 | - echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 324 | - exit; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - include_spip('inc/minipres'); |
|
| 328 | - echo minipres( |
|
| 329 | - $msg, |
|
| 330 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 331 | - ); |
|
| 332 | - exit; |
|
| 279 | + if (!$error) { |
|
| 280 | + return false; |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + spip_log("Erreur upload $error -- cf. http://php.net/manual/fr/features.file-upload.errors.php"); |
|
| 284 | + |
|
| 285 | + switch ($error) { |
|
| 286 | + case 4: /* UPLOAD_ERR_NO_FILE */ |
|
| 287 | + return true; |
|
| 288 | + |
|
| 289 | + # on peut affiner les differents messages d'erreur |
|
| 290 | + case 1: /* UPLOAD_ERR_INI_SIZE */ |
|
| 291 | + $msg = _T( |
|
| 292 | + 'upload_limit', |
|
| 293 | + ['max' => ini_get('upload_max_filesize')] |
|
| 294 | + ); |
|
| 295 | + break; |
|
| 296 | + case 2: /* UPLOAD_ERR_FORM_SIZE */ |
|
| 297 | + $msg = _T( |
|
| 298 | + 'upload_limit', |
|
| 299 | + ['max' => ini_get('upload_max_filesize')] |
|
| 300 | + ); |
|
| 301 | + break; |
|
| 302 | + case 3: /* UPLOAD_ERR_PARTIAL */ |
|
| 303 | + $msg = _T( |
|
| 304 | + 'upload_limit', |
|
| 305 | + ['max' => ini_get('upload_max_filesize')] |
|
| 306 | + ); |
|
| 307 | + break; |
|
| 308 | + |
|
| 309 | + default: /* autre */ |
|
| 310 | + if (!$msg) { |
|
| 311 | + $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | + . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | + } |
|
| 314 | + break; |
|
| 315 | + } |
|
| 316 | + |
|
| 317 | + spip_log("erreur upload $error"); |
|
| 318 | + if ($return) { |
|
| 319 | + return $msg; |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + if (_request('iframe') == 'iframe') { |
|
| 323 | + echo "<div class='upload_answer upload_error'>$msg</div>"; |
|
| 324 | + exit; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + include_spip('inc/minipres'); |
|
| 328 | + echo minipres( |
|
| 329 | + $msg, |
|
| 330 | + "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 331 | + ); |
|
| 332 | + exit; |
|
| 333 | 333 | } |
| 334 | 334 | |
| 335 | 335 | /** |
@@ -346,14 +346,14 @@ discard block |
||
| 346 | 346 | * @return string |
| 347 | 347 | */ |
| 348 | 348 | function corriger_extension($ext) { |
| 349 | - $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 350 | - |
|
| 351 | - return match ($ext) { |
|
| 352 | - 'htm' => 'html', |
|
| 353 | - 'jpeg' => 'jpg', |
|
| 354 | - 'tiff' => 'tif', |
|
| 355 | - 'aif' => 'aiff', |
|
| 356 | - 'mpeg' => 'mpg', |
|
| 357 | - default => $ext, |
|
| 358 | - }; |
|
| 349 | + $ext = preg_replace(',[^a-z0-9],i', '', $ext); |
|
| 350 | + |
|
| 351 | + return match ($ext) { |
|
| 352 | + 'htm' => 'html', |
|
| 353 | + 'jpeg' => 'jpg', |
|
| 354 | + 'tiff' => 'tif', |
|
| 355 | + 'aif' => 'aiff', |
|
| 356 | + 'mpeg' => 'mpg', |
|
| 357 | + default => $ext, |
|
| 358 | + }; |
|
| 359 | 359 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
| 64 | - $fichier = _DIR_IMG . $fichier; |
|
| 64 | + $fichier = _DIR_IMG.$fichier; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // fichier normal |
@@ -154,22 +154,22 @@ discard block |
||
| 154 | 154 | || !($r = verifier_upload_autorise($dest)) |
| 155 | 155 | || !empty($r['autozip']) |
| 156 | 156 | ) { |
| 157 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 157 | + $dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1]; |
|
| 158 | 158 | break; |
| 159 | 159 | } else { |
| 160 | 160 | $dest = substr($dest, 0, -strlen($m[0])); |
| 161 | - $ext = $m[1] . '.' . $ext; |
|
| 161 | + $ext = $m[1].'.'.$ext; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Si le document "source" est deja au bon endroit, ne rien faire |
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 166 | + if ($source == ($dir.$dest.'.'.$ext)) { |
|
| 167 | 167 | return $source; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // sinon tourner jusqu'a trouver un numero correct |
| 171 | 171 | $n = 0; |
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 172 | + while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) { |
|
| 173 | 173 | ; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | 231 | // Securite |
| 232 | 232 | if (str_starts_with($dest, (string) _DIR_RACINE)) { |
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 233 | + $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | 234 | } else { |
| 235 | 235 | $dest = preg_replace(',\.\.+,', '.', $dest); |
| 236 | 236 | } |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | default: /* autre */ |
| 310 | 310 | if (!$msg) { |
| 311 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 311 | + $msg = _T('pass_erreur').' '.$error |
|
| 312 | + . '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | 313 | } |
| 314 | 314 | break; |
| 315 | 315 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | include_spip('inc/minipres'); |
| 328 | 328 | echo minipres( |
| 329 | 329 | $msg, |
| 330 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 330 | + "<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode((string) $GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>' |
|
| 331 | 331 | ); |
| 332 | 332 | exit; |
| 333 | 333 | } |