@@ -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 | } |
@@ -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 | // Les parametres generaux du site sont dans une table SQL; |
@@ -26,51 +26,51 @@ discard block |
||
| 26 | 26 | define('_META_CACHE_TIME', 1 << 24); |
| 27 | 27 | |
| 28 | 28 | function inc_meta_dist($table = 'meta') { |
| 29 | - $new = null; |
|
| 30 | - // Lire les meta, en cache si present, valide et lisible |
|
| 31 | - // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 32 | - $cache = cache_meta($table); |
|
| 29 | + $new = null; |
|
| 30 | + // Lire les meta, en cache si present, valide et lisible |
|
| 31 | + // en cas d'install ne pas faire confiance au meta_cache eventuel |
|
| 32 | + $cache = cache_meta($table); |
|
| 33 | 33 | |
| 34 | - if ( |
|
| 35 | - (!($exec = _request('exec')) || !autoriser_sans_cookie($exec)) |
|
| 36 | - && ($new = jeune_fichier($cache, _META_CACHE_TIME)) |
|
| 37 | - && lire_fichier_securise($cache, $meta) |
|
| 38 | - && ($meta = @unserialize($meta)) |
|
| 39 | - ) { |
|
| 40 | - $GLOBALS[$table] = $meta; |
|
| 41 | - } |
|
| 34 | + if ( |
|
| 35 | + (!($exec = _request('exec')) || !autoriser_sans_cookie($exec)) |
|
| 36 | + && ($new = jeune_fichier($cache, _META_CACHE_TIME)) |
|
| 37 | + && lire_fichier_securise($cache, $meta) |
|
| 38 | + && ($meta = @unserialize($meta)) |
|
| 39 | + ) { |
|
| 40 | + $GLOBALS[$table] = $meta; |
|
| 41 | + } |
|
| 42 | 42 | |
| 43 | - if ( |
|
| 44 | - isset($GLOBALS[$table]['touch']) |
|
| 45 | - && $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME |
|
| 46 | - ) { |
|
| 47 | - $GLOBALS[$table] = []; |
|
| 48 | - } |
|
| 49 | - // sinon lire en base |
|
| 50 | - if (!$GLOBALS[$table]) { |
|
| 51 | - $new = !lire_metas($table); |
|
| 52 | - } |
|
| 43 | + if ( |
|
| 44 | + isset($GLOBALS[$table]['touch']) |
|
| 45 | + && $GLOBALS[$table]['touch'] < time() - _META_CACHE_TIME |
|
| 46 | + ) { |
|
| 47 | + $GLOBALS[$table] = []; |
|
| 48 | + } |
|
| 49 | + // sinon lire en base |
|
| 50 | + if (!$GLOBALS[$table]) { |
|
| 51 | + $new = !lire_metas($table); |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 55 | - if ( |
|
| 56 | - (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 57 | - && $GLOBALS[$table] |
|
| 58 | - && time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0) |
|
| 59 | - ) { |
|
| 60 | - // si on n'a pas l'acces en ecriture sur le cache, |
|
| 61 | - // ne pas renouveller l'alea sinon le cache devient faux |
|
| 62 | - if (supprimer_fichier($cache)) { |
|
| 63 | - include_spip('inc/acces'); |
|
| 64 | - renouvelle_alea(); |
|
| 65 | - $new = false; |
|
| 66 | - } else { |
|
| 67 | - spip_log("impossible d'ecrire dans " . $cache); |
|
| 68 | - } |
|
| 69 | - } |
|
| 70 | - // et refaire le cache si on a du lire en base |
|
| 71 | - if (!$new) { |
|
| 72 | - touch_meta(false, $table); |
|
| 73 | - } |
|
| 54 | + // renouveller l'alea general si trop vieux ou sur demande explicite |
|
| 55 | + if ( |
|
| 56 | + (test_espace_prive() || isset($_GET['renouvelle_alea'])) |
|
| 57 | + && $GLOBALS[$table] |
|
| 58 | + && time() > _RENOUVELLE_ALEA + ($GLOBALS['meta']['alea_ephemere_date'] ?? 0) |
|
| 59 | + ) { |
|
| 60 | + // si on n'a pas l'acces en ecriture sur le cache, |
|
| 61 | + // ne pas renouveller l'alea sinon le cache devient faux |
|
| 62 | + if (supprimer_fichier($cache)) { |
|
| 63 | + include_spip('inc/acces'); |
|
| 64 | + renouvelle_alea(); |
|
| 65 | + $new = false; |
|
| 66 | + } else { |
|
| 67 | + spip_log("impossible d'ecrire dans " . $cache); |
|
| 68 | + } |
|
| 69 | + } |
|
| 70 | + // et refaire le cache si on a du lire en base |
|
| 71 | + if (!$new) { |
|
| 72 | + touch_meta(false, $table); |
|
| 73 | + } |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | // fonctions aussi appelees a l'install ==> spip_query en premiere requete |
@@ -78,39 +78,39 @@ discard block |
||
| 78 | 78 | |
| 79 | 79 | function lire_metas($table = 'meta') { |
| 80 | 80 | |
| 81 | - if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 82 | - include_spip('base/abstract_sql'); |
|
| 83 | - $GLOBALS[$table] = []; |
|
| 84 | - while ($row = sql_fetch($result)) { |
|
| 85 | - $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 86 | - } |
|
| 87 | - sql_free($result); |
|
| 81 | + if ($result = spip_query("SELECT nom,valeur FROM spip_$table")) { |
|
| 82 | + include_spip('base/abstract_sql'); |
|
| 83 | + $GLOBALS[$table] = []; |
|
| 84 | + while ($row = sql_fetch($result)) { |
|
| 85 | + $GLOBALS[$table][$row['nom']] = $row['valeur']; |
|
| 86 | + } |
|
| 87 | + sql_free($result); |
|
| 88 | 88 | |
| 89 | - if ( |
|
| 90 | - !isset($GLOBALS[$table]['charset']) |
|
| 91 | - || !$GLOBALS[$table]['charset'] |
|
| 92 | - || $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 93 | - ) { |
|
| 94 | - ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 95 | - } |
|
| 89 | + if ( |
|
| 90 | + !isset($GLOBALS[$table]['charset']) |
|
| 91 | + || !$GLOBALS[$table]['charset'] |
|
| 92 | + || $GLOBALS[$table]['charset'] == '_DEFAULT_CHARSET' // hum, correction d'un bug ayant abime quelques install |
|
| 93 | + ) { |
|
| 94 | + ecrire_meta('charset', _DEFAULT_CHARSET, null, $table); |
|
| 95 | + } |
|
| 96 | 96 | |
| 97 | - // noter cette table de configuration dans les meta de SPIP |
|
| 98 | - if ($table !== 'meta') { |
|
| 99 | - $liste = []; |
|
| 100 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 101 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 102 | - } |
|
| 103 | - if (!$liste) { |
|
| 104 | - $liste = []; |
|
| 105 | - } |
|
| 106 | - if (!in_array($table, $liste)) { |
|
| 107 | - $liste[] = $table; |
|
| 108 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 109 | - } |
|
| 110 | - } |
|
| 111 | - } |
|
| 97 | + // noter cette table de configuration dans les meta de SPIP |
|
| 98 | + if ($table !== 'meta') { |
|
| 99 | + $liste = []; |
|
| 100 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 101 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 102 | + } |
|
| 103 | + if (!$liste) { |
|
| 104 | + $liste = []; |
|
| 105 | + } |
|
| 106 | + if (!in_array($table, $liste)) { |
|
| 107 | + $liste[] = $table; |
|
| 108 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 109 | + } |
|
| 110 | + } |
|
| 111 | + } |
|
| 112 | 112 | |
| 113 | - return $GLOBALS[$table] ?? null; |
|
| 113 | + return $GLOBALS[$table] ?? null; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -124,22 +124,22 @@ discard block |
||
| 124 | 124 | * Table SQL d'enregistrement des meta. |
| 125 | 125 | **/ |
| 126 | 126 | function touch_meta($antidate = false, $table = 'meta') { |
| 127 | - $file = cache_meta($table); |
|
| 128 | - if (!$antidate || !@touch($file, $antidate)) { |
|
| 129 | - $r = $GLOBALS[$table] ?? []; |
|
| 130 | - if ($table == 'meta') { |
|
| 131 | - unset($r['alea_ephemere']); |
|
| 132 | - unset($r['alea_ephemere_ancien']); |
|
| 133 | - // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 134 | - // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 135 | - // meme si son squelette est en cache |
|
| 136 | - //unset($r['secret_du_site']); |
|
| 137 | - if ($antidate) { |
|
| 138 | - $r['touch'] = $antidate; |
|
| 139 | - } |
|
| 140 | - } |
|
| 141 | - ecrire_fichier_securise($file, serialize($r)); |
|
| 142 | - } |
|
| 127 | + $file = cache_meta($table); |
|
| 128 | + if (!$antidate || !@touch($file, $antidate)) { |
|
| 129 | + $r = $GLOBALS[$table] ?? []; |
|
| 130 | + if ($table == 'meta') { |
|
| 131 | + unset($r['alea_ephemere']); |
|
| 132 | + unset($r['alea_ephemere_ancien']); |
|
| 133 | + // le secret du site est utilise pour encoder les contextes ajax que l'on considere fiables |
|
| 134 | + // mais le sortir deu cache meta implique une requete sql des qu'on a un form dynamique |
|
| 135 | + // meme si son squelette est en cache |
|
| 136 | + //unset($r['secret_du_site']); |
|
| 137 | + if ($antidate) { |
|
| 138 | + $r['touch'] = $antidate; |
|
| 139 | + } |
|
| 140 | + } |
|
| 141 | + ecrire_fichier_securise($file, serialize($r)); |
|
| 142 | + } |
|
| 143 | 143 | } |
| 144 | 144 | |
| 145 | 145 | /** |
@@ -155,21 +155,21 @@ discard block |
||
| 155 | 155 | * Table SQL d'enregistrement de la meta. |
| 156 | 156 | **/ |
| 157 | 157 | function effacer_meta($nom, $table = 'meta') { |
| 158 | - // section critique sur le cache: |
|
| 159 | - // l'invalider avant et apres la MAJ de la BD |
|
| 160 | - // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 161 | - // et utiliser une statique pour eviter des acces disques a repetition |
|
| 162 | - static $touch = []; |
|
| 163 | - $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 164 | - if (!isset($touch[$table])) { |
|
| 165 | - touch_meta($antidate, $table); |
|
| 166 | - } |
|
| 167 | - sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 168 | - unset($GLOBALS[$table][$nom]); |
|
| 169 | - if (!isset($touch[$table])) { |
|
| 170 | - touch_meta($antidate, $table); |
|
| 171 | - $touch[$table] = false; |
|
| 172 | - } |
|
| 158 | + // section critique sur le cache: |
|
| 159 | + // l'invalider avant et apres la MAJ de la BD |
|
| 160 | + // c'est un peu moins bien qu'un vrai verrou mais ca suffira |
|
| 161 | + // et utiliser une statique pour eviter des acces disques a repetition |
|
| 162 | + static $touch = []; |
|
| 163 | + $antidate = time() - (_META_CACHE_TIME << 4); |
|
| 164 | + if (!isset($touch[$table])) { |
|
| 165 | + touch_meta($antidate, $table); |
|
| 166 | + } |
|
| 167 | + sql_delete('spip_' . $table, "nom='$nom'", '', 'continue'); |
|
| 168 | + unset($GLOBALS[$table][$nom]); |
|
| 169 | + if (!isset($touch[$table])) { |
|
| 170 | + touch_meta($antidate, $table); |
|
| 171 | + $touch[$table] = false; |
|
| 172 | + } |
|
| 173 | 173 | } |
| 174 | 174 | |
| 175 | 175 | /** |
@@ -191,54 +191,54 @@ discard block |
||
| 191 | 191 | **/ |
| 192 | 192 | function ecrire_meta($nom, $valeur, $importable = null, $table = 'meta') { |
| 193 | 193 | |
| 194 | - static $touch = []; |
|
| 195 | - if (!$nom) { |
|
| 196 | - return; |
|
| 197 | - } |
|
| 198 | - include_spip('base/abstract_sql'); |
|
| 199 | - $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | - // table pas encore installee, travailler en php seulement |
|
| 201 | - if (!$res) { |
|
| 202 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 194 | + static $touch = []; |
|
| 195 | + if (!$nom) { |
|
| 196 | + return; |
|
| 197 | + } |
|
| 198 | + include_spip('base/abstract_sql'); |
|
| 199 | + $res = sql_select('*', 'spip_' . $table, 'nom=' . sql_quote($nom), '', '', '', '', '', 'continue'); |
|
| 200 | + // table pas encore installee, travailler en php seulement |
|
| 201 | + if (!$res) { |
|
| 202 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 203 | 203 | |
| 204 | - return; |
|
| 205 | - } |
|
| 206 | - $row = sql_fetch($res); |
|
| 207 | - sql_free($res); |
|
| 204 | + return; |
|
| 205 | + } |
|
| 206 | + $row = sql_fetch($res); |
|
| 207 | + sql_free($res); |
|
| 208 | 208 | |
| 209 | - // ne pas invalider le cache si affectation a l'identique |
|
| 210 | - // (tant pis si impt aurait du changer) |
|
| 211 | - if ( |
|
| 212 | - $row |
|
| 213 | - && $valeur == $row['valeur'] |
|
| 214 | - && isset($GLOBALS[$table][$nom]) |
|
| 215 | - && $GLOBALS[$table][$nom] == $valeur |
|
| 216 | - ) { |
|
| 217 | - return; |
|
| 218 | - } |
|
| 209 | + // ne pas invalider le cache si affectation a l'identique |
|
| 210 | + // (tant pis si impt aurait du changer) |
|
| 211 | + if ( |
|
| 212 | + $row |
|
| 213 | + && $valeur == $row['valeur'] |
|
| 214 | + && isset($GLOBALS[$table][$nom]) |
|
| 215 | + && $GLOBALS[$table][$nom] == $valeur |
|
| 216 | + ) { |
|
| 217 | + return; |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | - // cf effacer pour comprendre le double touch |
|
| 222 | - $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | - if (!isset($touch[$table])) { |
|
| 224 | - touch_meta($antidate, $table); |
|
| 225 | - } |
|
| 226 | - $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | - // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | - // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | - // de lecture des descriptions des tables |
|
| 230 | - if ($importable && isset($row['impt'])) { |
|
| 231 | - $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | - } |
|
| 233 | - if ($row) { |
|
| 234 | - sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | - } else { |
|
| 236 | - sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')'); |
|
| 237 | - } |
|
| 238 | - if (!isset($touch[$table])) { |
|
| 239 | - touch_meta($antidate, $table); |
|
| 240 | - $touch[$table] = false; |
|
| 241 | - } |
|
| 220 | + $GLOBALS[$table][$nom] = $valeur; |
|
| 221 | + // cf effacer pour comprendre le double touch |
|
| 222 | + $antidate = time() - (_META_CACHE_TIME << 1); |
|
| 223 | + if (!isset($touch[$table])) { |
|
| 224 | + touch_meta($antidate, $table); |
|
| 225 | + } |
|
| 226 | + $r = ['nom' => sql_quote($nom, '', 'text'), 'valeur' => sql_quote($valeur, '', 'text')]; |
|
| 227 | + // Gaffe aux tables sans impt (vieilles versions de SPIP notamment) |
|
| 228 | + // ici on utilise pas sql_updateq et sql_insertq pour ne pas provoquer trop tot |
|
| 229 | + // de lecture des descriptions des tables |
|
| 230 | + if ($importable && isset($row['impt'])) { |
|
| 231 | + $r['impt'] = sql_quote($importable, '', 'text'); |
|
| 232 | + } |
|
| 233 | + if ($row) { |
|
| 234 | + sql_update('spip_' . $table, $r, 'nom=' . sql_quote($nom)); |
|
| 235 | + } else { |
|
| 236 | + sql_insert('spip_' . $table, '(' . implode(',', array_keys($r)) . ')', '(' . implode(',', array_values($r)) . ')'); |
|
| 237 | + } |
|
| 238 | + if (!isset($touch[$table])) { |
|
| 239 | + touch_meta($antidate, $table); |
|
| 240 | + $touch[$table] = false; |
|
| 241 | + } |
|
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | /** |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | * Nom du fichier cache |
| 251 | 251 | **/ |
| 252 | 252 | function cache_meta($table = 'meta') { |
| 253 | - return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 253 | + return ($table == 'meta') ? _FILE_META : (_DIR_CACHE . $table . '.php'); |
|
| 254 | 254 | } |
| 255 | 255 | |
| 256 | 256 | /** |
@@ -259,14 +259,14 @@ discard block |
||
| 259 | 259 | * @param string $table |
| 260 | 260 | */ |
| 261 | 261 | function installer_table_meta($table) { |
| 262 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | - if (!$trouver_table("spip_$table")) { |
|
| 264 | - include_spip('base/auxiliaires'); |
|
| 265 | - include_spip('base/create'); |
|
| 266 | - creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | - $trouver_table(''); |
|
| 268 | - } |
|
| 269 | - lire_metas($table); |
|
| 262 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 263 | + if (!$trouver_table("spip_$table")) { |
|
| 264 | + include_spip('base/auxiliaires'); |
|
| 265 | + include_spip('base/create'); |
|
| 266 | + creer_ou_upgrader_table("spip_$table", $GLOBALS['tables_auxiliaires']['spip_meta'], false, false); |
|
| 267 | + $trouver_table(''); |
|
| 268 | + } |
|
| 269 | + lire_metas($table); |
|
| 270 | 270 | } |
| 271 | 271 | |
| 272 | 272 | /** |
@@ -278,44 +278,44 @@ discard block |
||
| 278 | 278 | * @param bool $force |
| 279 | 279 | */ |
| 280 | 280 | function supprimer_table_meta($table, $force = false) { |
| 281 | - if ($table !== 'meta') { |
|
| 282 | - // Vérifier le contenu restant de la table |
|
| 283 | - $nb_variables = sql_countsel("spip_$table"); |
|
| 281 | + if ($table !== 'meta') { |
|
| 282 | + // Vérifier le contenu restant de la table |
|
| 283 | + $nb_variables = sql_countsel("spip_$table"); |
|
| 284 | 284 | |
| 285 | - // Supprimer si : |
|
| 286 | - // - la table est vide |
|
| 287 | - // - ou limitée à la variable charset |
|
| 288 | - // - ou qu'on force la suppression |
|
| 289 | - if ( |
|
| 290 | - $force |
|
| 291 | - || !$nb_variables |
|
| 292 | - || $nb_variables == 1 && isset($GLOBALS[$table]['charset']) |
|
| 293 | - ) { |
|
| 294 | - // Supprimer la table des globaleset de la base |
|
| 295 | - unset($GLOBALS[$table]); |
|
| 296 | - sql_drop_table("spip_$table"); |
|
| 297 | - // Supprimer le fichier cache |
|
| 298 | - include_spip('inc/flock'); |
|
| 299 | - $cache = cache_meta($table); |
|
| 300 | - supprimer_fichier($cache); |
|
| 285 | + // Supprimer si : |
|
| 286 | + // - la table est vide |
|
| 287 | + // - ou limitée à la variable charset |
|
| 288 | + // - ou qu'on force la suppression |
|
| 289 | + if ( |
|
| 290 | + $force |
|
| 291 | + || !$nb_variables |
|
| 292 | + || $nb_variables == 1 && isset($GLOBALS[$table]['charset']) |
|
| 293 | + ) { |
|
| 294 | + // Supprimer la table des globaleset de la base |
|
| 295 | + unset($GLOBALS[$table]); |
|
| 296 | + sql_drop_table("spip_$table"); |
|
| 297 | + // Supprimer le fichier cache |
|
| 298 | + include_spip('inc/flock'); |
|
| 299 | + $cache = cache_meta($table); |
|
| 300 | + supprimer_fichier($cache); |
|
| 301 | 301 | |
| 302 | - // vider le cache des tables |
|
| 303 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | - $trouver_table(''); |
|
| 302 | + // vider le cache des tables |
|
| 303 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 304 | + $trouver_table(''); |
|
| 305 | 305 | |
| 306 | - // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 307 | - if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 308 | - $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 309 | - $cle = array_search($table, $liste); |
|
| 310 | - if ($cle !== false) { |
|
| 311 | - unset($liste[$cle]); |
|
| 312 | - if ($liste) { |
|
| 313 | - ecrire_meta('tables_config', serialize($liste)); |
|
| 314 | - } else { |
|
| 315 | - effacer_meta('tables_config'); |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - } |
|
| 319 | - } |
|
| 320 | - } |
|
| 306 | + // Supprimer la table de la liste des tables de configuration autres que spip_meta |
|
| 307 | + if (isset($GLOBALS['meta']['tables_config'])) { |
|
| 308 | + $liste = unserialize($GLOBALS['meta']['tables_config']); |
|
| 309 | + $cle = array_search($table, $liste); |
|
| 310 | + if ($cle !== false) { |
|
| 311 | + unset($liste[$cle]); |
|
| 312 | + if ($liste) { |
|
| 313 | + ecrire_meta('tables_config', serialize($liste)); |
|
| 314 | + } else { |
|
| 315 | + effacer_meta('tables_config'); |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + } |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | 321 | } |
@@ -19,19 +19,19 @@ |
||
| 19 | 19 | * Retourne la liste des menus favoris par défaut ainsi que leur rang |
| 20 | 20 | */ |
| 21 | 21 | function inc_definir_menus_favoris_dist() { |
| 22 | - return [ |
|
| 22 | + return [ |
|
| 23 | 23 | |
| 24 | - // Menu Édition, |
|
| 25 | - 'auteurs' => 1, |
|
| 26 | - 'rubriques' => 2, |
|
| 27 | - 'articles' => 3, |
|
| 24 | + // Menu Édition, |
|
| 25 | + 'auteurs' => 1, |
|
| 26 | + 'rubriques' => 2, |
|
| 27 | + 'articles' => 3, |
|
| 28 | 28 | |
| 29 | - // Menu Maintenance |
|
| 30 | - 'admin_vider' => 1, |
|
| 29 | + // Menu Maintenance |
|
| 30 | + 'admin_vider' => 1, |
|
| 31 | 31 | |
| 32 | - // Menu Configurations |
|
| 33 | - 'configurer_identite' => 1, |
|
| 34 | - 'admin_plugin' => 2, |
|
| 32 | + // Menu Configurations |
|
| 33 | + 'configurer_identite' => 1, |
|
| 34 | + 'admin_plugin' => 2, |
|
| 35 | 35 | |
| 36 | - ]; |
|
| 36 | + ]; |
|
| 37 | 37 | } |
@@ -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 | /** |
@@ -44,29 +44,29 @@ discard block |
||
| 44 | 44 | * sinon code HTML de la page après le traitement effectué. |
| 45 | 45 | **/ |
| 46 | 46 | function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) { |
| 47 | - $reprise = true; |
|
| 48 | - if ( |
|
| 49 | - !isset($GLOBALS['meta'][$script]) |
|
| 50 | - || !isset($GLOBALS['meta']['admin']) |
|
| 51 | - ) { |
|
| 52 | - $reprise = false; |
|
| 53 | - $res = debut_admin($script, $titre, $comment); |
|
| 54 | - if ($res) { |
|
| 55 | - return $res; |
|
| 56 | - } |
|
| 57 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | - ecrire_meta($script, serialize($_POST)); |
|
| 59 | - } |
|
| 47 | + $reprise = true; |
|
| 48 | + if ( |
|
| 49 | + !isset($GLOBALS['meta'][$script]) |
|
| 50 | + || !isset($GLOBALS['meta']['admin']) |
|
| 51 | + ) { |
|
| 52 | + $reprise = false; |
|
| 53 | + $res = debut_admin($script, $titre, $comment); |
|
| 54 | + if ($res) { |
|
| 55 | + return $res; |
|
| 56 | + } |
|
| 57 | + spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | + ecrire_meta($script, serialize($_POST)); |
|
| 59 | + } |
|
| 60 | 60 | |
| 61 | - $res = admin_verifie_session($script, $anonymous); |
|
| 62 | - if ($res) { |
|
| 63 | - return $res; |
|
| 64 | - } |
|
| 65 | - $base = charger_fonction($script, 'base'); |
|
| 66 | - $base($titre, $reprise); |
|
| 67 | - fin_admin($script); |
|
| 61 | + $res = admin_verifie_session($script, $anonymous); |
|
| 62 | + if ($res) { |
|
| 63 | + return $res; |
|
| 64 | + } |
|
| 65 | + $base = charger_fonction($script, 'base'); |
|
| 66 | + $base($titre, $reprise); |
|
| 67 | + fin_admin($script); |
|
| 68 | 68 | |
| 69 | - return ''; |
|
| 69 | + return ''; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -97,36 +97,36 @@ discard block |
||
| 97 | 97 | * Code HTML si message d'erreur, '' sinon; |
| 98 | 98 | */ |
| 99 | 99 | function admin_verifie_session($script, $anonymous = false) { |
| 100 | - include_spip('base/abstract_sql'); |
|
| 101 | - $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | - $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | - $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | - if ($valeur === null) { |
|
| 105 | - ecrire_meta('admin', $signal, 'non'); |
|
| 106 | - } else { |
|
| 107 | - if ( |
|
| 108 | - !$anonymous |
|
| 109 | - && $valeur != $signal |
|
| 110 | - && ( |
|
| 111 | - !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | - || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | - ) |
|
| 114 | - ) { |
|
| 115 | - include_spip('inc/minipres'); |
|
| 116 | - spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | - return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $journal = 'spip'; |
|
| 121 | - if (autoriser('configurer')) { |
|
| 122 | - // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | - $journal = 'webmestre'; |
|
| 124 | - } |
|
| 125 | - // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 100 | + include_spip('base/abstract_sql'); |
|
| 101 | + $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 102 | + $signal = fichier_admin($script, "$script$pref"); |
|
| 103 | + $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 104 | + if ($valeur === null) { |
|
| 105 | + ecrire_meta('admin', $signal, 'non'); |
|
| 106 | + } else { |
|
| 107 | + if ( |
|
| 108 | + !$anonymous |
|
| 109 | + && $valeur != $signal |
|
| 110 | + && ( |
|
| 111 | + !preg_match('/^(.*)_(\d+)_/', (string) $GLOBALS['meta']['admin'], $l) |
|
| 112 | + || (int) $l[2] != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 113 | + ) |
|
| 114 | + ) { |
|
| 115 | + include_spip('inc/minipres'); |
|
| 116 | + spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 117 | + return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $journal = 'spip'; |
|
| 121 | + if (autoriser('configurer')) { |
|
| 122 | + // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | + $journal = 'webmestre'; |
|
| 124 | + } |
|
| 125 | + // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Chemin du répertoire. |
| 140 | 140 | **/ |
| 141 | 141 | function dir_admin() { |
| 142 | - if (autoriser('configurer')) { |
|
| 143 | - return _DIR_TMP; |
|
| 144 | - } else { |
|
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | - } |
|
| 142 | + if (autoriser('configurer')) { |
|
| 143 | + return _DIR_TMP; |
|
| 144 | + } else { |
|
| 145 | + return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref . |
|
| 164 | + substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -187,76 +187,76 @@ discard block |
||
| 187 | 187 | * sinon chaîne vide si déjà fait. |
| 188 | 188 | **/ |
| 189 | 189 | function debut_admin($script, $action = '', $corps = '') { |
| 190 | - if ( |
|
| 191 | - !$action |
|
| 192 | - || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | - ) { |
|
| 194 | - include_spip('inc/minipres'); |
|
| 190 | + if ( |
|
| 191 | + !$action |
|
| 192 | + || !autoriser('webmestre') && !autoriser('chargerftp') |
|
| 193 | + ) { |
|
| 194 | + include_spip('inc/minipres'); |
|
| 195 | 195 | |
| 196 | - return minipres(); |
|
| 197 | - } else { |
|
| 198 | - $dir = dir_admin(); |
|
| 199 | - $signal = fichier_admin($script); |
|
| 200 | - if (@file_exists($dir . $signal)) { |
|
| 201 | - spip_log("Action admin: $action"); |
|
| 196 | + return minipres(); |
|
| 197 | + } else { |
|
| 198 | + $dir = dir_admin(); |
|
| 199 | + $signal = fichier_admin($script); |
|
| 200 | + if (@file_exists($dir . $signal)) { |
|
| 201 | + spip_log("Action admin: $action"); |
|
| 202 | 202 | |
| 203 | - return ''; |
|
| 204 | - } |
|
| 205 | - include_spip('inc/minipres'); |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | + include_spip('inc/minipres'); |
|
| 206 | 206 | |
| 207 | - // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | - // sauf dans les cas destroy |
|
| 209 | - if ( |
|
| 210 | - (autoriser('webmestre') || $script === 'repair') |
|
| 211 | - && $script != 'delete_all' |
|
| 212 | - ) { |
|
| 213 | - if (_request('validation_admin') == $signal) { |
|
| 214 | - spip_log("Action super-admin: $action"); |
|
| 207 | + // Si on est un super-admin, un bouton de validation suffit |
|
| 208 | + // sauf dans les cas destroy |
|
| 209 | + if ( |
|
| 210 | + (autoriser('webmestre') || $script === 'repair') |
|
| 211 | + && $script != 'delete_all' |
|
| 212 | + ) { |
|
| 213 | + if (_request('validation_admin') == $signal) { |
|
| 214 | + spip_log("Action super-admin: $action"); |
|
| 215 | 215 | |
| 216 | - return ''; |
|
| 217 | - } |
|
| 218 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | - $suivant = _T('bouton_valider'); |
|
| 220 | - $js = ''; |
|
| 221 | - } else { |
|
| 222 | - // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | - // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | - // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | - $corps .= http_script('', 'spip_barre.js'); |
|
| 216 | + return ''; |
|
| 217 | + } |
|
| 218 | + $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 219 | + $suivant = _T('bouton_valider'); |
|
| 220 | + $js = ''; |
|
| 221 | + } else { |
|
| 222 | + // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 223 | + // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 224 | + // mais evite de l'embarquer dans toutes les pages minipres |
|
| 225 | + $corps .= http_script('', 'spip_barre.js'); |
|
| 226 | 226 | |
| 227 | - $corps .= '<fieldset><legend>' |
|
| 228 | - . _T('info_authentification_ftp') |
|
| 229 | - . aider('ftp_auth') |
|
| 230 | - . "</legend>\n<label for='fichier'>" |
|
| 231 | - . _T('info_creer_repertoire') |
|
| 232 | - . "</label>\n" |
|
| 233 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | - . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | - . $signal |
|
| 236 | - . "' />" |
|
| 237 | - . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | - . '</fieldset>'; |
|
| 227 | + $corps .= '<fieldset><legend>' |
|
| 228 | + . _T('info_authentification_ftp') |
|
| 229 | + . aider('ftp_auth') |
|
| 230 | + . "</legend>\n<label for='fichier'>" |
|
| 231 | + . _T('info_creer_repertoire') |
|
| 232 | + . "</label>\n" |
|
| 233 | + . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 234 | + . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 235 | + . $signal |
|
| 236 | + . "' />" |
|
| 237 | + . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 238 | + . '</fieldset>'; |
|
| 239 | 239 | |
| 240 | - $suivant = _T('bouton_recharger_page'); |
|
| 240 | + $suivant = _T('bouton_recharger_page'); |
|
| 241 | 241 | |
| 242 | - // code volontairement tordu: |
|
| 243 | - // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | - // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | - // de JavaScript inactif. |
|
| 246 | - $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | - } |
|
| 242 | + // code volontairement tordu: |
|
| 243 | + // provoquer la copie dans le presse papier du nom du repertoire |
|
| 244 | + // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 245 | + // de JavaScript inactif. |
|
| 246 | + $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 247 | + } |
|
| 248 | 248 | |
| 249 | - // admin/xxx correspond |
|
| 250 | - // a exec/base_xxx de preference |
|
| 251 | - // et exec/xxx sinon (compat) |
|
| 252 | - if (tester_url_ecrire("base_$script")) { |
|
| 253 | - $script = "base_$script"; |
|
| 254 | - } |
|
| 255 | - $form = copy_request($script, $corps, $suivant); |
|
| 256 | - $info_action = _T('info_action', ['action' => "$action"]); |
|
| 249 | + // admin/xxx correspond |
|
| 250 | + // a exec/base_xxx de preference |
|
| 251 | + // et exec/xxx sinon (compat) |
|
| 252 | + if (tester_url_ecrire("base_$script")) { |
|
| 253 | + $script = "base_$script"; |
|
| 254 | + } |
|
| 255 | + $form = copy_request($script, $corps, $suivant); |
|
| 256 | + $info_action = _T('info_action', ['action' => "$action"]); |
|
| 257 | 257 | |
| 258 | - return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | - } |
|
| 258 | + return minipres($info_action, $form, ['onload' => $js]); |
|
| 259 | + } |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | /** |
@@ -267,13 +267,13 @@ discard block |
||
| 267 | 267 | * Nom de l'action (en base) qui a été exécutée |
| 268 | 268 | **/ |
| 269 | 269 | function fin_admin($action) { |
| 270 | - $signal = dir_admin() . fichier_admin($action); |
|
| 271 | - spip_unlink($signal); |
|
| 272 | - if ($action != 'delete_all') { |
|
| 273 | - effacer_meta($action); |
|
| 274 | - effacer_meta('admin'); |
|
| 275 | - spip_log("efface les meta admin et $action "); |
|
| 276 | - } |
|
| 270 | + $signal = dir_admin() . fichier_admin($action); |
|
| 271 | + spip_unlink($signal); |
|
| 272 | + if ($action != 'delete_all') { |
|
| 273 | + effacer_meta($action); |
|
| 274 | + effacer_meta('admin'); |
|
| 275 | + spip_log("efface les meta admin et $action "); |
|
| 276 | + } |
|
| 277 | 277 | } |
| 278 | 278 | |
| 279 | 279 | /** |
@@ -292,14 +292,14 @@ discard block |
||
| 292 | 292 | * Code HTML du formulaire |
| 293 | 293 | **/ |
| 294 | 294 | function copy_request($script, $suite, $submit = '') { |
| 295 | - include_spip('inc/filtres'); |
|
| 296 | - foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | - if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | - entites_html($c) . |
|
| 300 | - "' />"; |
|
| 301 | - } |
|
| 302 | - } |
|
| 295 | + include_spip('inc/filtres'); |
|
| 296 | + foreach ([...$_POST, ...$_GET] as $n => $c) { |
|
| 297 | + if (!in_array($n, ['fichier', 'exec', 'validation_admin']) && !is_array($c)) { |
|
| 298 | + $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 299 | + entites_html($c) . |
|
| 300 | + "' />"; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | 303 | |
| 304 | - return generer_form_ecrire($script, $suite, '', $submit); |
|
| 304 | + return generer_form_ecrire($script, $suite, '', $submit); |
|
| 305 | 305 | } |
@@ -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/autoriser'); // necessaire si appel de l'espace public |
@@ -44,66 +44,66 @@ discard block |
||
| 44 | 44 | **/ |
| 45 | 45 | function precharger_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 46 | 46 | |
| 47 | - $row = []; |
|
| 48 | - $table = table_objet_sql($type); |
|
| 49 | - $_id_objet = id_table_objet($table); |
|
| 50 | - |
|
| 51 | - // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | - if (is_numeric($id_objet)) { |
|
| 53 | - return sql_fetsel('*', $table, "$_id_objet=" . (int) $id_objet); |
|
| 54 | - } |
|
| 55 | - |
|
| 56 | - // ici, on demande une creation. |
|
| 57 | - // on prerempli certains elements : les champs si traduction, |
|
| 58 | - // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | - $desc = lister_tables_objets_sql($table); |
|
| 60 | - # il faudrait calculer $champ_titre ici |
|
| 61 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | - $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | - |
|
| 64 | - // si demande de traduction |
|
| 65 | - // on recupere les valeurs de la traduction |
|
| 66 | - if ($lier_trad) { |
|
| 67 | - if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 68 | - $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | - } else { |
|
| 70 | - $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | - } |
|
| 72 | - } else { |
|
| 73 | - $row[$champ_titre] = ''; |
|
| 74 | - if ($is_rubrique) { |
|
| 75 | - $row['id_rubrique'] = $id_rubrique; |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - |
|
| 79 | - // calcul de la rubrique |
|
| 80 | - # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | - // appel du script a la racine, faut choisir |
|
| 82 | - // admin restreint ==> sa premiere rubrique |
|
| 83 | - // autre ==> la derniere rubrique cree |
|
| 84 | - if ($is_rubrique && !$row['id_rubrique']) { |
|
| 85 | - if ($GLOBALS['connect_id_rubrique']) { |
|
| 86 | - $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 87 | - } else { |
|
| 88 | - $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 89 | - $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 90 | - } |
|
| 91 | - if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 92 | - // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 93 | - $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 94 | - while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 95 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - // recuperer le secteur, pour affecter les bons champs extras |
|
| 101 | - if ($id_rubrique && $is_secteur && !$row['id_secteur']) { |
|
| 102 | - $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 103 | - $row['id_secteur'] = $row_rub; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $row; |
|
| 47 | + $row = []; |
|
| 48 | + $table = table_objet_sql($type); |
|
| 49 | + $_id_objet = id_table_objet($table); |
|
| 50 | + |
|
| 51 | + // si l'objet existe deja, on retourne simplement ses valeurs |
|
| 52 | + if (is_numeric($id_objet)) { |
|
| 53 | + return sql_fetsel('*', $table, "$_id_objet=" . (int) $id_objet); |
|
| 54 | + } |
|
| 55 | + |
|
| 56 | + // ici, on demande une creation. |
|
| 57 | + // on prerempli certains elements : les champs si traduction, |
|
| 58 | + // les id_rubrique et id_secteur si l'objet a ces champs |
|
| 59 | + $desc = lister_tables_objets_sql($table); |
|
| 60 | + # il faudrait calculer $champ_titre ici |
|
| 61 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 62 | + $is_secteur = isset($desc['field']['id_secteur']); |
|
| 63 | + |
|
| 64 | + // si demande de traduction |
|
| 65 | + // on recupere les valeurs de la traduction |
|
| 66 | + if ($lier_trad) { |
|
| 67 | + if ($select = charger_fonction('precharger_traduction_' . $type, 'inc', true)) { |
|
| 68 | + $row = $select($id_objet, $id_rubrique, $lier_trad); |
|
| 69 | + } else { |
|
| 70 | + $row = precharger_traduction_objet($type, $id_objet, $id_rubrique, $lier_trad, $champ_titre); |
|
| 71 | + } |
|
| 72 | + } else { |
|
| 73 | + $row[$champ_titre] = ''; |
|
| 74 | + if ($is_rubrique) { |
|
| 75 | + $row['id_rubrique'] = $id_rubrique; |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + |
|
| 79 | + // calcul de la rubrique |
|
| 80 | + # note : comment faire pour des traductions sur l'objet rubriques ? |
|
| 81 | + // appel du script a la racine, faut choisir |
|
| 82 | + // admin restreint ==> sa premiere rubrique |
|
| 83 | + // autre ==> la derniere rubrique cree |
|
| 84 | + if ($is_rubrique && !$row['id_rubrique']) { |
|
| 85 | + if ($GLOBALS['connect_id_rubrique']) { |
|
| 86 | + $row['id_rubrique'] = $id_rubrique = current($GLOBALS['connect_id_rubrique']); |
|
| 87 | + } else { |
|
| 88 | + $row_rub = sql_fetsel('id_rubrique', 'spip_rubriques', '', '', 'id_rubrique DESC', 1); |
|
| 89 | + $row['id_rubrique'] = $id_rubrique = $row_rub['id_rubrique']; |
|
| 90 | + } |
|
| 91 | + if (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique'])) { |
|
| 92 | + // manque de chance, la rubrique n'est pas autorisee, on cherche un des secteurs autorises |
|
| 93 | + $res = sql_select('id_rubrique', 'spip_rubriques', 'id_parent=0'); |
|
| 94 | + while (!autoriser('creerarticledans', 'rubrique', $row['id_rubrique']) && $row_rub = sql_fetch($res)) { |
|
| 95 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + // recuperer le secteur, pour affecter les bons champs extras |
|
| 101 | + if ($id_rubrique && $is_secteur && !$row['id_secteur']) { |
|
| 102 | + $row_rub = sql_getfetsel('id_secteur', 'spip_rubriques', 'id_rubrique=' . sql_quote($id_rubrique)); |
|
| 103 | + $row['id_secteur'] = $row_rub; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $row; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | |
@@ -125,78 +125,78 @@ discard block |
||
| 125 | 125 | * Couples clés / valeurs des champs du formulaire à charger |
| 126 | 126 | **/ |
| 127 | 127 | function precharger_traduction_objet($type, $id_objet, $id_rubrique = 0, $lier_trad = 0, $champ_titre = 'titre') { |
| 128 | - $table = table_objet_sql($type); |
|
| 129 | - $_id_objet = id_table_objet($table); |
|
| 130 | - |
|
| 131 | - // Recuperer les donnees de l'objet original |
|
| 132 | - $row = sql_fetsel('*', $table, "$_id_objet=" . (int) $lier_trad); |
|
| 133 | - if ($row) { |
|
| 134 | - include_spip('inc/filtres'); |
|
| 135 | - $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 136 | - } else { |
|
| 137 | - $row = []; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // on met l'objet dans une rubrique si l'objet le peut |
|
| 141 | - $desc = lister_tables_objets_sql($table); |
|
| 142 | - $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 143 | - |
|
| 144 | - if ($is_rubrique) { |
|
| 145 | - $langues_dispo = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 146 | - // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 147 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo) && $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 148 | - $row['lang'] = $GLOBALS['spip_lang']; |
|
| 149 | - } |
|
| 150 | - // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 151 | - elseif (count($langues_dispo) == 2) { |
|
| 152 | - $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 153 | - if (count($autre_langue) == 1) { |
|
| 154 | - $row['lang'] = reset($autre_langue); |
|
| 155 | - } |
|
| 156 | - } |
|
| 157 | - else { |
|
| 158 | - $row['lang'] = 'en'; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if ($id_rubrique) { |
|
| 162 | - $row['id_rubrique'] = $id_rubrique; |
|
| 163 | - |
|
| 164 | - return $row; |
|
| 165 | - } |
|
| 166 | - $id_rubrique = $row['id_rubrique']; |
|
| 167 | - |
|
| 168 | - |
|
| 169 | - // Regler la langue, si possible, sur celle du redacteur |
|
| 170 | - // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 171 | - if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 172 | - // Si le menu de langues est autorise sur l'objet, |
|
| 173 | - // on peut changer la langue quelle que soit la rubrique |
|
| 174 | - // donc on reste dans la meme rubrique |
|
| 175 | - if (in_array($table, explode(',', (string) $GLOBALS['meta']['multi_objets']))) { |
|
| 176 | - $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 177 | - |
|
| 178 | - // Sinon, chercher la rubrique la plus adaptee pour |
|
| 179 | - // accueillir l'objet dans la langue du traducteur |
|
| 180 | - } elseif ($is_rubrique && $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 181 | - if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 182 | - $id_parent = 0; |
|
| 183 | - } else { |
|
| 184 | - // on cherche une rubrique soeur dans la bonne langue |
|
| 185 | - $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 186 | - $id_parent = $row_rub['id_parent']; |
|
| 187 | - } |
|
| 188 | - |
|
| 189 | - $row_rub = sql_fetsel( |
|
| 190 | - 'id_rubrique', |
|
| 191 | - 'spip_rubriques', |
|
| 192 | - "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . (int) $id_parent |
|
| 193 | - ); |
|
| 194 | - if ($row_rub) { |
|
| 195 | - $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - return $row; |
|
| 128 | + $table = table_objet_sql($type); |
|
| 129 | + $_id_objet = id_table_objet($table); |
|
| 130 | + |
|
| 131 | + // Recuperer les donnees de l'objet original |
|
| 132 | + $row = sql_fetsel('*', $table, "$_id_objet=" . (int) $lier_trad); |
|
| 133 | + if ($row) { |
|
| 134 | + include_spip('inc/filtres'); |
|
| 135 | + $row[$champ_titre] = filtrer_entites(objet_T($type, 'info_nouvelle_traduction')) . ' ' . $row[$champ_titre]; |
|
| 136 | + } else { |
|
| 137 | + $row = []; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // on met l'objet dans une rubrique si l'objet le peut |
|
| 141 | + $desc = lister_tables_objets_sql($table); |
|
| 142 | + $is_rubrique = isset($desc['field']['id_rubrique']); |
|
| 143 | + |
|
| 144 | + if ($is_rubrique) { |
|
| 145 | + $langues_dispo = explode(',', (string) $GLOBALS['meta']['langues_multilingue']); |
|
| 146 | + // si le redacteur utilise une autre langue que celle de la source, on suppose que c'est pour traduire dans sa langue |
|
| 147 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo) && $GLOBALS['spip_lang'] !== $row['lang']) { |
|
| 148 | + $row['lang'] = $GLOBALS['spip_lang']; |
|
| 149 | + } |
|
| 150 | + // sinon si il y a seulement 2 langues dispos, on bascule sur l'"autre" |
|
| 151 | + elseif (count($langues_dispo) == 2) { |
|
| 152 | + $autre_langue = array_diff($langues_dispo, [$row['lang']]); |
|
| 153 | + if (count($autre_langue) == 1) { |
|
| 154 | + $row['lang'] = reset($autre_langue); |
|
| 155 | + } |
|
| 156 | + } |
|
| 157 | + else { |
|
| 158 | + $row['lang'] = 'en'; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if ($id_rubrique) { |
|
| 162 | + $row['id_rubrique'] = $id_rubrique; |
|
| 163 | + |
|
| 164 | + return $row; |
|
| 165 | + } |
|
| 166 | + $id_rubrique = $row['id_rubrique']; |
|
| 167 | + |
|
| 168 | + |
|
| 169 | + // Regler la langue, si possible, sur celle du redacteur |
|
| 170 | + // Cela implique souvent de choisir une rubrique ou un secteur |
|
| 171 | + if (in_array($GLOBALS['spip_lang'], $langues_dispo)) { |
|
| 172 | + // Si le menu de langues est autorise sur l'objet, |
|
| 173 | + // on peut changer la langue quelle que soit la rubrique |
|
| 174 | + // donc on reste dans la meme rubrique |
|
| 175 | + if (in_array($table, explode(',', (string) $GLOBALS['meta']['multi_objets']))) { |
|
| 176 | + $row['id_rubrique'] = $row['id_rubrique']; # explicite :-) |
|
| 177 | + |
|
| 178 | + // Sinon, chercher la rubrique la plus adaptee pour |
|
| 179 | + // accueillir l'objet dans la langue du traducteur |
|
| 180 | + } elseif ($is_rubrique && $GLOBALS['meta']['multi_rubriques'] == 'oui') { |
|
| 181 | + if ($GLOBALS['meta']['multi_secteurs'] == 'oui') { |
|
| 182 | + $id_parent = 0; |
|
| 183 | + } else { |
|
| 184 | + // on cherche une rubrique soeur dans la bonne langue |
|
| 185 | + $row_rub = sql_fetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 186 | + $id_parent = $row_rub['id_parent']; |
|
| 187 | + } |
|
| 188 | + |
|
| 189 | + $row_rub = sql_fetsel( |
|
| 190 | + 'id_rubrique', |
|
| 191 | + 'spip_rubriques', |
|
| 192 | + "lang='" . $GLOBALS['spip_lang'] . "' AND id_parent=" . (int) $id_parent |
|
| 193 | + ); |
|
| 194 | + if ($row_rub) { |
|
| 195 | + $row['id_rubrique'] = $row_rub['id_rubrique']; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + return $row; |
|
| 202 | 202 | } |
@@ -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 | |
@@ -46,24 +46,24 @@ discard block |
||
| 46 | 46 | * - false si l'arbre xml ne peut être créé ou est vide |
| 47 | 47 | **/ |
| 48 | 48 | function spip_xml_load($fichier, $strict = true, $clean = true, $taille_max = 1_048_576, $datas = '', $profondeur = -1) { |
| 49 | - $contenu = ''; |
|
| 50 | - if (tester_url_absolue($fichier)) { |
|
| 51 | - include_spip('inc/distant'); |
|
| 52 | - $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | - $contenu = $contenu['page'] ?? ''; |
|
| 54 | - } else { |
|
| 55 | - lire_fichier($fichier, $contenu); |
|
| 56 | - } |
|
| 57 | - $arbre = []; |
|
| 58 | - if ($contenu) { |
|
| 59 | - $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | - } |
|
| 49 | + $contenu = ''; |
|
| 50 | + if (tester_url_absolue($fichier)) { |
|
| 51 | + include_spip('inc/distant'); |
|
| 52 | + $contenu = recuperer_url($fichier, ['taille_max' => $taille_max, 'datas' => $datas]); |
|
| 53 | + $contenu = $contenu['page'] ?? ''; |
|
| 54 | + } else { |
|
| 55 | + lire_fichier($fichier, $contenu); |
|
| 56 | + } |
|
| 57 | + $arbre = []; |
|
| 58 | + if ($contenu) { |
|
| 59 | + $arbre = spip_xml_parse($contenu, $strict, $clean, $profondeur); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - return count($arbre) ? $arbre : false; |
|
| 62 | + return count($arbre) ? $arbre : false; |
|
| 63 | 63 | } |
| 64 | 64 | |
| 65 | 65 | if (!defined('_SPIP_XML_TAG_SPLIT')) { |
| 66 | - define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 66 | + define('_SPIP_XML_TAG_SPLIT', '{<([^:>][^>]*?)>}sS'); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -82,150 +82,150 @@ discard block |
||
| 82 | 82 | * - false si l'arbre xml ne peut être créé ou est vide |
| 83 | 83 | **/ |
| 84 | 84 | function spip_xml_parse(&$texte, $strict = true, $clean = true, $profondeur = -1) { |
| 85 | - $out = []; |
|
| 86 | - // enlever les commentaires |
|
| 87 | - $charset = 'AUTO'; |
|
| 88 | - if ($clean) { |
|
| 89 | - if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | - $charset = $regs[2]; |
|
| 91 | - } |
|
| 92 | - $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | - $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | - include_spip('inc/charsets'); |
|
| 95 | - $clean = $charset; |
|
| 96 | - //$texte = importer_charset($texte,$charset); |
|
| 97 | - } |
|
| 98 | - if (is_string($clean)) { |
|
| 99 | - $charset = $clean; |
|
| 100 | - } |
|
| 101 | - $txt = $texte; |
|
| 85 | + $out = []; |
|
| 86 | + // enlever les commentaires |
|
| 87 | + $charset = 'AUTO'; |
|
| 88 | + if ($clean) { |
|
| 89 | + if (preg_match(",<\?xml\s(.*?)encoding=['\"]?(.*?)['\"]?(\s(.*))?\?>,im", $texte, $regs)) { |
|
| 90 | + $charset = $regs[2]; |
|
| 91 | + } |
|
| 92 | + $texte = preg_replace(',<!--(.*?)-->,is', '', $texte); |
|
| 93 | + $texte = preg_replace(',<\?(.*?)\?>,is', '', $texte); |
|
| 94 | + include_spip('inc/charsets'); |
|
| 95 | + $clean = $charset; |
|
| 96 | + //$texte = importer_charset($texte,$charset); |
|
| 97 | + } |
|
| 98 | + if (is_string($clean)) { |
|
| 99 | + $charset = $clean; |
|
| 100 | + } |
|
| 101 | + $txt = $texte; |
|
| 102 | 102 | |
| 103 | - // tant qu'il y a des tags |
|
| 104 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | - while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | - // tag ouvrant |
|
| 107 | - //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 103 | + // tant qu'il y a des tags |
|
| 104 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 105 | + while ((is_countable($chars) ? count($chars) : 0) >= 2) { |
|
| 106 | + // tag ouvrant |
|
| 107 | + //$chars = preg_split("{<([^>]*?)>}s",$txt,2,PREG_SPLIT_DELIM_CAPTURE); |
|
| 108 | 108 | |
| 109 | - // $before doit etre vide ou des espaces uniquements! |
|
| 110 | - $before = trim($chars[0]); |
|
| 109 | + // $before doit etre vide ou des espaces uniquements! |
|
| 110 | + $before = trim($chars[0]); |
|
| 111 | 111 | |
| 112 | - if (strlen($before) > 0) { |
|
| 113 | - return importer_charset($texte, $charset); |
|
| 114 | - }//$texte; // before non vide, donc on est dans du texte |
|
| 112 | + if (strlen($before) > 0) { |
|
| 113 | + return importer_charset($texte, $charset); |
|
| 114 | + }//$texte; // before non vide, donc on est dans du texte |
|
| 115 | 115 | |
| 116 | - $tag = rtrim($chars[1]); |
|
| 117 | - $txt = $chars[2]; |
|
| 116 | + $tag = rtrim($chars[1]); |
|
| 117 | + $txt = $chars[2]; |
|
| 118 | 118 | |
| 119 | - if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | - return importer_charset($texte, $charset); |
|
| 121 | - }//$texte; |
|
| 122 | - if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | - $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | - $out[$tag][] = ''; |
|
| 125 | - } else { |
|
| 126 | - $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | - $closing_tag = reset($closing_tag); |
|
| 128 | - // tag fermant |
|
| 129 | - $ncclos = strlen("</$closing_tag>"); |
|
| 130 | - $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | - if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | - $nclose = 0; |
|
| 133 | - $nopen = 0; |
|
| 134 | - $d = 0; |
|
| 135 | - while ( |
|
| 136 | - $p !== false |
|
| 137 | - && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | - && ($nopen += preg_match_all( |
|
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | - $morceau, |
|
| 141 | - $matches, |
|
| 142 | - PREG_SET_ORDER |
|
| 143 | - )) > $nclose |
|
| 144 | - ) { |
|
| 145 | - $nclose++; |
|
| 146 | - $d = $p + $ncclos; |
|
| 147 | - $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - if ($p === false) { |
|
| 151 | - if ($strict) { |
|
| 152 | - $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 119 | + if (str_starts_with($tag, '![CDATA[')) { |
|
| 120 | + return importer_charset($texte, $charset); |
|
| 121 | + }//$texte; |
|
| 122 | + if (str_ends_with($tag, '/')) { // self closing tag |
|
| 123 | + $tag = rtrim(substr($tag, 0, strlen($tag) - 1)); |
|
| 124 | + $out[$tag][] = ''; |
|
| 125 | + } else { |
|
| 126 | + $closing_tag = preg_split(",\s|\t|\n|\r,", trim($tag)); |
|
| 127 | + $closing_tag = reset($closing_tag); |
|
| 128 | + // tag fermant |
|
| 129 | + $ncclos = strlen("</$closing_tag>"); |
|
| 130 | + $p = strpos($txt, (string) "</$closing_tag>"); |
|
| 131 | + if ($p !== false && strpos($txt, '<') < $p) { |
|
| 132 | + $nclose = 0; |
|
| 133 | + $nopen = 0; |
|
| 134 | + $d = 0; |
|
| 135 | + while ( |
|
| 136 | + $p !== false |
|
| 137 | + && ($morceau = substr($txt, $d, $p - $d)) |
|
| 138 | + && ($nopen += preg_match_all( |
|
| 139 | + '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | + $morceau, |
|
| 141 | + $matches, |
|
| 142 | + PREG_SET_ORDER |
|
| 143 | + )) > $nclose |
|
| 144 | + ) { |
|
| 145 | + $nclose++; |
|
| 146 | + $d = $p + $ncclos; |
|
| 147 | + $p = strpos($txt, (string) "</$closing_tag>", $d); |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + if ($p === false) { |
|
| 151 | + if ($strict) { |
|
| 152 | + $out[$tag][] = "erreur : tag fermant $tag manquant::$txt"; |
|
| 153 | 153 | |
| 154 | - return $out; |
|
| 155 | - } else { |
|
| 156 | - return importer_charset($texte, $charset); |
|
| 157 | - }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | - } |
|
| 159 | - $content = substr($txt, 0, $p); |
|
| 160 | - $txt = substr($txt, $p + $ncclos); |
|
| 161 | - if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | - $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | - }//$content; |
|
| 164 | - else { |
|
| 165 | - $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | - } |
|
| 170 | - if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | - return $out; |
|
| 172 | - } else { |
|
| 173 | - return importer_charset($texte, $charset); |
|
| 174 | - }//$texte; |
|
| 154 | + return $out; |
|
| 155 | + } else { |
|
| 156 | + return importer_charset($texte, $charset); |
|
| 157 | + }//$texte // un tag qui constitue du texte a reporter dans $before |
|
| 158 | + } |
|
| 159 | + $content = substr($txt, 0, $p); |
|
| 160 | + $txt = substr($txt, $p + $ncclos); |
|
| 161 | + if ($profondeur == 0 || !str_contains($content, '<')) { // eviter une recursion si pas utile |
|
| 162 | + $out[$tag][] = importer_charset($content, $charset); |
|
| 163 | + }//$content; |
|
| 164 | + else { |
|
| 165 | + $out[$tag][] = spip_xml_parse($content, $strict, $clean, $profondeur - 1); |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + $chars = preg_split(_SPIP_XML_TAG_SPLIT, $txt, 2, PREG_SPLIT_DELIM_CAPTURE); |
|
| 169 | + } |
|
| 170 | + if (count($out) && (strlen(trim($txt)) == 0)) { |
|
| 171 | + return $out; |
|
| 172 | + } else { |
|
| 173 | + return importer_charset($texte, $charset); |
|
| 174 | + }//$texte; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | function spip_xml_aplatit($arbre, $separateur = ' ') { |
| 178 | - $s = ''; |
|
| 179 | - if (is_array($arbre)) { |
|
| 180 | - foreach ($arbre as $tag => $feuille) { |
|
| 181 | - if (is_array($feuille)) { |
|
| 182 | - if ($tag !== (int) $tag) { |
|
| 183 | - $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | - if (strlen((string) $f)) { |
|
| 185 | - $tagf = explode(' ', $tag); |
|
| 186 | - $tagf = $tagf[0]; |
|
| 187 | - $s .= "<$tag>$f</$tagf>"; |
|
| 188 | - } else { |
|
| 189 | - $s .= "<$tag />"; |
|
| 190 | - } |
|
| 191 | - } else { |
|
| 192 | - $s .= spip_xml_aplatit($feuille); |
|
| 193 | - } |
|
| 194 | - $s .= $separateur; |
|
| 195 | - } else { |
|
| 196 | - $s .= "$feuille$separateur"; |
|
| 197 | - } |
|
| 198 | - } |
|
| 199 | - } |
|
| 178 | + $s = ''; |
|
| 179 | + if (is_array($arbre)) { |
|
| 180 | + foreach ($arbre as $tag => $feuille) { |
|
| 181 | + if (is_array($feuille)) { |
|
| 182 | + if ($tag !== (int) $tag) { |
|
| 183 | + $f = spip_xml_aplatit($feuille, $separateur); |
|
| 184 | + if (strlen((string) $f)) { |
|
| 185 | + $tagf = explode(' ', $tag); |
|
| 186 | + $tagf = $tagf[0]; |
|
| 187 | + $s .= "<$tag>$f</$tagf>"; |
|
| 188 | + } else { |
|
| 189 | + $s .= "<$tag />"; |
|
| 190 | + } |
|
| 191 | + } else { |
|
| 192 | + $s .= spip_xml_aplatit($feuille); |
|
| 193 | + } |
|
| 194 | + $s .= $separateur; |
|
| 195 | + } else { |
|
| 196 | + $s .= "$feuille$separateur"; |
|
| 197 | + } |
|
| 198 | + } |
|
| 199 | + } |
|
| 200 | 200 | |
| 201 | - return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 201 | + return strlen((string) $separateur) ? substr($s, 0, -strlen((string) $separateur)) : $s; |
|
| 202 | 202 | } |
| 203 | 203 | |
| 204 | 204 | function spip_xml_tagname($tag) { |
| 205 | - if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | - return $reg[1]; |
|
| 207 | - } |
|
| 205 | + if (preg_match(',^([a-z][\w:]*),i', (string) $tag, $reg)) { |
|
| 206 | + return $reg[1]; |
|
| 207 | + } |
|
| 208 | 208 | |
| 209 | - return ''; |
|
| 209 | + return ''; |
|
| 210 | 210 | } |
| 211 | 211 | |
| 212 | 212 | function spip_xml_decompose_tag($tag) { |
| 213 | - $tagname = spip_xml_tagname($tag); |
|
| 214 | - $liste = []; |
|
| 215 | - $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | - $p = strpos($tag, '='); |
|
| 217 | - while ($p !== false) { |
|
| 218 | - $attr = trim(substr($tag, 0, $p)); |
|
| 219 | - $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | - $quote = $tag[0]; |
|
| 221 | - $p = strpos($tag, $quote, 1); |
|
| 222 | - $cont = substr($tag, 1, $p - 1); |
|
| 223 | - $liste[$attr] = $cont; |
|
| 224 | - $tag = substr($tag, $p + 1); |
|
| 225 | - $p = strpos($tag, '='); |
|
| 226 | - } |
|
| 213 | + $tagname = spip_xml_tagname($tag); |
|
| 214 | + $liste = []; |
|
| 215 | + $tag = ltrim(strpbrk((string) $tag, " \n\t")); |
|
| 216 | + $p = strpos($tag, '='); |
|
| 217 | + while ($p !== false) { |
|
| 218 | + $attr = trim(substr($tag, 0, $p)); |
|
| 219 | + $tag = ltrim(substr($tag, $p + 1)); |
|
| 220 | + $quote = $tag[0]; |
|
| 221 | + $p = strpos($tag, $quote, 1); |
|
| 222 | + $cont = substr($tag, 1, $p - 1); |
|
| 223 | + $liste[$attr] = $cont; |
|
| 224 | + $tag = substr($tag, $p + 1); |
|
| 225 | + $p = strpos($tag, '='); |
|
| 226 | + } |
|
| 227 | 227 | |
| 228 | - return [$tagname, $liste]; |
|
| 228 | + return [$tagname, $liste]; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -248,21 +248,21 @@ discard block |
||
| 248 | 248 | * false si aucun élément ne valide l'expression régulière, true sinon. |
| 249 | 249 | **/ |
| 250 | 250 | function spip_xml_match_nodes($regexp, &$arbre, &$matches, $init = true) { |
| 251 | - if ($init) { |
|
| 252 | - $matches = []; |
|
| 253 | - } |
|
| 254 | - if (is_array($arbre) && count($arbre)) { |
|
| 255 | - foreach (array_keys($arbre) as $tag) { |
|
| 256 | - if (preg_match($regexp, $tag)) { |
|
| 257 | - $matches[$tag] = &$arbre[$tag]; |
|
| 258 | - } |
|
| 259 | - if (is_array($arbre[$tag])) { |
|
| 260 | - foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | - spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - } |
|
| 265 | - } |
|
| 251 | + if ($init) { |
|
| 252 | + $matches = []; |
|
| 253 | + } |
|
| 254 | + if (is_array($arbre) && count($arbre)) { |
|
| 255 | + foreach (array_keys($arbre) as $tag) { |
|
| 256 | + if (preg_match($regexp, $tag)) { |
|
| 257 | + $matches[$tag] = &$arbre[$tag]; |
|
| 258 | + } |
|
| 259 | + if (is_array($arbre[$tag])) { |
|
| 260 | + foreach (array_keys($arbre[$tag]) as $occurences) { |
|
| 261 | + spip_xml_match_nodes($regexp, $arbre[$tag][$occurences], $matches, false); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | 266 | |
| 267 | - return (is_countable($matches) ? count($matches) : 0); |
|
| 267 | + return (is_countable($matches) ? count($matches) : 0); |
|
| 268 | 268 | } |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | use Spip\Texte\Collecteur\Modeles; |
| 14 | 14 | |
| 15 | 15 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 16 | - return; |
|
| 16 | + return; |
|
| 17 | 17 | } |
| 18 | 18 | |
| 19 | 19 | /** |
@@ -26,16 +26,16 @@ discard block |
||
| 26 | 26 | */ |
| 27 | 27 | function traiter_modeles($texte, $doublons = false, $echap = '', string $connect = '', ?Liens $collecteurLiens = null, $env = []) { |
| 28 | 28 | |
| 29 | - include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | - include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | - $collecteurModeles = new Modeles(); |
|
| 29 | + include_spip('src/Texte/Collecteur/AbstractCollecteur'); |
|
| 30 | + include_spip('src/Texte/Collecteur/Modeles'); |
|
| 31 | + $collecteurModeles = new Modeles(); |
|
| 32 | 32 | |
| 33 | - $options = [ |
|
| 34 | - 'doublons' => $doublons, |
|
| 35 | - 'echap' => $echap, |
|
| 36 | - 'connect' => $connect, |
|
| 37 | - 'collecteurLiens' => $collecteurLiens, |
|
| 38 | - 'env' => $env |
|
| 39 | - ]; |
|
| 40 | - return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 33 | + $options = [ |
|
| 34 | + 'doublons' => $doublons, |
|
| 35 | + 'echap' => $echap, |
|
| 36 | + 'connect' => $connect, |
|
| 37 | + 'collecteurLiens' => $collecteurLiens, |
|
| 38 | + 'env' => $env |
|
| 39 | + ]; |
|
| 40 | + return $collecteurModeles->traiter($texte ?? '', $options); |
|
| 41 | 41 | } |
@@ -10,76 +10,76 @@ |
||
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | 12 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 13 | - return; |
|
| 13 | + return; |
|
| 14 | 14 | } |
| 15 | 15 | |
| 16 | 16 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 17 | 17 | |
| 18 | 18 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 19 | - include_spip('inc/texte'); |
|
| 20 | - $titre = $descriptif = ''; |
|
| 21 | - if ($type === 'rubrique') { |
|
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | - if ($row) { |
|
| 24 | - $titre = typo($row['titre']); |
|
| 25 | - $descriptif = propre($row['descriptif']); |
|
| 26 | - } else { |
|
| 27 | - $titre = _T('info_racine_site'); |
|
| 28 | - } |
|
| 29 | - } |
|
| 19 | + include_spip('inc/texte'); |
|
| 20 | + $titre = $descriptif = ''; |
|
| 21 | + if ($type === 'rubrique') { |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 23 | + if ($row) { |
|
| 24 | + $titre = typo($row['titre']); |
|
| 25 | + $descriptif = propre($row['descriptif']); |
|
| 26 | + } else { |
|
| 27 | + $titre = _T('info_racine_site'); |
|
| 28 | + } |
|
| 29 | + } |
|
| 30 | 30 | |
| 31 | - $res = ''; |
|
| 32 | - if ( |
|
| 33 | - $type === 'rubrique' |
|
| 34 | - && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | - && isset($GLOBALS['meta']['image_process']) |
|
| 36 | - && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | - ) { |
|
| 38 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | - [$fid, $dir, $nom, $format] = $res; |
|
| 41 | - include_spip('inc/filtres_images_mini'); |
|
| 42 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | - if ($res) { |
|
| 44 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | - } |
|
| 46 | - } |
|
| 47 | - } |
|
| 31 | + $res = ''; |
|
| 32 | + if ( |
|
| 33 | + $type === 'rubrique' |
|
| 34 | + && (int) ($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 35 | + && isset($GLOBALS['meta']['image_process']) |
|
| 36 | + && $GLOBALS['meta']['image_process'] !== 'non' |
|
| 37 | + ) { |
|
| 38 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 39 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 40 | + [$fid, $dir, $nom, $format] = $res; |
|
| 41 | + include_spip('inc/filtres_images_mini'); |
|
| 42 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 43 | + if ($res) { |
|
| 44 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | 48 | |
| 49 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | - $id = (int) $id; |
|
| 49 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 50 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 51 | + $id = (int) $id; |
|
| 52 | 52 | |
| 53 | 53 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 54 | 54 | # et l'affichage de son titre dans le bandeau |
| 55 | - $titre = strtr( |
|
| 56 | - str_replace( |
|
| 57 | - "'", |
|
| 58 | - '’', |
|
| 59 | - str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | - ), |
|
| 61 | - "\n\r", |
|
| 62 | - ' ' |
|
| 63 | - ); |
|
| 55 | + $titre = strtr( |
|
| 56 | + str_replace( |
|
| 57 | + "'", |
|
| 58 | + '’', |
|
| 59 | + str_replace('"', '"', (string) textebrut($titre)) |
|
| 60 | + ), |
|
| 61 | + "\n\r", |
|
| 62 | + ' ' |
|
| 63 | + ); |
|
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do . '_selection_titre'; |
|
| 66 | 66 | |
| 67 | - return "<div style='display: none;'>" |
|
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | - . entites_html($titre) |
|
| 71 | - . '" />' |
|
| 72 | - . '</div>' |
|
| 73 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | - . '<div class="informer__item">' |
|
| 75 | - . ($res ?: '') |
|
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | - . '</div>' |
|
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | - . _T('bouton_choisir') |
|
| 82 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | - . '</div>' |
|
| 84 | - . '</div>'; |
|
| 67 | + return "<div style='display: none;'>" |
|
| 68 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . entites_html($titre) |
|
| 71 | + . '" />' |
|
| 72 | + . '</div>' |
|
| 73 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 74 | + . '<div class="informer__item">' |
|
| 75 | + . ($res ?: '') |
|
| 76 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 78 | + . '</div>' |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 80 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 81 | + . _T('bouton_choisir') |
|
| 82 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 83 | + . '</div>' |
|
| 84 | + . '</div>'; |
|
| 85 | 85 | } |
@@ -7,7 +7,7 @@ discard block |
||
| 7 | 7 | **/ |
| 8 | 8 | |
| 9 | 9 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 10 | - return; |
|
| 10 | + return; |
|
| 11 | 11 | } |
| 12 | 12 | |
| 13 | 13 | /** |
@@ -28,49 +28,49 @@ discard block |
||
| 28 | 28 | * - afficher : tableau des objets à afficher (mais pas forcément sélectionnables) |
| 29 | 29 | */ |
| 30 | 30 | function selecteur_lister_objets($includelist = [], $excludelist = []) { |
| 31 | - static $liste_selecteurs, $liste_parents; |
|
| 32 | - |
|
| 33 | - if (!$liste_selecteurs) { |
|
| 34 | - $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | - } |
|
| 36 | - $objets_selectionner = []; |
|
| 37 | - foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | - $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | - if (!empty($includelist)) { |
|
| 43 | - $includelist = array_map('table_objet', $includelist); |
|
| 44 | - $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | - } |
|
| 46 | - // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | - $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | - // On enlève toujours la racine |
|
| 49 | - $excludelist[] = 'racine'; |
|
| 50 | - $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | - |
|
| 52 | - // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | - $objets_afficher = $objets_selectionner; |
|
| 54 | - |
|
| 55 | - // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | - // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | - if (!$liste_parents) { |
|
| 58 | - $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | - } |
|
| 60 | - foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | - preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | - $parent = $captures[1]; |
|
| 63 | - $type = $captures[2]; |
|
| 64 | - // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | - if (in_array($type, $objets_afficher)) { |
|
| 66 | - $objets_afficher[] = $parent; |
|
| 67 | - } |
|
| 68 | - } |
|
| 69 | - |
|
| 70 | - return [ |
|
| 71 | - 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | - 'afficher' => array_unique($objets_afficher), |
|
| 73 | - ]; |
|
| 31 | + static $liste_selecteurs, $liste_parents; |
|
| 32 | + |
|
| 33 | + if (!$liste_selecteurs) { |
|
| 34 | + $liste_selecteurs = find_all_in_path('formulaires/selecteur/', 'hierarchie-[\w]+[.]html$'); |
|
| 35 | + } |
|
| 36 | + $objets_selectionner = []; |
|
| 37 | + foreach ($liste_selecteurs as $fichier => $chemin) { |
|
| 38 | + $objets_selectionner[] = preg_replace('/^hierarchie-([\w]+)[.]html$/', '$1', (string) $fichier); |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + // S'il y a une whitelist on ne garde que ce qui est dedans |
|
| 42 | + if (!empty($includelist)) { |
|
| 43 | + $includelist = array_map('table_objet', $includelist); |
|
| 44 | + $objets_selectionner = array_intersect($objets_selectionner, $includelist); |
|
| 45 | + } |
|
| 46 | + // On supprime ce qui est dans la liste d’exclusion |
|
| 47 | + $excludelist = array_map('table_objet', $excludelist); |
|
| 48 | + // On enlève toujours la racine |
|
| 49 | + $excludelist[] = 'racine'; |
|
| 50 | + $objets_selectionner = array_diff($objets_selectionner, $excludelist); |
|
| 51 | + |
|
| 52 | + // Ensuite on cherche ce qu'on doit afficher : au moins ceux qu'on peut sélectionner |
|
| 53 | + $objets_afficher = $objets_selectionner; |
|
| 54 | + |
|
| 55 | + // Il faut alors chercher d'éventuels parents obligatoires en plus : |
|
| 56 | + // lister-trucs-bidules.html => on doit afficher des "trucs" pour trouver des "bidules" |
|
| 57 | + if (!$liste_parents) { |
|
| 58 | + $liste_parents = find_all_in_path('formulaires/selecteur/', 'lister-[\w]+-[\w]+[.]html$'); |
|
| 59 | + } |
|
| 60 | + foreach ($liste_parents as $fichier => $chemin) { |
|
| 61 | + preg_match('/^lister-([\w]+)-([\w]+)[.]html$/', (string) $fichier, $captures); |
|
| 62 | + $parent = $captures[1]; |
|
| 63 | + $type = $captures[2]; |
|
| 64 | + // Si le type fait partie de ce qu'on doit afficher alors on ajoute aussi le parent à l'affichage |
|
| 65 | + if (in_array($type, $objets_afficher)) { |
|
| 66 | + $objets_afficher[] = $parent; |
|
| 67 | + } |
|
| 68 | + } |
|
| 69 | + |
|
| 70 | + return [ |
|
| 71 | + 'selectionner' => array_unique($objets_selectionner), |
|
| 72 | + 'afficher' => array_unique($objets_afficher), |
|
| 73 | + ]; |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -97,31 +97,31 @@ discard block |
||
| 97 | 97 | * liste des couples (objets => id_objet) ou liste des identifiants d'un type d'objet. |
| 98 | 98 | **/ |
| 99 | 99 | function picker_selected($selected, $type = '') { |
| 100 | - $select = []; |
|
| 101 | - $type = preg_replace(',\W,', '', $type); |
|
| 102 | - |
|
| 103 | - if ($selected && !is_array($selected)) { |
|
| 104 | - $selected = explode(',', $selected); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - if (is_array($selected)) { |
|
| 108 | - foreach ($selected as $value) { |
|
| 109 | - // Si c'est le bon format déjà |
|
| 110 | - if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | - $objet = $captures[1]; |
|
| 112 | - $id_objet = (int) $captures[2]; |
|
| 113 | - |
|
| 114 | - // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | - if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | - $select[] = $id_objet; |
|
| 117 | - } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | - $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | - } |
|
| 120 | - } |
|
| 121 | - } |
|
| 122 | - } |
|
| 123 | - |
|
| 124 | - return $select; |
|
| 100 | + $select = []; |
|
| 101 | + $type = preg_replace(',\W,', '', $type); |
|
| 102 | + |
|
| 103 | + if ($selected && !is_array($selected)) { |
|
| 104 | + $selected = explode(',', $selected); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + if (is_array($selected)) { |
|
| 108 | + foreach ($selected as $value) { |
|
| 109 | + // Si c'est le bon format déjà |
|
| 110 | + if (preg_match('/^([\w]+)[|](\d+)$/', (string) $value, $captures)) { |
|
| 111 | + $objet = $captures[1]; |
|
| 112 | + $id_objet = (int) $captures[2]; |
|
| 113 | + |
|
| 114 | + // Si on cherche un type et que c'est le bon, on renvoit un tableau que d'identifiants |
|
| 115 | + if (is_string($type) && $type == $objet && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 116 | + $select[] = $id_objet; |
|
| 117 | + } elseif (!$type && ($id_objet || in_array($objet, ['racine', 'rubrique']))) { |
|
| 118 | + $select[] = ['objet' => $objet, 'id_objet' => $id_objet]; |
|
| 119 | + } |
|
| 120 | + } |
|
| 121 | + } |
|
| 122 | + } |
|
| 123 | + |
|
| 124 | + return $select; |
|
| 125 | 125 | } |
| 126 | 126 | |
| 127 | 127 | /** |
@@ -138,53 +138,53 @@ discard block |
||
| 138 | 138 | * Booléen indiquant si les articles sont sélectionnables |
| 139 | 139 | */ |
| 140 | 140 | function picker_identifie_id_rapide($ref, $rubriques_ou_objets = false, $articles = false) { |
| 141 | - include_spip('inc/json'); |
|
| 142 | - include_spip('inc/lien'); |
|
| 143 | - |
|
| 144 | - // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | - $objets = []; |
|
| 146 | - if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | - $objets = $rubriques_ou_objets; |
|
| 148 | - } else { |
|
| 149 | - if ($rubriques_ou_objets) { |
|
| 150 | - $objets[] = 'rubriques'; |
|
| 151 | - } |
|
| 152 | - if ($articles) { |
|
| 153 | - $objets[] = 'articles'; |
|
| 154 | - } |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | - if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | - $type = reset($objets); |
|
| 160 | - $type = objet_type($type); |
|
| 161 | - $id = (int) $ref; |
|
| 162 | - $ref = $type . $ref; |
|
| 163 | - } |
|
| 164 | - else { |
|
| 165 | - // Si la référence ne correspond à rien, c'est fini |
|
| 166 | - if (!($match = typer_raccourci($ref))) { |
|
| 167 | - return json_export(false); |
|
| 168 | - } |
|
| 169 | - // Sinon on récupère les infos utiles |
|
| 170 | - [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | - |
|
| 172 | - // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | - if (!in_array(table_objet($type), $objets)) { |
|
| 174 | - return json_export(false); |
|
| 175 | - } |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | - include_spip('inc/filtres'); |
|
| 180 | - if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | - return json_export(false); |
|
| 182 | - } |
|
| 183 | - |
|
| 184 | - // On simplifie le texte |
|
| 185 | - $titre = attribut_html($titre); |
|
| 186 | - |
|
| 187 | - return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 141 | + include_spip('inc/json'); |
|
| 142 | + include_spip('inc/lien'); |
|
| 143 | + |
|
| 144 | + // On construit un tableau des objets sélectionnables suivant les paramètres |
|
| 145 | + $objets = []; |
|
| 146 | + if ($rubriques_ou_objets && is_array($rubriques_ou_objets)) { |
|
| 147 | + $objets = $rubriques_ou_objets; |
|
| 148 | + } else { |
|
| 149 | + if ($rubriques_ou_objets) { |
|
| 150 | + $objets[] = 'rubriques'; |
|
| 151 | + } |
|
| 152 | + if ($articles) { |
|
| 153 | + $objets[] = 'articles'; |
|
| 154 | + } |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + // si id numerique et un seul objet possible, pas d'ambiguite |
|
| 158 | + if (is_numeric($ref) && count($objets) === 1) { |
|
| 159 | + $type = reset($objets); |
|
| 160 | + $type = objet_type($type); |
|
| 161 | + $id = (int) $ref; |
|
| 162 | + $ref = $type . $ref; |
|
| 163 | + } |
|
| 164 | + else { |
|
| 165 | + // Si la référence ne correspond à rien, c'est fini |
|
| 166 | + if (!($match = typer_raccourci($ref))) { |
|
| 167 | + return json_export(false); |
|
| 168 | + } |
|
| 169 | + // Sinon on récupère les infos utiles |
|
| 170 | + [$type, , $id, , , , ] = array_pad($match, 7, null); |
|
| 171 | + |
|
| 172 | + // On regarde si le type trouvé fait partie des objets sélectionnables |
|
| 173 | + if (!in_array(table_objet($type), $objets)) { |
|
| 174 | + return json_export(false); |
|
| 175 | + } |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + // Maintenant que tout est bon, on cherche les informations sur cet objet |
|
| 179 | + include_spip('inc/filtres'); |
|
| 180 | + if (!$titre = generer_objet_info($id, $type, 'titre')) { |
|
| 181 | + return json_export(false); |
|
| 182 | + } |
|
| 183 | + |
|
| 184 | + // On simplifie le texte |
|
| 185 | + $titre = attribut_html($titre); |
|
| 186 | + |
|
| 187 | + return json_export(['type' => $type, 'id' => "$type|$id", 'titre' => $titre]); |
|
| 188 | 188 | } |
| 189 | 189 | |
| 190 | 190 | /** |
@@ -207,34 +207,34 @@ discard block |
||
| 207 | 207 | * Comme le filtre `oui` : espace (` `) si rubrique à afficher, chaîne vide sinon. |
| 208 | 208 | */ |
| 209 | 209 | function test_enfants_rubrique($id_rubrique, $types = []) { |
| 210 | - static $has_child = []; |
|
| 211 | - |
|
| 212 | - if (!isset($has_child[$id_rubrique])) { |
|
| 213 | - $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | - |
|
| 215 | - // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | - $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | - $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | - $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | - $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | - $has = array_column($has, 'id_parent'); |
|
| 221 | - $fratrie = array_diff($fratrie, $has); |
|
| 222 | - |
|
| 223 | - while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | - $type = array_shift($types); |
|
| 225 | - $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | - $h = array_column($h, 'id_rubrique'); |
|
| 227 | - $has = [...$has, ...$h]; |
|
| 228 | - $fratrie = array_diff($fratrie, $h); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - if ($has !== []) { |
|
| 232 | - $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | - } |
|
| 234 | - if ($fratrie !== []) { |
|
| 235 | - $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 210 | + static $has_child = []; |
|
| 211 | + |
|
| 212 | + if (!isset($has_child[$id_rubrique])) { |
|
| 213 | + $types = (is_array($types) ? array_filter($types) : []); |
|
| 214 | + |
|
| 215 | + // recuperer tous les freres et soeurs de la rubrique visee |
|
| 216 | + $id_parent = sql_getfetsel('id_parent', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 217 | + $fratrie = sql_allfetsel('id_rubrique', 'spip_rubriques', 'id_parent=' . (int) $id_parent); |
|
| 218 | + $fratrie = array_column($fratrie, 'id_rubrique'); |
|
| 219 | + $has = sql_allfetsel('DISTINCT id_parent', 'spip_rubriques', sql_in('id_parent', $fratrie)); |
|
| 220 | + $has = array_column($has, 'id_parent'); |
|
| 221 | + $fratrie = array_diff($fratrie, $has); |
|
| 222 | + |
|
| 223 | + while (count($fratrie) && is_array($types) && count($types)) { |
|
| 224 | + $type = array_shift($types); |
|
| 225 | + $h = sql_allfetsel('DISTINCT id_rubrique', table_objet_sql($type), sql_in('id_rubrique', $fratrie)); |
|
| 226 | + $h = array_column($h, 'id_rubrique'); |
|
| 227 | + $has = [...$has, ...$h]; |
|
| 228 | + $fratrie = array_diff($fratrie, $h); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + if ($has !== []) { |
|
| 232 | + $has_child += array_combine($has, array_pad([], count($has), true)); |
|
| 233 | + } |
|
| 234 | + if ($fratrie !== []) { |
|
| 235 | + $has_child += array_combine($fratrie, array_pad([], count($fratrie), false)); |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $has_child[$id_rubrique] ? ' ' : ''; |
|
| 240 | 240 | } |