@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | * @package SPIP\Core\Drapeaux\Edition |
| 30 | 30 | **/ |
| 31 | 31 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 32 | - return; |
|
| 32 | + return; |
|
| 33 | 33 | } |
| 34 | 34 | |
| 35 | 35 | |
@@ -44,46 +44,46 @@ discard block |
||
| 44 | 44 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 45 | 45 | **/ |
| 46 | 46 | function lire_tableau_edition() { |
| 47 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | - if (!$edition) { |
|
| 49 | - return []; |
|
| 50 | - } |
|
| 51 | - $changed = false; |
|
| 47 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 48 | + if (!$edition) { |
|
| 49 | + return []; |
|
| 50 | + } |
|
| 51 | + $changed = false; |
|
| 52 | 52 | |
| 53 | - $bon_pour_le_service = time() - 3600; |
|
| 54 | - // parcourir le tableau et virer les vieux |
|
| 55 | - foreach ($edition as $objet => $data) { |
|
| 56 | - if (!is_array($data)) { |
|
| 57 | - unset($edition[$objet]); |
|
| 58 | - } // vieille version |
|
| 59 | - else { |
|
| 60 | - foreach ($data as $id => $tab) { |
|
| 61 | - if (!is_array($tab)) { |
|
| 62 | - unset($edition[$objet][$tab]); |
|
| 63 | - } // vieille version |
|
| 64 | - else { |
|
| 65 | - foreach ($tab as $n => $duo) { |
|
| 66 | - if (current($duo) < $bon_pour_le_service) { |
|
| 67 | - unset($edition[$objet][$id][$n]); |
|
| 68 | - $changed = true; |
|
| 69 | - } |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - if (!$edition[$objet][$id]) { |
|
| 73 | - unset($edition[$objet][$id]); |
|
| 74 | - } |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - if (!$edition[$objet]) { |
|
| 78 | - unset($edition[$objet]); |
|
| 79 | - } |
|
| 80 | - } |
|
| 53 | + $bon_pour_le_service = time() - 3600; |
|
| 54 | + // parcourir le tableau et virer les vieux |
|
| 55 | + foreach ($edition as $objet => $data) { |
|
| 56 | + if (!is_array($data)) { |
|
| 57 | + unset($edition[$objet]); |
|
| 58 | + } // vieille version |
|
| 59 | + else { |
|
| 60 | + foreach ($data as $id => $tab) { |
|
| 61 | + if (!is_array($tab)) { |
|
| 62 | + unset($edition[$objet][$tab]); |
|
| 63 | + } // vieille version |
|
| 64 | + else { |
|
| 65 | + foreach ($tab as $n => $duo) { |
|
| 66 | + if (current($duo) < $bon_pour_le_service) { |
|
| 67 | + unset($edition[$objet][$id][$n]); |
|
| 68 | + $changed = true; |
|
| 69 | + } |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + if (!$edition[$objet][$id]) { |
|
| 73 | + unset($edition[$objet][$id]); |
|
| 74 | + } |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + if (!$edition[$objet]) { |
|
| 78 | + unset($edition[$objet]); |
|
| 79 | + } |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - if ($changed) { |
|
| 83 | - ecrire_tableau_edition($edition); |
|
| 84 | - } |
|
| 82 | + if ($changed) { |
|
| 83 | + ecrire_tableau_edition($edition); |
|
| 84 | + } |
|
| 85 | 85 | |
| 86 | - return $edition; |
|
| 86 | + return $edition; |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | /** |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 97 | 97 | **/ |
| 98 | 98 | function ecrire_tableau_edition($edition) { |
| 99 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 99 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -116,22 +116,22 @@ discard block |
||
| 116 | 116 | * Type d'objet édité |
| 117 | 117 | */ |
| 118 | 118 | function signale_edition($id, $auteur, $type = 'article') { |
| 119 | - include_spip('base/objets'); |
|
| 120 | - include_spip('inc/filtres'); |
|
| 121 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | - return; |
|
| 123 | - } |
|
| 119 | + include_spip('base/objets'); |
|
| 120 | + include_spip('inc/filtres'); |
|
| 121 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 122 | + return; |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | - $edition = lire_tableau_edition(); |
|
| 125 | + $edition = lire_tableau_edition(); |
|
| 126 | 126 | |
| 127 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 127 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 128 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 129 | 129 | |
| 130 | - if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | - $edition[$type][$id] = []; |
|
| 132 | - } |
|
| 133 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | - ecrire_tableau_edition($edition); |
|
| 130 | + if (!isset($edition[$type][$id]) || !is_array($edition[$type][$id])) { |
|
| 131 | + $edition[$type][$id] = []; |
|
| 132 | + } |
|
| 133 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 134 | + ecrire_tableau_edition($edition); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | /** |
@@ -148,9 +148,9 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function qui_edite($id, $type = 'article') { |
| 150 | 150 | |
| 151 | - $edition = lire_tableau_edition(); |
|
| 151 | + $edition = lire_tableau_edition(); |
|
| 152 | 152 | |
| 153 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 153 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | 154 | } |
| 155 | 155 | |
| 156 | 156 | /** |
@@ -164,23 +164,23 @@ discard block |
||
| 164 | 164 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 165 | 165 | */ |
| 166 | 166 | function mention_qui_edite($id, $type = 'article'): array { |
| 167 | - $modif = qui_edite($id, $type); |
|
| 168 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 167 | + $modif = qui_edite($id, $type); |
|
| 168 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 169 | 169 | |
| 170 | - if ($modif) { |
|
| 171 | - $quand = 0; |
|
| 172 | - foreach ($modif as $duo) { |
|
| 173 | - $auteurs[] = typo(key($duo)); |
|
| 174 | - $quand = max($quand, current($duo)); |
|
| 175 | - } |
|
| 170 | + if ($modif) { |
|
| 171 | + $quand = 0; |
|
| 172 | + foreach ($modif as $duo) { |
|
| 173 | + $auteurs[] = typo(key($duo)); |
|
| 174 | + $quand = max($quand, current($duo)); |
|
| 175 | + } |
|
| 176 | 176 | |
| 177 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | - return [ |
|
| 179 | - 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | - ]; |
|
| 182 | - } |
|
| 183 | - return []; |
|
| 177 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 178 | + return [ |
|
| 179 | + 'nom_auteur_modif' => implode(' | ', $auteurs), |
|
| 180 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 181 | + ]; |
|
| 182 | + } |
|
| 183 | + return []; |
|
| 184 | 184 | } |
| 185 | 185 | |
| 186 | 186 | /** |
@@ -194,25 +194,25 @@ discard block |
||
| 194 | 194 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 195 | 195 | */ |
| 196 | 196 | function liste_drapeau_edition($id_auteur) { |
| 197 | - $edition = lire_tableau_edition(); |
|
| 198 | - $objets_ouverts = []; |
|
| 197 | + $edition = lire_tableau_edition(); |
|
| 198 | + $objets_ouverts = []; |
|
| 199 | 199 | |
| 200 | - foreach ($edition as $objet => $data) { |
|
| 201 | - foreach ($data as $id => $auteurs) { |
|
| 202 | - if ( |
|
| 203 | - isset($auteurs[$id_auteur]) |
|
| 204 | - && is_array($auteurs[$id_auteur]) |
|
| 205 | - && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | - ) { |
|
| 207 | - $objets_ouverts[] = [ |
|
| 208 | - 'objet' => $objet, |
|
| 209 | - 'id_objet' => $id, |
|
| 210 | - ]; |
|
| 211 | - } |
|
| 212 | - } |
|
| 213 | - } |
|
| 200 | + foreach ($edition as $objet => $data) { |
|
| 201 | + foreach ($data as $id => $auteurs) { |
|
| 202 | + if ( |
|
| 203 | + isset($auteurs[$id_auteur]) |
|
| 204 | + && is_array($auteurs[$id_auteur]) |
|
| 205 | + && array_pop($auteurs[$id_auteur]) > time() - 3600 |
|
| 206 | + ) { |
|
| 207 | + $objets_ouverts[] = [ |
|
| 208 | + 'objet' => $objet, |
|
| 209 | + 'id_objet' => $id, |
|
| 210 | + ]; |
|
| 211 | + } |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | 214 | |
| 215 | - return $objets_ouverts; |
|
| 215 | + return $objets_ouverts; |
|
| 216 | 216 | } |
| 217 | 217 | |
| 218 | 218 | /** |
@@ -225,15 +225,15 @@ discard block |
||
| 225 | 225 | * @return void |
| 226 | 226 | */ |
| 227 | 227 | function debloquer_tous($id_auteur) { |
| 228 | - $edition = lire_tableau_edition(); |
|
| 229 | - foreach ($edition as $objet => $data) { |
|
| 230 | - foreach ($data as $id => $auteurs) { |
|
| 231 | - if (isset($auteurs[$id_auteur])) { |
|
| 232 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | - ecrire_tableau_edition($edition); |
|
| 234 | - } |
|
| 235 | - } |
|
| 236 | - } |
|
| 228 | + $edition = lire_tableau_edition(); |
|
| 229 | + foreach ($edition as $objet => $data) { |
|
| 230 | + foreach ($data as $id => $auteurs) { |
|
| 231 | + if (isset($auteurs[$id_auteur])) { |
|
| 232 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 233 | + ecrire_tableau_edition($edition); |
|
| 234 | + } |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,19 +251,19 @@ discard block |
||
| 251 | 251 | * @return void |
| 252 | 252 | */ |
| 253 | 253 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 254 | - $edition = lire_tableau_edition(); |
|
| 254 | + $edition = lire_tableau_edition(); |
|
| 255 | 255 | |
| 256 | - foreach ($edition as $objet => $data) { |
|
| 257 | - if ($objet == $type) { |
|
| 258 | - foreach ($data as $id => $auteurs) { |
|
| 259 | - if ( |
|
| 260 | - $id == $id_objet |
|
| 261 | - && isset($auteurs[$id_auteur]) |
|
| 262 | - ) { |
|
| 263 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | - ecrire_tableau_edition($edition); |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 256 | + foreach ($edition as $objet => $data) { |
|
| 257 | + if ($objet == $type) { |
|
| 258 | + foreach ($data as $id => $auteurs) { |
|
| 259 | + if ( |
|
| 260 | + $id == $id_objet |
|
| 261 | + && isset($auteurs[$id_auteur]) |
|
| 262 | + ) { |
|
| 263 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 264 | + ecrire_tableau_edition($edition); |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | 269 | } |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | if (!str_starts_with($fichier, (string) _DIR_IMG)) { |
| 64 | - $fichier = _DIR_IMG . $fichier; |
|
| 64 | + $fichier = _DIR_IMG.$fichier; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | // fichier normal |
@@ -154,22 +154,22 @@ discard block |
||
| 154 | 154 | || !($r = verifier_upload_autorise($dest)) |
| 155 | 155 | || !empty($r['autozip']) |
| 156 | 156 | ) { |
| 157 | - $dest = substr($dest, 0, -strlen($m[0])) . '_' . $m[1]; |
|
| 157 | + $dest = substr($dest, 0, -strlen($m[0])).'_'.$m[1]; |
|
| 158 | 158 | break; |
| 159 | 159 | } else { |
| 160 | 160 | $dest = substr($dest, 0, -strlen($m[0])); |
| 161 | - $ext = $m[1] . '.' . $ext; |
|
| 161 | + $ext = $m[1].'.'.$ext; |
|
| 162 | 162 | } |
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | // Si le document "source" est deja au bon endroit, ne rien faire |
| 166 | - if ($source == ($dir . $dest . '.' . $ext)) { |
|
| 166 | + if ($source == ($dir.$dest.'.'.$ext)) { |
|
| 167 | 167 | return $source; |
| 168 | 168 | } |
| 169 | 169 | |
| 170 | 170 | // sinon tourner jusqu'a trouver un numero correct |
| 171 | 171 | $n = 0; |
| 172 | - while (@file_exists($newFile = $dir . $dest . ($n++ ? ('-' . $n) : '') . '.' . $ext)) { |
|
| 172 | + while (@file_exists($newFile = $dir.$dest.($n++ ? ('-'.$n) : '').'.'.$ext)) { |
|
| 173 | 173 | ; |
| 174 | 174 | } |
| 175 | 175 | |
@@ -230,7 +230,7 @@ discard block |
||
| 230 | 230 | function deplacer_fichier_upload($source, $dest, $move = false) { |
| 231 | 231 | // Securite |
| 232 | 232 | if (str_starts_with($dest, (string) _DIR_RACINE)) { |
| 233 | - $dest = _DIR_RACINE . preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 233 | + $dest = _DIR_RACINE.preg_replace(',\.\.+,', '.', substr($dest, strlen((string) _DIR_RACINE))); |
|
| 234 | 234 | } else { |
| 235 | 235 | $dest = preg_replace(',\.\.+,', '.', $dest); |
| 236 | 236 | } |
@@ -308,8 +308,8 @@ discard block |
||
| 308 | 308 | |
| 309 | 309 | default: /* autre */ |
| 310 | 310 | if (!$msg) { |
| 311 | - $msg = _T('pass_erreur') . ' ' . $error |
|
| 312 | - . '<br />' . propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 311 | + $msg = _T('pass_erreur').' '.$error |
|
| 312 | + . '<br />'.propre('[->http://php.net/manual/fr/features.file-upload.errors.php]'); |
|
| 313 | 313 | } |
| 314 | 314 | break; |
| 315 | 315 | } |
@@ -327,7 +327,7 @@ discard block |
||
| 327 | 327 | include_spip('inc/minipres'); |
| 328 | 328 | echo minipres( |
| 329 | 329 | $msg, |
| 330 | - "<div style='text-align: " . $GLOBALS['spip_lang_right'] . "'><a href='" . rawurldecode((string) $GLOBALS['redirect']) . "'><button type='button'>" . _T('ecrire:bouton_suivant') . '</button></a></div>' |
|
| 330 | + "<div style='text-align: ".$GLOBALS['spip_lang_right']."'><a href='".rawurldecode((string) $GLOBALS['redirect'])."'><button type='button'>"._T('ecrire:bouton_suivant').'</button></a></div>' |
|
| 331 | 331 | ); |
| 332 | 332 | exit; |
| 333 | 333 | } |
@@ -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_logger()->info("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_logger()->info("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_logger()->info("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_logger()->info("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_logger()->info("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_logger()->info("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 | } |
@@ -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 | } |
@@ -336,8 +336,7 @@ |
||
| 336 | 336 | if (!autoriser('modifier', $type, (int) $id)) { |
| 337 | 337 | $contexte['editable'] = ''; |
| 338 | 338 | } |
| 339 | - } |
|
| 340 | - else { |
|
| 339 | + } else { |
|
| 341 | 340 | if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
| 342 | 341 | $contexte['editable'] = ''; |
| 343 | 342 | } |
@@ -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 | include_spip('base/abstract_sql'); |
| 22 | 22 | |
@@ -58,56 +58,56 @@ discard block |
||
| 58 | 58 | * Retour des traitements. |
| 59 | 59 | **/ |
| 60 | 60 | function formulaires_editer_objet_traiter( |
| 61 | - $type, |
|
| 62 | - $id = 'new', |
|
| 63 | - $id_parent = 0, |
|
| 64 | - $lier_trad = 0, |
|
| 65 | - $retour = '', |
|
| 66 | - $config_fonc = 'articles_edit_config', |
|
| 67 | - $row = [], |
|
| 68 | - $hidden = '' |
|
| 61 | + $type, |
|
| 62 | + $id = 'new', |
|
| 63 | + $id_parent = 0, |
|
| 64 | + $lier_trad = 0, |
|
| 65 | + $retour = '', |
|
| 66 | + $config_fonc = 'articles_edit_config', |
|
| 67 | + $row = [], |
|
| 68 | + $hidden = '' |
|
| 69 | 69 | ) { |
| 70 | 70 | |
| 71 | - $res = []; |
|
| 72 | - // eviter la redirection forcee par l'action... |
|
| 73 | - set_request('redirect'); |
|
| 74 | - if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | - [$id, $err] = $action_editer($id); |
|
| 76 | - } else { |
|
| 77 | - $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | - [$id, $err] = $action_editer($id, $type); |
|
| 79 | - } |
|
| 80 | - $id_table_objet = id_table_objet($type); |
|
| 81 | - $res[$id_table_objet] = $id; |
|
| 82 | - if ($err || !$id) { |
|
| 83 | - $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | - } else { |
|
| 85 | - // Un lien de trad a prendre en compte |
|
| 86 | - if ($lier_trad) { |
|
| 87 | - // referencer la traduction |
|
| 88 | - $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | - $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | - // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | - $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | - $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | - if ($err) { |
|
| 94 | - $res['message_erreur'] = $err; |
|
| 95 | - return $res; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | - if ($retour) { |
|
| 101 | - if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | - $res['editable'] = true; |
|
| 104 | - } else { |
|
| 105 | - $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | - } |
|
| 107 | - } |
|
| 108 | - } |
|
| 109 | - |
|
| 110 | - return $res; |
|
| 71 | + $res = []; |
|
| 72 | + // eviter la redirection forcee par l'action... |
|
| 73 | + set_request('redirect'); |
|
| 74 | + if ($action_editer = charger_fonction("editer_$type", 'action', true)) { |
|
| 75 | + [$id, $err] = $action_editer($id); |
|
| 76 | + } else { |
|
| 77 | + $action_editer = charger_fonction('editer_objet', 'action'); |
|
| 78 | + [$id, $err] = $action_editer($id, $type); |
|
| 79 | + } |
|
| 80 | + $id_table_objet = id_table_objet($type); |
|
| 81 | + $res[$id_table_objet] = $id; |
|
| 82 | + if ($err || !$id) { |
|
| 83 | + $res['message_erreur'] = ($err ?: _T('erreur')); |
|
| 84 | + } else { |
|
| 85 | + // Un lien de trad a prendre en compte |
|
| 86 | + if ($lier_trad) { |
|
| 87 | + // referencer la traduction |
|
| 88 | + $referencer_traduction = charger_fonction('referencer_traduction', 'action'); |
|
| 89 | + $referencer_traduction($type, $id, $lier_trad); |
|
| 90 | + // actions de recopie de champs / liens sur le nouvel objet créé |
|
| 91 | + $completer_traduction = charger_fonction('completer_traduction', 'inc'); |
|
| 92 | + $err = $completer_traduction($type, $id, $lier_trad); |
|
| 93 | + if ($err) { |
|
| 94 | + $res['message_erreur'] = $err; |
|
| 95 | + return $res; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + $res['message_ok'] = _T('info_modification_enregistree'); |
|
| 100 | + if ($retour) { |
|
| 101 | + if (str_starts_with($retour, 'javascript:')) { |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 103 | + $res['editable'] = true; |
|
| 104 | + } else { |
|
| 105 | + $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
|
| 106 | + } |
|
| 107 | + } |
|
| 108 | + } |
|
| 109 | + |
|
| 110 | + return $res; |
|
| 111 | 111 | } |
| 112 | 112 | |
| 113 | 113 | /** |
@@ -131,29 +131,29 @@ discard block |
||
| 131 | 131 | * Tableau des erreurs |
| 132 | 132 | **/ |
| 133 | 133 | function formulaires_editer_objet_verifier($type, $id = 'new', $oblis = []) { |
| 134 | - $erreurs = []; |
|
| 135 | - if ((int) $id) { |
|
| 136 | - $conflits = controler_contenu($type, $id); |
|
| 137 | - if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | - foreach ($conflits as $champ => $conflit) { |
|
| 139 | - if (!isset($erreurs[$champ])) { |
|
| 140 | - $erreurs[$champ] = ''; |
|
| 141 | - } |
|
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | - } |
|
| 144 | - } |
|
| 145 | - } |
|
| 146 | - foreach ($oblis as $obli) { |
|
| 147 | - $value = _request($obli); |
|
| 148 | - if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | - if (!isset($erreurs[$obli])) { |
|
| 150 | - $erreurs[$obli] = ''; |
|
| 151 | - } |
|
| 152 | - $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | - } |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return $erreurs; |
|
| 134 | + $erreurs = []; |
|
| 135 | + if ((int) $id) { |
|
| 136 | + $conflits = controler_contenu($type, $id); |
|
| 137 | + if ($conflits && (is_countable($conflits) ? count($conflits) : 0)) { |
|
| 138 | + foreach ($conflits as $champ => $conflit) { |
|
| 139 | + if (!isset($erreurs[$champ])) { |
|
| 140 | + $erreurs[$champ] = ''; |
|
| 141 | + } |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 143 | + } |
|
| 144 | + } |
|
| 145 | + } |
|
| 146 | + foreach ($oblis as $obli) { |
|
| 147 | + $value = _request($obli); |
|
| 148 | + if (is_null($value) || !(is_array($value) ? count($value) : strlen((string) $value))) { |
|
| 149 | + if (!isset($erreurs[$obli])) { |
|
| 150 | + $erreurs[$obli] = ''; |
|
| 151 | + } |
|
| 152 | + $erreurs[$obli] .= _T('info_obligatoire'); |
|
| 153 | + } |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return $erreurs; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -198,151 +198,151 @@ discard block |
||
| 198 | 198 | * Environnement du formulaire. |
| 199 | 199 | **/ |
| 200 | 200 | function formulaires_editer_objet_charger( |
| 201 | - $type, |
|
| 202 | - $id = 'new', |
|
| 203 | - $id_parent = 0, |
|
| 204 | - $lier_trad = 0, |
|
| 205 | - $retour = '', |
|
| 206 | - $config_fonc = 'articles_edit_config', |
|
| 207 | - $row = [], |
|
| 208 | - $hidden = '' |
|
| 201 | + $type, |
|
| 202 | + $id = 'new', |
|
| 203 | + $id_parent = 0, |
|
| 204 | + $lier_trad = 0, |
|
| 205 | + $retour = '', |
|
| 206 | + $config_fonc = 'articles_edit_config', |
|
| 207 | + $row = [], |
|
| 208 | + $hidden = '' |
|
| 209 | 209 | ) { |
| 210 | 210 | |
| 211 | - $table_objet = table_objet($type); |
|
| 212 | - $table_objet_sql = table_objet_sql($type); |
|
| 213 | - $id_table_objet = id_table_objet($type); |
|
| 214 | - if (!is_array($row)) { |
|
| 215 | - $row = []; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | - if ( |
|
| 220 | - $config_fonc |
|
| 221 | - && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | - && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | - && in_array($config_fonc, $args) |
|
| 225 | - ) { |
|
| 226 | - $config_fonc = ''; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $new = !is_numeric($id); |
|
| 230 | - $lang_default = ''; |
|
| 231 | - // Appel direct dans un squelette |
|
| 232 | - if (!$row) { |
|
| 233 | - if (!$new || $lier_trad) { |
|
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | - $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | - // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | - $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | - } else { |
|
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | - } |
|
| 241 | - if (!$new) { |
|
| 242 | - $md5 = controles_md5($row ?: []); |
|
| 243 | - } |
|
| 244 | - } |
|
| 245 | - if (!$row) { |
|
| 246 | - $row = []; |
|
| 247 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | - if ($desc = $trouver_table($table_objet)) { |
|
| 249 | - foreach ($desc['field'] as $k => $v) { |
|
| 250 | - $row[$k] = ''; |
|
| 251 | - } |
|
| 252 | - } |
|
| 253 | - } |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | - // (et donc: pas de lien de traduction) |
|
| 258 | - $id = ($new || $lier_trad) |
|
| 259 | - ? 'oui' |
|
| 260 | - : $row[$id_table_objet]; |
|
| 261 | - $row[$id_table_objet] = $id; |
|
| 262 | - |
|
| 263 | - $contexte = $row; |
|
| 264 | - if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | - if (!isset($contexte['id_parent'])) { |
|
| 266 | - unset($contexte['id_rubrique']); |
|
| 267 | - } |
|
| 268 | - $contexte['id_parent'] = $id_parent; |
|
| 269 | - } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | - // id_rubrique dans id_parent si possible |
|
| 271 | - if (isset($contexte['id_rubrique'])) { |
|
| 272 | - $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | - unset($contexte['id_rubrique']); |
|
| 274 | - } else { |
|
| 275 | - $contexte['id_parent'] = ''; |
|
| 276 | - } |
|
| 277 | - if ( |
|
| 278 | - !$contexte['id_parent'] |
|
| 279 | - && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | - ) { |
|
| 281 | - $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | - } |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $config = []; |
|
| 286 | - if ($config_fonc) { |
|
| 287 | - $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | - if (!$lang_default) { |
|
| 289 | - include_spip('inc/session'); |
|
| 290 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | - } |
|
| 292 | - } |
|
| 293 | - $config += [ |
|
| 294 | - 'lignes' => 0, |
|
| 295 | - 'langue' => '', |
|
| 296 | - ]; |
|
| 297 | - |
|
| 298 | - $att_text = " class='textarea' " |
|
| 299 | - . " rows='" |
|
| 300 | - . ($config['lignes'] + 15) |
|
| 301 | - . "' cols='40'"; |
|
| 302 | - |
|
| 303 | - |
|
| 304 | - // on veut conserver la langue de l'interface ; |
|
| 305 | - // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | - // voudrait l'exploiter |
|
| 307 | - if (isset($contexte['lang'])) { |
|
| 308 | - $contexte['langue'] = $contexte['lang']; |
|
| 309 | - unset($contexte['lang']); |
|
| 310 | - } |
|
| 311 | - |
|
| 312 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | - ($lier_trad |
|
| 314 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | - $lier_trad . |
|
| 316 | - "' />" . |
|
| 317 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | - $lang_default . |
|
| 319 | - "' />" |
|
| 320 | - : '') |
|
| 321 | - . $hidden |
|
| 322 | - . ($md5 ?? ''); |
|
| 323 | - |
|
| 324 | - // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | - $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | - |
|
| 327 | - // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | - // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | - // on le garde pour compat |
|
| 330 | - $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | - |
|
| 332 | - // et in fine placer l'autorisation |
|
| 333 | - include_spip('inc/autoriser'); |
|
| 334 | - if ((int) $id) { |
|
| 335 | - if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | - $contexte['editable'] = ''; |
|
| 337 | - } |
|
| 338 | - } |
|
| 339 | - else { |
|
| 340 | - if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | - $contexte['editable'] = ''; |
|
| 342 | - } |
|
| 343 | - } |
|
| 344 | - |
|
| 345 | - return $contexte; |
|
| 211 | + $table_objet = table_objet($type); |
|
| 212 | + $table_objet_sql = table_objet_sql($type); |
|
| 213 | + $id_table_objet = id_table_objet($type); |
|
| 214 | + if (!is_array($row)) { |
|
| 215 | + $row = []; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + // on accepte pas une fonction de config inconnue si elle vient d'un modele |
|
| 219 | + if ( |
|
| 220 | + $config_fonc |
|
| 221 | + && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
|
| 222 | + && $config_fonc !== $table_objet . '_edit_config' |
|
| 223 | + && ($args = test_formulaire_inclus_par_modele()) |
|
| 224 | + && in_array($config_fonc, $args) |
|
| 225 | + ) { |
|
| 226 | + $config_fonc = ''; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $new = !is_numeric($id); |
|
| 230 | + $lang_default = ''; |
|
| 231 | + // Appel direct dans un squelette |
|
| 232 | + if (!$row) { |
|
| 233 | + if (!$new || $lier_trad) { |
|
| 234 | + if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 235 | + $row = $select($id, $id_parent, $lier_trad); |
|
| 236 | + // si on a une fonction precharger, elle pu faire un reglage de langue |
|
| 237 | + $lang_default = (empty($row['lang']) ? null : $row['lang']); |
|
| 238 | + } else { |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 240 | + } |
|
| 241 | + if (!$new) { |
|
| 242 | + $md5 = controles_md5($row ?: []); |
|
| 243 | + } |
|
| 244 | + } |
|
| 245 | + if (!$row) { |
|
| 246 | + $row = []; |
|
| 247 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 248 | + if ($desc = $trouver_table($table_objet)) { |
|
| 249 | + foreach ($desc['field'] as $k => $v) { |
|
| 250 | + $row[$k] = ''; |
|
| 251 | + } |
|
| 252 | + } |
|
| 253 | + } |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + // Gaffe: sans ceci, on ecrase systematiquement l'article d'origine |
|
| 257 | + // (et donc: pas de lien de traduction) |
|
| 258 | + $id = ($new || $lier_trad) |
|
| 259 | + ? 'oui' |
|
| 260 | + : $row[$id_table_objet]; |
|
| 261 | + $row[$id_table_objet] = $id; |
|
| 262 | + |
|
| 263 | + $contexte = $row; |
|
| 264 | + if (is_numeric($id_parent) && strlen($id_parent) && (!isset($contexte['id_parent']) || $new)) { |
|
| 265 | + if (!isset($contexte['id_parent'])) { |
|
| 266 | + unset($contexte['id_rubrique']); |
|
| 267 | + } |
|
| 268 | + $contexte['id_parent'] = $id_parent; |
|
| 269 | + } elseif (!isset($contexte['id_parent'])) { |
|
| 270 | + // id_rubrique dans id_parent si possible |
|
| 271 | + if (isset($contexte['id_rubrique'])) { |
|
| 272 | + $contexte['id_parent'] = $contexte['id_rubrique']; |
|
| 273 | + unset($contexte['id_rubrique']); |
|
| 274 | + } else { |
|
| 275 | + $contexte['id_parent'] = ''; |
|
| 276 | + } |
|
| 277 | + if ( |
|
| 278 | + !$contexte['id_parent'] |
|
| 279 | + && ($preselectionner_parent_nouvel_objet = charger_fonction('preselectionner_parent_nouvel_objet', 'inc', true)) |
|
| 280 | + ) { |
|
| 281 | + $contexte['id_parent'] = $preselectionner_parent_nouvel_objet($type, $row); |
|
| 282 | + } |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $config = []; |
|
| 286 | + if ($config_fonc) { |
|
| 287 | + $contexte['config'] = $config = $config_fonc($contexte); |
|
| 288 | + if (!$lang_default) { |
|
| 289 | + include_spip('inc/session'); |
|
| 290 | + $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 291 | + } |
|
| 292 | + } |
|
| 293 | + $config += [ |
|
| 294 | + 'lignes' => 0, |
|
| 295 | + 'langue' => '', |
|
| 296 | + ]; |
|
| 297 | + |
|
| 298 | + $att_text = " class='textarea' " |
|
| 299 | + . " rows='" |
|
| 300 | + . ($config['lignes'] + 15) |
|
| 301 | + . "' cols='40'"; |
|
| 302 | + |
|
| 303 | + |
|
| 304 | + // on veut conserver la langue de l'interface ; |
|
| 305 | + // on passe cette donnee sous un autre nom, au cas ou le squelette |
|
| 306 | + // voudrait l'exploiter |
|
| 307 | + if (isset($contexte['lang'])) { |
|
| 308 | + $contexte['langue'] = $contexte['lang']; |
|
| 309 | + unset($contexte['lang']); |
|
| 310 | + } |
|
| 311 | + |
|
| 312 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 313 | + ($lier_trad |
|
| 314 | + ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | + $lier_trad . |
|
| 316 | + "' />" . |
|
| 317 | + "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | + $lang_default . |
|
| 319 | + "' />" |
|
| 320 | + : '') |
|
| 321 | + . $hidden |
|
| 322 | + . ($md5 ?? ''); |
|
| 323 | + |
|
| 324 | + // preciser que le formulaire doit passer dans un pipeline |
|
| 325 | + $contexte['_pipeline'] = ['editer_contenu_objet', ['type' => $type, 'id' => $id]]; |
|
| 326 | + |
|
| 327 | + // preciser que le formulaire doit etre securise auteur/action |
|
| 328 | + // n'est plus utile lorsque l'action accepte l'id en argument direct |
|
| 329 | + // on le garde pour compat |
|
| 330 | + $contexte['_action'] = ["editer_$type", $id]; |
|
| 331 | + |
|
| 332 | + // et in fine placer l'autorisation |
|
| 333 | + include_spip('inc/autoriser'); |
|
| 334 | + if ((int) $id) { |
|
| 335 | + if (!autoriser('modifier', $type, (int) $id)) { |
|
| 336 | + $contexte['editable'] = ''; |
|
| 337 | + } |
|
| 338 | + } |
|
| 339 | + else { |
|
| 340 | + if (!autoriser('creer', $type, 0, null, ['id_parent' => $id_parent])) { |
|
| 341 | + $contexte['editable'] = ''; |
|
| 342 | + } |
|
| 343 | + } |
|
| 344 | + |
|
| 345 | + return $contexte; |
|
| 346 | 346 | } |
| 347 | 347 | |
| 348 | 348 | /** |
@@ -353,29 +353,29 @@ discard block |
||
| 353 | 353 | * @return array |
| 354 | 354 | */ |
| 355 | 355 | function coupe_trop_long($texte) { |
| 356 | - $aider = charger_fonction('aider', 'inc'); |
|
| 357 | - if (strlen($texte) > 28 * 1024) { |
|
| 358 | - $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | - if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | - $suite = substr($texte, $pos + 2); |
|
| 363 | - } else { |
|
| 364 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | - if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | - $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | - } else { |
|
| 369 | - $decalage = 1; |
|
| 370 | - } |
|
| 371 | - $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | - $suite = substr($texte, $pos + $decalage); |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - return ([$debut, $suite]); |
|
| 376 | - } else { |
|
| 377 | - return ([$texte, '']); |
|
| 378 | - } |
|
| 356 | + $aider = charger_fonction('aider', 'inc'); |
|
| 357 | + if (strlen($texte) > 28 * 1024) { |
|
| 358 | + $texte = str_replace("\r\n", "\n", $texte); |
|
| 359 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | + if ($pos > 0 && $pos < 32 * 1024) { |
|
| 361 | + $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 362 | + $suite = substr($texte, $pos + 2); |
|
| 363 | + } else { |
|
| 364 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | + if (!($pos > 0 && $pos < 32 * 1024)) { |
|
| 366 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | + $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
|
| 368 | + } else { |
|
| 369 | + $decalage = 1; |
|
| 370 | + } |
|
| 371 | + $debut = substr($texte, 0, $pos + $decalage); // Il faut conserver l'espace s'il y en a un |
|
| 372 | + $suite = substr($texte, $pos + $decalage); |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + return ([$debut, $suite]); |
|
| 376 | + } else { |
|
| 377 | + return ([$texte, '']); |
|
| 378 | + } |
|
| 379 | 379 | } |
| 380 | 380 | |
| 381 | 381 | /** |
@@ -386,13 +386,13 @@ discard block |
||
| 386 | 386 | * @param int $longueur |
| 387 | 387 | */ |
| 388 | 388 | function titre_automatique($champ_titre, $champs_contenu, $longueur = null) { |
| 389 | - if (!_request($champ_titre)) { |
|
| 390 | - $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | - $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | - if ($t) { |
|
| 393 | - set_request($champ_titre, $t); |
|
| 394 | - } |
|
| 395 | - } |
|
| 389 | + if (!_request($champ_titre)) { |
|
| 390 | + $titrer_contenu = charger_fonction('titrer_contenu', 'inc'); |
|
| 391 | + $t = is_null($longueur) ? $titrer_contenu($champs_contenu) : $titrer_contenu($champs_contenu, null, $longueur); |
|
| 392 | + if ($t) { |
|
| 393 | + set_request($champ_titre, $t); |
|
| 394 | + } |
|
| 395 | + } |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -412,20 +412,20 @@ discard block |
||
| 412 | 412 | * @return string |
| 413 | 413 | */ |
| 414 | 414 | function inc_titrer_contenu_dist($champs_contenu, $c = null, $longueur = 50) { |
| 415 | - // trouver un champ texte non vide |
|
| 416 | - $t = ''; |
|
| 417 | - foreach ($champs_contenu as $champ) { |
|
| 418 | - if ($t = _request($champ, $c)) { |
|
| 419 | - break; |
|
| 420 | - } |
|
| 421 | - } |
|
| 422 | - |
|
| 423 | - if ($t) { |
|
| 424 | - include_spip('inc/texte_mini'); |
|
| 425 | - $t = couper($t, $longueur, '...'); |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - return $t; |
|
| 415 | + // trouver un champ texte non vide |
|
| 416 | + $t = ''; |
|
| 417 | + foreach ($champs_contenu as $champ) { |
|
| 418 | + if ($t = _request($champ, $c)) { |
|
| 419 | + break; |
|
| 420 | + } |
|
| 421 | + } |
|
| 422 | + |
|
| 423 | + if ($t) { |
|
| 424 | + include_spip('inc/texte_mini'); |
|
| 425 | + $t = couper($t, $longueur, '...'); |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + return $t; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -447,22 +447,22 @@ discard block |
||
| 447 | 447 | * - array sinon couples ('$prefixe$colonne => md5) |
| 448 | 448 | **/ |
| 449 | 449 | function controles_md5(array $data, string $prefixe = 'ctr_', string $format = 'html') { |
| 450 | - $ctr = []; |
|
| 451 | - foreach ($data as $key => $val) { |
|
| 452 | - $m = md5($val ?? ''); |
|
| 453 | - $k = $prefixe . $key; |
|
| 454 | - |
|
| 455 | - $ctr[$k] = match ($format) { |
|
| 456 | - 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | - default => $m, |
|
| 458 | - }; |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - if ($format === 'html') { |
|
| 462 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | - } else { |
|
| 464 | - return $ctr; |
|
| 465 | - } |
|
| 450 | + $ctr = []; |
|
| 451 | + foreach ($data as $key => $val) { |
|
| 452 | + $m = md5($val ?? ''); |
|
| 453 | + $k = $prefixe . $key; |
|
| 454 | + |
|
| 455 | + $ctr[$k] = match ($format) { |
|
| 456 | + 'html' => "<input type='hidden' value='$m' name='$k' />", |
|
| 457 | + default => $m, |
|
| 458 | + }; |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + if ($format === 'html') { |
|
| 462 | + return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 463 | + } else { |
|
| 464 | + return $ctr; |
|
| 465 | + } |
|
| 466 | 466 | } |
| 467 | 467 | |
| 468 | 468 | /** |
@@ -501,80 +501,80 @@ discard block |
||
| 501 | 501 | * - post : le contenu posté |
| 502 | 502 | **/ |
| 503 | 503 | function controler_contenu($type, $id, $options = [], $c = false, $serveur = '') { |
| 504 | - include_spip('inc/filtres'); |
|
| 505 | - |
|
| 506 | - $table_objet = table_objet($type); |
|
| 507 | - $spip_table_objet = table_objet_sql($type); |
|
| 508 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | - $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | - |
|
| 511 | - // Appels incomplets (sans $c) |
|
| 512 | - if (!is_array($c)) { |
|
| 513 | - $c = []; |
|
| 514 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | - if (_request($champ)) { |
|
| 516 | - $c[$champ] = _request($champ); |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - |
|
| 521 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | - // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | - // il faut passer par instituer_XX() |
|
| 524 | - // TODO: faut-il passer ces variables interdites |
|
| 525 | - // dans un fichier de description separe ? |
|
| 526 | - unset($c['statut']); |
|
| 527 | - unset($c['id_parent']); |
|
| 528 | - unset($c['id_rubrique']); |
|
| 529 | - unset($c['id_secteur']); |
|
| 530 | - |
|
| 531 | - // Gerer les champs non vides |
|
| 532 | - if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | - if ($c[$champ] === '') { |
|
| 535 | - $c[$champ] = $sinon; |
|
| 536 | - } |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - |
|
| 540 | - // N'accepter que les champs qui existent |
|
| 541 | - // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | - $champs = []; |
|
| 543 | - foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | - if (isset($c[$champ])) { |
|
| 545 | - $champs[$champ] = $c[$champ]; |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // Nettoyer les valeurs |
|
| 550 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | - |
|
| 552 | - // Envoyer aux plugins |
|
| 553 | - $champs = pipeline( |
|
| 554 | - 'pre_edition', |
|
| 555 | - [ |
|
| 556 | - 'args' => [ |
|
| 557 | - 'table' => $spip_table_objet, // compatibilite |
|
| 558 | - 'table_objet' => $table_objet, |
|
| 559 | - 'spip_table_objet' => $spip_table_objet, |
|
| 560 | - 'type' => $type, |
|
| 561 | - 'id_objet' => $id, |
|
| 562 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | - 'action' => 'controler', |
|
| 564 | - 'serveur' => $serveur, |
|
| 565 | - ], |
|
| 566 | - 'data' => $champs |
|
| 567 | - ] |
|
| 568 | - ); |
|
| 569 | - |
|
| 570 | - if (!$champs) { |
|
| 571 | - return false; |
|
| 572 | - } |
|
| 573 | - |
|
| 574 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | - $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | - |
|
| 577 | - return $conflits; |
|
| 504 | + include_spip('inc/filtres'); |
|
| 505 | + |
|
| 506 | + $table_objet = table_objet($type); |
|
| 507 | + $spip_table_objet = table_objet_sql($type); |
|
| 508 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 509 | + $desc = $trouver_table($table_objet, $serveur); |
|
| 510 | + |
|
| 511 | + // Appels incomplets (sans $c) |
|
| 512 | + if (!is_array($c)) { |
|
| 513 | + $c = []; |
|
| 514 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 515 | + if (_request($champ)) { |
|
| 516 | + $c[$champ] = _request($champ); |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + |
|
| 521 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 522 | + // car elles ne relevent pas de autoriser(article, modifier) ; |
|
| 523 | + // il faut passer par instituer_XX() |
|
| 524 | + // TODO: faut-il passer ces variables interdites |
|
| 525 | + // dans un fichier de description separe ? |
|
| 526 | + unset($c['statut']); |
|
| 527 | + unset($c['id_parent']); |
|
| 528 | + unset($c['id_rubrique']); |
|
| 529 | + unset($c['id_secteur']); |
|
| 530 | + |
|
| 531 | + // Gerer les champs non vides |
|
| 532 | + if (isset($options['nonvide']) && is_array($options['nonvide'])) { |
|
| 533 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 534 | + if ($c[$champ] === '') { |
|
| 535 | + $c[$champ] = $sinon; |
|
| 536 | + } |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + |
|
| 540 | + // N'accepter que les champs qui existent |
|
| 541 | + // [TODO] ici aussi on peut valider les contenus en fonction du type |
|
| 542 | + $champs = []; |
|
| 543 | + foreach ($desc['field'] as $champ => $ignore) { |
|
| 544 | + if (isset($c[$champ])) { |
|
| 545 | + $champs[$champ] = $c[$champ]; |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // Nettoyer les valeurs |
|
| 550 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 551 | + |
|
| 552 | + // Envoyer aux plugins |
|
| 553 | + $champs = pipeline( |
|
| 554 | + 'pre_edition', |
|
| 555 | + [ |
|
| 556 | + 'args' => [ |
|
| 557 | + 'table' => $spip_table_objet, // compatibilite |
|
| 558 | + 'table_objet' => $table_objet, |
|
| 559 | + 'spip_table_objet' => $spip_table_objet, |
|
| 560 | + 'type' => $type, |
|
| 561 | + 'id_objet' => $id, |
|
| 562 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 563 | + 'action' => 'controler', |
|
| 564 | + 'serveur' => $serveur, |
|
| 565 | + ], |
|
| 566 | + 'data' => $champs |
|
| 567 | + ] |
|
| 568 | + ); |
|
| 569 | + |
|
| 570 | + if (!$champs) { |
|
| 571 | + return false; |
|
| 572 | + } |
|
| 573 | + |
|
| 574 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 575 | + $conflits = controler_md5($champs, $_POST, $type, $id, $serveur, $options['prefix'] ?? 'ctr_'); |
|
| 576 | + |
|
| 577 | + return $conflits; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | |
@@ -604,66 +604,66 @@ discard block |
||
| 604 | 604 | * - post : le contenu posté |
| 605 | 605 | **/ |
| 606 | 606 | function controler_md5(&$champs, $ctr, $type, $id, $serveur, $prefix = 'ctr_') { |
| 607 | - $spip_table_objet = table_objet_sql($type); |
|
| 608 | - $id_table_objet = id_table_objet($type); |
|
| 609 | - |
|
| 610 | - // Controle des MD5 envoyes |
|
| 611 | - // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | - // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | - foreach ($champs as $key => $val) { |
|
| 614 | - if ( |
|
| 615 | - isset($ctr[$prefix . $key]) |
|
| 616 | - && ($m = $ctr[$prefix . $key]) |
|
| 617 | - && (is_scalar($val) && $m == md5($val)) |
|
| 618 | - ) { |
|
| 619 | - unset($champs[$key]); |
|
| 620 | - } |
|
| 621 | - } |
|
| 622 | - if (!$champs) { |
|
| 623 | - return; |
|
| 624 | - } |
|
| 625 | - |
|
| 626 | - // On veut savoir si notre modif va avoir un impact |
|
| 627 | - // par rapport aux donnees contenues dans la base |
|
| 628 | - // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | - $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | - $intact = true; |
|
| 631 | - foreach ($champs as $ch => $val) { |
|
| 632 | - $intact &= ($s[$ch] == $val); |
|
| 633 | - } |
|
| 634 | - if ($intact) { |
|
| 635 | - return; |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - // Detection de conflits : |
|
| 639 | - // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | - // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | - // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | - // de conflit. |
|
| 643 | - $ctrh = $ctrq = $conflits = []; |
|
| 644 | - foreach (array_keys($champs) as $key) { |
|
| 645 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | - $ctrh[$key] = $m; |
|
| 647 | - $ctrq[] = $key; |
|
| 648 | - } |
|
| 649 | - } |
|
| 650 | - if ($ctrq) { |
|
| 651 | - $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | - foreach ($ctrh as $key => $m) { |
|
| 653 | - if ( |
|
| 654 | - $m != md5((string) $ctrq[$key]) |
|
| 655 | - && $champs[$key] !== $ctrq[$key] |
|
| 656 | - ) { |
|
| 657 | - $conflits[$key] = [ |
|
| 658 | - 'base' => $ctrq[$key], |
|
| 659 | - 'post' => $champs[$key] |
|
| 660 | - ]; |
|
| 661 | - unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } |
|
| 665 | - |
|
| 666 | - return $conflits; |
|
| 607 | + $spip_table_objet = table_objet_sql($type); |
|
| 608 | + $id_table_objet = id_table_objet($type); |
|
| 609 | + |
|
| 610 | + // Controle des MD5 envoyes |
|
| 611 | + // On elimine les donnees non modifiees par le formulaire (mais |
|
| 612 | + // potentiellement modifiees entre temps par un autre utilisateur) |
|
| 613 | + foreach ($champs as $key => $val) { |
|
| 614 | + if ( |
|
| 615 | + isset($ctr[$prefix . $key]) |
|
| 616 | + && ($m = $ctr[$prefix . $key]) |
|
| 617 | + && (is_scalar($val) && $m == md5($val)) |
|
| 618 | + ) { |
|
| 619 | + unset($champs[$key]); |
|
| 620 | + } |
|
| 621 | + } |
|
| 622 | + if (!$champs) { |
|
| 623 | + return; |
|
| 624 | + } |
|
| 625 | + |
|
| 626 | + // On veut savoir si notre modif va avoir un impact |
|
| 627 | + // par rapport aux donnees contenues dans la base |
|
| 628 | + // (qui peuvent etre differentes de celles ayant servi a calculer le ctr) |
|
| 629 | + $s = sql_fetsel(array_keys($champs), $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 630 | + $intact = true; |
|
| 631 | + foreach ($champs as $ch => $val) { |
|
| 632 | + $intact &= ($s[$ch] == $val); |
|
| 633 | + } |
|
| 634 | + if ($intact) { |
|
| 635 | + return; |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + // Detection de conflits : |
|
| 639 | + // On verifie si notre modif ne provient pas d'un formulaire |
|
| 640 | + // genere a partir de donnees modifiees dans l'intervalle ; ici |
|
| 641 | + // on compare a ce qui est dans la base, et on bloque en cas |
|
| 642 | + // de conflit. |
|
| 643 | + $ctrh = $ctrq = $conflits = []; |
|
| 644 | + foreach (array_keys($champs) as $key) { |
|
| 645 | + if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 646 | + $ctrh[$key] = $m; |
|
| 647 | + $ctrq[] = $key; |
|
| 648 | + } |
|
| 649 | + } |
|
| 650 | + if ($ctrq) { |
|
| 651 | + $ctrq = sql_fetsel($ctrq, $spip_table_objet, "$id_table_objet=$id", $serveur); |
|
| 652 | + foreach ($ctrh as $key => $m) { |
|
| 653 | + if ( |
|
| 654 | + $m != md5((string) $ctrq[$key]) |
|
| 655 | + && $champs[$key] !== $ctrq[$key] |
|
| 656 | + ) { |
|
| 657 | + $conflits[$key] = [ |
|
| 658 | + 'base' => $ctrq[$key], |
|
| 659 | + 'post' => $champs[$key] |
|
| 660 | + ]; |
|
| 661 | + unset($champs[$key]); # stocker quand meme les modifs ? |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } |
|
| 665 | + |
|
| 666 | + return $conflits; |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | /** |
@@ -675,9 +675,9 @@ discard block |
||
| 675 | 675 | * @return string |
| 676 | 676 | */ |
| 677 | 677 | function display_conflit_champ($x) { |
| 678 | - if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | - } else { |
|
| 681 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | - } |
|
| 678 | + if (strstr($x, "\n") || strlen($x) > 80) { |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 680 | + } else { |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 682 | + } |
|
| 683 | 683 | } |
@@ -99,7 +99,7 @@ discard block |
||
| 99 | 99 | $res['message_ok'] = _T('info_modification_enregistree'); |
| 100 | 100 | if ($retour) { |
| 101 | 101 | if (str_starts_with($retour, 'javascript:')) { |
| 102 | - $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/' . substr($retour, 11) . '/*]]>*/</script>'; |
|
| 102 | + $res['message_ok'] .= '<script type="text/javascript">/*<![CDATA[*/'.substr($retour, 11).'/*]]>*/</script>'; |
|
| 103 | 103 | $res['editable'] = true; |
| 104 | 104 | } else { |
| 105 | 105 | $res['redirect'] = parametre_url($retour, $id_table_objet, $id); |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | if (!isset($erreurs[$champ])) { |
| 140 | 140 | $erreurs[$champ] = ''; |
| 141 | 141 | } |
| 142 | - $erreurs[$champ] .= _T('alerte_modif_info_concourante') . "<br /><textarea readonly='readonly' class='forml'>" . entites_html($conflit['base']) . '</textarea>'; |
|
| 142 | + $erreurs[$champ] .= _T('alerte_modif_info_concourante')."<br /><textarea readonly='readonly' class='forml'>".entites_html($conflit['base']).'</textarea>'; |
|
| 143 | 143 | } |
| 144 | 144 | } |
| 145 | 145 | } |
@@ -219,7 +219,7 @@ discard block |
||
| 219 | 219 | if ( |
| 220 | 220 | $config_fonc |
| 221 | 221 | && !in_array($config_fonc, ['articles_edit_config', 'rubriques_edit_config', 'auteurs_edit_config']) |
| 222 | - && $config_fonc !== $table_objet . '_edit_config' |
|
| 222 | + && $config_fonc !== $table_objet.'_edit_config' |
|
| 223 | 223 | && ($args = test_formulaire_inclus_par_modele()) |
| 224 | 224 | && in_array($config_fonc, $args) |
| 225 | 225 | ) { |
@@ -231,12 +231,12 @@ discard block |
||
| 231 | 231 | // Appel direct dans un squelette |
| 232 | 232 | if (!$row) { |
| 233 | 233 | if (!$new || $lier_trad) { |
| 234 | - if ($select = charger_fonction('precharger_' . $type, 'inc', true)) { |
|
| 234 | + if ($select = charger_fonction('precharger_'.$type, 'inc', true)) { |
|
| 235 | 235 | $row = $select($id, $id_parent, $lier_trad); |
| 236 | 236 | // si on a une fonction precharger, elle pu faire un reglage de langue |
| 237 | 237 | $lang_default = (empty($row['lang']) ? null : $row['lang']); |
| 238 | 238 | } else { |
| 239 | - $row = sql_fetsel('*', $table_objet_sql, $id_table_objet . '=' . (int) $id); |
|
| 239 | + $row = sql_fetsel('*', $table_objet_sql, $id_table_objet.'='.(int) $id); |
|
| 240 | 240 | } |
| 241 | 241 | if (!$new) { |
| 242 | 242 | $md5 = controles_md5($row ?: []); |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | $contexte['config'] = $config = $config_fonc($contexte); |
| 288 | 288 | if (!$lang_default) { |
| 289 | 289 | include_spip('inc/session'); |
| 290 | - $lang_default = $config['langue'] ?? session_get('lang') ; |
|
| 290 | + $lang_default = $config['langue'] ?? session_get('lang'); |
|
| 291 | 291 | } |
| 292 | 292 | } |
| 293 | 293 | $config += [ |
@@ -309,13 +309,13 @@ discard block |
||
| 309 | 309 | unset($contexte['lang']); |
| 310 | 310 | } |
| 311 | 311 | |
| 312 | - $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n" . |
|
| 312 | + $contexte['_hidden'] = "<input type='hidden' name='editer_$type' value='oui' />\n". |
|
| 313 | 313 | ($lier_trad |
| 314 | - ? "\n<input type='hidden' name='lier_trad' value='" . |
|
| 315 | - $lier_trad . |
|
| 316 | - "' />" . |
|
| 317 | - "\n<input type='hidden' name='changer_lang' value='" . |
|
| 318 | - $lang_default . |
|
| 314 | + ? "\n<input type='hidden' name='lier_trad' value='". |
|
| 315 | + $lier_trad. |
|
| 316 | + "' />". |
|
| 317 | + "\n<input type='hidden' name='changer_lang' value='". |
|
| 318 | + $lang_default. |
|
| 319 | 319 | "' />" |
| 320 | 320 | : '') |
| 321 | 321 | . $hidden |
@@ -356,14 +356,14 @@ discard block |
||
| 356 | 356 | $aider = charger_fonction('aider', 'inc'); |
| 357 | 357 | if (strlen($texte) > 28 * 1024) { |
| 358 | 358 | $texte = str_replace("\r\n", "\n", $texte); |
| 359 | - $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 359 | + $pos = strpos($texte, "\n\n", 28 * 1024); // coupe para > 28 ko |
|
| 360 | 360 | if ($pos > 0 && $pos < 32 * 1024) { |
| 361 | - $debut = substr($texte, 0, $pos) . "\n\n<!--SPIP-->\n"; |
|
| 361 | + $debut = substr($texte, 0, $pos)."\n\n<!--SPIP-->\n"; |
|
| 362 | 362 | $suite = substr($texte, $pos + 2); |
| 363 | 363 | } else { |
| 364 | - $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 364 | + $pos = strpos($texte, ' ', 28 * 1024); // sinon coupe espace |
|
| 365 | 365 | if (!($pos > 0 && $pos < 32 * 1024)) { |
| 366 | - $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 366 | + $pos = 28 * 1024; // au pire (pas d'espace trouv'e) |
|
| 367 | 367 | $decalage = 0; // si y'a pas d'espace, il ne faut pas perdre le caract`ere |
| 368 | 368 | } else { |
| 369 | 369 | $decalage = 1; |
@@ -450,7 +450,7 @@ discard block |
||
| 450 | 450 | $ctr = []; |
| 451 | 451 | foreach ($data as $key => $val) { |
| 452 | 452 | $m = md5($val ?? ''); |
| 453 | - $k = $prefixe . $key; |
|
| 453 | + $k = $prefixe.$key; |
|
| 454 | 454 | |
| 455 | 455 | $ctr[$k] = match ($format) { |
| 456 | 456 | 'html' => "<input type='hidden' value='$m' name='$k' />", |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | if ($format === 'html') { |
| 462 | - return "\n\n<!-- controles md5 -->\n" . implode("\n", $ctr) . "\n\n"; |
|
| 462 | + return "\n\n<!-- controles md5 -->\n".implode("\n", $ctr)."\n\n"; |
|
| 463 | 463 | } else { |
| 464 | 464 | return $ctr; |
| 465 | 465 | } |
@@ -612,8 +612,8 @@ discard block |
||
| 612 | 612 | // potentiellement modifiees entre temps par un autre utilisateur) |
| 613 | 613 | foreach ($champs as $key => $val) { |
| 614 | 614 | if ( |
| 615 | - isset($ctr[$prefix . $key]) |
|
| 616 | - && ($m = $ctr[$prefix . $key]) |
|
| 615 | + isset($ctr[$prefix.$key]) |
|
| 616 | + && ($m = $ctr[$prefix.$key]) |
|
| 617 | 617 | && (is_scalar($val) && $m == md5($val)) |
| 618 | 618 | ) { |
| 619 | 619 | unset($champs[$key]); |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | // de conflit. |
| 643 | 643 | $ctrh = $ctrq = $conflits = []; |
| 644 | 644 | foreach (array_keys($champs) as $key) { |
| 645 | - if (isset($ctr[$prefix . $key]) && ($m = $ctr[$prefix . $key])) { |
|
| 645 | + if (isset($ctr[$prefix.$key]) && ($m = $ctr[$prefix.$key])) { |
|
| 646 | 646 | $ctrh[$key] = $m; |
| 647 | 647 | $ctrq[] = $key; |
| 648 | 648 | } |
@@ -676,8 +676,8 @@ discard block |
||
| 676 | 676 | */ |
| 677 | 677 | function display_conflit_champ($x) { |
| 678 | 678 | if (strstr($x, "\n") || strlen($x) > 80) { |
| 679 | - return "<textarea style='width:99%; height:10em;'>" . entites_html($x) . "</textarea>\n"; |
|
| 679 | + return "<textarea style='width:99%; height:10em;'>".entites_html($x)."</textarea>\n"; |
|
| 680 | 680 | } else { |
| 681 | - return "<input type='text' size='40' style='width:99%' value=\"" . entites_html($x) . "\" />\n"; |
|
| 681 | + return "<input type='text' size='40' style='width:99%' value=\"".entites_html($x)."\" />\n"; |
|
| 682 | 682 | } |
| 683 | 683 | } |
@@ -44,10 +44,10 @@ discard block |
||
| 44 | 44 | } |
| 45 | 45 | |
| 46 | 46 | if ($query) { |
| 47 | - $url .= '?' . $query; |
|
| 47 | + $url .= '?'.$query; |
|
| 48 | 48 | } |
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/'.preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
| 78 | 78 | $r = array_pad($r, 3, ''); |
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 80 | + return $r[1].resolve_path($r[2]); |
|
| 81 | 81 | } |
| 82 | 82 | |
| 83 | 83 | # L'url site spip est un lien absolu aussi |
@@ -97,10 +97,10 @@ discard block |
||
| 97 | 97 | $hash = $regs[5] ?? ''; |
| 98 | 98 | } |
| 99 | 99 | return match (substr($lien, 0, 1)) { |
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 100 | + '/' => $debut.resolve_path($lien), |
|
| 101 | + '#' => $debut.resolve_path($dir.$mot.$get.$lien), |
|
| 102 | + '' => $debut.resolve_path($dir.$mot.$get.$hash), |
|
| 103 | + default => $debut.resolve_path($dir.$lien), |
|
| 104 | 104 | }; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -129,7 +129,7 @@ discard block |
||
| 129 | 129 | return ''; |
| 130 | 130 | } |
| 131 | 131 | if (!$base) { |
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 132 | + $base = url_de_base().(_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | 133 | } |
| 134 | 134 | |
| 135 | 135 | return suivre_lien($base, $url); |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | * @param array $protocoles_autorises |
| 153 | 153 | * @return bool |
| 154 | 154 | */ |
| 155 | -function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
|
| 155 | +function protocole_verifier($url_absolue, $protocoles_autorises = ['http', 'https']) { |
|
| 156 | 156 | |
| 157 | 157 | if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
| 158 | 158 | $protocole = $m[1]; |
@@ -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 | |
@@ -34,20 +34,20 @@ discard block |
||
| 34 | 34 | * @return string URL nettoyée |
| 35 | 35 | **/ |
| 36 | 36 | function resolve_path($url) { |
| 37 | - [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | - while ( |
|
| 39 | - preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | - || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | - || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | - ) { |
|
| 43 | - $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | - } |
|
| 37 | + [$url, $query] = array_pad(explode('?', $url, 2), 2, null); |
|
| 38 | + while ( |
|
| 39 | + preg_match(',/\.?/,', (string) $url, $regs) # supprime // et /./ |
|
| 40 | + || preg_match(',/[^/]*/\.\./,S', (string) $url, $regs) # supprime /toto/../ |
|
| 41 | + || preg_match(',^/\.\./,S', (string) $url, $regs) # supprime les /../ du haut |
|
| 42 | + ) { |
|
| 43 | + $url = str_replace($regs[0], '/', (string) $url); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | - if ($query) { |
|
| 47 | - $url .= '?' . $query; |
|
| 48 | - } |
|
| 46 | + if ($query) { |
|
| 47 | + $url .= '?' . $query; |
|
| 48 | + } |
|
| 49 | 49 | |
| 50 | - return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 50 | + return '/' . preg_replace(',^/,S', '', (string) $url); |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -68,40 +68,40 @@ discard block |
||
| 68 | 68 | **/ |
| 69 | 69 | function suivre_lien($url, $lien) { |
| 70 | 70 | |
| 71 | - $mot = null; |
|
| 72 | - $get = null; |
|
| 73 | - $hash = null; |
|
| 74 | - if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | - return $lien; |
|
| 76 | - } |
|
| 77 | - if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | - $r = array_pad($r, 3, ''); |
|
| 71 | + $mot = null; |
|
| 72 | + $get = null; |
|
| 73 | + $hash = null; |
|
| 74 | + if (preg_match(',^(mailto|javascript|data|tel|callto|file|ftp):,iS', $lien)) { |
|
| 75 | + return $lien; |
|
| 76 | + } |
|
| 77 | + if (preg_match(';^((?:[a-z]{3,33}:)?//.*?)(/.*)?$;iS', $lien, $r)) { |
|
| 78 | + $r = array_pad($r, 3, ''); |
|
| 79 | 79 | |
| 80 | - return $r[1] . resolve_path($r[2]); |
|
| 81 | - } |
|
| 80 | + return $r[1] . resolve_path($r[2]); |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - # L'url site spip est un lien absolu aussi |
|
| 84 | - if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | - return $lien; |
|
| 86 | - } |
|
| 83 | + # L'url site spip est un lien absolu aussi |
|
| 84 | + if (isset($GLOBALS['meta']['adresse_site']) && $lien == $GLOBALS['meta']['adresse_site']) { |
|
| 85 | + return $lien; |
|
| 86 | + } |
|
| 87 | 87 | |
| 88 | - # lien relatif, il faut verifier l'url de base |
|
| 89 | - # commencer par virer la chaine de get de l'url de base |
|
| 90 | - $dir = '/'; |
|
| 91 | - $debut = ''; |
|
| 92 | - if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | - $debut = $regs[1]; |
|
| 94 | - $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | - $mot = $regs[3]; |
|
| 96 | - $get = $regs[4] ?? ''; |
|
| 97 | - $hash = $regs[5] ?? ''; |
|
| 98 | - } |
|
| 99 | - return match (substr($lien, 0, 1)) { |
|
| 100 | - '/' => $debut . resolve_path($lien), |
|
| 101 | - '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | - '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | - default => $debut . resolve_path($dir . $lien), |
|
| 104 | - }; |
|
| 88 | + # lien relatif, il faut verifier l'url de base |
|
| 89 | + # commencer par virer la chaine de get de l'url de base |
|
| 90 | + $dir = '/'; |
|
| 91 | + $debut = ''; |
|
| 92 | + if (preg_match(';^((?:[a-z]{3,7}:)?//[^/]+)(/.*?/?)?([^/#?]*)([?][^#]*)?(#.*)?$;S', $url, $regs)) { |
|
| 93 | + $debut = $regs[1]; |
|
| 94 | + $dir = strlen($regs[2]) ? $regs[2] : '/'; |
|
| 95 | + $mot = $regs[3]; |
|
| 96 | + $get = $regs[4] ?? ''; |
|
| 97 | + $hash = $regs[5] ?? ''; |
|
| 98 | + } |
|
| 99 | + return match (substr($lien, 0, 1)) { |
|
| 100 | + '/' => $debut . resolve_path($lien), |
|
| 101 | + '#' => $debut . resolve_path($dir . $mot . $get . $lien), |
|
| 102 | + '' => $debut . resolve_path($dir . $mot . $get . $hash), |
|
| 103 | + default => $debut . resolve_path($dir . $lien), |
|
| 104 | + }; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | |
@@ -124,15 +124,15 @@ discard block |
||
| 124 | 124 | * @return string texte ou URL (en absolus) |
| 125 | 125 | **/ |
| 126 | 126 | function url_absolue($url, $base = '') { |
| 127 | - $url = trim((string) $url); |
|
| 128 | - if (strlen($url = trim($url)) == 0) { |
|
| 129 | - return ''; |
|
| 130 | - } |
|
| 131 | - if (!$base) { |
|
| 132 | - $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | - } |
|
| 127 | + $url = trim((string) $url); |
|
| 128 | + if (strlen($url = trim($url)) == 0) { |
|
| 129 | + return ''; |
|
| 130 | + } |
|
| 131 | + if (!$base) { |
|
| 132 | + $base = url_de_base() . (_DIR_RACINE ? _DIR_RESTREINT_ABS : ''); |
|
| 133 | + } |
|
| 134 | 134 | |
| 135 | - return suivre_lien($base, $url); |
|
| 135 | + return suivre_lien($base, $url); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -143,7 +143,7 @@ discard block |
||
| 143 | 143 | * @return string |
| 144 | 144 | */ |
| 145 | 145 | function protocole_implicite($url_absolue) { |
| 146 | - return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 146 | + return preg_replace(';^[a-z]{3,7}://;i', '//', $url_absolue); |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -154,16 +154,16 @@ discard block |
||
| 154 | 154 | */ |
| 155 | 155 | function protocole_verifier($url_absolue, $protocoles_autorises = ['http','https']) { |
| 156 | 156 | |
| 157 | - if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | - $protocole = $m[1]; |
|
| 159 | - if ( |
|
| 160 | - in_array($protocole, $protocoles_autorises) |
|
| 161 | - || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | - ) { |
|
| 163 | - return true; |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - return false; |
|
| 157 | + if (preg_match(';^([a-z]{3,7})://;i', $url_absolue, $m)) { |
|
| 158 | + $protocole = $m[1]; |
|
| 159 | + if ( |
|
| 160 | + in_array($protocole, $protocoles_autorises) |
|
| 161 | + || in_array(strtolower($protocole), array_map('strtolower', $protocoles_autorises)) |
|
| 162 | + ) { |
|
| 163 | + return true; |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + return false; |
|
| 167 | 167 | } |
| 168 | 168 | |
| 169 | 169 | /** |
@@ -180,31 +180,31 @@ discard block |
||
| 180 | 180 | * @return string texte avec des URLs absolues |
| 181 | 181 | **/ |
| 182 | 182 | function liens_absolus($texte, $base = '') { |
| 183 | - if ($texte === null || $texte === '') { |
|
| 184 | - return ''; |
|
| 185 | - } |
|
| 186 | - if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | - if (!function_exists('extraire_attribut')) { |
|
| 188 | - include_spip('inc/filtres'); |
|
| 189 | - } |
|
| 190 | - foreach ($liens as $lien) { |
|
| 191 | - foreach (['href', 'src'] as $attr) { |
|
| 192 | - $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | - if ( |
|
| 194 | - strlen((string) $href) > 0 |
|
| 195 | - && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | - ) { |
|
| 197 | - $abs = url_absolue($href, $base); |
|
| 198 | - if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) { |
|
| 199 | - $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | - $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | - } |
|
| 202 | - } |
|
| 203 | - } |
|
| 204 | - } |
|
| 205 | - } |
|
| 183 | + if ($texte === null || $texte === '') { |
|
| 184 | + return ''; |
|
| 185 | + } |
|
| 186 | + if (preg_match_all(',(<(a|link|image|img|script)\s[^<>]*(href|src)=[^<>]*>),imsS', $texte, $liens, PREG_SET_ORDER)) { |
|
| 187 | + if (!function_exists('extraire_attribut')) { |
|
| 188 | + include_spip('inc/filtres'); |
|
| 189 | + } |
|
| 190 | + foreach ($liens as $lien) { |
|
| 191 | + foreach (['href', 'src'] as $attr) { |
|
| 192 | + $href = extraire_attribut($lien[0], $attr) ?? ''; |
|
| 193 | + if ( |
|
| 194 | + strlen((string) $href) > 0 |
|
| 195 | + && !preg_match(';^((?:[a-z]{3,7}:)?//);iS', (string) $href) |
|
| 196 | + ) { |
|
| 197 | + $abs = url_absolue($href, $base); |
|
| 198 | + if (rtrim((string) $href, '/') !== rtrim($abs, '/') && !preg_match('/^#/', (string) $href)) { |
|
| 199 | + $texte_lien = inserer_attribut($lien[0], $attr, $abs); |
|
| 200 | + $texte = str_replace($lien[0], $texte_lien, $texte); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | + } |
|
| 204 | + } |
|
| 205 | + } |
|
| 206 | 206 | |
| 207 | - return $texte; |
|
| 207 | + return $texte; |
|
| 208 | 208 | } |
| 209 | 209 | |
| 210 | 210 | |
@@ -222,12 +222,12 @@ discard block |
||
| 222 | 222 | * @return string texte ou URL (en absolus) |
| 223 | 223 | **/ |
| 224 | 224 | function abs_url($texte, $base = '') { |
| 225 | - trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | - if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | - return url_absolue($texte, $base); |
|
| 228 | - } else { |
|
| 229 | - return liens_absolus($texte, $base); |
|
| 230 | - } |
|
| 225 | + trigger_deprecation('spip', '5.0', sprintf('Using "%s" is deprecated. Use "%s" or "%s"', __FUNCTION__, 'url_absolue', 'liens_absolus')); |
|
| 226 | + if ($GLOBALS['mode_abs_url'] == 'url') { |
|
| 227 | + return url_absolue($texte, $base); |
|
| 228 | + } else { |
|
| 229 | + return liens_absolus($texte, $base); |
|
| 230 | + } |
|
| 231 | 231 | } |
| 232 | 232 | |
| 233 | 233 | /** |
@@ -240,11 +240,11 @@ discard block |
||
| 240 | 240 | * @return string |
| 241 | 241 | */ |
| 242 | 242 | function spip_htmlspecialchars($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 243 | - if (is_null($flags)) { |
|
| 244 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | - } |
|
| 243 | + if (is_null($flags)) { |
|
| 244 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 245 | + } |
|
| 246 | 246 | |
| 247 | - return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 247 | + return htmlspecialchars($string, $flags, $encoding, $double_encode); |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | /** |
@@ -257,9 +257,9 @@ discard block |
||
| 257 | 257 | * @return string |
| 258 | 258 | */ |
| 259 | 259 | function spip_htmlentities($string, $flags = null, $encoding = 'UTF-8', $double_encode = true) { |
| 260 | - if (is_null($flags)) { |
|
| 261 | - $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | - } |
|
| 260 | + if (is_null($flags)) { |
|
| 261 | + $flags = ENT_COMPAT | ENT_HTML401; |
|
| 262 | + } |
|
| 263 | 263 | |
| 264 | - return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 264 | + return htmlentities($string, $flags, $encoding, $double_encode); |
|
| 265 | 265 | } |
@@ -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 | } |
@@ -136,7 +136,7 @@ |
||
| 136 | 136 | $p !== false |
| 137 | 137 | && ($morceau = substr($txt, $d, $p - $d)) |
| 138 | 138 | && ($nopen += preg_match_all( |
| 139 | - '{<' . preg_quote((string) $closing_tag) . '(\s*>|\s[^>]*[^/>]>)}is', |
|
| 139 | + '{<'.preg_quote((string) $closing_tag).'(\s*>|\s[^>]*[^/>]>)}is', |
|
| 140 | 140 | $morceau, |
| 141 | 141 | $matches, |
| 142 | 142 | PREG_SET_ORDER |
@@ -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 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | include_spip('inc/texte'); |
| 20 | 20 | $titre = $descriptif = ''; |
| 21 | 21 | if ($type === 'rubrique') { |
| 22 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . (int) $id); |
|
| 22 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.(int) $id); |
|
| 23 | 23 | if ($row) { |
| 24 | 24 | $titre = typo($row['titre']); |
| 25 | 25 | $descriptif = propre($row['descriptif']); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | include_spip('inc/filtres_images_mini'); |
| 42 | 42 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 43 | 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>"; |
|
| 44 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | 45 | } |
| 46 | 46 | } |
| 47 | 47 | } |
@@ -62,21 +62,21 @@ discard block |
||
| 62 | 62 | ' ' |
| 63 | 63 | ); |
| 64 | 64 | |
| 65 | - $js_func = $do . '_selection_titre'; |
|
| 65 | + $js_func = $do.'_selection_titre'; |
|
| 66 | 66 | |
| 67 | 67 | return "<div style='display: none;'>" |
| 68 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 69 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 68 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 69 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 70 | 70 | . entites_html($titre) |
| 71 | 71 | . '" />' |
| 72 | 72 | . '</div>' |
| 73 | 73 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 74 | 74 | . '<div class="informer__item">' |
| 75 | 75 | . ($res ?: '') |
| 76 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 77 | - . ($descriptif ? "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>' : '') |
|
| 76 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 77 | + . ($descriptif ? "<div class='informer__descriptif'>".safehtml($descriptif).'</div>' : '') |
|
| 78 | 78 | . '</div>' |
| 79 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 79 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 80 | 80 | . "<input type='submit' class='fondo btn submit' value='" |
| 81 | 81 | . _T('bouton_choisir') |
| 82 | 82 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -17,16 +17,16 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_SPIP_SELECT_RUBRIQUES')) { |
| 24 | - /** |
|
| 25 | - * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | - * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | - * mettre 100000 pour desactiver ajax |
|
| 28 | - */ |
|
| 29 | - define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 24 | + /** |
|
| 25 | + * @var int Nombre de rubriques maximum du sélecteur de rubriques. |
|
| 26 | + * Au delà, on bascule sur un sélecteur ajax. |
|
| 27 | + * mettre 100000 pour desactiver ajax |
|
| 28 | + */ |
|
| 29 | + define('_SPIP_SELECT_RUBRIQUES', 20); |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -54,22 +54,22 @@ discard block |
||
| 54 | 54 | * Code HTML du sélecteur |
| 55 | 55 | **/ |
| 56 | 56 | function inc_chercher_rubrique_dist($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 57 | - if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | - return ''; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - // Mode sans Ajax : |
|
| 62 | - // - soit parce que le cookie ajax n'est pas la |
|
| 63 | - // - soit parce qu'il y a peu de rubriques |
|
| 64 | - if ( |
|
| 65 | - _SPIP_AJAX < 1 |
|
| 66 | - || $type == 'breve' |
|
| 67 | - || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | - ) { |
|
| 69 | - return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | - } else { |
|
| 71 | - return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | - } |
|
| 57 | + if (sql_countsel('spip_rubriques') < 1) { |
|
| 58 | + return ''; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + // Mode sans Ajax : |
|
| 62 | + // - soit parce que le cookie ajax n'est pas la |
|
| 63 | + // - soit parce qu'il y a peu de rubriques |
|
| 64 | + if ( |
|
| 65 | + _SPIP_AJAX < 1 |
|
| 66 | + || $type == 'breve' |
|
| 67 | + || sql_countsel('spip_rubriques') < _SPIP_SELECT_RUBRIQUES |
|
| 68 | + ) { |
|
| 69 | + return selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem); |
|
| 70 | + } else { |
|
| 71 | + return selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem, $do); |
|
| 72 | + } |
|
| 73 | 73 | } |
| 74 | 74 | |
| 75 | 75 | // compatibilite pour extensions qui utilisaient l'ancien nom |
@@ -86,17 +86,17 @@ discard block |
||
| 86 | 86 | **/ |
| 87 | 87 | function style_menu_rubriques($i) { |
| 88 | 88 | |
| 89 | - $espace = ''; |
|
| 90 | - $style = ''; |
|
| 91 | - for ($count = 1; $count <= $i; $count++) { |
|
| 92 | - $espace .= ' '; |
|
| 93 | - } |
|
| 94 | - if ($i == 1) { |
|
| 95 | - $espace = ''; |
|
| 96 | - } |
|
| 97 | - $class = "niveau_$i"; |
|
| 98 | - |
|
| 99 | - return [$class, $style, $espace]; |
|
| 89 | + $espace = ''; |
|
| 90 | + $style = ''; |
|
| 91 | + for ($count = 1; $count <= $i; $count++) { |
|
| 92 | + $espace .= ' '; |
|
| 93 | + } |
|
| 94 | + if ($i == 1) { |
|
| 95 | + $espace = ''; |
|
| 96 | + } |
|
| 97 | + $class = "niveau_$i"; |
|
| 98 | + |
|
| 99 | + return [$class, $style, $espace]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -120,57 +120,57 @@ discard block |
||
| 120 | 120 | * Code HTML du sélecteur |
| 121 | 121 | **/ |
| 122 | 122 | function sous_menu_rubriques($id_rubrique, $root, $niv, &$data, &$enfants, $exclus, $restreint, $type) { |
| 123 | - static $decalage_secteur; |
|
| 124 | - |
|
| 125 | - // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | - if ($exclus > 0 && $root == $exclus) { |
|
| 127 | - return ''; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | - |
|
| 132 | - // selected ? |
|
| 133 | - $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | - |
|
| 135 | - // le style en fonction de la profondeur |
|
| 136 | - [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | - |
|
| 138 | - $class .= ' selec_rub'; |
|
| 139 | - |
|
| 140 | - // creer l'<option> pour la rubrique $root |
|
| 141 | - |
|
| 142 | - if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | - $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | - . $data[$root] |
|
| 145 | - . '</option>' . "\n"; |
|
| 146 | - } else { |
|
| 147 | - $r = ''; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // et le sous-menu pour ses enfants |
|
| 151 | - $sous = ''; |
|
| 152 | - if (isset($enfants[$root])) { |
|
| 153 | - foreach ($enfants[$root] as $sousrub) { |
|
| 154 | - $sous .= sous_menu_rubriques( |
|
| 155 | - $id_rubrique, |
|
| 156 | - $sousrub, |
|
| 157 | - $niv + 1, |
|
| 158 | - $data, |
|
| 159 | - $enfants, |
|
| 160 | - $exclus, |
|
| 161 | - $restreint, |
|
| 162 | - $type |
|
| 163 | - ); |
|
| 164 | - } |
|
| 165 | - } |
|
| 166 | - |
|
| 167 | - // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | - if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | - return $sous; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // et voila le travail |
|
| 173 | - return $r . $sous; |
|
| 123 | + static $decalage_secteur; |
|
| 124 | + |
|
| 125 | + // Si on a demande l'exclusion ne pas descendre dans la rubrique courante |
|
| 126 | + if ($exclus > 0 && $root == $exclus) { |
|
| 127 | + return ''; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + // en fonction du niveau faire un affichage plus ou moins kikoo |
|
| 131 | + |
|
| 132 | + // selected ? |
|
| 133 | + $selected = ($root == $id_rubrique) ? ' selected="selected"' : ''; |
|
| 134 | + |
|
| 135 | + // le style en fonction de la profondeur |
|
| 136 | + [$class, $style, $espace] = style_menu_rubriques($niv); |
|
| 137 | + |
|
| 138 | + $class .= ' selec_rub'; |
|
| 139 | + |
|
| 140 | + // creer l'<option> pour la rubrique $root |
|
| 141 | + |
|
| 142 | + if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
|
| 143 | + $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
|
| 144 | + . $data[$root] |
|
| 145 | + . '</option>' . "\n"; |
|
| 146 | + } else { |
|
| 147 | + $r = ''; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // et le sous-menu pour ses enfants |
|
| 151 | + $sous = ''; |
|
| 152 | + if (isset($enfants[$root])) { |
|
| 153 | + foreach ($enfants[$root] as $sousrub) { |
|
| 154 | + $sous .= sous_menu_rubriques( |
|
| 155 | + $id_rubrique, |
|
| 156 | + $sousrub, |
|
| 157 | + $niv + 1, |
|
| 158 | + $data, |
|
| 159 | + $enfants, |
|
| 160 | + $exclus, |
|
| 161 | + $restreint, |
|
| 162 | + $type |
|
| 163 | + ); |
|
| 164 | + } |
|
| 165 | + } |
|
| 166 | + |
|
| 167 | + // si l'objet a deplacer est publie, verifier qu'on a acces aux rubriques |
|
| 168 | + if ($restreint && $root != $id_rubrique && !autoriser('publierdans', 'rubrique', $root)) { |
|
| 169 | + return $sous; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // et voila le travail |
|
| 173 | + return $r . $sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -191,75 +191,75 @@ discard block |
||
| 191 | 191 | * Code HTML du sélecteur |
| 192 | 192 | **/ |
| 193 | 193 | function selecteur_rubrique_html($id_rubrique, $type, $restreint, $idem = 0) { |
| 194 | - $enfants = []; |
|
| 195 | - $data = []; |
|
| 196 | - if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | - $data[0] = _T('info_racine_site'); |
|
| 198 | - } |
|
| 199 | - # premier choix = neant |
|
| 200 | - # si auteur (rubriques restreintes) |
|
| 201 | - # ou si creation avec id_rubrique=0 |
|
| 202 | - elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | - $data[0] = ' '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - // |
|
| 207 | - // creer une structure contenant toute l'arborescence |
|
| 208 | - // |
|
| 209 | - |
|
| 210 | - include_spip('base/abstract_sql'); |
|
| 211 | - $q = sql_select( |
|
| 212 | - 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | - 'spip_rubriques', |
|
| 214 | - ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | - '', |
|
| 216 | - '0+titre,titre' |
|
| 217 | - ); |
|
| 218 | - while ($r = sql_fetch($q)) { |
|
| 219 | - if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | - // titre largeur maxi a 50 |
|
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | - if ( |
|
| 223 | - $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | - && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | - ) { |
|
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | - } |
|
| 228 | - $data[$r['id_rubrique']] = $titre; |
|
| 229 | - $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | - if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | - $id_parent = $r['id_parent']; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // si une seule rubrique comme choix possible, |
|
| 237 | - // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | - // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | - if ( |
|
| 240 | - count($data) == 2 |
|
| 241 | - && isset($data[0]) |
|
| 242 | - && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | - && !$id_rubrique |
|
| 244 | - ) { |
|
| 245 | - unset($data[0]); |
|
| 246 | - } |
|
| 247 | - |
|
| 248 | - |
|
| 249 | - $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | - $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | - |
|
| 252 | - if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | - } else { |
|
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - # message pour neuneus (a supprimer ?) |
|
| 194 | + $enfants = []; |
|
| 195 | + $data = []; |
|
| 196 | + if ($type == 'rubrique' && autoriser('publierdans', 'rubrique', 0)) { |
|
| 197 | + $data[0] = _T('info_racine_site'); |
|
| 198 | + } |
|
| 199 | + # premier choix = neant |
|
| 200 | + # si auteur (rubriques restreintes) |
|
| 201 | + # ou si creation avec id_rubrique=0 |
|
| 202 | + elseif ($type == 'auteur' || !$id_rubrique) { |
|
| 203 | + $data[0] = ' '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + // |
|
| 207 | + // creer une structure contenant toute l'arborescence |
|
| 208 | + // |
|
| 209 | + |
|
| 210 | + include_spip('base/abstract_sql'); |
|
| 211 | + $q = sql_select( |
|
| 212 | + 'id_rubrique, id_parent, titre, statut, lang, langue_choisie', |
|
| 213 | + 'spip_rubriques', |
|
| 214 | + ($type == 'breve' ? ' id_parent=0 ' : ''), |
|
| 215 | + '', |
|
| 216 | + '0+titre,titre' |
|
| 217 | + ); |
|
| 218 | + while ($r = sql_fetch($q)) { |
|
| 219 | + if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
|
| 220 | + // titre largeur maxi a 50 |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 222 | + if ( |
|
| 223 | + $GLOBALS['meta']['multi_rubriques'] == 'oui' |
|
| 224 | + && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
|
| 225 | + ) { |
|
| 226 | + $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 227 | + } |
|
| 228 | + $data[$r['id_rubrique']] = $titre; |
|
| 229 | + $enfants[$r['id_parent']][] = $r['id_rubrique']; |
|
| 230 | + if ($id_rubrique == $r['id_rubrique']) { |
|
| 231 | + $id_parent = $r['id_parent']; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // si une seule rubrique comme choix possible, |
|
| 237 | + // inutile de mettre le selecteur sur un choix vide par defaut |
|
| 238 | + // sauf si le selecteur s'adresse a une rubrique puisque on peut la mettre a la racine dans ce cas |
|
| 239 | + if ( |
|
| 240 | + count($data) == 2 |
|
| 241 | + && isset($data[0]) |
|
| 242 | + && !in_array($type, ['auteur', 'rubrique']) |
|
| 243 | + && !$id_rubrique |
|
| 244 | + ) { |
|
| 245 | + unset($data[0]); |
|
| 246 | + } |
|
| 247 | + |
|
| 248 | + |
|
| 249 | + $opt = sous_menu_rubriques($id_rubrique, 0, 0, $data, $enfants, $idem, $restreint, $type); |
|
| 250 | + $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
|
| 251 | + |
|
| 252 | + if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
|
| 253 | + $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 254 | + } else { |
|
| 255 | + $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + # message pour neuneus (a supprimer ?) |
|
| 259 | 259 | # if ($type != 'auteur' AND $type != 'breve') |
| 260 | 260 | # $r .= "\n<br />"._T('texte_rappel_selection_champs'); |
| 261 | 261 | |
| 262 | - return $r; |
|
| 262 | + return $r; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | /** |
@@ -293,22 +293,22 @@ discard block |
||
| 293 | 293 | */ |
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | - if ($id_rubrique) { |
|
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | - } else { |
|
| 299 | - $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | - } |
|
| 296 | + if ($id_rubrique) { |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 298 | + } else { |
|
| 299 | + $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
|
| 300 | + } |
|
| 301 | 301 | |
| 302 | - $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 302 | + $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | - $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | - . ($idem ? "&exclus=$idem" : '') |
|
| 307 | - . ($restreint ? '' : '&racine=oui') |
|
| 308 | - . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 305 | + $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
|
| 306 | + . ($idem ? "&exclus=$idem" : '') |
|
| 307 | + . ($restreint ? '' : '&racine=oui') |
|
| 308 | + . (isset($GLOBALS['var_profile']) ? '&var_profile=1' : '')); |
|
| 309 | 309 | |
| 310 | 310 | |
| 311 | - return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 311 | + return construire_selecteur($url, '', 'selection_rubrique', 'id_parent', $init, $id_rubrique); |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -338,30 +338,30 @@ discard block |
||
| 338 | 338 | * Code HTML du sélecteur de rubrique AJAX |
| 339 | 339 | **/ |
| 340 | 340 | function construire_selecteur($url, $js, $idom, $name, $init = '', $id = 0) { |
| 341 | - $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | - // si icone de recherche on embed le svg |
|
| 343 | - $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | - $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | - |
|
| 346 | - return |
|
| 347 | - "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | - . $js |
|
| 349 | - . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | - . "return charger_node_url_si_vide('" |
|
| 351 | - . $url |
|
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | - . $img_icone |
|
| 354 | - . "</a><img src='" |
|
| 355 | - . chemin_image('loader.svg') |
|
| 356 | - . "' class='loader' id='img_" |
|
| 357 | - . $idom |
|
| 358 | - . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | - . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | - . $init |
|
| 361 | - . ' />' |
|
| 362 | - . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | - . $id |
|
| 364 | - . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | - . $idom |
|
| 366 | - . "'\nstyle='display: none;'></div>"; |
|
| 341 | + $icone = (str_contains($idom, 'auteur')) ? 'auteur-24.png' : 'rechercher-20.png'; |
|
| 342 | + // si icone de recherche on embed le svg |
|
| 343 | + $balise = ($icone === 'rechercher-20.png' ? chercher_filtre('balise_svg') : chercher_filtre('balise_img')); |
|
| 344 | + $img_icone = $balise(chemin_image($icone), _T('titre_image_selecteur')); |
|
| 345 | + |
|
| 346 | + return |
|
| 347 | + "<div class='rubrique_actuelle'><a href='#' class='rubrique-search' role='button' style='display:inline-flex;vertical-align:middle;' onclick=\"" |
|
| 348 | + . $js |
|
| 349 | + . " jQuery(this).toggleClass('toggled'); " |
|
| 350 | + . "return charger_node_url_si_vide('" |
|
| 351 | + . $url |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 353 | + . $img_icone |
|
| 354 | + . "</a><img src='" |
|
| 355 | + . chemin_image('loader.svg') |
|
| 356 | + . "' class='loader' id='img_" |
|
| 357 | + . $idom |
|
| 358 | + . "'\nstyle='visibility: hidden;' alt='*' />" |
|
| 359 | + . "<input id='titreparent' name='titreparent' class='text'" |
|
| 360 | + . $init |
|
| 361 | + . ' />' |
|
| 362 | + . "<input type='hidden' id='$name' name='$name' value='" |
|
| 363 | + . $id |
|
| 364 | + . "' /><div class='nettoyeur'></div></div><div id='" |
|
| 365 | + . $idom |
|
| 366 | + . "'\nstyle='display: none;'></div>"; |
|
| 367 | 367 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (isset($data[$root])) { # pas de racine sauf pour les rubriques |
| 143 | 143 | $r = "<option$selected value='$root' class='$class' style='$style'>$espace" |
| 144 | 144 | . $data[$root] |
| 145 | - . '</option>' . "\n"; |
|
| 145 | + . '</option>'."\n"; |
|
| 146 | 146 | } else { |
| 147 | 147 | $r = ''; |
| 148 | 148 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | } |
| 171 | 171 | |
| 172 | 172 | // et voila le travail |
| 173 | - return $r . $sous; |
|
| 173 | + return $r.$sous; |
|
| 174 | 174 | } |
| 175 | 175 | |
| 176 | 176 | /** |
@@ -218,12 +218,12 @@ discard block |
||
| 218 | 218 | while ($r = sql_fetch($q)) { |
| 219 | 219 | if (autoriser('voir', 'rubrique', $r['id_rubrique'])) { |
| 220 | 220 | // titre largeur maxi a 50 |
| 221 | - $titre = couper(supprimer_tags(typo($r['titre'])) . ' ', 50); |
|
| 221 | + $titre = couper(supprimer_tags(typo($r['titre'])).' ', 50); |
|
| 222 | 222 | if ( |
| 223 | 223 | $GLOBALS['meta']['multi_rubriques'] == 'oui' |
| 224 | 224 | && ($r['langue_choisie'] == 'oui' || $r['id_parent'] == 0) |
| 225 | 225 | ) { |
| 226 | - $titre .= ' [' . traduire_nom_langue($r['lang']) . ']'; |
|
| 226 | + $titre .= ' ['.traduire_nom_langue($r['lang']).']'; |
|
| 227 | 227 | } |
| 228 | 228 | $data[$r['id_rubrique']] = $titre; |
| 229 | 229 | $enfants[$r['id_parent']][] = $r['id_rubrique']; |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | $att = " id='id_parent' name='id_parent'\nclass='selecteur_parent verdana1'"; |
| 251 | 251 | |
| 252 | 252 | if (preg_match(',^<option[^<>]*value=.(\d*).[^<>]*>([^<]*)</option>$,', $opt, $r)) { |
| 253 | - $r = "<input$att type='hidden' value='" . $r[1] . "' />" . $r[2]; |
|
| 253 | + $r = "<input$att type='hidden' value='".$r[1]."' />".$r[2]; |
|
| 254 | 254 | } else { |
| 255 | - $r = '<select' . $att . " size='1'>\n$opt</select>\n"; |
|
| 255 | + $r = '<select'.$att." size='1'>\n$opt</select>\n"; |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | # message pour neuneus (a supprimer ?) |
@@ -294,13 +294,13 @@ discard block |
||
| 294 | 294 | function selecteur_rubrique_ajax($id_rubrique, $type, $restreint, $idem = 0, $do = 'aff') { |
| 295 | 295 | |
| 296 | 296 | if ($id_rubrique) { |
| 297 | - $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique=' . (int) $id_rubrique); |
|
| 297 | + $titre = sql_getfetsel('titre', 'spip_rubriques', 'id_rubrique='.(int) $id_rubrique); |
|
| 298 | 298 | } else { |
| 299 | 299 | $titre = $type == 'auteur' ? ' ' : _T('info_racine_site'); |
| 300 | 300 | } |
| 301 | 301 | |
| 302 | 302 | $titre = str_replace('&', '&', (string) entites_html(textebrut(typo($titre)))); |
| 303 | - $init = " disabled='disabled' type='text' value=\"" . $titre . "\"\nstyle='width:300px;'"; |
|
| 303 | + $init = " disabled='disabled' type='text' value=\"".$titre."\"\nstyle='width:300px;'"; |
|
| 304 | 304 | |
| 305 | 305 | $url = generer_url_ecrire('selectionner', "id=$id_rubrique&type=$type&do=$do" |
| 306 | 306 | . ($idem ? "&exclus=$idem" : '') |
@@ -349,7 +349,7 @@ discard block |
||
| 349 | 349 | . " jQuery(this).toggleClass('toggled'); " |
| 350 | 350 | . "return charger_node_url_si_vide('" |
| 351 | 351 | . $url |
| 352 | - . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='" . attribut_html(_T('titre_image_selecteur')) . "'>" |
|
| 352 | + . "', this.parentNode.nextSibling, this.nextSibling,'',event)\" title='".attribut_html(_T('titre_image_selecteur'))."'>" |
|
| 353 | 353 | . $img_icone |
| 354 | 354 | . "</a><img src='" |
| 355 | 355 | . chemin_image('loader.svg') |