@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | * @package SPIP\Core\Drapeaux\Edition |
| 31 | 31 | **/ |
| 32 | 32 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 33 | - return; |
|
| 33 | + return; |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | |
@@ -45,46 +45,46 @@ discard block |
||
| 45 | 45 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 46 | 46 | **/ |
| 47 | 47 | function lire_tableau_edition() { |
| 48 | - $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | - if (!$edition) { |
|
| 50 | - return []; |
|
| 51 | - } |
|
| 52 | - $changed = false; |
|
| 48 | + $edition = @unserialize($GLOBALS['meta']['drapeau_edition']); |
|
| 49 | + if (!$edition) { |
|
| 50 | + return []; |
|
| 51 | + } |
|
| 52 | + $changed = false; |
|
| 53 | 53 | |
| 54 | - $bon_pour_le_service = time() - 3600; |
|
| 55 | - // parcourir le tableau et virer les vieux |
|
| 56 | - foreach ($edition as $objet => $data) { |
|
| 57 | - if (!is_array($data)) { |
|
| 58 | - unset($edition[$objet]); |
|
| 59 | - } // vieille version |
|
| 60 | - else { |
|
| 61 | - foreach ($data as $id => $tab) { |
|
| 62 | - if (!is_array($tab)) { |
|
| 63 | - unset($edition[$objet][$tab]); |
|
| 64 | - } // vieille version |
|
| 65 | - else { |
|
| 66 | - foreach ($tab as $n => $duo) { |
|
| 67 | - if (current($duo) < $bon_pour_le_service) { |
|
| 68 | - unset($edition[$objet][$id][$n]); |
|
| 69 | - $changed = true; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - } |
|
| 73 | - if (!$edition[$objet][$id]) { |
|
| 74 | - unset($edition[$objet][$id]); |
|
| 75 | - } |
|
| 76 | - } |
|
| 77 | - } |
|
| 78 | - if (!$edition[$objet]) { |
|
| 79 | - unset($edition[$objet]); |
|
| 80 | - } |
|
| 81 | - } |
|
| 54 | + $bon_pour_le_service = time() - 3600; |
|
| 55 | + // parcourir le tableau et virer les vieux |
|
| 56 | + foreach ($edition as $objet => $data) { |
|
| 57 | + if (!is_array($data)) { |
|
| 58 | + unset($edition[$objet]); |
|
| 59 | + } // vieille version |
|
| 60 | + else { |
|
| 61 | + foreach ($data as $id => $tab) { |
|
| 62 | + if (!is_array($tab)) { |
|
| 63 | + unset($edition[$objet][$tab]); |
|
| 64 | + } // vieille version |
|
| 65 | + else { |
|
| 66 | + foreach ($tab as $n => $duo) { |
|
| 67 | + if (current($duo) < $bon_pour_le_service) { |
|
| 68 | + unset($edition[$objet][$id][$n]); |
|
| 69 | + $changed = true; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + } |
|
| 73 | + if (!$edition[$objet][$id]) { |
|
| 74 | + unset($edition[$objet][$id]); |
|
| 75 | + } |
|
| 76 | + } |
|
| 77 | + } |
|
| 78 | + if (!$edition[$objet]) { |
|
| 79 | + unset($edition[$objet]); |
|
| 80 | + } |
|
| 81 | + } |
|
| 82 | 82 | |
| 83 | - if ($changed) { |
|
| 84 | - ecrire_tableau_edition($edition); |
|
| 85 | - } |
|
| 83 | + if ($changed) { |
|
| 84 | + ecrire_tableau_edition($edition); |
|
| 85 | + } |
|
| 86 | 86 | |
| 87 | - return $edition; |
|
| 87 | + return $edition; |
|
| 88 | 88 | } |
| 89 | 89 | |
| 90 | 90 | /** |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | * `[ type d'objet ][id_objet][id_auteur][nom de l'auteur] = time()` |
| 98 | 98 | **/ |
| 99 | 99 | function ecrire_tableau_edition($edition) { |
| 100 | - ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 100 | + ecrire_meta('drapeau_edition', serialize($edition)); |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -117,22 +117,22 @@ discard block |
||
| 117 | 117 | * Type d'objet édité |
| 118 | 118 | */ |
| 119 | 119 | function signale_edition($id, $auteur, $type = 'article') { |
| 120 | - include_spip('base/objets'); |
|
| 121 | - include_spip('inc/filtres'); |
|
| 122 | - if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | - return; |
|
| 124 | - } |
|
| 120 | + include_spip('base/objets'); |
|
| 121 | + include_spip('inc/filtres'); |
|
| 122 | + if (objet_info($type, 'editable') !== 'oui') { |
|
| 123 | + return; |
|
| 124 | + } |
|
| 125 | 125 | |
| 126 | - $edition = lire_tableau_edition(); |
|
| 126 | + $edition = lire_tableau_edition(); |
|
| 127 | 127 | |
| 128 | - $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | - $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 128 | + $nom = $auteur['nom'] ?? $GLOBALS['ip']; |
|
| 129 | + $id_a = $auteur['id_auteur'] ?? $GLOBALS['ip']; |
|
| 130 | 130 | |
| 131 | - if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | - $edition[$type][$id] = []; |
|
| 133 | - } |
|
| 134 | - $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | - ecrire_tableau_edition($edition); |
|
| 131 | + if (!isset($edition[$type][$id]) or !is_array($edition[$type][$id])) { |
|
| 132 | + $edition[$type][$id] = []; |
|
| 133 | + } |
|
| 134 | + $edition[$type][$id][$id_a][$nom] = time(); |
|
| 135 | + ecrire_tableau_edition($edition); |
|
| 136 | 136 | } |
| 137 | 137 | |
| 138 | 138 | /** |
@@ -149,9 +149,9 @@ discard block |
||
| 149 | 149 | */ |
| 150 | 150 | function qui_edite($id, $type = 'article') { |
| 151 | 151 | |
| 152 | - $edition = lire_tableau_edition(); |
|
| 152 | + $edition = lire_tableau_edition(); |
|
| 153 | 153 | |
| 154 | - return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 154 | + return empty($edition[$type][$id]) ? [] : $edition[$type][$id]; |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -165,23 +165,23 @@ discard block |
||
| 165 | 165 | * Liste de tableaux `['nom_auteur_modif' => x|y|z, 'date_diff' => n]` |
| 166 | 166 | */ |
| 167 | 167 | function mention_qui_edite($id, $type = 'article'): array { |
| 168 | - $modif = qui_edite($id, $type); |
|
| 169 | - unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 168 | + $modif = qui_edite($id, $type); |
|
| 169 | + unset($modif[$GLOBALS['visiteur_session']['id_auteur']]); |
|
| 170 | 170 | |
| 171 | - if ($modif) { |
|
| 172 | - $quand = 0; |
|
| 173 | - foreach ($modif as $duo) { |
|
| 174 | - $auteurs[] = typo(key($duo)); |
|
| 175 | - $quand = max($quand, current($duo)); |
|
| 176 | - } |
|
| 171 | + if ($modif) { |
|
| 172 | + $quand = 0; |
|
| 173 | + foreach ($modif as $duo) { |
|
| 174 | + $auteurs[] = typo(key($duo)); |
|
| 175 | + $quand = max($quand, current($duo)); |
|
| 176 | + } |
|
| 177 | 177 | |
| 178 | - // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | - return [ |
|
| 180 | - 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | - 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | - ]; |
|
| 183 | - } |
|
| 184 | - return []; |
|
| 178 | + // format lie a la chaine de langue 'avis_article_modifie' |
|
| 179 | + return [ |
|
| 180 | + 'nom_auteur_modif' => join(' | ', $auteurs), |
|
| 181 | + 'date_diff' => ceil((time() - $quand) / 60) |
|
| 182 | + ]; |
|
| 183 | + } |
|
| 184 | + return []; |
|
| 185 | 185 | } |
| 186 | 186 | |
| 187 | 187 | /** |
@@ -195,25 +195,25 @@ discard block |
||
| 195 | 195 | * Liste de tableaux `['objet' => x, 'id_objet' => n]` |
| 196 | 196 | */ |
| 197 | 197 | function liste_drapeau_edition($id_auteur) { |
| 198 | - $edition = lire_tableau_edition(); |
|
| 199 | - $objets_ouverts = []; |
|
| 198 | + $edition = lire_tableau_edition(); |
|
| 199 | + $objets_ouverts = []; |
|
| 200 | 200 | |
| 201 | - foreach ($edition as $objet => $data) { |
|
| 202 | - foreach ($data as $id => $auteurs) { |
|
| 203 | - if ( |
|
| 204 | - isset($auteurs[$id_auteur]) |
|
| 205 | - and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | - and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | - ) { |
|
| 208 | - $objets_ouverts[] = [ |
|
| 209 | - 'objet' => $objet, |
|
| 210 | - 'id_objet' => $id, |
|
| 211 | - ]; |
|
| 212 | - } |
|
| 213 | - } |
|
| 214 | - } |
|
| 201 | + foreach ($edition as $objet => $data) { |
|
| 202 | + foreach ($data as $id => $auteurs) { |
|
| 203 | + if ( |
|
| 204 | + isset($auteurs[$id_auteur]) |
|
| 205 | + and is_array($auteurs[$id_auteur]) // precaution |
|
| 206 | + and (array_pop($auteurs[$id_auteur]) > time() - 3600) |
|
| 207 | + ) { |
|
| 208 | + $objets_ouverts[] = [ |
|
| 209 | + 'objet' => $objet, |
|
| 210 | + 'id_objet' => $id, |
|
| 211 | + ]; |
|
| 212 | + } |
|
| 213 | + } |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - return $objets_ouverts; |
|
| 216 | + return $objets_ouverts; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -226,15 +226,15 @@ discard block |
||
| 226 | 226 | * @return void |
| 227 | 227 | */ |
| 228 | 228 | function debloquer_tous($id_auteur) { |
| 229 | - $edition = lire_tableau_edition(); |
|
| 230 | - foreach ($edition as $objet => $data) { |
|
| 231 | - foreach ($data as $id => $auteurs) { |
|
| 232 | - if (isset($auteurs[$id_auteur])) { |
|
| 233 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | - ecrire_tableau_edition($edition); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 229 | + $edition = lire_tableau_edition(); |
|
| 230 | + foreach ($edition as $objet => $data) { |
|
| 231 | + foreach ($data as $id => $auteurs) { |
|
| 232 | + if (isset($auteurs[$id_auteur])) { |
|
| 233 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 234 | + ecrire_tableau_edition($edition); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,19 +252,19 @@ discard block |
||
| 252 | 252 | * @return void |
| 253 | 253 | */ |
| 254 | 254 | function debloquer_edition($id_auteur, $id_objet, $type = 'article') { |
| 255 | - $edition = lire_tableau_edition(); |
|
| 255 | + $edition = lire_tableau_edition(); |
|
| 256 | 256 | |
| 257 | - foreach ($edition as $objet => $data) { |
|
| 258 | - if ($objet == $type) { |
|
| 259 | - foreach ($data as $id => $auteurs) { |
|
| 260 | - if ( |
|
| 261 | - $id == $id_objet |
|
| 262 | - and isset($auteurs[$id_auteur]) |
|
| 263 | - ) { |
|
| 264 | - unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | - ecrire_tableau_edition($edition); |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - } |
|
| 269 | - } |
|
| 257 | + foreach ($edition as $objet => $data) { |
|
| 258 | + if ($objet == $type) { |
|
| 259 | + foreach ($data as $id => $auteurs) { |
|
| 260 | + if ( |
|
| 261 | + $id == $id_objet |
|
| 262 | + and isset($auteurs[$id_auteur]) |
|
| 263 | + ) { |
|
| 264 | + unset($edition[$objet][$id][$id_auteur]); |
|
| 265 | + ecrire_tableau_edition($edition); |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + } |
|
| 269 | + } |
|
| 270 | 270 | } |
@@ -648,8 +648,7 @@ discard block |
||
| 648 | 648 | if (!$srcSize) { |
| 649 | 649 | $poids_img[$src] = filesize($src); |
| 650 | 650 | } |
| 651 | - } |
|
| 652 | - elseif (strpos($src, '<svg') !== false) { |
|
| 651 | + } elseif (strpos($src, '<svg') !== false) { |
|
| 653 | 652 | include_spip('inc/svg'); |
| 654 | 653 | if ($attrs = svg_lire_attributs($src)) { |
| 655 | 654 | [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
@@ -3507,8 +3506,7 @@ discard block |
||
| 3507 | 3506 | ) { |
| 3508 | 3507 | if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
| 3509 | 3508 | $img_file = $variante_svg_size; |
| 3510 | - } |
|
| 3511 | - else { |
|
| 3509 | + } else { |
|
| 3512 | 3510 | $img_file = $variante_svg_generique; |
| 3513 | 3511 | } |
| 3514 | 3512 | } |
@@ -3540,8 +3538,7 @@ discard block |
||
| 3540 | 3538 | } |
| 3541 | 3539 | if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
| 3542 | 3540 | $img_file = chemin_image($img); |
| 3543 | - } |
|
| 3544 | - else { |
|
| 3541 | + } else { |
|
| 3545 | 3542 | if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
| 3546 | 3543 | $img_file = http_img_variante_svg_si_possible($img_file); |
| 3547 | 3544 | } |
@@ -3571,11 +3568,9 @@ discard block |
||
| 3571 | 3568 | } |
| 3572 | 3569 | if ($alt === false) { |
| 3573 | 3570 | $alt = ''; |
| 3574 | - } |
|
| 3575 | - elseif ($alt or $alt === '') { |
|
| 3571 | + } elseif ($alt or $alt === '') { |
|
| 3576 | 3572 | $alt = " alt='" . attribut_html($alt) . "'"; |
| 3577 | - } |
|
| 3578 | - else { |
|
| 3573 | + } else { |
|
| 3579 | 3574 | $alt = " alt='" . attribut_html($title) . "'"; |
| 3580 | 3575 | } |
| 3581 | 3576 | return "<img src='" . attribut_html($img_file) . "'$alt" |
@@ -3702,13 +3697,11 @@ discard block |
||
| 3702 | 3697 | if (!is_null($class)) { |
| 3703 | 3698 | if (strlen($class)) { |
| 3704 | 3699 | $img = inserer_attribut($img, 'class', $class); |
| 3705 | - } |
|
| 3706 | - else { |
|
| 3700 | + } else { |
|
| 3707 | 3701 | $img = vider_attribut($img, 'class'); |
| 3708 | 3702 | } |
| 3709 | 3703 | } |
| 3710 | - } |
|
| 3711 | - else { |
|
| 3704 | + } else { |
|
| 3712 | 3705 | $img = http_img_pack( |
| 3713 | 3706 | $img, |
| 3714 | 3707 | $alt, |
@@ -3806,8 +3799,7 @@ discard block |
||
| 3806 | 3799 | if (!is_null($class)) { |
| 3807 | 3800 | if (strlen($class)) { |
| 3808 | 3801 | $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
| 3809 | - } |
|
| 3810 | - else { |
|
| 3802 | + } else { |
|
| 3811 | 3803 | $balise_svg = vider_attribut($balise_svg, 'class'); |
| 3812 | 3804 | } |
| 3813 | 3805 | } |
@@ -3819,8 +3811,7 @@ discard block |
||
| 3819 | 3811 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3820 | 3812 | $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
| 3821 | 3813 | $balise_svg .= $title; |
| 3822 | - } |
|
| 3823 | - else { |
|
| 3814 | + } else { |
|
| 3824 | 3815 | $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
| 3825 | 3816 | } |
| 3826 | 3817 | |
@@ -5231,8 +5222,7 @@ discard block |
||
| 5231 | 5222 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5232 | 5223 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5233 | 5224 | $hash = md5($contexte_implicite['host'] . '::' . $cache); |
| 5234 | - } |
|
| 5235 | - else { |
|
| 5225 | + } else { |
|
| 5236 | 5226 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5237 | 5227 | ksort($contexte); |
| 5238 | 5228 | $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | include_fichiers_fonctions(); |
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 100 | 100 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 101 | 101 | if (is_callable($f)) { |
| 102 | 102 | return $f; |
@@ -231,7 +231,7 @@ discard block |
||
| 231 | 231 | // affichage "GIT [master: abcdef]" |
| 232 | 232 | $commit = $desc['commit_short'] ?? $desc['commit']; |
| 233 | 233 | if ($desc['branch']) { |
| 234 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 234 | + $commit = $desc['branch'].': '.$commit; |
|
| 235 | 235 | } |
| 236 | 236 | return "{$desc['vcs']} [$commit]"; |
| 237 | 237 | } |
@@ -250,9 +250,9 @@ discard block |
||
| 250 | 250 | } |
| 251 | 251 | |
| 252 | 252 | // version installee par GIT |
| 253 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 253 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 254 | 254 | $currentHead = trim(substr($c, 4)); |
| 255 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 255 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 256 | 256 | return [ |
| 257 | 257 | 'vcs' => 'GIT', |
| 258 | 258 | 'branch' => basename($currentHead), |
@@ -267,12 +267,12 @@ discard block |
||
| 267 | 267 | |
| 268 | 268 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 269 | 269 | // et laisser passer les fonctions personnelles baptisees image_... |
| 270 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 271 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 272 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 273 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 274 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 275 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 270 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 271 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 272 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 273 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 274 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 275 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 276 | 276 | |
| 277 | 277 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 278 | 278 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -431,8 +431,8 @@ discard block |
||
| 431 | 431 | */ |
| 432 | 432 | function filtre_debug($val, $key = null) { |
| 433 | 433 | $debug = ( |
| 434 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 435 | - ) . var_export($val, true); |
|
| 434 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 435 | + ).var_export($val, true); |
|
| 436 | 436 | |
| 437 | 437 | include_spip('inc/autoriser'); |
| 438 | 438 | if (autoriser('webmestre')) { |
@@ -488,7 +488,7 @@ discard block |
||
| 488 | 488 | $is_file = false; |
| 489 | 489 | } |
| 490 | 490 | if ($is_file) { |
| 491 | - $is_local_file = function ($path) { |
|
| 491 | + $is_local_file = function($path) { |
|
| 492 | 492 | if (strpos($path, '?') !== false) { |
| 493 | 493 | $path = supprimer_timestamp($path); |
| 494 | 494 | // remove ?24px added by find_in_theme on .svg files |
@@ -537,7 +537,7 @@ discard block |
||
| 537 | 537 | if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
| 538 | 538 | if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
| 539 | 539 | $srcover = $match[1]; |
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 540 | + $srcover_filter = $filtre("<img src='".$match[1]."' />", ...$args); |
|
| 541 | 541 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 542 | 542 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
| 543 | 543 | } |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | // " -> " et tout ce genre de choses |
| 943 | 943 | $u = $GLOBALS['meta']['pcre_u']; |
| 944 | 944 | $texte = str_replace(' ', ' ', $texte); |
| 945 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 945 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 946 | 946 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 947 | 947 | $texte = entites_html($texte, false, false); |
| 948 | 948 | // mais bien echapper les double quotes ! |
@@ -1004,7 +1004,7 @@ discard block |
||
| 1004 | 1004 | return ''; |
| 1005 | 1005 | } |
| 1006 | 1006 | return preg_replace( |
| 1007 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1007 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1008 | 1008 | '', |
| 1009 | 1009 | $texte |
| 1010 | 1010 | ); |
@@ -1033,7 +1033,7 @@ discard block |
||
| 1033 | 1033 | if ( |
| 1034 | 1034 | $texte and |
| 1035 | 1035 | preg_match( |
| 1036 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1036 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1037 | 1037 | $texte, |
| 1038 | 1038 | $regs |
| 1039 | 1039 | ) |
@@ -1124,8 +1124,8 @@ discard block |
||
| 1124 | 1124 | **/ |
| 1125 | 1125 | function textebrut($texte) { |
| 1126 | 1126 | $u = $GLOBALS['meta']['pcre_u']; |
| 1127 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1128 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1127 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1128 | + $texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte); |
|
| 1129 | 1129 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1130 | 1130 | $texte = preg_replace("/\n+$/", '', $texte); |
| 1131 | 1131 | $texte = preg_replace("/\n +/", "\n", $texte); |
@@ -1159,7 +1159,7 @@ discard block |
||
| 1159 | 1159 | ) |
| 1160 | 1160 | ) { |
| 1161 | 1161 | foreach ($liens[0] as $a) { |
| 1162 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1162 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1163 | 1163 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1164 | 1164 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1165 | 1165 | $texte = str_replace($a, $ablank, $texte); |
@@ -1184,7 +1184,7 @@ discard block |
||
| 1184 | 1184 | foreach ($regs[0] as $a) { |
| 1185 | 1185 | $rel = extraire_attribut($a, 'rel') ?? ''; |
| 1186 | 1186 | if (strpos($rel, 'nofollow') === false) { |
| 1187 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1187 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1188 | 1188 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1189 | 1189 | $texte = str_replace($a, $anofollow, $texte); |
| 1190 | 1190 | } |
@@ -1213,7 +1213,7 @@ discard block |
||
| 1213 | 1213 | $u = $GLOBALS['meta']['pcre_u']; |
| 1214 | 1214 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1215 | 1215 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1216 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1216 | + $texte = preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1217 | 1217 | |
| 1218 | 1218 | return $texte; |
| 1219 | 1219 | } |
@@ -1244,7 +1244,7 @@ discard block |
||
| 1244 | 1244 | return $texte; |
| 1245 | 1245 | } |
| 1246 | 1246 | include_spip('inc/texte'); |
| 1247 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1247 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1248 | 1248 | 'div' : 'span'; |
| 1249 | 1249 | |
| 1250 | 1250 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1335,7 +1335,7 @@ discard block |
||
| 1335 | 1335 | |
| 1336 | 1336 | // Calcul de la taille et choix de l'unité |
| 1337 | 1337 | $affichage = _T( |
| 1338 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1338 | + 'spip:taille_'.$unites[$puissance].$suffixe_item, |
|
| 1339 | 1339 | [ |
| 1340 | 1340 | 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
| 1341 | 1341 | ] |
@@ -1369,7 +1369,7 @@ discard block |
||
| 1369 | 1369 | } |
| 1370 | 1370 | $u = $GLOBALS['meta']['pcre_u']; |
| 1371 | 1371 | if ($textebrut) { |
| 1372 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1372 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1373 | 1373 | } |
| 1374 | 1374 | $texte = texte_backend($texte); |
| 1375 | 1375 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1404,7 +1404,7 @@ discard block |
||
| 1404 | 1404 | # un message pour abs_url |
| 1405 | 1405 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1406 | 1406 | $url = trim($url); |
| 1407 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1407 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1408 | 1408 | |
| 1409 | 1409 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1410 | 1410 | } |
@@ -1610,7 +1610,7 @@ discard block |
||
| 1610 | 1610 | |
| 1611 | 1611 | $debut = ''; |
| 1612 | 1612 | $suite = $texte; |
| 1613 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1613 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1614 | 1614 | $debut .= substr($suite, 0, $t - 1); |
| 1615 | 1615 | $suite = substr($suite, $t); |
| 1616 | 1616 | $car = substr($suite, 0, 1); |
@@ -1628,7 +1628,7 @@ discard block |
||
| 1628 | 1628 | $suite = substr($suite, strlen($regs[0])); |
| 1629 | 1629 | } |
| 1630 | 1630 | } |
| 1631 | - $texte = $debut . $suite; |
|
| 1631 | + $texte = $debut.$suite; |
|
| 1632 | 1632 | |
| 1633 | 1633 | if ($collecteurModeles) { |
| 1634 | 1634 | $texte = $collecteurModeles->retablir($texte); |
@@ -1636,7 +1636,7 @@ discard block |
||
| 1636 | 1636 | |
| 1637 | 1637 | $texte = echappe_retour($texte); |
| 1638 | 1638 | |
| 1639 | - return $texte . $fin; |
|
| 1639 | + return $texte.$fin; |
|
| 1640 | 1640 | } |
| 1641 | 1641 | |
| 1642 | 1642 | |
@@ -1912,7 +1912,7 @@ discard block |
||
| 1912 | 1912 | if (is_array($balise)) { |
| 1913 | 1913 | array_walk( |
| 1914 | 1914 | $balise, |
| 1915 | - function (&$a, $key, $t) { |
|
| 1915 | + function(&$a, $key, $t) { |
|
| 1916 | 1916 | $a = extraire_attribut($a, $t); |
| 1917 | 1917 | }, |
| 1918 | 1918 | $attribut |
@@ -2010,14 +2010,14 @@ discard block |
||
| 2010 | 2010 | |
| 2011 | 2011 | if ($old !== null) { |
| 2012 | 2012 | // Remplacer l'ancien attribut du meme nom |
| 2013 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2013 | + $balise = $r[1].$insert.$r[5]; |
|
| 2014 | 2014 | } else { |
| 2015 | 2015 | // preferer une balise " />" (comme <img />) |
| 2016 | 2016 | if (preg_match(',/>,', $balise)) { |
| 2017 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2017 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2018 | 2018 | } // sinon une balise <a ...> ... </a> |
| 2019 | 2019 | else { |
| 2020 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2020 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2021 | 2021 | } |
| 2022 | 2022 | } |
| 2023 | 2023 | |
@@ -2075,7 +2075,7 @@ discard block |
||
| 2075 | 2075 | in_array($operation, ['ajouter', 'commuter']) |
| 2076 | 2076 | and !$is_class_presente |
| 2077 | 2077 | ) { |
| 2078 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2078 | + $class_new = ltrim(rtrim($class_new ?? '').' '.$c); |
|
| 2079 | 2079 | } elseif ( |
| 2080 | 2080 | in_array($operation, ['supprimer', 'commuter']) |
| 2081 | 2081 | and $is_class_presente |
@@ -2145,7 +2145,7 @@ discard block |
||
| 2145 | 2145 | // Quelques fonctions de calcul arithmetique |
| 2146 | 2146 | // |
| 2147 | 2147 | function floatstr($a) { |
| 2148 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2148 | + return str_replace(',', '.', (string) floatval($a)); |
|
| 2149 | 2149 | } |
| 2150 | 2150 | function strize($f, $a, $b) { |
| 2151 | 2151 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2286,13 +2286,13 @@ discard block |
||
| 2286 | 2286 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2287 | 2287 | define('_TAGS_NOM_AUTEUR', ''); |
| 2288 | 2288 | } |
| 2289 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2289 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2290 | 2290 | foreach ($tags_acceptes as $tag) { |
| 2291 | 2291 | if (strlen($tag)) { |
| 2292 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2293 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2294 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2295 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2292 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2293 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2294 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2295 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2296 | 2296 | } |
| 2297 | 2297 | } |
| 2298 | 2298 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2412,10 +2412,10 @@ discard block |
||
| 2412 | 2412 | $fichier = basename($url); |
| 2413 | 2413 | |
| 2414 | 2414 | return '<a rel="enclosure"' |
| 2415 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2416 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2417 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2418 | - . '>' . $fichier . '</a>'; |
|
| 2415 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2416 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2417 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2418 | + . '>'.$fichier.'</a>'; |
|
| 2419 | 2419 | } |
| 2420 | 2420 | |
| 2421 | 2421 | /** |
@@ -2443,9 +2443,9 @@ discard block |
||
| 2443 | 2443 | } # vieux data |
| 2444 | 2444 | $fichier = basename($url); |
| 2445 | 2445 | $enclosures[] = '<enclosure' |
| 2446 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2447 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2448 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2446 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2447 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2448 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2449 | 2449 | . ' />'; |
| 2450 | 2450 | } |
| 2451 | 2451 | } |
@@ -2471,7 +2471,7 @@ discard block |
||
| 2471 | 2471 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2472 | 2472 | $subjects .= '<dc:subject>' |
| 2473 | 2473 | . texte_backend(textebrut($e)) |
| 2474 | - . '</dc:subject>' . "\n"; |
|
| 2474 | + . '</dc:subject>'."\n"; |
|
| 2475 | 2475 | } |
| 2476 | 2476 | } |
| 2477 | 2477 | |
@@ -2507,7 +2507,7 @@ discard block |
||
| 2507 | 2507 | if (is_array($texte)) { |
| 2508 | 2508 | array_walk( |
| 2509 | 2509 | $texte, |
| 2510 | - function (&$a, $key, $t) { |
|
| 2510 | + function(&$a, $key, $t) { |
|
| 2511 | 2511 | $a = extraire_balise($a, $t); |
| 2512 | 2512 | }, |
| 2513 | 2513 | $tag |
@@ -2555,7 +2555,7 @@ discard block |
||
| 2555 | 2555 | if (is_array($texte)) { |
| 2556 | 2556 | array_walk( |
| 2557 | 2557 | $texte, |
| 2558 | - function (&$a, $key, $t) { |
|
| 2558 | + function(&$a, $key, $t) { |
|
| 2559 | 2559 | $a = extraire_balises($a, $t); |
| 2560 | 2560 | }, |
| 2561 | 2561 | $tag |
@@ -2688,7 +2688,7 @@ discard block |
||
| 2688 | 2688 | if ($fond != '404') { |
| 2689 | 2689 | $contexte = array_shift($p); |
| 2690 | 2690 | $contexte['page'] = $fond; |
| 2691 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2691 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2692 | 2692 | } |
| 2693 | 2693 | } |
| 2694 | 2694 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2743,9 +2743,9 @@ discard block |
||
| 2743 | 2743 | . '"' |
| 2744 | 2744 | . (is_null($val) |
| 2745 | 2745 | ? '' |
| 2746 | - : ' value="' . entites_html($val) . '"' |
|
| 2746 | + : ' value="'.entites_html($val).'"' |
|
| 2747 | 2747 | ) |
| 2748 | - . ' type="hidden"' . "\n/>"; |
|
| 2748 | + . ' type="hidden"'."\n/>"; |
|
| 2749 | 2749 | } |
| 2750 | 2750 | |
| 2751 | 2751 | return join('', $hidden); |
@@ -2855,7 +2855,7 @@ discard block |
||
| 2855 | 2855 | |
| 2856 | 2856 | return preg_replace_callback( |
| 2857 | 2857 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2858 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2858 | + fn($x) => "url('".suivre_lien($path, $x[1])."')", |
|
| 2859 | 2859 | $contenu |
| 2860 | 2860 | ); |
| 2861 | 2861 | } |
@@ -2916,14 +2916,14 @@ discard block |
||
| 2916 | 2916 | ) { |
| 2917 | 2917 | $distant = true; |
| 2918 | 2918 | $cssf = parse_url($css); |
| 2919 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2919 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 2920 | 2920 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 2921 | 2921 | } else { |
| 2922 | 2922 | $distant = false; |
| 2923 | 2923 | $cssf = $css; |
| 2924 | 2924 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2925 | 2925 | //propose (rien a faire dans ce cas) |
| 2926 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2926 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2927 | 2927 | if (@file_exists($f)) { |
| 2928 | 2928 | return $f; |
| 2929 | 2929 | } |
@@ -2933,7 +2933,7 @@ discard block |
||
| 2933 | 2933 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2934 | 2934 | $f = $dir_var |
| 2935 | 2935 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2936 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2936 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2937 | 2937 | |
| 2938 | 2938 | // la css peut etre distante (url absolue !) |
| 2939 | 2939 | if ($distant) { |
@@ -2979,8 +2979,8 @@ discard block |
||
| 2979 | 2979 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 2980 | 2980 | elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
| 2981 | 2981 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 2982 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2983 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2982 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 2983 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 2984 | 2984 | } |
| 2985 | 2985 | $src[] = $regs[0][$k]; |
| 2986 | 2986 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -3029,7 +3029,7 @@ discard block |
||
| 3029 | 3029 | |
| 3030 | 3030 | $f = basename($css, '.css'); |
| 3031 | 3031 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3032 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3032 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3033 | 3033 | . '.css'; |
| 3034 | 3034 | |
| 3035 | 3035 | if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
@@ -3039,7 +3039,7 @@ discard block |
||
| 3039 | 3039 | if ($url_absolue_css == $css) { |
| 3040 | 3040 | if ( |
| 3041 | 3041 | strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 3042 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3042 | + or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3043 | 3043 | ) { |
| 3044 | 3044 | include_spip('inc/distant'); |
| 3045 | 3045 | $contenu = recuperer_url($css); |
@@ -3151,7 +3151,7 @@ discard block |
||
| 3151 | 3151 | $expression = str_replace('\/', '/', $expression); |
| 3152 | 3152 | $expression = str_replace('/', '\/', $expression); |
| 3153 | 3153 | |
| 3154 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3154 | + if (preg_match('/'.$expression.'/'.$modif, $texte ?? '', $r)) { |
|
| 3155 | 3155 | if (isset($r[$capte])) { |
| 3156 | 3156 | return $r[$capte]; |
| 3157 | 3157 | } else { |
@@ -3193,7 +3193,7 @@ discard block |
||
| 3193 | 3193 | $expression = str_replace('\/', '/', $expression); |
| 3194 | 3194 | $expression = str_replace('/', '\/', $expression); |
| 3195 | 3195 | |
| 3196 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3196 | + return (string) preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3197 | 3197 | } |
| 3198 | 3198 | |
| 3199 | 3199 | |
@@ -3212,7 +3212,7 @@ discard block |
||
| 3212 | 3212 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3213 | 3213 | |
| 3214 | 3214 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3215 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3215 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3216 | 3216 | |
| 3217 | 3217 | if ( |
| 3218 | 3218 | strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
@@ -3226,7 +3226,7 @@ discard block |
||
| 3226 | 3226 | if (!isset($doublons['documents'])) { |
| 3227 | 3227 | $doublons['documents'] = ''; |
| 3228 | 3228 | } |
| 3229 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3229 | + $doublons['documents'] .= ','.join(',', $matches[1]); |
|
| 3230 | 3230 | } |
| 3231 | 3231 | |
| 3232 | 3232 | return $letexte; |
@@ -3283,7 +3283,7 @@ discard block |
||
| 3283 | 3283 | if ($env) { |
| 3284 | 3284 | foreach ($env as $i => $j) { |
| 3285 | 3285 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3286 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3286 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3287 | 3287 | } |
| 3288 | 3288 | } |
| 3289 | 3289 | } |
@@ -3322,7 +3322,7 @@ discard block |
||
| 3322 | 3322 | if ($env) { |
| 3323 | 3323 | foreach ($env as $i => $j) { |
| 3324 | 3324 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3325 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3325 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3326 | 3326 | } |
| 3327 | 3327 | } |
| 3328 | 3328 | } |
@@ -3396,10 +3396,10 @@ discard block |
||
| 3396 | 3396 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3397 | 3397 | if ( |
| 3398 | 3398 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3399 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3399 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg' |
|
| 3400 | 3400 | and file_exists($variante_svg_generique) |
| 3401 | 3401 | ) { |
| 3402 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3402 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) { |
|
| 3403 | 3403 | $img_file = $variante_svg_size; |
| 3404 | 3404 | } |
| 3405 | 3405 | else { |
@@ -3457,7 +3457,7 @@ discard block |
||
| 3457 | 3457 | return ''; |
| 3458 | 3458 | } |
| 3459 | 3459 | } |
| 3460 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3460 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3461 | 3461 | } |
| 3462 | 3462 | |
| 3463 | 3463 | if (file_exists($img_file)) { |
@@ -3467,14 +3467,14 @@ discard block |
||
| 3467 | 3467 | $alt = ''; |
| 3468 | 3468 | } |
| 3469 | 3469 | elseif ($alt or $alt === '') { |
| 3470 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3470 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3471 | 3471 | } |
| 3472 | 3472 | else { |
| 3473 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3473 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3474 | 3474 | } |
| 3475 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3476 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3477 | - . ' ' . ltrim($atts) |
|
| 3475 | + return "<img src='".attribut_html($img_file)."'$alt" |
|
| 3476 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3477 | + . ' '.ltrim($atts) |
|
| 3478 | 3478 | . ' />'; |
| 3479 | 3479 | } |
| 3480 | 3480 | |
@@ -3488,10 +3488,10 @@ discard block |
||
| 3488 | 3488 | */ |
| 3489 | 3489 | function http_style_background($img, $att = '', $size = null) { |
| 3490 | 3490 | if ($size and is_numeric($size)) { |
| 3491 | - $size = trim($size) . 'px'; |
|
| 3491 | + $size = trim($size).'px'; |
|
| 3492 | 3492 | } |
| 3493 | - return " style='background" . |
|
| 3494 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3493 | + return " style='background". |
|
| 3494 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3495 | 3495 | . ($size ? "background-size:{$size};" : '') |
| 3496 | 3496 | . "'"; |
| 3497 | 3497 | } |
@@ -3606,7 +3606,7 @@ discard block |
||
| 3606 | 3606 | $img = http_img_pack( |
| 3607 | 3607 | $img, |
| 3608 | 3608 | $alt, |
| 3609 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3609 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3610 | 3610 | '', |
| 3611 | 3611 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3612 | 3612 | ); |
@@ -3691,7 +3691,7 @@ discard block |
||
| 3691 | 3691 | $balise_svg_source = $balise_svg; |
| 3692 | 3692 | |
| 3693 | 3693 | // entete XML à supprimer |
| 3694 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3694 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg); |
|
| 3695 | 3695 | |
| 3696 | 3696 | // IE est toujours mon ami |
| 3697 | 3697 | $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
@@ -3709,9 +3709,9 @@ discard block |
||
| 3709 | 3709 | // regler le alt |
| 3710 | 3710 | if ($alt) { |
| 3711 | 3711 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3712 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3712 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3713 | 3713 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3714 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3714 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3715 | 3715 | $balise_svg .= $title; |
| 3716 | 3716 | } |
| 3717 | 3717 | else { |
@@ -3759,7 +3759,7 @@ discard block |
||
| 3759 | 3759 | if (is_array($tableau)) { |
| 3760 | 3760 | foreach ($tableau as $k => $v) { |
| 3761 | 3761 | $res = recuperer_fond( |
| 3762 | - 'modeles/' . $modele, |
|
| 3762 | + 'modeles/'.$modele, |
|
| 3763 | 3763 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3764 | 3764 | ); |
| 3765 | 3765 | $texte .= $res; |
@@ -3944,7 +3944,7 @@ discard block |
||
| 3944 | 3944 | } |
| 3945 | 3945 | |
| 3946 | 3946 | $c = serialize($c); |
| 3947 | - $cle = calculer_cle_action($form . $c); |
|
| 3947 | + $cle = calculer_cle_action($form.$c); |
|
| 3948 | 3948 | $c = "$cle:$c"; |
| 3949 | 3949 | |
| 3950 | 3950 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -4002,15 +4002,15 @@ discard block |
||
| 4002 | 4002 | } |
| 4003 | 4003 | // toujours encoder l'url source dans le bloc ajax |
| 4004 | 4004 | $r = self(); |
| 4005 | - $r = ' data-origin="' . $r . '"'; |
|
| 4005 | + $r = ' data-origin="'.$r.'"'; |
|
| 4006 | 4006 | $class = 'ajaxbloc'; |
| 4007 | 4007 | if ($ajaxid and is_string($ajaxid)) { |
| 4008 | 4008 | // ajaxid est normalement conforme a un nom de classe css |
| 4009 | 4009 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 4010 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4010 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 4011 | 4011 | } |
| 4012 | 4012 | |
| 4013 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4013 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4014 | 4014 | } |
| 4015 | 4015 | |
| 4016 | 4016 | /** |
@@ -4054,7 +4054,7 @@ discard block |
||
| 4054 | 4054 | $cle = substr($c, 0, $p); |
| 4055 | 4055 | $c = substr($c, $p + 1); |
| 4056 | 4056 | |
| 4057 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4057 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 4058 | 4058 | $env = @unserialize($c); |
| 4059 | 4059 | return $env; |
| 4060 | 4060 | } |
@@ -4175,13 +4175,13 @@ discard block |
||
| 4175 | 4175 | } |
| 4176 | 4176 | } |
| 4177 | 4177 | } |
| 4178 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4178 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4179 | 4179 | } else { |
| 4180 | 4180 | $bal = 'a'; |
| 4181 | 4181 | $att = "href='$url'" |
| 4182 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4183 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4184 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4182 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4183 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4184 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4185 | 4185 | . $evt; |
| 4186 | 4186 | } |
| 4187 | 4187 | if ($libelle === null) { |
@@ -4320,7 +4320,7 @@ discard block |
||
| 4320 | 4320 | |
| 4321 | 4321 | // Icône |
| 4322 | 4322 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4323 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4323 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4324 | 4324 | |
| 4325 | 4325 | // Markup final |
| 4326 | 4326 | if ($type == 'lien') { |
@@ -4595,20 +4595,20 @@ discard block |
||
| 4595 | 4595 | $class_form = 'ajax'; |
| 4596 | 4596 | $class = str_replace('ajax', '', $class); |
| 4597 | 4597 | } |
| 4598 | - $class_btn = 'submit ' . trim($class); |
|
| 4598 | + $class_btn = 'submit '.trim($class); |
|
| 4599 | 4599 | |
| 4600 | 4600 | if ($confirm) { |
| 4601 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4601 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4602 | 4602 | if ($callback) { |
| 4603 | 4603 | $callback = "$confirm?($callback):false"; |
| 4604 | 4604 | } else { |
| 4605 | 4605 | $callback = $confirm; |
| 4606 | 4606 | } |
| 4607 | 4607 | } |
| 4608 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4608 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4609 | 4609 | $title = $title ? " title='$title'" : ''; |
| 4610 | 4610 | |
| 4611 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4611 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4612 | 4612 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4613 | 4613 | } |
| 4614 | 4614 | |
@@ -4673,14 +4673,14 @@ discard block |
||
| 4673 | 4673 | $champ_titre = ''; |
| 4674 | 4674 | if ($demande_titre) { |
| 4675 | 4675 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4676 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4676 | + $champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : ''; |
|
| 4677 | 4677 | } |
| 4678 | 4678 | include_spip('base/abstract_sql'); |
| 4679 | 4679 | include_spip('base/connect_sql'); |
| 4680 | 4680 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4681 | - '*' . $champ_titre, |
|
| 4681 | + '*'.$champ_titre, |
|
| 4682 | 4682 | $desc['table_sql'], |
| 4683 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4683 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 4684 | 4684 | ); |
| 4685 | 4685 | |
| 4686 | 4686 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4773,8 +4773,7 @@ discard block |
||
| 4773 | 4773 | if (isset($ligne_sql['chapo'])) { |
| 4774 | 4774 | $chapo = $ligne_sql['chapo']; |
| 4775 | 4775 | $texte = strlen($descriptif) ? |
| 4776 | - '' : |
|
| 4777 | - "$chapo \n\n $texte"; |
|
| 4776 | + '' : "$chapo \n\n $texte"; |
|
| 4778 | 4777 | } |
| 4779 | 4778 | |
| 4780 | 4779 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4849,7 +4848,7 @@ discard block |
||
| 4849 | 4848 | return $texte; |
| 4850 | 4849 | } |
| 4851 | 4850 | |
| 4852 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4851 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4853 | 4852 | |
| 4854 | 4853 | // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
| 4855 | 4854 | if (test_espace_prive()) { |
@@ -4888,7 +4887,7 @@ discard block |
||
| 4888 | 4887 | } |
| 4889 | 4888 | $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
| 4890 | 4889 | |
| 4891 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4890 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 4892 | 4891 | } |
| 4893 | 4892 | |
| 4894 | 4893 | /** |
@@ -4914,10 +4913,10 @@ discard block |
||
| 4914 | 4913 | function wrap($texte, $wrap) { |
| 4915 | 4914 | $balises = extraire_balises($wrap); |
| 4916 | 4915 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4917 | - $texte = $wrap . $texte; |
|
| 4916 | + $texte = $wrap.$texte; |
|
| 4918 | 4917 | $regs = array_reverse($regs[1]); |
| 4919 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4920 | - $texte = $texte . $wrap; |
|
| 4918 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 4919 | + $texte = $texte.$wrap; |
|
| 4921 | 4920 | } |
| 4922 | 4921 | |
| 4923 | 4922 | return $texte; |
@@ -4948,7 +4947,7 @@ discard block |
||
| 4948 | 4947 | |
| 4949 | 4948 | // caster $u en array si besoin |
| 4950 | 4949 | if (is_object($u)) { |
| 4951 | - $u = (array)$u; |
|
| 4950 | + $u = (array) $u; |
|
| 4952 | 4951 | } |
| 4953 | 4952 | |
| 4954 | 4953 | if (is_array($u)) { |
@@ -4970,7 +4969,7 @@ discard block |
||
| 4970 | 4969 | // sinon on passe a la ligne et on indente |
| 4971 | 4970 | $i_str = str_pad('', $indent, ' '); |
| 4972 | 4971 | foreach ($u as $k => $v) { |
| 4973 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4972 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4974 | 4973 | } |
| 4975 | 4974 | |
| 4976 | 4975 | return $out; |
@@ -5024,7 +5023,7 @@ discard block |
||
| 5024 | 5023 | * @return string |
| 5025 | 5024 | */ |
| 5026 | 5025 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5027 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5026 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 5028 | 5027 | $icone = chemin_image($icone); |
| 5029 | 5028 | $balise_img = charger_filtre('balise_img'); |
| 5030 | 5029 | |
@@ -5050,7 +5049,7 @@ discard block |
||
| 5050 | 5049 | */ |
| 5051 | 5050 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5052 | 5051 | $chaine = explode(':', $chaine); |
| 5053 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5052 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5054 | 5053 | return $t; |
| 5055 | 5054 | } |
| 5056 | 5055 | $chaine = implode(':', $chaine); |
@@ -5116,7 +5115,7 @@ discard block |
||
| 5116 | 5115 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5117 | 5116 | |
| 5118 | 5117 | // calculer le nom de la css |
| 5119 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5118 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5120 | 5119 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5121 | 5120 | $contexte_implicite = calculer_contexte_implicite(); |
| 5122 | 5121 | |
@@ -5124,14 +5123,14 @@ discard block |
||
| 5124 | 5123 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5125 | 5124 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5126 | 5125 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5127 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5126 | + $hash = md5($contexte_implicite['host'].'::'.$cache); |
|
| 5128 | 5127 | } |
| 5129 | 5128 | else { |
| 5130 | 5129 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5131 | 5130 | ksort($contexte); |
| 5132 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5131 | + $hash = md5($fond.json_encode($contexte_implicite, JSON_THROW_ON_ERROR).json_encode($contexte, JSON_THROW_ON_ERROR).$connect); |
|
| 5133 | 5132 | } |
| 5134 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5133 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5135 | 5134 | |
| 5136 | 5135 | // mettre a jour le fichier si il n'existe pas |
| 5137 | 5136 | // ou trop ancien |
@@ -5139,8 +5138,8 @@ discard block |
||
| 5139 | 5138 | // et recopie sur le fichier cible uniquement si il change |
| 5140 | 5139 | if ( |
| 5141 | 5140 | !file_exists($filename) |
| 5142 | - or !file_exists($filename . '.last') |
|
| 5143 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5141 | + or !file_exists($filename.'.last') |
|
| 5142 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified']) |
|
| 5144 | 5143 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 5145 | 5144 | ) { |
| 5146 | 5145 | $contenu = $cache['texte']; |
@@ -5164,10 +5163,10 @@ discard block |
||
| 5164 | 5163 | } |
| 5165 | 5164 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5166 | 5165 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5167 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5166 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 5168 | 5167 | } |
| 5169 | 5168 | // et ecrire le fichier si il change |
| 5170 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5169 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5171 | 5170 | } |
| 5172 | 5171 | |
| 5173 | 5172 | return timestamp($filename); |
@@ -5400,7 +5399,7 @@ discard block |
||
| 5400 | 5399 | if ($e > 0 and strlen($mid) > 8) { |
| 5401 | 5400 | $mid = '***...***'; |
| 5402 | 5401 | } |
| 5403 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5402 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5404 | 5403 | } |
| 5405 | 5404 | |
| 5406 | 5405 | |
@@ -5462,7 +5461,7 @@ discard block |
||
| 5462 | 5461 | case 'id': |
| 5463 | 5462 | case 'anchor': |
| 5464 | 5463 | if (preg_match(',^\d,', $texte)) { |
| 5465 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5464 | + $texte = substr($type, 0, 1).$texte; |
|
| 5466 | 5465 | } |
| 5467 | 5466 | } |
| 5468 | 5467 | |
@@ -5472,9 +5471,9 @@ discard block |
||
| 5472 | 5471 | |
| 5473 | 5472 | if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
| 5474 | 5473 | if (preg_match(',^\d,', $texte)) { |
| 5475 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5474 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5476 | 5475 | } |
| 5477 | - $texte .= $separateur . md5($original); |
|
| 5476 | + $texte .= $separateur.md5($original); |
|
| 5478 | 5477 | $texte = substr($texte, 0, $longueur_mini); |
| 5479 | 5478 | } |
| 5480 | 5479 | |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,33 +77,33 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - if (is_callable($f)) { |
|
| 102 | - return $f; |
|
| 103 | - } |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + if (is_callable($f)) { |
|
| 102 | + return $f; |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + return $default; |
|
| 107 | 107 | } |
| 108 | 108 | |
| 109 | 109 | /** |
@@ -147,8 +147,8 @@ discard block |
||
| 147 | 147 | * Chaîne vide sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function appliquer_filtre($arg, $filtre) { |
| 150 | - $args = func_get_args(); |
|
| 151 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 150 | + $args = func_get_args(); |
|
| 151 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | /** |
@@ -173,8 +173,8 @@ discard block |
||
| 173 | 173 | * texte d'origine sinon |
| 174 | 174 | **/ |
| 175 | 175 | function appliquer_si_filtre($arg, $filtre) { |
| 176 | - $args = func_get_args(); |
|
| 177 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 176 | + $args = func_get_args(); |
|
| 177 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | 180 | /** |
@@ -190,12 +190,12 @@ discard block |
||
| 190 | 190 | * Version de SPIP |
| 191 | 191 | **/ |
| 192 | 192 | function spip_version() { |
| 193 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | - $version .= " $vcs_version"; |
|
| 196 | - } |
|
| 193 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 194 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 195 | + $version .= " $vcs_version"; |
|
| 196 | + } |
|
| 197 | 197 | |
| 198 | - return $version; |
|
| 198 | + return $version; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -207,11 +207,11 @@ discard block |
||
| 207 | 207 | * @return string |
| 208 | 208 | */ |
| 209 | 209 | function header_silencieux($version): string { |
| 210 | - if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | - $version = ''; |
|
| 212 | - } |
|
| 210 | + if (isset($GLOBALS['spip_header_silencieux']) && (bool) $GLOBALS['spip_header_silencieux']) { |
|
| 211 | + $version = ''; |
|
| 212 | + } |
|
| 213 | 213 | |
| 214 | - return (string) $version; |
|
| 214 | + return (string) $version; |
|
| 215 | 215 | } |
| 216 | 216 | |
| 217 | 217 | /** |
@@ -224,16 +224,16 @@ discard block |
||
| 224 | 224 | * - string|null si $raw = false |
| 225 | 225 | */ |
| 226 | 226 | function version_vcs_courante($dir, $raw = false) { |
| 227 | - $desc = decrire_version_git($dir); |
|
| 228 | - if ($desc === null or $raw) { |
|
| 229 | - return $desc; |
|
| 230 | - } |
|
| 231 | - // affichage "GIT [master: abcdef]" |
|
| 232 | - $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 233 | - if ($desc['branch']) { |
|
| 234 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 235 | - } |
|
| 236 | - return "{$desc['vcs']} [$commit]"; |
|
| 227 | + $desc = decrire_version_git($dir); |
|
| 228 | + if ($desc === null or $raw) { |
|
| 229 | + return $desc; |
|
| 230 | + } |
|
| 231 | + // affichage "GIT [master: abcdef]" |
|
| 232 | + $commit = $desc['commit_short'] ?? $desc['commit']; |
|
| 233 | + if ($desc['branch']) { |
|
| 234 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 235 | + } |
|
| 236 | + return "{$desc['vcs']} [$commit]"; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -245,24 +245,24 @@ discard block |
||
| 245 | 245 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 246 | 246 | **/ |
| 247 | 247 | function decrire_version_git($dir) { |
| 248 | - if (!$dir) { |
|
| 249 | - $dir = '.'; |
|
| 250 | - } |
|
| 251 | - |
|
| 252 | - // version installee par GIT |
|
| 253 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 254 | - $currentHead = trim(substr($c, 4)); |
|
| 255 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 256 | - return [ |
|
| 257 | - 'vcs' => 'GIT', |
|
| 258 | - 'branch' => basename($currentHead), |
|
| 259 | - 'commit' => trim($hash), |
|
| 260 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 261 | - ]; |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - |
|
| 265 | - return null; |
|
| 248 | + if (!$dir) { |
|
| 249 | + $dir = '.'; |
|
| 250 | + } |
|
| 251 | + |
|
| 252 | + // version installee par GIT |
|
| 253 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 254 | + $currentHead = trim(substr($c, 4)); |
|
| 255 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 256 | + return [ |
|
| 257 | + 'vcs' => 'GIT', |
|
| 258 | + 'branch' => basename($currentHead), |
|
| 259 | + 'commit' => trim($hash), |
|
| 260 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 261 | + ]; |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + |
|
| 265 | + return null; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -309,18 +309,18 @@ discard block |
||
| 309 | 309 | * Code HTML retourné par le filtre |
| 310 | 310 | **/ |
| 311 | 311 | function filtrer($filtre) { |
| 312 | - $tous = func_get_args(); |
|
| 313 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 314 | - return image_filtrer($tous); |
|
| 315 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 316 | - array_shift($tous); |
|
| 317 | - return $f(...$tous); |
|
| 318 | - } else { |
|
| 319 | - // le filtre n'existe pas, on provoque une erreur |
|
| 320 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 321 | - erreur_squelette($msg); |
|
| 322 | - return ''; |
|
| 323 | - } |
|
| 312 | + $tous = func_get_args(); |
|
| 313 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 314 | + return image_filtrer($tous); |
|
| 315 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 316 | + array_shift($tous); |
|
| 317 | + return $f(...$tous); |
|
| 318 | + } else { |
|
| 319 | + // le filtre n'existe pas, on provoque une erreur |
|
| 320 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 321 | + erreur_squelette($msg); |
|
| 322 | + return ''; |
|
| 323 | + } |
|
| 324 | 324 | } |
| 325 | 325 | |
| 326 | 326 | /** |
@@ -337,11 +337,11 @@ discard block |
||
| 337 | 337 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 338 | 338 | */ |
| 339 | 339 | function trouver_filtre_matrice($filtre) { |
| 340 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 341 | - find_in_path($f, '', true); |
|
| 342 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 343 | - } |
|
| 344 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 340 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 341 | + find_in_path($f, '', true); |
|
| 342 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 343 | + } |
|
| 344 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 345 | 345 | } |
| 346 | 346 | |
| 347 | 347 | |
@@ -369,8 +369,8 @@ discard block |
||
| 369 | 369 | * @return mixed |
| 370 | 370 | */ |
| 371 | 371 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 372 | - $Pile['vars'][$key] = $val; |
|
| 373 | - return $continue ? $val : ''; |
|
| 372 | + $Pile['vars'][$key] = $val; |
|
| 373 | + return $continue ? $val : ''; |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | /** |
@@ -396,8 +396,8 @@ discard block |
||
| 396 | 396 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 397 | 397 | */ |
| 398 | 398 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 399 | - $Pile[0][$key] = $val; |
|
| 400 | - return $continue ? $val : ''; |
|
| 399 | + $Pile[0][$key] = $val; |
|
| 400 | + return $continue ? $val : ''; |
|
| 401 | 401 | } |
| 402 | 402 | |
| 403 | 403 | /** |
@@ -406,8 +406,8 @@ discard block |
||
| 406 | 406 | * @return string |
| 407 | 407 | */ |
| 408 | 408 | function filtre_sanitize_env(&$Pile, $keys) { |
| 409 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 410 | - return ''; |
|
| 409 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 410 | + return ''; |
|
| 411 | 411 | } |
| 412 | 412 | |
| 413 | 413 | |
@@ -430,18 +430,18 @@ discard block |
||
| 430 | 430 | * @return mixed Retourne la valeur (sans la modifier). |
| 431 | 431 | */ |
| 432 | 432 | function filtre_debug($val, $key = null) { |
| 433 | - $debug = ( |
|
| 434 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 435 | - ) . var_export($val, true); |
|
| 433 | + $debug = ( |
|
| 434 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 435 | + ) . var_export($val, true); |
|
| 436 | 436 | |
| 437 | - include_spip('inc/autoriser'); |
|
| 438 | - if (autoriser('webmestre')) { |
|
| 439 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 440 | - } |
|
| 437 | + include_spip('inc/autoriser'); |
|
| 438 | + if (autoriser('webmestre')) { |
|
| 439 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 440 | + } |
|
| 441 | 441 | |
| 442 | - spip_log($debug, 'debug'); |
|
| 442 | + spip_log($debug, 'debug'); |
|
| 443 | 443 | |
| 444 | - return $val; |
|
| 444 | + return $val; |
|
| 445 | 445 | } |
| 446 | 446 | |
| 447 | 447 | |
@@ -471,84 +471,84 @@ discard block |
||
| 471 | 471 | * texte qui a reçu les filtres |
| 472 | 472 | **/ |
| 473 | 473 | function image_filtrer($args) { |
| 474 | - $filtre = array_shift($args); # enlever $filtre |
|
| 475 | - $texte = array_shift($args); |
|
| 476 | - if ($texte === null || !strlen($texte)) { |
|
| 477 | - return ''; |
|
| 478 | - } |
|
| 479 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 480 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 481 | - // Cas du nom de fichier local |
|
| 482 | - $is_file = trim($texte); |
|
| 483 | - if ( |
|
| 484 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 485 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 486 | - or strpos($is_file, '/') === 0 |
|
| 487 | - ) { |
|
| 488 | - $is_file = false; |
|
| 489 | - } |
|
| 490 | - if ($is_file) { |
|
| 491 | - $is_local_file = function ($path) { |
|
| 492 | - if (strpos($path, '?') !== false) { |
|
| 493 | - $path = supprimer_timestamp($path); |
|
| 494 | - // remove ?24px added by find_in_theme on .svg files |
|
| 495 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 496 | - } |
|
| 497 | - return file_exists($path); |
|
| 498 | - }; |
|
| 499 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 500 | - $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 501 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 502 | - return $res; |
|
| 503 | - } |
|
| 504 | - } |
|
| 505 | - |
|
| 506 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 507 | - if ( |
|
| 508 | - preg_match_all( |
|
| 509 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 510 | - $texte, |
|
| 511 | - $tags, |
|
| 512 | - PREG_SET_ORDER |
|
| 513 | - ) |
|
| 514 | - ) { |
|
| 515 | - foreach ($tags as $tag) { |
|
| 516 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 517 | - if ( |
|
| 518 | - !$class or |
|
| 519 | - (strpos($class, 'filtre_inactif') === false |
|
| 520 | - // compat historique a virer en 3.2 |
|
| 521 | - and !str_contains($class, 'no_image_filtrer')) |
|
| 522 | - ) { |
|
| 523 | - if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 524 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 525 | - if ($tag[1]) { |
|
| 526 | - $w = extraire_attribut($reduit, 'width'); |
|
| 527 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 528 | - $w = $regs[1]; |
|
| 529 | - } |
|
| 530 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 531 | - $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 532 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 533 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 534 | - } |
|
| 535 | - } |
|
| 536 | - // traiter aussi un eventuel mouseover |
|
| 537 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 538 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 539 | - $srcover = $match[1]; |
|
| 540 | - $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 546 | - } |
|
| 547 | - } |
|
| 548 | - } |
|
| 549 | - } |
|
| 550 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 551 | - return $texte; |
|
| 474 | + $filtre = array_shift($args); # enlever $filtre |
|
| 475 | + $texte = array_shift($args); |
|
| 476 | + if ($texte === null || !strlen($texte)) { |
|
| 477 | + return ''; |
|
| 478 | + } |
|
| 479 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 480 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 481 | + // Cas du nom de fichier local |
|
| 482 | + $is_file = trim($texte); |
|
| 483 | + if ( |
|
| 484 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 485 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 486 | + or strpos($is_file, '/') === 0 |
|
| 487 | + ) { |
|
| 488 | + $is_file = false; |
|
| 489 | + } |
|
| 490 | + if ($is_file) { |
|
| 491 | + $is_local_file = function ($path) { |
|
| 492 | + if (strpos($path, '?') !== false) { |
|
| 493 | + $path = supprimer_timestamp($path); |
|
| 494 | + // remove ?24px added by find_in_theme on .svg files |
|
| 495 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 496 | + } |
|
| 497 | + return file_exists($path); |
|
| 498 | + }; |
|
| 499 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 500 | + $res = $filtre("<img src='$is_file' />", ...$args); |
|
| 501 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 502 | + return $res; |
|
| 503 | + } |
|
| 504 | + } |
|
| 505 | + |
|
| 506 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 507 | + if ( |
|
| 508 | + preg_match_all( |
|
| 509 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 510 | + $texte, |
|
| 511 | + $tags, |
|
| 512 | + PREG_SET_ORDER |
|
| 513 | + ) |
|
| 514 | + ) { |
|
| 515 | + foreach ($tags as $tag) { |
|
| 516 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 517 | + if ( |
|
| 518 | + !$class or |
|
| 519 | + (strpos($class, 'filtre_inactif') === false |
|
| 520 | + // compat historique a virer en 3.2 |
|
| 521 | + and !str_contains($class, 'no_image_filtrer')) |
|
| 522 | + ) { |
|
| 523 | + if ($reduit = $filtre($tag[3], ...$args)) { |
|
| 524 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 525 | + if ($tag[1]) { |
|
| 526 | + $w = extraire_attribut($reduit, 'width'); |
|
| 527 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 528 | + $w = $regs[1]; |
|
| 529 | + } |
|
| 530 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 531 | + $style = preg_replace(',width:\s*\d+px,S', "width:{$w}px", $style); |
|
| 532 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 533 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 534 | + } |
|
| 535 | + } |
|
| 536 | + // traiter aussi un eventuel mouseover |
|
| 537 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 538 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 539 | + $srcover = $match[1]; |
|
| 540 | + $srcover_filter = $filtre("<img src='" . $match[1] . "' />", ...$args); |
|
| 541 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 542 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | + } |
|
| 549 | + } |
|
| 550 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 551 | + return $texte; |
|
| 552 | 552 | } |
| 553 | 553 | |
| 554 | 554 | /** |
@@ -565,94 +565,94 @@ discard block |
||
| 565 | 565 | **/ |
| 566 | 566 | function infos_image($img, $force_refresh = false) { |
| 567 | 567 | |
| 568 | - static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 569 | - $srcWidth = 0; |
|
| 570 | - $srcHeight = 0; |
|
| 571 | - $srcSize = null; |
|
| 572 | - |
|
| 573 | - $src = extraire_attribut($img, 'src'); |
|
| 574 | - |
|
| 575 | - if (!$src) { |
|
| 576 | - $src = $img; |
|
| 577 | - } else { |
|
| 578 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 579 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 580 | - if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 581 | - $srcWidth = $srcHeight = 0; |
|
| 582 | - } |
|
| 583 | - } |
|
| 584 | - |
|
| 585 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 586 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 587 | - if (tester_url_absolue($src)) { |
|
| 588 | - include_spip('inc/distant'); |
|
| 589 | - $fichier = copie_locale($src); |
|
| 590 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 591 | - } |
|
| 592 | - if (($p = strpos($src, '?')) !== false) { |
|
| 593 | - $src = substr($src, 0, $p); |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - $imagesize = false; |
|
| 597 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 598 | - $srcWidth = $largeur_img[$src]; |
|
| 599 | - } |
|
| 600 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 601 | - $srcHeight = $hauteur_img[$src]; |
|
| 602 | - } |
|
| 603 | - if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 604 | - $srcSize = $poids_img[$src]; |
|
| 605 | - } |
|
| 606 | - if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 607 | - if ( |
|
| 608 | - file_exists($src) |
|
| 609 | - and $imagesize = spip_getimagesize($src) |
|
| 610 | - ) { |
|
| 611 | - if (!$srcWidth) { |
|
| 612 | - $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 613 | - } |
|
| 614 | - if (!$srcHeight) { |
|
| 615 | - $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 616 | - } |
|
| 617 | - if (!$srcSize) { |
|
| 618 | - $poids_img[$src] = filesize($src); |
|
| 619 | - } |
|
| 620 | - } |
|
| 621 | - elseif (strpos($src, '<svg') !== false) { |
|
| 622 | - include_spip('inc/svg'); |
|
| 623 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 624 | - [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 625 | - if (!$srcWidth) { |
|
| 626 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 627 | - } |
|
| 628 | - if (!$srcHeight) { |
|
| 629 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 630 | - } |
|
| 631 | - if (!$srcSize) { |
|
| 632 | - $poids_img[$src] = $srcSize = strlen($src); |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - } |
|
| 636 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 637 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 638 | - elseif ( |
|
| 639 | - @file_exists($f = "$src.src") |
|
| 640 | - and lire_fichier($f, $valeurs) |
|
| 641 | - and $valeurs = unserialize($valeurs) |
|
| 642 | - ) { |
|
| 643 | - if (!$srcWidth) { |
|
| 644 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 645 | - } |
|
| 646 | - if (!$srcHeight) { |
|
| 647 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 648 | - } |
|
| 649 | - if (!$srcSize) { |
|
| 650 | - $poids_img[$src] = $srcSize = 0; |
|
| 651 | - } |
|
| 652 | - } |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 568 | + static $largeur_img = [], $hauteur_img = [], $poids_img = []; |
|
| 569 | + $srcWidth = 0; |
|
| 570 | + $srcHeight = 0; |
|
| 571 | + $srcSize = null; |
|
| 572 | + |
|
| 573 | + $src = extraire_attribut($img, 'src'); |
|
| 574 | + |
|
| 575 | + if (!$src) { |
|
| 576 | + $src = $img; |
|
| 577 | + } else { |
|
| 578 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 579 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 580 | + if (!ctype_digit(strval($srcWidth)) or !ctype_digit(strval($srcHeight))) { |
|
| 581 | + $srcWidth = $srcHeight = 0; |
|
| 582 | + } |
|
| 583 | + } |
|
| 584 | + |
|
| 585 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 586 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 587 | + if (tester_url_absolue($src)) { |
|
| 588 | + include_spip('inc/distant'); |
|
| 589 | + $fichier = copie_locale($src); |
|
| 590 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 591 | + } |
|
| 592 | + if (($p = strpos($src, '?')) !== false) { |
|
| 593 | + $src = substr($src, 0, $p); |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + $imagesize = false; |
|
| 597 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 598 | + $srcWidth = $largeur_img[$src]; |
|
| 599 | + } |
|
| 600 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 601 | + $srcHeight = $hauteur_img[$src]; |
|
| 602 | + } |
|
| 603 | + if (isset($poids_img[$src]) and !$force_refresh) { |
|
| 604 | + $srcSize = $poids_img[$src]; |
|
| 605 | + } |
|
| 606 | + if (!$srcWidth or !$srcHeight or is_null($srcSize)) { |
|
| 607 | + if ( |
|
| 608 | + file_exists($src) |
|
| 609 | + and $imagesize = spip_getimagesize($src) |
|
| 610 | + ) { |
|
| 611 | + if (!$srcWidth) { |
|
| 612 | + $largeur_img[$src] = $srcWidth = $imagesize[0]; |
|
| 613 | + } |
|
| 614 | + if (!$srcHeight) { |
|
| 615 | + $hauteur_img[$src] = $srcHeight = $imagesize[1]; |
|
| 616 | + } |
|
| 617 | + if (!$srcSize) { |
|
| 618 | + $poids_img[$src] = filesize($src); |
|
| 619 | + } |
|
| 620 | + } |
|
| 621 | + elseif (strpos($src, '<svg') !== false) { |
|
| 622 | + include_spip('inc/svg'); |
|
| 623 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 624 | + [$width, $height, $viewbox] = svg_getimagesize_from_attr($attrs); |
|
| 625 | + if (!$srcWidth) { |
|
| 626 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 627 | + } |
|
| 628 | + if (!$srcHeight) { |
|
| 629 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 630 | + } |
|
| 631 | + if (!$srcSize) { |
|
| 632 | + $poids_img[$src] = $srcSize = strlen($src); |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + } |
|
| 636 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 637 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 638 | + elseif ( |
|
| 639 | + @file_exists($f = "$src.src") |
|
| 640 | + and lire_fichier($f, $valeurs) |
|
| 641 | + and $valeurs = unserialize($valeurs) |
|
| 642 | + ) { |
|
| 643 | + if (!$srcWidth) { |
|
| 644 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 645 | + } |
|
| 646 | + if (!$srcHeight) { |
|
| 647 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 648 | + } |
|
| 649 | + if (!$srcSize) { |
|
| 650 | + $poids_img[$src] = $srcSize = 0; |
|
| 651 | + } |
|
| 652 | + } |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + return ['hauteur' => $srcHeight, 'largeur' => $srcWidth, 'poids' => $srcSize]; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -668,13 +668,13 @@ discard block |
||
| 668 | 668 | * poids |
| 669 | 669 | **/ |
| 670 | 670 | function poids_image($img, $force_refresh = false) { |
| 671 | - $infos = infos_image($img, $force_refresh); |
|
| 672 | - return $infos['poids']; |
|
| 671 | + $infos = infos_image($img, $force_refresh); |
|
| 672 | + return $infos['poids']; |
|
| 673 | 673 | } |
| 674 | 674 | |
| 675 | 675 | function taille_image($img, $force_refresh = false) { |
| 676 | - $infos = infos_image($img, $force_refresh); |
|
| 677 | - return [$infos['hauteur'], $infos['largeur']]; |
|
| 676 | + $infos = infos_image($img, $force_refresh); |
|
| 677 | + return [$infos['hauteur'], $infos['largeur']]; |
|
| 678 | 678 | } |
| 679 | 679 | |
| 680 | 680 | /** |
@@ -691,12 +691,12 @@ discard block |
||
| 691 | 691 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 692 | 692 | **/ |
| 693 | 693 | function largeur($img) { |
| 694 | - if (!$img) { |
|
| 695 | - return; |
|
| 696 | - } |
|
| 697 | - [$h, $l] = taille_image($img); |
|
| 694 | + if (!$img) { |
|
| 695 | + return; |
|
| 696 | + } |
|
| 697 | + [$h, $l] = taille_image($img); |
|
| 698 | 698 | |
| 699 | - return $l; |
|
| 699 | + return $l; |
|
| 700 | 700 | } |
| 701 | 701 | |
| 702 | 702 | /** |
@@ -713,12 +713,12 @@ discard block |
||
| 713 | 713 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 714 | 714 | **/ |
| 715 | 715 | function hauteur($img) { |
| 716 | - if (!$img) { |
|
| 717 | - return; |
|
| 718 | - } |
|
| 719 | - [$h, $l] = taille_image($img); |
|
| 716 | + if (!$img) { |
|
| 717 | + return; |
|
| 718 | + } |
|
| 719 | + [$h, $l] = taille_image($img); |
|
| 720 | 720 | |
| 721 | - return $h; |
|
| 721 | + return $h; |
|
| 722 | 722 | } |
| 723 | 723 | |
| 724 | 724 | |
@@ -738,11 +738,11 @@ discard block |
||
| 738 | 738 | * @return string |
| 739 | 739 | **/ |
| 740 | 740 | function corriger_entites_html($texte) { |
| 741 | - if (strpos($texte, '&') === false) { |
|
| 742 | - return $texte; |
|
| 743 | - } |
|
| 741 | + if (strpos($texte, '&') === false) { |
|
| 742 | + return $texte; |
|
| 743 | + } |
|
| 744 | 744 | |
| 745 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 745 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 746 | 746 | } |
| 747 | 747 | |
| 748 | 748 | /** |
@@ -757,11 +757,11 @@ discard block |
||
| 757 | 757 | * @return string |
| 758 | 758 | **/ |
| 759 | 759 | function corriger_toutes_entites_html($texte) { |
| 760 | - if (strpos($texte, '&') === false) { |
|
| 761 | - return $texte; |
|
| 762 | - } |
|
| 760 | + if (strpos($texte, '&') === false) { |
|
| 761 | + return $texte; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 764 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | /** |
@@ -771,7 +771,7 @@ discard block |
||
| 771 | 771 | * @return string |
| 772 | 772 | **/ |
| 773 | 773 | function proteger_amp($texte) { |
| 774 | - return str_replace('&', '&', $texte); |
|
| 774 | + return str_replace('&', '&', $texte); |
|
| 775 | 775 | } |
| 776 | 776 | |
| 777 | 777 | |
@@ -802,21 +802,21 @@ discard block |
||
| 802 | 802 | * @return mixed|string |
| 803 | 803 | */ |
| 804 | 804 | function entites_html($texte, $tout = false, $quote = true) { |
| 805 | - if ( |
|
| 806 | - !is_string($texte) or !$texte |
|
| 807 | - or strpbrk($texte, "&\"'<>") == false |
|
| 808 | - ) { |
|
| 809 | - return $texte; |
|
| 810 | - } |
|
| 811 | - include_spip('inc/texte'); |
|
| 812 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 813 | - $flags |= ENT_HTML401; |
|
| 814 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 815 | - if ($tout) { |
|
| 816 | - return corriger_toutes_entites_html($texte); |
|
| 817 | - } else { |
|
| 818 | - return corriger_entites_html($texte); |
|
| 819 | - } |
|
| 805 | + if ( |
|
| 806 | + !is_string($texte) or !$texte |
|
| 807 | + or strpbrk($texte, "&\"'<>") == false |
|
| 808 | + ) { |
|
| 809 | + return $texte; |
|
| 810 | + } |
|
| 811 | + include_spip('inc/texte'); |
|
| 812 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 813 | + $flags |= ENT_HTML401; |
|
| 814 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 815 | + if ($tout) { |
|
| 816 | + return corriger_toutes_entites_html($texte); |
|
| 817 | + } else { |
|
| 818 | + return corriger_entites_html($texte); |
|
| 819 | + } |
|
| 820 | 820 | } |
| 821 | 821 | |
| 822 | 822 | /** |
@@ -835,38 +835,38 @@ discard block |
||
| 835 | 835 | * texte converti |
| 836 | 836 | **/ |
| 837 | 837 | function filtrer_entites(?string $texte): string { |
| 838 | - $texte ??= ''; |
|
| 839 | - if (strpos($texte, '&') === false) { |
|
| 840 | - return $texte; |
|
| 841 | - } |
|
| 842 | - // filtrer |
|
| 843 | - $texte = html2unicode($texte); |
|
| 844 | - // remettre le tout dans le charset cible |
|
| 845 | - $texte = unicode2charset($texte); |
|
| 846 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 847 | - // (on le faisait deja avec un ") |
|
| 848 | - if (strpos($texte, '&#') !== false) { |
|
| 849 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 850 | - } |
|
| 838 | + $texte ??= ''; |
|
| 839 | + if (strpos($texte, '&') === false) { |
|
| 840 | + return $texte; |
|
| 841 | + } |
|
| 842 | + // filtrer |
|
| 843 | + $texte = html2unicode($texte); |
|
| 844 | + // remettre le tout dans le charset cible |
|
| 845 | + $texte = unicode2charset($texte); |
|
| 846 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 847 | + // (on le faisait deja avec un ") |
|
| 848 | + if (strpos($texte, '&#') !== false) { |
|
| 849 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - return $texte; |
|
| 852 | + return $texte; |
|
| 853 | 853 | } |
| 854 | 854 | |
| 855 | 855 | |
| 856 | 856 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 857 | - /** |
|
| 858 | - * Version sécurisée de filtrer_entites |
|
| 859 | - * |
|
| 860 | - * @uses interdire_scripts() |
|
| 861 | - * @uses filtrer_entites() |
|
| 862 | - * |
|
| 863 | - * @param string $t |
|
| 864 | - * @return string |
|
| 865 | - */ |
|
| 866 | - function filtre_filtrer_entites_dist($t) { |
|
| 867 | - include_spip('inc/texte'); |
|
| 868 | - return interdire_scripts(filtrer_entites($t)); |
|
| 869 | - } |
|
| 857 | + /** |
|
| 858 | + * Version sécurisée de filtrer_entites |
|
| 859 | + * |
|
| 860 | + * @uses interdire_scripts() |
|
| 861 | + * @uses filtrer_entites() |
|
| 862 | + * |
|
| 863 | + * @param string $t |
|
| 864 | + * @return string |
|
| 865 | + */ |
|
| 866 | + function filtre_filtrer_entites_dist($t) { |
|
| 867 | + include_spip('inc/texte'); |
|
| 868 | + return interdire_scripts(filtrer_entites($t)); |
|
| 869 | + } |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | |
@@ -881,18 +881,18 @@ discard block |
||
| 881 | 881 | * @return string|array |
| 882 | 882 | **/ |
| 883 | 883 | function supprimer_caracteres_illegaux($texte) { |
| 884 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 885 | - static $to = null; |
|
| 884 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 885 | + static $to = null; |
|
| 886 | 886 | |
| 887 | - if (is_array($texte)) { |
|
| 888 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 889 | - } |
|
| 887 | + if (is_array($texte)) { |
|
| 888 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 889 | + } |
|
| 890 | 890 | |
| 891 | - if (!$to) { |
|
| 892 | - $to = str_repeat('-', strlen($from)); |
|
| 893 | - } |
|
| 891 | + if (!$to) { |
|
| 892 | + $to = str_repeat('-', strlen($from)); |
|
| 893 | + } |
|
| 894 | 894 | |
| 895 | - return strtr($texte, $from, $to); |
|
| 895 | + return strtr($texte, $from, $to); |
|
| 896 | 896 | } |
| 897 | 897 | |
| 898 | 898 | /** |
@@ -904,10 +904,10 @@ discard block |
||
| 904 | 904 | * @return string|array |
| 905 | 905 | **/ |
| 906 | 906 | function corriger_caracteres($texte) { |
| 907 | - $texte = corriger_caracteres_windows($texte); |
|
| 908 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 907 | + $texte = corriger_caracteres_windows($texte); |
|
| 908 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 909 | 909 | |
| 910 | - return $texte; |
|
| 910 | + return $texte; |
|
| 911 | 911 | } |
| 912 | 912 | |
| 913 | 913 | /** |
@@ -924,44 +924,44 @@ discard block |
||
| 924 | 924 | * texte encodé pour XML |
| 925 | 925 | */ |
| 926 | 926 | function texte_backend(string $texte): string { |
| 927 | - if ($texte === '') { |
|
| 928 | - return ''; |
|
| 929 | - } |
|
| 927 | + if ($texte === '') { |
|
| 928 | + return ''; |
|
| 929 | + } |
|
| 930 | 930 | |
| 931 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 931 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 932 | 932 | |
| 933 | - // si on a des liens ou des images, les passer en absolu |
|
| 934 | - $texte = liens_absolus($texte); |
|
| 933 | + // si on a des liens ou des images, les passer en absolu |
|
| 934 | + $texte = liens_absolus($texte); |
|
| 935 | 935 | |
| 936 | - // echapper les tags > < |
|
| 937 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 936 | + // echapper les tags > < |
|
| 937 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 938 | 938 | |
| 939 | - // importer les é |
|
| 940 | - $texte = filtrer_entites($texte); |
|
| 939 | + // importer les é |
|
| 940 | + $texte = filtrer_entites($texte); |
|
| 941 | 941 | |
| 942 | - // " -> " et tout ce genre de choses |
|
| 943 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 944 | - $texte = str_replace(' ', ' ', $texte); |
|
| 945 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 946 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 947 | - $texte = entites_html($texte, false, false); |
|
| 948 | - // mais bien echapper les double quotes ! |
|
| 949 | - $texte = str_replace('"', '"', $texte); |
|
| 942 | + // " -> " et tout ce genre de choses |
|
| 943 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 944 | + $texte = str_replace(' ', ' ', $texte); |
|
| 945 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 946 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 947 | + $texte = entites_html($texte, false, false); |
|
| 948 | + // mais bien echapper les double quotes ! |
|
| 949 | + $texte = str_replace('"', '"', $texte); |
|
| 950 | 950 | |
| 951 | - // verifier le charset |
|
| 952 | - $texte = charset2unicode($texte); |
|
| 951 | + // verifier le charset |
|
| 952 | + $texte = charset2unicode($texte); |
|
| 953 | 953 | |
| 954 | - // Caracteres problematiques en iso-latin 1 |
|
| 955 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 956 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 957 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 958 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 959 | - } |
|
| 954 | + // Caracteres problematiques en iso-latin 1 |
|
| 955 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 956 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 957 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 958 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 959 | + } |
|
| 960 | 960 | |
| 961 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 962 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 963 | - // ==> on les remplace par l'entite HTML |
|
| 964 | - return str_replace($apostrophe, "'", $texte); |
|
| 961 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 962 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 963 | + // ==> on les remplace par l'entite HTML |
|
| 964 | + return str_replace($apostrophe, "'", $texte); |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | /** |
@@ -978,7 +978,7 @@ discard block |
||
| 978 | 978 | * texte encodé et quote pour XML |
| 979 | 979 | */ |
| 980 | 980 | function texte_backendq(string $texte): string { |
| 981 | - return addslashes(texte_backend($texte)); |
|
| 981 | + return addslashes(texte_backend($texte)); |
|
| 982 | 982 | } |
| 983 | 983 | |
| 984 | 984 | |
@@ -1000,14 +1000,14 @@ discard block |
||
| 1000 | 1000 | * Texte sans son numéro éventuel |
| 1001 | 1001 | **/ |
| 1002 | 1002 | function supprimer_numero(?string $texte): string { |
| 1003 | - if ($texte === null) { |
|
| 1004 | - return ''; |
|
| 1005 | - } |
|
| 1006 | - return preg_replace( |
|
| 1007 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1008 | - '', |
|
| 1009 | - $texte |
|
| 1010 | - ); |
|
| 1003 | + if ($texte === null) { |
|
| 1004 | + return ''; |
|
| 1005 | + } |
|
| 1006 | + return preg_replace( |
|
| 1007 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1008 | + '', |
|
| 1009 | + $texte |
|
| 1010 | + ); |
|
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | 1013 | /** |
@@ -1030,18 +1030,18 @@ discard block |
||
| 1030 | 1030 | * Numéro de titre, sinon chaîne vide |
| 1031 | 1031 | **/ |
| 1032 | 1032 | function recuperer_numero(?string $texte): string { |
| 1033 | - if ( |
|
| 1034 | - $texte and |
|
| 1035 | - preg_match( |
|
| 1036 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1037 | - $texte, |
|
| 1038 | - $regs |
|
| 1039 | - ) |
|
| 1040 | - ) { |
|
| 1041 | - return strval($regs[1]); |
|
| 1042 | - } else { |
|
| 1043 | - return ''; |
|
| 1044 | - } |
|
| 1033 | + if ( |
|
| 1034 | + $texte and |
|
| 1035 | + preg_match( |
|
| 1036 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1037 | + $texte, |
|
| 1038 | + $regs |
|
| 1039 | + ) |
|
| 1040 | + ) { |
|
| 1041 | + return strval($regs[1]); |
|
| 1042 | + } else { |
|
| 1043 | + return ''; |
|
| 1044 | + } |
|
| 1045 | 1045 | } |
| 1046 | 1046 | |
| 1047 | 1047 | /** |
@@ -1068,16 +1068,16 @@ discard block |
||
| 1068 | 1068 | * texte ou tableau de textes converti |
| 1069 | 1069 | **/ |
| 1070 | 1070 | function supprimer_tags($texte, $rempl = '') { |
| 1071 | - if ($texte === null) { |
|
| 1072 | - return ''; |
|
| 1073 | - } |
|
| 1074 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1075 | - // ne pas oublier un < final non ferme car coupe |
|
| 1076 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1077 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1078 | - $texte = str_replace('<', '<', $texte); |
|
| 1071 | + if ($texte === null) { |
|
| 1072 | + return ''; |
|
| 1073 | + } |
|
| 1074 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1075 | + // ne pas oublier un < final non ferme car coupe |
|
| 1076 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1077 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1078 | + $texte = str_replace('<', '<', $texte); |
|
| 1079 | 1079 | |
| 1080 | - return $texte; |
|
| 1080 | + return $texte; |
|
| 1081 | 1081 | } |
| 1082 | 1082 | |
| 1083 | 1083 | /** |
@@ -1100,9 +1100,9 @@ discard block |
||
| 1100 | 1100 | * texte converti |
| 1101 | 1101 | **/ |
| 1102 | 1102 | function echapper_tags($texte, $rempl = '') { |
| 1103 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1103 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1104 | 1104 | |
| 1105 | - return $texte; |
|
| 1105 | + return $texte; |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1123,18 +1123,18 @@ discard block |
||
| 1123 | 1123 | * texte converti |
| 1124 | 1124 | **/ |
| 1125 | 1125 | function textebrut($texte) { |
| 1126 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1127 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1128 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1129 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1130 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1131 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1132 | - $texte = supprimer_tags($texte); |
|
| 1133 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1134 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1135 | - $texte = str_replace('’', "'", $texte); |
|
| 1126 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1127 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1128 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1129 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1130 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1131 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1132 | + $texte = supprimer_tags($texte); |
|
| 1133 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1134 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1135 | + $texte = str_replace('’', "'", $texte); |
|
| 1136 | 1136 | |
| 1137 | - return $texte; |
|
| 1137 | + return $texte; |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | |
@@ -1150,23 +1150,23 @@ discard block |
||
| 1150 | 1150 | * texte avec liens ouvrants |
| 1151 | 1151 | **/ |
| 1152 | 1152 | function liens_ouvrants($texte) { |
| 1153 | - if ( |
|
| 1154 | - preg_match_all( |
|
| 1155 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1156 | - $texte, |
|
| 1157 | - $liens, |
|
| 1158 | - PREG_PATTERN_ORDER |
|
| 1159 | - ) |
|
| 1160 | - ) { |
|
| 1161 | - foreach ($liens[0] as $a) { |
|
| 1162 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1163 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1164 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1165 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1166 | - } |
|
| 1167 | - } |
|
| 1168 | - |
|
| 1169 | - return $texte; |
|
| 1153 | + if ( |
|
| 1154 | + preg_match_all( |
|
| 1155 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1156 | + $texte, |
|
| 1157 | + $liens, |
|
| 1158 | + PREG_PATTERN_ORDER |
|
| 1159 | + ) |
|
| 1160 | + ) { |
|
| 1161 | + foreach ($liens[0] as $a) { |
|
| 1162 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1163 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1164 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1165 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1166 | + } |
|
| 1167 | + } |
|
| 1168 | + |
|
| 1169 | + return $texte; |
|
| 1170 | 1170 | } |
| 1171 | 1171 | |
| 1172 | 1172 | /** |
@@ -1176,22 +1176,22 @@ discard block |
||
| 1176 | 1176 | * @return string |
| 1177 | 1177 | */ |
| 1178 | 1178 | function liens_nofollow($texte) { |
| 1179 | - if (stripos($texte, '<a') === false) { |
|
| 1180 | - return $texte; |
|
| 1181 | - } |
|
| 1179 | + if (stripos($texte, '<a') === false) { |
|
| 1180 | + return $texte; |
|
| 1181 | + } |
|
| 1182 | 1182 | |
| 1183 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1184 | - foreach ($regs[0] as $a) { |
|
| 1185 | - $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1186 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1187 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1188 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1189 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1190 | - } |
|
| 1191 | - } |
|
| 1192 | - } |
|
| 1183 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1184 | + foreach ($regs[0] as $a) { |
|
| 1185 | + $rel = extraire_attribut($a, 'rel') ?? ''; |
|
| 1186 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1187 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1188 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1189 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1190 | + } |
|
| 1191 | + } |
|
| 1192 | + } |
|
| 1193 | 1193 | |
| 1194 | - return $texte; |
|
| 1194 | + return $texte; |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | /** |
@@ -1210,12 +1210,12 @@ discard block |
||
| 1210 | 1210 | * texte sans paraghaphes |
| 1211 | 1211 | **/ |
| 1212 | 1212 | function PtoBR($texte) { |
| 1213 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1214 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1215 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1216 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1213 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1214 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1215 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1216 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1217 | 1217 | |
| 1218 | - return $texte; |
|
| 1218 | + return $texte; |
|
| 1219 | 1219 | } |
| 1220 | 1220 | |
| 1221 | 1221 | |
@@ -1240,19 +1240,19 @@ discard block |
||
| 1240 | 1240 | * @return string texte encadré du style CSS |
| 1241 | 1241 | */ |
| 1242 | 1242 | function lignes_longues($texte) { |
| 1243 | - trigger_error( |
|
| 1244 | - sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1245 | - \E_USER_DEPRECATED |
|
| 1246 | - ); |
|
| 1243 | + trigger_error( |
|
| 1244 | + sprintf('Usage of function or filter \'%s\' is deprecated. Use CSS instead.', __FUNCTION__), |
|
| 1245 | + \E_USER_DEPRECATED |
|
| 1246 | + ); |
|
| 1247 | 1247 | |
| 1248 | - if (!strlen(trim($texte))) { |
|
| 1249 | - return $texte; |
|
| 1250 | - } |
|
| 1251 | - include_spip('inc/texte'); |
|
| 1252 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1253 | - 'div' : 'span'; |
|
| 1248 | + if (!strlen(trim($texte))) { |
|
| 1249 | + return $texte; |
|
| 1250 | + } |
|
| 1251 | + include_spip('inc/texte'); |
|
| 1252 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1253 | + 'div' : 'span'; |
|
| 1254 | 1254 | |
| 1255 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1255 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | /** |
@@ -1271,30 +1271,30 @@ discard block |
||
| 1271 | 1271 | * @return string texte en majuscule |
| 1272 | 1272 | */ |
| 1273 | 1273 | function majuscules($texte) { |
| 1274 | - if (!strlen($texte)) { |
|
| 1275 | - return ''; |
|
| 1276 | - } |
|
| 1274 | + if (!strlen($texte)) { |
|
| 1275 | + return ''; |
|
| 1276 | + } |
|
| 1277 | 1277 | |
| 1278 | - // Cas du turc |
|
| 1279 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1280 | - # remplacer hors des tags et des entites |
|
| 1281 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1282 | - foreach ($regs as $n => $match) { |
|
| 1283 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1284 | - } |
|
| 1285 | - } |
|
| 1278 | + // Cas du turc |
|
| 1279 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1280 | + # remplacer hors des tags et des entites |
|
| 1281 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1282 | + foreach ($regs as $n => $match) { |
|
| 1283 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1284 | + } |
|
| 1285 | + } |
|
| 1286 | 1286 | |
| 1287 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1287 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1288 | 1288 | |
| 1289 | - if ($regs) { |
|
| 1290 | - foreach ($regs as $n => $match) { |
|
| 1291 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1292 | - } |
|
| 1293 | - } |
|
| 1294 | - } |
|
| 1289 | + if ($regs) { |
|
| 1290 | + foreach ($regs as $n => $match) { |
|
| 1291 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1292 | + } |
|
| 1293 | + } |
|
| 1294 | + } |
|
| 1295 | 1295 | |
| 1296 | - // Cas general |
|
| 1297 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1296 | + // Cas general |
|
| 1297 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1316,38 +1316,38 @@ discard block |
||
| 1316 | 1316 | */ |
| 1317 | 1317 | function taille_en_octets($octets, $systeme = 'BI') { |
| 1318 | 1318 | |
| 1319 | - // Texte à afficher pour la taille |
|
| 1320 | - $affichage = ''; |
|
| 1319 | + // Texte à afficher pour la taille |
|
| 1320 | + $affichage = ''; |
|
| 1321 | 1321 | |
| 1322 | - static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1323 | - static $precisions = [0, 1, 1, 2]; |
|
| 1322 | + static $unites = ['octets', 'ko', 'mo', 'go']; |
|
| 1323 | + static $precisions = [0, 1, 1, 2]; |
|
| 1324 | 1324 | |
| 1325 | - if ($octets >= 1) { |
|
| 1326 | - // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1327 | - $systeme = strtolower($systeme); |
|
| 1328 | - if ($systeme === 'bi') { |
|
| 1329 | - $kilo = 1024; |
|
| 1330 | - $suffixe_item = "_$systeme"; |
|
| 1331 | - } elseif ($systeme === 'si') { |
|
| 1332 | - $kilo = 1000; |
|
| 1333 | - $suffixe_item = ''; |
|
| 1334 | - } else { |
|
| 1335 | - return $affichage; |
|
| 1336 | - } |
|
| 1325 | + if ($octets >= 1) { |
|
| 1326 | + // Déterminer le nombre d'octets représentant le kilo en fonction du système choisi |
|
| 1327 | + $systeme = strtolower($systeme); |
|
| 1328 | + if ($systeme === 'bi') { |
|
| 1329 | + $kilo = 1024; |
|
| 1330 | + $suffixe_item = "_$systeme"; |
|
| 1331 | + } elseif ($systeme === 'si') { |
|
| 1332 | + $kilo = 1000; |
|
| 1333 | + $suffixe_item = ''; |
|
| 1334 | + } else { |
|
| 1335 | + return $affichage; |
|
| 1336 | + } |
|
| 1337 | 1337 | |
| 1338 | - // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1339 | - $puissance = floor(log($octets, $kilo)); |
|
| 1338 | + // Identification de la puissance en "kilo" correspondant à l'unité la plus appropriée |
|
| 1339 | + $puissance = floor(log($octets, $kilo)); |
|
| 1340 | 1340 | |
| 1341 | - // Calcul de la taille et choix de l'unité |
|
| 1342 | - $affichage = _T( |
|
| 1343 | - 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1344 | - [ |
|
| 1345 | - 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1346 | - ] |
|
| 1347 | - ); |
|
| 1348 | - } |
|
| 1341 | + // Calcul de la taille et choix de l'unité |
|
| 1342 | + $affichage = _T( |
|
| 1343 | + 'spip:taille_' . $unites[$puissance] . $suffixe_item, |
|
| 1344 | + [ |
|
| 1345 | + 'taille' => round($octets / pow($kilo, $puissance), $precisions[$puissance]) |
|
| 1346 | + ] |
|
| 1347 | + ); |
|
| 1348 | + } |
|
| 1349 | 1349 | |
| 1350 | - return $affichage; |
|
| 1350 | + return $affichage; |
|
| 1351 | 1351 | } |
| 1352 | 1352 | |
| 1353 | 1353 | |
@@ -1369,21 +1369,21 @@ discard block |
||
| 1369 | 1369 | * texte prêt pour être utilisé en attribut HTML |
| 1370 | 1370 | **/ |
| 1371 | 1371 | function attribut_html(?string $texte, $textebrut = true): string { |
| 1372 | - if ($texte === null) { |
|
| 1373 | - return ''; |
|
| 1374 | - } |
|
| 1375 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1376 | - if ($textebrut) { |
|
| 1377 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1378 | - } |
|
| 1379 | - $texte = texte_backend($texte); |
|
| 1380 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1372 | + if ($texte === null) { |
|
| 1373 | + return ''; |
|
| 1374 | + } |
|
| 1375 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1376 | + if ($textebrut) { |
|
| 1377 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1378 | + } |
|
| 1379 | + $texte = texte_backend($texte); |
|
| 1380 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1381 | 1381 | |
| 1382 | - return preg_replace( |
|
| 1383 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1384 | - ['&', '&'], |
|
| 1385 | - $texte |
|
| 1386 | - ); |
|
| 1382 | + return preg_replace( |
|
| 1383 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1384 | + ['&', '&'], |
|
| 1385 | + $texte |
|
| 1386 | + ); |
|
| 1387 | 1387 | } |
| 1388 | 1388 | |
| 1389 | 1389 | |
@@ -1403,15 +1403,15 @@ discard block |
||
| 1403 | 1403 | * URL ou chaîne vide |
| 1404 | 1404 | **/ |
| 1405 | 1405 | function vider_url(?string $url, $entites = true): string { |
| 1406 | - if ($url === null) { |
|
| 1407 | - return ''; |
|
| 1408 | - } |
|
| 1409 | - # un message pour abs_url |
|
| 1410 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1411 | - $url = trim($url); |
|
| 1412 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1406 | + if ($url === null) { |
|
| 1407 | + return ''; |
|
| 1408 | + } |
|
| 1409 | + # un message pour abs_url |
|
| 1410 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1411 | + $url = trim($url); |
|
| 1412 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1413 | 1413 | |
| 1414 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1414 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1415 | 1415 | } |
| 1416 | 1416 | |
| 1417 | 1417 | |
@@ -1426,10 +1426,10 @@ discard block |
||
| 1426 | 1426 | * @return string Adresse email maquillée |
| 1427 | 1427 | **/ |
| 1428 | 1428 | function antispam($texte) { |
| 1429 | - include_spip('inc/acces'); |
|
| 1430 | - $masque = creer_pass_aleatoire(3); |
|
| 1429 | + include_spip('inc/acces'); |
|
| 1430 | + $masque = creer_pass_aleatoire(3); |
|
| 1431 | 1431 | |
| 1432 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1432 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1433 | 1433 | } |
| 1434 | 1434 | |
| 1435 | 1435 | /** |
@@ -1461,8 +1461,8 @@ discard block |
||
| 1461 | 1461 | * True si on a le droit d'accès, false sinon. |
| 1462 | 1462 | **/ |
| 1463 | 1463 | function filtre_securiser_acces_dist($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1464 | - include_spip('inc/acces'); |
|
| 1465 | - return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1464 | + include_spip('inc/acces'); |
|
| 1465 | + return securiser_acces_low_sec($id_auteur, $cle, $op ? "$dir $op $args" : $dir); |
|
| 1466 | 1466 | } |
| 1467 | 1467 | |
| 1468 | 1468 | /** |
@@ -1486,13 +1486,13 @@ discard block |
||
| 1486 | 1486 | * Retourne $texte, sinon $sinon. |
| 1487 | 1487 | **/ |
| 1488 | 1488 | function sinon($texte, $sinon = '') { |
| 1489 | - if ($texte) { |
|
| 1490 | - return $texte; |
|
| 1491 | - } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1492 | - return $texte; |
|
| 1493 | - } else { |
|
| 1494 | - return $sinon; |
|
| 1495 | - } |
|
| 1489 | + if ($texte) { |
|
| 1490 | + return $texte; |
|
| 1491 | + } elseif (is_scalar($texte) and strlen($texte)) { |
|
| 1492 | + return $texte; |
|
| 1493 | + } else { |
|
| 1494 | + return $sinon; |
|
| 1495 | + } |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | /** |
@@ -1516,7 +1516,7 @@ discard block |
||
| 1516 | 1516 | * @return mixed |
| 1517 | 1517 | **/ |
| 1518 | 1518 | function choixsivide($a, $vide, $pasvide) { |
| 1519 | - return $a ? $pasvide : $vide; |
|
| 1519 | + return $a ? $pasvide : $vide; |
|
| 1520 | 1520 | } |
| 1521 | 1521 | |
| 1522 | 1522 | /** |
@@ -1540,7 +1540,7 @@ discard block |
||
| 1540 | 1540 | * @return mixed |
| 1541 | 1541 | **/ |
| 1542 | 1542 | function choixsiegal($a1, $a2, $v, $f) { |
| 1543 | - return ($a1 == $a2) ? $v : $f; |
|
| 1543 | + return ($a1 == $a2) ? $v : $f; |
|
| 1544 | 1544 | } |
| 1545 | 1545 | |
| 1546 | 1546 | // |
@@ -1559,13 +1559,13 @@ discard block |
||
| 1559 | 1559 | * @return string |
| 1560 | 1560 | **/ |
| 1561 | 1561 | function filtrer_ical($texte) { |
| 1562 | - #include_spip('inc/charsets'); |
|
| 1563 | - $texte = html2unicode($texte); |
|
| 1564 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1565 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1566 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1562 | + #include_spip('inc/charsets'); |
|
| 1563 | + $texte = html2unicode($texte); |
|
| 1564 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset']), 'utf-8'); |
|
| 1565 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1566 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1567 | 1567 | |
| 1568 | - return $texte; |
|
| 1568 | + return $texte; |
|
| 1569 | 1569 | } |
| 1570 | 1570 | |
| 1571 | 1571 | |
@@ -1590,58 +1590,58 @@ discard block |
||
| 1590 | 1590 | * @return string |
| 1591 | 1591 | **/ |
| 1592 | 1592 | function post_autobr($texte, $delim = "\n_ ") { |
| 1593 | - if (!function_exists('echappe_html')) { |
|
| 1594 | - include_spip('inc/texte_mini'); |
|
| 1595 | - } |
|
| 1596 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1597 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1598 | - |
|
| 1599 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1600 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1601 | - } else { |
|
| 1602 | - $fin = ''; |
|
| 1603 | - } |
|
| 1604 | - |
|
| 1605 | - $texte = echappe_html($texte, '', true); |
|
| 1606 | - |
|
| 1607 | - // echapper les modeles |
|
| 1608 | - $collecteurModeles = null; |
|
| 1609 | - if (strpos($texte, '<') !== false) { |
|
| 1610 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1611 | - include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1612 | - $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1613 | - $texte = $collecteurModeles->echapper($texte); |
|
| 1614 | - } |
|
| 1615 | - |
|
| 1616 | - $debut = ''; |
|
| 1617 | - $suite = $texte; |
|
| 1618 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1619 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1620 | - $suite = substr($suite, $t); |
|
| 1621 | - $car = substr($suite, 0, 1); |
|
| 1622 | - if ( |
|
| 1623 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1624 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1625 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1626 | - ) { |
|
| 1627 | - $debut .= $delim; |
|
| 1628 | - } else { |
|
| 1629 | - $debut .= "\n"; |
|
| 1630 | - } |
|
| 1631 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1632 | - $debut .= $regs[0]; |
|
| 1633 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1634 | - } |
|
| 1635 | - } |
|
| 1636 | - $texte = $debut . $suite; |
|
| 1637 | - |
|
| 1638 | - if ($collecteurModeles) { |
|
| 1639 | - $texte = $collecteurModeles->retablir($texte); |
|
| 1640 | - } |
|
| 1641 | - |
|
| 1642 | - $texte = echappe_retour($texte); |
|
| 1643 | - |
|
| 1644 | - return $texte . $fin; |
|
| 1593 | + if (!function_exists('echappe_html')) { |
|
| 1594 | + include_spip('inc/texte_mini'); |
|
| 1595 | + } |
|
| 1596 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1597 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1598 | + |
|
| 1599 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1600 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1601 | + } else { |
|
| 1602 | + $fin = ''; |
|
| 1603 | + } |
|
| 1604 | + |
|
| 1605 | + $texte = echappe_html($texte, '', true); |
|
| 1606 | + |
|
| 1607 | + // echapper les modeles |
|
| 1608 | + $collecteurModeles = null; |
|
| 1609 | + if (strpos($texte, '<') !== false) { |
|
| 1610 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1611 | + include_spip("src/Texte/Collecteur/Modeles"); |
|
| 1612 | + $collecteurModeles = new Spip\Texte\Collecteur\Modeles(); |
|
| 1613 | + $texte = $collecteurModeles->echapper($texte); |
|
| 1614 | + } |
|
| 1615 | + |
|
| 1616 | + $debut = ''; |
|
| 1617 | + $suite = $texte; |
|
| 1618 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1619 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1620 | + $suite = substr($suite, $t); |
|
| 1621 | + $car = substr($suite, 0, 1); |
|
| 1622 | + if ( |
|
| 1623 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1624 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1625 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1626 | + ) { |
|
| 1627 | + $debut .= $delim; |
|
| 1628 | + } else { |
|
| 1629 | + $debut .= "\n"; |
|
| 1630 | + } |
|
| 1631 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1632 | + $debut .= $regs[0]; |
|
| 1633 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1634 | + } |
|
| 1635 | + } |
|
| 1636 | + $texte = $debut . $suite; |
|
| 1637 | + |
|
| 1638 | + if ($collecteurModeles) { |
|
| 1639 | + $texte = $collecteurModeles->retablir($texte); |
|
| 1640 | + } |
|
| 1641 | + |
|
| 1642 | + $texte = echappe_retour($texte); |
|
| 1643 | + |
|
| 1644 | + return $texte . $fin; |
|
| 1645 | 1645 | } |
| 1646 | 1646 | |
| 1647 | 1647 | |
@@ -1676,30 +1676,30 @@ discard block |
||
| 1676 | 1676 | **/ |
| 1677 | 1677 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1678 | 1678 | |
| 1679 | - if ( |
|
| 1680 | - $letexte |
|
| 1681 | - and strpos($letexte, '<:') !== false |
|
| 1682 | - ) { |
|
| 1683 | - if (!$lang) { |
|
| 1684 | - $lang = $GLOBALS['spip_lang']; |
|
| 1685 | - } |
|
| 1686 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1687 | - if (is_bool($options)) { |
|
| 1688 | - $options = ['echappe_span' => $options]; |
|
| 1689 | - } |
|
| 1690 | - if (!isset($options['echappe_span'])) { |
|
| 1691 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1692 | - } |
|
| 1693 | - $options['lang'] = $lang; |
|
| 1679 | + if ( |
|
| 1680 | + $letexte |
|
| 1681 | + and strpos($letexte, '<:') !== false |
|
| 1682 | + ) { |
|
| 1683 | + if (!$lang) { |
|
| 1684 | + $lang = $GLOBALS['spip_lang']; |
|
| 1685 | + } |
|
| 1686 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1687 | + if (is_bool($options)) { |
|
| 1688 | + $options = ['echappe_span' => $options]; |
|
| 1689 | + } |
|
| 1690 | + if (!isset($options['echappe_span'])) { |
|
| 1691 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1692 | + } |
|
| 1693 | + $options['lang'] = $lang; |
|
| 1694 | 1694 | |
| 1695 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1696 | - include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1697 | - $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1695 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1696 | + include_spip("src/Texte/Collecteur/Idiomes"); |
|
| 1697 | + $collecteurIdiomes = new Spip\Texte\Collecteur\Idiomes(); |
|
| 1698 | 1698 | |
| 1699 | - $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1699 | + $letexte = $collecteurIdiomes->traiter($letexte, $options); |
|
| 1700 | 1700 | |
| 1701 | - } |
|
| 1702 | - return $letexte; |
|
| 1701 | + } |
|
| 1702 | + return $letexte; |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | /** |
@@ -1737,34 +1737,34 @@ discard block |
||
| 1737 | 1737 | **/ |
| 1738 | 1738 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1739 | 1739 | |
| 1740 | - if ( |
|
| 1741 | - $letexte |
|
| 1742 | - and stripos($letexte, '<multi') !== false |
|
| 1743 | - ) { |
|
| 1744 | - if (!$lang) { |
|
| 1745 | - $lang = $GLOBALS['spip_lang']; |
|
| 1746 | - } |
|
| 1740 | + if ( |
|
| 1741 | + $letexte |
|
| 1742 | + and stripos($letexte, '<multi') !== false |
|
| 1743 | + ) { |
|
| 1744 | + if (!$lang) { |
|
| 1745 | + $lang = $GLOBALS['spip_lang']; |
|
| 1746 | + } |
|
| 1747 | 1747 | |
| 1748 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1749 | - if (is_bool($options)) { |
|
| 1750 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1751 | - } |
|
| 1752 | - if (!isset($options['echappe_span'])) { |
|
| 1753 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1754 | - } |
|
| 1755 | - if (!isset($options['lang_defaut'])) { |
|
| 1756 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1757 | - } |
|
| 1758 | - $options['lang'] = $lang; |
|
| 1748 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1749 | + if (is_bool($options)) { |
|
| 1750 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1751 | + } |
|
| 1752 | + if (!isset($options['echappe_span'])) { |
|
| 1753 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1754 | + } |
|
| 1755 | + if (!isset($options['lang_defaut'])) { |
|
| 1756 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1757 | + } |
|
| 1758 | + $options['lang'] = $lang; |
|
| 1759 | 1759 | |
| 1760 | - include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1761 | - include_spip("src/Texte/Collecteur/Multis"); |
|
| 1762 | - $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1760 | + include_spip("src/Texte/Collecteur/AbstractCollecteur"); |
|
| 1761 | + include_spip("src/Texte/Collecteur/Multis"); |
|
| 1762 | + $collecteurMultis = new Spip\Texte\Collecteur\Multis(); |
|
| 1763 | 1763 | |
| 1764 | - $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1765 | - } |
|
| 1764 | + $letexte = $collecteurMultis->traiter($letexte, $options); |
|
| 1765 | + } |
|
| 1766 | 1766 | |
| 1767 | - return $letexte; |
|
| 1767 | + return $letexte; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1774,7 +1774,7 @@ discard block |
||
| 1774 | 1774 | * @return string L'initiale en majuscule |
| 1775 | 1775 | */ |
| 1776 | 1776 | function filtre_initiale($nom) { |
| 1777 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1777 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1778 | 1778 | } |
| 1779 | 1779 | |
| 1780 | 1780 | |
@@ -1819,33 +1819,33 @@ discard block |
||
| 1819 | 1819 | * - null (interne) : si on empile |
| 1820 | 1820 | **/ |
| 1821 | 1821 | function unique($donnee, $famille = '', $cpt = false) { |
| 1822 | - static $mem = []; |
|
| 1823 | - // permettre de vider la pile et de la restaurer |
|
| 1824 | - // pour le calcul de introduction... |
|
| 1825 | - if ($famille == '_spip_raz_') { |
|
| 1826 | - $tmp = $mem; |
|
| 1827 | - $mem = []; |
|
| 1828 | - |
|
| 1829 | - return $tmp; |
|
| 1830 | - } elseif ($famille == '_spip_set_') { |
|
| 1831 | - $mem = $donnee; |
|
| 1832 | - |
|
| 1833 | - return; |
|
| 1834 | - } |
|
| 1835 | - // eviter une notice |
|
| 1836 | - if (!isset($mem[$famille])) { |
|
| 1837 | - $mem[$famille] = []; |
|
| 1838 | - } |
|
| 1839 | - if ($cpt) { |
|
| 1840 | - return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1841 | - } |
|
| 1842 | - // eviter une notice |
|
| 1843 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1844 | - $mem[$famille][$donnee] = 0; |
|
| 1845 | - } |
|
| 1846 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1847 | - return $donnee; |
|
| 1848 | - } |
|
| 1822 | + static $mem = []; |
|
| 1823 | + // permettre de vider la pile et de la restaurer |
|
| 1824 | + // pour le calcul de introduction... |
|
| 1825 | + if ($famille == '_spip_raz_') { |
|
| 1826 | + $tmp = $mem; |
|
| 1827 | + $mem = []; |
|
| 1828 | + |
|
| 1829 | + return $tmp; |
|
| 1830 | + } elseif ($famille == '_spip_set_') { |
|
| 1831 | + $mem = $donnee; |
|
| 1832 | + |
|
| 1833 | + return; |
|
| 1834 | + } |
|
| 1835 | + // eviter une notice |
|
| 1836 | + if (!isset($mem[$famille])) { |
|
| 1837 | + $mem[$famille] = []; |
|
| 1838 | + } |
|
| 1839 | + if ($cpt) { |
|
| 1840 | + return is_countable($mem[$famille]) ? count($mem[$famille]) : 0; |
|
| 1841 | + } |
|
| 1842 | + // eviter une notice |
|
| 1843 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1844 | + $mem[$famille][$donnee] = 0; |
|
| 1845 | + } |
|
| 1846 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1847 | + return $donnee; |
|
| 1848 | + } |
|
| 1849 | 1849 | } |
| 1850 | 1850 | |
| 1851 | 1851 | |
@@ -1875,20 +1875,20 @@ discard block |
||
| 1875 | 1875 | * Une des valeurs en fonction du compteur. |
| 1876 | 1876 | **/ |
| 1877 | 1877 | function alterner($i, ...$args) { |
| 1878 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1879 | - $num = count($args); |
|
| 1878 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1879 | + $num = count($args); |
|
| 1880 | 1880 | |
| 1881 | - if ($num === 1 && is_array($args[0])) { |
|
| 1882 | - // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1883 | - $args = array_values($args[0]); |
|
| 1884 | - $num = count($args); |
|
| 1885 | - } |
|
| 1881 | + if ($num === 1 && is_array($args[0])) { |
|
| 1882 | + // un tableau de valeur dont les cles sont numerotees de 0 a num |
|
| 1883 | + $args = array_values($args[0]); |
|
| 1884 | + $num = count($args); |
|
| 1885 | + } |
|
| 1886 | 1886 | |
| 1887 | - // un index compris entre 0 et num exclus |
|
| 1888 | - $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1889 | - $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1890 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1891 | - return $args[$i]; |
|
| 1887 | + // un index compris entre 0 et num exclus |
|
| 1888 | + $i = ((intval($i) - 1) % $num); // dans ]-$num;$num[ |
|
| 1889 | + $i = ($i + $num) % $num; // dans [0;$num[ |
|
| 1890 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1891 | + return $args[$i]; |
|
| 1892 | 1892 | } |
| 1893 | 1893 | |
| 1894 | 1894 | |
@@ -1914,52 +1914,52 @@ discard block |
||
| 1914 | 1914 | * - null lorsque l’attribut n’existe pas. |
| 1915 | 1915 | **/ |
| 1916 | 1916 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1917 | - if (is_array($balise)) { |
|
| 1918 | - array_walk( |
|
| 1919 | - $balise, |
|
| 1920 | - function (&$a, $key, $t) { |
|
| 1921 | - $a = extraire_attribut($a, $t); |
|
| 1922 | - }, |
|
| 1923 | - $attribut |
|
| 1924 | - ); |
|
| 1925 | - |
|
| 1926 | - return $balise; |
|
| 1927 | - } |
|
| 1928 | - if ( |
|
| 1929 | - $balise |
|
| 1930 | - && stripos($balise, $attribut) !== false |
|
| 1931 | - && preg_match( |
|
| 1932 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1933 | - . $attribut |
|
| 1934 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1935 | - $balise, |
|
| 1936 | - $r |
|
| 1937 | - ) |
|
| 1938 | - ) { |
|
| 1939 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1940 | - $r[4] = substr($r[3], 1, -1); |
|
| 1941 | - $r[3] = $r[3][0]; |
|
| 1942 | - } elseif ($r[3] !== '') { |
|
| 1943 | - $r[4] = $r[3]; |
|
| 1944 | - $r[3] = ''; |
|
| 1945 | - } else { |
|
| 1946 | - $r[4] = trim($r[2]); |
|
| 1947 | - } |
|
| 1948 | - $att = $r[4]; |
|
| 1949 | - if (strpos($att, '&#') !== false) { |
|
| 1950 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1951 | - } |
|
| 1952 | - $att = filtrer_entites($att); |
|
| 1953 | - } else { |
|
| 1954 | - $att = null; |
|
| 1955 | - $r = []; |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - if ($complet) { |
|
| 1959 | - return [$att, $r]; |
|
| 1960 | - } else { |
|
| 1961 | - return $att; |
|
| 1962 | - } |
|
| 1917 | + if (is_array($balise)) { |
|
| 1918 | + array_walk( |
|
| 1919 | + $balise, |
|
| 1920 | + function (&$a, $key, $t) { |
|
| 1921 | + $a = extraire_attribut($a, $t); |
|
| 1922 | + }, |
|
| 1923 | + $attribut |
|
| 1924 | + ); |
|
| 1925 | + |
|
| 1926 | + return $balise; |
|
| 1927 | + } |
|
| 1928 | + if ( |
|
| 1929 | + $balise |
|
| 1930 | + && stripos($balise, $attribut) !== false |
|
| 1931 | + && preg_match( |
|
| 1932 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1933 | + . $attribut |
|
| 1934 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1935 | + $balise, |
|
| 1936 | + $r |
|
| 1937 | + ) |
|
| 1938 | + ) { |
|
| 1939 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1940 | + $r[4] = substr($r[3], 1, -1); |
|
| 1941 | + $r[3] = $r[3][0]; |
|
| 1942 | + } elseif ($r[3] !== '') { |
|
| 1943 | + $r[4] = $r[3]; |
|
| 1944 | + $r[3] = ''; |
|
| 1945 | + } else { |
|
| 1946 | + $r[4] = trim($r[2]); |
|
| 1947 | + } |
|
| 1948 | + $att = $r[4]; |
|
| 1949 | + if (strpos($att, '&#') !== false) { |
|
| 1950 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1951 | + } |
|
| 1952 | + $att = filtrer_entites($att); |
|
| 1953 | + } else { |
|
| 1954 | + $att = null; |
|
| 1955 | + $r = []; |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + if ($complet) { |
|
| 1959 | + return [$att, $r]; |
|
| 1960 | + } else { |
|
| 1961 | + return $att; |
|
| 1962 | + } |
|
| 1963 | 1963 | } |
| 1964 | 1964 | |
| 1965 | 1965 | /** |
@@ -1992,41 +1992,41 @@ discard block |
||
| 1992 | 1992 | **/ |
| 1993 | 1993 | function inserer_attribut(?string $balise, string $attribut, string $val, bool $proteger = true, bool $vider = false): string { |
| 1994 | 1994 | |
| 1995 | - if ($balise === null or $balise === '') { |
|
| 1996 | - return ''; |
|
| 1997 | - } |
|
| 1995 | + if ($balise === null or $balise === '') { |
|
| 1996 | + return ''; |
|
| 1997 | + } |
|
| 1998 | 1998 | |
| 1999 | - // preparer l'attribut |
|
| 2000 | - // supprimer les etc mais pas les balises html |
|
| 2001 | - // qui ont un sens dans un attribut value d'un input |
|
| 2002 | - if ($proteger) { |
|
| 2003 | - $val = attribut_html($val, false); |
|
| 2004 | - } |
|
| 1999 | + // preparer l'attribut |
|
| 2000 | + // supprimer les etc mais pas les balises html |
|
| 2001 | + // qui ont un sens dans un attribut value d'un input |
|
| 2002 | + if ($proteger) { |
|
| 2003 | + $val = attribut_html($val, false); |
|
| 2004 | + } |
|
| 2005 | 2005 | |
| 2006 | - // echapper les ' pour eviter tout bug |
|
| 2007 | - $val = str_replace("'", ''', $val); |
|
| 2008 | - if ($vider and strlen($val) === 0) { |
|
| 2009 | - $insert = ''; |
|
| 2010 | - } else { |
|
| 2011 | - $insert = " $attribut='$val'"; |
|
| 2012 | - } |
|
| 2006 | + // echapper les ' pour eviter tout bug |
|
| 2007 | + $val = str_replace("'", ''', $val); |
|
| 2008 | + if ($vider and strlen($val) === 0) { |
|
| 2009 | + $insert = ''; |
|
| 2010 | + } else { |
|
| 2011 | + $insert = " $attribut='$val'"; |
|
| 2012 | + } |
|
| 2013 | 2013 | |
| 2014 | - [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2014 | + [$old, $r] = extraire_attribut($balise, $attribut, true); |
|
| 2015 | 2015 | |
| 2016 | - if ($old !== null) { |
|
| 2017 | - // Remplacer l'ancien attribut du meme nom |
|
| 2018 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2019 | - } else { |
|
| 2020 | - // preferer une balise " />" (comme <img />) |
|
| 2021 | - if (preg_match(',/>,', $balise)) { |
|
| 2022 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2023 | - } // sinon une balise <a ...> ... </a> |
|
| 2024 | - else { |
|
| 2025 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2026 | - } |
|
| 2027 | - } |
|
| 2016 | + if ($old !== null) { |
|
| 2017 | + // Remplacer l'ancien attribut du meme nom |
|
| 2018 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2019 | + } else { |
|
| 2020 | + // preferer une balise " />" (comme <img />) |
|
| 2021 | + if (preg_match(',/>,', $balise)) { |
|
| 2022 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2023 | + } // sinon une balise <a ...> ... </a> |
|
| 2024 | + else { |
|
| 2025 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2026 | + } |
|
| 2027 | + } |
|
| 2028 | 2028 | |
| 2029 | - return $balise; |
|
| 2029 | + return $balise; |
|
| 2030 | 2030 | } |
| 2031 | 2031 | |
| 2032 | 2032 | /** |
@@ -2044,7 +2044,7 @@ discard block |
||
| 2044 | 2044 | * @return string Code HTML sans l'attribut |
| 2045 | 2045 | **/ |
| 2046 | 2046 | function vider_attribut(?string $balise, string $attribut): string { |
| 2047 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2047 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2048 | 2048 | } |
| 2049 | 2049 | |
| 2050 | 2050 | /** |
@@ -2056,50 +2056,50 @@ discard block |
||
| 2056 | 2056 | * @return string |
| 2057 | 2057 | */ |
| 2058 | 2058 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2059 | - if (is_string($class)) { |
|
| 2060 | - $class = explode(' ', trim($class)); |
|
| 2061 | - } |
|
| 2062 | - $class = array_filter($class); |
|
| 2063 | - $class = array_unique($class); |
|
| 2064 | - if (!$class) { |
|
| 2065 | - return $balise; |
|
| 2066 | - } |
|
| 2067 | - |
|
| 2068 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2069 | - $class_new = $class_courante; |
|
| 2070 | - foreach ($class as $c) { |
|
| 2071 | - $is_class_presente = false; |
|
| 2072 | - if ( |
|
| 2073 | - $class_courante |
|
| 2074 | - and str_contains($class_courante, (string) $c) |
|
| 2075 | - and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2076 | - ) { |
|
| 2077 | - $is_class_presente = true; |
|
| 2078 | - } |
|
| 2079 | - if ( |
|
| 2080 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2081 | - and !$is_class_presente |
|
| 2082 | - ) { |
|
| 2083 | - $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2084 | - } elseif ( |
|
| 2085 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2086 | - and $is_class_presente |
|
| 2087 | - ) { |
|
| 2088 | - $class_new = preg_split(",\s+,", $class_new); |
|
| 2089 | - $class_new = array_diff($class_new, [$c]); |
|
| 2090 | - $class_new = implode(' ', $class_new); |
|
| 2091 | - } |
|
| 2092 | - } |
|
| 2093 | - |
|
| 2094 | - if ($class_new !== $class_courante) { |
|
| 2095 | - if (strlen($class_new)) { |
|
| 2096 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2097 | - } elseif ($class_courante) { |
|
| 2098 | - $balise = vider_attribut($balise, 'class'); |
|
| 2099 | - } |
|
| 2100 | - } |
|
| 2101 | - |
|
| 2102 | - return $balise; |
|
| 2059 | + if (is_string($class)) { |
|
| 2060 | + $class = explode(' ', trim($class)); |
|
| 2061 | + } |
|
| 2062 | + $class = array_filter($class); |
|
| 2063 | + $class = array_unique($class); |
|
| 2064 | + if (!$class) { |
|
| 2065 | + return $balise; |
|
| 2066 | + } |
|
| 2067 | + |
|
| 2068 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2069 | + $class_new = $class_courante; |
|
| 2070 | + foreach ($class as $c) { |
|
| 2071 | + $is_class_presente = false; |
|
| 2072 | + if ( |
|
| 2073 | + $class_courante |
|
| 2074 | + and str_contains($class_courante, (string) $c) |
|
| 2075 | + and in_array($c, preg_split(",\s+,", $class_courante)) |
|
| 2076 | + ) { |
|
| 2077 | + $is_class_presente = true; |
|
| 2078 | + } |
|
| 2079 | + if ( |
|
| 2080 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2081 | + and !$is_class_presente |
|
| 2082 | + ) { |
|
| 2083 | + $class_new = ltrim(rtrim($class_new ?? '') . ' ' . $c); |
|
| 2084 | + } elseif ( |
|
| 2085 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2086 | + and $is_class_presente |
|
| 2087 | + ) { |
|
| 2088 | + $class_new = preg_split(",\s+,", $class_new); |
|
| 2089 | + $class_new = array_diff($class_new, [$c]); |
|
| 2090 | + $class_new = implode(' ', $class_new); |
|
| 2091 | + } |
|
| 2092 | + } |
|
| 2093 | + |
|
| 2094 | + if ($class_new !== $class_courante) { |
|
| 2095 | + if (strlen($class_new)) { |
|
| 2096 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2097 | + } elseif ($class_courante) { |
|
| 2098 | + $balise = vider_attribut($balise, 'class'); |
|
| 2099 | + } |
|
| 2100 | + } |
|
| 2101 | + |
|
| 2102 | + return $balise; |
|
| 2103 | 2103 | } |
| 2104 | 2104 | |
| 2105 | 2105 | /** |
@@ -2109,7 +2109,7 @@ discard block |
||
| 2109 | 2109 | * @return string |
| 2110 | 2110 | */ |
| 2111 | 2111 | function ajouter_class($balise, $class) { |
| 2112 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2112 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2113 | 2113 | } |
| 2114 | 2114 | |
| 2115 | 2115 | /** |
@@ -2119,7 +2119,7 @@ discard block |
||
| 2119 | 2119 | * @return string |
| 2120 | 2120 | */ |
| 2121 | 2121 | function supprimer_class($balise, $class) { |
| 2122 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2122 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2123 | 2123 | } |
| 2124 | 2124 | |
| 2125 | 2125 | /** |
@@ -2130,7 +2130,7 @@ discard block |
||
| 2130 | 2130 | * @return string |
| 2131 | 2131 | */ |
| 2132 | 2132 | function commuter_class($balise, $class) { |
| 2133 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2133 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2134 | 2134 | } |
| 2135 | 2135 | |
| 2136 | 2136 | /** |
@@ -2141,19 +2141,19 @@ discard block |
||
| 2141 | 2141 | * @return string |
| 2142 | 2142 | */ |
| 2143 | 2143 | function tester_config($id, $mode = '') { |
| 2144 | - include_spip('action/inscrire_auteur'); |
|
| 2144 | + include_spip('action/inscrire_auteur'); |
|
| 2145 | 2145 | |
| 2146 | - return tester_statut_inscription($mode, $id); |
|
| 2146 | + return tester_statut_inscription($mode, $id); |
|
| 2147 | 2147 | } |
| 2148 | 2148 | |
| 2149 | 2149 | // |
| 2150 | 2150 | // Quelques fonctions de calcul arithmetique |
| 2151 | 2151 | // |
| 2152 | 2152 | function floatstr($a) { |
| 2153 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2153 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2154 | 2154 | } |
| 2155 | 2155 | function strize($f, $a, $b) { |
| 2156 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2156 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | 2159 | /** |
@@ -2172,11 +2172,11 @@ discard block |
||
| 2172 | 2172 | * @return int $a+$b |
| 2173 | 2173 | **/ |
| 2174 | 2174 | function plus($a, $b) { |
| 2175 | - return $a + $b; |
|
| 2175 | + return $a + $b; |
|
| 2176 | 2176 | } |
| 2177 | 2177 | |
| 2178 | 2178 | function strplus($a, $b) { |
| 2179 | - return strize('plus', $a, $b); |
|
| 2179 | + return strize('plus', $a, $b); |
|
| 2180 | 2180 | } |
| 2181 | 2181 | |
| 2182 | 2182 | /** |
@@ -2195,11 +2195,11 @@ discard block |
||
| 2195 | 2195 | * @return int $a-$b |
| 2196 | 2196 | **/ |
| 2197 | 2197 | function moins($a, $b) { |
| 2198 | - return $a - $b; |
|
| 2198 | + return $a - $b; |
|
| 2199 | 2199 | } |
| 2200 | 2200 | |
| 2201 | 2201 | function strmoins($a, $b) { |
| 2202 | - return strize('moins', $a, $b); |
|
| 2202 | + return strize('moins', $a, $b); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | /** |
@@ -2219,11 +2219,11 @@ discard block |
||
| 2219 | 2219 | * @return int $a*$b |
| 2220 | 2220 | **/ |
| 2221 | 2221 | function mult($a, $b) { |
| 2222 | - return $a * $b; |
|
| 2222 | + return $a * $b; |
|
| 2223 | 2223 | } |
| 2224 | 2224 | |
| 2225 | 2225 | function strmult($a, $b) { |
| 2226 | - return strize('mult', $a, $b); |
|
| 2226 | + return strize('mult', $a, $b); |
|
| 2227 | 2227 | } |
| 2228 | 2228 | |
| 2229 | 2229 | /** |
@@ -2243,11 +2243,11 @@ discard block |
||
| 2243 | 2243 | * @return int $a/$b (ou 0 si $b est nul) |
| 2244 | 2244 | **/ |
| 2245 | 2245 | function div($a, $b) { |
| 2246 | - return $b ? $a / $b : 0; |
|
| 2246 | + return $b ? $a / $b : 0; |
|
| 2247 | 2247 | } |
| 2248 | 2248 | |
| 2249 | 2249 | function strdiv($a, $b) { |
| 2250 | - return strize('div', $a, $b); |
|
| 2250 | + return strize('div', $a, $b); |
|
| 2251 | 2251 | } |
| 2252 | 2252 | |
| 2253 | 2253 | /** |
@@ -2268,7 +2268,7 @@ discard block |
||
| 2268 | 2268 | * @return int ($nb % $mod) + $add |
| 2269 | 2269 | **/ |
| 2270 | 2270 | function modulo($nb, $mod, $add = 0) { |
| 2271 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2271 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2272 | 2272 | } |
| 2273 | 2273 | |
| 2274 | 2274 | |
@@ -2283,26 +2283,26 @@ discard block |
||
| 2283 | 2283 | * - true sinon |
| 2284 | 2284 | **/ |
| 2285 | 2285 | function nom_acceptable($nom) { |
| 2286 | - $remp2 = []; |
|
| 2287 | - $remp1 = []; |
|
| 2288 | - if (!is_string($nom)) { |
|
| 2289 | - return false; |
|
| 2290 | - } |
|
| 2291 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2292 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2293 | - } |
|
| 2294 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2295 | - foreach ($tags_acceptes as $tag) { |
|
| 2296 | - if (strlen($tag)) { |
|
| 2297 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2298 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2299 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2300 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2301 | - } |
|
| 2302 | - } |
|
| 2303 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2304 | - |
|
| 2305 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2286 | + $remp2 = []; |
|
| 2287 | + $remp1 = []; |
|
| 2288 | + if (!is_string($nom)) { |
|
| 2289 | + return false; |
|
| 2290 | + } |
|
| 2291 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2292 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2293 | + } |
|
| 2294 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2295 | + foreach ($tags_acceptes as $tag) { |
|
| 2296 | + if (strlen($tag)) { |
|
| 2297 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2298 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2299 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2300 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2301 | + } |
|
| 2302 | + } |
|
| 2303 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2304 | + |
|
| 2305 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2306 | 2306 | } |
| 2307 | 2307 | |
| 2308 | 2308 | |
@@ -2318,14 +2318,14 @@ discard block |
||
| 2318 | 2318 | * - renvoie un tableau si l'entree est un tableau |
| 2319 | 2319 | **/ |
| 2320 | 2320 | function email_valide($adresses) { |
| 2321 | - if (is_array($adresses)) { |
|
| 2322 | - $adresses = array_map('email_valide', $adresses); |
|
| 2323 | - $adresses = array_filter($adresses); |
|
| 2324 | - return $adresses; |
|
| 2325 | - } |
|
| 2321 | + if (is_array($adresses)) { |
|
| 2322 | + $adresses = array_map('email_valide', $adresses); |
|
| 2323 | + $adresses = array_filter($adresses); |
|
| 2324 | + return $adresses; |
|
| 2325 | + } |
|
| 2326 | 2326 | |
| 2327 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2328 | - return $email_valide($adresses); |
|
| 2327 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2328 | + return $email_valide($adresses); |
|
| 2329 | 2329 | } |
| 2330 | 2330 | |
| 2331 | 2331 | /** |
@@ -2339,29 +2339,29 @@ discard block |
||
| 2339 | 2339 | * @return string texte |
| 2340 | 2340 | **/ |
| 2341 | 2341 | function afficher_enclosures($tags) { |
| 2342 | - $s = []; |
|
| 2343 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2344 | - if ( |
|
| 2345 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2346 | - and $t = extraire_attribut($tag, 'href') |
|
| 2347 | - ) { |
|
| 2348 | - $s[] = preg_replace( |
|
| 2349 | - ',>[^<]+</a>,S', |
|
| 2350 | - '>' |
|
| 2351 | - . http_img_pack( |
|
| 2352 | - 'attachment-16.png', |
|
| 2353 | - $t, |
|
| 2354 | - '', |
|
| 2355 | - $t, |
|
| 2356 | - ['utiliser_suffixe_size' => true] |
|
| 2357 | - ) |
|
| 2358 | - . '</a>', |
|
| 2359 | - $tag |
|
| 2360 | - ); |
|
| 2361 | - } |
|
| 2362 | - } |
|
| 2363 | - |
|
| 2364 | - return join(' ', $s); |
|
| 2342 | + $s = []; |
|
| 2343 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2344 | + if ( |
|
| 2345 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2346 | + and $t = extraire_attribut($tag, 'href') |
|
| 2347 | + ) { |
|
| 2348 | + $s[] = preg_replace( |
|
| 2349 | + ',>[^<]+</a>,S', |
|
| 2350 | + '>' |
|
| 2351 | + . http_img_pack( |
|
| 2352 | + 'attachment-16.png', |
|
| 2353 | + $t, |
|
| 2354 | + '', |
|
| 2355 | + $t, |
|
| 2356 | + ['utiliser_suffixe_size' => true] |
|
| 2357 | + ) |
|
| 2358 | + . '</a>', |
|
| 2359 | + $tag |
|
| 2360 | + ); |
|
| 2361 | + } |
|
| 2362 | + } |
|
| 2363 | + |
|
| 2364 | + return join(' ', $s); |
|
| 2365 | 2365 | } |
| 2366 | 2366 | |
| 2367 | 2367 | /** |
@@ -2376,15 +2376,15 @@ discard block |
||
| 2376 | 2376 | * @return string Liens trouvés |
| 2377 | 2377 | **/ |
| 2378 | 2378 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2379 | - $s = []; |
|
| 2380 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2381 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2382 | - if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2383 | - $s[] = $tag; |
|
| 2384 | - } |
|
| 2385 | - } |
|
| 2379 | + $s = []; |
|
| 2380 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2381 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2382 | + if (strstr(",$rels,", (string) ",$rel,")) { |
|
| 2383 | + $s[] = $tag; |
|
| 2384 | + } |
|
| 2385 | + } |
|
| 2386 | 2386 | |
| 2387 | - return join(', ', $s); |
|
| 2387 | + return join(', ', $s); |
|
| 2388 | 2388 | } |
| 2389 | 2389 | |
| 2390 | 2390 | |
@@ -2406,21 +2406,21 @@ discard block |
||
| 2406 | 2406 | * @return string Tag HTML `<a>` avec microformat. |
| 2407 | 2407 | **/ |
| 2408 | 2408 | function enclosure2microformat($e) { |
| 2409 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2410 | - $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2411 | - } |
|
| 2412 | - $type = extraire_attribut($e, 'type'); |
|
| 2413 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2414 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2415 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2416 | - } |
|
| 2417 | - $fichier = basename($url); |
|
| 2409 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url') ?? '')) { |
|
| 2410 | + $url = filtrer_entites(extraire_attribut($e, 'href') ?? ''); |
|
| 2411 | + } |
|
| 2412 | + $type = extraire_attribut($e, 'type'); |
|
| 2413 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2414 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2415 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2416 | + } |
|
| 2417 | + $fichier = basename($url); |
|
| 2418 | 2418 | |
| 2419 | - return '<a rel="enclosure"' |
|
| 2420 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2421 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2422 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2423 | - . '>' . $fichier . '</a>'; |
|
| 2419 | + return '<a rel="enclosure"' |
|
| 2420 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2421 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2422 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2423 | + . '>' . $fichier . '</a>'; |
|
| 2424 | 2424 | } |
| 2425 | 2425 | |
| 2426 | 2426 | /** |
@@ -2438,24 +2438,24 @@ discard block |
||
| 2438 | 2438 | * @return string Tags RSS `<enclosure>`. |
| 2439 | 2439 | **/ |
| 2440 | 2440 | function microformat2enclosure($tags) { |
| 2441 | - $enclosures = []; |
|
| 2442 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2443 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2444 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2445 | - $type = extraire_attribut($e, 'type'); |
|
| 2446 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2447 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2448 | - } # vieux data |
|
| 2449 | - $fichier = basename($url); |
|
| 2450 | - $enclosures[] = '<enclosure' |
|
| 2451 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2452 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2453 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2454 | - . ' />'; |
|
| 2455 | - } |
|
| 2456 | - } |
|
| 2441 | + $enclosures = []; |
|
| 2442 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2443 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2444 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2445 | + $type = extraire_attribut($e, 'type'); |
|
| 2446 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2447 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2448 | + } # vieux data |
|
| 2449 | + $fichier = basename($url); |
|
| 2450 | + $enclosures[] = '<enclosure' |
|
| 2451 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2452 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2453 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2454 | + . ' />'; |
|
| 2455 | + } |
|
| 2456 | + } |
|
| 2457 | 2457 | |
| 2458 | - return join("\n", $enclosures); |
|
| 2458 | + return join("\n", $enclosures); |
|
| 2459 | 2459 | } |
| 2460 | 2460 | |
| 2461 | 2461 | |
@@ -2471,16 +2471,16 @@ discard block |
||
| 2471 | 2471 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2472 | 2472 | **/ |
| 2473 | 2473 | function tags2dcsubject($tags) { |
| 2474 | - $subjects = ''; |
|
| 2475 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2476 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2477 | - $subjects .= '<dc:subject>' |
|
| 2478 | - . texte_backend(textebrut($e)) |
|
| 2479 | - . '</dc:subject>' . "\n"; |
|
| 2480 | - } |
|
| 2481 | - } |
|
| 2474 | + $subjects = ''; |
|
| 2475 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2476 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2477 | + $subjects .= '<dc:subject>' |
|
| 2478 | + . texte_backend(textebrut($e)) |
|
| 2479 | + . '</dc:subject>' . "\n"; |
|
| 2480 | + } |
|
| 2481 | + } |
|
| 2482 | 2482 | |
| 2483 | - return $subjects; |
|
| 2483 | + return $subjects; |
|
| 2484 | 2484 | } |
| 2485 | 2485 | |
| 2486 | 2486 | /** |
@@ -2509,27 +2509,27 @@ discard block |
||
| 2509 | 2509 | * - Tableau de résultats, si tableau en entrée. |
| 2510 | 2510 | **/ |
| 2511 | 2511 | function extraire_balise($texte, $tag = 'a') { |
| 2512 | - if (is_array($texte)) { |
|
| 2513 | - array_walk( |
|
| 2514 | - $texte, |
|
| 2515 | - function (&$a, $key, $t) { |
|
| 2516 | - $a = extraire_balise($a, $t); |
|
| 2517 | - }, |
|
| 2518 | - $tag |
|
| 2519 | - ); |
|
| 2520 | - |
|
| 2521 | - return $texte; |
|
| 2522 | - } |
|
| 2523 | - |
|
| 2524 | - if ( |
|
| 2525 | - preg_match( |
|
| 2526 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2527 | - $texte, |
|
| 2528 | - $regs |
|
| 2529 | - ) |
|
| 2530 | - ) { |
|
| 2531 | - return $regs[0]; |
|
| 2532 | - } |
|
| 2512 | + if (is_array($texte)) { |
|
| 2513 | + array_walk( |
|
| 2514 | + $texte, |
|
| 2515 | + function (&$a, $key, $t) { |
|
| 2516 | + $a = extraire_balise($a, $t); |
|
| 2517 | + }, |
|
| 2518 | + $tag |
|
| 2519 | + ); |
|
| 2520 | + |
|
| 2521 | + return $texte; |
|
| 2522 | + } |
|
| 2523 | + |
|
| 2524 | + if ( |
|
| 2525 | + preg_match( |
|
| 2526 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2527 | + $texte, |
|
| 2528 | + $regs |
|
| 2529 | + ) |
|
| 2530 | + ) { |
|
| 2531 | + return $regs[0]; |
|
| 2532 | + } |
|
| 2533 | 2533 | } |
| 2534 | 2534 | |
| 2535 | 2535 | /** |
@@ -2557,30 +2557,30 @@ discard block |
||
| 2557 | 2557 | * - Tableau de résultats, si tableau en entrée. |
| 2558 | 2558 | **/ |
| 2559 | 2559 | function extraire_balises($texte, $tag = 'a') { |
| 2560 | - if (is_array($texte)) { |
|
| 2561 | - array_walk( |
|
| 2562 | - $texte, |
|
| 2563 | - function (&$a, $key, $t) { |
|
| 2564 | - $a = extraire_balises($a, $t); |
|
| 2565 | - }, |
|
| 2566 | - $tag |
|
| 2567 | - ); |
|
| 2568 | - |
|
| 2569 | - return $texte; |
|
| 2570 | - } |
|
| 2571 | - |
|
| 2572 | - if ( |
|
| 2573 | - preg_match_all( |
|
| 2574 | - ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2575 | - $texte, |
|
| 2576 | - $regs, |
|
| 2577 | - PREG_PATTERN_ORDER |
|
| 2578 | - ) |
|
| 2579 | - ) { |
|
| 2580 | - return $regs[0]; |
|
| 2581 | - } else { |
|
| 2582 | - return []; |
|
| 2583 | - } |
|
| 2560 | + if (is_array($texte)) { |
|
| 2561 | + array_walk( |
|
| 2562 | + $texte, |
|
| 2563 | + function (&$a, $key, $t) { |
|
| 2564 | + $a = extraire_balises($a, $t); |
|
| 2565 | + }, |
|
| 2566 | + $tag |
|
| 2567 | + ); |
|
| 2568 | + |
|
| 2569 | + return $texte; |
|
| 2570 | + } |
|
| 2571 | + |
|
| 2572 | + if ( |
|
| 2573 | + preg_match_all( |
|
| 2574 | + ",<{$tag}\b[^>]*(/>|>.*</{$tag}\b[^>]*>|>),UimsS", |
|
| 2575 | + $texte, |
|
| 2576 | + $regs, |
|
| 2577 | + PREG_PATTERN_ORDER |
|
| 2578 | + ) |
|
| 2579 | + ) { |
|
| 2580 | + return $regs[0]; |
|
| 2581 | + } else { |
|
| 2582 | + return []; |
|
| 2583 | + } |
|
| 2584 | 2584 | } |
| 2585 | 2585 | |
| 2586 | 2586 | /** |
@@ -2609,11 +2609,11 @@ discard block |
||
| 2609 | 2609 | * - `$def` si on n'a pas transmis de tableau |
| 2610 | 2610 | **/ |
| 2611 | 2611 | function in_any($val, $vals, $def = '') { |
| 2612 | - if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2613 | - $vals = $v; |
|
| 2614 | - } |
|
| 2612 | + if (!is_array($vals) and $vals and $v = unserialize($vals)) { |
|
| 2613 | + $vals = $v; |
|
| 2614 | + } |
|
| 2615 | 2615 | |
| 2616 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2616 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2617 | 2617 | } |
| 2618 | 2618 | |
| 2619 | 2619 | |
@@ -2634,12 +2634,12 @@ discard block |
||
| 2634 | 2634 | * Résultat du calcul |
| 2635 | 2635 | **/ |
| 2636 | 2636 | function valeur_numerique($expr) { |
| 2637 | - $a = 0; |
|
| 2638 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2639 | - eval("\$a = $expr;"); |
|
| 2640 | - } |
|
| 2637 | + $a = 0; |
|
| 2638 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2639 | + eval("\$a = $expr;"); |
|
| 2640 | + } |
|
| 2641 | 2641 | |
| 2642 | - return intval($a); |
|
| 2642 | + return intval($a); |
|
| 2643 | 2643 | } |
| 2644 | 2644 | |
| 2645 | 2645 | /** |
@@ -2658,7 +2658,7 @@ discard block |
||
| 2658 | 2658 | * Retourne `$a*$b/$c` |
| 2659 | 2659 | **/ |
| 2660 | 2660 | function regledetrois($a, $b, $c) { |
| 2661 | - return round($a * $b / $c); |
|
| 2661 | + return round($a * $b / $c); |
|
| 2662 | 2662 | } |
| 2663 | 2663 | |
| 2664 | 2664 | |
@@ -2681,79 +2681,79 @@ discard block |
||
| 2681 | 2681 | * @return string Suite de champs input hidden |
| 2682 | 2682 | **/ |
| 2683 | 2683 | function form_hidden(?string $action = ''): string { |
| 2684 | - $action ??= ''; |
|
| 2685 | - |
|
| 2686 | - $contexte = []; |
|
| 2687 | - include_spip('inc/urls'); |
|
| 2688 | - if ( |
|
| 2689 | - $p = urls_decoder_url($action, '') |
|
| 2690 | - and reset($p) |
|
| 2691 | - ) { |
|
| 2692 | - $fond = array_shift($p); |
|
| 2693 | - if ($fond != '404') { |
|
| 2694 | - $contexte = array_shift($p); |
|
| 2695 | - $contexte['page'] = $fond; |
|
| 2696 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2697 | - } |
|
| 2698 | - } |
|
| 2699 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2700 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2701 | - unset($contexte['type']); |
|
| 2702 | - } |
|
| 2703 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2704 | - unset($contexte['type-page']); |
|
| 2705 | - } |
|
| 2706 | - |
|
| 2707 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2708 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2709 | - $values = []; |
|
| 2710 | - |
|
| 2711 | - // d'abord avec celles de l'url |
|
| 2712 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2713 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2714 | - $c = explode('=', $c, 2); |
|
| 2715 | - $var = array_shift($c); |
|
| 2716 | - $val = array_shift($c) ?? ''; |
|
| 2717 | - if ($var) { |
|
| 2718 | - $val = rawurldecode($val); |
|
| 2719 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2720 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2721 | - $values[] = [$var, $val]; |
|
| 2722 | - } else { |
|
| 2723 | - if (!isset($values[$var])) { |
|
| 2724 | - $values[$var] = [$var, $val]; |
|
| 2725 | - } |
|
| 2726 | - } |
|
| 2727 | - } |
|
| 2728 | - } |
|
| 2729 | - } |
|
| 2730 | - |
|
| 2731 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2732 | - foreach ($contexte as $var => $val) { |
|
| 2733 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2734 | - $values[] = [$var, $val]; |
|
| 2735 | - } else { |
|
| 2736 | - if (!isset($values[$var])) { |
|
| 2737 | - $values[$var] = [$var, $val]; |
|
| 2738 | - } |
|
| 2739 | - } |
|
| 2740 | - } |
|
| 2741 | - |
|
| 2742 | - // puis on rassemble le tout |
|
| 2743 | - $hidden = []; |
|
| 2744 | - foreach ($values as $value) { |
|
| 2745 | - [$var, $val] = $value; |
|
| 2746 | - $hidden[] = '<input name="' |
|
| 2747 | - . entites_html($var) |
|
| 2748 | - . '"' |
|
| 2749 | - . (is_null($val) |
|
| 2750 | - ? '' |
|
| 2751 | - : ' value="' . entites_html($val) . '"' |
|
| 2752 | - ) |
|
| 2753 | - . ' type="hidden"' . "\n/>"; |
|
| 2754 | - } |
|
| 2755 | - |
|
| 2756 | - return join('', $hidden); |
|
| 2684 | + $action ??= ''; |
|
| 2685 | + |
|
| 2686 | + $contexte = []; |
|
| 2687 | + include_spip('inc/urls'); |
|
| 2688 | + if ( |
|
| 2689 | + $p = urls_decoder_url($action, '') |
|
| 2690 | + and reset($p) |
|
| 2691 | + ) { |
|
| 2692 | + $fond = array_shift($p); |
|
| 2693 | + if ($fond != '404') { |
|
| 2694 | + $contexte = array_shift($p); |
|
| 2695 | + $contexte['page'] = $fond; |
|
| 2696 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2697 | + } |
|
| 2698 | + } |
|
| 2699 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2700 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2701 | + unset($contexte['type']); |
|
| 2702 | + } |
|
| 2703 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2704 | + unset($contexte['type-page']); |
|
| 2705 | + } |
|
| 2706 | + |
|
| 2707 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2708 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2709 | + $values = []; |
|
| 2710 | + |
|
| 2711 | + // d'abord avec celles de l'url |
|
| 2712 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2713 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2714 | + $c = explode('=', $c, 2); |
|
| 2715 | + $var = array_shift($c); |
|
| 2716 | + $val = array_shift($c) ?? ''; |
|
| 2717 | + if ($var) { |
|
| 2718 | + $val = rawurldecode($val); |
|
| 2719 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2720 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2721 | + $values[] = [$var, $val]; |
|
| 2722 | + } else { |
|
| 2723 | + if (!isset($values[$var])) { |
|
| 2724 | + $values[$var] = [$var, $val]; |
|
| 2725 | + } |
|
| 2726 | + } |
|
| 2727 | + } |
|
| 2728 | + } |
|
| 2729 | + } |
|
| 2730 | + |
|
| 2731 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2732 | + foreach ($contexte as $var => $val) { |
|
| 2733 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2734 | + $values[] = [$var, $val]; |
|
| 2735 | + } else { |
|
| 2736 | + if (!isset($values[$var])) { |
|
| 2737 | + $values[$var] = [$var, $val]; |
|
| 2738 | + } |
|
| 2739 | + } |
|
| 2740 | + } |
|
| 2741 | + |
|
| 2742 | + // puis on rassemble le tout |
|
| 2743 | + $hidden = []; |
|
| 2744 | + foreach ($values as $value) { |
|
| 2745 | + [$var, $val] = $value; |
|
| 2746 | + $hidden[] = '<input name="' |
|
| 2747 | + . entites_html($var) |
|
| 2748 | + . '"' |
|
| 2749 | + . (is_null($val) |
|
| 2750 | + ? '' |
|
| 2751 | + : ' value="' . entites_html($val) . '"' |
|
| 2752 | + ) |
|
| 2753 | + . ' type="hidden"' . "\n/>"; |
|
| 2754 | + } |
|
| 2755 | + |
|
| 2756 | + return join('', $hidden); |
|
| 2757 | 2757 | } |
| 2758 | 2758 | |
| 2759 | 2759 | |
@@ -2775,7 +2775,7 @@ discard block |
||
| 2775 | 2775 | * - la première valeur du tableau sinon. |
| 2776 | 2776 | **/ |
| 2777 | 2777 | function filtre_reset($array) { |
| 2778 | - return !is_array($array) ? null : reset($array); |
|
| 2778 | + return !is_array($array) ? null : reset($array); |
|
| 2779 | 2779 | } |
| 2780 | 2780 | |
| 2781 | 2781 | /** |
@@ -2796,7 +2796,7 @@ discard block |
||
| 2796 | 2796 | * - la dernière valeur du tableau sinon. |
| 2797 | 2797 | **/ |
| 2798 | 2798 | function filtre_end($array) { |
| 2799 | - return !is_array($array) ? null : end($array); |
|
| 2799 | + return !is_array($array) ? null : end($array); |
|
| 2800 | 2800 | } |
| 2801 | 2801 | |
| 2802 | 2802 | /** |
@@ -2816,11 +2816,11 @@ discard block |
||
| 2816 | 2816 | * |
| 2817 | 2817 | **/ |
| 2818 | 2818 | function filtre_push($array, $val) { |
| 2819 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2820 | - return ''; |
|
| 2821 | - } |
|
| 2819 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2820 | + return ''; |
|
| 2821 | + } |
|
| 2822 | 2822 | |
| 2823 | - return $array; |
|
| 2823 | + return $array; |
|
| 2824 | 2824 | } |
| 2825 | 2825 | |
| 2826 | 2826 | /** |
@@ -2839,7 +2839,7 @@ discard block |
||
| 2839 | 2839 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2840 | 2840 | **/ |
| 2841 | 2841 | function filtre_find($array, $val) { |
| 2842 | - return (is_array($array) and in_array($val, $array)); |
|
| 2842 | + return (is_array($array) and in_array($val, $array)); |
|
| 2843 | 2843 | } |
| 2844 | 2844 | |
| 2845 | 2845 | |
@@ -2856,13 +2856,13 @@ discard block |
||
| 2856 | 2856 | * Contenu avec urls en absolus |
| 2857 | 2857 | **/ |
| 2858 | 2858 | function urls_absolues_css($contenu, $source) { |
| 2859 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2859 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2860 | 2860 | |
| 2861 | - return preg_replace_callback( |
|
| 2862 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2863 | - fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2864 | - $contenu |
|
| 2865 | - ); |
|
| 2861 | + return preg_replace_callback( |
|
| 2862 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2863 | + fn($x) => "url('" . suivre_lien($path, $x[1]) . "')", |
|
| 2864 | + $contenu |
|
| 2865 | + ); |
|
| 2866 | 2866 | } |
| 2867 | 2867 | |
| 2868 | 2868 | |
@@ -2891,119 +2891,119 @@ discard block |
||
| 2891 | 2891 | * Chemin du fichier CSS inversé |
| 2892 | 2892 | **/ |
| 2893 | 2893 | function direction_css($css, $voulue = '') { |
| 2894 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2895 | - return $css; |
|
| 2896 | - } |
|
| 2897 | - include_spip('inc/lang'); |
|
| 2898 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2899 | - if ($voulue = strtolower($voulue)) { |
|
| 2900 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2901 | - $voulue = lang_dir($voulue); |
|
| 2902 | - } |
|
| 2903 | - } else { |
|
| 2904 | - $voulue = lang_dir(); |
|
| 2905 | - } |
|
| 2906 | - |
|
| 2907 | - $r = count($r) > 1; |
|
| 2908 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2909 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2910 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2911 | - |
|
| 2912 | - if ($voulue == $dir) { |
|
| 2913 | - return $css; |
|
| 2914 | - } |
|
| 2915 | - |
|
| 2916 | - if ( |
|
| 2917 | - // url absolue |
|
| 2918 | - preg_match(',^https?:,i', $css) |
|
| 2919 | - // ou qui contient un ? |
|
| 2920 | - or (($p = strpos($css, '?')) !== false) |
|
| 2921 | - ) { |
|
| 2922 | - $distant = true; |
|
| 2923 | - $cssf = parse_url($css); |
|
| 2924 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2925 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2926 | - } else { |
|
| 2927 | - $distant = false; |
|
| 2928 | - $cssf = $css; |
|
| 2929 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2930 | - //propose (rien a faire dans ce cas) |
|
| 2931 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2932 | - if (@file_exists($f)) { |
|
| 2933 | - return $f; |
|
| 2934 | - } |
|
| 2935 | - } |
|
| 2936 | - |
|
| 2937 | - // 2. |
|
| 2938 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2939 | - $f = $dir_var |
|
| 2940 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2941 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2942 | - |
|
| 2943 | - // la css peut etre distante (url absolue !) |
|
| 2944 | - if ($distant) { |
|
| 2945 | - include_spip('inc/distant'); |
|
| 2946 | - $res = recuperer_url($css); |
|
| 2947 | - if (!$res or !$contenu = $res['page']) { |
|
| 2948 | - return $css; |
|
| 2949 | - } |
|
| 2950 | - } else { |
|
| 2951 | - if ( |
|
| 2952 | - (@filemtime($f) > @filemtime($css)) |
|
| 2953 | - and (_VAR_MODE != 'recalcul') |
|
| 2954 | - ) { |
|
| 2955 | - return $f; |
|
| 2956 | - } |
|
| 2957 | - if (!lire_fichier($css, $contenu)) { |
|
| 2958 | - return $css; |
|
| 2959 | - } |
|
| 2960 | - } |
|
| 2961 | - |
|
| 2962 | - |
|
| 2963 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2964 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 2965 | - $parser = new csstidy(); |
|
| 2966 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 2967 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 2968 | - $parser->parse($contenu); |
|
| 2969 | - |
|
| 2970 | - $contenu = $parser->print->plain(); |
|
| 2971 | - |
|
| 2972 | - |
|
| 2973 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 2974 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2975 | - $src = []; |
|
| 2976 | - $src_direction_css = []; |
|
| 2977 | - $src_faux_abs = []; |
|
| 2978 | - $d = dirname($css); |
|
| 2979 | - foreach ($regs[1] as $k => $import_css) { |
|
| 2980 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2981 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2982 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2983 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2984 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2985 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2986 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2987 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2988 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2989 | - } |
|
| 2990 | - $src[] = $regs[0][$k]; |
|
| 2991 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2992 | - } |
|
| 2993 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2994 | - |
|
| 2995 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 2996 | - |
|
| 2997 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 2998 | - if (count($src_faux_abs)) { |
|
| 2999 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3000 | - } |
|
| 3001 | - |
|
| 3002 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3003 | - return $css; |
|
| 3004 | - } |
|
| 3005 | - |
|
| 3006 | - return $f; |
|
| 2894 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2895 | + return $css; |
|
| 2896 | + } |
|
| 2897 | + include_spip('inc/lang'); |
|
| 2898 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2899 | + if ($voulue = strtolower($voulue)) { |
|
| 2900 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2901 | + $voulue = lang_dir($voulue); |
|
| 2902 | + } |
|
| 2903 | + } else { |
|
| 2904 | + $voulue = lang_dir(); |
|
| 2905 | + } |
|
| 2906 | + |
|
| 2907 | + $r = count($r) > 1; |
|
| 2908 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2909 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2910 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2911 | + |
|
| 2912 | + if ($voulue == $dir) { |
|
| 2913 | + return $css; |
|
| 2914 | + } |
|
| 2915 | + |
|
| 2916 | + if ( |
|
| 2917 | + // url absolue |
|
| 2918 | + preg_match(',^https?:,i', $css) |
|
| 2919 | + // ou qui contient un ? |
|
| 2920 | + or (($p = strpos($css, '?')) !== false) |
|
| 2921 | + ) { |
|
| 2922 | + $distant = true; |
|
| 2923 | + $cssf = parse_url($css); |
|
| 2924 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2925 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2926 | + } else { |
|
| 2927 | + $distant = false; |
|
| 2928 | + $cssf = $css; |
|
| 2929 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2930 | + //propose (rien a faire dans ce cas) |
|
| 2931 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2932 | + if (@file_exists($f)) { |
|
| 2933 | + return $f; |
|
| 2934 | + } |
|
| 2935 | + } |
|
| 2936 | + |
|
| 2937 | + // 2. |
|
| 2938 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2939 | + $f = $dir_var |
|
| 2940 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2941 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2942 | + |
|
| 2943 | + // la css peut etre distante (url absolue !) |
|
| 2944 | + if ($distant) { |
|
| 2945 | + include_spip('inc/distant'); |
|
| 2946 | + $res = recuperer_url($css); |
|
| 2947 | + if (!$res or !$contenu = $res['page']) { |
|
| 2948 | + return $css; |
|
| 2949 | + } |
|
| 2950 | + } else { |
|
| 2951 | + if ( |
|
| 2952 | + (@filemtime($f) > @filemtime($css)) |
|
| 2953 | + and (_VAR_MODE != 'recalcul') |
|
| 2954 | + ) { |
|
| 2955 | + return $f; |
|
| 2956 | + } |
|
| 2957 | + if (!lire_fichier($css, $contenu)) { |
|
| 2958 | + return $css; |
|
| 2959 | + } |
|
| 2960 | + } |
|
| 2961 | + |
|
| 2962 | + |
|
| 2963 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 2964 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 2965 | + $parser = new csstidy(); |
|
| 2966 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 2967 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 2968 | + $parser->parse($contenu); |
|
| 2969 | + |
|
| 2970 | + $contenu = $parser->print->plain(); |
|
| 2971 | + |
|
| 2972 | + |
|
| 2973 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 2974 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 2975 | + $src = []; |
|
| 2976 | + $src_direction_css = []; |
|
| 2977 | + $src_faux_abs = []; |
|
| 2978 | + $d = dirname($css); |
|
| 2979 | + foreach ($regs[1] as $k => $import_css) { |
|
| 2980 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 2981 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 2982 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 2983 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 2984 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 2985 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 2986 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 2987 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 2988 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 2989 | + } |
|
| 2990 | + $src[] = $regs[0][$k]; |
|
| 2991 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 2992 | + } |
|
| 2993 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 2994 | + |
|
| 2995 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 2996 | + |
|
| 2997 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 2998 | + if (count($src_faux_abs)) { |
|
| 2999 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3000 | + } |
|
| 3001 | + |
|
| 3002 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3003 | + return $css; |
|
| 3004 | + } |
|
| 3005 | + |
|
| 3006 | + return $f; |
|
| 3007 | 3007 | } |
| 3008 | 3008 | |
| 3009 | 3009 | |
@@ -3026,46 +3026,46 @@ discard block |
||
| 3026 | 3026 | * - Chemin ou URL du fichier CSS source sinon. |
| 3027 | 3027 | **/ |
| 3028 | 3028 | function url_absolue_css($css) { |
| 3029 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3030 | - return $css; |
|
| 3031 | - } |
|
| 3029 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3030 | + return $css; |
|
| 3031 | + } |
|
| 3032 | 3032 | |
| 3033 | - $url_absolue_css = url_absolue($css); |
|
| 3033 | + $url_absolue_css = url_absolue($css); |
|
| 3034 | 3034 | |
| 3035 | - $f = basename($css, '.css'); |
|
| 3036 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3037 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3038 | - . '.css'; |
|
| 3035 | + $f = basename($css, '.css'); |
|
| 3036 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3037 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3038 | + . '.css'; |
|
| 3039 | 3039 | |
| 3040 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3041 | - return $f; |
|
| 3042 | - } |
|
| 3040 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3041 | + return $f; |
|
| 3042 | + } |
|
| 3043 | 3043 | |
| 3044 | - if ($url_absolue_css == $css) { |
|
| 3045 | - if ( |
|
| 3046 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3047 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3048 | - ) { |
|
| 3049 | - include_spip('inc/distant'); |
|
| 3050 | - $contenu = recuperer_url($css); |
|
| 3051 | - $contenu = $contenu['page'] ?? ''; |
|
| 3052 | - if (!$contenu) { |
|
| 3053 | - return $css; |
|
| 3054 | - } |
|
| 3055 | - } |
|
| 3056 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3057 | - return $css; |
|
| 3058 | - } |
|
| 3044 | + if ($url_absolue_css == $css) { |
|
| 3045 | + if ( |
|
| 3046 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3047 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3048 | + ) { |
|
| 3049 | + include_spip('inc/distant'); |
|
| 3050 | + $contenu = recuperer_url($css); |
|
| 3051 | + $contenu = $contenu['page'] ?? ''; |
|
| 3052 | + if (!$contenu) { |
|
| 3053 | + return $css; |
|
| 3054 | + } |
|
| 3055 | + } |
|
| 3056 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3057 | + return $css; |
|
| 3058 | + } |
|
| 3059 | 3059 | |
| 3060 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3061 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3060 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3061 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3062 | 3062 | |
| 3063 | - // ecrire la css |
|
| 3064 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3065 | - return $css; |
|
| 3066 | - } |
|
| 3063 | + // ecrire la css |
|
| 3064 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3065 | + return $css; |
|
| 3066 | + } |
|
| 3067 | 3067 | |
| 3068 | - return $f; |
|
| 3068 | + return $f; |
|
| 3069 | 3069 | } |
| 3070 | 3070 | |
| 3071 | 3071 | |
@@ -3099,24 +3099,24 @@ discard block |
||
| 3099 | 3099 | * Valeur trouvée ou valeur par défaut. |
| 3100 | 3100 | **/ |
| 3101 | 3101 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3102 | - foreach (explode('/', $cle) as $k) { |
|
| 3103 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3102 | + foreach (explode('/', $cle) as $k) { |
|
| 3103 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3104 | 3104 | |
| 3105 | - if (is_object($table)) { |
|
| 3106 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3107 | - } elseif (is_array($table)) { |
|
| 3108 | - if ($conserver_null) { |
|
| 3109 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3110 | - } else { |
|
| 3111 | - $table = ($table[$k] ?? $defaut); |
|
| 3112 | - } |
|
| 3113 | - } else { |
|
| 3114 | - $table = $defaut; |
|
| 3115 | - break; |
|
| 3116 | - } |
|
| 3117 | - } |
|
| 3105 | + if (is_object($table)) { |
|
| 3106 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3107 | + } elseif (is_array($table)) { |
|
| 3108 | + if ($conserver_null) { |
|
| 3109 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3110 | + } else { |
|
| 3111 | + $table = ($table[$k] ?? $defaut); |
|
| 3112 | + } |
|
| 3113 | + } else { |
|
| 3114 | + $table = $defaut; |
|
| 3115 | + break; |
|
| 3116 | + } |
|
| 3117 | + } |
|
| 3118 | 3118 | |
| 3119 | - return $table; |
|
| 3119 | + return $table; |
|
| 3120 | 3120 | } |
| 3121 | 3121 | |
| 3122 | 3122 | /** |
@@ -3149,22 +3149,22 @@ discard block |
||
| 3149 | 3149 | * - string : expression trouvée. |
| 3150 | 3150 | **/ |
| 3151 | 3151 | function filtre_match_dist(?string $texte, $expression, $modif = 'UuimsS', $capte = 0) { |
| 3152 | - if (intval($modif) and $capte == 0) { |
|
| 3153 | - $capte = $modif; |
|
| 3154 | - $modif = 'UuimsS'; |
|
| 3155 | - } |
|
| 3156 | - $expression = str_replace('\/', '/', $expression); |
|
| 3157 | - $expression = str_replace('/', '\/', $expression); |
|
| 3152 | + if (intval($modif) and $capte == 0) { |
|
| 3153 | + $capte = $modif; |
|
| 3154 | + $modif = 'UuimsS'; |
|
| 3155 | + } |
|
| 3156 | + $expression = str_replace('\/', '/', $expression); |
|
| 3157 | + $expression = str_replace('/', '\/', $expression); |
|
| 3158 | 3158 | |
| 3159 | - if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3160 | - if (isset($r[$capte])) { |
|
| 3161 | - return $r[$capte]; |
|
| 3162 | - } else { |
|
| 3163 | - return true; |
|
| 3164 | - } |
|
| 3165 | - } |
|
| 3159 | + if (preg_match('/' . $expression . '/' . $modif, $texte ?? '', $r)) { |
|
| 3160 | + if (isset($r[$capte])) { |
|
| 3161 | + return $r[$capte]; |
|
| 3162 | + } else { |
|
| 3163 | + return true; |
|
| 3164 | + } |
|
| 3165 | + } |
|
| 3166 | 3166 | |
| 3167 | - return false; |
|
| 3167 | + return false; |
|
| 3168 | 3168 | } |
| 3169 | 3169 | |
| 3170 | 3170 | |
@@ -3191,14 +3191,14 @@ discard block |
||
| 3191 | 3191 | * Texte |
| 3192 | 3192 | **/ |
| 3193 | 3193 | function replace(?string $texte, string $expression, string $replace = '', string $modif = 'UimsS'): string { |
| 3194 | - if (null === $texte) { |
|
| 3195 | - return ''; |
|
| 3196 | - } |
|
| 3194 | + if (null === $texte) { |
|
| 3195 | + return ''; |
|
| 3196 | + } |
|
| 3197 | 3197 | |
| 3198 | - $expression = str_replace('\/', '/', $expression); |
|
| 3199 | - $expression = str_replace('/', '\/', $expression); |
|
| 3198 | + $expression = str_replace('\/', '/', $expression); |
|
| 3199 | + $expression = str_replace('/', '\/', $expression); |
|
| 3200 | 3200 | |
| 3201 | - return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3201 | + return (string) preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3202 | 3202 | } |
| 3203 | 3203 | |
| 3204 | 3204 | |
@@ -3216,25 +3216,25 @@ discard block |
||
| 3216 | 3216 | **/ |
| 3217 | 3217 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3218 | 3218 | |
| 3219 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3220 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3219 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3220 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3221 | 3221 | |
| 3222 | - if ( |
|
| 3223 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3224 | - and preg_match_all( |
|
| 3225 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3226 | - $t, |
|
| 3227 | - $matches, |
|
| 3228 | - PREG_PATTERN_ORDER |
|
| 3229 | - ) |
|
| 3230 | - ) { |
|
| 3231 | - if (!isset($doublons['documents'])) { |
|
| 3232 | - $doublons['documents'] = ''; |
|
| 3233 | - } |
|
| 3234 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3235 | - } |
|
| 3222 | + if ( |
|
| 3223 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3224 | + and preg_match_all( |
|
| 3225 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3226 | + $t, |
|
| 3227 | + $matches, |
|
| 3228 | + PREG_PATTERN_ORDER |
|
| 3229 | + ) |
|
| 3230 | + ) { |
|
| 3231 | + if (!isset($doublons['documents'])) { |
|
| 3232 | + $doublons['documents'] = ''; |
|
| 3233 | + } |
|
| 3234 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3235 | + } |
|
| 3236 | 3236 | |
| 3237 | - return $letexte; |
|
| 3237 | + return $letexte; |
|
| 3238 | 3238 | } |
| 3239 | 3239 | |
| 3240 | 3240 | /** |
@@ -3248,7 +3248,7 @@ discard block |
||
| 3248 | 3248 | * @return string Chaîne vide |
| 3249 | 3249 | **/ |
| 3250 | 3250 | function vide($texte) { |
| 3251 | - return ''; |
|
| 3251 | + return ''; |
|
| 3252 | 3252 | } |
| 3253 | 3253 | |
| 3254 | 3254 | // |
@@ -3277,23 +3277,23 @@ discard block |
||
| 3277 | 3277 | * Code HTML résultant |
| 3278 | 3278 | **/ |
| 3279 | 3279 | function env_to_params($env, $ignore_params = []) { |
| 3280 | - $ignore_params = array_merge( |
|
| 3281 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3282 | - $ignore_params |
|
| 3283 | - ); |
|
| 3284 | - if (!is_array($env)) { |
|
| 3285 | - $env = unserialize($env); |
|
| 3286 | - } |
|
| 3287 | - $texte = ''; |
|
| 3288 | - if ($env) { |
|
| 3289 | - foreach ($env as $i => $j) { |
|
| 3290 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3291 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3292 | - } |
|
| 3293 | - } |
|
| 3294 | - } |
|
| 3295 | - |
|
| 3296 | - return $texte; |
|
| 3280 | + $ignore_params = array_merge( |
|
| 3281 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3282 | + $ignore_params |
|
| 3283 | + ); |
|
| 3284 | + if (!is_array($env)) { |
|
| 3285 | + $env = unserialize($env); |
|
| 3286 | + } |
|
| 3287 | + $texte = ''; |
|
| 3288 | + if ($env) { |
|
| 3289 | + foreach ($env as $i => $j) { |
|
| 3290 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3291 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3292 | + } |
|
| 3293 | + } |
|
| 3294 | + } |
|
| 3295 | + |
|
| 3296 | + return $texte; |
|
| 3297 | 3297 | } |
| 3298 | 3298 | |
| 3299 | 3299 | /** |
@@ -3316,23 +3316,23 @@ discard block |
||
| 3316 | 3316 | * Code HTML résultant |
| 3317 | 3317 | **/ |
| 3318 | 3318 | function env_to_attributs($env, $ignore_params = []) { |
| 3319 | - $ignore_params = array_merge( |
|
| 3320 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3321 | - $ignore_params |
|
| 3322 | - ); |
|
| 3323 | - if (!is_array($env)) { |
|
| 3324 | - $env = unserialize($env); |
|
| 3325 | - } |
|
| 3326 | - $texte = ''; |
|
| 3327 | - if ($env) { |
|
| 3328 | - foreach ($env as $i => $j) { |
|
| 3329 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3330 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3331 | - } |
|
| 3332 | - } |
|
| 3333 | - } |
|
| 3319 | + $ignore_params = array_merge( |
|
| 3320 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3321 | + $ignore_params |
|
| 3322 | + ); |
|
| 3323 | + if (!is_array($env)) { |
|
| 3324 | + $env = unserialize($env); |
|
| 3325 | + } |
|
| 3326 | + $texte = ''; |
|
| 3327 | + if ($env) { |
|
| 3328 | + foreach ($env as $i => $j) { |
|
| 3329 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3330 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3331 | + } |
|
| 3332 | + } |
|
| 3333 | + } |
|
| 3334 | 3334 | |
| 3335 | - return $texte; |
|
| 3335 | + return $texte; |
|
| 3336 | 3336 | } |
| 3337 | 3337 | |
| 3338 | 3338 | |
@@ -3350,7 +3350,7 @@ discard block |
||
| 3350 | 3350 | * @return string Chaînes concaténés |
| 3351 | 3351 | **/ |
| 3352 | 3352 | function concat(...$args): string { |
| 3353 | - return join('', $args); |
|
| 3353 | + return join('', $args); |
|
| 3354 | 3354 | } |
| 3355 | 3355 | |
| 3356 | 3356 | |
@@ -3370,23 +3370,23 @@ discard block |
||
| 3370 | 3370 | * Contenu du ou des fichiers, concaténé |
| 3371 | 3371 | **/ |
| 3372 | 3372 | function charge_scripts($files, $script = true) { |
| 3373 | - $flux = ''; |
|
| 3374 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3375 | - if (!is_string($file)) { |
|
| 3376 | - continue; |
|
| 3377 | - } |
|
| 3378 | - if ($script) { |
|
| 3379 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3380 | - } |
|
| 3381 | - if ($file) { |
|
| 3382 | - $path = find_in_path($file); |
|
| 3383 | - if ($path) { |
|
| 3384 | - $flux .= spip_file_get_contents($path); |
|
| 3385 | - } |
|
| 3386 | - } |
|
| 3387 | - } |
|
| 3388 | - |
|
| 3389 | - return $flux; |
|
| 3373 | + $flux = ''; |
|
| 3374 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3375 | + if (!is_string($file)) { |
|
| 3376 | + continue; |
|
| 3377 | + } |
|
| 3378 | + if ($script) { |
|
| 3379 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3380 | + } |
|
| 3381 | + if ($file) { |
|
| 3382 | + $path = find_in_path($file); |
|
| 3383 | + if ($path) { |
|
| 3384 | + $flux .= spip_file_get_contents($path); |
|
| 3385 | + } |
|
| 3386 | + } |
|
| 3387 | + } |
|
| 3388 | + |
|
| 3389 | + return $flux; |
|
| 3390 | 3390 | } |
| 3391 | 3391 | |
| 3392 | 3392 | /** |
@@ -3397,22 +3397,22 @@ discard block |
||
| 3397 | 3397 | * @return string |
| 3398 | 3398 | */ |
| 3399 | 3399 | function http_img_variante_svg_si_possible($img_file) { |
| 3400 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3401 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3402 | - if ( |
|
| 3403 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3404 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3405 | - and file_exists($variante_svg_generique) |
|
| 3406 | - ) { |
|
| 3407 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3408 | - $img_file = $variante_svg_size; |
|
| 3409 | - } |
|
| 3410 | - else { |
|
| 3411 | - $img_file = $variante_svg_generique; |
|
| 3412 | - } |
|
| 3413 | - } |
|
| 3400 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3401 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3402 | + if ( |
|
| 3403 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3404 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3405 | + and file_exists($variante_svg_generique) |
|
| 3406 | + ) { |
|
| 3407 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3408 | + $img_file = $variante_svg_size; |
|
| 3409 | + } |
|
| 3410 | + else { |
|
| 3411 | + $img_file = $variante_svg_generique; |
|
| 3412 | + } |
|
| 3413 | + } |
|
| 3414 | 3414 | |
| 3415 | - return $img_file; |
|
| 3415 | + return $img_file; |
|
| 3416 | 3416 | } |
| 3417 | 3417 | |
| 3418 | 3418 | /** |
@@ -3433,54 +3433,54 @@ discard block |
||
| 3433 | 3433 | */ |
| 3434 | 3434 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3435 | 3435 | |
| 3436 | - $img_file = $img; |
|
| 3437 | - if ($p = strpos($img_file, '?')) { |
|
| 3438 | - $img_file = substr($img_file, 0, $p); |
|
| 3439 | - } |
|
| 3440 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3441 | - $img_file = chemin_image($img); |
|
| 3442 | - } |
|
| 3443 | - else { |
|
| 3444 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3445 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3446 | - } |
|
| 3447 | - } |
|
| 3448 | - if (stripos($atts, 'width') === false) { |
|
| 3449 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3450 | - if ( |
|
| 3451 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3452 | - or $options['utiliser_suffixe_size'] == true |
|
| 3453 | - or str_contains($img_file, '-xx.svg')) |
|
| 3454 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3455 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3456 | - ) { |
|
| 3457 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3458 | - } else { |
|
| 3459 | - $taille = taille_image($img_file); |
|
| 3460 | - [$hauteur, $largeur] = $taille; |
|
| 3461 | - if (!$hauteur or !$largeur) { |
|
| 3462 | - return ''; |
|
| 3463 | - } |
|
| 3464 | - } |
|
| 3465 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3466 | - } |
|
| 3467 | - |
|
| 3468 | - if (file_exists($img_file)) { |
|
| 3469 | - $img_file = timestamp($img_file); |
|
| 3470 | - } |
|
| 3471 | - if ($alt === false) { |
|
| 3472 | - $alt = ''; |
|
| 3473 | - } |
|
| 3474 | - elseif ($alt or $alt === '') { |
|
| 3475 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3476 | - } |
|
| 3477 | - else { |
|
| 3478 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3479 | - } |
|
| 3480 | - return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3481 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3482 | - . ' ' . ltrim($atts) |
|
| 3483 | - . ' />'; |
|
| 3436 | + $img_file = $img; |
|
| 3437 | + if ($p = strpos($img_file, '?')) { |
|
| 3438 | + $img_file = substr($img_file, 0, $p); |
|
| 3439 | + } |
|
| 3440 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3441 | + $img_file = chemin_image($img); |
|
| 3442 | + } |
|
| 3443 | + else { |
|
| 3444 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3445 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3446 | + } |
|
| 3447 | + } |
|
| 3448 | + if (stripos($atts, 'width') === false) { |
|
| 3449 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3450 | + if ( |
|
| 3451 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3452 | + or $options['utiliser_suffixe_size'] == true |
|
| 3453 | + or str_contains($img_file, '-xx.svg')) |
|
| 3454 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3455 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3456 | + ) { |
|
| 3457 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3458 | + } else { |
|
| 3459 | + $taille = taille_image($img_file); |
|
| 3460 | + [$hauteur, $largeur] = $taille; |
|
| 3461 | + if (!$hauteur or !$largeur) { |
|
| 3462 | + return ''; |
|
| 3463 | + } |
|
| 3464 | + } |
|
| 3465 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3466 | + } |
|
| 3467 | + |
|
| 3468 | + if (file_exists($img_file)) { |
|
| 3469 | + $img_file = timestamp($img_file); |
|
| 3470 | + } |
|
| 3471 | + if ($alt === false) { |
|
| 3472 | + $alt = ''; |
|
| 3473 | + } |
|
| 3474 | + elseif ($alt or $alt === '') { |
|
| 3475 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3476 | + } |
|
| 3477 | + else { |
|
| 3478 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3479 | + } |
|
| 3480 | + return "<img src='" . attribut_html($img_file) . "'$alt" |
|
| 3481 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3482 | + . ' ' . ltrim($atts) |
|
| 3483 | + . ' />'; |
|
| 3484 | 3484 | } |
| 3485 | 3485 | |
| 3486 | 3486 | /** |
@@ -3492,70 +3492,70 @@ discard block |
||
| 3492 | 3492 | * @return string |
| 3493 | 3493 | */ |
| 3494 | 3494 | function http_style_background($img, $att = '', $size = null) { |
| 3495 | - if ($size and is_numeric($size)) { |
|
| 3496 | - $size = trim($size) . 'px'; |
|
| 3497 | - } |
|
| 3498 | - return " style='background" . |
|
| 3499 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3500 | - . ($size ? "background-size:{$size};" : '') |
|
| 3501 | - . "'"; |
|
| 3495 | + if ($size and is_numeric($size)) { |
|
| 3496 | + $size = trim($size) . 'px'; |
|
| 3497 | + } |
|
| 3498 | + return " style='background" . |
|
| 3499 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3500 | + . ($size ? "background-size:{$size};" : '') |
|
| 3501 | + . "'"; |
|
| 3502 | 3502 | } |
| 3503 | 3503 | |
| 3504 | 3504 | |
| 3505 | 3505 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3506 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3507 | - while (is_null(end($args)) and count($args)) { |
|
| 3508 | - array_pop($args); |
|
| 3509 | - } |
|
| 3510 | - if (!count($args)) { |
|
| 3511 | - return [null, null, null]; |
|
| 3512 | - } |
|
| 3513 | - if (count($args) < 3) { |
|
| 3514 | - $maybe_size = array_pop($args); |
|
| 3515 | - // @2x |
|
| 3516 | - // @1.5x |
|
| 3517 | - // 512 |
|
| 3518 | - // 512x* |
|
| 3519 | - // 512x300 |
|
| 3520 | - if ( |
|
| 3521 | - !strlen($maybe_size) |
|
| 3522 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3523 | - ) { |
|
| 3524 | - $args[] = $maybe_size; |
|
| 3525 | - $maybe_size = null; |
|
| 3526 | - } |
|
| 3527 | - while (count($args) < 2) { |
|
| 3528 | - $args[] = null; // default alt or class |
|
| 3529 | - } |
|
| 3530 | - $args[] = $maybe_size; |
|
| 3531 | - } |
|
| 3532 | - return $args; |
|
| 3506 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3507 | + while (is_null(end($args)) and count($args)) { |
|
| 3508 | + array_pop($args); |
|
| 3509 | + } |
|
| 3510 | + if (!count($args)) { |
|
| 3511 | + return [null, null, null]; |
|
| 3512 | + } |
|
| 3513 | + if (count($args) < 3) { |
|
| 3514 | + $maybe_size = array_pop($args); |
|
| 3515 | + // @2x |
|
| 3516 | + // @1.5x |
|
| 3517 | + // 512 |
|
| 3518 | + // 512x* |
|
| 3519 | + // 512x300 |
|
| 3520 | + if ( |
|
| 3521 | + !strlen($maybe_size) |
|
| 3522 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3523 | + ) { |
|
| 3524 | + $args[] = $maybe_size; |
|
| 3525 | + $maybe_size = null; |
|
| 3526 | + } |
|
| 3527 | + while (count($args) < 2) { |
|
| 3528 | + $args[] = null; // default alt or class |
|
| 3529 | + } |
|
| 3530 | + $args[] = $maybe_size; |
|
| 3531 | + } |
|
| 3532 | + return $args; |
|
| 3533 | 3533 | } |
| 3534 | 3534 | |
| 3535 | 3535 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3536 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3537 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3538 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3539 | - [$h, $w] = taille_image($img); |
|
| 3540 | - $height = intval(round($h / $coef)); |
|
| 3541 | - $width = intval(round($w / $coef)); |
|
| 3542 | - } |
|
| 3543 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3544 | - else { |
|
| 3545 | - $size = explode('x', $size, 2); |
|
| 3546 | - $size = array_map('trim', $size); |
|
| 3547 | - $height = $width = intval(array_shift($size)); |
|
| 3548 | - |
|
| 3549 | - if (count($size) and reset($size)) { |
|
| 3550 | - $height = array_shift($size); |
|
| 3551 | - if ($height === '*') { |
|
| 3552 | - [$h, $w] = taille_image($img); |
|
| 3553 | - $height = intval(round($h * $width / $w)); |
|
| 3554 | - } |
|
| 3555 | - } |
|
| 3556 | - } |
|
| 3557 | - |
|
| 3558 | - return [$width, $height]; |
|
| 3536 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3537 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3538 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3539 | + [$h, $w] = taille_image($img); |
|
| 3540 | + $height = intval(round($h / $coef)); |
|
| 3541 | + $width = intval(round($w / $coef)); |
|
| 3542 | + } |
|
| 3543 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3544 | + else { |
|
| 3545 | + $size = explode('x', $size, 2); |
|
| 3546 | + $size = array_map('trim', $size); |
|
| 3547 | + $height = $width = intval(array_shift($size)); |
|
| 3548 | + |
|
| 3549 | + if (count($size) and reset($size)) { |
|
| 3550 | + $height = array_shift($size); |
|
| 3551 | + if ($height === '*') { |
|
| 3552 | + [$h, $w] = taille_image($img); |
|
| 3553 | + $height = intval(round($h * $width / $w)); |
|
| 3554 | + } |
|
| 3555 | + } |
|
| 3556 | + } |
|
| 3557 | + |
|
| 3558 | + return [$width, $height]; |
|
| 3559 | 3559 | } |
| 3560 | 3560 | |
| 3561 | 3561 | /** |
@@ -3591,43 +3591,43 @@ discard block |
||
| 3591 | 3591 | */ |
| 3592 | 3592 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3593 | 3593 | |
| 3594 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3595 | - |
|
| 3596 | - $img = trim((string) $img); |
|
| 3597 | - if (strpos($img, '<img') === 0) { |
|
| 3598 | - if (!is_null($alt)) { |
|
| 3599 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3600 | - } |
|
| 3601 | - if (!is_null($class)) { |
|
| 3602 | - if (strlen($class)) { |
|
| 3603 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3604 | - } |
|
| 3605 | - else { |
|
| 3606 | - $img = vider_attribut($img, 'class'); |
|
| 3607 | - } |
|
| 3608 | - } |
|
| 3609 | - } |
|
| 3610 | - else { |
|
| 3611 | - $img = http_img_pack( |
|
| 3612 | - $img, |
|
| 3613 | - $alt, |
|
| 3614 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3615 | - '', |
|
| 3616 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3617 | - ); |
|
| 3618 | - if (is_null($alt)) { |
|
| 3619 | - $img = vider_attribut($img, 'alt'); |
|
| 3620 | - } |
|
| 3621 | - } |
|
| 3622 | - |
|
| 3623 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3624 | - [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3625 | - |
|
| 3626 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3627 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3628 | - } |
|
| 3629 | - |
|
| 3630 | - return $img; |
|
| 3594 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3595 | + |
|
| 3596 | + $img = trim((string) $img); |
|
| 3597 | + if (strpos($img, '<img') === 0) { |
|
| 3598 | + if (!is_null($alt)) { |
|
| 3599 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3600 | + } |
|
| 3601 | + if (!is_null($class)) { |
|
| 3602 | + if (strlen($class)) { |
|
| 3603 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3604 | + } |
|
| 3605 | + else { |
|
| 3606 | + $img = vider_attribut($img, 'class'); |
|
| 3607 | + } |
|
| 3608 | + } |
|
| 3609 | + } |
|
| 3610 | + else { |
|
| 3611 | + $img = http_img_pack( |
|
| 3612 | + $img, |
|
| 3613 | + $alt, |
|
| 3614 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3615 | + '', |
|
| 3616 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3617 | + ); |
|
| 3618 | + if (is_null($alt)) { |
|
| 3619 | + $img = vider_attribut($img, 'alt'); |
|
| 3620 | + } |
|
| 3621 | + } |
|
| 3622 | + |
|
| 3623 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3624 | + [$width, $height] = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3625 | + |
|
| 3626 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3627 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3628 | + } |
|
| 3629 | + |
|
| 3630 | + return $img; |
|
| 3631 | 3631 | } |
| 3632 | 3632 | |
| 3633 | 3633 | |
@@ -3661,80 +3661,80 @@ discard block |
||
| 3661 | 3661 | */ |
| 3662 | 3662 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3663 | 3663 | |
| 3664 | - $svg = null; |
|
| 3665 | - $img = trim($img); |
|
| 3666 | - $img_file = $img; |
|
| 3667 | - if (strpos($img, '<svg') === false) { |
|
| 3668 | - if ($p = strpos($img_file, '?')) { |
|
| 3669 | - $img_file = substr($img_file, 0, $p); |
|
| 3670 | - } |
|
| 3671 | - |
|
| 3672 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3673 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3674 | - if (tester_url_absolue($img_file)) { |
|
| 3675 | - include_spip('inc/distant'); |
|
| 3676 | - $fichier = copie_locale($img_file); |
|
| 3677 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3678 | - } |
|
| 3679 | - |
|
| 3680 | - if ( |
|
| 3681 | - !$img_file |
|
| 3682 | - or !file_exists($img_file) |
|
| 3683 | - or !$svg = file_get_contents($img_file) |
|
| 3684 | - ) { |
|
| 3685 | - return ''; |
|
| 3686 | - } |
|
| 3687 | - } |
|
| 3688 | - |
|
| 3689 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3690 | - return ''; |
|
| 3691 | - } |
|
| 3692 | - |
|
| 3693 | - [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3694 | - |
|
| 3695 | - $balise_svg = $match[0]; |
|
| 3696 | - $balise_svg_source = $balise_svg; |
|
| 3697 | - |
|
| 3698 | - // entete XML à supprimer |
|
| 3699 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3700 | - |
|
| 3701 | - // IE est toujours mon ami |
|
| 3702 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3703 | - |
|
| 3704 | - // regler la classe |
|
| 3705 | - if (!is_null($class)) { |
|
| 3706 | - if (strlen($class)) { |
|
| 3707 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3708 | - } |
|
| 3709 | - else { |
|
| 3710 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3711 | - } |
|
| 3712 | - } |
|
| 3713 | - |
|
| 3714 | - // regler le alt |
|
| 3715 | - if ($alt) { |
|
| 3716 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3717 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3718 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3719 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3720 | - $balise_svg .= $title; |
|
| 3721 | - } |
|
| 3722 | - else { |
|
| 3723 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3724 | - } |
|
| 3725 | - |
|
| 3726 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3727 | - |
|
| 3728 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3729 | - [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3730 | - |
|
| 3731 | - if (!function_exists('svg_redimensionner')) { |
|
| 3732 | - include_spip('inc/svg'); |
|
| 3733 | - } |
|
| 3734 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3735 | - } |
|
| 3736 | - |
|
| 3737 | - return $svg; |
|
| 3664 | + $svg = null; |
|
| 3665 | + $img = trim($img); |
|
| 3666 | + $img_file = $img; |
|
| 3667 | + if (strpos($img, '<svg') === false) { |
|
| 3668 | + if ($p = strpos($img_file, '?')) { |
|
| 3669 | + $img_file = substr($img_file, 0, $p); |
|
| 3670 | + } |
|
| 3671 | + |
|
| 3672 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3673 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3674 | + if (tester_url_absolue($img_file)) { |
|
| 3675 | + include_spip('inc/distant'); |
|
| 3676 | + $fichier = copie_locale($img_file); |
|
| 3677 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3678 | + } |
|
| 3679 | + |
|
| 3680 | + if ( |
|
| 3681 | + !$img_file |
|
| 3682 | + or !file_exists($img_file) |
|
| 3683 | + or !$svg = file_get_contents($img_file) |
|
| 3684 | + ) { |
|
| 3685 | + return ''; |
|
| 3686 | + } |
|
| 3687 | + } |
|
| 3688 | + |
|
| 3689 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3690 | + return ''; |
|
| 3691 | + } |
|
| 3692 | + |
|
| 3693 | + [$alt, $class, $size] = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3694 | + |
|
| 3695 | + $balise_svg = $match[0]; |
|
| 3696 | + $balise_svg_source = $balise_svg; |
|
| 3697 | + |
|
| 3698 | + // entete XML à supprimer |
|
| 3699 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3700 | + |
|
| 3701 | + // IE est toujours mon ami |
|
| 3702 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3703 | + |
|
| 3704 | + // regler la classe |
|
| 3705 | + if (!is_null($class)) { |
|
| 3706 | + if (strlen($class)) { |
|
| 3707 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3708 | + } |
|
| 3709 | + else { |
|
| 3710 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3711 | + } |
|
| 3712 | + } |
|
| 3713 | + |
|
| 3714 | + // regler le alt |
|
| 3715 | + if ($alt) { |
|
| 3716 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3717 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3718 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3719 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3720 | + $balise_svg .= $title; |
|
| 3721 | + } |
|
| 3722 | + else { |
|
| 3723 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3724 | + } |
|
| 3725 | + |
|
| 3726 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3727 | + |
|
| 3728 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3729 | + [$width, $height] = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3730 | + |
|
| 3731 | + if (!function_exists('svg_redimensionner')) { |
|
| 3732 | + include_spip('inc/svg'); |
|
| 3733 | + } |
|
| 3734 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3735 | + } |
|
| 3736 | + |
|
| 3737 | + return $svg; |
|
| 3738 | 3738 | } |
| 3739 | 3739 | |
| 3740 | 3740 | |
@@ -3760,18 +3760,18 @@ discard block |
||
| 3760 | 3760 | * Code HTML résultant |
| 3761 | 3761 | **/ |
| 3762 | 3762 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3763 | - $texte = ''; |
|
| 3764 | - if (is_array($tableau)) { |
|
| 3765 | - foreach ($tableau as $k => $v) { |
|
| 3766 | - $res = recuperer_fond( |
|
| 3767 | - 'modeles/' . $modele, |
|
| 3768 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3769 | - ); |
|
| 3770 | - $texte .= $res; |
|
| 3771 | - } |
|
| 3772 | - } |
|
| 3763 | + $texte = ''; |
|
| 3764 | + if (is_array($tableau)) { |
|
| 3765 | + foreach ($tableau as $k => $v) { |
|
| 3766 | + $res = recuperer_fond( |
|
| 3767 | + 'modeles/' . $modele, |
|
| 3768 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3769 | + ); |
|
| 3770 | + $texte .= $res; |
|
| 3771 | + } |
|
| 3772 | + } |
|
| 3773 | 3773 | |
| 3774 | - return $texte; |
|
| 3774 | + return $texte; |
|
| 3775 | 3775 | } |
| 3776 | 3776 | |
| 3777 | 3777 | |
@@ -3796,37 +3796,37 @@ discard block |
||
| 3796 | 3796 | * - tout : retourne toutes les informations du plugin actif |
| 3797 | 3797 | **/ |
| 3798 | 3798 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3799 | - include_spip('inc/plugin'); |
|
| 3800 | - $plugin = strtoupper($plugin); |
|
| 3801 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3802 | - |
|
| 3803 | - if (!$plugin) { |
|
| 3804 | - return serialize(array_keys($plugins_actifs)); |
|
| 3805 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3806 | - return ''; |
|
| 3807 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3808 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3809 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3810 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3811 | - } else { |
|
| 3812 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3813 | - // On prend en compte les extensions |
|
| 3814 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3815 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3816 | - } else { |
|
| 3817 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3818 | - } |
|
| 3819 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3820 | - return ''; |
|
| 3821 | - } |
|
| 3822 | - if ($type_info == 'tout') { |
|
| 3823 | - return $infos; |
|
| 3824 | - } elseif ($type_info == 'est_actif') { |
|
| 3825 | - return $infos ? 1 : 0; |
|
| 3826 | - } else { |
|
| 3827 | - return strval($infos[$type_info]); |
|
| 3828 | - } |
|
| 3829 | - } |
|
| 3799 | + include_spip('inc/plugin'); |
|
| 3800 | + $plugin = strtoupper($plugin); |
|
| 3801 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3802 | + |
|
| 3803 | + if (!$plugin) { |
|
| 3804 | + return serialize(array_keys($plugins_actifs)); |
|
| 3805 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3806 | + return ''; |
|
| 3807 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3808 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3809 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3810 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3811 | + } else { |
|
| 3812 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3813 | + // On prend en compte les extensions |
|
| 3814 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3815 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3816 | + } else { |
|
| 3817 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3818 | + } |
|
| 3819 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3820 | + return ''; |
|
| 3821 | + } |
|
| 3822 | + if ($type_info == 'tout') { |
|
| 3823 | + return $infos; |
|
| 3824 | + } elseif ($type_info == 'est_actif') { |
|
| 3825 | + return $infos ? 1 : 0; |
|
| 3826 | + } else { |
|
| 3827 | + return strval($infos[$type_info]); |
|
| 3828 | + } |
|
| 3829 | + } |
|
| 3830 | 3830 | } |
| 3831 | 3831 | |
| 3832 | 3832 | |
@@ -3853,9 +3853,9 @@ discard block |
||
| 3853 | 3853 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3854 | 3854 | */ |
| 3855 | 3855 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3856 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3856 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3857 | 3857 | |
| 3858 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3858 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3859 | 3859 | } |
| 3860 | 3860 | |
| 3861 | 3861 | |
@@ -3885,19 +3885,19 @@ discard block |
||
| 3885 | 3885 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3886 | 3886 | */ |
| 3887 | 3887 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3888 | - static $puce_statut = null; |
|
| 3889 | - if (!$puce_statut) { |
|
| 3890 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3891 | - } |
|
| 3888 | + static $puce_statut = null; |
|
| 3889 | + if (!$puce_statut) { |
|
| 3890 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3891 | + } |
|
| 3892 | 3892 | |
| 3893 | - return $puce_statut( |
|
| 3894 | - $id_objet, |
|
| 3895 | - $statut, |
|
| 3896 | - $id_parent, |
|
| 3897 | - $objet, |
|
| 3898 | - false, |
|
| 3899 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3900 | - ); |
|
| 3893 | + return $puce_statut( |
|
| 3894 | + $id_objet, |
|
| 3895 | + $statut, |
|
| 3896 | + $id_parent, |
|
| 3897 | + $objet, |
|
| 3898 | + false, |
|
| 3899 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3900 | + ); |
|
| 3901 | 3901 | } |
| 3902 | 3902 | |
| 3903 | 3903 | |
@@ -3924,98 +3924,98 @@ discard block |
||
| 3924 | 3924 | * hash du contexte |
| 3925 | 3925 | */ |
| 3926 | 3926 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3927 | - $env = null; |
|
| 3928 | - if ( |
|
| 3929 | - is_string($c) |
|
| 3930 | - and @unserialize($c) !== false |
|
| 3931 | - ) { |
|
| 3932 | - $c = unserialize($c); |
|
| 3933 | - } |
|
| 3934 | - |
|
| 3935 | - // supprimer les parametres debut_x |
|
| 3936 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3937 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3938 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3939 | - if (is_array($c)) { |
|
| 3940 | - foreach ($c as $k => $v) { |
|
| 3941 | - if (strpos($k, 'debut_') === 0) { |
|
| 3942 | - unset($c[$k]); |
|
| 3943 | - } |
|
| 3944 | - } |
|
| 3945 | - } |
|
| 3946 | - |
|
| 3947 | - if (!function_exists('calculer_cle_action')) { |
|
| 3948 | - include_spip('inc/securiser_action'); |
|
| 3949 | - } |
|
| 3950 | - |
|
| 3951 | - $c = serialize($c); |
|
| 3952 | - $cle = calculer_cle_action($form . $c); |
|
| 3953 | - $c = "$cle:$c"; |
|
| 3954 | - |
|
| 3955 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3956 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3957 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3958 | - // que ce qui est toléré. |
|
| 3959 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3960 | - if (!$cache_contextes_ajax) { |
|
| 3961 | - $env = $c; |
|
| 3962 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3963 | - $env = gzdeflate($env); |
|
| 3964 | - } |
|
| 3965 | - $env = _xor($env); |
|
| 3966 | - $env = base64_encode($env); |
|
| 3967 | - $len = strlen($env); |
|
| 3968 | - // Si l’url est trop longue pour le navigateur |
|
| 3969 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3970 | - if ($len > $max_len) { |
|
| 3971 | - $cache_contextes_ajax = true; |
|
| 3972 | - spip_log( |
|
| 3973 | - 'Contextes AJAX forces en fichiers !' |
|
| 3974 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3975 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3976 | - _LOG_AVERTISSEMENT |
|
| 3977 | - ); |
|
| 3978 | - } |
|
| 3979 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3980 | - elseif ( |
|
| 3981 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3982 | - and $max_len < $len |
|
| 3983 | - ) { |
|
| 3984 | - $cache_contextes_ajax = true; |
|
| 3985 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 3986 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 3987 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3988 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3989 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3990 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3991 | - } |
|
| 3992 | - } |
|
| 3993 | - |
|
| 3994 | - if ($cache_contextes_ajax) { |
|
| 3995 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3996 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3997 | - $md5 = md5($c); |
|
| 3998 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 3999 | - $env = $md5; |
|
| 4000 | - } |
|
| 4001 | - |
|
| 4002 | - if ($emboite === null) { |
|
| 4003 | - return $env; |
|
| 4004 | - } |
|
| 4005 | - if (!trim($emboite)) { |
|
| 4006 | - return ''; |
|
| 4007 | - } |
|
| 4008 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4009 | - $r = self(); |
|
| 4010 | - $r = ' data-origin="' . $r . '"'; |
|
| 4011 | - $class = 'ajaxbloc'; |
|
| 4012 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4013 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4014 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4015 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4016 | - } |
|
| 4017 | - |
|
| 4018 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3927 | + $env = null; |
|
| 3928 | + if ( |
|
| 3929 | + is_string($c) |
|
| 3930 | + and @unserialize($c) !== false |
|
| 3931 | + ) { |
|
| 3932 | + $c = unserialize($c); |
|
| 3933 | + } |
|
| 3934 | + |
|
| 3935 | + // supprimer les parametres debut_x |
|
| 3936 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3937 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3938 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3939 | + if (is_array($c)) { |
|
| 3940 | + foreach ($c as $k => $v) { |
|
| 3941 | + if (strpos($k, 'debut_') === 0) { |
|
| 3942 | + unset($c[$k]); |
|
| 3943 | + } |
|
| 3944 | + } |
|
| 3945 | + } |
|
| 3946 | + |
|
| 3947 | + if (!function_exists('calculer_cle_action')) { |
|
| 3948 | + include_spip('inc/securiser_action'); |
|
| 3949 | + } |
|
| 3950 | + |
|
| 3951 | + $c = serialize($c); |
|
| 3952 | + $cle = calculer_cle_action($form . $c); |
|
| 3953 | + $c = "$cle:$c"; |
|
| 3954 | + |
|
| 3955 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3956 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3957 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3958 | + // que ce qui est toléré. |
|
| 3959 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3960 | + if (!$cache_contextes_ajax) { |
|
| 3961 | + $env = $c; |
|
| 3962 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3963 | + $env = gzdeflate($env); |
|
| 3964 | + } |
|
| 3965 | + $env = _xor($env); |
|
| 3966 | + $env = base64_encode($env); |
|
| 3967 | + $len = strlen($env); |
|
| 3968 | + // Si l’url est trop longue pour le navigateur |
|
| 3969 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 3970 | + if ($len > $max_len) { |
|
| 3971 | + $cache_contextes_ajax = true; |
|
| 3972 | + spip_log( |
|
| 3973 | + 'Contextes AJAX forces en fichiers !' |
|
| 3974 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3975 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 3976 | + _LOG_AVERTISSEMENT |
|
| 3977 | + ); |
|
| 3978 | + } |
|
| 3979 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 3980 | + elseif ( |
|
| 3981 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 3982 | + and $max_len < $len |
|
| 3983 | + ) { |
|
| 3984 | + $cache_contextes_ajax = true; |
|
| 3985 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 3986 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 3987 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 3988 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 3989 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 3990 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 3991 | + } |
|
| 3992 | + } |
|
| 3993 | + |
|
| 3994 | + if ($cache_contextes_ajax) { |
|
| 3995 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 3996 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 3997 | + $md5 = md5($c); |
|
| 3998 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 3999 | + $env = $md5; |
|
| 4000 | + } |
|
| 4001 | + |
|
| 4002 | + if ($emboite === null) { |
|
| 4003 | + return $env; |
|
| 4004 | + } |
|
| 4005 | + if (!trim($emboite)) { |
|
| 4006 | + return ''; |
|
| 4007 | + } |
|
| 4008 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4009 | + $r = self(); |
|
| 4010 | + $r = ' data-origin="' . $r . '"'; |
|
| 4011 | + $class = 'ajaxbloc'; |
|
| 4012 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4013 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4014 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4015 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4016 | + } |
|
| 4017 | + |
|
| 4018 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4019 | 4019 | } |
| 4020 | 4020 | |
| 4021 | 4021 | /** |
@@ -4035,37 +4035,37 @@ discard block |
||
| 4035 | 4035 | * - false : erreur de décodage |
| 4036 | 4036 | */ |
| 4037 | 4037 | function decoder_contexte_ajax($c, $form = '') { |
| 4038 | - if (!function_exists('calculer_cle_action')) { |
|
| 4039 | - include_spip('inc/securiser_action'); |
|
| 4040 | - } |
|
| 4041 | - if ( |
|
| 4042 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4043 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4044 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4045 | - ) { |
|
| 4046 | - $c = $contexte; |
|
| 4047 | - } else { |
|
| 4048 | - $c = @base64_decode($c); |
|
| 4049 | - $c = _xor($c); |
|
| 4050 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4051 | - $c = @gzinflate($c); |
|
| 4052 | - } |
|
| 4053 | - } |
|
| 4054 | - |
|
| 4055 | - // extraire la signature en debut de contexte |
|
| 4056 | - // et la verifier avant de deserializer |
|
| 4057 | - // format : signature:donneesserializees |
|
| 4058 | - if ($p = strpos($c, ':')) { |
|
| 4059 | - $cle = substr($c, 0, $p); |
|
| 4060 | - $c = substr($c, $p + 1); |
|
| 4061 | - |
|
| 4062 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4063 | - $env = @unserialize($c); |
|
| 4064 | - return $env; |
|
| 4065 | - } |
|
| 4066 | - } |
|
| 4067 | - |
|
| 4068 | - return false; |
|
| 4038 | + if (!function_exists('calculer_cle_action')) { |
|
| 4039 | + include_spip('inc/securiser_action'); |
|
| 4040 | + } |
|
| 4041 | + if ( |
|
| 4042 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4043 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4044 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4045 | + ) { |
|
| 4046 | + $c = $contexte; |
|
| 4047 | + } else { |
|
| 4048 | + $c = @base64_decode($c); |
|
| 4049 | + $c = _xor($c); |
|
| 4050 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4051 | + $c = @gzinflate($c); |
|
| 4052 | + } |
|
| 4053 | + } |
|
| 4054 | + |
|
| 4055 | + // extraire la signature en debut de contexte |
|
| 4056 | + // et la verifier avant de deserializer |
|
| 4057 | + // format : signature:donneesserializees |
|
| 4058 | + if ($p = strpos($c, ':')) { |
|
| 4059 | + $cle = substr($c, 0, $p); |
|
| 4060 | + $c = substr($c, $p + 1); |
|
| 4061 | + |
|
| 4062 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4063 | + $env = @unserialize($c); |
|
| 4064 | + return $env; |
|
| 4065 | + } |
|
| 4066 | + } |
|
| 4067 | + |
|
| 4068 | + return false; |
|
| 4069 | 4069 | } |
| 4070 | 4070 | |
| 4071 | 4071 | |
@@ -4083,20 +4083,20 @@ discard block |
||
| 4083 | 4083 | * Message décrypté ou encrypté |
| 4084 | 4084 | **/ |
| 4085 | 4085 | function _xor($message, $key = null) { |
| 4086 | - if (is_null($key)) { |
|
| 4087 | - if (!function_exists('calculer_cle_action')) { |
|
| 4088 | - include_spip('inc/securiser_action'); |
|
| 4089 | - } |
|
| 4090 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4091 | - } |
|
| 4086 | + if (is_null($key)) { |
|
| 4087 | + if (!function_exists('calculer_cle_action')) { |
|
| 4088 | + include_spip('inc/securiser_action'); |
|
| 4089 | + } |
|
| 4090 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4091 | + } |
|
| 4092 | 4092 | |
| 4093 | - $keylen = strlen($key); |
|
| 4094 | - $messagelen = strlen($message); |
|
| 4095 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4096 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4097 | - } |
|
| 4093 | + $keylen = strlen($key); |
|
| 4094 | + $messagelen = strlen($message); |
|
| 4095 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4096 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4097 | + } |
|
| 4098 | 4098 | |
| 4099 | - return $message; |
|
| 4099 | + return $message; |
|
| 4100 | 4100 | } |
| 4101 | 4101 | |
| 4102 | 4102 | /** |
@@ -4110,7 +4110,7 @@ discard block |
||
| 4110 | 4110 | * @return string |
| 4111 | 4111 | */ |
| 4112 | 4112 | function url_reponse_forum($texte) { |
| 4113 | - return $texte; |
|
| 4113 | + return $texte; |
|
| 4114 | 4114 | } |
| 4115 | 4115 | |
| 4116 | 4116 | /** |
@@ -4124,7 +4124,7 @@ discard block |
||
| 4124 | 4124 | * @return string |
| 4125 | 4125 | */ |
| 4126 | 4126 | function url_rss_forum($texte) { |
| 4127 | - return $texte; |
|
| 4127 | + return $texte; |
|
| 4128 | 4128 | } |
| 4129 | 4129 | |
| 4130 | 4130 | |
@@ -4163,37 +4163,37 @@ discard block |
||
| 4163 | 4163 | * Code HTML |
| 4164 | 4164 | */ |
| 4165 | 4165 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4166 | - if ($on) { |
|
| 4167 | - $bal = 'strong'; |
|
| 4168 | - $class = ''; |
|
| 4169 | - $att = ''; |
|
| 4170 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4171 | - // a.active span.selected.active etc.... |
|
| 4172 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4173 | - $on = explode('.', $on); |
|
| 4174 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4175 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4176 | - $bal = array_shift($on); |
|
| 4177 | - $class = implode(' ', $on); |
|
| 4178 | - if ($bal == 'a') { |
|
| 4179 | - $att = 'href="#" '; |
|
| 4180 | - } |
|
| 4181 | - } |
|
| 4182 | - } |
|
| 4183 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4184 | - } else { |
|
| 4185 | - $bal = 'a'; |
|
| 4186 | - $att = "href='$url'" |
|
| 4187 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4188 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4189 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4190 | - . $evt; |
|
| 4191 | - } |
|
| 4192 | - if ($libelle === null) { |
|
| 4193 | - $libelle = $url; |
|
| 4194 | - } |
|
| 4195 | - |
|
| 4196 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4166 | + if ($on) { |
|
| 4167 | + $bal = 'strong'; |
|
| 4168 | + $class = ''; |
|
| 4169 | + $att = ''; |
|
| 4170 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4171 | + // a.active span.selected.active etc.... |
|
| 4172 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4173 | + $on = explode('.', $on); |
|
| 4174 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4175 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4176 | + $bal = array_shift($on); |
|
| 4177 | + $class = implode(' ', $on); |
|
| 4178 | + if ($bal == 'a') { |
|
| 4179 | + $att = 'href="#" '; |
|
| 4180 | + } |
|
| 4181 | + } |
|
| 4182 | + } |
|
| 4183 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4184 | + } else { |
|
| 4185 | + $bal = 'a'; |
|
| 4186 | + $att = "href='$url'" |
|
| 4187 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4188 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4189 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4190 | + . $evt; |
|
| 4191 | + } |
|
| 4192 | + if ($libelle === null) { |
|
| 4193 | + $libelle = $url; |
|
| 4194 | + } |
|
| 4195 | + |
|
| 4196 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4197 | 4197 | } |
| 4198 | 4198 | |
| 4199 | 4199 | |
@@ -4210,39 +4210,39 @@ discard block |
||
| 4210 | 4210 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4211 | 4211 | */ |
| 4212 | 4212 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4213 | - static $local_singulier_ou_pluriel = []; |
|
| 4214 | - |
|
| 4215 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4216 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4217 | - return ''; |
|
| 4218 | - } |
|
| 4219 | - if (!is_array($vars)) { |
|
| 4220 | - return ''; |
|
| 4221 | - } |
|
| 4222 | - |
|
| 4223 | - $langue = $GLOBALS['spip_lang']; |
|
| 4224 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4225 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4226 | - if ( |
|
| 4227 | - $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4228 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4229 | - ) { |
|
| 4230 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4231 | - } |
|
| 4232 | - } |
|
| 4233 | - |
|
| 4234 | - // si on a une surcharge on l'utilise |
|
| 4235 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4236 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4237 | - } |
|
| 4238 | - |
|
| 4239 | - // sinon traitement par defaut |
|
| 4240 | - $vars[$var] = $nb; |
|
| 4241 | - if ($nb >= 2) { |
|
| 4242 | - return _T($chaine_plusieurs, $vars); |
|
| 4243 | - } else { |
|
| 4244 | - return _T($chaine_un, $vars); |
|
| 4245 | - } |
|
| 4213 | + static $local_singulier_ou_pluriel = []; |
|
| 4214 | + |
|
| 4215 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4216 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4217 | + return ''; |
|
| 4218 | + } |
|
| 4219 | + if (!is_array($vars)) { |
|
| 4220 | + return ''; |
|
| 4221 | + } |
|
| 4222 | + |
|
| 4223 | + $langue = $GLOBALS['spip_lang']; |
|
| 4224 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4225 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4226 | + if ( |
|
| 4227 | + $f = charger_fonction("singulier_ou_pluriel_{$langue}", 'inc', true) |
|
| 4228 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4229 | + ) { |
|
| 4230 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4231 | + } |
|
| 4232 | + } |
|
| 4233 | + |
|
| 4234 | + // si on a une surcharge on l'utilise |
|
| 4235 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4236 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4237 | + } |
|
| 4238 | + |
|
| 4239 | + // sinon traitement par defaut |
|
| 4240 | + $vars[$var] = $nb; |
|
| 4241 | + if ($nb >= 2) { |
|
| 4242 | + return _T($chaine_plusieurs, $vars); |
|
| 4243 | + } else { |
|
| 4244 | + return _T($chaine_un, $vars); |
|
| 4245 | + } |
|
| 4246 | 4246 | } |
| 4247 | 4247 | |
| 4248 | 4248 | |
@@ -4270,73 +4270,73 @@ discard block |
||
| 4270 | 4270 | */ |
| 4271 | 4271 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4272 | 4272 | |
| 4273 | - $class_lien = $class_bouton = $class; |
|
| 4274 | - |
|
| 4275 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4276 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4277 | - $class_lien .= ' danger'; |
|
| 4278 | - $class_bouton .= ' btn_danger'; |
|
| 4279 | - } elseif ($fonction == 'rien.gif') { |
|
| 4280 | - $fonction = ''; |
|
| 4281 | - } elseif ($fonction == 'delsafe') { |
|
| 4282 | - $fonction = 'del'; |
|
| 4283 | - } |
|
| 4284 | - |
|
| 4285 | - $fond_origine = $fond; |
|
| 4286 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4287 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4288 | - [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4289 | - } |
|
| 4290 | - |
|
| 4291 | - // Ajouter le type d'objet dans la classe |
|
| 4292 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4293 | - $class_lien .= " $objet_type"; |
|
| 4294 | - $class_bouton .= " $objet_type"; |
|
| 4295 | - |
|
| 4296 | - // texte |
|
| 4297 | - $alt = attribut_html($texte); |
|
| 4298 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4299 | - |
|
| 4300 | - // Liens : préparer les classes ajax |
|
| 4301 | - $ajax = ''; |
|
| 4302 | - if ($type === 'lien') { |
|
| 4303 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4304 | - $ajax = 'ajax'; |
|
| 4305 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4306 | - $ajax .= ' preload'; |
|
| 4307 | - } |
|
| 4308 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4309 | - $ajax .= ' nocache'; |
|
| 4310 | - } |
|
| 4311 | - $ajax = " class='$ajax'"; |
|
| 4312 | - } |
|
| 4313 | - } |
|
| 4314 | - |
|
| 4315 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4316 | - $size = 24; |
|
| 4317 | - if ( |
|
| 4318 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4319 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4320 | - ) { |
|
| 4321 | - $size = $match[1]; |
|
| 4322 | - } |
|
| 4323 | - $class_lien .= " s$size"; |
|
| 4324 | - $class_bouton .= " s$size"; |
|
| 4325 | - |
|
| 4326 | - // Icône |
|
| 4327 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4328 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4329 | - |
|
| 4330 | - // Markup final |
|
| 4331 | - if ($type == 'lien') { |
|
| 4332 | - return "<span class='icone $class_lien'>" |
|
| 4333 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4334 | - . $icone |
|
| 4335 | - . "<b>$texte</b>" |
|
| 4336 | - . "</a></span>\n"; |
|
| 4337 | - } else { |
|
| 4338 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4339 | - } |
|
| 4273 | + $class_lien = $class_bouton = $class; |
|
| 4274 | + |
|
| 4275 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4276 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4277 | + $class_lien .= ' danger'; |
|
| 4278 | + $class_bouton .= ' btn_danger'; |
|
| 4279 | + } elseif ($fonction == 'rien.gif') { |
|
| 4280 | + $fonction = ''; |
|
| 4281 | + } elseif ($fonction == 'delsafe') { |
|
| 4282 | + $fonction = 'del'; |
|
| 4283 | + } |
|
| 4284 | + |
|
| 4285 | + $fond_origine = $fond; |
|
| 4286 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4287 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4288 | + [$fond, $fonction] = $icone_renommer($fond, $fonction); |
|
| 4289 | + } |
|
| 4290 | + |
|
| 4291 | + // Ajouter le type d'objet dans la classe |
|
| 4292 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4293 | + $class_lien .= " $objet_type"; |
|
| 4294 | + $class_bouton .= " $objet_type"; |
|
| 4295 | + |
|
| 4296 | + // texte |
|
| 4297 | + $alt = attribut_html($texte); |
|
| 4298 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4299 | + |
|
| 4300 | + // Liens : préparer les classes ajax |
|
| 4301 | + $ajax = ''; |
|
| 4302 | + if ($type === 'lien') { |
|
| 4303 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4304 | + $ajax = 'ajax'; |
|
| 4305 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4306 | + $ajax .= ' preload'; |
|
| 4307 | + } |
|
| 4308 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4309 | + $ajax .= ' nocache'; |
|
| 4310 | + } |
|
| 4311 | + $ajax = " class='$ajax'"; |
|
| 4312 | + } |
|
| 4313 | + } |
|
| 4314 | + |
|
| 4315 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4316 | + $size = 24; |
|
| 4317 | + if ( |
|
| 4318 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4319 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4320 | + ) { |
|
| 4321 | + $size = $match[1]; |
|
| 4322 | + } |
|
| 4323 | + $class_lien .= " s$size"; |
|
| 4324 | + $class_bouton .= " s$size"; |
|
| 4325 | + |
|
| 4326 | + // Icône |
|
| 4327 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4328 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4329 | + |
|
| 4330 | + // Markup final |
|
| 4331 | + if ($type == 'lien') { |
|
| 4332 | + return "<span class='icone $class_lien'>" |
|
| 4333 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4334 | + . $icone |
|
| 4335 | + . "<b>$texte</b>" |
|
| 4336 | + . "</a></span>\n"; |
|
| 4337 | + } else { |
|
| 4338 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4339 | + } |
|
| 4340 | 4340 | } |
| 4341 | 4341 | |
| 4342 | 4342 | /** |
@@ -4360,7 +4360,7 @@ discard block |
||
| 4360 | 4360 | * Code HTML du lien |
| 4361 | 4361 | **/ |
| 4362 | 4362 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4363 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4363 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4364 | 4364 | } |
| 4365 | 4365 | |
| 4366 | 4366 | /** |
@@ -4395,7 +4395,7 @@ discard block |
||
| 4395 | 4395 | * Code HTML du lien |
| 4396 | 4396 | **/ |
| 4397 | 4397 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4398 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4398 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4399 | 4399 | } |
| 4400 | 4400 | |
| 4401 | 4401 | /** |
@@ -4440,7 +4440,7 @@ discard block |
||
| 4440 | 4440 | * Code HTML du lien |
| 4441 | 4441 | **/ |
| 4442 | 4442 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4443 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4443 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4444 | 4444 | } |
| 4445 | 4445 | |
| 4446 | 4446 | /** |
@@ -4471,7 +4471,7 @@ discard block |
||
| 4471 | 4471 | * Code HTML du lien |
| 4472 | 4472 | **/ |
| 4473 | 4473 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4474 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4474 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4475 | 4475 | } |
| 4476 | 4476 | |
| 4477 | 4477 | /** |
@@ -4502,7 +4502,7 @@ discard block |
||
| 4502 | 4502 | * Code HTML du lien |
| 4503 | 4503 | */ |
| 4504 | 4504 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4505 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4505 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4506 | 4506 | } |
| 4507 | 4507 | |
| 4508 | 4508 | |
@@ -4524,7 +4524,7 @@ discard block |
||
| 4524 | 4524 | * @return array Liste des éléments |
| 4525 | 4525 | */ |
| 4526 | 4526 | function filtre_explode_dist($a, $b) { |
| 4527 | - return explode($b, (string) $a); |
|
| 4527 | + return explode($b, (string) $a); |
|
| 4528 | 4528 | } |
| 4529 | 4529 | |
| 4530 | 4530 | /** |
@@ -4545,7 +4545,7 @@ discard block |
||
| 4545 | 4545 | * @return string texte |
| 4546 | 4546 | */ |
| 4547 | 4547 | function filtre_implode_dist($a, $b) { |
| 4548 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4548 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4549 | 4549 | } |
| 4550 | 4550 | |
| 4551 | 4551 | /** |
@@ -4554,22 +4554,22 @@ discard block |
||
| 4554 | 4554 | * @return string Code CSS |
| 4555 | 4555 | */ |
| 4556 | 4556 | function bando_images_background() { |
| 4557 | - include_spip('inc/bandeau'); |
|
| 4558 | - // recuperer tous les boutons et leurs images |
|
| 4559 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4557 | + include_spip('inc/bandeau'); |
|
| 4558 | + // recuperer tous les boutons et leurs images |
|
| 4559 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4560 | 4560 | |
| 4561 | - $res = ''; |
|
| 4562 | - foreach ($boutons as $page => $detail) { |
|
| 4563 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4564 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4565 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4566 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4567 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4568 | - } |
|
| 4569 | - } |
|
| 4570 | - } |
|
| 4561 | + $res = ''; |
|
| 4562 | + foreach ($boutons as $page => $detail) { |
|
| 4563 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4564 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4565 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4566 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4567 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4568 | + } |
|
| 4569 | + } |
|
| 4570 | + } |
|
| 4571 | 4571 | |
| 4572 | - return $res; |
|
| 4572 | + return $res; |
|
| 4573 | 4573 | } |
| 4574 | 4574 | |
| 4575 | 4575 | /** |
@@ -4594,27 +4594,27 @@ discard block |
||
| 4594 | 4594 | */ |
| 4595 | 4595 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4596 | 4596 | |
| 4597 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4598 | - $class_form = ''; |
|
| 4599 | - if (strpos($class, 'ajax') !== false) { |
|
| 4600 | - $class_form = 'ajax'; |
|
| 4601 | - $class = str_replace('ajax', '', $class); |
|
| 4602 | - } |
|
| 4603 | - $class_btn = 'submit ' . trim($class); |
|
| 4597 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4598 | + $class_form = ''; |
|
| 4599 | + if (strpos($class, 'ajax') !== false) { |
|
| 4600 | + $class_form = 'ajax'; |
|
| 4601 | + $class = str_replace('ajax', '', $class); |
|
| 4602 | + } |
|
| 4603 | + $class_btn = 'submit ' . trim($class); |
|
| 4604 | 4604 | |
| 4605 | - if ($confirm) { |
|
| 4606 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4607 | - if ($callback) { |
|
| 4608 | - $callback = "$confirm?($callback):false"; |
|
| 4609 | - } else { |
|
| 4610 | - $callback = $confirm; |
|
| 4611 | - } |
|
| 4612 | - } |
|
| 4613 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4614 | - $title = $title ? " title='$title'" : ''; |
|
| 4605 | + if ($confirm) { |
|
| 4606 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4607 | + if ($callback) { |
|
| 4608 | + $callback = "$confirm?($callback):false"; |
|
| 4609 | + } else { |
|
| 4610 | + $callback = $confirm; |
|
| 4611 | + } |
|
| 4612 | + } |
|
| 4613 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4614 | + $title = $title ? " title='$title'" : ''; |
|
| 4615 | 4615 | |
| 4616 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4617 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4616 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4617 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4618 | 4618 | } |
| 4619 | 4619 | |
| 4620 | 4620 | /** |
@@ -4637,101 +4637,101 @@ discard block |
||
| 4637 | 4637 | * @return string |
| 4638 | 4638 | */ |
| 4639 | 4639 | function generer_objet_info($id_objet, string $type_objet, string $info, string $etoile = '', array $params = []): string { |
| 4640 | - static $trouver_table = null; |
|
| 4641 | - static $objets; |
|
| 4642 | - |
|
| 4643 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4644 | - $id_objet = intval($id_objet); |
|
| 4645 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4646 | - return ''; |
|
| 4647 | - } |
|
| 4648 | - |
|
| 4649 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4650 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4651 | - return ''; |
|
| 4652 | - } |
|
| 4653 | - |
|
| 4654 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4655 | - if ($info == 'url') { |
|
| 4656 | - return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4657 | - } |
|
| 4658 | - |
|
| 4659 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4660 | - $demande_titre = ($info === 'titre'); |
|
| 4661 | - $demande_introduction = ($info === 'introduction'); |
|
| 4662 | - |
|
| 4663 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4664 | - if ( |
|
| 4665 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4666 | - or |
|
| 4667 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4668 | - ) { |
|
| 4669 | - if (!$trouver_table) { |
|
| 4670 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4671 | - } |
|
| 4672 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4673 | - if (!$desc) { |
|
| 4674 | - return $objets[$type_objet] = false; |
|
| 4675 | - } |
|
| 4676 | - |
|
| 4677 | - // Si on demande le titre, on le gere en interne |
|
| 4678 | - $champ_titre = ''; |
|
| 4679 | - if ($demande_titre) { |
|
| 4680 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4681 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4682 | - } |
|
| 4683 | - include_spip('base/abstract_sql'); |
|
| 4684 | - include_spip('base/connect_sql'); |
|
| 4685 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4686 | - '*' . $champ_titre, |
|
| 4687 | - $desc['table_sql'], |
|
| 4688 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4689 | - ); |
|
| 4690 | - |
|
| 4691 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4692 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4693 | - } |
|
| 4694 | - |
|
| 4695 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4696 | - // ajouter la longueur au début des params supplémentaires |
|
| 4697 | - if ($demande_introduction) { |
|
| 4698 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4699 | - array_unshift($params, $introduction_longueur); |
|
| 4700 | - } |
|
| 4701 | - |
|
| 4702 | - // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4703 | - if ( |
|
| 4704 | - $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4705 | - // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4706 | - or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4707 | - ) { |
|
| 4708 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4709 | - } |
|
| 4710 | - // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4711 | - elseif ( |
|
| 4712 | - $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4713 | - // @deprecated 4.1 generer_TRUC_entite |
|
| 4714 | - or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4715 | - ) { |
|
| 4716 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4717 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4718 | - else { |
|
| 4719 | - $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4720 | - } |
|
| 4721 | - |
|
| 4722 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4723 | - if (!$etoile) { |
|
| 4724 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4725 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4726 | - $info_generee = appliquer_traitement_champ( |
|
| 4727 | - $info_generee, |
|
| 4728 | - $info, |
|
| 4729 | - table_objet($type_objet), |
|
| 4730 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4731 | - ); |
|
| 4732 | - } |
|
| 4733 | - |
|
| 4734 | - return $info_generee; |
|
| 4640 | + static $trouver_table = null; |
|
| 4641 | + static $objets; |
|
| 4642 | + |
|
| 4643 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4644 | + $id_objet = intval($id_objet); |
|
| 4645 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4646 | + return ''; |
|
| 4647 | + } |
|
| 4648 | + |
|
| 4649 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4650 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4651 | + return ''; |
|
| 4652 | + } |
|
| 4653 | + |
|
| 4654 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4655 | + if ($info == 'url') { |
|
| 4656 | + return generer_objet_url($id_objet, $type_objet, ...$params); |
|
| 4657 | + } |
|
| 4658 | + |
|
| 4659 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4660 | + $demande_titre = ($info === 'titre'); |
|
| 4661 | + $demande_introduction = ($info === 'introduction'); |
|
| 4662 | + |
|
| 4663 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4664 | + if ( |
|
| 4665 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4666 | + or |
|
| 4667 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4668 | + ) { |
|
| 4669 | + if (!$trouver_table) { |
|
| 4670 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4671 | + } |
|
| 4672 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4673 | + if (!$desc) { |
|
| 4674 | + return $objets[$type_objet] = false; |
|
| 4675 | + } |
|
| 4676 | + |
|
| 4677 | + // Si on demande le titre, on le gere en interne |
|
| 4678 | + $champ_titre = ''; |
|
| 4679 | + if ($demande_titre) { |
|
| 4680 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4681 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4682 | + } |
|
| 4683 | + include_spip('base/abstract_sql'); |
|
| 4684 | + include_spip('base/connect_sql'); |
|
| 4685 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4686 | + '*' . $champ_titre, |
|
| 4687 | + $desc['table_sql'], |
|
| 4688 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4689 | + ); |
|
| 4690 | + |
|
| 4691 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4692 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4693 | + } |
|
| 4694 | + |
|
| 4695 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4696 | + // ajouter la longueur au début des params supplémentaires |
|
| 4697 | + if ($demande_introduction) { |
|
| 4698 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4699 | + array_unshift($params, $introduction_longueur); |
|
| 4700 | + } |
|
| 4701 | + |
|
| 4702 | + // Si la fonction generer_TYPE_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4703 | + if ( |
|
| 4704 | + $generer = charger_fonction("generer_{$type_objet}_{$info}", '', true) |
|
| 4705 | + // @deprecated 4.1 generer_TRUC_TYPE |
|
| 4706 | + or $generer = charger_fonction("generer_{$info}_{$type_objet}", '', true) |
|
| 4707 | + ) { |
|
| 4708 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4709 | + } |
|
| 4710 | + // Si la fonction generer_objet_TRUC existe, on l'utilise pour formater $info_generee |
|
| 4711 | + elseif ( |
|
| 4712 | + $generer = charger_fonction("generer_objet_{$info}", '', true) |
|
| 4713 | + // @deprecated 4.1 generer_TRUC_entite |
|
| 4714 | + or $generer = charger_fonction("generer_{$info}_entite", '', true) |
|
| 4715 | + ) { |
|
| 4716 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4717 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4718 | + else { |
|
| 4719 | + $info_generee = ($objets[$type_objet][$id_objet][$info] ?? ''); |
|
| 4720 | + } |
|
| 4721 | + |
|
| 4722 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4723 | + if (!$etoile) { |
|
| 4724 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4725 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4726 | + $info_generee = appliquer_traitement_champ( |
|
| 4727 | + $info_generee, |
|
| 4728 | + $info, |
|
| 4729 | + table_objet($type_objet), |
|
| 4730 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4731 | + ); |
|
| 4732 | + } |
|
| 4733 | + |
|
| 4734 | + return $info_generee; |
|
| 4735 | 4735 | } |
| 4736 | 4736 | |
| 4737 | 4737 | /** |
@@ -4739,7 +4739,7 @@ discard block |
||
| 4739 | 4739 | * @see generer_objet_info |
| 4740 | 4740 | */ |
| 4741 | 4741 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4742 | - return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4742 | + return generer_objet_info(intval($id_objet), $type_objet, $info, $etoile, $params); |
|
| 4743 | 4743 | } |
| 4744 | 4744 | |
| 4745 | 4745 | /** |
@@ -4772,36 +4772,36 @@ discard block |
||
| 4772 | 4772 | */ |
| 4773 | 4773 | function generer_objet_introduction(int $id_objet, string $type_objet, array $ligne_sql, ?int $introduction_longueur = null, $longueur_ou_suite = null, ?string $suite = null, string $connect = ''): string { |
| 4774 | 4774 | |
| 4775 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4776 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4777 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4778 | - if (isset($ligne_sql['chapo'])) { |
|
| 4779 | - $chapo = $ligne_sql['chapo']; |
|
| 4780 | - $texte = strlen($descriptif) ? |
|
| 4781 | - '' : |
|
| 4782 | - "$chapo \n\n $texte"; |
|
| 4783 | - } |
|
| 4775 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4776 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4777 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4778 | + if (isset($ligne_sql['chapo'])) { |
|
| 4779 | + $chapo = $ligne_sql['chapo']; |
|
| 4780 | + $texte = strlen($descriptif) ? |
|
| 4781 | + '' : |
|
| 4782 | + "$chapo \n\n $texte"; |
|
| 4783 | + } |
|
| 4784 | 4784 | |
| 4785 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4786 | - if (!intval($longueur_ou_suite)) { |
|
| 4787 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4788 | - } else { |
|
| 4789 | - $longueur = intval($longueur_ou_suite); |
|
| 4790 | - } |
|
| 4785 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4786 | + if (!intval($longueur_ou_suite)) { |
|
| 4787 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4788 | + } else { |
|
| 4789 | + $longueur = intval($longueur_ou_suite); |
|
| 4790 | + } |
|
| 4791 | 4791 | |
| 4792 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4793 | - // Ex : #INTRODUCTION{...} |
|
| 4794 | - if ( |
|
| 4795 | - is_null($suite) |
|
| 4796 | - and !intval($longueur_ou_suite) |
|
| 4797 | - ) { |
|
| 4798 | - $suite = $longueur_ou_suite; |
|
| 4799 | - } |
|
| 4792 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4793 | + // Ex : #INTRODUCTION{...} |
|
| 4794 | + if ( |
|
| 4795 | + is_null($suite) |
|
| 4796 | + and !intval($longueur_ou_suite) |
|
| 4797 | + ) { |
|
| 4798 | + $suite = $longueur_ou_suite; |
|
| 4799 | + } |
|
| 4800 | 4800 | |
| 4801 | - $f = chercher_filtre('introduction'); |
|
| 4802 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4801 | + $f = chercher_filtre('introduction'); |
|
| 4802 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4803 | 4803 | |
| 4804 | - return $introduction; |
|
| 4804 | + return $introduction; |
|
| 4805 | 4805 | } |
| 4806 | 4806 | |
| 4807 | 4807 | /** |
@@ -4809,7 +4809,7 @@ discard block |
||
| 4809 | 4809 | * @see generer_objet_introduction |
| 4810 | 4810 | */ |
| 4811 | 4811 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, string $connect = '') { |
| 4812 | - return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4812 | + return generer_objet_introduction(intval($id_objet), $type_objet, $ligne_sql, $introduction_longueur, $longueur_ou_suite, $suite, $connect); |
|
| 4813 | 4813 | } |
| 4814 | 4814 | |
| 4815 | 4815 | /** |
@@ -4823,49 +4823,49 @@ discard block |
||
| 4823 | 4823 | * @return string |
| 4824 | 4824 | */ |
| 4825 | 4825 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], string $connect = '') { |
| 4826 | - if (!$champ) { |
|
| 4827 | - return $texte; |
|
| 4828 | - } |
|
| 4826 | + if (!$champ) { |
|
| 4827 | + return $texte; |
|
| 4828 | + } |
|
| 4829 | 4829 | |
| 4830 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4831 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4832 | - include_fichiers_fonctions(); |
|
| 4830 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4831 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4832 | + include_fichiers_fonctions(); |
|
| 4833 | 4833 | |
| 4834 | - $champ = strtoupper($champ); |
|
| 4835 | - $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4836 | - if (!$traitements or !is_array($traitements)) { |
|
| 4837 | - return $texte; |
|
| 4838 | - } |
|
| 4834 | + $champ = strtoupper($champ); |
|
| 4835 | + $traitements = $GLOBALS['table_des_traitements'][$champ] ?? false; |
|
| 4836 | + if (!$traitements or !is_array($traitements)) { |
|
| 4837 | + return $texte; |
|
| 4838 | + } |
|
| 4839 | 4839 | |
| 4840 | - $traitement = ''; |
|
| 4841 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4842 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4843 | - $table_objet = table_objet($table_objet); |
|
| 4844 | - if (isset($traitements[$table_objet])) { |
|
| 4845 | - $traitement = $traitements[$table_objet]; |
|
| 4846 | - } |
|
| 4847 | - } |
|
| 4848 | - if (!$traitement and isset($traitements[0])) { |
|
| 4849 | - $traitement = $traitements[0]; |
|
| 4850 | - } |
|
| 4851 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4840 | + $traitement = ''; |
|
| 4841 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4842 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4843 | + $table_objet = table_objet($table_objet); |
|
| 4844 | + if (isset($traitements[$table_objet])) { |
|
| 4845 | + $traitement = $traitements[$table_objet]; |
|
| 4846 | + } |
|
| 4847 | + } |
|
| 4848 | + if (!$traitement and isset($traitements[0])) { |
|
| 4849 | + $traitement = $traitements[0]; |
|
| 4850 | + } |
|
| 4851 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4852 | 4852 | |
| 4853 | - if (!$traitement) { |
|
| 4854 | - return $texte; |
|
| 4855 | - } |
|
| 4853 | + if (!$traitement) { |
|
| 4854 | + return $texte; |
|
| 4855 | + } |
|
| 4856 | 4856 | |
| 4857 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4857 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4858 | 4858 | |
| 4859 | - // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4860 | - if (test_espace_prive()) { |
|
| 4861 | - $env['espace_prive'] = 1; |
|
| 4862 | - } |
|
| 4859 | + // signaler qu'on est dans l'espace prive pour les filtres qui se servent de ce flag |
|
| 4860 | + if (test_espace_prive()) { |
|
| 4861 | + $env['espace_prive'] = 1; |
|
| 4862 | + } |
|
| 4863 | 4863 | |
| 4864 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4865 | - $Pile = [0 => $env]; |
|
| 4866 | - eval("\$texte = $traitement;"); |
|
| 4864 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4865 | + $Pile = [0 => $env]; |
|
| 4866 | + eval("\$texte = $traitement;"); |
|
| 4867 | 4867 | |
| 4868 | - return $texte; |
|
| 4868 | + return $texte; |
|
| 4869 | 4869 | } |
| 4870 | 4870 | |
| 4871 | 4871 | |
@@ -4879,21 +4879,21 @@ discard block |
||
| 4879 | 4879 | * @return string |
| 4880 | 4880 | */ |
| 4881 | 4881 | function generer_objet_lien(int $id_objet, string $objet, int $longueur = 80, string $connect = ''): string { |
| 4882 | - include_spip('inc/liens'); |
|
| 4883 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4884 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4885 | - // le raccourcis n'est plus valide |
|
| 4886 | - $titre = typo($titre['titre'] ?? ''); |
|
| 4887 | - // on essaye avec generer_info_entite ? |
|
| 4888 | - if (!strlen($titre) and !$connect) { |
|
| 4889 | - $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4890 | - } |
|
| 4891 | - if (!strlen($titre)) { |
|
| 4892 | - $titre = _T('info_sans_titre'); |
|
| 4893 | - } |
|
| 4894 | - $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4882 | + include_spip('inc/liens'); |
|
| 4883 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4884 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4885 | + // le raccourcis n'est plus valide |
|
| 4886 | + $titre = typo($titre['titre'] ?? ''); |
|
| 4887 | + // on essaye avec generer_info_entite ? |
|
| 4888 | + if (!strlen($titre) and !$connect) { |
|
| 4889 | + $titre = generer_objet_info($id_objet, $objet, 'titre'); |
|
| 4890 | + } |
|
| 4891 | + if (!strlen($titre)) { |
|
| 4892 | + $titre = _T('info_sans_titre'); |
|
| 4893 | + } |
|
| 4894 | + $url = generer_objet_url($id_objet, $objet, '', '', null, '', $connect); |
|
| 4895 | 4895 | |
| 4896 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4896 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4897 | 4897 | } |
| 4898 | 4898 | |
| 4899 | 4899 | /** |
@@ -4901,7 +4901,7 @@ discard block |
||
| 4901 | 4901 | * @see generer_objet_lien |
| 4902 | 4902 | */ |
| 4903 | 4903 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4904 | - return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4904 | + return generer_objet_lien(intval($id_objet), $objet, $longueur, $connect ?? ''); |
|
| 4905 | 4905 | } |
| 4906 | 4906 | |
| 4907 | 4907 | /** |
@@ -4917,15 +4917,15 @@ discard block |
||
| 4917 | 4917 | * @return string |
| 4918 | 4918 | */ |
| 4919 | 4919 | function wrap($texte, $wrap) { |
| 4920 | - $balises = extraire_balises($wrap); |
|
| 4921 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4922 | - $texte = $wrap . $texte; |
|
| 4923 | - $regs = array_reverse($regs[1]); |
|
| 4924 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4925 | - $texte = $texte . $wrap; |
|
| 4926 | - } |
|
| 4920 | + $balises = extraire_balises($wrap); |
|
| 4921 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4922 | + $texte = $wrap . $texte; |
|
| 4923 | + $regs = array_reverse($regs[1]); |
|
| 4924 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4925 | + $texte = $texte . $wrap; |
|
| 4926 | + } |
|
| 4927 | 4927 | |
| 4928 | - return $texte; |
|
| 4928 | + return $texte; |
|
| 4929 | 4929 | } |
| 4930 | 4930 | |
| 4931 | 4931 | |
@@ -4945,44 +4945,44 @@ discard block |
||
| 4945 | 4945 | * @return array|mixed|string |
| 4946 | 4946 | */ |
| 4947 | 4947 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4948 | - if (is_string($u)) { |
|
| 4949 | - $u = typo($u); |
|
| 4948 | + if (is_string($u)) { |
|
| 4949 | + $u = typo($u); |
|
| 4950 | 4950 | |
| 4951 | - return $u; |
|
| 4952 | - } |
|
| 4951 | + return $u; |
|
| 4952 | + } |
|
| 4953 | 4953 | |
| 4954 | - // caster $u en array si besoin |
|
| 4955 | - if (is_object($u)) { |
|
| 4956 | - $u = (array)$u; |
|
| 4957 | - } |
|
| 4954 | + // caster $u en array si besoin |
|
| 4955 | + if (is_object($u)) { |
|
| 4956 | + $u = (array)$u; |
|
| 4957 | + } |
|
| 4958 | 4958 | |
| 4959 | - if (is_array($u)) { |
|
| 4960 | - $out = ''; |
|
| 4961 | - // toutes les cles sont numeriques ? |
|
| 4962 | - // et aucun enfant n'est un tableau |
|
| 4963 | - // liste simple separee par des virgules |
|
| 4964 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4965 | - $array_values = array_map('is_array', $u); |
|
| 4966 | - $object_values = array_map('is_object', $u); |
|
| 4967 | - if ( |
|
| 4968 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4969 | - and !array_sum($array_values) |
|
| 4970 | - and !array_sum($object_values) |
|
| 4971 | - ) { |
|
| 4972 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4973 | - } |
|
| 4959 | + if (is_array($u)) { |
|
| 4960 | + $out = ''; |
|
| 4961 | + // toutes les cles sont numeriques ? |
|
| 4962 | + // et aucun enfant n'est un tableau |
|
| 4963 | + // liste simple separee par des virgules |
|
| 4964 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4965 | + $array_values = array_map('is_array', $u); |
|
| 4966 | + $object_values = array_map('is_object', $u); |
|
| 4967 | + if ( |
|
| 4968 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4969 | + and !array_sum($array_values) |
|
| 4970 | + and !array_sum($object_values) |
|
| 4971 | + ) { |
|
| 4972 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4973 | + } |
|
| 4974 | 4974 | |
| 4975 | - // sinon on passe a la ligne et on indente |
|
| 4976 | - $i_str = str_pad('', $indent, ' '); |
|
| 4977 | - foreach ($u as $k => $v) { |
|
| 4978 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4979 | - } |
|
| 4975 | + // sinon on passe a la ligne et on indente |
|
| 4976 | + $i_str = str_pad('', $indent, ' '); |
|
| 4977 | + foreach ($u as $k => $v) { |
|
| 4978 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4979 | + } |
|
| 4980 | 4980 | |
| 4981 | - return $out; |
|
| 4982 | - } |
|
| 4981 | + return $out; |
|
| 4982 | + } |
|
| 4983 | 4983 | |
| 4984 | - // on sait pas quoi faire... |
|
| 4985 | - return $u; |
|
| 4984 | + // on sait pas quoi faire... |
|
| 4985 | + return $u; |
|
| 4986 | 4986 | } |
| 4987 | 4987 | |
| 4988 | 4988 | |
@@ -4995,10 +4995,10 @@ discard block |
||
| 4995 | 4995 | * @return string|array |
| 4996 | 4996 | */ |
| 4997 | 4997 | function objet_info($objet, $info) { |
| 4998 | - $table = table_objet_sql($objet); |
|
| 4999 | - $infos = lister_tables_objets_sql($table); |
|
| 4998 | + $table = table_objet_sql($objet); |
|
| 4999 | + $infos = lister_tables_objets_sql($table); |
|
| 5000 | 5000 | |
| 5001 | - return ($infos[$info] ?? ''); |
|
| 5001 | + return ($infos[$info] ?? ''); |
|
| 5002 | 5002 | } |
| 5003 | 5003 | |
| 5004 | 5004 | /** |
@@ -5013,11 +5013,11 @@ discard block |
||
| 5013 | 5013 | * texte traduit du comptage, tel que '3 articles' |
| 5014 | 5014 | */ |
| 5015 | 5015 | function objet_afficher_nb($nb, $objet) { |
| 5016 | - if (!$nb) { |
|
| 5017 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5018 | - } else { |
|
| 5019 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5020 | - } |
|
| 5016 | + if (!$nb) { |
|
| 5017 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5018 | + } else { |
|
| 5019 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5020 | + } |
|
| 5021 | 5021 | } |
| 5022 | 5022 | |
| 5023 | 5023 | /** |
@@ -5029,11 +5029,11 @@ discard block |
||
| 5029 | 5029 | * @return string |
| 5030 | 5030 | */ |
| 5031 | 5031 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5032 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5033 | - $icone = chemin_image($icone); |
|
| 5034 | - $balise_img = charger_filtre('balise_img'); |
|
| 5032 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5033 | + $icone = chemin_image($icone); |
|
| 5034 | + $balise_img = charger_filtre('balise_img'); |
|
| 5035 | 5035 | |
| 5036 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5036 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5037 | 5037 | } |
| 5038 | 5038 | |
| 5039 | 5039 | /** |
@@ -5054,12 +5054,12 @@ discard block |
||
| 5054 | 5054 | * @return string |
| 5055 | 5055 | */ |
| 5056 | 5056 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5057 | - $chaine = explode(':', $chaine); |
|
| 5058 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5059 | - return $t; |
|
| 5060 | - } |
|
| 5061 | - $chaine = implode(':', $chaine); |
|
| 5062 | - return _T($chaine, $args, $options); |
|
| 5057 | + $chaine = explode(':', $chaine); |
|
| 5058 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5059 | + return $t; |
|
| 5060 | + } |
|
| 5061 | + $chaine = implode(':', $chaine); |
|
| 5062 | + return _T($chaine, $args, $options); |
|
| 5063 | 5063 | } |
| 5064 | 5064 | |
| 5065 | 5065 | /** |
@@ -5073,18 +5073,18 @@ discard block |
||
| 5073 | 5073 | * @return string Code HTML |
| 5074 | 5074 | */ |
| 5075 | 5075 | function insert_head_css_conditionnel($flux) { |
| 5076 | - if ( |
|
| 5077 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5078 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5079 | - ) { |
|
| 5080 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5081 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5082 | - $p = $p1; |
|
| 5083 | - } |
|
| 5084 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5085 | - } |
|
| 5076 | + if ( |
|
| 5077 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5078 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5079 | + ) { |
|
| 5080 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5081 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5082 | + $p = $p1; |
|
| 5083 | + } |
|
| 5084 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5085 | + } |
|
| 5086 | 5086 | |
| 5087 | - return $flux; |
|
| 5087 | + return $flux; |
|
| 5088 | 5088 | } |
| 5089 | 5089 | |
| 5090 | 5090 | /** |
@@ -5107,75 +5107,75 @@ discard block |
||
| 5107 | 5107 | * @return string |
| 5108 | 5108 | */ |
| 5109 | 5109 | function produire_fond_statique($fond, $contexte = [], $options = [], string $connect = '') { |
| 5110 | - if (isset($contexte['format'])) { |
|
| 5111 | - $extension = $contexte['format']; |
|
| 5112 | - unset($contexte['format']); |
|
| 5113 | - } else { |
|
| 5114 | - $extension = 'html'; |
|
| 5115 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5116 | - $extension = $m[1]; |
|
| 5117 | - } |
|
| 5118 | - } |
|
| 5119 | - // recuperer le contenu produit par le squelette |
|
| 5120 | - $options['raw'] = true; |
|
| 5121 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5122 | - |
|
| 5123 | - // calculer le nom de la css |
|
| 5124 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5125 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5126 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5127 | - |
|
| 5128 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5129 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5130 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5131 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5132 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5133 | - } |
|
| 5134 | - else { |
|
| 5135 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5136 | - ksort($contexte); |
|
| 5137 | - $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5138 | - } |
|
| 5139 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5140 | - |
|
| 5141 | - // mettre a jour le fichier si il n'existe pas |
|
| 5142 | - // ou trop ancien |
|
| 5143 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5144 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5145 | - if ( |
|
| 5146 | - !file_exists($filename) |
|
| 5147 | - or !file_exists($filename . '.last') |
|
| 5148 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5149 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5150 | - ) { |
|
| 5151 | - $contenu = $cache['texte']; |
|
| 5152 | - // passer les urls en absolu si c'est une css |
|
| 5153 | - if ($extension == 'css') { |
|
| 5154 | - $contenu = urls_absolues_css( |
|
| 5155 | - $contenu, |
|
| 5156 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5157 | - ); |
|
| 5158 | - } |
|
| 5159 | - |
|
| 5160 | - $comment = ''; |
|
| 5161 | - // ne pas insérer de commentaire sur certains formats |
|
| 5162 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5163 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5164 | - foreach ($contexte as $k => $v) { |
|
| 5165 | - if (is_array($v)) { |
|
| 5166 | - $v = var_export($v, true); |
|
| 5167 | - } |
|
| 5168 | - $comment .= ",$k=$v"; |
|
| 5169 | - } |
|
| 5170 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5171 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5172 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5173 | - } |
|
| 5174 | - // et ecrire le fichier si il change |
|
| 5175 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5176 | - } |
|
| 5177 | - |
|
| 5178 | - return timestamp($filename); |
|
| 5110 | + if (isset($contexte['format'])) { |
|
| 5111 | + $extension = $contexte['format']; |
|
| 5112 | + unset($contexte['format']); |
|
| 5113 | + } else { |
|
| 5114 | + $extension = 'html'; |
|
| 5115 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5116 | + $extension = $m[1]; |
|
| 5117 | + } |
|
| 5118 | + } |
|
| 5119 | + // recuperer le contenu produit par le squelette |
|
| 5120 | + $options['raw'] = true; |
|
| 5121 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5122 | + |
|
| 5123 | + // calculer le nom de la css |
|
| 5124 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5125 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5126 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5127 | + |
|
| 5128 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5129 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5130 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5131 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5132 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5133 | + } |
|
| 5134 | + else { |
|
| 5135 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5136 | + ksort($contexte); |
|
| 5137 | + $hash = md5($fond . json_encode($contexte_implicite, JSON_THROW_ON_ERROR) . json_encode($contexte, JSON_THROW_ON_ERROR) . $connect); |
|
| 5138 | + } |
|
| 5139 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5140 | + |
|
| 5141 | + // mettre a jour le fichier si il n'existe pas |
|
| 5142 | + // ou trop ancien |
|
| 5143 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5144 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5145 | + if ( |
|
| 5146 | + !file_exists($filename) |
|
| 5147 | + or !file_exists($filename . '.last') |
|
| 5148 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5149 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5150 | + ) { |
|
| 5151 | + $contenu = $cache['texte']; |
|
| 5152 | + // passer les urls en absolu si c'est une css |
|
| 5153 | + if ($extension == 'css') { |
|
| 5154 | + $contenu = urls_absolues_css( |
|
| 5155 | + $contenu, |
|
| 5156 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5157 | + ); |
|
| 5158 | + } |
|
| 5159 | + |
|
| 5160 | + $comment = ''; |
|
| 5161 | + // ne pas insérer de commentaire sur certains formats |
|
| 5162 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5163 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5164 | + foreach ($contexte as $k => $v) { |
|
| 5165 | + if (is_array($v)) { |
|
| 5166 | + $v = var_export($v, true); |
|
| 5167 | + } |
|
| 5168 | + $comment .= ",$k=$v"; |
|
| 5169 | + } |
|
| 5170 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5171 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5172 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5173 | + } |
|
| 5174 | + // et ecrire le fichier si il change |
|
| 5175 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5176 | + } |
|
| 5177 | + |
|
| 5178 | + return timestamp($filename); |
|
| 5179 | 5179 | } |
| 5180 | 5180 | |
| 5181 | 5181 | /** |
@@ -5188,15 +5188,15 @@ discard block |
||
| 5188 | 5188 | * $fichier auquel on a ajouté le timestamp |
| 5189 | 5189 | */ |
| 5190 | 5190 | function timestamp($fichier) { |
| 5191 | - if ( |
|
| 5192 | - !$fichier |
|
| 5193 | - or !file_exists($fichier) |
|
| 5194 | - or !$m = filemtime($fichier) |
|
| 5195 | - ) { |
|
| 5196 | - return $fichier; |
|
| 5197 | - } |
|
| 5191 | + if ( |
|
| 5192 | + !$fichier |
|
| 5193 | + or !file_exists($fichier) |
|
| 5194 | + or !$m = filemtime($fichier) |
|
| 5195 | + ) { |
|
| 5196 | + return $fichier; |
|
| 5197 | + } |
|
| 5198 | 5198 | |
| 5199 | - return "$fichier?$m"; |
|
| 5199 | + return "$fichier?$m"; |
|
| 5200 | 5200 | } |
| 5201 | 5201 | |
| 5202 | 5202 | /** |
@@ -5206,11 +5206,11 @@ discard block |
||
| 5206 | 5206 | * @return string |
| 5207 | 5207 | */ |
| 5208 | 5208 | function supprimer_timestamp($url) { |
| 5209 | - if (strpos($url, '?') === false) { |
|
| 5210 | - return $url; |
|
| 5211 | - } |
|
| 5209 | + if (strpos($url, '?') === false) { |
|
| 5210 | + return $url; |
|
| 5211 | + } |
|
| 5212 | 5212 | |
| 5213 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5213 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5214 | 5214 | } |
| 5215 | 5215 | |
| 5216 | 5216 | /** |
@@ -5225,15 +5225,15 @@ discard block |
||
| 5225 | 5225 | * @return string |
| 5226 | 5226 | */ |
| 5227 | 5227 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5228 | - include_spip('inc/envoyer_mail'); |
|
| 5228 | + include_spip('inc/envoyer_mail'); |
|
| 5229 | 5229 | |
| 5230 | - $titre = nettoyer_titre_email($titre); |
|
| 5231 | - // on est dans un squelette : securiser le retour |
|
| 5232 | - if (strpos($titre, '<') !== false) { |
|
| 5233 | - $titre = interdire_scripts($titre); |
|
| 5234 | - } |
|
| 5230 | + $titre = nettoyer_titre_email($titre); |
|
| 5231 | + // on est dans un squelette : securiser le retour |
|
| 5232 | + if (strpos($titre, '<') !== false) { |
|
| 5233 | + $titre = interdire_scripts($titre); |
|
| 5234 | + } |
|
| 5235 | 5235 | |
| 5236 | - return $titre; |
|
| 5236 | + return $titre; |
|
| 5237 | 5237 | } |
| 5238 | 5238 | |
| 5239 | 5239 | /** |
@@ -5255,27 +5255,27 @@ discard block |
||
| 5255 | 5255 | * @return string |
| 5256 | 5256 | */ |
| 5257 | 5257 | function filtre_chercher_rubrique_dist( |
| 5258 | - $titre, |
|
| 5259 | - $id_objet, |
|
| 5260 | - $id_parent, |
|
| 5261 | - $objet, |
|
| 5262 | - $id_secteur, |
|
| 5263 | - $restreint, |
|
| 5264 | - $actionable = false, |
|
| 5265 | - $retour_sans_cadre = false |
|
| 5258 | + $titre, |
|
| 5259 | + $id_objet, |
|
| 5260 | + $id_parent, |
|
| 5261 | + $objet, |
|
| 5262 | + $id_secteur, |
|
| 5263 | + $restreint, |
|
| 5264 | + $actionable = false, |
|
| 5265 | + $retour_sans_cadre = false |
|
| 5266 | 5266 | ) { |
| 5267 | - include_spip('inc/filtres_ecrire'); |
|
| 5267 | + include_spip('inc/filtres_ecrire'); |
|
| 5268 | 5268 | |
| 5269 | - return chercher_rubrique( |
|
| 5270 | - $titre, |
|
| 5271 | - $id_objet, |
|
| 5272 | - $id_parent, |
|
| 5273 | - $objet, |
|
| 5274 | - $id_secteur, |
|
| 5275 | - $restreint, |
|
| 5276 | - $actionable, |
|
| 5277 | - $retour_sans_cadre |
|
| 5278 | - ); |
|
| 5269 | + return chercher_rubrique( |
|
| 5270 | + $titre, |
|
| 5271 | + $id_objet, |
|
| 5272 | + $id_parent, |
|
| 5273 | + $objet, |
|
| 5274 | + $id_secteur, |
|
| 5275 | + $restreint, |
|
| 5276 | + $actionable, |
|
| 5277 | + $retour_sans_cadre |
|
| 5278 | + ); |
|
| 5279 | 5279 | } |
| 5280 | 5280 | |
| 5281 | 5281 | /** |
@@ -5304,56 +5304,56 @@ discard block |
||
| 5304 | 5304 | * Chaîne vide si l'accès est autorisé |
| 5305 | 5305 | */ |
| 5306 | 5306 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5307 | - if ($ok) { |
|
| 5308 | - return ''; |
|
| 5309 | - } |
|
| 5310 | - |
|
| 5311 | - // Vider tous les tampons |
|
| 5312 | - $level = @ob_get_level(); |
|
| 5313 | - while ($level--) { |
|
| 5314 | - @ob_end_clean(); |
|
| 5315 | - } |
|
| 5316 | - |
|
| 5317 | - include_spip('inc/headers'); |
|
| 5318 | - |
|
| 5319 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5320 | - if ($url) { |
|
| 5321 | - redirige_par_entete($url, '', $statut); |
|
| 5322 | - } |
|
| 5323 | - |
|
| 5324 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5325 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5326 | - $message = $statut; |
|
| 5327 | - $statut = 0; |
|
| 5328 | - } |
|
| 5329 | - if (!$message) { |
|
| 5330 | - $message = ''; |
|
| 5331 | - } |
|
| 5332 | - $statut = intval($statut); |
|
| 5333 | - |
|
| 5334 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5335 | - if (test_espace_prive()) { |
|
| 5336 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5337 | - $statut = 403; |
|
| 5338 | - } |
|
| 5339 | - http_response_code(403); |
|
| 5340 | - $echec = charger_fonction('403', 'exec'); |
|
| 5341 | - $echec($message); |
|
| 5342 | - } else { |
|
| 5343 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5344 | - if (!$statut) { |
|
| 5345 | - $statut = 404; |
|
| 5346 | - } |
|
| 5347 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5348 | - http_response_code($statut); |
|
| 5349 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5350 | - if ($statut >= 400) { |
|
| 5351 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5352 | - } |
|
| 5353 | - } |
|
| 5354 | - |
|
| 5355 | - |
|
| 5356 | - exit; |
|
| 5307 | + if ($ok) { |
|
| 5308 | + return ''; |
|
| 5309 | + } |
|
| 5310 | + |
|
| 5311 | + // Vider tous les tampons |
|
| 5312 | + $level = @ob_get_level(); |
|
| 5313 | + while ($level--) { |
|
| 5314 | + @ob_end_clean(); |
|
| 5315 | + } |
|
| 5316 | + |
|
| 5317 | + include_spip('inc/headers'); |
|
| 5318 | + |
|
| 5319 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5320 | + if ($url) { |
|
| 5321 | + redirige_par_entete($url, '', $statut); |
|
| 5322 | + } |
|
| 5323 | + |
|
| 5324 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5325 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5326 | + $message = $statut; |
|
| 5327 | + $statut = 0; |
|
| 5328 | + } |
|
| 5329 | + if (!$message) { |
|
| 5330 | + $message = ''; |
|
| 5331 | + } |
|
| 5332 | + $statut = intval($statut); |
|
| 5333 | + |
|
| 5334 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5335 | + if (test_espace_prive()) { |
|
| 5336 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5337 | + $statut = 403; |
|
| 5338 | + } |
|
| 5339 | + http_response_code(403); |
|
| 5340 | + $echec = charger_fonction('403', 'exec'); |
|
| 5341 | + $echec($message); |
|
| 5342 | + } else { |
|
| 5343 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5344 | + if (!$statut) { |
|
| 5345 | + $statut = 404; |
|
| 5346 | + } |
|
| 5347 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5348 | + http_response_code($statut); |
|
| 5349 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5350 | + if ($statut >= 400) { |
|
| 5351 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5352 | + } |
|
| 5353 | + } |
|
| 5354 | + |
|
| 5355 | + |
|
| 5356 | + exit; |
|
| 5357 | 5357 | } |
| 5358 | 5358 | |
| 5359 | 5359 | /** |
@@ -5364,11 +5364,11 @@ discard block |
||
| 5364 | 5364 | * @return string |
| 5365 | 5365 | */ |
| 5366 | 5366 | function filtre_compacte_dist($source, $format = null) { |
| 5367 | - if (function_exists('minifier')) { |
|
| 5368 | - return minifier($source, $format); |
|
| 5369 | - } |
|
| 5367 | + if (function_exists('minifier')) { |
|
| 5368 | + return minifier($source, $format); |
|
| 5369 | + } |
|
| 5370 | 5370 | |
| 5371 | - return $source; |
|
| 5371 | + return $source; |
|
| 5372 | 5372 | } |
| 5373 | 5373 | |
| 5374 | 5374 | |
@@ -5380,32 +5380,32 @@ discard block |
||
| 5380 | 5380 | * @return string |
| 5381 | 5381 | */ |
| 5382 | 5382 | function spip_affiche_mot_de_passe_masque(?string $passe, bool $afficher_partiellement = false, ?int $portion_pourcent = null): string { |
| 5383 | - $passe ??= ''; |
|
| 5384 | - $l = strlen($passe); |
|
| 5385 | - |
|
| 5386 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5387 | - if (!$l) { |
|
| 5388 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5389 | - } |
|
| 5390 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5391 | - } |
|
| 5392 | - |
|
| 5393 | - if (is_null($portion_pourcent)) { |
|
| 5394 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5395 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5396 | - } |
|
| 5397 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5398 | - } |
|
| 5399 | - if ($portion_pourcent >= 100) { |
|
| 5400 | - return $passe; |
|
| 5401 | - } |
|
| 5402 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5403 | - $e = max($e, 0); |
|
| 5404 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5405 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5406 | - $mid = '***...***'; |
|
| 5407 | - } |
|
| 5408 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5383 | + $passe ??= ''; |
|
| 5384 | + $l = strlen($passe); |
|
| 5385 | + |
|
| 5386 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5387 | + if (!$l) { |
|
| 5388 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5389 | + } |
|
| 5390 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5391 | + } |
|
| 5392 | + |
|
| 5393 | + if (is_null($portion_pourcent)) { |
|
| 5394 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5395 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5396 | + } |
|
| 5397 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5398 | + } |
|
| 5399 | + if ($portion_pourcent >= 100) { |
|
| 5400 | + return $passe; |
|
| 5401 | + } |
|
| 5402 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5403 | + $e = max($e, 0); |
|
| 5404 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5405 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5406 | + $mid = '***...***'; |
|
| 5407 | + } |
|
| 5408 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5409 | 5409 | } |
| 5410 | 5410 | |
| 5411 | 5411 | |
@@ -5426,64 +5426,64 @@ discard block |
||
| 5426 | 5426 | */ |
| 5427 | 5427 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5428 | 5428 | |
| 5429 | - $original = $texte; |
|
| 5430 | - $separateur = ($options['separateur'] ?? '_'); |
|
| 5431 | - $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5432 | - $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5429 | + $original = $texte; |
|
| 5430 | + $separateur = ($options['separateur'] ?? '_'); |
|
| 5431 | + $longueur_maxi = ($options['longueur_maxi'] ?? 60); |
|
| 5432 | + $longueur_mini = ($options['longueur_mini'] ?? 0); |
|
| 5433 | 5433 | |
| 5434 | - if (!function_exists('translitteration')) { |
|
| 5435 | - include_spip('inc/charsets'); |
|
| 5436 | - } |
|
| 5434 | + if (!function_exists('translitteration')) { |
|
| 5435 | + include_spip('inc/charsets'); |
|
| 5436 | + } |
|
| 5437 | 5437 | |
| 5438 | - // pas de balise html |
|
| 5439 | - if (strpos($texte, '<') !== false) { |
|
| 5440 | - $texte = strip_tags($texte); |
|
| 5441 | - } |
|
| 5442 | - if (strpos($texte, '&') !== false) { |
|
| 5443 | - $texte = unicode2charset($texte); |
|
| 5444 | - } |
|
| 5445 | - // On enlève les espaces indésirables |
|
| 5446 | - $texte = trim($texte); |
|
| 5438 | + // pas de balise html |
|
| 5439 | + if (strpos($texte, '<') !== false) { |
|
| 5440 | + $texte = strip_tags($texte); |
|
| 5441 | + } |
|
| 5442 | + if (strpos($texte, '&') !== false) { |
|
| 5443 | + $texte = unicode2charset($texte); |
|
| 5444 | + } |
|
| 5445 | + // On enlève les espaces indésirables |
|
| 5446 | + $texte = trim($texte); |
|
| 5447 | 5447 | |
| 5448 | - // On enlève les accents et cie |
|
| 5449 | - $texte = translitteration($texte); |
|
| 5448 | + // On enlève les accents et cie |
|
| 5449 | + $texte = translitteration($texte); |
|
| 5450 | 5450 | |
| 5451 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5452 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5451 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5452 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5453 | 5453 | |
| 5454 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5455 | - while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5456 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5457 | - } |
|
| 5454 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5455 | + while (strpos($texte, (string) "$separateur$separateur") !== false) { |
|
| 5456 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5457 | + } |
|
| 5458 | 5458 | |
| 5459 | - // pas de separateur au debut ni a la fin |
|
| 5460 | - $texte = trim($texte, $separateur); |
|
| 5459 | + // pas de separateur au debut ni a la fin |
|
| 5460 | + $texte = trim($texte, $separateur); |
|
| 5461 | 5461 | |
| 5462 | - // en minuscules |
|
| 5463 | - $texte = strtolower($texte); |
|
| 5462 | + // en minuscules |
|
| 5463 | + $texte = strtolower($texte); |
|
| 5464 | 5464 | |
| 5465 | - switch ($type) { |
|
| 5466 | - case 'class': |
|
| 5467 | - case 'id': |
|
| 5468 | - case 'anchor': |
|
| 5469 | - if (preg_match(',^\d,', $texte)) { |
|
| 5470 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5471 | - } |
|
| 5472 | - } |
|
| 5465 | + switch ($type) { |
|
| 5466 | + case 'class': |
|
| 5467 | + case 'id': |
|
| 5468 | + case 'anchor': |
|
| 5469 | + if (preg_match(',^\d,', $texte)) { |
|
| 5470 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5471 | + } |
|
| 5472 | + } |
|
| 5473 | 5473 | |
| 5474 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5475 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5476 | - } |
|
| 5474 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5475 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5476 | + } |
|
| 5477 | 5477 | |
| 5478 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5479 | - if (preg_match(',^\d,', $texte)) { |
|
| 5480 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5481 | - } |
|
| 5482 | - $texte .= $separateur . md5($original); |
|
| 5483 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5484 | - } |
|
| 5478 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5479 | + if (preg_match(',^\d,', $texte)) { |
|
| 5480 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5481 | + } |
|
| 5482 | + $texte .= $separateur . md5($original); |
|
| 5483 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5484 | + } |
|
| 5485 | 5485 | |
| 5486 | - return $texte; |
|
| 5486 | + return $texte; |
|
| 5487 | 5487 | } |
| 5488 | 5488 | |
| 5489 | 5489 | |
@@ -5504,11 +5504,11 @@ discard block |
||
| 5504 | 5504 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5505 | 5505 | */ |
| 5506 | 5506 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5507 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5508 | - if ($ucfirst) { |
|
| 5509 | - $label = spip_ucfirst($label); |
|
| 5510 | - } |
|
| 5511 | - return $label; |
|
| 5507 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5508 | + if ($ucfirst) { |
|
| 5509 | + $label = spip_ucfirst($label); |
|
| 5510 | + } |
|
| 5511 | + return $label; |
|
| 5512 | 5512 | } |
| 5513 | 5513 | |
| 5514 | 5514 | /** |
@@ -5521,8 +5521,8 @@ discard block |
||
| 5521 | 5521 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5522 | 5522 | */ |
| 5523 | 5523 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5524 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5525 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5524 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5525 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5526 | 5526 | } |
| 5527 | 5527 | |
| 5528 | 5528 | |
@@ -5535,19 +5535,19 @@ discard block |
||
| 5535 | 5535 | * @return array |
| 5536 | 5536 | */ |
| 5537 | 5537 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5538 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5539 | - return []; |
|
| 5540 | - } |
|
| 5538 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5539 | + return []; |
|
| 5540 | + } |
|
| 5541 | 5541 | |
| 5542 | - // compatibilite signature inversee |
|
| 5543 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5544 | - [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5545 | - } |
|
| 5542 | + // compatibilite signature inversee |
|
| 5543 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5544 | + [$objet, $id_objet] = [$id_objet, $objet]; |
|
| 5545 | + } |
|
| 5546 | 5546 | |
| 5547 | - if (!function_exists($fonction)) { |
|
| 5548 | - include_spip('base/objets'); |
|
| 5549 | - } |
|
| 5550 | - return $fonction($objet, $id_objet); |
|
| 5547 | + if (!function_exists($fonction)) { |
|
| 5548 | + include_spip('base/objets'); |
|
| 5549 | + } |
|
| 5550 | + return $fonction($objet, $id_objet); |
|
| 5551 | 5551 | } |
| 5552 | 5552 | |
| 5553 | 5553 | |
@@ -5562,7 +5562,7 @@ discard block |
||
| 5562 | 5562 | * @return array |
| 5563 | 5563 | */ |
| 5564 | 5564 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5565 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5565 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5566 | 5566 | } |
| 5567 | 5567 | |
| 5568 | 5568 | /** |
@@ -5576,7 +5576,7 @@ discard block |
||
| 5576 | 5576 | * @return array |
| 5577 | 5577 | */ |
| 5578 | 5578 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5579 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5579 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5580 | 5580 | } |
| 5581 | 5581 | |
| 5582 | 5582 | /** |
@@ -5590,7 +5590,7 @@ discard block |
||
| 5590 | 5590 | * @return array |
| 5591 | 5591 | */ |
| 5592 | 5592 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5593 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5593 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5594 | 5594 | } |
| 5595 | 5595 | |
| 5596 | 5596 | /** |
@@ -5604,5 +5604,5 @@ discard block |
||
| 5604 | 5604 | * @return array |
| 5605 | 5605 | */ |
| 5606 | 5606 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5607 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5607 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5608 | 5608 | } |
@@ -14,171 +14,171 @@ |
||
| 14 | 14 | |
| 15 | 15 | /** Gestion des clés d’authentification / chiffrement de SPIP */ |
| 16 | 16 | final class SpipCles { |
| 17 | - private static array $instances = []; |
|
| 18 | - |
|
| 19 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 20 | - private Cles $cles; |
|
| 21 | - |
|
| 22 | - public static function instance(string $file = ''): self { |
|
| 23 | - if (empty(self::$instances[$file])) { |
|
| 24 | - self::$instances[$file] = new self($file); |
|
| 25 | - } |
|
| 26 | - return self::$instances[$file]; |
|
| 27 | - } |
|
| 28 | - |
|
| 29 | - /** |
|
| 30 | - * Retourne le secret du site (shorthand) |
|
| 31 | - * @uses self::getSecretSite() |
|
| 32 | - */ |
|
| 33 | - public static function secret_du_site(): ?string { |
|
| 34 | - return (self::instance())->getSecretSite(); |
|
| 35 | - } |
|
| 36 | - |
|
| 37 | - private function __construct(string $file = '') { |
|
| 38 | - if ($file) { |
|
| 39 | - $this->file = $file; |
|
| 40 | - } |
|
| 41 | - $this->cles = new Cles($this->read()); |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - /** |
|
| 45 | - * Renvoyer le secret du site |
|
| 46 | - * |
|
| 47 | - * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 48 | - * On ne doit pas l'exporter |
|
| 49 | - * |
|
| 50 | - * Le secret est partagé entre une clé disque et une clé bdd |
|
| 51 | - * |
|
| 52 | - * @return string |
|
| 53 | - */ |
|
| 54 | - public function getSecretSite(bool $autoInit = true): ?string { |
|
| 55 | - $key = $this->getKey('secret_du_site', $autoInit); |
|
| 56 | - $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 57 | - // conserve la même longeur. |
|
| 58 | - return $key ^ $meta; |
|
| 59 | - } |
|
| 60 | - |
|
| 61 | - /** Renvoyer le secret des authentifications */ |
|
| 62 | - public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 63 | - return $this->getKey('secret_des_auth', $autoInit); |
|
| 64 | - } |
|
| 65 | - public function save(): bool { |
|
| 66 | - return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 67 | - } |
|
| 68 | - |
|
| 69 | - /** |
|
| 70 | - * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 71 | - * |
|
| 72 | - * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 73 | - * @return string Contenu de la sauvegarde chiffrée générée |
|
| 74 | - */ |
|
| 75 | - public function backup( |
|
| 76 | - #[\SensitiveParameter] |
|
| 77 | - string $withKey |
|
| 78 | - ): string { |
|
| 79 | - if (count($this->cles)) { |
|
| 80 | - return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 81 | - } |
|
| 82 | - return ''; |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - /** |
|
| 86 | - * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 87 | - * (si la sauvegarde est bien valide) |
|
| 88 | - * |
|
| 89 | - * @param string $backup Sauvegarde chiffrée (générée par backup()) |
|
| 90 | - * @param int $id_auteur |
|
| 91 | - * @param string $pass |
|
| 92 | - * @return void |
|
| 93 | - */ |
|
| 94 | - public function restore( |
|
| 95 | - string $backup, |
|
| 96 | - #[\SensitiveParameter] |
|
| 97 | - string $password_clair, |
|
| 98 | - #[\SensitiveParameter] |
|
| 99 | - string $password_hash, |
|
| 100 | - int $id_auteur |
|
| 101 | - ): bool { |
|
| 102 | - if (empty($backup)) { |
|
| 103 | - return false; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 107 | - $json = json_decode($sauvegarde, true); |
|
| 108 | - if (!$json) { |
|
| 109 | - return false; |
|
| 110 | - } |
|
| 111 | - |
|
| 112 | - // cela semble une sauvegarde valide |
|
| 113 | - $cles_potentielles = array_map('base64_decode', $json); |
|
| 114 | - |
|
| 115 | - // il faut faire une double verif sur secret_des_auth |
|
| 116 | - // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 117 | - // et par extension tous les passwords |
|
| 118 | - if (!empty($cles_potentielles['secret_des_auth'])) { |
|
| 119 | - if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
|
| 120 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 121 | - unset($cles_potentielles['secret_des_auth']); |
|
| 122 | - } |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - // on merge les cles pour recuperer les cles manquantes |
|
| 126 | - $restauration = false; |
|
| 127 | - foreach ($cles_potentielles as $name => $key) { |
|
| 128 | - if (!$this->cles->has($name)) { |
|
| 129 | - $this->cles->set($name, $key); |
|
| 130 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 131 | - $restauration = true; |
|
| 132 | - } |
|
| 133 | - } |
|
| 134 | - return $restauration; |
|
| 135 | - } |
|
| 136 | - |
|
| 137 | - private function getKey(string $name, bool $autoInit): ?string { |
|
| 138 | - if ($this->cles->has($name)) { |
|
| 139 | - return $this->cles->get($name); |
|
| 140 | - } |
|
| 141 | - if ($autoInit) { |
|
| 142 | - $this->cles->generate($name); |
|
| 143 | - // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 144 | - if ($this->save()) { |
|
| 145 | - return $this->cles->get($name); |
|
| 146 | - } |
|
| 147 | - // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 148 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 149 | - $this->cles->delete($name); |
|
| 150 | - } |
|
| 151 | - return null; |
|
| 152 | - } |
|
| 153 | - |
|
| 154 | - private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 155 | - if (!isset($GLOBALS['meta'][$name])) { |
|
| 156 | - include_spip('base/abstract_sql'); |
|
| 157 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 158 | - } |
|
| 159 | - $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 160 | - if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 161 | - return $key; |
|
| 162 | - } |
|
| 163 | - if (!$autoInit) { |
|
| 164 | - return null; |
|
| 165 | - } |
|
| 166 | - $key = Chiffrement::keygen(); |
|
| 167 | - ecrire_meta($name, base64_encode($key), 'non'); |
|
| 168 | - lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 169 | - |
|
| 170 | - return $key; |
|
| 171 | - } |
|
| 172 | - |
|
| 173 | - private function read(): array { |
|
| 174 | - lire_fichier_securise($this->file, $json); |
|
| 175 | - if ( |
|
| 176 | - $json |
|
| 177 | - and $json = \json_decode($json, true) |
|
| 178 | - and is_array($json) |
|
| 179 | - ) { |
|
| 180 | - return array_map('base64_decode', $json); |
|
| 181 | - } |
|
| 182 | - return []; |
|
| 183 | - } |
|
| 17 | + private static array $instances = []; |
|
| 18 | + |
|
| 19 | + private string $file = _DIR_ETC . 'cles.php'; |
|
| 20 | + private Cles $cles; |
|
| 21 | + |
|
| 22 | + public static function instance(string $file = ''): self { |
|
| 23 | + if (empty(self::$instances[$file])) { |
|
| 24 | + self::$instances[$file] = new self($file); |
|
| 25 | + } |
|
| 26 | + return self::$instances[$file]; |
|
| 27 | + } |
|
| 28 | + |
|
| 29 | + /** |
|
| 30 | + * Retourne le secret du site (shorthand) |
|
| 31 | + * @uses self::getSecretSite() |
|
| 32 | + */ |
|
| 33 | + public static function secret_du_site(): ?string { |
|
| 34 | + return (self::instance())->getSecretSite(); |
|
| 35 | + } |
|
| 36 | + |
|
| 37 | + private function __construct(string $file = '') { |
|
| 38 | + if ($file) { |
|
| 39 | + $this->file = $file; |
|
| 40 | + } |
|
| 41 | + $this->cles = new Cles($this->read()); |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + /** |
|
| 45 | + * Renvoyer le secret du site |
|
| 46 | + * |
|
| 47 | + * Le secret du site doit rester aussi secret que possible, et est eternel |
|
| 48 | + * On ne doit pas l'exporter |
|
| 49 | + * |
|
| 50 | + * Le secret est partagé entre une clé disque et une clé bdd |
|
| 51 | + * |
|
| 52 | + * @return string |
|
| 53 | + */ |
|
| 54 | + public function getSecretSite(bool $autoInit = true): ?string { |
|
| 55 | + $key = $this->getKey('secret_du_site', $autoInit); |
|
| 56 | + $meta = $this->getMetaKey('secret_du_site', $autoInit); |
|
| 57 | + // conserve la même longeur. |
|
| 58 | + return $key ^ $meta; |
|
| 59 | + } |
|
| 60 | + |
|
| 61 | + /** Renvoyer le secret des authentifications */ |
|
| 62 | + public function getSecretAuth(bool $autoInit = false): ?string { |
|
| 63 | + return $this->getKey('secret_des_auth', $autoInit); |
|
| 64 | + } |
|
| 65 | + public function save(): bool { |
|
| 66 | + return ecrire_fichier_securise($this->file, $this->cles->toJson()); |
|
| 67 | + } |
|
| 68 | + |
|
| 69 | + /** |
|
| 70 | + * Fournir une sauvegarde chiffree des cles (a l'aide d'une autre clé, comme le pass d'un auteur) |
|
| 71 | + * |
|
| 72 | + * @param string $withKey Clé de chiffrage de la sauvegarde |
|
| 73 | + * @return string Contenu de la sauvegarde chiffrée générée |
|
| 74 | + */ |
|
| 75 | + public function backup( |
|
| 76 | + #[\SensitiveParameter] |
|
| 77 | + string $withKey |
|
| 78 | + ): string { |
|
| 79 | + if (count($this->cles)) { |
|
| 80 | + return Chiffrement::chiffrer($this->cles->toJson(), $withKey); |
|
| 81 | + } |
|
| 82 | + return ''; |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + /** |
|
| 86 | + * Restaurer les cles manquantes depuis une sauvegarde chiffree des cles |
|
| 87 | + * (si la sauvegarde est bien valide) |
|
| 88 | + * |
|
| 89 | + * @param string $backup Sauvegarde chiffrée (générée par backup()) |
|
| 90 | + * @param int $id_auteur |
|
| 91 | + * @param string $pass |
|
| 92 | + * @return void |
|
| 93 | + */ |
|
| 94 | + public function restore( |
|
| 95 | + string $backup, |
|
| 96 | + #[\SensitiveParameter] |
|
| 97 | + string $password_clair, |
|
| 98 | + #[\SensitiveParameter] |
|
| 99 | + string $password_hash, |
|
| 100 | + int $id_auteur |
|
| 101 | + ): bool { |
|
| 102 | + if (empty($backup)) { |
|
| 103 | + return false; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $sauvegarde = Chiffrement::dechiffrer($backup, $password_clair); |
|
| 107 | + $json = json_decode($sauvegarde, true); |
|
| 108 | + if (!$json) { |
|
| 109 | + return false; |
|
| 110 | + } |
|
| 111 | + |
|
| 112 | + // cela semble une sauvegarde valide |
|
| 113 | + $cles_potentielles = array_map('base64_decode', $json); |
|
| 114 | + |
|
| 115 | + // il faut faire une double verif sur secret_des_auth |
|
| 116 | + // pour s'assurer qu'elle permet bien de decrypter le pass de l'auteur qui fournit la sauvegarde |
|
| 117 | + // et par extension tous les passwords |
|
| 118 | + if (!empty($cles_potentielles['secret_des_auth'])) { |
|
| 119 | + if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
|
| 120 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 121 | + unset($cles_potentielles['secret_des_auth']); |
|
| 122 | + } |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + // on merge les cles pour recuperer les cles manquantes |
|
| 126 | + $restauration = false; |
|
| 127 | + foreach ($cles_potentielles as $name => $key) { |
|
| 128 | + if (!$this->cles->has($name)) { |
|
| 129 | + $this->cles->set($name, $key); |
|
| 130 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 131 | + $restauration = true; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | + return $restauration; |
|
| 135 | + } |
|
| 136 | + |
|
| 137 | + private function getKey(string $name, bool $autoInit): ?string { |
|
| 138 | + if ($this->cles->has($name)) { |
|
| 139 | + return $this->cles->get($name); |
|
| 140 | + } |
|
| 141 | + if ($autoInit) { |
|
| 142 | + $this->cles->generate($name); |
|
| 143 | + // si l'ecriture de fichier a bien marche on peut utiliser la cle |
|
| 144 | + if ($this->save()) { |
|
| 145 | + return $this->cles->get($name); |
|
| 146 | + } |
|
| 147 | + // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
|
| 148 | + spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 149 | + $this->cles->delete($name); |
|
| 150 | + } |
|
| 151 | + return null; |
|
| 152 | + } |
|
| 153 | + |
|
| 154 | + private function getMetaKey(string $name, bool $autoInit = true): ?string { |
|
| 155 | + if (!isset($GLOBALS['meta'][$name])) { |
|
| 156 | + include_spip('base/abstract_sql'); |
|
| 157 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 158 | + } |
|
| 159 | + $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
|
| 160 | + if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
|
| 161 | + return $key; |
|
| 162 | + } |
|
| 163 | + if (!$autoInit) { |
|
| 164 | + return null; |
|
| 165 | + } |
|
| 166 | + $key = Chiffrement::keygen(); |
|
| 167 | + ecrire_meta($name, base64_encode($key), 'non'); |
|
| 168 | + lire_metas(); // au cas ou ecrire_meta() ne fonctionne pas |
|
| 169 | + |
|
| 170 | + return $key; |
|
| 171 | + } |
|
| 172 | + |
|
| 173 | + private function read(): array { |
|
| 174 | + lire_fichier_securise($this->file, $json); |
|
| 175 | + if ( |
|
| 176 | + $json |
|
| 177 | + and $json = \json_decode($json, true) |
|
| 178 | + and is_array($json) |
|
| 179 | + ) { |
|
| 180 | + return array_map('base64_decode', $json); |
|
| 181 | + } |
|
| 182 | + return []; |
|
| 183 | + } |
|
| 184 | 184 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | final class SpipCles { |
| 17 | 17 | private static array $instances = []; |
| 18 | 18 | |
| 19 | - private string $file = _DIR_ETC . 'cles.php'; |
|
| 19 | + private string $file = _DIR_ETC.'cles.php'; |
|
| 20 | 20 | private Cles $cles; |
| 21 | 21 | |
| 22 | 22 | public static function instance(string $file = ''): self { |
@@ -117,7 +117,7 @@ discard block |
||
| 117 | 117 | // et par extension tous les passwords |
| 118 | 118 | if (!empty($cles_potentielles['secret_des_auth'])) { |
| 119 | 119 | if (!Password::verifier($password_clair, $password_hash, $cles_potentielles['secret_des_auth'])) { |
| 120 | - spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 120 | + spip_log("Restauration de la cle `secret_des_auth` par id_auteur $id_auteur erronnee, on ignore", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 121 | 121 | unset($cles_potentielles['secret_des_auth']); |
| 122 | 122 | } |
| 123 | 123 | } |
@@ -127,7 +127,7 @@ discard block |
||
| 127 | 127 | foreach ($cles_potentielles as $name => $key) { |
| 128 | 128 | if (!$this->cles->has($name)) { |
| 129 | 129 | $this->cles->set($name, $key); |
| 130 | - spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer' . _LOG_INFO_IMPORTANTE); |
|
| 130 | + spip_log("Restauration de la cle $name par id_auteur $id_auteur", 'chiffrer'._LOG_INFO_IMPORTANTE); |
|
| 131 | 131 | $restauration = true; |
| 132 | 132 | } |
| 133 | 133 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | return $this->cles->get($name); |
| 146 | 146 | } |
| 147 | 147 | // sinon loger et annule la cle generee car il ne faut pas l'utiliser |
| 148 | - spip_log('Echec ecriture du fichier cle ' . $this->file . " ; impossible de generer une cle $name", 'chiffrer' . _LOG_ERREUR); |
|
| 148 | + spip_log('Echec ecriture du fichier cle '.$this->file." ; impossible de generer une cle $name", 'chiffrer'._LOG_ERREUR); |
|
| 149 | 149 | $this->cles->delete($name); |
| 150 | 150 | } |
| 151 | 151 | return null; |
@@ -154,7 +154,7 @@ discard block |
||
| 154 | 154 | private function getMetaKey(string $name, bool $autoInit = true): ?string { |
| 155 | 155 | if (!isset($GLOBALS['meta'][$name])) { |
| 156 | 156 | include_spip('base/abstract_sql'); |
| 157 | - $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = ' . sql_quote($name, '', 'string')); |
|
| 157 | + $GLOBALS['meta'][$name] = sql_getfetsel('valeur', 'spip_meta', 'nom = '.sql_quote($name, '', 'string')); |
|
| 158 | 158 | } |
| 159 | 159 | $key = base64_decode($GLOBALS['meta'][$name] ?? ''); |
| 160 | 160 | if (strlen($key) === \SODIUM_CRYPTO_SECRETBOX_KEYBYTES) { |
@@ -113,7 +113,7 @@ discard block |
||
| 113 | 113 | |
| 114 | 114 | // Appels incomplets (sans $c) |
| 115 | 115 | if (!is_array($c)) { |
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 116 | + spip_log('erreur appel objet_modifier_champs('.$objet.'), manque $c'); |
|
| 117 | 117 | |
| 118 | 118 | return _T('erreur_technique_enregistrement_impossible'); |
| 119 | 119 | } |
@@ -140,7 +140,7 @@ discard block |
||
| 140 | 140 | // N'accepter que les champs qui existent dans la table |
| 141 | 141 | $champs = array_intersect_key($c, $desc['field']); |
| 142 | 142 | // et dont la valeur n'est pas null |
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 143 | + $champs = array_filter($champs, static function($var) { |
|
| 144 | 144 | return $var !== null; |
| 145 | 145 | }); |
| 146 | 146 | // TODO: ici aussi on peut valider les contenus |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | $champs = array_map('corriger_caracteres', $champs); |
| 151 | 151 | |
| 152 | 152 | // On récupère l'état avant toute modification |
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet.'='.$id_objet); |
|
| 154 | 154 | |
| 155 | 155 | // Envoyer aux plugins |
| 156 | 156 | $champs = pipeline( |
@@ -205,7 +205,7 @@ discard block |
||
| 205 | 205 | $id_rubrique = 0; |
| 206 | 206 | if (isset($desc['field']['id_rubrique'])) { |
| 207 | 207 | $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=".intval($id_objet)); |
|
| 209 | 209 | } |
| 210 | 210 | $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
| 211 | 211 | $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
@@ -227,13 +227,13 @@ discard block |
||
| 227 | 227 | } |
| 228 | 228 | |
| 229 | 229 | // allez on commit la modif |
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=".intval($id_objet), [], $serveur); |
|
| 231 | 231 | |
| 232 | 232 | // on verifie si elle est bien passee |
| 233 | 233 | $moof = sql_fetsel( |
| 234 | 234 | array_keys($champs), |
| 235 | 235 | $spip_table_objet, |
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 236 | + "$id_table_objet=".intval($id_objet), |
|
| 237 | 237 | [], |
| 238 | 238 | [], |
| 239 | 239 | '', |
@@ -269,13 +269,13 @@ discard block |
||
| 269 | 269 | // c'est un cas exceptionnel |
| 270 | 270 | if (count($liste)) { |
| 271 | 271 | spip_log( |
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :".var_export($conflits, true), |
|
| 273 | + 'modifier.'._LOG_CRITIQUE |
|
| 274 | 274 | ); |
| 275 | 275 | |
| 276 | 276 | return _T( |
| 277 | 277 | 'erreur_technique_enregistrement_champs', |
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 278 | + ['champs' => "<i>'".implode("'</i>,<i>'", $liste)."'</i>"] |
|
| 279 | 279 | ); |
| 280 | 280 | } |
| 281 | 281 | } |
@@ -317,18 +317,18 @@ discard block |
||
| 317 | 317 | include_spip('inc/filtres_mini'); |
| 318 | 318 | $qui = ''; |
| 319 | 319 | if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
| 320 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 320 | + $qui .= ' #id_auteur:'.$GLOBALS['visiteur_session']['id_auteur'].'#'; |
|
| 321 | 321 | } |
| 322 | 322 | if (!empty($GLOBALS['visiteur_session']['nom'])) { |
| 323 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 323 | + $qui .= ' #nom:'.$GLOBALS['visiteur_session']['nom'].'#'; |
|
| 324 | 324 | } |
| 325 | 325 | if ($qui == '') { |
| 326 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 326 | + $qui = '#ip:'.$GLOBALS['ip'].'#'; |
|
| 327 | 327 | } |
| 328 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 328 | + journal(_L($qui.' a édité '.$objet.' '.$id_objet.' ('.join( |
|
| 329 | 329 | '+', |
| 330 | 330 | array_diff(array_keys($champs), ['date_modif']) |
| 331 | - ) . ')'), [ |
|
| 331 | + ).')'), [ |
|
| 332 | 332 | 'faire' => 'modifier', |
| 333 | 333 | 'quoi' => $objet, |
| 334 | 334 | 'id' => $id_objet |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -39,28 +39,28 @@ discard block |
||
| 39 | 39 | * Tableau des champs et valeurs collectées |
| 40 | 40 | */ |
| 41 | 41 | function collecter_requests($include_list, $exclude_list = [], $set = null, $tous = false) { |
| 42 | - $c = $set; |
|
| 43 | - if (!$c) { |
|
| 44 | - $c = []; |
|
| 45 | - foreach ($include_list as $champ) { |
|
| 46 | - // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | - // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | - $val = _request($champ); |
|
| 49 | - if ($tous or $val !== null) { |
|
| 50 | - $c[$champ] = $val; |
|
| 51 | - } |
|
| 52 | - } |
|
| 53 | - // on ajoute toujours la lang en saisie possible |
|
| 54 | - // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | - if ($l = _request('changer_lang')) { |
|
| 56 | - $c['lang'] = $l; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - foreach ($exclude_list as $champ) { |
|
| 60 | - unset($c[$champ]); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - return $c; |
|
| 42 | + $c = $set; |
|
| 43 | + if (!$c) { |
|
| 44 | + $c = []; |
|
| 45 | + foreach ($include_list as $champ) { |
|
| 46 | + // on ne collecte que les champs reellement envoyes par defaut. |
|
| 47 | + // le cas d'un envoi de valeur NULL peut du coup poser probleme. |
|
| 48 | + $val = _request($champ); |
|
| 49 | + if ($tous or $val !== null) { |
|
| 50 | + $c[$champ] = $val; |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | + // on ajoute toujours la lang en saisie possible |
|
| 54 | + // meme si pas prevu au depart pour l'objet concerne |
|
| 55 | + if ($l = _request('changer_lang')) { |
|
| 56 | + $c['lang'] = $l; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + foreach ($exclude_list as $champ) { |
|
| 60 | + unset($c[$champ]); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + return $c; |
|
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | /** |
@@ -97,262 +97,262 @@ discard block |
||
| 97 | 97 | * - chaîne : texte d'un message d'erreur |
| 98 | 98 | */ |
| 99 | 99 | function objet_modifier_champs($objet, $id_objet, $options, $c = null, $serveur = '') { |
| 100 | - if (!$id_objet = intval($id_objet)) { |
|
| 101 | - spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | - |
|
| 103 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - include_spip('inc/filtres'); |
|
| 107 | - |
|
| 108 | - $table_objet = table_objet($objet, $serveur); |
|
| 109 | - $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | - $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | - $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | - |
|
| 114 | - // Appels incomplets (sans $c) |
|
| 115 | - if (!is_array($c)) { |
|
| 116 | - spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | - |
|
| 118 | - return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | - } |
|
| 120 | - |
|
| 121 | - // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | - // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | - // il faut passer par instituer_XX() |
|
| 124 | - // TODO: faut-il passer ces variables interdites |
|
| 125 | - // dans un fichier de description separe ? |
|
| 126 | - unset($c['statut']); |
|
| 127 | - unset($c['id_parent']); |
|
| 128 | - unset($c['id_rubrique']); |
|
| 129 | - unset($c['id_secteur']); |
|
| 130 | - |
|
| 131 | - // Gerer les champs non vides |
|
| 132 | - if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | - foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | - if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | - $c[$champ] = $sinon; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - // N'accepter que les champs qui existent dans la table |
|
| 141 | - $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | - // et dont la valeur n'est pas null |
|
| 143 | - $champs = array_filter($champs, static function ($var) { |
|
| 144 | - return $var !== null; |
|
| 145 | - }); |
|
| 146 | - // TODO: ici aussi on peut valider les contenus |
|
| 147 | - // en fonction du type |
|
| 148 | - |
|
| 149 | - // Nettoyer les valeurs |
|
| 150 | - $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | - |
|
| 152 | - // On récupère l'état avant toute modification |
|
| 153 | - $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | - |
|
| 155 | - // Envoyer aux plugins |
|
| 156 | - $champs = pipeline( |
|
| 157 | - 'pre_edition', |
|
| 158 | - [ |
|
| 159 | - 'args' => [ |
|
| 160 | - 'table' => $spip_table_objet, // compatibilite |
|
| 161 | - 'table_objet' => $table_objet, |
|
| 162 | - 'spip_table_objet' => $spip_table_objet, |
|
| 163 | - 'desc' => $desc, |
|
| 164 | - 'type' => $objet, |
|
| 165 | - 'id_objet' => $id_objet, |
|
| 166 | - 'data' => $options['data'] ?? null, |
|
| 167 | - 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | - 'serveur' => $serveur, |
|
| 170 | - 'action' => $options['action'] ?? 'modifier' |
|
| 171 | - ], |
|
| 172 | - 'data' => $champs |
|
| 173 | - ] |
|
| 174 | - ); |
|
| 175 | - |
|
| 176 | - if (!$champs) { |
|
| 177 | - return false; |
|
| 178 | - } |
|
| 179 | - |
|
| 180 | - |
|
| 181 | - // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | - include_spip('inc/config'); |
|
| 183 | - if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | - include_spip('inc/drapeau_edition'); |
|
| 185 | - signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | - include_spip('inc/editer'); |
|
| 190 | - if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | - $options['data'] = &$_POST; |
|
| 192 | - } |
|
| 193 | - $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | - // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | - // et gere l'interface |
|
| 196 | - // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | - if ($conflits) { |
|
| 198 | - return _T('titre_conflit_edition'); |
|
| 199 | - } |
|
| 200 | - |
|
| 201 | - if ($champs) { |
|
| 202 | - // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | - if (isset($champs['lang'])) { |
|
| 204 | - if ($changer_lang = $champs['lang']) { |
|
| 205 | - $id_rubrique = 0; |
|
| 206 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | - $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | - $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | - } |
|
| 210 | - $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | - $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | - } |
|
| 213 | - // on laisse 'lang' dans $champs, |
|
| 214 | - // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | - // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | - // deja pris en compte |
|
| 217 | - } |
|
| 218 | - |
|
| 219 | - // la modif peut avoir lieu |
|
| 220 | - |
|
| 221 | - // faut-il ajouter date_modif ? |
|
| 222 | - if ( |
|
| 223 | - !empty($options['date_modif']) |
|
| 224 | - and !isset($champs[$options['date_modif']]) |
|
| 225 | - ) { |
|
| 226 | - $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // allez on commit la modif |
|
| 230 | - sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | - |
|
| 232 | - // on verifie si elle est bien passee |
|
| 233 | - $moof = sql_fetsel( |
|
| 234 | - array_keys($champs), |
|
| 235 | - $spip_table_objet, |
|
| 236 | - "$id_table_objet=" . intval($id_objet), |
|
| 237 | - [], |
|
| 238 | - [], |
|
| 239 | - '', |
|
| 240 | - [], |
|
| 241 | - $serveur |
|
| 242 | - ); |
|
| 243 | - // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | - if ($moof != $champs) { |
|
| 245 | - $liste = []; |
|
| 246 | - foreach ($moof as $k => $v) { |
|
| 247 | - if ( |
|
| 248 | - $v !== $champs[$k] |
|
| 249 | - // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | - and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | - // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | - and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | - ) { |
|
| 254 | - $liste[] = $k; |
|
| 255 | - $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | - $conflits[$k]['save'] = $v; |
|
| 257 | - |
|
| 258 | - // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | - // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | - if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | - include_spip('inc/charsets'); |
|
| 262 | - if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | - array_pop($liste); |
|
| 264 | - } |
|
| 265 | - } |
|
| 266 | - } |
|
| 267 | - } |
|
| 268 | - // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | - // c'est un cas exceptionnel |
|
| 270 | - if (count($liste)) { |
|
| 271 | - spip_log( |
|
| 272 | - "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | - 'modifier.' . _LOG_CRITIQUE |
|
| 274 | - ); |
|
| 275 | - |
|
| 276 | - return _T( |
|
| 277 | - 'erreur_technique_enregistrement_champs', |
|
| 278 | - ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | - ); |
|
| 280 | - } |
|
| 281 | - } |
|
| 282 | - |
|
| 283 | - // Invalider les caches |
|
| 284 | - if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | - include_spip('inc/invalideur'); |
|
| 286 | - if (is_array($options['invalideur'])) { |
|
| 287 | - array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | - } else { |
|
| 289 | - suivre_invalideur($options['invalideur']); |
|
| 290 | - } |
|
| 291 | - } |
|
| 292 | - |
|
| 293 | - // Notifications, gestion des revisions... |
|
| 294 | - // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | - pipeline( |
|
| 296 | - 'post_edition', |
|
| 297 | - [ |
|
| 298 | - 'args' => [ |
|
| 299 | - 'table' => $spip_table_objet, |
|
| 300 | - 'table_objet' => $table_objet, |
|
| 301 | - 'spip_table_objet' => $spip_table_objet, |
|
| 302 | - 'desc' => $desc, |
|
| 303 | - 'type' => $objet, |
|
| 304 | - 'id_objet' => $id_objet, |
|
| 305 | - 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | - 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | - 'serveur' => $serveur, |
|
| 308 | - 'action' => $options['action'] ?? 'modifier' |
|
| 309 | - ], |
|
| 310 | - 'data' => $champs |
|
| 311 | - ] |
|
| 312 | - ); |
|
| 313 | - } |
|
| 100 | + if (!$id_objet = intval($id_objet)) { |
|
| 101 | + spip_log('Erreur $id_objet non defini', 'warn'); |
|
| 102 | + |
|
| 103 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + include_spip('inc/filtres'); |
|
| 107 | + |
|
| 108 | + $table_objet = table_objet($objet, $serveur); |
|
| 109 | + $spip_table_objet = table_objet_sql($objet, $serveur); |
|
| 110 | + $id_table_objet = id_table_objet($objet, $serveur); |
|
| 111 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 112 | + $desc = $trouver_table($spip_table_objet, $serveur); |
|
| 113 | + |
|
| 114 | + // Appels incomplets (sans $c) |
|
| 115 | + if (!is_array($c)) { |
|
| 116 | + spip_log('erreur appel objet_modifier_champs(' . $objet . '), manque $c'); |
|
| 117 | + |
|
| 118 | + return _T('erreur_technique_enregistrement_impossible'); |
|
| 119 | + } |
|
| 120 | + |
|
| 121 | + // Securite : certaines variables ne sont jamais acceptees ici |
|
| 122 | + // car elles ne relevent pas de autoriser(xxx, modifier) ; |
|
| 123 | + // il faut passer par instituer_XX() |
|
| 124 | + // TODO: faut-il passer ces variables interdites |
|
| 125 | + // dans un fichier de description separe ? |
|
| 126 | + unset($c['statut']); |
|
| 127 | + unset($c['id_parent']); |
|
| 128 | + unset($c['id_rubrique']); |
|
| 129 | + unset($c['id_secteur']); |
|
| 130 | + |
|
| 131 | + // Gerer les champs non vides |
|
| 132 | + if (isset($options['nonvide']) and is_array($options['nonvide'])) { |
|
| 133 | + foreach ($options['nonvide'] as $champ => $sinon) { |
|
| 134 | + if (isset($c[$champ]) and $c[$champ] === '') { |
|
| 135 | + $c[$champ] = $sinon; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + // N'accepter que les champs qui existent dans la table |
|
| 141 | + $champs = array_intersect_key($c, $desc['field']); |
|
| 142 | + // et dont la valeur n'est pas null |
|
| 143 | + $champs = array_filter($champs, static function ($var) { |
|
| 144 | + return $var !== null; |
|
| 145 | + }); |
|
| 146 | + // TODO: ici aussi on peut valider les contenus |
|
| 147 | + // en fonction du type |
|
| 148 | + |
|
| 149 | + // Nettoyer les valeurs |
|
| 150 | + $champs = array_map('corriger_caracteres', $champs); |
|
| 151 | + |
|
| 152 | + // On récupère l'état avant toute modification |
|
| 153 | + $row = sql_fetsel('*', $spip_table_objet, $id_table_objet . '=' . $id_objet); |
|
| 154 | + |
|
| 155 | + // Envoyer aux plugins |
|
| 156 | + $champs = pipeline( |
|
| 157 | + 'pre_edition', |
|
| 158 | + [ |
|
| 159 | + 'args' => [ |
|
| 160 | + 'table' => $spip_table_objet, // compatibilite |
|
| 161 | + 'table_objet' => $table_objet, |
|
| 162 | + 'spip_table_objet' => $spip_table_objet, |
|
| 163 | + 'desc' => $desc, |
|
| 164 | + 'type' => $objet, |
|
| 165 | + 'id_objet' => $id_objet, |
|
| 166 | + 'data' => $options['data'] ?? null, |
|
| 167 | + 'champs' => $options['champs'] ?? [], // [doc] c'est quoi ? |
|
| 168 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 169 | + 'serveur' => $serveur, |
|
| 170 | + 'action' => $options['action'] ?? 'modifier' |
|
| 171 | + ], |
|
| 172 | + 'data' => $champs |
|
| 173 | + ] |
|
| 174 | + ); |
|
| 175 | + |
|
| 176 | + if (!$champs) { |
|
| 177 | + return false; |
|
| 178 | + } |
|
| 179 | + |
|
| 180 | + |
|
| 181 | + // marquer le fait que l'objet est travaille par toto a telle date |
|
| 182 | + include_spip('inc/config'); |
|
| 183 | + if (lire_config('articles_modif', 'non') !== 'non') { |
|
| 184 | + include_spip('inc/drapeau_edition'); |
|
| 185 | + signale_edition($id_objet, $GLOBALS['visiteur_session'], $objet); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + // Verifier si les mises a jour sont pertinentes, datees, en conflit etc |
|
| 189 | + include_spip('inc/editer'); |
|
| 190 | + if (!isset($options['data']) or is_null($options['data'])) { |
|
| 191 | + $options['data'] = &$_POST; |
|
| 192 | + } |
|
| 193 | + $conflits = controler_md5($champs, $options['data'], $objet, $id_objet, $serveur); |
|
| 194 | + // cas hypothetique : normalement inc/editer verifie en amont le conflit edition |
|
| 195 | + // et gere l'interface |
|
| 196 | + // ici on ne renvoie donc qu'un messsage d'erreur, au cas ou on y arrive quand meme |
|
| 197 | + if ($conflits) { |
|
| 198 | + return _T('titre_conflit_edition'); |
|
| 199 | + } |
|
| 200 | + |
|
| 201 | + if ($champs) { |
|
| 202 | + // cas particulier de la langue : passer par instituer_langue_objet |
|
| 203 | + if (isset($champs['lang'])) { |
|
| 204 | + if ($changer_lang = $champs['lang']) { |
|
| 205 | + $id_rubrique = 0; |
|
| 206 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 207 | + $parent = ($objet == 'rubrique') ? 'id_parent' : 'id_rubrique'; |
|
| 208 | + $id_rubrique = sql_getfetsel($parent, $spip_table_objet, "$id_table_objet=" . intval($id_objet)); |
|
| 209 | + } |
|
| 210 | + $instituer_langue_objet = charger_fonction('instituer_langue_objet', 'action'); |
|
| 211 | + $champs['lang'] = $instituer_langue_objet($objet, $id_objet, $id_rubrique, $changer_lang, $serveur); |
|
| 212 | + } |
|
| 213 | + // on laisse 'lang' dans $champs, |
|
| 214 | + // ca permet de passer dans le pipeline post_edition et de journaliser |
|
| 215 | + // et ca ne gene pas qu'on refasse un sql_updateq dessus apres l'avoir |
|
| 216 | + // deja pris en compte |
|
| 217 | + } |
|
| 218 | + |
|
| 219 | + // la modif peut avoir lieu |
|
| 220 | + |
|
| 221 | + // faut-il ajouter date_modif ? |
|
| 222 | + if ( |
|
| 223 | + !empty($options['date_modif']) |
|
| 224 | + and !isset($champs[$options['date_modif']]) |
|
| 225 | + ) { |
|
| 226 | + $champs[$options['date_modif']] = date('Y-m-d H:i:s'); |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // allez on commit la modif |
|
| 230 | + sql_updateq($spip_table_objet, $champs, "$id_table_objet=" . intval($id_objet), [], $serveur); |
|
| 231 | + |
|
| 232 | + // on verifie si elle est bien passee |
|
| 233 | + $moof = sql_fetsel( |
|
| 234 | + array_keys($champs), |
|
| 235 | + $spip_table_objet, |
|
| 236 | + "$id_table_objet=" . intval($id_objet), |
|
| 237 | + [], |
|
| 238 | + [], |
|
| 239 | + '', |
|
| 240 | + [], |
|
| 241 | + $serveur |
|
| 242 | + ); |
|
| 243 | + // si difference entre les champs, reperer les champs mal enregistres |
|
| 244 | + if ($moof != $champs) { |
|
| 245 | + $liste = []; |
|
| 246 | + foreach ($moof as $k => $v) { |
|
| 247 | + if ( |
|
| 248 | + $v !== $champs[$k] |
|
| 249 | + // ne pas alerter si le champ est numerique est que les valeurs sont equivalentes |
|
| 250 | + and (!is_numeric($v) or intval($v) !== intval($champs[$k])) |
|
| 251 | + // ne pas alerter si le champ est date, qu'on a envoye une valeur vide et qu'on recupere une date nulle |
|
| 252 | + and (strlen($champs[$k]) or !in_array($v, ['0000-00-00 00:00:00', '0000-00-00'])) |
|
| 253 | + ) { |
|
| 254 | + $liste[] = $k; |
|
| 255 | + $conflits[$k]['post'] = $champs[$k]; |
|
| 256 | + $conflits[$k]['save'] = $v; |
|
| 257 | + |
|
| 258 | + // cas specifique MySQL+emoji : si l'un est la |
|
| 259 | + // conversion utf8_noplanes de l'autre alors c'est OK |
|
| 260 | + if (defined('_MYSQL_NOPLANES') && _MYSQL_NOPLANES) { |
|
| 261 | + include_spip('inc/charsets'); |
|
| 262 | + if ($v == utf8_noplanes($champs[$k])) { |
|
| 263 | + array_pop($liste); |
|
| 264 | + } |
|
| 265 | + } |
|
| 266 | + } |
|
| 267 | + } |
|
| 268 | + // si un champ n'a pas ete correctement enregistre, loger et retourner une erreur |
|
| 269 | + // c'est un cas exceptionnel |
|
| 270 | + if (count($liste)) { |
|
| 271 | + spip_log( |
|
| 272 | + "Erreur enregistrement en base $objet/$id_objet champs :" . var_export($conflits, true), |
|
| 273 | + 'modifier.' . _LOG_CRITIQUE |
|
| 274 | + ); |
|
| 275 | + |
|
| 276 | + return _T( |
|
| 277 | + 'erreur_technique_enregistrement_champs', |
|
| 278 | + ['champs' => "<i>'" . implode("'</i>,<i>'", $liste) . "'</i>"] |
|
| 279 | + ); |
|
| 280 | + } |
|
| 281 | + } |
|
| 282 | + |
|
| 283 | + // Invalider les caches |
|
| 284 | + if (isset($options['invalideur']) and $options['invalideur']) { |
|
| 285 | + include_spip('inc/invalideur'); |
|
| 286 | + if (is_array($options['invalideur'])) { |
|
| 287 | + array_map('suivre_invalideur', $options['invalideur']); |
|
| 288 | + } else { |
|
| 289 | + suivre_invalideur($options['invalideur']); |
|
| 290 | + } |
|
| 291 | + } |
|
| 292 | + |
|
| 293 | + // Notifications, gestion des revisions... |
|
| 294 | + // en standard, appelle |nouvelle_revision ci-dessous |
|
| 295 | + pipeline( |
|
| 296 | + 'post_edition', |
|
| 297 | + [ |
|
| 298 | + 'args' => [ |
|
| 299 | + 'table' => $spip_table_objet, |
|
| 300 | + 'table_objet' => $table_objet, |
|
| 301 | + 'spip_table_objet' => $spip_table_objet, |
|
| 302 | + 'desc' => $desc, |
|
| 303 | + 'type' => $objet, |
|
| 304 | + 'id_objet' => $id_objet, |
|
| 305 | + 'champs' => $options['champs'] ?? [], // [doc] kesako ? |
|
| 306 | + 'champs_anciens' => $row, // état du contenu avant modif |
|
| 307 | + 'serveur' => $serveur, |
|
| 308 | + 'action' => $options['action'] ?? 'modifier' |
|
| 309 | + ], |
|
| 310 | + 'data' => $champs |
|
| 311 | + ] |
|
| 312 | + ); |
|
| 313 | + } |
|
| 314 | 314 | |
| 315 | - // Appeler une notification |
|
| 316 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | - $notifications( |
|
| 318 | - "{$objet}_modifier", |
|
| 319 | - $id_objet, |
|
| 320 | - [ |
|
| 321 | - 'champs' => $champs, |
|
| 322 | - ] |
|
| 323 | - ); |
|
| 324 | - $notifications( |
|
| 325 | - 'objet_modifier', |
|
| 326 | - $id_objet, |
|
| 327 | - [ |
|
| 328 | - 'objet' => $objet, |
|
| 329 | - 'id_objet' => $id_objet, |
|
| 330 | - 'champs' => $champs, |
|
| 331 | - ] |
|
| 332 | - ); |
|
| 333 | - } |
|
| 334 | - |
|
| 335 | - // journaliser l'affaire |
|
| 336 | - // message a affiner :-) |
|
| 337 | - include_spip('inc/filtres_mini'); |
|
| 338 | - $qui = ''; |
|
| 339 | - if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | - $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | - } |
|
| 342 | - if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | - $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | - } |
|
| 345 | - if ($qui == '') { |
|
| 346 | - $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | - } |
|
| 348 | - journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | - '+', |
|
| 350 | - array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | - ) . ')'), [ |
|
| 352 | - 'faire' => 'modifier', |
|
| 353 | - 'quoi' => $objet, |
|
| 354 | - 'id' => $id_objet |
|
| 355 | - ]); |
|
| 356 | - |
|
| 357 | - return ''; |
|
| 315 | + // Appeler une notification |
|
| 316 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 317 | + $notifications( |
|
| 318 | + "{$objet}_modifier", |
|
| 319 | + $id_objet, |
|
| 320 | + [ |
|
| 321 | + 'champs' => $champs, |
|
| 322 | + ] |
|
| 323 | + ); |
|
| 324 | + $notifications( |
|
| 325 | + 'objet_modifier', |
|
| 326 | + $id_objet, |
|
| 327 | + [ |
|
| 328 | + 'objet' => $objet, |
|
| 329 | + 'id_objet' => $id_objet, |
|
| 330 | + 'champs' => $champs, |
|
| 331 | + ] |
|
| 332 | + ); |
|
| 333 | + } |
|
| 334 | + |
|
| 335 | + // journaliser l'affaire |
|
| 336 | + // message a affiner :-) |
|
| 337 | + include_spip('inc/filtres_mini'); |
|
| 338 | + $qui = ''; |
|
| 339 | + if (!empty($GLOBALS['visiteur_session']['id_auteur'])) { |
|
| 340 | + $qui .= ' #id_auteur:' . $GLOBALS['visiteur_session']['id_auteur'] . '#'; |
|
| 341 | + } |
|
| 342 | + if (!empty($GLOBALS['visiteur_session']['nom'])) { |
|
| 343 | + $qui .= ' #nom:' . $GLOBALS['visiteur_session']['nom'] . '#'; |
|
| 344 | + } |
|
| 345 | + if ($qui == '') { |
|
| 346 | + $qui = '#ip:' . $GLOBALS['ip'] . '#'; |
|
| 347 | + } |
|
| 348 | + journal(_L($qui . ' a édité ' . $objet . ' ' . $id_objet . ' (' . join( |
|
| 349 | + '+', |
|
| 350 | + array_diff(array_keys($champs), ['date_modif']) |
|
| 351 | + ) . ')'), [ |
|
| 352 | + 'faire' => 'modifier', |
|
| 353 | + 'quoi' => $objet, |
|
| 354 | + 'id' => $id_objet |
|
| 355 | + ]); |
|
| 356 | + |
|
| 357 | + return ''; |
|
| 358 | 358 | } |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | $row = sql_fetsel( |
| 50 | 50 | '*', |
| 51 | 51 | 'spip_auteurs', |
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 52 | + 'login='.sql_quote($login, $serveur, 'text')." AND statut<>'5poubelle'", |
|
| 53 | 53 | '', |
| 54 | 54 | '', |
| 55 | 55 | '', |
@@ -77,20 +77,20 @@ discard block |
||
| 77 | 77 | // legacy = md5 ou sha256 |
| 78 | 78 | case 32: |
| 79 | 79 | // tres anciens mots de passe encodes en md5(alea.pass) |
| 80 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $hash = md5($row['alea_actuel'].$pass); |
|
| 81 | 81 | $methode = 'md5'; |
| 82 | 82 | case 64: |
| 83 | 83 | if (empty($hash)) { |
| 84 | 84 | // anciens mots de passe encodes en sha256(alea.pass) |
| 85 | 85 | include_spip('auth/sha256.inc'); |
| 86 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $hash = spip_sha256($row['alea_actuel'].$pass); |
|
| 87 | 87 | $methode = 'sha256'; |
| 88 | 88 | } |
| 89 | 89 | if ($row['pass'] === $hash) { |
| 90 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via $methode", 'auth'._LOG_DEBUG); |
|
| 91 | 91 | // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
| 92 | 92 | if (!empty($row['backup_cles'])) { |
| 93 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 94 | 94 | } |
| 95 | 95 | break; |
| 96 | 96 | } |
@@ -108,19 +108,19 @@ discard block |
||
| 108 | 108 | and !empty($row['backup_cles']) |
| 109 | 109 | ) { |
| 110 | 110 | if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
| 111 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #'.$row['id_auteur'], 'auth'._LOG_INFO_IMPORTANTE); |
|
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | 114 | } |
| 115 | 115 | else { |
| 116 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 117 | 117 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | 121 | else { |
| 122 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 123 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 122 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #'.$row['id_auteur']." n'est pas valide", 'auth'._LOG_ERREUR); |
|
| 123 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur='.intval($row['id_auteur'])); |
|
| 124 | 124 | } |
| 125 | 125 | } |
| 126 | 126 | |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | unset($row); |
| 129 | 129 | } |
| 130 | 130 | else { |
| 131 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + spip_log("validation du mot de passe pour l'auteur #".$row['id_auteur']." $login via Password::verifier", 'auth'._LOG_DEBUG); |
|
| 132 | 132 | } |
| 133 | 133 | break; |
| 134 | 134 | } |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | @sql_update( |
| 176 | 176 | 'spip_auteurs', |
| 177 | 177 | $set, |
| 178 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + 'id_auteur='.intval($row['id_auteur']).' AND pass='.sql_quote( |
|
| 179 | 179 | $row['pass'], |
| 180 | 180 | $serveur, |
| 181 | 181 | 'text' |
@@ -223,24 +223,24 @@ discard block |
||
| 223 | 223 | |
| 224 | 224 | // si force, on ne verifie pas la presence d'un backup chez un webmestre |
| 225 | 225 | if ($force) { |
| 226 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 226 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth'._LOG_INFO_IMPORTANTE); |
|
| 227 | 227 | $secret = $cles->getSecretAuth(true); |
| 228 | 228 | return true; |
| 229 | 229 | } |
| 230 | 230 | |
| 231 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 231 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut='.sql_quote('0minirezo').' AND webmestre='.sql_quote('oui')." AND backup_cles!=''"); |
|
| 232 | 232 | $has_backup = array_column($has_backup, 'id_auteur'); |
| 233 | 233 | if (empty($has_backup)) { |
| 234 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 234 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth'._LOG_INFO_IMPORTANTE); |
|
| 235 | 235 | if ($secret = $cles->getSecretAuth(true)) { |
| 236 | 236 | return true; |
| 237 | 237 | } |
| 238 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 238 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth'._LOG_ERREUR); |
|
| 239 | 239 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 240 | + raler_fichier(_DIR_ETC.'cles.php'); |
|
| 241 | 241 | } |
| 242 | 242 | else { |
| 243 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 243 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #'.implode(', #', $has_backup).' doit se connecter pour restaurer son backup des cles', 'auth'._LOG_ERREUR); |
|
| 244 | 244 | } |
| 245 | 245 | return false; |
| 246 | 246 | } |
@@ -257,8 +257,8 @@ discard block |
||
| 257 | 257 | $flux['data'] .= |
| 258 | 258 | '<script type="text/javascript">/*<![CDATA[*/' |
| 259 | 259 | . "$js\n" |
| 260 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 261 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "var login_info={'login':'".$flux['args']['contexte']['var_login']."'," |
|
| 261 | + . "'page_auteur': '".generer_url_public('informer_auteur')."'," |
|
| 262 | 262 | . "'informe_auteur_en_cours':false," |
| 263 | 263 | . "'attente_informe':0};" |
| 264 | 264 | . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | } else { |
| 302 | 302 | $n = sql_countsel( |
| 303 | 303 | 'spip_auteurs', |
| 304 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 304 | + 'login='.sql_quote($new_login).' AND id_auteur!='.intval($id_auteur)." AND statut!='5poubelle'", |
|
| 305 | 305 | '', |
| 306 | 306 | '', |
| 307 | 307 | $serveur |
@@ -329,7 +329,7 @@ discard block |
||
| 329 | 329 | } |
| 330 | 330 | if ( |
| 331 | 331 | !$id_auteur = intval($id_auteur) |
| 332 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 332 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 333 | 333 | ) { |
| 334 | 334 | return false; |
| 335 | 335 | } |
@@ -344,7 +344,7 @@ discard block |
||
| 344 | 344 | $anciens = sql_allfetsel( |
| 345 | 345 | 'id_auteur', |
| 346 | 346 | 'spip_auteurs', |
| 347 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 347 | + 'login='.sql_quote($new_login, $serveur, 'text')." AND statut='5poubelle'", |
|
| 348 | 348 | '', |
| 349 | 349 | '', |
| 350 | 350 | '', |
@@ -378,8 +378,8 @@ discard block |
||
| 378 | 378 | $r = sql_getfetsel( |
| 379 | 379 | 'login', |
| 380 | 380 | 'spip_auteurs', |
| 381 | - "statut<>'5poubelle'" . |
|
| 382 | - ' AND (length(pass)>0)' . |
|
| 381 | + "statut<>'5poubelle'". |
|
| 382 | + ' AND (length(pass)>0)'. |
|
| 383 | 383 | " AND (login=$l)", |
| 384 | 384 | '', |
| 385 | 385 | '', |
@@ -398,8 +398,8 @@ discard block |
||
| 398 | 398 | return sql_getfetsel( |
| 399 | 399 | 'login', |
| 400 | 400 | 'spip_auteurs', |
| 401 | - "statut<>'5poubelle'" . |
|
| 402 | - ' AND (length(pass)>0)' . |
|
| 401 | + "statut<>'5poubelle'". |
|
| 402 | + ' AND (length(pass)>0)'. |
|
| 403 | 403 | " AND (login<>'' AND (nom=$l OR email=$l))", |
| 404 | 404 | '', |
| 405 | 405 | '', |
@@ -468,7 +468,7 @@ discard block |
||
| 468 | 468 | |
| 469 | 469 | if ( |
| 470 | 470 | !$id_auteur = intval($id_auteur) |
| 471 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 471 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur='.intval($id_auteur), '', '', '', '', $serveur) |
|
| 472 | 472 | ) { |
| 473 | 473 | return false; |
| 474 | 474 | } |
@@ -529,8 +529,8 @@ discard block |
||
| 529 | 529 | or isset($champs['statut']) |
| 530 | 530 | or (isset($options['all']) and $options['all']) |
| 531 | 531 | ) { |
| 532 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 533 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 532 | + $htaccess = _DIR_RESTREINT._ACCESS_FILE_NAME; |
|
| 533 | + $htpasswd = _DIR_TMP._AUTH_USER_FILE; |
|
| 534 | 534 | |
| 535 | 535 | // Cette variable de configuration peut etre posee par un plugin |
| 536 | 536 | // par exemple acces_restreint ; |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | and !@file_exists($htaccess) |
| 541 | 541 | ) { |
| 542 | 542 | spip_unlink($htpasswd); |
| 543 | - spip_unlink($htpasswd . '-admin'); |
|
| 543 | + spip_unlink($htpasswd.'-admin'); |
|
| 544 | 544 | |
| 545 | 545 | return; |
| 546 | 546 | } |
@@ -558,16 +558,16 @@ discard block |
||
| 558 | 558 | ); |
| 559 | 559 | while ($t = sql_fetch($s)) { |
| 560 | 560 | if (strlen($t['login']) and strlen($t['htpass'])) { |
| 561 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + $p1 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 562 | 562 | if ($t['statut'] == '0minirezo') { |
| 563 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 563 | + $p2 .= $t['login'].':'.$t['htpass']."\n"; |
|
| 564 | 564 | } |
| 565 | 565 | } |
| 566 | 566 | } |
| 567 | 567 | sql_free($s); |
| 568 | 568 | if ($p1) { |
| 569 | 569 | ecrire_fichier($htpasswd, $p1); |
| 570 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 570 | + ecrire_fichier($htpasswd.'-admin', $p2); |
|
| 571 | 571 | spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
| 572 | 572 | } |
| 573 | 573 | } |
@@ -111,14 +111,12 @@ discard block |
||
| 111 | 111 | spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
| 112 | 112 | if ($cles->save()) { |
| 113 | 113 | $secret = $cles->getSecretAuth(); |
| 114 | - } |
|
| 115 | - else { |
|
| 114 | + } else { |
|
| 116 | 115 | spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 117 | 116 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 118 | 117 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 119 | 118 | } |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
| 123 | 121 | sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
| 124 | 122 | } |
@@ -126,8 +124,7 @@ discard block |
||
| 126 | 124 | |
| 127 | 125 | if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
| 128 | 126 | unset($row); |
| 129 | - } |
|
| 130 | - else { |
|
| 127 | + } else { |
|
| 131 | 128 | spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
| 132 | 129 | } |
| 133 | 130 | break; |
@@ -238,8 +235,7 @@ discard block |
||
| 238 | 235 | spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
| 239 | 236 | // et on echoue car on ne veut pas que la situation reste telle quelle |
| 240 | 237 | raler_fichier(_DIR_ETC . 'cles.php'); |
| 241 | - } |
|
| 242 | - else { |
|
| 238 | + } else { |
|
| 243 | 239 | spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
| 244 | 240 | } |
| 245 | 241 | return false; |
@@ -479,8 +475,7 @@ discard block |
||
| 479 | 475 | if (!$secret) { |
| 480 | 476 | if (auth_spip_initialiser_secret()) { |
| 481 | 477 | $secret = $cles->getSecretAuth(); |
| 482 | - } |
|
| 483 | - else { |
|
| 478 | + } else { |
|
| 484 | 479 | return false; |
| 485 | 480 | } |
| 486 | 481 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | use Spip\Chiffrer\SpipCles; |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -34,169 +34,169 @@ discard block |
||
| 34 | 34 | */ |
| 35 | 35 | function auth_spip_dist($login, $pass, $serveur = '', $phpauth = false) { |
| 36 | 36 | |
| 37 | - // retrouver le login |
|
| 38 | - $login = auth_spip_retrouver_login($login); |
|
| 39 | - // login inconnu, n'allons pas plus loin |
|
| 40 | - if (!$login) { |
|
| 41 | - return []; |
|
| 42 | - } |
|
| 43 | - |
|
| 44 | - $md5pass = ''; |
|
| 45 | - $shapass = $shanext = ''; |
|
| 46 | - $auteur_peut_sauver_cles = false; |
|
| 47 | - |
|
| 48 | - if ($pass) { |
|
| 49 | - $row = sql_fetsel( |
|
| 50 | - '*', |
|
| 51 | - 'spip_auteurs', |
|
| 52 | - 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | - '', |
|
| 54 | - '', |
|
| 55 | - '', |
|
| 56 | - '', |
|
| 57 | - $serveur |
|
| 58 | - ); |
|
| 59 | - |
|
| 60 | - // lever un flag si cet auteur peut sauver les cles |
|
| 61 | - if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | - $auteur_peut_sauver_cles = true; |
|
| 63 | - } |
|
| 64 | - } |
|
| 65 | - |
|
| 66 | - // login inexistant ou mot de passe vide |
|
| 67 | - if (!$pass or !$row) { |
|
| 68 | - return []; |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - $cles = SpipCles::instance(); |
|
| 72 | - $secret = $cles->getSecretAuth(); |
|
| 73 | - |
|
| 74 | - $hash = null; |
|
| 75 | - switch (strlen($row['pass'])) { |
|
| 76 | - // legacy = md5 ou sha256 |
|
| 77 | - case 32: |
|
| 78 | - // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | - $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | - $methode = 'md5'; |
|
| 81 | - case 64: |
|
| 82 | - if (empty($hash)) { |
|
| 83 | - // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | - include_spip('auth/sha256.inc'); |
|
| 85 | - $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | - $methode = 'sha256'; |
|
| 87 | - } |
|
| 88 | - if ($row['pass'] === $hash) { |
|
| 89 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | - // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 91 | - if (!empty($row['backup_cles'])) { |
|
| 92 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | - } |
|
| 94 | - break; |
|
| 95 | - } |
|
| 96 | - |
|
| 97 | - // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | - |
|
| 99 | - case 60: |
|
| 100 | - case 98: |
|
| 101 | - default: |
|
| 102 | - // doit-on restaurer un backup des cles ? |
|
| 103 | - // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | - if ( |
|
| 105 | - !$secret |
|
| 106 | - and $auteur_peut_sauver_cles |
|
| 107 | - and !empty($row['backup_cles']) |
|
| 108 | - ) { |
|
| 109 | - if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | - spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | - if ($cles->save()) { |
|
| 112 | - $secret = $cles->getSecretAuth(); |
|
| 113 | - } |
|
| 114 | - else { |
|
| 115 | - spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - else { |
|
| 121 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | - sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 123 | - } |
|
| 124 | - } |
|
| 125 | - |
|
| 126 | - if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | - unset($row); |
|
| 128 | - } |
|
| 129 | - else { |
|
| 130 | - spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | - } |
|
| 132 | - break; |
|
| 133 | - } |
|
| 134 | - |
|
| 135 | - // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | - // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | - // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | - // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 139 | - if (!$secret and $auteur_peut_sauver_cles) { |
|
| 140 | - if (auth_spip_initialiser_secret()) { |
|
| 141 | - $secret = $cles->getSecretAuth(); |
|
| 142 | - } |
|
| 143 | - } |
|
| 144 | - |
|
| 145 | - // login/mot de passe incorrect |
|
| 146 | - if (empty($row)) { |
|
| 147 | - return []; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // fait tourner le codage du pass dans la base |
|
| 151 | - // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | - if (!$phpauth and $secret) { |
|
| 153 | - include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | - $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | - if ($pass_hash_next) { |
|
| 156 | - $set = [ |
|
| 157 | - 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | - 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | - 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | - ]; |
|
| 161 | - |
|
| 162 | - // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | - // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | - $htpass = generer_htpass($pass); |
|
| 165 | - if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | - $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | - } |
|
| 168 | - |
|
| 169 | - // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | - if ($auteur_peut_sauver_cles) { |
|
| 171 | - $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - @sql_update( |
|
| 175 | - 'spip_auteurs', |
|
| 176 | - $set, |
|
| 177 | - 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | - $row['pass'], |
|
| 179 | - $serveur, |
|
| 180 | - 'text' |
|
| 181 | - ), |
|
| 182 | - [], |
|
| 183 | - $serveur |
|
| 184 | - ); |
|
| 185 | - |
|
| 186 | - // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | - if (isset($set['htpass'])) { |
|
| 188 | - ecrire_acces(); |
|
| 189 | - } |
|
| 190 | - } |
|
| 191 | - |
|
| 192 | - // En profiter pour verifier la securite de tmp/ |
|
| 193 | - // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | - if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | - return false; |
|
| 196 | - } |
|
| 197 | - } |
|
| 198 | - |
|
| 199 | - return $row; |
|
| 37 | + // retrouver le login |
|
| 38 | + $login = auth_spip_retrouver_login($login); |
|
| 39 | + // login inconnu, n'allons pas plus loin |
|
| 40 | + if (!$login) { |
|
| 41 | + return []; |
|
| 42 | + } |
|
| 43 | + |
|
| 44 | + $md5pass = ''; |
|
| 45 | + $shapass = $shanext = ''; |
|
| 46 | + $auteur_peut_sauver_cles = false; |
|
| 47 | + |
|
| 48 | + if ($pass) { |
|
| 49 | + $row = sql_fetsel( |
|
| 50 | + '*', |
|
| 51 | + 'spip_auteurs', |
|
| 52 | + 'login=' . sql_quote($login, $serveur, 'text') . " AND statut<>'5poubelle'", |
|
| 53 | + '', |
|
| 54 | + '', |
|
| 55 | + '', |
|
| 56 | + '', |
|
| 57 | + $serveur |
|
| 58 | + ); |
|
| 59 | + |
|
| 60 | + // lever un flag si cet auteur peut sauver les cles |
|
| 61 | + if ($row['statut'] === '0minirezo' and $row['webmestre'] === 'oui' and isset($row['backup_cles'])) { |
|
| 62 | + $auteur_peut_sauver_cles = true; |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | + |
|
| 66 | + // login inexistant ou mot de passe vide |
|
| 67 | + if (!$pass or !$row) { |
|
| 68 | + return []; |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + $cles = SpipCles::instance(); |
|
| 72 | + $secret = $cles->getSecretAuth(); |
|
| 73 | + |
|
| 74 | + $hash = null; |
|
| 75 | + switch (strlen($row['pass'])) { |
|
| 76 | + // legacy = md5 ou sha256 |
|
| 77 | + case 32: |
|
| 78 | + // tres anciens mots de passe encodes en md5(alea.pass) |
|
| 79 | + $hash = md5($row['alea_actuel'] . $pass); |
|
| 80 | + $methode = 'md5'; |
|
| 81 | + case 64: |
|
| 82 | + if (empty($hash)) { |
|
| 83 | + // anciens mots de passe encodes en sha256(alea.pass) |
|
| 84 | + include_spip('auth/sha256.inc'); |
|
| 85 | + $hash = spip_sha256($row['alea_actuel'] . $pass); |
|
| 86 | + $methode = 'sha256'; |
|
| 87 | + } |
|
| 88 | + if ($row['pass'] === $hash) { |
|
| 89 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via $methode", 'auth' . _LOG_DEBUG); |
|
| 90 | + // ce n'est pas cense arriver, mais si jamais c'est un backup inutilisable, il faut le nettoyer pour ne pas bloquer la creation d'une nouvelle cle d'auth |
|
| 91 | + if (!empty($row['backup_cles'])) { |
|
| 92 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 93 | + } |
|
| 94 | + break; |
|
| 95 | + } |
|
| 96 | + |
|
| 97 | + // on teste la methode par defaut, au cas ou ce serait un pass moderne qui a la malchance d'etre en 64char de long |
|
| 98 | + |
|
| 99 | + case 60: |
|
| 100 | + case 98: |
|
| 101 | + default: |
|
| 102 | + // doit-on restaurer un backup des cles ? |
|
| 103 | + // si on a le bon pass on peut decoder le backup, retrouver la cle, et du coup valider le pass |
|
| 104 | + if ( |
|
| 105 | + !$secret |
|
| 106 | + and $auteur_peut_sauver_cles |
|
| 107 | + and !empty($row['backup_cles']) |
|
| 108 | + ) { |
|
| 109 | + if ($cles->restore($row['backup_cles'], $pass, $row['pass'], $row['id_auteur'])) { |
|
| 110 | + spip_log('Les cles secretes ont ete restaurées avec le backup du webmestre #' . $row['id_auteur'], 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 111 | + if ($cles->save()) { |
|
| 112 | + $secret = $cles->getSecretAuth(); |
|
| 113 | + } |
|
| 114 | + else { |
|
| 115 | + spip_log("Echec restauration des cles : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 116 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 117 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + else { |
|
| 121 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) mais le backup du webmestre #' . $row['id_auteur'] . " n'est pas valide", 'auth' . _LOG_ERREUR); |
|
| 122 | + sql_updateq('spip_auteurs', ['backup_cles' => ''], 'id_auteur=' . intval($row['id_auteur'])); |
|
| 123 | + } |
|
| 124 | + } |
|
| 125 | + |
|
| 126 | + if (!$secret or !Password::verifier($pass, $row['pass'], $secret)) { |
|
| 127 | + unset($row); |
|
| 128 | + } |
|
| 129 | + else { |
|
| 130 | + spip_log("validation du mot de passe pour l'auteur #" . $row['id_auteur'] . " $login via Password::verifier", 'auth' . _LOG_DEBUG); |
|
| 131 | + } |
|
| 132 | + break; |
|
| 133 | + } |
|
| 134 | + |
|
| 135 | + // Migration depuis ancienne version : si on a pas encore de cle |
|
| 136 | + // ET si c'est le login d'un auteur qui peut sauver la cle |
|
| 137 | + // créer la clé (en s'assurant bien que personne n'a de backup d'un precedent fichier cle.php) |
|
| 138 | + // si c'est un auteur normal, on ne fait rien, il garde son ancien pass hashé en sha256 en attendant le login d'un webmestre |
|
| 139 | + if (!$secret and $auteur_peut_sauver_cles) { |
|
| 140 | + if (auth_spip_initialiser_secret()) { |
|
| 141 | + $secret = $cles->getSecretAuth(); |
|
| 142 | + } |
|
| 143 | + } |
|
| 144 | + |
|
| 145 | + // login/mot de passe incorrect |
|
| 146 | + if (empty($row)) { |
|
| 147 | + return []; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // fait tourner le codage du pass dans la base |
|
| 151 | + // sauf si phpauth : cela reviendrait a changer l'alea a chaque hit, et aucune action verifiable par securiser_action() |
|
| 152 | + if (!$phpauth and $secret) { |
|
| 153 | + include_spip('inc/acces'); // pour creer_uniqid et verifier_htaccess |
|
| 154 | + $pass_hash_next = Password::hacher($pass, $secret); |
|
| 155 | + if ($pass_hash_next) { |
|
| 156 | + $set = [ |
|
| 157 | + 'alea_actuel' => 'alea_futur', // @deprecated 4.1 |
|
| 158 | + 'alea_futur' => sql_quote(creer_uniqid(), $serveur, 'text'), // @deprecated 4.1 |
|
| 159 | + 'pass' => sql_quote($pass_hash_next, $serveur, 'text'), |
|
| 160 | + ]; |
|
| 161 | + |
|
| 162 | + // regenerer un htpass si on a active/desactive le plugin htpasswd |
|
| 163 | + // et/ou que l'algo a change - pour etre certain de toujours utiliser le bon algo |
|
| 164 | + $htpass = generer_htpass($pass); |
|
| 165 | + if (strlen($htpass) !== strlen($row['htpass'])) { |
|
| 166 | + $set['htpass'] = sql_quote($htpass, $serveur, 'text'); |
|
| 167 | + } |
|
| 168 | + |
|
| 169 | + // a chaque login de webmestre : sauvegarde chiffree des clés du site (avec les pass du webmestre) |
|
| 170 | + if ($auteur_peut_sauver_cles) { |
|
| 171 | + $set['backup_cles'] = sql_quote($cles->backup($pass), $serveur, 'text'); |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + @sql_update( |
|
| 175 | + 'spip_auteurs', |
|
| 176 | + $set, |
|
| 177 | + 'id_auteur=' . intval($row['id_auteur']) . ' AND pass=' . sql_quote( |
|
| 178 | + $row['pass'], |
|
| 179 | + $serveur, |
|
| 180 | + 'text' |
|
| 181 | + ), |
|
| 182 | + [], |
|
| 183 | + $serveur |
|
| 184 | + ); |
|
| 185 | + |
|
| 186 | + // si on a change le htpass car changement d'algo, regenerer les fichiers htpasswd |
|
| 187 | + if (isset($set['htpass'])) { |
|
| 188 | + ecrire_acces(); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | + |
|
| 192 | + // En profiter pour verifier la securite de tmp/ |
|
| 193 | + // Si elle ne fonctionne pas a l'installation, prevenir |
|
| 194 | + if (!verifier_htaccess(_DIR_TMP) and defined('_ECRIRE_INSTALL')) { |
|
| 195 | + return false; |
|
| 196 | + } |
|
| 197 | + } |
|
| 198 | + |
|
| 199 | + return $row; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -211,36 +211,36 @@ discard block |
||
| 211 | 211 | * @return bool |
| 212 | 212 | */ |
| 213 | 213 | function auth_spip_initialiser_secret(bool $force = false): bool { |
| 214 | - $cles = SpipCles::instance(); |
|
| 215 | - $secret = $cles->getSecretAuth(); |
|
| 216 | - |
|
| 217 | - // on ne fait rien si on a un secret dispo |
|
| 218 | - if ($secret) { |
|
| 219 | - return false; |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | - if ($force) { |
|
| 224 | - spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | - $secret = $cles->getSecretAuth(true); |
|
| 226 | - return true; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | - $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | - if (empty($has_backup)) { |
|
| 232 | - spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 233 | - if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | - return true; |
|
| 235 | - } |
|
| 236 | - spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | - // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | - raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | - } |
|
| 240 | - else { |
|
| 241 | - spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 242 | - } |
|
| 243 | - return false; |
|
| 214 | + $cles = SpipCles::instance(); |
|
| 215 | + $secret = $cles->getSecretAuth(); |
|
| 216 | + |
|
| 217 | + // on ne fait rien si on a un secret dispo |
|
| 218 | + if ($secret) { |
|
| 219 | + return false; |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // si force, on ne verifie pas la presence d'un backup chez un webmestre |
|
| 223 | + if ($force) { |
|
| 224 | + spip_log('Pas de cle secrete disponible, on regenere une nouvelle cle forcee - tous les mots de passe sont invalides', 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 225 | + $secret = $cles->getSecretAuth(true); |
|
| 226 | + return true; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + $has_backup = sql_allfetsel('id_auteur', 'spip_auteurs', 'statut=' . sql_quote('0minirezo') . ' AND webmestre=' . sql_quote('oui') . " AND backup_cles!=''"); |
|
| 230 | + $has_backup = array_column($has_backup, 'id_auteur'); |
|
| 231 | + if (empty($has_backup)) { |
|
| 232 | + spip_log("Pas de cle secrete disponible, et aucun webmestre n'a de backup, on regenere une nouvelle cle - tous les mots de passe sont invalides", 'auth' . _LOG_INFO_IMPORTANTE); |
|
| 233 | + if ($secret = $cles->getSecretAuth(true)) { |
|
| 234 | + return true; |
|
| 235 | + } |
|
| 236 | + spip_log("Echec generation d'une nouvelle cle : verifier les droits d'ecriture ?", 'auth' . _LOG_ERREUR); |
|
| 237 | + // et on echoue car on ne veut pas que la situation reste telle quelle |
|
| 238 | + raler_fichier(_DIR_ETC . 'cles.php'); |
|
| 239 | + } |
|
| 240 | + else { |
|
| 241 | + spip_log('Pas de cle secrete disponible (fichier config/cle.php absent ?) un des webmestres #' . implode(', #', $has_backup) . ' doit se connecter pour restaurer son backup des cles', 'auth' . _LOG_ERREUR); |
|
| 242 | + } |
|
| 243 | + return false; |
|
| 244 | 244 | } |
| 245 | 245 | |
| 246 | 246 | /** |
@@ -250,19 +250,19 @@ discard block |
||
| 250 | 250 | * @return array |
| 251 | 251 | */ |
| 252 | 252 | function auth_spip_formulaire_login($flux) { |
| 253 | - // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | - $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | - $flux['data'] .= |
|
| 256 | - '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | - . "$js\n" |
|
| 258 | - . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | - . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | - . "'informe_auteur_en_cours':false," |
|
| 261 | - . "'attente_informe':0};" |
|
| 262 | - . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | - . '/*]]>*/</script>'; |
|
| 264 | - |
|
| 265 | - return $flux; |
|
| 253 | + // javascript qui gere la securite du login en evitant de faire circuler le pass en clair |
|
| 254 | + $js = file_get_contents(find_in_path('prive/javascript/login.js')); |
|
| 255 | + $flux['data'] .= |
|
| 256 | + '<script type="text/javascript">/*<![CDATA[*/' |
|
| 257 | + . "$js\n" |
|
| 258 | + . "var login_info={'login':'" . $flux['args']['contexte']['var_login'] . "'," |
|
| 259 | + . "'page_auteur': '" . generer_url_public('informer_auteur') . "'," |
|
| 260 | + . "'informe_auteur_en_cours':false," |
|
| 261 | + . "'attente_informe':0};" |
|
| 262 | + . "jQuery(function(){jQuery('#var_login').change(actualise_auteur);});" |
|
| 263 | + . '/*]]>*/</script>'; |
|
| 264 | + |
|
| 265 | + return $flux; |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | |
@@ -274,11 +274,11 @@ discard block |
||
| 274 | 274 | * toujours true pour un auteur cree dans SPIP |
| 275 | 275 | */ |
| 276 | 276 | function auth_spip_autoriser_modifier_login(string $serveur = ''): bool { |
| 277 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | - if (strlen($serveur)) { |
|
| 279 | - return false; |
|
| 280 | - } |
|
| 281 | - return true; |
|
| 277 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 278 | + if (strlen($serveur)) { |
|
| 279 | + return false; |
|
| 280 | + } |
|
| 281 | + return true; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -292,25 +292,25 @@ discard block |
||
| 292 | 292 | * message d'erreur si login non valide, chaine vide sinon |
| 293 | 293 | */ |
| 294 | 294 | function auth_spip_verifier_login($new_login, $id_auteur = 0, $serveur = '') { |
| 295 | - // login et mot de passe |
|
| 296 | - if (strlen($new_login)) { |
|
| 297 | - if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | - return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | - } else { |
|
| 300 | - $n = sql_countsel( |
|
| 301 | - 'spip_auteurs', |
|
| 302 | - 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | - '', |
|
| 304 | - '', |
|
| 305 | - $serveur |
|
| 306 | - ); |
|
| 307 | - if ($n) { |
|
| 308 | - return _T('info_login_existant'); |
|
| 309 | - } |
|
| 310 | - } |
|
| 311 | - } |
|
| 312 | - |
|
| 313 | - return ''; |
|
| 295 | + // login et mot de passe |
|
| 296 | + if (strlen($new_login)) { |
|
| 297 | + if (strlen($new_login) < _LOGIN_TROP_COURT) { |
|
| 298 | + return _T('info_login_trop_court_car_pluriel', ['nb' => _LOGIN_TROP_COURT]); |
|
| 299 | + } else { |
|
| 300 | + $n = sql_countsel( |
|
| 301 | + 'spip_auteurs', |
|
| 302 | + 'login=' . sql_quote($new_login) . ' AND id_auteur!=' . intval($id_auteur) . " AND statut!='5poubelle'", |
|
| 303 | + '', |
|
| 304 | + '', |
|
| 305 | + $serveur |
|
| 306 | + ); |
|
| 307 | + if ($n) { |
|
| 308 | + return _T('info_login_existant'); |
|
| 309 | + } |
|
| 310 | + } |
|
| 311 | + } |
|
| 312 | + |
|
| 313 | + return ''; |
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | /** |
@@ -322,41 +322,41 @@ discard block |
||
| 322 | 322 | * @return bool |
| 323 | 323 | */ |
| 324 | 324 | function auth_spip_modifier_login($new_login, $id_auteur, $serveur = '') { |
| 325 | - if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | - return false; |
|
| 327 | - } |
|
| 328 | - if ( |
|
| 329 | - !$id_auteur = intval($id_auteur) |
|
| 330 | - or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | - ) { |
|
| 332 | - return false; |
|
| 333 | - } |
|
| 334 | - if ($new_login == $auteur['login']) { |
|
| 335 | - return true; |
|
| 336 | - } // on a rien fait mais c'est bon ! |
|
| 337 | - |
|
| 338 | - include_spip('action/editer_auteur'); |
|
| 339 | - |
|
| 340 | - // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | - if (strlen($new_login)) { |
|
| 342 | - $anciens = sql_allfetsel( |
|
| 343 | - 'id_auteur', |
|
| 344 | - 'spip_auteurs', |
|
| 345 | - 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | - '', |
|
| 347 | - '', |
|
| 348 | - '', |
|
| 349 | - '', |
|
| 350 | - $serveur |
|
| 351 | - ); |
|
| 352 | - while ($row = array_pop($anciens)) { |
|
| 353 | - auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | - |
|
| 359 | - return true; |
|
| 325 | + if (is_null($new_login) or auth_spip_verifier_login($new_login, $id_auteur, $serveur) != '') { |
|
| 326 | + return false; |
|
| 327 | + } |
|
| 328 | + if ( |
|
| 329 | + !$id_auteur = intval($id_auteur) |
|
| 330 | + or !$auteur = sql_fetsel('login', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 331 | + ) { |
|
| 332 | + return false; |
|
| 333 | + } |
|
| 334 | + if ($new_login == $auteur['login']) { |
|
| 335 | + return true; |
|
| 336 | + } // on a rien fait mais c'est bon ! |
|
| 337 | + |
|
| 338 | + include_spip('action/editer_auteur'); |
|
| 339 | + |
|
| 340 | + // vider le login des auteurs a la poubelle qui avaient ce meme login |
|
| 341 | + if (strlen($new_login)) { |
|
| 342 | + $anciens = sql_allfetsel( |
|
| 343 | + 'id_auteur', |
|
| 344 | + 'spip_auteurs', |
|
| 345 | + 'login=' . sql_quote($new_login, $serveur, 'text') . " AND statut='5poubelle'", |
|
| 346 | + '', |
|
| 347 | + '', |
|
| 348 | + '', |
|
| 349 | + '', |
|
| 350 | + $serveur |
|
| 351 | + ); |
|
| 352 | + while ($row = array_pop($anciens)) { |
|
| 353 | + auteur_modifier($row['id_auteur'], ['login' => ''], true); // manque la gestion de $serveur |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + auteur_modifier($id_auteur, ['login' => $new_login], true); // manque la gestion de $serveur |
|
| 358 | + |
|
| 359 | + return true; |
|
| 360 | 360 | } |
| 361 | 361 | |
| 362 | 362 | /** |
@@ -368,44 +368,44 @@ discard block |
||
| 368 | 368 | * @return string |
| 369 | 369 | */ |
| 370 | 370 | function auth_spip_retrouver_login($login, $serveur = '') { |
| 371 | - if (!strlen($login)) { |
|
| 372 | - return null; |
|
| 373 | - } // pas la peine de requeter |
|
| 374 | - $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | - if ( |
|
| 376 | - $r = sql_getfetsel( |
|
| 377 | - 'login', |
|
| 378 | - 'spip_auteurs', |
|
| 379 | - "statut<>'5poubelle'" . |
|
| 380 | - ' AND (length(pass)>0)' . |
|
| 381 | - " AND (login=$l)", |
|
| 382 | - '', |
|
| 383 | - '', |
|
| 384 | - '', |
|
| 385 | - '', |
|
| 386 | - $serveur |
|
| 387 | - ) |
|
| 388 | - ) { |
|
| 389 | - return $r; |
|
| 390 | - } |
|
| 391 | - // Si pas d'auteur avec ce login |
|
| 392 | - // regarder s'il a saisi son nom ou son mail. |
|
| 393 | - // Ne pas fusionner avec la requete precedente |
|
| 394 | - // car un nom peut etre homonyme d'un autre login |
|
| 395 | - else { |
|
| 396 | - return sql_getfetsel( |
|
| 397 | - 'login', |
|
| 398 | - 'spip_auteurs', |
|
| 399 | - "statut<>'5poubelle'" . |
|
| 400 | - ' AND (length(pass)>0)' . |
|
| 401 | - " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | - '', |
|
| 403 | - '', |
|
| 404 | - '', |
|
| 405 | - '', |
|
| 406 | - $serveur |
|
| 407 | - ); |
|
| 408 | - } |
|
| 371 | + if (!strlen($login)) { |
|
| 372 | + return null; |
|
| 373 | + } // pas la peine de requeter |
|
| 374 | + $l = sql_quote($login, $serveur, 'text'); |
|
| 375 | + if ( |
|
| 376 | + $r = sql_getfetsel( |
|
| 377 | + 'login', |
|
| 378 | + 'spip_auteurs', |
|
| 379 | + "statut<>'5poubelle'" . |
|
| 380 | + ' AND (length(pass)>0)' . |
|
| 381 | + " AND (login=$l)", |
|
| 382 | + '', |
|
| 383 | + '', |
|
| 384 | + '', |
|
| 385 | + '', |
|
| 386 | + $serveur |
|
| 387 | + ) |
|
| 388 | + ) { |
|
| 389 | + return $r; |
|
| 390 | + } |
|
| 391 | + // Si pas d'auteur avec ce login |
|
| 392 | + // regarder s'il a saisi son nom ou son mail. |
|
| 393 | + // Ne pas fusionner avec la requete precedente |
|
| 394 | + // car un nom peut etre homonyme d'un autre login |
|
| 395 | + else { |
|
| 396 | + return sql_getfetsel( |
|
| 397 | + 'login', |
|
| 398 | + 'spip_auteurs', |
|
| 399 | + "statut<>'5poubelle'" . |
|
| 400 | + ' AND (length(pass)>0)' . |
|
| 401 | + " AND (login<>'' AND (nom=$l OR email=$l))", |
|
| 402 | + '', |
|
| 403 | + '', |
|
| 404 | + '', |
|
| 405 | + '', |
|
| 406 | + $serveur |
|
| 407 | + ); |
|
| 408 | + } |
|
| 409 | 409 | } |
| 410 | 410 | |
| 411 | 411 | /** |
@@ -416,11 +416,11 @@ discard block |
||
| 416 | 416 | * toujours true pour un auteur cree dans SPIP |
| 417 | 417 | */ |
| 418 | 418 | function auth_spip_autoriser_modifier_pass(string $serveur = ''): bool { |
| 419 | - // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | - if (strlen($serveur)) { |
|
| 421 | - return false; |
|
| 422 | - } |
|
| 423 | - return true; |
|
| 419 | + // les fonctions d'ecriture sur base distante sont encore incompletes |
|
| 420 | + if (strlen($serveur)) { |
|
| 421 | + return false; |
|
| 422 | + } |
|
| 423 | + return true; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | |
@@ -441,12 +441,12 @@ discard block |
||
| 441 | 441 | * message d'erreur si login non valide, chaine vide sinon |
| 442 | 442 | */ |
| 443 | 443 | function auth_spip_verifier_pass($login, $new_pass, $id_auteur = 0, $serveur = '') { |
| 444 | - // login et mot de passe |
|
| 445 | - if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | - return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | - } |
|
| 444 | + // login et mot de passe |
|
| 445 | + if (strlen($new_pass) < _PASS_LONGUEUR_MINI) { |
|
| 446 | + return _T('info_passe_trop_court_car_pluriel', ['nb' => _PASS_LONGUEUR_MINI]); |
|
| 447 | + } |
|
| 448 | 448 | |
| 449 | - return ''; |
|
| 449 | + return ''; |
|
| 450 | 450 | } |
| 451 | 451 | |
| 452 | 452 | /** |
@@ -460,47 +460,47 @@ discard block |
||
| 460 | 460 | * @return bool |
| 461 | 461 | */ |
| 462 | 462 | function auth_spip_modifier_pass($login, $new_pass, $id_auteur, $serveur = '') { |
| 463 | - if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | - return false; |
|
| 465 | - } |
|
| 466 | - |
|
| 467 | - if ( |
|
| 468 | - !$id_auteur = intval($id_auteur) |
|
| 469 | - or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | - ) { |
|
| 471 | - return false; |
|
| 472 | - } |
|
| 473 | - |
|
| 474 | - $cles = SpipCles::instance(); |
|
| 475 | - $secret = $cles->getSecretAuth(); |
|
| 476 | - if (!$secret) { |
|
| 477 | - if (auth_spip_initialiser_secret()) { |
|
| 478 | - $secret = $cles->getSecretAuth(); |
|
| 479 | - } |
|
| 480 | - else { |
|
| 481 | - return false; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - |
|
| 486 | - include_spip('inc/acces'); |
|
| 487 | - $set = [ |
|
| 488 | - 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | - 'htpass' => generer_htpass($new_pass), |
|
| 490 | - 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | - 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | - 'low_sec' => '', |
|
| 493 | - ]; |
|
| 494 | - |
|
| 495 | - // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | - if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | - $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - include_spip('action/editer_auteur'); |
|
| 501 | - auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | - |
|
| 503 | - return true; // on a bien modifie le pass |
|
| 463 | + if (is_null($new_pass) or auth_spip_verifier_pass($login, $new_pass, $id_auteur, $serveur) != '') { |
|
| 464 | + return false; |
|
| 465 | + } |
|
| 466 | + |
|
| 467 | + if ( |
|
| 468 | + !$id_auteur = intval($id_auteur) |
|
| 469 | + or !$auteur = sql_fetsel('login, statut, webmestre', 'spip_auteurs', 'id_auteur=' . intval($id_auteur), '', '', '', '', $serveur) |
|
| 470 | + ) { |
|
| 471 | + return false; |
|
| 472 | + } |
|
| 473 | + |
|
| 474 | + $cles = SpipCles::instance(); |
|
| 475 | + $secret = $cles->getSecretAuth(); |
|
| 476 | + if (!$secret) { |
|
| 477 | + if (auth_spip_initialiser_secret()) { |
|
| 478 | + $secret = $cles->getSecretAuth(); |
|
| 479 | + } |
|
| 480 | + else { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + |
|
| 486 | + include_spip('inc/acces'); |
|
| 487 | + $set = [ |
|
| 488 | + 'pass' => Password::hacher($new_pass, $secret), |
|
| 489 | + 'htpass' => generer_htpass($new_pass), |
|
| 490 | + 'alea_actuel' => creer_uniqid(), // @deprecated 4.1 |
|
| 491 | + 'alea_futur' => creer_uniqid(), // @deprecated 4.1 |
|
| 492 | + 'low_sec' => '', |
|
| 493 | + ]; |
|
| 494 | + |
|
| 495 | + // si c'est un webmestre, on met a jour son backup des cles |
|
| 496 | + if ($auteur['statut'] === '0minirezo' and $auteur['webmestre'] === 'oui') { |
|
| 497 | + $set['backup_cles'] = $cles->backup($new_pass); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + include_spip('action/editer_auteur'); |
|
| 501 | + auteur_modifier($id_auteur, $set, true); // manque la gestion de $serveur |
|
| 502 | + |
|
| 503 | + return true; // on a bien modifie le pass |
|
| 504 | 504 | } |
| 505 | 505 | |
| 506 | 506 | /** |
@@ -514,58 +514,58 @@ discard block |
||
| 514 | 514 | * @return void |
| 515 | 515 | */ |
| 516 | 516 | function auth_spip_synchroniser_distant($id_auteur, $champs, $options = [], string $serveur = ''): void { |
| 517 | - // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | - if (strlen($serveur)) { |
|
| 519 | - return; |
|
| 520 | - } |
|
| 521 | - // si un login, pass ou statut a ete modifie |
|
| 522 | - // regenerer les fichier htpass |
|
| 523 | - if ( |
|
| 524 | - isset($champs['login']) |
|
| 525 | - or isset($champs['pass']) |
|
| 526 | - or isset($champs['statut']) |
|
| 527 | - or (isset($options['all']) and $options['all']) |
|
| 528 | - ) { |
|
| 529 | - $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | - $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | - |
|
| 532 | - // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | - // par exemple acces_restreint ; |
|
| 534 | - // si .htaccess existe, outrepasser spip_meta |
|
| 535 | - if ( |
|
| 536 | - (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | - and !@file_exists($htaccess) |
|
| 538 | - ) { |
|
| 539 | - spip_unlink($htpasswd); |
|
| 540 | - spip_unlink($htpasswd . '-admin'); |
|
| 541 | - |
|
| 542 | - return; |
|
| 543 | - } |
|
| 544 | - |
|
| 545 | - # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | - # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | - // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | - |
|
| 549 | - $p1 = ''; // login:htpass pour tous |
|
| 550 | - $p2 = ''; // login:htpass pour les admins |
|
| 551 | - $s = sql_select( |
|
| 552 | - 'login, htpass, statut', |
|
| 553 | - 'spip_auteurs', |
|
| 554 | - sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | - ); |
|
| 556 | - while ($t = sql_fetch($s)) { |
|
| 557 | - if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | - $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | - if ($t['statut'] == '0minirezo') { |
|
| 560 | - $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | - } |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - sql_free($s); |
|
| 565 | - if ($p1) { |
|
| 566 | - ecrire_fichier($htpasswd, $p1); |
|
| 567 | - ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | - spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | - } |
|
| 570 | - } |
|
| 517 | + // ne rien faire pour une base distante : on ne sait pas regenerer les htaccess |
|
| 518 | + if (strlen($serveur)) { |
|
| 519 | + return; |
|
| 520 | + } |
|
| 521 | + // si un login, pass ou statut a ete modifie |
|
| 522 | + // regenerer les fichier htpass |
|
| 523 | + if ( |
|
| 524 | + isset($champs['login']) |
|
| 525 | + or isset($champs['pass']) |
|
| 526 | + or isset($champs['statut']) |
|
| 527 | + or (isset($options['all']) and $options['all']) |
|
| 528 | + ) { |
|
| 529 | + $htaccess = _DIR_RESTREINT . _ACCESS_FILE_NAME; |
|
| 530 | + $htpasswd = _DIR_TMP . _AUTH_USER_FILE; |
|
| 531 | + |
|
| 532 | + // Cette variable de configuration peut etre posee par un plugin |
|
| 533 | + // par exemple acces_restreint ; |
|
| 534 | + // si .htaccess existe, outrepasser spip_meta |
|
| 535 | + if ( |
|
| 536 | + (!isset($GLOBALS['meta']['creer_htpasswd']) or ($GLOBALS['meta']['creer_htpasswd'] != 'oui')) |
|
| 537 | + and !@file_exists($htaccess) |
|
| 538 | + ) { |
|
| 539 | + spip_unlink($htpasswd); |
|
| 540 | + spip_unlink($htpasswd . '-admin'); |
|
| 541 | + |
|
| 542 | + return; |
|
| 543 | + } |
|
| 544 | + |
|
| 545 | + # remarque : ici on laisse passer les "nouveau" de maniere a leur permettre |
|
| 546 | + # de devenir redacteur le cas echeant (auth http)... a nettoyer |
|
| 547 | + // attention, il faut au prealable se connecter a la base (necessaire car utilise par install) |
|
| 548 | + |
|
| 549 | + $p1 = ''; // login:htpass pour tous |
|
| 550 | + $p2 = ''; // login:htpass pour les admins |
|
| 551 | + $s = sql_select( |
|
| 552 | + 'login, htpass, statut', |
|
| 553 | + 'spip_auteurs', |
|
| 554 | + sql_in('statut', ['1comite', '0minirezo', 'nouveau']) |
|
| 555 | + ); |
|
| 556 | + while ($t = sql_fetch($s)) { |
|
| 557 | + if (strlen($t['login']) and strlen($t['htpass'])) { |
|
| 558 | + $p1 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 559 | + if ($t['statut'] == '0minirezo') { |
|
| 560 | + $p2 .= $t['login'] . ':' . $t['htpass'] . "\n"; |
|
| 561 | + } |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + sql_free($s); |
|
| 565 | + if ($p1) { |
|
| 566 | + ecrire_fichier($htpasswd, $p1); |
|
| 567 | + ecrire_fichier($htpasswd . '-admin', $p2); |
|
| 568 | + spip_log("Ecriture de $htpasswd et $htpasswd-admin"); |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | 571 | } |
@@ -11,77 +11,77 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 20 | - include_spip('inc/texte'); |
|
| 21 | - $titre = $descriptif = ''; |
|
| 22 | - if ($type === 'rubrique') { |
|
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | - if ($row) { |
|
| 25 | - $titre = typo($row['titre']); |
|
| 26 | - $descriptif = propre($row['descriptif']); |
|
| 27 | - } else { |
|
| 28 | - $titre = _T('info_racine_site'); |
|
| 29 | - } |
|
| 30 | - } |
|
| 20 | + include_spip('inc/texte'); |
|
| 21 | + $titre = $descriptif = ''; |
|
| 22 | + if ($type === 'rubrique') { |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + if ($row) { |
|
| 25 | + $titre = typo($row['titre']); |
|
| 26 | + $descriptif = propre($row['descriptif']); |
|
| 27 | + } else { |
|
| 28 | + $titre = _T('info_racine_site'); |
|
| 29 | + } |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - $res = ''; |
|
| 33 | - if ( |
|
| 34 | - $type === 'rubrique' |
|
| 35 | - and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | - and isset($GLOBALS['meta']['image_process']) |
|
| 37 | - ) { |
|
| 38 | - if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | - [$fid, $dir, $nom, $format] = $res; |
|
| 42 | - include_spip('inc/filtres_images_mini'); |
|
| 43 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | - if ($res) { |
|
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | - } |
|
| 47 | - } |
|
| 48 | - } |
|
| 49 | - } |
|
| 32 | + $res = ''; |
|
| 33 | + if ( |
|
| 34 | + $type === 'rubrique' |
|
| 35 | + and intval($GLOBALS['visiteur_session']['prefs']['display'] ?? 0) !== 1 |
|
| 36 | + and isset($GLOBALS['meta']['image_process']) |
|
| 37 | + ) { |
|
| 38 | + if ($GLOBALS['meta']['image_process'] !== 'non') { |
|
| 39 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 40 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 41 | + [$fid, $dir, $nom, $format] = $res; |
|
| 42 | + include_spip('inc/filtres_images_mini'); |
|
| 43 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 44 | + if ($res) { |
|
| 45 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | + } |
|
| 47 | + } |
|
| 48 | + } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | - $id = intval($id); |
|
| 51 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 52 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 53 | + $id = intval($id); |
|
| 54 | 54 | |
| 55 | 55 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 56 | 56 | # et l'affichage de son titre dans le bandeau |
| 57 | - $titre = strtr( |
|
| 58 | - str_replace( |
|
| 59 | - "'", |
|
| 60 | - '’', |
|
| 61 | - str_replace('"', '"', textebrut($titre)) |
|
| 62 | - ), |
|
| 63 | - "\n\r", |
|
| 64 | - ' ' |
|
| 65 | - ); |
|
| 57 | + $titre = strtr( |
|
| 58 | + str_replace( |
|
| 59 | + "'", |
|
| 60 | + '’', |
|
| 61 | + str_replace('"', '"', textebrut($titre)) |
|
| 62 | + ), |
|
| 63 | + "\n\r", |
|
| 64 | + ' ' |
|
| 65 | + ); |
|
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do . '_selection_titre'; |
|
| 68 | 68 | |
| 69 | - return "<div style='display: none;'>" |
|
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | - . entites_html($titre) |
|
| 73 | - . '" />' |
|
| 74 | - . '</div>' |
|
| 75 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | - . '<div class="informer__item">' |
|
| 77 | - . (!$res ? '' : $res) |
|
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | - . '</div>' |
|
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | - . _T('bouton_choisir') |
|
| 84 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | - . '</div>' |
|
| 86 | - . '</div>'; |
|
| 69 | + return "<div style='display: none;'>" |
|
| 70 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 72 | + . entites_html($titre) |
|
| 73 | + . '" />' |
|
| 74 | + . '</div>' |
|
| 75 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 76 | + . '<div class="informer__item">' |
|
| 77 | + . (!$res ? '' : $res) |
|
| 78 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 80 | + . '</div>' |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 82 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 83 | + . _T('bouton_choisir') |
|
| 84 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 85 | + . '</div>' |
|
| 86 | + . '</div>'; |
|
| 87 | 87 | } |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | include_spip('inc/texte'); |
| 21 | 21 | $titre = $descriptif = ''; |
| 22 | 22 | if ($type === 'rubrique') { |
| 23 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 23 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id)); |
|
| 24 | 24 | if ($row) { |
| 25 | 25 | $titre = typo($row['titre']); |
| 26 | 26 | $descriptif = propre($row['descriptif']); |
@@ -42,7 +42,7 @@ discard block |
||
| 42 | 42 | include_spip('inc/filtres_images_mini'); |
| 43 | 43 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 44 | 44 | if ($res) { |
| 45 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 45 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 46 | 46 | } |
| 47 | 47 | } |
| 48 | 48 | } |
@@ -64,21 +64,21 @@ discard block |
||
| 64 | 64 | ' ' |
| 65 | 65 | ); |
| 66 | 66 | |
| 67 | - $js_func = $do . '_selection_titre'; |
|
| 67 | + $js_func = $do.'_selection_titre'; |
|
| 68 | 68 | |
| 69 | 69 | return "<div style='display: none;'>" |
| 70 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 71 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 70 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 71 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 72 | 72 | . entites_html($titre) |
| 73 | 73 | . '" />' |
| 74 | 74 | . '</div>' |
| 75 | 75 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 76 | 76 | . '<div class="informer__item">' |
| 77 | 77 | . (!$res ? '' : $res) |
| 78 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 79 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 78 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 79 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>') |
|
| 80 | 80 | . '</div>' |
| 81 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 81 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 82 | 82 | . "<input type='submit' class='fondo btn submit' value='" |
| 83 | 83 | . _T('bouton_choisir') |
| 84 | 84 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,25 +43,25 @@ discard block |
||
| 43 | 43 | * @return string Code HTML |
| 44 | 44 | **/ |
| 45 | 45 | function inc_commencer_page_dist( |
| 46 | - $titre = '', |
|
| 47 | - $rubrique = 'accueil', |
|
| 48 | - $sous_rubrique = 'accueil', |
|
| 49 | - $id_rubrique = '', |
|
| 50 | - $menu = true, |
|
| 51 | - $minipres = false, |
|
| 52 | - $alertes = true |
|
| 46 | + $titre = '', |
|
| 47 | + $rubrique = 'accueil', |
|
| 48 | + $sous_rubrique = 'accueil', |
|
| 49 | + $id_rubrique = '', |
|
| 50 | + $menu = true, |
|
| 51 | + $minipres = false, |
|
| 52 | + $alertes = true |
|
| 53 | 53 | ) { |
| 54 | 54 | |
| 55 | - include_spip('inc/headers'); |
|
| 55 | + include_spip('inc/headers'); |
|
| 56 | 56 | |
| 57 | - http_no_cache(); |
|
| 57 | + http_no_cache(); |
|
| 58 | 58 | |
| 59 | - return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | - . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | - . "<div id='page'>" |
|
| 62 | - . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | - . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | - . '<div class="largeur">'; |
|
| 59 | + return init_entete($titre, $id_rubrique, $minipres) |
|
| 60 | + . init_body($rubrique, $sous_rubrique, $id_rubrique, $menu) |
|
| 61 | + . "<div id='page'>" |
|
| 62 | + . auteurs_recemment_connectes($GLOBALS['connect_id_auteur']) |
|
| 63 | + . ($alertes ? alertes_auteur($GLOBALS['connect_id_auteur']) : '') |
|
| 64 | + . '<div class="largeur">'; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -82,21 +82,21 @@ discard block |
||
| 82 | 82 | * Entête du fichier HTML avec le DOCTYPE |
| 83 | 83 | */ |
| 84 | 84 | function init_entete($titre = '', $dummy = 0, $minipres = false) { |
| 85 | - include_spip('inc/texte'); |
|
| 86 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - $titre = '[' |
|
| 91 | - . $nom_site_spip |
|
| 92 | - . ']' |
|
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | - |
|
| 95 | - return _DOCTYPE_ECRIRE |
|
| 96 | - . html_lang_attributes() |
|
| 97 | - . "<head>\n" |
|
| 98 | - . init_head($titre, $dummy, $minipres) |
|
| 99 | - . "</head>\n"; |
|
| 85 | + include_spip('inc/texte'); |
|
| 86 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 87 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + $titre = '[' |
|
| 91 | + . $nom_site_spip |
|
| 92 | + . ']' |
|
| 93 | + . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 94 | + |
|
| 95 | + return _DOCTYPE_ECRIRE |
|
| 96 | + . html_lang_attributes() |
|
| 97 | + . "<head>\n" |
|
| 98 | + . init_head($titre, $dummy, $minipres) |
|
| 99 | + . "</head>\n"; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string |
| 111 | 111 | */ |
| 112 | 112 | function init_head($titre = '', $dummy = 0, $minipres = false) { |
| 113 | - return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 113 | + return recuperer_fond('prive/squelettes/head/dist', ['titre' => $titre, 'minipres' => $minipres ? ' ' : '']); |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | /** |
@@ -132,20 +132,20 @@ discard block |
||
| 132 | 132 | */ |
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | - $res = pipeline('body_prive', "<body class='" |
|
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | - . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | - . '>'); |
|
| 135 | + $res = pipeline('body_prive', "<body class='" |
|
| 136 | + . init_body_class() . ' ' . _request('exec') . "'" |
|
| 137 | + . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
|
| 138 | + . '>'); |
|
| 139 | 139 | |
| 140 | - if (!$menu) { |
|
| 141 | - return $res; |
|
| 142 | - } |
|
| 140 | + if (!$menu) { |
|
| 141 | + return $res; |
|
| 142 | + } |
|
| 143 | 143 | |
| 144 | 144 | |
| 145 | - $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 145 | + $bandeau = charger_fonction('bandeau', 'inc'); |
|
| 146 | 146 | |
| 147 | - return $res |
|
| 148 | - . $bandeau(); |
|
| 147 | + return $res |
|
| 148 | + . $bandeau(); |
|
| 149 | 149 | } |
| 150 | 150 | |
| 151 | 151 | /** |
@@ -157,23 +157,23 @@ discard block |
||
| 157 | 157 | * @return string Classes CSS (séparées par des espaces) |
| 158 | 158 | */ |
| 159 | 159 | function init_body_class() { |
| 160 | - $display_modes = [ |
|
| 161 | - 0 => 'icones_img_texte' // défaut. |
|
| 162 | - /*init*/, |
|
| 163 | - 1 => 'icones_texte', |
|
| 164 | - 2 => 'icones_img_texte', |
|
| 165 | - 3 => 'icones_img' |
|
| 166 | - ]; |
|
| 160 | + $display_modes = [ |
|
| 161 | + 0 => 'icones_img_texte' // défaut. |
|
| 162 | + /*init*/, |
|
| 163 | + 1 => 'icones_texte', |
|
| 164 | + 2 => 'icones_img_texte', |
|
| 165 | + 3 => 'icones_img' |
|
| 166 | + ]; |
|
| 167 | 167 | |
| 168 | - $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 168 | + $prefs = $GLOBALS['visiteur_session']['prefs'] ?? []; |
|
| 169 | 169 | |
| 170 | - $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | - $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 170 | + $display_mode = $display_modes[intval($prefs['display'] ?? 0)] ?? $display_modes[0]; |
|
| 171 | + $spip_display_navigation = isset($prefs['display_navigation']) ? spip_sanitize_classname($prefs['display_navigation']) : 'navigation_avec_icones'; |
|
| 172 | 172 | |
| 173 | - $couleur = intval($prefs['couleur'] ?? 2); |
|
| 173 | + $couleur = intval($prefs['couleur'] ?? 2); |
|
| 174 | 174 | |
| 175 | - $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | - return spip_sanitize_classname($classes); |
|
| 175 | + $classes = "spip-theme-colors-$couleur $spip_display_navigation $display_mode"; |
|
| 176 | + return spip_sanitize_classname($classes); |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -184,5 +184,5 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | function auteurs_recemment_connectes($id_auteur) { |
| 187 | - return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 187 | + return recuperer_fond('prive/objets/liste/auteurs_enligne'); |
|
| 188 | 188 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $titre = '[' |
| 91 | 91 | . $nom_site_spip |
| 92 | 92 | . ']' |
| 93 | - . ($titre ? ' ' . textebrut(typo($titre)) : ''); |
|
| 93 | + . ($titre ? ' '.textebrut(typo($titre)) : ''); |
|
| 94 | 94 | |
| 95 | 95 | return _DOCTYPE_ECRIRE |
| 96 | 96 | . html_lang_attributes() |
@@ -133,7 +133,7 @@ discard block |
||
| 133 | 133 | function init_body($rubrique = 'accueil', $sous_rubrique = 'accueil', $id_rubrique = '', $menu = true) { |
| 134 | 134 | |
| 135 | 135 | $res = pipeline('body_prive', "<body class='" |
| 136 | - . init_body_class() . ' ' . _request('exec') . "'" |
|
| 136 | + . init_body_class().' '._request('exec')."'" |
|
| 137 | 137 | . ($GLOBALS['spip_lang_rtl'] ? " dir='rtl'" : '') |
| 138 | 138 | . '>'); |
| 139 | 139 | |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | /** Drapeau indiquant que l'on est dans l'espace privé */ |
| 20 | 20 | define('_ESPACE_PRIVE', true); |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - include 'inc_version.php'; |
|
| 22 | + include 'inc_version.php'; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | include_spip('inc/cookie'); |
@@ -35,18 +35,18 @@ discard block |
||
| 35 | 35 | // alors il faut blinder les variables d'URL |
| 36 | 36 | // |
| 37 | 37 | if (autoriser_sans_cookie($exec, false)) { |
| 38 | - if (!isset($reinstall)) { |
|
| 39 | - $reinstall = 'non'; |
|
| 40 | - } |
|
| 41 | - $var_auth = true; |
|
| 38 | + if (!isset($reinstall)) { |
|
| 39 | + $reinstall = 'non'; |
|
| 40 | + } |
|
| 41 | + $var_auth = true; |
|
| 42 | 42 | } else { |
| 43 | - // Authentification, redefinissable |
|
| 44 | - $auth = charger_fonction('auth', 'inc'); |
|
| 45 | - $var_auth = $auth(); |
|
| 46 | - if ($var_auth) { |
|
| 47 | - echo auth_echec($var_auth); |
|
| 48 | - exit; |
|
| 49 | - } |
|
| 43 | + // Authentification, redefinissable |
|
| 44 | + $auth = charger_fonction('auth', 'inc'); |
|
| 45 | + $var_auth = $auth(); |
|
| 46 | + if ($var_auth) { |
|
| 47 | + echo auth_echec($var_auth); |
|
| 48 | + exit; |
|
| 49 | + } |
|
| 50 | 50 | } |
| 51 | 51 | |
| 52 | 52 | // initialiser a la langue par defaut |
@@ -57,29 +57,29 @@ discard block |
||
| 57 | 57 | |
| 58 | 58 | |
| 59 | 59 | if (_request('action') or _request('var_ajax') or _request('formulaire_action')) { |
| 60 | - if (!autoriser_sans_cookie($exec)) { |
|
| 61 | - // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 62 | - include_spip('public/aiguiller'); |
|
| 63 | - if ( |
|
| 64 | - // cas des appels actions ?action=xxx |
|
| 65 | - traiter_appels_actions() |
|
| 66 | - or |
|
| 67 | - // cas des hits ajax sur les inclusions ajax |
|
| 68 | - traiter_appels_inclusions_ajax() |
|
| 69 | - or |
|
| 70 | - // cas des formulaires charger/verifier/traiter |
|
| 71 | - traiter_formulaires_dynamiques() |
|
| 72 | - ) { |
|
| 73 | - exit; |
|
| 74 | - } // le hit est fini ! |
|
| 75 | - } |
|
| 60 | + if (!autoriser_sans_cookie($exec)) { |
|
| 61 | + // Charger l'aiguilleur qui va mettre sur la bonne voie les traitements derogatoires |
|
| 62 | + include_spip('public/aiguiller'); |
|
| 63 | + if ( |
|
| 64 | + // cas des appels actions ?action=xxx |
|
| 65 | + traiter_appels_actions() |
|
| 66 | + or |
|
| 67 | + // cas des hits ajax sur les inclusions ajax |
|
| 68 | + traiter_appels_inclusions_ajax() |
|
| 69 | + or |
|
| 70 | + // cas des formulaires charger/verifier/traiter |
|
| 71 | + traiter_formulaires_dynamiques() |
|
| 72 | + ) { |
|
| 73 | + exit; |
|
| 74 | + } // le hit est fini ! |
|
| 75 | + } |
|
| 76 | 76 | } |
| 77 | 77 | // securiser les redirect du back-office |
| 78 | 78 | if (_request('redirect')) { |
| 79 | - if (!function_exists('securiser_redirect_action')) { |
|
| 80 | - include_spip('public/aiguiller'); |
|
| 81 | - } |
|
| 82 | - set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 79 | + if (!function_exists('securiser_redirect_action')) { |
|
| 80 | + include_spip('public/aiguiller'); |
|
| 81 | + } |
|
| 82 | + set_request('redirect', securiser_redirect_action(_request('redirect'))); |
|
| 83 | 83 | } |
| 84 | 84 | |
| 85 | 85 | |
@@ -89,12 +89,12 @@ discard block |
||
| 89 | 89 | |
| 90 | 90 | // Controle de la version, sauf si on est deja en train de s'en occuper |
| 91 | 91 | if ( |
| 92 | - !$reinstall == 'oui' |
|
| 93 | - and !_AJAX |
|
| 94 | - and isset($GLOBALS['meta']['version_installee']) |
|
| 95 | - and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 92 | + !$reinstall == 'oui' |
|
| 93 | + and !_AJAX |
|
| 94 | + and isset($GLOBALS['meta']['version_installee']) |
|
| 95 | + and ($GLOBALS['spip_version_base'] != (str_replace(',', '.', $GLOBALS['meta']['version_installee']))) |
|
| 96 | 96 | ) { |
| 97 | - $exec = 'demande_mise_a_jour'; |
|
| 97 | + $exec = 'demande_mise_a_jour'; |
|
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | // Quand une action d'administration est en cours (meta "admin"), |
@@ -104,39 +104,39 @@ discard block |
||
| 104 | 104 | // sinon c'est qu'elle a ete interrompue et il faut la reprendre |
| 105 | 105 | |
| 106 | 106 | elseif (isset($GLOBALS['meta']['admin'])) { |
| 107 | - if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 108 | - [, $var_f, $n] = $l; |
|
| 109 | - } |
|
| 110 | - if ( |
|
| 111 | - _AJAX |
|
| 112 | - or !( |
|
| 113 | - isset($_COOKIE['spip_admin']) |
|
| 114 | - or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 115 | - ) |
|
| 116 | - ) { |
|
| 117 | - spip_log('Quand la meta admin vaut ' . |
|
| 118 | - $GLOBALS['meta']['admin'] . |
|
| 119 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 120 | - ' En cas de probleme, detruire cette meta.'); |
|
| 121 | - die(_T('info_travaux_texte')); |
|
| 122 | - } |
|
| 123 | - if ($n) { |
|
| 124 | - [, $var_f, $n] = $l; |
|
| 125 | - if (tester_url_ecrire("base_$var_f")) { |
|
| 126 | - $var_f = "base_$var_f"; |
|
| 127 | - } |
|
| 128 | - if ($var_f != $exec) { |
|
| 129 | - spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 130 | - $exec = $var_f; |
|
| 131 | - set_request('exec', $exec); |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + if (preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l)) { |
|
| 108 | + [, $var_f, $n] = $l; |
|
| 109 | + } |
|
| 110 | + if ( |
|
| 111 | + _AJAX |
|
| 112 | + or !( |
|
| 113 | + isset($_COOKIE['spip_admin']) |
|
| 114 | + or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
|
| 115 | + ) |
|
| 116 | + ) { |
|
| 117 | + spip_log('Quand la meta admin vaut ' . |
|
| 118 | + $GLOBALS['meta']['admin'] . |
|
| 119 | + ' seul un admin peut se connecter et sans AJAX.' . |
|
| 120 | + ' En cas de probleme, detruire cette meta.'); |
|
| 121 | + die(_T('info_travaux_texte')); |
|
| 122 | + } |
|
| 123 | + if ($n) { |
|
| 124 | + [, $var_f, $n] = $l; |
|
| 125 | + if (tester_url_ecrire("base_$var_f")) { |
|
| 126 | + $var_f = "base_$var_f"; |
|
| 127 | + } |
|
| 128 | + if ($var_f != $exec) { |
|
| 129 | + spip_log("Le script $var_f lance par auteur$n se substitue a l'exec $exec"); |
|
| 130 | + $exec = $var_f; |
|
| 131 | + set_request('exec', $exec); |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | // si nom pas plausible, prendre le script par defaut |
| 136 | 136 | // attention aux deux cas 404/403 qui commencent par un 4 ! |
| 137 | 137 | elseif (!preg_match(',^[a-z4_][0-9a-z_-]*$,i', $exec)) { |
| 138 | - $exec = 'accueil'; |
|
| 139 | - set_request('exec', $exec); |
|
| 138 | + $exec = 'accueil'; |
|
| 139 | + set_request('exec', $exec); |
|
| 140 | 140 | } |
| 141 | 141 | |
| 142 | 142 | // si la langue est specifiee par cookie et ne correspond pas |
@@ -144,19 +144,19 @@ discard block |
||
| 144 | 144 | // on appelle directement la fonction, car un appel d'action peut conduire a une boucle infinie |
| 145 | 145 | // si le cookie n'est pas pose correctement dans l'action |
| 146 | 146 | if ( |
| 147 | - !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 148 | - and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 147 | + !$var_auth and isset($_COOKIE['spip_lang_ecrire']) |
|
| 148 | + and $_COOKIE['spip_lang_ecrire'] <> $GLOBALS['visiteur_session']['lang'] |
|
| 149 | 149 | ) { |
| 150 | - include_spip('action/converser'); |
|
| 151 | - action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 150 | + include_spip('action/converser'); |
|
| 151 | + action_converser_post($GLOBALS['visiteur_session']['lang'], true); |
|
| 152 | 152 | } |
| 153 | 153 | |
| 154 | 154 | if ($var_f = tester_url_ecrire($exec)) { |
| 155 | - $var_f = charger_fonction($var_f); |
|
| 156 | - $var_f(); // at last |
|
| 155 | + $var_f = charger_fonction($var_f); |
|
| 156 | + $var_f(); // at last |
|
| 157 | 157 | } else { |
| 158 | - // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 159 | - // ce qui permet de laisser la main a un plugin |
|
| 160 | - $var_f = charger_fonction('404'); |
|
| 161 | - $var_f($exec); |
|
| 158 | + // Rien de connu: rerouter vers exec=404 au lieu d'echouer |
|
| 159 | + // ce qui permet de laisser la main a un plugin |
|
| 160 | + $var_f = charger_fonction('404'); |
|
| 161 | + $var_f($exec); |
|
| 162 | 162 | } |
@@ -9,7 +9,7 @@ discard block |
||
| 9 | 9 | * Ce programme est un logiciel libre distribué sous licence GNU/GPL. * |
| 10 | 10 | \***************************************************************************/ |
| 11 | 11 | |
| 12 | -require_once __DIR__ . '/../vendor/autoload.php'; |
|
| 12 | +require_once __DIR__.'/../vendor/autoload.php'; |
|
| 13 | 13 | |
| 14 | 14 | /** |
| 15 | 15 | * Fichier d'exécution de l'interface privée |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | // Determiner l'action demandee |
| 30 | 30 | // |
| 31 | 31 | |
| 32 | -$exec = (string)_request('exec'); |
|
| 32 | +$exec = (string) _request('exec'); |
|
| 33 | 33 | $reinstall = (!is_null(_request('reinstall'))) ? _request('reinstall') : ($exec == 'install' ? 'oui' : null); |
| 34 | 34 | // |
| 35 | 35 | // Les scripts d'insallation n'authentifient pas, forcement, |
@@ -115,9 +115,9 @@ discard block |
||
| 115 | 115 | or (isset($GLOBALS['visiteur_session']) and $GLOBALS['visiteur_session']['statut'] == '0minirezo') |
| 116 | 116 | ) |
| 117 | 117 | ) { |
| 118 | - spip_log('Quand la meta admin vaut ' . |
|
| 119 | - $GLOBALS['meta']['admin'] . |
|
| 120 | - ' seul un admin peut se connecter et sans AJAX.' . |
|
| 118 | + spip_log('Quand la meta admin vaut '. |
|
| 119 | + $GLOBALS['meta']['admin']. |
|
| 120 | + ' seul un admin peut se connecter et sans AJAX.'. |
|
| 121 | 121 | ' En cas de probleme, detruire cette meta.'); |
| 122 | 122 | die(_T('info_travaux_texte')); |
| 123 | 123 | } |
@@ -76,12 +76,12 @@ discard block |
||
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | 78 | if (($t = objet_type($objet)) !== $objet) { |
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 80 | 80 | $objet = $t; |
| 81 | 81 | } |
| 82 | 82 | if ( |
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 83 | + include_spip('action/editer_'.$objet) |
|
| 84 | + and function_exists($modifier = $objet.'_modifier') |
|
| 85 | 85 | ) { |
| 86 | 86 | return $modifier($id, $set); |
| 87 | 87 | } |
@@ -90,7 +90,7 @@ discard block |
||
| 90 | 90 | $trouver_table = charger_fonction('trouver_table', 'base'); |
| 91 | 91 | $desc = $trouver_table($table_sql); |
| 92 | 92 | if (!$desc or !isset($desc['field'])) { |
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer'._LOG_ERREUR); |
|
| 94 | 94 | |
| 95 | 95 | return _L("Erreur objet $objet inconnu"); |
| 96 | 96 | } |
@@ -170,12 +170,12 @@ discard block |
||
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | 171 | $d = null; |
| 172 | 172 | if (($t = objet_type($objet)) !== $objet) { |
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 174 | 174 | $objet = $t; |
| 175 | 175 | } |
| 176 | 176 | if ( |
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 177 | + include_spip('action/editer_'.$objet) |
|
| 178 | + and function_exists($inserer = $objet.'_inserer') |
|
| 179 | 179 | ) { |
| 180 | 180 | return $inserer($id_parent, $set); |
| 181 | 181 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
| 197 | 197 | $id_rubrique = $row['id_rubrique']; |
| 198 | 198 | } else { |
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique='.intval($id_rubrique)); |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | $champs['id_rubrique'] = $id_rubrique; |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | */ |
| 315 | 315 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 316 | 316 | if (($t = objet_type($objet)) !== $objet) { |
| 317 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 317 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 318 | 318 | $objet = $t; |
| 319 | 319 | } |
| 320 | 320 | if ( |
| 321 | - include_spip('action/editer_' . $objet) |
|
| 322 | - and function_exists($instituer = $objet . '_instituer') |
|
| 321 | + include_spip('action/editer_'.$objet) |
|
| 322 | + and function_exists($instituer = $objet.'_instituer') |
|
| 323 | 323 | ) { |
| 324 | 324 | return $instituer($id, $c, $calcul_rub); |
| 325 | 325 | } |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
| 349 | 349 | $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
| 350 | 350 | |
| 351 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 351 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet).'='.intval($id)); |
|
| 352 | 352 | |
| 353 | 353 | $id_rubrique = $row['id_rubrique']; |
| 354 | 354 | $statut_ancien = $statut = $row['statut']; |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
| 372 | 372 | $statut = $champs['statut'] = $s; |
| 373 | 373 | } else { |
| 374 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 374 | + spip_log("editer_objet $objet #$id refus ".json_encode($c, JSON_THROW_ON_ERROR), 'editer'._LOG_INFO_IMPORTANTE); |
|
| 375 | 375 | } |
| 376 | 376 | } |
| 377 | 377 | |
@@ -401,7 +401,7 @@ discard block |
||
| 401 | 401 | and isset($c['id_parent']) |
| 402 | 402 | and $id_parent = $c['id_parent'] |
| 403 | 403 | and $id_parent != $id_rubrique |
| 404 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 404 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique='.intval($id_parent))) |
|
| 405 | 405 | ) { |
| 406 | 406 | $champs['id_rubrique'] = $id_parent; |
| 407 | 407 | |
@@ -500,7 +500,7 @@ discard block |
||
| 500 | 500 | // Si on deplace l'objet |
| 501 | 501 | // changer aussi son secteur et sa langue (si heritee) |
| 502 | 502 | if (isset($champs['id_rubrique'])) { |
| 503 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 503 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique='.sql_quote($champs['id_rubrique'])); |
|
| 504 | 504 | $langue = $row_rub['lang']; |
| 505 | 505 | |
| 506 | 506 | if (isset($desc['field']['id_secteur'])) { |
@@ -512,7 +512,7 @@ discard block |
||
| 512 | 512 | sql_fetsel( |
| 513 | 513 | '1', |
| 514 | 514 | $table_sql, |
| 515 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 515 | + id_table_objet($objet).'='.intval($id)." AND langue_choisie<>'oui' AND lang<>".sql_quote($langue) |
|
| 516 | 516 | ) |
| 517 | 517 | ) { |
| 518 | 518 | $champs['lang'] = $langue; |
@@ -523,7 +523,7 @@ discard block |
||
| 523 | 523 | if (!$champs) { |
| 524 | 524 | return; |
| 525 | 525 | } |
| 526 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 526 | + sql_updateq($table_sql, $champs, id_table_objet($objet).'='.intval($id)); |
|
| 527 | 527 | |
| 528 | 528 | // Changer le statut des rubriques concernees |
| 529 | 529 | if ($cond) { |
@@ -567,7 +567,7 @@ discard block |
||
| 567 | 567 | */ |
| 568 | 568 | function objet_lire($objet, $valeur_id, $options = []) { |
| 569 | 569 | if (($t = objet_type($objet)) !== $objet) { |
| 570 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 570 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer'._LOG_INFO_IMPORTANTE); |
|
| 571 | 571 | $objet = $t; |
| 572 | 572 | } |
| 573 | 573 | |
@@ -589,7 +589,7 @@ discard block |
||
| 589 | 589 | ) { |
| 590 | 590 | // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
| 591 | 591 | if ( |
| 592 | - include_spip('action/editer_' . $objet) |
|
| 592 | + include_spip('action/editer_'.$objet) |
|
| 593 | 593 | and function_exists($lire = "{$objet}_lire_champs") |
| 594 | 594 | ) { |
| 595 | 595 | $valeurs = $lire($objet, $valeur_id, $champ_id); |
@@ -599,7 +599,7 @@ discard block |
||
| 599 | 599 | |
| 600 | 600 | // La condition est appliquée sur le champ désigné par l'utilisateur. |
| 601 | 601 | $where = [ |
| 602 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 602 | + $champ_id.'='.sql_quote($valeur_id) |
|
| 603 | 603 | ]; |
| 604 | 604 | |
| 605 | 605 | // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | */ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -33,36 +33,36 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | function action_editer_objet_dist($id = null, $objet = null, $set = null) { |
| 35 | 35 | |
| 36 | - // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | - if (is_null($id) or is_null($objet)) { |
|
| 38 | - $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | - $arg = $securiser_action(); |
|
| 40 | - [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | - } |
|
| 42 | - |
|
| 43 | - // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | - if (is_null($id) or is_null($objet)) { |
|
| 45 | - include_spip('inc/minipres'); |
|
| 46 | - echo minipres(_T('info_acces_interdit')); |
|
| 47 | - die(); |
|
| 48 | - } |
|
| 49 | - |
|
| 50 | - // si id n'est pas un nombre, c'est une creation |
|
| 51 | - // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | - if (!$id = intval($id)) { |
|
| 53 | - // on ne sait pas si un parent existe mais on essaye |
|
| 54 | - $id_parent = _request('id_parent'); |
|
| 55 | - $id = objet_inserer($objet, $id_parent); |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - if (!($id = intval($id)) > 0) { |
|
| 59 | - return [$id, _L('echec enregistrement en base')]; |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - // Enregistre l'envoi dans la BD |
|
| 63 | - $err = objet_modifier($objet, $id, $set); |
|
| 64 | - |
|
| 65 | - return [$id, $err]; |
|
| 36 | + // appel direct depuis une url avec arg = "objet/id" |
|
| 37 | + if (is_null($id) or is_null($objet)) { |
|
| 38 | + $securiser_action = charger_fonction('securiser_action', 'inc'); |
|
| 39 | + $arg = $securiser_action(); |
|
| 40 | + [$objet, $id] = array_pad(explode('/', $arg, 2), 2, null); |
|
| 41 | + } |
|
| 42 | + |
|
| 43 | + // appel incorrect ou depuis une url erronnée interdit |
|
| 44 | + if (is_null($id) or is_null($objet)) { |
|
| 45 | + include_spip('inc/minipres'); |
|
| 46 | + echo minipres(_T('info_acces_interdit')); |
|
| 47 | + die(); |
|
| 48 | + } |
|
| 49 | + |
|
| 50 | + // si id n'est pas un nombre, c'est une creation |
|
| 51 | + // mais on verifie qu'on a toutes les donnees qu'il faut. |
|
| 52 | + if (!$id = intval($id)) { |
|
| 53 | + // on ne sait pas si un parent existe mais on essaye |
|
| 54 | + $id_parent = _request('id_parent'); |
|
| 55 | + $id = objet_inserer($objet, $id_parent); |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + if (!($id = intval($id)) > 0) { |
|
| 59 | + return [$id, _L('echec enregistrement en base')]; |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + // Enregistre l'envoi dans la BD |
|
| 63 | + $err = objet_modifier($objet, $id, $set); |
|
| 64 | + |
|
| 65 | + return [$id, $err]; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | /** |
@@ -75,85 +75,85 @@ discard block |
||
| 75 | 75 | * @return mixed|string |
| 76 | 76 | */ |
| 77 | 77 | function objet_modifier($objet, $id, $set = null) { |
| 78 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | - spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | - $objet = $t; |
|
| 81 | - } |
|
| 82 | - if ( |
|
| 83 | - include_spip('action/editer_' . $objet) |
|
| 84 | - and function_exists($modifier = $objet . '_modifier') |
|
| 85 | - ) { |
|
| 86 | - return $modifier($id, $set); |
|
| 87 | - } |
|
| 88 | - |
|
| 89 | - $table_sql = table_objet_sql($objet); |
|
| 90 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | - $desc = $trouver_table($table_sql); |
|
| 92 | - if (!$desc or !isset($desc['field'])) { |
|
| 93 | - spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | - |
|
| 95 | - return _L("Erreur objet $objet inconnu"); |
|
| 96 | - } |
|
| 97 | - include_spip('inc/modifier'); |
|
| 98 | - |
|
| 99 | - $champ_date = ''; |
|
| 100 | - if (isset($desc['date']) and $desc['date']) { |
|
| 101 | - $champ_date = $desc['date']; |
|
| 102 | - } elseif (isset($desc['field']['date'])) { |
|
| 103 | - $champ_date = 'date'; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - $include_list = array_keys($desc['field']); |
|
| 107 | - // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | - // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | - $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | - |
|
| 111 | - if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | - $include_list = $desc['champs_editables']; |
|
| 113 | - } |
|
| 114 | - $c = collecter_requests( |
|
| 115 | - // include list |
|
| 116 | - $include_list, |
|
| 117 | - // exclude list |
|
| 118 | - [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | - // donnees eventuellement fournies |
|
| 120 | - $set |
|
| 121 | - ); |
|
| 122 | - |
|
| 123 | - // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | - if (objet_test_si_publie($objet, $id)) { |
|
| 125 | - $invalideur = "id='$objet/$id'"; |
|
| 126 | - $indexation = true; |
|
| 127 | - } else { |
|
| 128 | - $invalideur = ''; |
|
| 129 | - $indexation = false; |
|
| 130 | - } |
|
| 131 | - |
|
| 132 | - if ( |
|
| 133 | - $err = objet_modifier_champs( |
|
| 134 | - $objet, |
|
| 135 | - $id, |
|
| 136 | - [ |
|
| 137 | - 'data' => $set, |
|
| 138 | - 'nonvide' => '', |
|
| 139 | - 'invalideur' => $invalideur, |
|
| 140 | - 'indexation' => $indexation, |
|
| 141 | - // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | - 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | - ], |
|
| 144 | - $c |
|
| 145 | - ) |
|
| 146 | - ) { |
|
| 147 | - return $err; |
|
| 148 | - } |
|
| 149 | - |
|
| 150 | - // Modification de statut, changement de rubrique ? |
|
| 151 | - // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | - // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | - $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | - $err = objet_instituer($objet, $id, $c); |
|
| 155 | - |
|
| 156 | - return $err; |
|
| 78 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 79 | + spip_log("objet_modifier: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 80 | + $objet = $t; |
|
| 81 | + } |
|
| 82 | + if ( |
|
| 83 | + include_spip('action/editer_' . $objet) |
|
| 84 | + and function_exists($modifier = $objet . '_modifier') |
|
| 85 | + ) { |
|
| 86 | + return $modifier($id, $set); |
|
| 87 | + } |
|
| 88 | + |
|
| 89 | + $table_sql = table_objet_sql($objet); |
|
| 90 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 91 | + $desc = $trouver_table($table_sql); |
|
| 92 | + if (!$desc or !isset($desc['field'])) { |
|
| 93 | + spip_log("Objet $objet inconnu dans objet_modifier", 'editer' . _LOG_ERREUR); |
|
| 94 | + |
|
| 95 | + return _L("Erreur objet $objet inconnu"); |
|
| 96 | + } |
|
| 97 | + include_spip('inc/modifier'); |
|
| 98 | + |
|
| 99 | + $champ_date = ''; |
|
| 100 | + if (isset($desc['date']) and $desc['date']) { |
|
| 101 | + $champ_date = $desc['date']; |
|
| 102 | + } elseif (isset($desc['field']['date'])) { |
|
| 103 | + $champ_date = 'date'; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + $include_list = array_keys($desc['field']); |
|
| 107 | + // on ne traite pas la cle primaire par defaut, notamment car |
|
| 108 | + // sur une creation, id_x vaut 'oui', et serait enregistre en id_x=0 dans la base |
|
| 109 | + $include_list = array_diff($include_list, [$desc['key']['PRIMARY KEY']]); |
|
| 110 | + |
|
| 111 | + if (isset($desc['champs_editables']) and is_array($desc['champs_editables'])) { |
|
| 112 | + $include_list = $desc['champs_editables']; |
|
| 113 | + } |
|
| 114 | + $c = collecter_requests( |
|
| 115 | + // include list |
|
| 116 | + $include_list, |
|
| 117 | + // exclude list |
|
| 118 | + [$champ_date, 'statut', 'id_parent', 'id_secteur'], |
|
| 119 | + // donnees eventuellement fournies |
|
| 120 | + $set |
|
| 121 | + ); |
|
| 122 | + |
|
| 123 | + // Si l'objet est publie, invalider les caches et demander sa reindexation |
|
| 124 | + if (objet_test_si_publie($objet, $id)) { |
|
| 125 | + $invalideur = "id='$objet/$id'"; |
|
| 126 | + $indexation = true; |
|
| 127 | + } else { |
|
| 128 | + $invalideur = ''; |
|
| 129 | + $indexation = false; |
|
| 130 | + } |
|
| 131 | + |
|
| 132 | + if ( |
|
| 133 | + $err = objet_modifier_champs( |
|
| 134 | + $objet, |
|
| 135 | + $id, |
|
| 136 | + [ |
|
| 137 | + 'data' => $set, |
|
| 138 | + 'nonvide' => '', |
|
| 139 | + 'invalideur' => $invalideur, |
|
| 140 | + 'indexation' => $indexation, |
|
| 141 | + // champ a mettre a date('Y-m-d H:i:s') s'il y a modif |
|
| 142 | + 'date_modif' => (isset($desc['field']['date_modif']) ? 'date_modif' : '') |
|
| 143 | + ], |
|
| 144 | + $c |
|
| 145 | + ) |
|
| 146 | + ) { |
|
| 147 | + return $err; |
|
| 148 | + } |
|
| 149 | + |
|
| 150 | + // Modification de statut, changement de rubrique ? |
|
| 151 | + // FIXME: Ici lorsqu'un $set est passé, la fonction collecter_requests() retourne tout |
|
| 152 | + // le tableau $set hors liste d’exclusion, mais du coup on a possiblement des champs en trop. |
|
| 153 | + $c = collecter_requests([$champ_date, 'statut', 'id_parent'], [], $set); |
|
| 154 | + $err = objet_instituer($objet, $id, $c); |
|
| 155 | + |
|
| 156 | + return $err; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -168,157 +168,157 @@ discard block |
||
| 168 | 168 | * @return bool|int |
| 169 | 169 | */ |
| 170 | 170 | function objet_inserer($objet, $id_parent = null, $set = null) { |
| 171 | - $d = null; |
|
| 172 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | - spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | - $objet = $t; |
|
| 175 | - } |
|
| 176 | - if ( |
|
| 177 | - include_spip('action/editer_' . $objet) |
|
| 178 | - and function_exists($inserer = $objet . '_inserer') |
|
| 179 | - ) { |
|
| 180 | - return $inserer($id_parent, $set); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - $table_sql = table_objet_sql($objet); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $desc = $trouver_table($table_sql); |
|
| 186 | - if (!$desc or !isset($desc['field'])) { |
|
| 187 | - return 0; |
|
| 188 | - } |
|
| 189 | - |
|
| 190 | - $lang_rub = ''; |
|
| 191 | - $champs = []; |
|
| 192 | - if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | - // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | - // dans la premiere rubrique racine |
|
| 195 | - if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | - $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | - $id_rubrique = $row['id_rubrique']; |
|
| 198 | - } else { |
|
| 199 | - $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | - } |
|
| 201 | - |
|
| 202 | - $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | - if (isset($desc['field']['id_secteur'])) { |
|
| 204 | - $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | - } |
|
| 206 | - $lang_rub = $row['lang']; |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | - // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | - // ou a defaut celle de la rubrique |
|
| 212 | - // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | - if ( |
|
| 214 | - isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | - $table_sql, |
|
| 216 | - explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | - ) |
|
| 218 | - ) { |
|
| 219 | - lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | - if ( |
|
| 221 | - in_array( |
|
| 222 | - $GLOBALS['spip_lang'], |
|
| 223 | - explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | - ) |
|
| 225 | - ) { |
|
| 226 | - $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | - if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | - $champs['langue_choisie'] = 'oui'; |
|
| 229 | - } |
|
| 230 | - } |
|
| 231 | - } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | - $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | - $champs['langue_choisie'] = 'non'; |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - if (isset($desc['field']['statut'])) { |
|
| 237 | - if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | - $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | - $champs['statut'] = reset($cles_statut); |
|
| 240 | - } else { |
|
| 241 | - $champs['statut'] = 'prepa'; |
|
| 242 | - } |
|
| 243 | - } |
|
| 244 | - |
|
| 245 | - |
|
| 246 | - if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | - $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | - } |
|
| 249 | - |
|
| 250 | - if ($set) { |
|
| 251 | - $champs = array_merge($champs, $set); |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // Envoyer aux plugins |
|
| 255 | - $champs = pipeline( |
|
| 256 | - 'pre_insertion', |
|
| 257 | - [ |
|
| 258 | - 'args' => [ |
|
| 259 | - 'table' => $table_sql, |
|
| 260 | - 'id_parent' => $id_parent, |
|
| 261 | - ], |
|
| 262 | - 'data' => $champs |
|
| 263 | - ] |
|
| 264 | - ); |
|
| 265 | - |
|
| 266 | - $id = sql_insertq($table_sql, $champs); |
|
| 267 | - |
|
| 268 | - if ($id) { |
|
| 269 | - // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | - // et associer l'auteur sinon |
|
| 271 | - // si la table n'a pas deja un champ id_auteur |
|
| 272 | - // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | - if ( |
|
| 274 | - $id > 0 |
|
| 275 | - and !isset($desc['field']['id_auteur']) |
|
| 276 | - ) { |
|
| 277 | - $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | - $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | - : _request('id_auteur')); |
|
| 280 | - if ($id_auteur) { |
|
| 281 | - include_spip('action/editer_auteur'); |
|
| 282 | - auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | - } |
|
| 284 | - } |
|
| 285 | - |
|
| 286 | - pipeline( |
|
| 287 | - 'post_insertion', |
|
| 288 | - [ |
|
| 289 | - 'args' => [ |
|
| 290 | - 'table' => $table_sql, |
|
| 291 | - 'id_parent' => $id_parent, |
|
| 292 | - 'id_objet' => $id, |
|
| 293 | - ], |
|
| 294 | - 'data' => $champs |
|
| 295 | - ] |
|
| 296 | - ); |
|
| 297 | - } |
|
| 171 | + $d = null; |
|
| 172 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 173 | + spip_log("objet_inserer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 174 | + $objet = $t; |
|
| 175 | + } |
|
| 176 | + if ( |
|
| 177 | + include_spip('action/editer_' . $objet) |
|
| 178 | + and function_exists($inserer = $objet . '_inserer') |
|
| 179 | + ) { |
|
| 180 | + return $inserer($id_parent, $set); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + $table_sql = table_objet_sql($objet); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $desc = $trouver_table($table_sql); |
|
| 186 | + if (!$desc or !isset($desc['field'])) { |
|
| 187 | + return 0; |
|
| 188 | + } |
|
| 189 | + |
|
| 190 | + $lang_rub = ''; |
|
| 191 | + $champs = []; |
|
| 192 | + if (isset($desc['field']['id_rubrique'])) { |
|
| 193 | + // Si id_rubrique vaut 0 ou n'est pas definie, creer l'objet |
|
| 194 | + // dans la premiere rubrique racine |
|
| 195 | + if (!$id_rubrique = intval($id_parent)) { |
|
| 196 | + $row = sql_fetsel('id_rubrique, id_secteur, lang', 'spip_rubriques', 'id_parent=0', '', '0+titre,titre', '1'); |
|
| 197 | + $id_rubrique = $row['id_rubrique']; |
|
| 198 | + } else { |
|
| 199 | + $row = sql_fetsel('lang, id_secteur', 'spip_rubriques', 'id_rubrique=' . intval($id_rubrique)); |
|
| 200 | + } |
|
| 201 | + |
|
| 202 | + $champs['id_rubrique'] = $id_rubrique; |
|
| 203 | + if (isset($desc['field']['id_secteur'])) { |
|
| 204 | + $champs['id_secteur'] = $row['id_secteur']; |
|
| 205 | + } |
|
| 206 | + $lang_rub = $row['lang']; |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + // La langue a la creation : si les liens de traduction sont autorises |
|
| 210 | + // dans les rubriques, on essaie avec la langue de l'auteur, |
|
| 211 | + // ou a defaut celle de la rubrique |
|
| 212 | + // Sinon c'est la langue de la rubrique qui est choisie + heritee |
|
| 213 | + if ( |
|
| 214 | + isset($desc['field']['lang']) and !empty($GLOBALS['meta']['multi_objets']) and in_array( |
|
| 215 | + $table_sql, |
|
| 216 | + explode(',', $GLOBALS['meta']['multi_objets']) |
|
| 217 | + ) |
|
| 218 | + ) { |
|
| 219 | + lang_select($GLOBALS['visiteur_session']['lang']); |
|
| 220 | + if ( |
|
| 221 | + in_array( |
|
| 222 | + $GLOBALS['spip_lang'], |
|
| 223 | + explode(',', $GLOBALS['meta']['langues_multilingue']) |
|
| 224 | + ) |
|
| 225 | + ) { |
|
| 226 | + $champs['lang'] = $GLOBALS['spip_lang']; |
|
| 227 | + if (isset($desc['field']['langue_choisie'])) { |
|
| 228 | + $champs['langue_choisie'] = 'oui'; |
|
| 229 | + } |
|
| 230 | + } |
|
| 231 | + } elseif (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 232 | + $champs['lang'] = ($lang_rub ?: $GLOBALS['meta']['langue_site']); |
|
| 233 | + $champs['langue_choisie'] = 'non'; |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + if (isset($desc['field']['statut'])) { |
|
| 237 | + if (isset($desc['statut_textes_instituer'])) { |
|
| 238 | + $cles_statut = array_keys($desc['statut_textes_instituer']); |
|
| 239 | + $champs['statut'] = reset($cles_statut); |
|
| 240 | + } else { |
|
| 241 | + $champs['statut'] = 'prepa'; |
|
| 242 | + } |
|
| 243 | + } |
|
| 244 | + |
|
| 245 | + |
|
| 246 | + if ((isset($desc['date']) and $d = $desc['date']) or isset($desc['field'][$d = 'date'])) { |
|
| 247 | + $champs[$d] = date('Y-m-d H:i:s'); |
|
| 248 | + } |
|
| 249 | + |
|
| 250 | + if ($set) { |
|
| 251 | + $champs = array_merge($champs, $set); |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // Envoyer aux plugins |
|
| 255 | + $champs = pipeline( |
|
| 256 | + 'pre_insertion', |
|
| 257 | + [ |
|
| 258 | + 'args' => [ |
|
| 259 | + 'table' => $table_sql, |
|
| 260 | + 'id_parent' => $id_parent, |
|
| 261 | + ], |
|
| 262 | + 'data' => $champs |
|
| 263 | + ] |
|
| 264 | + ); |
|
| 265 | + |
|
| 266 | + $id = sql_insertq($table_sql, $champs); |
|
| 267 | + |
|
| 268 | + if ($id) { |
|
| 269 | + // controler si le serveur n'a pas renvoye une erreur |
|
| 270 | + // et associer l'auteur sinon |
|
| 271 | + // si la table n'a pas deja un champ id_auteur |
|
| 272 | + // et si le form n'a pas poste un id_auteur (meme vide, ce qui sert a annuler cette auto association) |
|
| 273 | + if ( |
|
| 274 | + $id > 0 |
|
| 275 | + and !isset($desc['field']['id_auteur']) |
|
| 276 | + ) { |
|
| 277 | + $id_auteur = ((is_null(_request('id_auteur')) and isset($GLOBALS['visiteur_session']['id_auteur'])) ? |
|
| 278 | + $GLOBALS['visiteur_session']['id_auteur'] |
|
| 279 | + : _request('id_auteur')); |
|
| 280 | + if ($id_auteur) { |
|
| 281 | + include_spip('action/editer_auteur'); |
|
| 282 | + auteur_associer($id_auteur, [$objet => $id]); |
|
| 283 | + } |
|
| 284 | + } |
|
| 285 | + |
|
| 286 | + pipeline( |
|
| 287 | + 'post_insertion', |
|
| 288 | + [ |
|
| 289 | + 'args' => [ |
|
| 290 | + 'table' => $table_sql, |
|
| 291 | + 'id_parent' => $id_parent, |
|
| 292 | + 'id_objet' => $id, |
|
| 293 | + ], |
|
| 294 | + 'data' => $champs |
|
| 295 | + ] |
|
| 296 | + ); |
|
| 297 | + } |
|
| 298 | 298 | |
| 299 | - // Appeler une notification |
|
| 300 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | - $notifications( |
|
| 302 | - "{$objet}_inserer", |
|
| 303 | - $id, |
|
| 304 | - [ |
|
| 305 | - 'id_parent' => $id_parent, |
|
| 306 | - 'champs' => $champs, |
|
| 307 | - ] |
|
| 308 | - ); |
|
| 309 | - $notifications( |
|
| 310 | - 'objet_inserer', |
|
| 311 | - $id, |
|
| 312 | - [ |
|
| 313 | - 'objet' => $objet, |
|
| 314 | - 'id_objet' => $id, |
|
| 315 | - 'id_parent' => $id_parent, |
|
| 316 | - 'champs' => $champs, |
|
| 317 | - ] |
|
| 318 | - ); |
|
| 319 | - } |
|
| 320 | - |
|
| 321 | - return $id; |
|
| 299 | + // Appeler une notification |
|
| 300 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 301 | + $notifications( |
|
| 302 | + "{$objet}_inserer", |
|
| 303 | + $id, |
|
| 304 | + [ |
|
| 305 | + 'id_parent' => $id_parent, |
|
| 306 | + 'champs' => $champs, |
|
| 307 | + ] |
|
| 308 | + ); |
|
| 309 | + $notifications( |
|
| 310 | + 'objet_inserer', |
|
| 311 | + $id, |
|
| 312 | + [ |
|
| 313 | + 'objet' => $objet, |
|
| 314 | + 'id_objet' => $id, |
|
| 315 | + 'id_parent' => $id_parent, |
|
| 316 | + 'champs' => $champs, |
|
| 317 | + ] |
|
| 318 | + ); |
|
| 319 | + } |
|
| 320 | + |
|
| 321 | + return $id; |
|
| 322 | 322 | } |
| 323 | 323 | |
| 324 | 324 | |
@@ -335,138 +335,138 @@ discard block |
||
| 335 | 335 | * @return string |
| 336 | 336 | */ |
| 337 | 337 | function objet_instituer($objet, $id, $c, $calcul_rub = true) { |
| 338 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | - spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | - $objet = $t; |
|
| 341 | - } |
|
| 342 | - if ( |
|
| 343 | - include_spip('action/editer_' . $objet) |
|
| 344 | - and function_exists($instituer = $objet . '_instituer') |
|
| 345 | - ) { |
|
| 346 | - return $instituer($id, $c, $calcul_rub); |
|
| 347 | - } |
|
| 348 | - |
|
| 349 | - $table_sql = table_objet_sql($objet); |
|
| 350 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | - $desc = $trouver_table($table_sql); |
|
| 352 | - if (!$desc or !isset($desc['field'])) { |
|
| 353 | - return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - include_spip('inc/autoriser'); |
|
| 357 | - include_spip('inc/rubriques'); |
|
| 358 | - include_spip('inc/modifier'); |
|
| 359 | - |
|
| 360 | - $sel = []; |
|
| 361 | - $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | - |
|
| 363 | - $champ_date = ''; |
|
| 364 | - if (isset($desc['date']) and $desc['date']) { |
|
| 365 | - $champ_date = $desc['date']; |
|
| 366 | - } elseif (isset($desc['field']['date'])) { |
|
| 367 | - $champ_date = 'date'; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | - $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | - |
|
| 373 | - $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | - |
|
| 375 | - $id_rubrique = $row['id_rubrique']; |
|
| 376 | - $statut_ancien = $statut = $row['statut']; |
|
| 377 | - $date_ancienne = $date = $row['date']; |
|
| 378 | - $champs = []; |
|
| 379 | - |
|
| 380 | - $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | - $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | - |
|
| 383 | - // cf autorisations dans inc/instituer_objet |
|
| 384 | - if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | - if ( |
|
| 386 | - $id_rubrique ? |
|
| 387 | - autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | - : |
|
| 389 | - autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | - ) { |
|
| 391 | - $statut = $champs['statut'] = $s; |
|
| 392 | - } else { |
|
| 393 | - if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | - $statut = $champs['statut'] = $s; |
|
| 395 | - } else { |
|
| 396 | - spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | - } |
|
| 398 | - } |
|
| 399 | - |
|
| 400 | - // En cas de publication, fixer la date a "maintenant" |
|
| 401 | - // sauf si $c commande autre chose |
|
| 402 | - // ou si l'objet est deja date dans le futur |
|
| 403 | - // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | - if ($champ_date) { |
|
| 405 | - if ( |
|
| 406 | - $champs['statut'] == 'publie' |
|
| 407 | - or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | - or $d |
|
| 409 | - ) { |
|
| 410 | - if ($d or strtotime($d = $date) > time()) { |
|
| 411 | - $champs[$champ_date] = $date = $d; |
|
| 412 | - } else { |
|
| 413 | - $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | - } |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - } |
|
| 418 | - |
|
| 419 | - // Verifier que la rubrique demandee existe et est differente |
|
| 420 | - // de la rubrique actuelle |
|
| 421 | - if ( |
|
| 422 | - $id_rubrique |
|
| 423 | - and isset($c['id_parent']) |
|
| 424 | - and $id_parent = $c['id_parent'] |
|
| 425 | - and $id_parent != $id_rubrique |
|
| 426 | - and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | - ) { |
|
| 428 | - $champs['id_rubrique'] = $id_parent; |
|
| 429 | - |
|
| 430 | - // si l'objet etait publie |
|
| 431 | - // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | - // repasser l'objet en statut 'propose'. |
|
| 433 | - if ( |
|
| 434 | - $statut == 'publie' |
|
| 435 | - and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | - ) { |
|
| 437 | - $champs['statut'] = 'prop'; |
|
| 438 | - } |
|
| 439 | - } |
|
| 440 | - |
|
| 441 | - |
|
| 442 | - // Envoyer aux plugins |
|
| 443 | - $champs = pipeline( |
|
| 444 | - 'pre_edition', |
|
| 445 | - [ |
|
| 446 | - 'args' => [ |
|
| 447 | - 'table' => $table_sql, |
|
| 448 | - 'id_objet' => $id, |
|
| 449 | - 'action' => 'instituer', |
|
| 450 | - 'statut_ancien' => $statut_ancien, |
|
| 451 | - 'date_ancienne' => $date_ancienne, |
|
| 452 | - 'id_parent_ancien' => $id_rubrique, |
|
| 453 | - ], |
|
| 454 | - 'data' => $champs |
|
| 455 | - ] |
|
| 456 | - ); |
|
| 457 | - |
|
| 458 | - if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | - return ''; |
|
| 460 | - } |
|
| 461 | - |
|
| 462 | - // Envoyer les modifs. |
|
| 463 | - objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | - |
|
| 465 | - // Invalider les caches |
|
| 466 | - include_spip('inc/invalideur'); |
|
| 467 | - suivre_invalideur("id='$objet/$id'"); |
|
| 468 | - |
|
| 469 | - /* |
|
| 338 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 339 | + spip_log("objet_instituer: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 340 | + $objet = $t; |
|
| 341 | + } |
|
| 342 | + if ( |
|
| 343 | + include_spip('action/editer_' . $objet) |
|
| 344 | + and function_exists($instituer = $objet . '_instituer') |
|
| 345 | + ) { |
|
| 346 | + return $instituer($id, $c, $calcul_rub); |
|
| 347 | + } |
|
| 348 | + |
|
| 349 | + $table_sql = table_objet_sql($objet); |
|
| 350 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 351 | + $desc = $trouver_table($table_sql); |
|
| 352 | + if (!$desc or !isset($desc['field'])) { |
|
| 353 | + return _L("Impossible d'instituer $objet : non connu en base"); |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + include_spip('inc/autoriser'); |
|
| 357 | + include_spip('inc/rubriques'); |
|
| 358 | + include_spip('inc/modifier'); |
|
| 359 | + |
|
| 360 | + $sel = []; |
|
| 361 | + $sel[] = (isset($desc['field']['statut']) ? 'statut' : "'' as statut"); |
|
| 362 | + |
|
| 363 | + $champ_date = ''; |
|
| 364 | + if (isset($desc['date']) and $desc['date']) { |
|
| 365 | + $champ_date = $desc['date']; |
|
| 366 | + } elseif (isset($desc['field']['date'])) { |
|
| 367 | + $champ_date = 'date'; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $sel[] = ($champ_date ? "$champ_date as date" : "'' as date"); |
|
| 371 | + $sel[] = (isset($desc['field']['id_rubrique']) ? 'id_rubrique' : '0 as id_rubrique'); |
|
| 372 | + |
|
| 373 | + $row = sql_fetsel($sel, $table_sql, id_table_objet($objet) . '=' . intval($id)); |
|
| 374 | + |
|
| 375 | + $id_rubrique = $row['id_rubrique']; |
|
| 376 | + $statut_ancien = $statut = $row['statut']; |
|
| 377 | + $date_ancienne = $date = $row['date']; |
|
| 378 | + $champs = []; |
|
| 379 | + |
|
| 380 | + $d = ($date and isset($c[$champ_date])) ? $c[$champ_date] : null; |
|
| 381 | + $s = (isset($desc['field']['statut']) and isset($c['statut'])) ? $c['statut'] : $statut; |
|
| 382 | + |
|
| 383 | + // cf autorisations dans inc/instituer_objet |
|
| 384 | + if ($s != $statut or ($d and $d != $date)) { |
|
| 385 | + if ( |
|
| 386 | + $id_rubrique ? |
|
| 387 | + autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 388 | + : |
|
| 389 | + autoriser('instituer', $objet, $id, null, ['statut' => $s]) |
|
| 390 | + ) { |
|
| 391 | + $statut = $champs['statut'] = $s; |
|
| 392 | + } else { |
|
| 393 | + if ($s != 'publie' and autoriser('modifier', $objet, $id)) { |
|
| 394 | + $statut = $champs['statut'] = $s; |
|
| 395 | + } else { |
|
| 396 | + spip_log("editer_objet $objet #$id refus " . json_encode($c, JSON_THROW_ON_ERROR), 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 397 | + } |
|
| 398 | + } |
|
| 399 | + |
|
| 400 | + // En cas de publication, fixer la date a "maintenant" |
|
| 401 | + // sauf si $c commande autre chose |
|
| 402 | + // ou si l'objet est deja date dans le futur |
|
| 403 | + // En cas de proposition d'un objet (mais pas depublication), idem |
|
| 404 | + if ($champ_date) { |
|
| 405 | + if ( |
|
| 406 | + $champs['statut'] == 'publie' |
|
| 407 | + or ($champs['statut'] == 'prop' and !in_array($statut_ancien, ['publie', 'prop'])) |
|
| 408 | + or $d |
|
| 409 | + ) { |
|
| 410 | + if ($d or strtotime($d = $date) > time()) { |
|
| 411 | + $champs[$champ_date] = $date = $d; |
|
| 412 | + } else { |
|
| 413 | + $champs[$champ_date] = $date = date('Y-m-d H:i:s'); |
|
| 414 | + } |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + } |
|
| 418 | + |
|
| 419 | + // Verifier que la rubrique demandee existe et est differente |
|
| 420 | + // de la rubrique actuelle |
|
| 421 | + if ( |
|
| 422 | + $id_rubrique |
|
| 423 | + and isset($c['id_parent']) |
|
| 424 | + and $id_parent = $c['id_parent'] |
|
| 425 | + and $id_parent != $id_rubrique |
|
| 426 | + and (sql_fetsel('1', 'spip_rubriques', 'id_rubrique=' . intval($id_parent))) |
|
| 427 | + ) { |
|
| 428 | + $champs['id_rubrique'] = $id_parent; |
|
| 429 | + |
|
| 430 | + // si l'objet etait publie |
|
| 431 | + // et que le demandeur n'est pas admin de la rubrique |
|
| 432 | + // repasser l'objet en statut 'propose'. |
|
| 433 | + if ( |
|
| 434 | + $statut == 'publie' |
|
| 435 | + and !autoriser('publierdans', 'rubrique', $id_rubrique) |
|
| 436 | + ) { |
|
| 437 | + $champs['statut'] = 'prop'; |
|
| 438 | + } |
|
| 439 | + } |
|
| 440 | + |
|
| 441 | + |
|
| 442 | + // Envoyer aux plugins |
|
| 443 | + $champs = pipeline( |
|
| 444 | + 'pre_edition', |
|
| 445 | + [ |
|
| 446 | + 'args' => [ |
|
| 447 | + 'table' => $table_sql, |
|
| 448 | + 'id_objet' => $id, |
|
| 449 | + 'action' => 'instituer', |
|
| 450 | + 'statut_ancien' => $statut_ancien, |
|
| 451 | + 'date_ancienne' => $date_ancienne, |
|
| 452 | + 'id_parent_ancien' => $id_rubrique, |
|
| 453 | + ], |
|
| 454 | + 'data' => $champs |
|
| 455 | + ] |
|
| 456 | + ); |
|
| 457 | + |
|
| 458 | + if (!(is_countable($champs) ? count($champs) : 0)) { |
|
| 459 | + return ''; |
|
| 460 | + } |
|
| 461 | + |
|
| 462 | + // Envoyer les modifs. |
|
| 463 | + objet_editer_heritage($objet, $id, $id_rubrique, $statut_ancien, $champs, $calcul_rub); |
|
| 464 | + |
|
| 465 | + // Invalider les caches |
|
| 466 | + include_spip('inc/invalideur'); |
|
| 467 | + suivre_invalideur("id='$objet/$id'"); |
|
| 468 | + |
|
| 469 | + /* |
|
| 470 | 470 | if ($date) { |
| 471 | 471 | $t = strtotime($date); |
| 472 | 472 | $p = @$GLOBALS['meta']['date_prochain_postdate']; |
@@ -475,60 +475,60 @@ discard block |
||
| 475 | 475 | } |
| 476 | 476 | }*/ |
| 477 | 477 | |
| 478 | - // Pipeline |
|
| 479 | - pipeline( |
|
| 480 | - 'post_edition', |
|
| 481 | - [ |
|
| 482 | - 'args' => [ |
|
| 483 | - 'table' => $table_sql, |
|
| 484 | - 'id_objet' => $id, |
|
| 485 | - 'action' => 'instituer', |
|
| 486 | - 'statut_ancien' => $statut_ancien, |
|
| 487 | - 'date_ancienne' => $date_ancienne, |
|
| 488 | - 'id_parent_ancien' => $id_rubrique, |
|
| 489 | - ], |
|
| 490 | - 'data' => $champs |
|
| 491 | - ] |
|
| 492 | - ); |
|
| 493 | - |
|
| 494 | - // Notifications |
|
| 495 | - if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | - $notifications( |
|
| 497 | - "{$objet}_instituer", |
|
| 498 | - $id, |
|
| 499 | - [ |
|
| 500 | - 'statut' => $statut, |
|
| 501 | - 'statut_ancien' => $statut_ancien, |
|
| 502 | - 'date' => $date, |
|
| 503 | - 'date_ancienne' => $date_ancienne, |
|
| 504 | - 'id_parent_ancien' => $id_rubrique, |
|
| 505 | - 'champs' => $champs, |
|
| 506 | - ] |
|
| 507 | - ); |
|
| 508 | - $notifications( |
|
| 509 | - 'objet_instituer', |
|
| 510 | - $id, |
|
| 511 | - [ |
|
| 512 | - 'objet' => $objet, |
|
| 513 | - 'id_objet' => $id, |
|
| 514 | - 'statut' => $statut, |
|
| 515 | - 'statut_ancien' => $statut_ancien, |
|
| 516 | - 'date' => $date, |
|
| 517 | - 'date_ancienne' => $date_ancienne, |
|
| 518 | - 'id_parent_ancien' => $id_rubrique, |
|
| 519 | - 'champs' => $champs, |
|
| 520 | - ] |
|
| 521 | - ); |
|
| 478 | + // Pipeline |
|
| 479 | + pipeline( |
|
| 480 | + 'post_edition', |
|
| 481 | + [ |
|
| 482 | + 'args' => [ |
|
| 483 | + 'table' => $table_sql, |
|
| 484 | + 'id_objet' => $id, |
|
| 485 | + 'action' => 'instituer', |
|
| 486 | + 'statut_ancien' => $statut_ancien, |
|
| 487 | + 'date_ancienne' => $date_ancienne, |
|
| 488 | + 'id_parent_ancien' => $id_rubrique, |
|
| 489 | + ], |
|
| 490 | + 'data' => $champs |
|
| 491 | + ] |
|
| 492 | + ); |
|
| 493 | + |
|
| 494 | + // Notifications |
|
| 495 | + if ($notifications = charger_fonction('notifications', 'inc')) { |
|
| 496 | + $notifications( |
|
| 497 | + "{$objet}_instituer", |
|
| 498 | + $id, |
|
| 499 | + [ |
|
| 500 | + 'statut' => $statut, |
|
| 501 | + 'statut_ancien' => $statut_ancien, |
|
| 502 | + 'date' => $date, |
|
| 503 | + 'date_ancienne' => $date_ancienne, |
|
| 504 | + 'id_parent_ancien' => $id_rubrique, |
|
| 505 | + 'champs' => $champs, |
|
| 506 | + ] |
|
| 507 | + ); |
|
| 508 | + $notifications( |
|
| 509 | + 'objet_instituer', |
|
| 510 | + $id, |
|
| 511 | + [ |
|
| 512 | + 'objet' => $objet, |
|
| 513 | + 'id_objet' => $id, |
|
| 514 | + 'statut' => $statut, |
|
| 515 | + 'statut_ancien' => $statut_ancien, |
|
| 516 | + 'date' => $date, |
|
| 517 | + 'date_ancienne' => $date_ancienne, |
|
| 518 | + 'id_parent_ancien' => $id_rubrique, |
|
| 519 | + 'champs' => $champs, |
|
| 520 | + ] |
|
| 521 | + ); |
|
| 522 | 522 | |
| 523 | - // Rétro-compat |
|
| 524 | - $notifications( |
|
| 525 | - "instituer$objet", |
|
| 526 | - $id, |
|
| 527 | - ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | - ); |
|
| 529 | - } |
|
| 530 | - |
|
| 531 | - return ''; // pas d'erreur |
|
| 523 | + // Rétro-compat |
|
| 524 | + $notifications( |
|
| 525 | + "instituer$objet", |
|
| 526 | + $id, |
|
| 527 | + ['statut' => $statut, 'statut_ancien' => $statut_ancien, 'date' => $date, 'date_ancienne' => $date_ancienne] |
|
| 528 | + ); |
|
| 529 | + } |
|
| 530 | + |
|
| 531 | + return ''; // pas d'erreur |
|
| 532 | 532 | } |
| 533 | 533 | |
| 534 | 534 | /** |
@@ -543,51 +543,51 @@ discard block |
||
| 543 | 543 | * @return void |
| 544 | 544 | */ |
| 545 | 545 | function objet_editer_heritage($objet, $id, $id_rubrique, $statut, $champs, $cond = true) { |
| 546 | - $table_sql = table_objet_sql($objet); |
|
| 547 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | - $desc = $trouver_table($table_sql); |
|
| 549 | - |
|
| 550 | - // Si on deplace l'objet |
|
| 551 | - // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | - if (isset($champs['id_rubrique'])) { |
|
| 553 | - $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | - $langue = $row_rub['lang']; |
|
| 555 | - |
|
| 556 | - if (isset($desc['field']['id_secteur'])) { |
|
| 557 | - $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | - } |
|
| 559 | - |
|
| 560 | - if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | - if ( |
|
| 562 | - sql_fetsel( |
|
| 563 | - '1', |
|
| 564 | - $table_sql, |
|
| 565 | - id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | - ) |
|
| 567 | - ) { |
|
| 568 | - $champs['lang'] = $langue; |
|
| 569 | - } |
|
| 570 | - } |
|
| 571 | - } |
|
| 572 | - |
|
| 573 | - if (!$champs) { |
|
| 574 | - return; |
|
| 575 | - } |
|
| 576 | - sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | - |
|
| 578 | - // Changer le statut des rubriques concernees |
|
| 579 | - if ($cond) { |
|
| 580 | - include_spip('inc/rubriques'); |
|
| 581 | - //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | - $postdate = false; |
|
| 583 | - // On rajoute les infos de l'objet |
|
| 584 | - $infos = [ |
|
| 585 | - 'objet' => $objet, |
|
| 586 | - 'id_objet' => $id, |
|
| 587 | - 'statut_ancien' => $statut, |
|
| 588 | - ]; |
|
| 589 | - calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | - } |
|
| 546 | + $table_sql = table_objet_sql($objet); |
|
| 547 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 548 | + $desc = $trouver_table($table_sql); |
|
| 549 | + |
|
| 550 | + // Si on deplace l'objet |
|
| 551 | + // changer aussi son secteur et sa langue (si heritee) |
|
| 552 | + if (isset($champs['id_rubrique'])) { |
|
| 553 | + $row_rub = sql_fetsel('id_secteur, lang', 'spip_rubriques', 'id_rubrique=' . sql_quote($champs['id_rubrique'])); |
|
| 554 | + $langue = $row_rub['lang']; |
|
| 555 | + |
|
| 556 | + if (isset($desc['field']['id_secteur'])) { |
|
| 557 | + $champs['id_secteur'] = $row_rub['id_secteur']; |
|
| 558 | + } |
|
| 559 | + |
|
| 560 | + if (isset($desc['field']['lang']) and isset($desc['field']['langue_choisie'])) { |
|
| 561 | + if ( |
|
| 562 | + sql_fetsel( |
|
| 563 | + '1', |
|
| 564 | + $table_sql, |
|
| 565 | + id_table_objet($objet) . '=' . intval($id) . " AND langue_choisie<>'oui' AND lang<>" . sql_quote($langue) |
|
| 566 | + ) |
|
| 567 | + ) { |
|
| 568 | + $champs['lang'] = $langue; |
|
| 569 | + } |
|
| 570 | + } |
|
| 571 | + } |
|
| 572 | + |
|
| 573 | + if (!$champs) { |
|
| 574 | + return; |
|
| 575 | + } |
|
| 576 | + sql_updateq($table_sql, $champs, id_table_objet($objet) . '=' . intval($id)); |
|
| 577 | + |
|
| 578 | + // Changer le statut des rubriques concernees |
|
| 579 | + if ($cond) { |
|
| 580 | + include_spip('inc/rubriques'); |
|
| 581 | + //$postdate = ($GLOBALS['meta']["post_dates"] == "non" AND isset($champs['date']) AND (strtotime($champs['date']) < time()))?$champs['date']:false; |
|
| 582 | + $postdate = false; |
|
| 583 | + // On rajoute les infos de l'objet |
|
| 584 | + $infos = [ |
|
| 585 | + 'objet' => $objet, |
|
| 586 | + 'id_objet' => $id, |
|
| 587 | + 'statut_ancien' => $statut, |
|
| 588 | + ]; |
|
| 589 | + calculer_rubriques_if($id_rubrique, $champs, $infos, $postdate); |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | |
@@ -616,75 +616,75 @@ discard block |
||
| 616 | 616 | * string|int : valeur du champ demande pour l'objet demande |
| 617 | 617 | */ |
| 618 | 618 | function objet_lire($objet, $valeur_id, $options = []) { |
| 619 | - if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | - spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | - $objet = $t; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | - // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | - static $descriptions = []; |
|
| 627 | - |
|
| 628 | - // On détermine le nom du champ id de la table. |
|
| 629 | - include_spip('base/objets'); |
|
| 630 | - $primary = id_table_objet($objet); |
|
| 631 | - |
|
| 632 | - // On détermine l'id à utiliser. |
|
| 633 | - $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | - |
|
| 635 | - // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | - if ( |
|
| 637 | - !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | - or (isset($options['force']) and $options['force']) |
|
| 639 | - ) { |
|
| 640 | - // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | - if ( |
|
| 642 | - include_spip('action/editer_' . $objet) |
|
| 643 | - and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | - ) { |
|
| 645 | - $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | - } else { |
|
| 647 | - // On récupère la table SQL à partir du type d'objet. |
|
| 648 | - $table = table_objet_sql($objet); |
|
| 649 | - |
|
| 650 | - // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | - $where = [ |
|
| 652 | - $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | - ]; |
|
| 654 | - |
|
| 655 | - // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | - $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | - } |
|
| 658 | - |
|
| 659 | - if (!$valeurs) { |
|
| 660 | - $valeurs = false; |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | - |
|
| 665 | - if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | - $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | - $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | - } |
|
| 669 | - } |
|
| 670 | - |
|
| 671 | - $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | - |
|
| 673 | - // On ne retourne maintenant que les champs demandés. |
|
| 674 | - // - on détermine les informations à renvoyer. |
|
| 675 | - if ($retour and !empty($options['champs'])) { |
|
| 676 | - $champs = $options['champs']; |
|
| 677 | - // Extraction des seules informations demandées. |
|
| 678 | - // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | - // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | - if (is_array($champs)) { |
|
| 681 | - // Tableau des informations valides |
|
| 682 | - $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | - } else { |
|
| 684 | - // Valeur unique demandée. |
|
| 685 | - $retour = ($retour[$champs] ?? false); |
|
| 686 | - } |
|
| 687 | - } |
|
| 688 | - |
|
| 689 | - return $retour; |
|
| 619 | + if (($t = objet_type($objet)) !== $objet) { |
|
| 620 | + spip_log("objet_lire: appel avec type $objet invalide au lieu de $t", 'editer' . _LOG_INFO_IMPORTANTE); |
|
| 621 | + $objet = $t; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // tableau du cache des descriptions et des id d'objet (au sens id_xxx). |
|
| 625 | + // Les tableaux sont toujours indexés par le trio [objet][cle][valeur_cle] |
|
| 626 | + static $descriptions = []; |
|
| 627 | + |
|
| 628 | + // On détermine le nom du champ id de la table. |
|
| 629 | + include_spip('base/objets'); |
|
| 630 | + $primary = id_table_objet($objet); |
|
| 631 | + |
|
| 632 | + // On détermine l'id à utiliser. |
|
| 633 | + $champ_id = (!empty($options['champ_id']) ? $options['champ_id'] : $primary); |
|
| 634 | + |
|
| 635 | + // Si l'objet n'a pas encore été stocké, il faut récupérer sa description complète. |
|
| 636 | + if ( |
|
| 637 | + !isset($descriptions[$objet][$champ_id][$valeur_id]) |
|
| 638 | + or (isset($options['force']) and $options['force']) |
|
| 639 | + ) { |
|
| 640 | + // Il est possible pour un type d'objet de fournir une fonction de lecture de tous les champs d'un objet. |
|
| 641 | + if ( |
|
| 642 | + include_spip('action/editer_' . $objet) |
|
| 643 | + and function_exists($lire = "{$objet}_lire_champs") |
|
| 644 | + ) { |
|
| 645 | + $valeurs = $lire($objet, $valeur_id, $champ_id); |
|
| 646 | + } else { |
|
| 647 | + // On récupère la table SQL à partir du type d'objet. |
|
| 648 | + $table = table_objet_sql($objet); |
|
| 649 | + |
|
| 650 | + // La condition est appliquée sur le champ désigné par l'utilisateur. |
|
| 651 | + $where = [ |
|
| 652 | + $champ_id . '=' . sql_quote($valeur_id) |
|
| 653 | + ]; |
|
| 654 | + |
|
| 655 | + // Acquisition de tous les champs de l'objet : si l'accès SQL retourne une erreur on renvoie un tableau vide. |
|
| 656 | + $valeurs = sql_fetsel('*', $table, $where); |
|
| 657 | + } |
|
| 658 | + |
|
| 659 | + if (!$valeurs) { |
|
| 660 | + $valeurs = false; |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + $descriptions[$objet][$champ_id][$valeur_id] = $valeurs; |
|
| 664 | + |
|
| 665 | + if ($champ_id !== $primary and isset($valeurs[$primary])) { |
|
| 666 | + $descriptions[$objet][$primary][$valeurs[$primary]] = $valeurs; |
|
| 667 | + $descriptions[$objet][$champ_id][$valeur_id] = &$descriptions[$objet][$primary][$valeurs[$primary]]; |
|
| 668 | + } |
|
| 669 | + } |
|
| 670 | + |
|
| 671 | + $retour = $descriptions[$objet][$champ_id][$valeur_id]; |
|
| 672 | + |
|
| 673 | + // On ne retourne maintenant que les champs demandés. |
|
| 674 | + // - on détermine les informations à renvoyer. |
|
| 675 | + if ($retour and !empty($options['champs'])) { |
|
| 676 | + $champs = $options['champs']; |
|
| 677 | + // Extraction des seules informations demandées. |
|
| 678 | + // -- si on demande une information unique on renvoie la valeur simple, sinon on renvoie un tableau. |
|
| 679 | + // -- si une information n'est pas un champ valide elle n'est pas renvoyée sans renvoyer d'erreur. |
|
| 680 | + if (is_array($champs)) { |
|
| 681 | + // Tableau des informations valides |
|
| 682 | + $retour = array_intersect_key($retour, array_flip($champs)); |
|
| 683 | + } else { |
|
| 684 | + // Valeur unique demandée. |
|
| 685 | + $retour = ($retour[$champs] ?? false); |
|
| 686 | + } |
|
| 687 | + } |
|
| 688 | + |
|
| 689 | + return $retour; |
|
| 690 | 690 | } |