@@ -164,8 +164,7 @@ discard block |
||
| 164 | 164 | |
| 165 | 165 | if ($start === false || $start === 'end') { |
| 166 | 166 | $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
| 167 | - } |
|
| 168 | - else { |
|
| 167 | + } else { |
|
| 169 | 168 | $p = stripos($svg, '<svg'); |
| 170 | 169 | $p = strpos($svg, '>', $p); |
| 171 | 170 | $svg = substr_replace($svg, $shapes, $p + 1, 0); |
@@ -224,8 +223,7 @@ discard block |
||
| 224 | 223 | if (str_starts_with($couleur, 'rgb(')) { |
| 225 | 224 | $c = explode(',', substr($couleur, 4)); |
| 226 | 225 | $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
| 227 | - } |
|
| 228 | - else { |
|
| 226 | + } else { |
|
| 229 | 227 | $couleur = couleur_html_to_hex($couleur); |
| 230 | 228 | } |
| 231 | 229 | return '#' . ltrim($couleur, '#'); |
@@ -281,17 +279,14 @@ discard block |
||
| 281 | 279 | // si pas de height valide, on suppose l'image carree |
| 282 | 280 | $viewBox[3] = $width; |
| 283 | 281 | } |
| 284 | - } |
|
| 285 | - else { |
|
| 282 | + } else { |
|
| 286 | 283 | // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
| 287 | 284 | $width = $viewBox[2]; |
| 288 | 285 | if ($width < 1) { |
| 289 | 286 | $coeff = max($coeff, 1000); |
| 290 | - } |
|
| 291 | - elseif ($width < 10) { |
|
| 287 | + } elseif ($width < 10) { |
|
| 292 | 288 | $coeff = max($coeff, 100); |
| 293 | - } |
|
| 294 | - elseif ($width < 100) { |
|
| 289 | + } elseif ($width < 100) { |
|
| 295 | 290 | $coeff = max($coeff, 10); |
| 296 | 291 | } |
| 297 | 292 | } |
@@ -304,16 +299,13 @@ discard block |
||
| 304 | 299 | if (empty($attributs['viewBox'])) { |
| 305 | 300 | $viewBox[3] = $height; |
| 306 | 301 | } |
| 307 | - } |
|
| 308 | - else { |
|
| 302 | + } else { |
|
| 309 | 303 | $height = $viewBox[3]; |
| 310 | 304 | if ($height < 1) { |
| 311 | 305 | $coeff = max($coeff, 1000); |
| 312 | - } |
|
| 313 | - elseif ($height < 10) { |
|
| 306 | + } elseif ($height < 10) { |
|
| 314 | 307 | $coeff = max($coeff, 100); |
| 315 | - } |
|
| 316 | - elseif ($height < 100) { |
|
| 308 | + } elseif ($height < 100) { |
|
| 317 | 309 | $coeff = max($coeff, 10); |
| 318 | 310 | } |
| 319 | 311 | } |
@@ -454,8 +446,7 @@ discard block |
||
| 454 | 446 | if (isset($attributs['viewBox'])) { |
| 455 | 447 | $viewBox = explode(' ', $attributs['viewBox']); |
| 456 | 448 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
| 457 | - } |
|
| 458 | - else { |
|
| 449 | + } else { |
|
| 459 | 450 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 460 | 451 | } |
| 461 | 452 | $svg = svg_insert_shapes($svg, $rect); |
@@ -484,8 +475,7 @@ discard block |
||
| 484 | 475 | if (isset($attributs['viewBox'])) { |
| 485 | 476 | $viewBox = explode(' ', $attributs['viewBox']); |
| 486 | 477 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
| 487 | - } |
|
| 488 | - else { |
|
| 478 | + } else { |
|
| 489 | 479 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 490 | 480 | } |
| 491 | 481 | $svg = svg_insert_shapes($svg, $rect, false); |
@@ -606,8 +596,7 @@ discard block |
||
| 606 | 596 | $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
| 607 | 597 | $mx = -$x; |
| 608 | 598 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 609 | - } |
|
| 610 | - else { |
|
| 599 | + } else { |
|
| 611 | 600 | $transform = 'scale(1,-1)'; |
| 612 | 601 | |
| 613 | 602 | $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
@@ -666,8 +655,7 @@ discard block |
||
| 666 | 655 | $c = array_shift($colors); |
| 667 | 656 | if (strlen($c) == 4) { |
| 668 | 657 | $short[] = $c; |
| 669 | - } |
|
| 670 | - else { |
|
| 658 | + } else { |
|
| 671 | 659 | $long[] = $c; |
| 672 | 660 | } |
| 673 | 661 | } |
@@ -16,13 +16,13 @@ discard block |
||
| 16 | 16 | **/ |
| 17 | 17 | |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | if (!defined('IMG_SVG')) { |
| 23 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | - define('IMG_SVG', 128); |
|
| 25 | - define('IMAGETYPE_SVG', 19); |
|
| 23 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 24 | + define('IMG_SVG', 128); |
|
| 25 | + define('IMAGETYPE_SVG', 19); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -38,35 +38,35 @@ discard block |
||
| 38 | 38 | * false si on a pas pu charger l'image |
| 39 | 39 | */ |
| 40 | 40 | function svg_charger($fichier, $maxlen = null) { |
| 41 | - if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | - $image = explode(';', $fichier, 2); |
|
| 43 | - $image = end($image); |
|
| 44 | - if (str_starts_with($image, 'base64,')) { |
|
| 45 | - $image = base64_decode(substr($image, 7)); |
|
| 46 | - } |
|
| 47 | - if (str_contains($image, '<svg')) { |
|
| 48 | - return $image; |
|
| 49 | - } |
|
| 50 | - // encodage inconnu ou autre format d'image ? |
|
| 51 | - return false; |
|
| 52 | - } |
|
| 53 | - // c'est peut etre deja une image svg ? |
|
| 54 | - if (str_contains($fichier, '<svg')) { |
|
| 55 | - return $fichier; |
|
| 56 | - } |
|
| 57 | - if (!file_exists($fichier)) { |
|
| 58 | - include_spip('inc/filtres'); |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 65 | - // est-ce bien une image svg ? |
|
| 66 | - if (str_contains($image, '<svg')) { |
|
| 67 | - return $image; |
|
| 68 | - } |
|
| 69 | - return false; |
|
| 41 | + if (str_starts_with($fichier, 'data:image/svg+xml')) { |
|
| 42 | + $image = explode(';', $fichier, 2); |
|
| 43 | + $image = end($image); |
|
| 44 | + if (str_starts_with($image, 'base64,')) { |
|
| 45 | + $image = base64_decode(substr($image, 7)); |
|
| 46 | + } |
|
| 47 | + if (str_contains($image, '<svg')) { |
|
| 48 | + return $image; |
|
| 49 | + } |
|
| 50 | + // encodage inconnu ou autre format d'image ? |
|
| 51 | + return false; |
|
| 52 | + } |
|
| 53 | + // c'est peut etre deja une image svg ? |
|
| 54 | + if (str_contains($fichier, '<svg')) { |
|
| 55 | + return $fichier; |
|
| 56 | + } |
|
| 57 | + if (!file_exists($fichier)) { |
|
| 58 | + include_spip('inc/filtres'); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + $image = is_null($maxlen) ? file_get_contents($fichier) : file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 65 | + // est-ce bien une image svg ? |
|
| 66 | + if (str_contains($image, '<svg')) { |
|
| 67 | + return $image; |
|
| 68 | + } |
|
| 69 | + return false; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | /** |
@@ -75,28 +75,28 @@ discard block |
||
| 75 | 75 | * @return array|bool |
| 76 | 76 | */ |
| 77 | 77 | function svg_lire_balise_svg($fichier) { |
| 78 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 79 | - return false; |
|
| 80 | - } |
|
| 81 | - |
|
| 82 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 83 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 84 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 85 | - |
|
| 86 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 87 | - if (!function_exists('extraire_attribut')) { |
|
| 88 | - include_spip('inc/filtres'); |
|
| 89 | - } |
|
| 90 | - $attributs = []; |
|
| 91 | - foreach ($matches[1] as $att) { |
|
| 92 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return [$balise_svg, $attributs]; |
|
| 96 | - } |
|
| 97 | - } |
|
| 98 | - |
|
| 99 | - return false; |
|
| 78 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 79 | + return false; |
|
| 80 | + } |
|
| 81 | + |
|
| 82 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 83 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 84 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 85 | + |
|
| 86 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 87 | + if (!function_exists('extraire_attribut')) { |
|
| 88 | + include_spip('inc/filtres'); |
|
| 89 | + } |
|
| 90 | + $attributs = []; |
|
| 91 | + foreach ($matches[1] as $att) { |
|
| 92 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return [$balise_svg, $attributs]; |
|
| 96 | + } |
|
| 97 | + } |
|
| 98 | + |
|
| 99 | + return false; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -106,12 +106,12 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | function svg_lire_attributs($img) { |
| 108 | 108 | |
| 109 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 110 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 111 | - return $attributs; |
|
| 112 | - } |
|
| 109 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 110 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 111 | + return $attributs; |
|
| 112 | + } |
|
| 113 | 113 | |
| 114 | - return false; |
|
| 114 | + return false; |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -121,19 +121,19 @@ discard block |
||
| 121 | 121 | * @return bool|float|int |
| 122 | 122 | */ |
| 123 | 123 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 124 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 125 | - return match (strtolower($m[2])) { |
|
| 126 | - '%' => false, |
|
| 127 | - 'em' => round($m[1] * 16, $precision), |
|
| 128 | - 'ex' => round($m[1] * 16, $precision), |
|
| 129 | - 'pc' => round($m[1] * 16, $precision), |
|
| 130 | - 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 131 | - 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 132 | - 'in' => round($m[1] * 96, $precision), |
|
| 133 | - default => $m[1], |
|
| 134 | - }; |
|
| 135 | - } |
|
| 136 | - return false; |
|
| 124 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 125 | + return match (strtolower($m[2])) { |
|
| 126 | + '%' => false, |
|
| 127 | + 'em' => round($m[1] * 16, $precision), |
|
| 128 | + 'ex' => round($m[1] * 16, $precision), |
|
| 129 | + 'pc' => round($m[1] * 16, $precision), |
|
| 130 | + 'cm' => round($m[1] * 96 / 2.54, $precision), |
|
| 131 | + 'mm' => round($m[1] * 96 / 25.4, $precision), |
|
| 132 | + 'in' => round($m[1] * 96, $precision), |
|
| 133 | + default => $m[1], |
|
| 134 | + }; |
|
| 135 | + } |
|
| 136 | + return false; |
|
| 137 | 137 | } |
| 138 | 138 | |
| 139 | 139 | /** |
@@ -144,14 +144,14 @@ discard block |
||
| 144 | 144 | * @return string |
| 145 | 145 | */ |
| 146 | 146 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 147 | - $new_balise_svg = '<svg'; |
|
| 148 | - foreach ($attributs as $k => $v) { |
|
| 149 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 150 | - } |
|
| 151 | - $new_balise_svg .= '>'; |
|
| 152 | - |
|
| 153 | - $p = strpos($svg, $old_balise_svg); |
|
| 154 | - return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 147 | + $new_balise_svg = '<svg'; |
|
| 148 | + foreach ($attributs as $k => $v) { |
|
| 149 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 150 | + } |
|
| 151 | + $new_balise_svg .= '>'; |
|
| 152 | + |
|
| 153 | + $p = strpos($svg, $old_balise_svg); |
|
| 154 | + return substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 155 | 155 | } |
| 156 | 156 | |
| 157 | 157 | /** |
@@ -163,15 +163,15 @@ discard block |
||
| 163 | 163 | */ |
| 164 | 164 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 165 | 165 | |
| 166 | - if ($start === false || $start === 'end') { |
|
| 167 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 168 | - } |
|
| 169 | - else { |
|
| 170 | - $p = stripos($svg, '<svg'); |
|
| 171 | - $p = strpos($svg, '>', $p); |
|
| 172 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 173 | - } |
|
| 174 | - return $svg; |
|
| 166 | + if ($start === false || $start === 'end') { |
|
| 167 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 168 | + } |
|
| 169 | + else { |
|
| 170 | + $p = stripos($svg, '<svg'); |
|
| 171 | + $p = strpos($svg, '>', $p); |
|
| 172 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 173 | + } |
|
| 174 | + return $svg; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -184,12 +184,12 @@ discard block |
||
| 184 | 184 | * @return string |
| 185 | 185 | */ |
| 186 | 186 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 187 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 188 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 189 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 190 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 191 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 192 | - return svg_insert_shapes($svg, '</g>', false); |
|
| 187 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 188 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 189 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 190 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 191 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 192 | + return svg_insert_shapes($svg, '</g>', false); |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -200,20 +200,20 @@ discard block |
||
| 200 | 200 | * @return bool|string |
| 201 | 201 | */ |
| 202 | 202 | function svg_redimensionner($img, $new_width, $new_height) { |
| 203 | - if ( |
|
| 204 | - ($svg = svg_charger($img)) |
|
| 205 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 206 | - ) { |
|
| 207 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 208 | - if (!isset($attributs['viewBox'])) { |
|
| 209 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 210 | - } |
|
| 211 | - $attributs['width'] = (string) $new_width; |
|
| 212 | - $attributs['height'] = (string) $new_height; |
|
| 213 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 214 | - } |
|
| 215 | - |
|
| 216 | - return $img; |
|
| 203 | + if ( |
|
| 204 | + ($svg = svg_charger($img)) |
|
| 205 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 206 | + ) { |
|
| 207 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 208 | + if (!isset($attributs['viewBox'])) { |
|
| 209 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 210 | + } |
|
| 211 | + $attributs['width'] = (string) $new_width; |
|
| 212 | + $attributs['height'] = (string) $new_height; |
|
| 213 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 214 | + } |
|
| 215 | + |
|
| 216 | + return $img; |
|
| 217 | 217 | } |
| 218 | 218 | |
| 219 | 219 | /** |
@@ -222,14 +222,14 @@ discard block |
||
| 222 | 222 | * @return string |
| 223 | 223 | */ |
| 224 | 224 | function svg_couleur_to_hexa($couleur) { |
| 225 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 226 | - $c = explode(',', substr($couleur, 4)); |
|
| 227 | - $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 228 | - } |
|
| 229 | - else { |
|
| 230 | - $couleur = couleur_html_to_hex($couleur); |
|
| 231 | - } |
|
| 232 | - return '#' . ltrim($couleur, '#'); |
|
| 225 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 226 | + $c = explode(',', substr($couleur, 4)); |
|
| 227 | + $couleur = _couleur_dec_to_hex((int) $c[0], (int) $c[1], (int) $c[2]); |
|
| 228 | + } |
|
| 229 | + else { |
|
| 230 | + $couleur = couleur_html_to_hex($couleur); |
|
| 231 | + } |
|
| 232 | + return '#' . ltrim($couleur, '#'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -238,11 +238,11 @@ discard block |
||
| 238 | 238 | * @return array |
| 239 | 239 | */ |
| 240 | 240 | function svg_couleur_to_rgb($couleur) { |
| 241 | - if (str_starts_with($couleur, 'rgb(')) { |
|
| 242 | - $c = explode(',', substr($couleur, 4)); |
|
| 243 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 244 | - } |
|
| 245 | - return _couleur_hex_to_dec($couleur); |
|
| 241 | + if (str_starts_with($couleur, 'rgb(')) { |
|
| 242 | + $c = explode(',', substr($couleur, 4)); |
|
| 243 | + return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 244 | + } |
|
| 245 | + return _couleur_hex_to_dec($couleur); |
|
| 246 | 246 | } |
| 247 | 247 | |
| 248 | 248 | |
@@ -252,80 +252,80 @@ discard block |
||
| 252 | 252 | * @return array |
| 253 | 253 | */ |
| 254 | 254 | function svg_getimagesize_from_attr($attributs) { |
| 255 | - $width = 350; // default width |
|
| 256 | - $height = 150; // default height |
|
| 257 | - |
|
| 258 | - $viewBox = "0 0 $width $height"; |
|
| 259 | - if (isset($attributs['viewBox'])) { |
|
| 260 | - $viewBox = $attributs['viewBox']; |
|
| 261 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 262 | - } |
|
| 263 | - // et on la convertit en px |
|
| 264 | - $viewBox = explode(' ', $viewBox); |
|
| 265 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 266 | - if (!$viewBox[2]) { |
|
| 267 | - $viewBox[2] = $width; |
|
| 268 | - } |
|
| 269 | - if (!$viewBox[3]) { |
|
| 270 | - $viewBox[3] = $height; |
|
| 271 | - } |
|
| 272 | - |
|
| 273 | - $coeff = 1; |
|
| 274 | - if ( |
|
| 275 | - isset($attributs['width']) |
|
| 276 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 277 | - ) { |
|
| 278 | - $width = $w; |
|
| 279 | - // si on avait pas de viewBox, la construire a partir de ce width |
|
| 280 | - if (empty($attributs['viewBox'])) { |
|
| 281 | - $viewBox[2] = $width; |
|
| 282 | - // si pas de height valide, on suppose l'image carree |
|
| 283 | - $viewBox[3] = $width; |
|
| 284 | - } |
|
| 285 | - } |
|
| 286 | - else { |
|
| 287 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 288 | - $width = $viewBox[2]; |
|
| 289 | - if ($width < 1) { |
|
| 290 | - $coeff = max($coeff, 1000); |
|
| 291 | - } |
|
| 292 | - elseif ($width < 10) { |
|
| 293 | - $coeff = max($coeff, 100); |
|
| 294 | - } |
|
| 295 | - elseif ($width < 100) { |
|
| 296 | - $coeff = max($coeff, 10); |
|
| 297 | - } |
|
| 298 | - } |
|
| 299 | - if ( |
|
| 300 | - isset($attributs['height']) |
|
| 301 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 302 | - ) { |
|
| 303 | - $height = $h; |
|
| 304 | - // si on avait pas de viewBox, la construire a partir de ce height |
|
| 305 | - if (empty($attributs['viewBox'])) { |
|
| 306 | - $viewBox[3] = $height; |
|
| 307 | - } |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - $height = $viewBox[3]; |
|
| 311 | - if ($height < 1) { |
|
| 312 | - $coeff = max($coeff, 1000); |
|
| 313 | - } |
|
| 314 | - elseif ($height < 10) { |
|
| 315 | - $coeff = max($coeff, 100); |
|
| 316 | - } |
|
| 317 | - elseif ($height < 100) { |
|
| 318 | - $coeff = max($coeff, 10); |
|
| 319 | - } |
|
| 320 | - } |
|
| 321 | - |
|
| 322 | - // arrondir le width et height en pixel in fine |
|
| 323 | - $width = round($coeff * $width); |
|
| 324 | - $height = round($coeff * $height); |
|
| 325 | - |
|
| 326 | - $viewBox = implode(' ', $viewBox); |
|
| 327 | - |
|
| 328 | - return [$width, $height, $viewBox]; |
|
| 255 | + $width = 350; // default width |
|
| 256 | + $height = 150; // default height |
|
| 257 | + |
|
| 258 | + $viewBox = "0 0 $width $height"; |
|
| 259 | + if (isset($attributs['viewBox'])) { |
|
| 260 | + $viewBox = $attributs['viewBox']; |
|
| 261 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 262 | + } |
|
| 263 | + // et on la convertit en px |
|
| 264 | + $viewBox = explode(' ', $viewBox); |
|
| 265 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 266 | + if (!$viewBox[2]) { |
|
| 267 | + $viewBox[2] = $width; |
|
| 268 | + } |
|
| 269 | + if (!$viewBox[3]) { |
|
| 270 | + $viewBox[3] = $height; |
|
| 271 | + } |
|
| 272 | + |
|
| 273 | + $coeff = 1; |
|
| 274 | + if ( |
|
| 275 | + isset($attributs['width']) |
|
| 276 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 277 | + ) { |
|
| 278 | + $width = $w; |
|
| 279 | + // si on avait pas de viewBox, la construire a partir de ce width |
|
| 280 | + if (empty($attributs['viewBox'])) { |
|
| 281 | + $viewBox[2] = $width; |
|
| 282 | + // si pas de height valide, on suppose l'image carree |
|
| 283 | + $viewBox[3] = $width; |
|
| 284 | + } |
|
| 285 | + } |
|
| 286 | + else { |
|
| 287 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 288 | + $width = $viewBox[2]; |
|
| 289 | + if ($width < 1) { |
|
| 290 | + $coeff = max($coeff, 1000); |
|
| 291 | + } |
|
| 292 | + elseif ($width < 10) { |
|
| 293 | + $coeff = max($coeff, 100); |
|
| 294 | + } |
|
| 295 | + elseif ($width < 100) { |
|
| 296 | + $coeff = max($coeff, 10); |
|
| 297 | + } |
|
| 298 | + } |
|
| 299 | + if ( |
|
| 300 | + isset($attributs['height']) |
|
| 301 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 302 | + ) { |
|
| 303 | + $height = $h; |
|
| 304 | + // si on avait pas de viewBox, la construire a partir de ce height |
|
| 305 | + if (empty($attributs['viewBox'])) { |
|
| 306 | + $viewBox[3] = $height; |
|
| 307 | + } |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + $height = $viewBox[3]; |
|
| 311 | + if ($height < 1) { |
|
| 312 | + $coeff = max($coeff, 1000); |
|
| 313 | + } |
|
| 314 | + elseif ($height < 10) { |
|
| 315 | + $coeff = max($coeff, 100); |
|
| 316 | + } |
|
| 317 | + elseif ($height < 100) { |
|
| 318 | + $coeff = max($coeff, 10); |
|
| 319 | + } |
|
| 320 | + } |
|
| 321 | + |
|
| 322 | + // arrondir le width et height en pixel in fine |
|
| 323 | + $width = round($coeff * $width); |
|
| 324 | + $height = round($coeff * $height); |
|
| 325 | + |
|
| 326 | + $viewBox = implode(' ', $viewBox); |
|
| 327 | + |
|
| 328 | + return [$width, $height, $viewBox]; |
|
| 329 | 329 | } |
| 330 | 330 | |
| 331 | 331 | /** |
@@ -341,23 +341,23 @@ discard block |
||
| 341 | 341 | * @return string |
| 342 | 342 | */ |
| 343 | 343 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 344 | - if ( |
|
| 345 | - ($svg = svg_charger($img)) |
|
| 346 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 347 | - ) { |
|
| 348 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 349 | - |
|
| 350 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 351 | - |
|
| 352 | - if ($force_width_and_height) { |
|
| 353 | - $attributs['width'] = $width; |
|
| 354 | - $attributs['height'] = $height; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - $attributs['viewBox'] = $viewBox; |
|
| 358 | - return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 359 | - } |
|
| 360 | - return $img; |
|
| 344 | + if ( |
|
| 345 | + ($svg = svg_charger($img)) |
|
| 346 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 347 | + ) { |
|
| 348 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 349 | + |
|
| 350 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 351 | + |
|
| 352 | + if ($force_width_and_height) { |
|
| 353 | + $attributs['width'] = $width; |
|
| 354 | + $attributs['height'] = $height; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + $attributs['viewBox'] = $viewBox; |
|
| 358 | + return svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 359 | + } |
|
| 360 | + return $img; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | /** |
@@ -366,13 +366,13 @@ discard block |
||
| 366 | 366 | * @return array|mixed |
| 367 | 367 | */ |
| 368 | 368 | function svg_extract_couleurs($img) { |
| 369 | - if ( |
|
| 370 | - ($svg = svg_charger($img)) |
|
| 371 | - && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 372 | - ) { |
|
| 373 | - return $matches[0]; |
|
| 374 | - } |
|
| 375 | - return []; |
|
| 369 | + if ( |
|
| 370 | + ($svg = svg_charger($img)) |
|
| 371 | + && preg_match_all('/(#[0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f][0-9a-f])|(rgb\([\s\d]+,[\s\d]+,[\s\d]+\))|(#[0-9a-f][0-9a-f][0-9a-f])/imS', $svg, $matches) |
|
| 372 | + ) { |
|
| 373 | + return $matches[0]; |
|
| 374 | + } |
|
| 375 | + return []; |
|
| 376 | 376 | } |
| 377 | 377 | |
| 378 | 378 | /** |
@@ -383,58 +383,58 @@ discard block |
||
| 383 | 383 | * @return bool|string |
| 384 | 384 | */ |
| 385 | 385 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 386 | - if ( |
|
| 387 | - ($svg = svg_force_viewBox_px($img)) |
|
| 388 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 389 | - ) { |
|
| 390 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 391 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 392 | - |
|
| 393 | - $viewport_w = $new_width; |
|
| 394 | - $viewport_h = $new_height; |
|
| 395 | - $viewport_ox = $offset_width; |
|
| 396 | - $viewport_oy = $offset_height; |
|
| 397 | - |
|
| 398 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 399 | - if ( |
|
| 400 | - isset($attributs['width']) |
|
| 401 | - && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 402 | - && isset($attributs['height']) |
|
| 403 | - && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 404 | - ) { |
|
| 405 | - $xscale = $viewBox[2] / $w; |
|
| 406 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 407 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 408 | - $yscale = $viewBox[3] / $h; |
|
| 409 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 410 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 414 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // maintenant on redefinit la viewBox |
|
| 418 | - $viewBox[0] += $viewport_ox; |
|
| 419 | - $viewBox[1] += $viewport_oy; |
|
| 420 | - $viewBox[2] = $viewport_w; |
|
| 421 | - $viewBox[3] = $viewport_h; |
|
| 422 | - |
|
| 423 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 424 | - $attributs['width'] = (string) $new_width; |
|
| 425 | - $attributs['height'] = (string) $new_height; |
|
| 426 | - |
|
| 427 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 428 | - |
|
| 429 | - // ajouter un background |
|
| 430 | - if ($background_color && $background_color !== 'transparent') { |
|
| 431 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - return $svg; |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - return $img; |
|
| 386 | + if ( |
|
| 387 | + ($svg = svg_force_viewBox_px($img)) |
|
| 388 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 389 | + ) { |
|
| 390 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 391 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 392 | + |
|
| 393 | + $viewport_w = $new_width; |
|
| 394 | + $viewport_h = $new_height; |
|
| 395 | + $viewport_ox = $offset_width; |
|
| 396 | + $viewport_oy = $offset_height; |
|
| 397 | + |
|
| 398 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 399 | + if ( |
|
| 400 | + isset($attributs['width']) |
|
| 401 | + && ($w = svg_dimension_to_pixels($attributs['width'])) |
|
| 402 | + && isset($attributs['height']) |
|
| 403 | + && ($h = svg_dimension_to_pixels($attributs['height'])) |
|
| 404 | + ) { |
|
| 405 | + $xscale = $viewBox[2] / $w; |
|
| 406 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 407 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 408 | + $yscale = $viewBox[3] / $h; |
|
| 409 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 410 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + if ($viewport_w > $viewBox[2] || $viewport_h > $viewBox[3]) { |
|
| 414 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // maintenant on redefinit la viewBox |
|
| 418 | + $viewBox[0] += $viewport_ox; |
|
| 419 | + $viewBox[1] += $viewport_oy; |
|
| 420 | + $viewBox[2] = $viewport_w; |
|
| 421 | + $viewBox[3] = $viewport_h; |
|
| 422 | + |
|
| 423 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 424 | + $attributs['width'] = (string) $new_width; |
|
| 425 | + $attributs['height'] = (string) $new_height; |
|
| 426 | + |
|
| 427 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 428 | + |
|
| 429 | + // ajouter un background |
|
| 430 | + if ($background_color && $background_color !== 'transparent') { |
|
| 431 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + return $svg; |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + return $img; |
|
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | /** |
@@ -444,26 +444,26 @@ discard block |
||
| 444 | 444 | * @return bool|string |
| 445 | 445 | */ |
| 446 | 446 | function svg_ajouter_background($img, $background_color) { |
| 447 | - if ( |
|
| 448 | - ($svg = svg_charger($img)) |
|
| 449 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 450 | - ) { |
|
| 451 | - if ($background_color && $background_color !== 'transparent') { |
|
| 452 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 453 | - |
|
| 454 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 455 | - if (isset($attributs['viewBox'])) { |
|
| 456 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 457 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 458 | - } |
|
| 459 | - else { |
|
| 460 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 461 | - } |
|
| 462 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 463 | - } |
|
| 464 | - return $svg; |
|
| 465 | - } |
|
| 466 | - return $img; |
|
| 447 | + if ( |
|
| 448 | + ($svg = svg_charger($img)) |
|
| 449 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 450 | + ) { |
|
| 451 | + if ($background_color && $background_color !== 'transparent') { |
|
| 452 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 453 | + |
|
| 454 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 455 | + if (isset($attributs['viewBox'])) { |
|
| 456 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 457 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 458 | + } |
|
| 459 | + else { |
|
| 460 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 461 | + } |
|
| 462 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 463 | + } |
|
| 464 | + return $svg; |
|
| 465 | + } |
|
| 466 | + return $img; |
|
| 467 | 467 | } |
| 468 | 468 | |
| 469 | 469 | |
@@ -474,26 +474,26 @@ discard block |
||
| 474 | 474 | * @return bool|string |
| 475 | 475 | */ |
| 476 | 476 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 477 | - if ( |
|
| 478 | - ($svg = svg_charger($img)) |
|
| 479 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 480 | - ) { |
|
| 481 | - if ($background_color && $background_color !== 'transparent') { |
|
| 482 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | - |
|
| 484 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | - if (isset($attributs['viewBox'])) { |
|
| 486 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | - } |
|
| 489 | - else { |
|
| 490 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | - } |
|
| 492 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 493 | - } |
|
| 494 | - return $svg; |
|
| 495 | - } |
|
| 496 | - return $img; |
|
| 477 | + if ( |
|
| 478 | + ($svg = svg_charger($img)) |
|
| 479 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 480 | + ) { |
|
| 481 | + if ($background_color && $background_color !== 'transparent') { |
|
| 482 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 483 | + |
|
| 484 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 485 | + if (isset($attributs['viewBox'])) { |
|
| 486 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 487 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | + } |
|
| 489 | + else { |
|
| 490 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 491 | + } |
|
| 492 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 493 | + } |
|
| 494 | + return $svg; |
|
| 495 | + } |
|
| 496 | + return $img; |
|
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | |
@@ -504,27 +504,27 @@ discard block |
||
| 504 | 504 | * @return bool|string |
| 505 | 505 | */ |
| 506 | 506 | function svg_transformer($img, $attributs) { |
| 507 | - if ( |
|
| 508 | - ($svg = svg_charger($img)) |
|
| 509 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 510 | - ) { |
|
| 511 | - if ($attributs) { |
|
| 512 | - [$balise_svg, ] = $svg_infos; |
|
| 513 | - $g = '<g'; |
|
| 514 | - foreach ($attributs as $k => $v) { |
|
| 515 | - if (strlen($v)) { |
|
| 516 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - if (strlen($g) > 2) { |
|
| 520 | - $g .= '>'; |
|
| 521 | - $svg = svg_insert_shapes($svg, $g); |
|
| 522 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 523 | - } |
|
| 524 | - } |
|
| 525 | - return $svg; |
|
| 526 | - } |
|
| 527 | - return $img; |
|
| 507 | + if ( |
|
| 508 | + ($svg = svg_charger($img)) |
|
| 509 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 510 | + ) { |
|
| 511 | + if ($attributs) { |
|
| 512 | + [$balise_svg, ] = $svg_infos; |
|
| 513 | + $g = '<g'; |
|
| 514 | + foreach ($attributs as $k => $v) { |
|
| 515 | + if (strlen($v)) { |
|
| 516 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + if (strlen($g) > 2) { |
|
| 520 | + $g .= '>'; |
|
| 521 | + $svg = svg_insert_shapes($svg, $g); |
|
| 522 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 523 | + } |
|
| 524 | + } |
|
| 525 | + return $svg; |
|
| 526 | + } |
|
| 527 | + return $img; |
|
| 528 | 528 | } |
| 529 | 529 | |
| 530 | 530 | /** |
@@ -535,21 +535,21 @@ discard block |
||
| 535 | 535 | * @return bool|string |
| 536 | 536 | */ |
| 537 | 537 | function svg_apply_filter($img, $filter_def) { |
| 538 | - if ( |
|
| 539 | - ($svg = svg_charger($img)) |
|
| 540 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 541 | - ) { |
|
| 542 | - if ($filter_def) { |
|
| 543 | - [$balise_svg, ] = $svg_infos; |
|
| 544 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 545 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 546 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 547 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 548 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 549 | - } |
|
| 550 | - return $svg; |
|
| 551 | - } |
|
| 552 | - return $img; |
|
| 538 | + if ( |
|
| 539 | + ($svg = svg_charger($img)) |
|
| 540 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 541 | + ) { |
|
| 542 | + if ($filter_def) { |
|
| 543 | + [$balise_svg, ] = $svg_infos; |
|
| 544 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 545 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 546 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 547 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 548 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 549 | + } |
|
| 550 | + return $svg; |
|
| 551 | + } |
|
| 552 | + return $img; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | /** |
@@ -559,8 +559,8 @@ discard block |
||
| 559 | 559 | * @return string |
| 560 | 560 | */ |
| 561 | 561 | function svg_filter_blur($img, $blur_width) { |
| 562 | - $blur_width = (int) $blur_width; |
|
| 563 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 562 | + $blur_width = (int) $blur_width; |
|
| 563 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 564 | 564 | } |
| 565 | 565 | |
| 566 | 566 | /** |
@@ -570,10 +570,10 @@ discard block |
||
| 570 | 570 | * @return bool|string |
| 571 | 571 | */ |
| 572 | 572 | function svg_filter_grayscale($img, $intensity) { |
| 573 | - $value = round(1.0 - $intensity, 2); |
|
| 574 | - //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 575 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 576 | - return svg_apply_filter($img, $filter); |
|
| 573 | + $value = round(1.0 - $intensity, 2); |
|
| 574 | + //$filter = "<feColorMatrix type=\"matrix\" values=\"0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0.3333 0.3333 0.3333 0 0 0 0 0 1 0\"/>"; |
|
| 575 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 576 | + return svg_apply_filter($img, $filter); |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /** |
@@ -586,8 +586,8 @@ discard block |
||
| 586 | 586 | * @return bool|string |
| 587 | 587 | */ |
| 588 | 588 | function svg_filter_sepia($img, $intensity) { |
| 589 | - $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 590 | - return svg_apply_filter($img, $filter); |
|
| 589 | + $filter = '<feColorMatrix type="matrix" values="0.30 0.30 0.30 0.0 0 0.25 0.25 0.25 0.0 0 0.20 0.20 0.20 0.0 0 0.00 0.00 0.00 1 0"/>'; |
|
| 590 | + return svg_apply_filter($img, $filter); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -597,30 +597,30 @@ discard block |
||
| 597 | 597 | * @return bool|string |
| 598 | 598 | */ |
| 599 | 599 | function svg_flip($img, $HorV) { |
| 600 | - if ( |
|
| 601 | - ($svg = svg_force_viewBox_px($img)) |
|
| 602 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 603 | - ) { |
|
| 604 | - [$balise_svg, $atts] = $svg_infos; |
|
| 605 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 606 | - |
|
| 607 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 608 | - $transform = 'scale(-1,1)'; |
|
| 609 | - |
|
| 610 | - $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 611 | - $mx = -$x; |
|
| 612 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 613 | - } |
|
| 614 | - else { |
|
| 615 | - $transform = 'scale(1,-1)'; |
|
| 616 | - |
|
| 617 | - $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 618 | - $my = -$y; |
|
| 619 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 620 | - } |
|
| 621 | - return svg_transformer($svg, ['transform' => $transform]); |
|
| 622 | - } |
|
| 623 | - return $img; |
|
| 600 | + if ( |
|
| 601 | + ($svg = svg_force_viewBox_px($img)) |
|
| 602 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 603 | + ) { |
|
| 604 | + [$balise_svg, $atts] = $svg_infos; |
|
| 605 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 606 | + |
|
| 607 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 608 | + $transform = 'scale(-1,1)'; |
|
| 609 | + |
|
| 610 | + $x = (int) $viewBox[0] + (int) ($viewBox[2] / 2); |
|
| 611 | + $mx = -$x; |
|
| 612 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 613 | + } |
|
| 614 | + else { |
|
| 615 | + $transform = 'scale(1,-1)'; |
|
| 616 | + |
|
| 617 | + $y = (int) $viewBox[1] + (int) ($viewBox[3] / 2); |
|
| 618 | + $my = -$y; |
|
| 619 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 620 | + } |
|
| 621 | + return svg_transformer($svg, ['transform' => $transform]); |
|
| 622 | + } |
|
| 623 | + return $img; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -634,19 +634,19 @@ discard block |
||
| 634 | 634 | * @return bool|string |
| 635 | 635 | */ |
| 636 | 636 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 637 | - if ( |
|
| 638 | - ($svg = svg_force_viewBox_px($img)) |
|
| 639 | - && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 640 | - ) { |
|
| 641 | - [$balise_svg, $atts] = $svg_infos; |
|
| 642 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 643 | - |
|
| 644 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 645 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 646 | - |
|
| 647 | - return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 648 | - } |
|
| 649 | - return $img; |
|
| 637 | + if ( |
|
| 638 | + ($svg = svg_force_viewBox_px($img)) |
|
| 639 | + && ($svg_infos = svg_lire_balise_svg($svg)) |
|
| 640 | + ) { |
|
| 641 | + [$balise_svg, $atts] = $svg_infos; |
|
| 642 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 643 | + |
|
| 644 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 645 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 646 | + |
|
| 647 | + return svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 648 | + } |
|
| 649 | + return $img; |
|
| 650 | 650 | } |
| 651 | 651 | |
| 652 | 652 | /** |
@@ -658,40 +658,40 @@ discard block |
||
| 658 | 658 | * @return bool|mixed|string |
| 659 | 659 | */ |
| 660 | 660 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 661 | - if ( |
|
| 662 | - ($svg = svg_force_viewBox_px($img)) |
|
| 663 | - && ($colors = svg_extract_couleurs($svg)) |
|
| 664 | - ) { |
|
| 665 | - $colors = array_unique($colors); |
|
| 666 | - |
|
| 667 | - $short = []; |
|
| 668 | - $long = []; |
|
| 669 | - while (count($colors)) { |
|
| 670 | - $c = array_shift($colors); |
|
| 671 | - if (strlen($c) == 4) { |
|
| 672 | - $short[] = $c; |
|
| 673 | - } |
|
| 674 | - else { |
|
| 675 | - $long[] = $c; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - $colors = [...$long, ...$short]; |
|
| 680 | - $new_colors = []; |
|
| 681 | - $colors = array_flip($colors); |
|
| 682 | - foreach ($colors as $c => $k) { |
|
| 683 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 684 | - } |
|
| 685 | - |
|
| 686 | - |
|
| 687 | - foreach ($colors as $original => $replace) { |
|
| 688 | - $new = svg_couleur_to_hexa($original); |
|
| 689 | - $new_colors[$replace] = $callback_filter($new); |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 693 | - |
|
| 694 | - return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 695 | - } |
|
| 696 | - return $img; |
|
| 661 | + if ( |
|
| 662 | + ($svg = svg_force_viewBox_px($img)) |
|
| 663 | + && ($colors = svg_extract_couleurs($svg)) |
|
| 664 | + ) { |
|
| 665 | + $colors = array_unique($colors); |
|
| 666 | + |
|
| 667 | + $short = []; |
|
| 668 | + $long = []; |
|
| 669 | + while (count($colors)) { |
|
| 670 | + $c = array_shift($colors); |
|
| 671 | + if (strlen($c) == 4) { |
|
| 672 | + $short[] = $c; |
|
| 673 | + } |
|
| 674 | + else { |
|
| 675 | + $long[] = $c; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + $colors = [...$long, ...$short]; |
|
| 680 | + $new_colors = []; |
|
| 681 | + $colors = array_flip($colors); |
|
| 682 | + foreach ($colors as $c => $k) { |
|
| 683 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 684 | + } |
|
| 685 | + |
|
| 686 | + |
|
| 687 | + foreach ($colors as $original => $replace) { |
|
| 688 | + $new = svg_couleur_to_hexa($original); |
|
| 689 | + $new_colors[$replace] = $callback_filter($new); |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 693 | + |
|
| 694 | + return str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 695 | + } |
|
| 696 | + return $img; |
|
| 697 | 697 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | } |
| 57 | 57 | if (!file_exists($fichier)) { |
| 58 | 58 | include_spip('inc/filtres'); |
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | 60 | if (!file_exists($fichier)) { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 147 | 147 | $new_balise_svg = '<svg'; |
| 148 | 148 | foreach ($attributs as $k => $v) { |
| 149 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 149 | + $new_balise_svg .= " $k=\"".entites_html($v).'"'; |
|
| 150 | 150 | } |
| 151 | 151 | $new_balise_svg .= '>'; |
| 152 | 152 | |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 165 | 165 | |
| 166 | 166 | if ($start === false || $start === 'end') { |
| 167 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 167 | + $svg = str_replace('</svg>', $shapes.'</svg>', $svg); |
|
| 168 | 168 | } |
| 169 | 169 | else { |
| 170 | 170 | $p = stripos($svg, '<svg'); |
@@ -185,10 +185,10 @@ discard block |
||
| 185 | 185 | */ |
| 186 | 186 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 187 | 187 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 188 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 188 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 189 | 189 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 190 | 190 | $g = "<g clip-path=\"url(#$id)\">"; |
| 191 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 191 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 192 | 192 | return svg_insert_shapes($svg, '</g>', false); |
| 193 | 193 | } |
| 194 | 194 | |
@@ -206,7 +206,7 @@ discard block |
||
| 206 | 206 | ) { |
| 207 | 207 | [$balise_svg, $attributs] = $svg_infos; |
| 208 | 208 | if (!isset($attributs['viewBox'])) { |
| 209 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 209 | + $attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height']; |
|
| 210 | 210 | } |
| 211 | 211 | $attributs['width'] = (string) $new_width; |
| 212 | 212 | $attributs['height'] = (string) $new_height; |
@@ -229,7 +229,7 @@ discard block |
||
| 229 | 229 | else { |
| 230 | 230 | $couleur = couleur_html_to_hex($couleur); |
| 231 | 231 | } |
| 232 | - return '#' . ltrim($couleur, '#'); |
|
| 232 | + return '#'.ltrim($couleur, '#'); |
|
| 233 | 233 | } |
| 234 | 234 | |
| 235 | 235 | /** |
@@ -240,7 +240,7 @@ discard block |
||
| 240 | 240 | function svg_couleur_to_rgb($couleur) { |
| 241 | 241 | if (str_starts_with($couleur, 'rgb(')) { |
| 242 | 242 | $c = explode(',', substr($couleur, 4)); |
| 243 | - return ['red' => (int) $c[0],'green' => (int) $c[1],'blue' => (int) $c[2]]; |
|
| 243 | + return ['red' => (int) $c[0], 'green' => (int) $c[1], 'blue' => (int) $c[2]]; |
|
| 244 | 244 | } |
| 245 | 245 | return _couleur_hex_to_dec($couleur); |
| 246 | 246 | } |
@@ -454,7 +454,7 @@ discard block |
||
| 454 | 454 | $background_color = svg_couleur_to_hexa($background_color); |
| 455 | 455 | if (isset($attributs['viewBox'])) { |
| 456 | 456 | $viewBox = explode(' ', $attributs['viewBox']); |
| 457 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 457 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 458 | 458 | } |
| 459 | 459 | else { |
| 460 | 460 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -484,7 +484,7 @@ discard block |
||
| 484 | 484 | $background_color = svg_couleur_to_hexa($background_color); |
| 485 | 485 | if (isset($attributs['viewBox'])) { |
| 486 | 486 | $viewBox = explode(' ', $attributs['viewBox']); |
| 487 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 487 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 488 | 488 | } |
| 489 | 489 | else { |
| 490 | 490 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -513,7 +513,7 @@ discard block |
||
| 513 | 513 | $g = '<g'; |
| 514 | 514 | foreach ($attributs as $k => $v) { |
| 515 | 515 | if (strlen($v)) { |
| 516 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 516 | + $g .= " $k=\"".attribut_html($v).'"'; |
|
| 517 | 517 | } |
| 518 | 518 | } |
| 519 | 519 | if (strlen($g) > 2) { |
@@ -541,10 +541,10 @@ discard block |
||
| 541 | 541 | ) { |
| 542 | 542 | if ($filter_def) { |
| 543 | 543 | [$balise_svg, ] = $svg_infos; |
| 544 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 544 | + $filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 545 | 545 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 546 | 546 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 547 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 547 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 548 | 548 | $svg = svg_insert_shapes($svg, '</g>', false); |
| 549 | 549 | } |
| 550 | 550 | return $svg; |
@@ -15,22 +15,22 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées pour installer SPIP |
| 16 | 16 | **/ |
| 17 | 17 | class Installation extends Admin { |
| 18 | - public const TYPE = 'installation'; |
|
| 18 | + public const TYPE = 'installation'; |
|
| 19 | 19 | |
| 20 | - protected function setOptions(array $options) { |
|
| 21 | - $options['titre'] ??= ''; |
|
| 22 | - if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | - $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | - } |
|
| 25 | - $options = parent::setOptions($options); |
|
| 26 | - $options['couleur_fond'] = '#a1124d'; |
|
| 27 | - $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | - $options['footer'] = ''; |
|
| 29 | - return $options; |
|
| 30 | - } |
|
| 20 | + protected function setOptions(array $options) { |
|
| 21 | + $options['titre'] ??= ''; |
|
| 22 | + if (!$options['titre'] || $options['titre'] === 'AUTO') { |
|
| 23 | + $options['titre'] = _T('info_installation_systeme_publication'); |
|
| 24 | + } |
|
| 25 | + $options = parent::setOptions($options); |
|
| 26 | + $options['couleur_fond'] = '#a1124d'; |
|
| 27 | + $options['css_files'][] = find_in_theme('installation.css'); |
|
| 28 | + $options['footer'] = ''; |
|
| 29 | + return $options; |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function page($corps = '', $options = []) { |
|
| 33 | - $options['titre'] ??= 'AUTO'; |
|
| 34 | - return parent::page($corps, $options); |
|
| 35 | - } |
|
| 32 | + public function page($corps = '', $options = []) { |
|
| 33 | + $options['titre'] ??= 'AUTO'; |
|
| 34 | + return parent::page($corps, $options); |
|
| 35 | + } |
|
| 36 | 36 | } |
@@ -114,11 +114,9 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | if ($statut && test_espace_prive()) { |
| 116 | 116 | $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
| 117 | - } |
|
| 118 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 117 | + } elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | 118 | $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
| 120 | - } |
|
| 121 | - else { |
|
| 119 | + } else { |
|
| 122 | 120 | $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
| 123 | 121 | } |
| 124 | 122 | |
@@ -130,12 +128,10 @@ discard block |
||
| 130 | 128 | . $titre |
| 131 | 129 | . '</div>'; |
| 132 | 130 | $options['titre'] = ''; |
| 133 | - } |
|
| 134 | - else { |
|
| 131 | + } else { |
|
| 135 | 132 | $options['titre'] = $titre; |
| 136 | 133 | } |
| 137 | - } |
|
| 138 | - else { |
|
| 134 | + } else { |
|
| 139 | 135 | $options['titre'] = $titre; |
| 140 | 136 | } |
| 141 | 137 | $options['page_title'] = $titre; |
@@ -15,146 +15,146 @@ |
||
| 15 | 15 | * Présentation des pages simplifiées d’admin pour envoyer un message à un utilisateur |
| 16 | 16 | **/ |
| 17 | 17 | class Admin extends Page { |
| 18 | - public const TYPE = 'admin'; |
|
| 19 | - protected function setOptions(array $options) { |
|
| 20 | - $options['couleur_fond'] = '#999'; |
|
| 21 | - if (empty($options['css_files'])) { |
|
| 22 | - $options['css_files'] = []; |
|
| 23 | - } |
|
| 24 | - array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | - |
|
| 26 | - $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | - |
|
| 28 | - return $options; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - |
|
| 32 | - /** |
|
| 33 | - * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | - * |
|
| 35 | - * @param array $options |
|
| 36 | - * @return string |
|
| 37 | - * Code HTML |
|
| 38 | - */ |
|
| 39 | - public function installDebutPage($options = []) { |
|
| 40 | - |
|
| 41 | - $options = $this->setOptions($options); |
|
| 42 | - return parent::ouvreBody($options) |
|
| 43 | - . parent::ouvreCorps($options); |
|
| 44 | - } |
|
| 45 | - |
|
| 46 | - /** |
|
| 47 | - * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | - * |
|
| 49 | - * @param array $options |
|
| 50 | - * @return string |
|
| 51 | - * Code HTML |
|
| 52 | - */ |
|
| 53 | - public function installFinPage($options = []) { |
|
| 54 | - |
|
| 55 | - $options = $this->setOptions($options); |
|
| 56 | - return parent::fermeCorps($options) |
|
| 57 | - . parent::fermeBody(); |
|
| 58 | - } |
|
| 59 | - |
|
| 60 | - |
|
| 61 | - /** |
|
| 62 | - * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | - * le contenu transmis dans `$corps`. |
|
| 64 | - * |
|
| 65 | - * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | - * accès à cette page par exemple). |
|
| 67 | - * |
|
| 68 | - * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | - * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | - * |
|
| 71 | - * @param string $corps |
|
| 72 | - * Corps de la page |
|
| 73 | - * @param array $options |
|
| 74 | - * @return string |
|
| 75 | - * HTML de la page |
|
| 76 | - * @see ouvreBody() |
|
| 77 | - * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | - * int $status : status de la page |
|
| 79 | - * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | - * @uses ouvreBody() |
|
| 81 | - * @uses fermeBody() |
|
| 82 | - * |
|
| 83 | - */ |
|
| 84 | - public function page($corps = '', $options = []) { |
|
| 85 | - |
|
| 86 | - $footer = ''; |
|
| 87 | - |
|
| 88 | - $titre = $options['titre'] ?? ''; |
|
| 89 | - if (!$titre) { |
|
| 90 | - if (empty($corps) && !isset($options['status'])) { |
|
| 91 | - $options['status'] = 403; |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - if ( |
|
| 95 | - !$titre = _request('action') |
|
| 96 | - && !$titre = _request('exec') |
|
| 97 | - && !$titre = _request('page') |
|
| 98 | - ) { |
|
| 99 | - $titre = '?'; |
|
| 100 | - } |
|
| 101 | - |
|
| 102 | - $titre = spip_htmlspecialchars($titre); |
|
| 103 | - |
|
| 104 | - $titre = ($titre == 'install') |
|
| 105 | - ? _T('avis_espace_interdit') |
|
| 106 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | - |
|
| 108 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | - |
|
| 111 | - if ($statut != '0minirezo') { |
|
| 112 | - $titre = _T('info_acces_interdit'); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - if ($statut && test_espace_prive()) { |
|
| 116 | - $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | - } |
|
| 118 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | - $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | - } |
|
| 121 | - else { |
|
| 122 | - $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - spip_logger('minipres')->info($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 126 | - |
|
| 127 | - $options['footer'] = $footer; |
|
| 128 | - if (empty($corps)) { |
|
| 129 | - $corps = "<div class='msg-alert error'>" |
|
| 130 | - . $titre |
|
| 131 | - . '</div>'; |
|
| 132 | - $options['titre'] = ''; |
|
| 133 | - } |
|
| 134 | - else { |
|
| 135 | - $options['titre'] = $titre; |
|
| 136 | - } |
|
| 137 | - } |
|
| 138 | - else { |
|
| 139 | - $options['titre'] = $titre; |
|
| 140 | - } |
|
| 141 | - $options['page_title'] = $titre; |
|
| 142 | - |
|
| 143 | - $options = $this->setOptions($options); |
|
| 144 | - |
|
| 145 | - $html = parent::page($corps, $options); |
|
| 146 | - |
|
| 147 | - if (!_AJAX) { |
|
| 148 | - return $html; |
|
| 149 | - } else { |
|
| 150 | - include_spip('inc/headers'); |
|
| 151 | - include_spip('inc/actions'); |
|
| 152 | - $url = self('&', true); |
|
| 153 | - foreach ($_POST as $v => $c) { |
|
| 154 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | - } |
|
| 156 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | - return ''; |
|
| 158 | - } |
|
| 159 | - } |
|
| 18 | + public const TYPE = 'admin'; |
|
| 19 | + protected function setOptions(array $options) { |
|
| 20 | + $options['couleur_fond'] = '#999'; |
|
| 21 | + if (empty($options['css_files'])) { |
|
| 22 | + $options['css_files'] = []; |
|
| 23 | + } |
|
| 24 | + array_unshift($options['css_files'], find_in_theme('minipres.css')); |
|
| 25 | + |
|
| 26 | + $options['page_title'] = ($options['titre'] ?? ''); |
|
| 27 | + |
|
| 28 | + return $options; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + |
|
| 32 | + /** |
|
| 33 | + * Retourne le début d'une page HTML minimale (de type installation ou erreur) |
|
| 34 | + * |
|
| 35 | + * @param array $options |
|
| 36 | + * @return string |
|
| 37 | + * Code HTML |
|
| 38 | + */ |
|
| 39 | + public function installDebutPage($options = []) { |
|
| 40 | + |
|
| 41 | + $options = $this->setOptions($options); |
|
| 42 | + return parent::ouvreBody($options) |
|
| 43 | + . parent::ouvreCorps($options); |
|
| 44 | + } |
|
| 45 | + |
|
| 46 | + /** |
|
| 47 | + * Retourne le fin d'une page HTML minimale (de type installation ou erreur) |
|
| 48 | + * |
|
| 49 | + * @param array $options |
|
| 50 | + * @return string |
|
| 51 | + * Code HTML |
|
| 52 | + */ |
|
| 53 | + public function installFinPage($options = []) { |
|
| 54 | + |
|
| 55 | + $options = $this->setOptions($options); |
|
| 56 | + return parent::fermeCorps($options) |
|
| 57 | + . parent::fermeBody(); |
|
| 58 | + } |
|
| 59 | + |
|
| 60 | + |
|
| 61 | + /** |
|
| 62 | + * Retourne une page HTML contenant, dans une présentation minimale, |
|
| 63 | + * le contenu transmis dans `$corps`. |
|
| 64 | + * |
|
| 65 | + * Appelée pour afficher un message d’erreur (l’utilisateur n’a pas |
|
| 66 | + * accès à cette page par exemple). |
|
| 67 | + * |
|
| 68 | + * Lorsqu’aucun argument n’est transmis, un header 403 est renvoyé, |
|
| 69 | + * ainsi qu’un message indiquant une interdiction d’accès. |
|
| 70 | + * |
|
| 71 | + * @param string $corps |
|
| 72 | + * Corps de la page |
|
| 73 | + * @param array $options |
|
| 74 | + * @return string |
|
| 75 | + * HTML de la page |
|
| 76 | + * @see ouvreBody() |
|
| 77 | + * string $titre : Titre à l'affichage (différent de $page_title) |
|
| 78 | + * int $status : status de la page |
|
| 79 | + * string $footer : pied de la box en remplacement du bouton retour par défaut |
|
| 80 | + * @uses ouvreBody() |
|
| 81 | + * @uses fermeBody() |
|
| 82 | + * |
|
| 83 | + */ |
|
| 84 | + public function page($corps = '', $options = []) { |
|
| 85 | + |
|
| 86 | + $footer = ''; |
|
| 87 | + |
|
| 88 | + $titre = $options['titre'] ?? ''; |
|
| 89 | + if (!$titre) { |
|
| 90 | + if (empty($corps) && !isset($options['status'])) { |
|
| 91 | + $options['status'] = 403; |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + if ( |
|
| 95 | + !$titre = _request('action') |
|
| 96 | + && !$titre = _request('exec') |
|
| 97 | + && !$titre = _request('page') |
|
| 98 | + ) { |
|
| 99 | + $titre = '?'; |
|
| 100 | + } |
|
| 101 | + |
|
| 102 | + $titre = spip_htmlspecialchars($titre); |
|
| 103 | + |
|
| 104 | + $titre = ($titre == 'install') |
|
| 105 | + ? _T('avis_espace_interdit') |
|
| 106 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 107 | + |
|
| 108 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 109 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 110 | + |
|
| 111 | + if ($statut != '0minirezo') { |
|
| 112 | + $titre = _T('info_acces_interdit'); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + if ($statut && test_espace_prive()) { |
|
| 116 | + $footer = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 117 | + } |
|
| 118 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 119 | + $footer = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 120 | + } |
|
| 121 | + else { |
|
| 122 | + $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + spip_logger('minipres')->info($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 126 | + |
|
| 127 | + $options['footer'] = $footer; |
|
| 128 | + if (empty($corps)) { |
|
| 129 | + $corps = "<div class='msg-alert error'>" |
|
| 130 | + . $titre |
|
| 131 | + . '</div>'; |
|
| 132 | + $options['titre'] = ''; |
|
| 133 | + } |
|
| 134 | + else { |
|
| 135 | + $options['titre'] = $titre; |
|
| 136 | + } |
|
| 137 | + } |
|
| 138 | + else { |
|
| 139 | + $options['titre'] = $titre; |
|
| 140 | + } |
|
| 141 | + $options['page_title'] = $titre; |
|
| 142 | + |
|
| 143 | + $options = $this->setOptions($options); |
|
| 144 | + |
|
| 145 | + $html = parent::page($corps, $options); |
|
| 146 | + |
|
| 147 | + if (!_AJAX) { |
|
| 148 | + return $html; |
|
| 149 | + } else { |
|
| 150 | + include_spip('inc/headers'); |
|
| 151 | + include_spip('inc/actions'); |
|
| 152 | + $url = self('&', true); |
|
| 153 | + foreach ($_POST as $v => $c) { |
|
| 154 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 155 | + } |
|
| 156 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 157 | + return ''; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | 160 | } |
@@ -103,7 +103,7 @@ discard block |
||
| 103 | 103 | |
| 104 | 104 | $titre = ($titre == 'install') |
| 105 | 105 | ? _T('avis_espace_interdit') |
| 106 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 106 | + : $titre.' : '._T('info_acces_interdit'); |
|
| 107 | 107 | |
| 108 | 108 | $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
| 109 | 109 | $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $footer = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site'] ?? ''); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - spip_logger('minipres')->info($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 125 | + spip_logger('minipres')->info($nom." $titre ".$_SERVER['REQUEST_URI']); |
|
| 126 | 126 | |
| 127 | 127 | $options['footer'] = $footer; |
| 128 | 128 | if (empty($corps)) { |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | foreach ($_POST as $v => $c) { |
| 154 | 154 | $url = parametre_url($url, $v, $c, '&'); |
| 155 | 155 | } |
| 156 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 156 | + ajax_retour('<div>'.$titre.redirige_formulaire($url).'</div>', false); |
|
| 157 | 157 | return ''; |
| 158 | 158 | } |
| 159 | 159 | } |
@@ -8,112 +8,112 @@ |
||
| 8 | 8 | **/ |
| 9 | 9 | class Sqlite |
| 10 | 10 | { |
| 11 | - /** @var Requeteur[] Liste des instances de requêteurs créés */ |
|
| 12 | - public static $requeteurs = []; |
|
| 13 | - /** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */ |
|
| 14 | - public static $transaction_en_cours = []; |
|
| 11 | + /** @var Requeteur[] Liste des instances de requêteurs créés */ |
|
| 12 | + public static $requeteurs = []; |
|
| 13 | + /** @var bool[] Pour chaque connexion, flag pour savoir si une transaction est en cours */ |
|
| 14 | + public static $transaction_en_cours = []; |
|
| 15 | 15 | |
| 16 | 16 | |
| 17 | - /** |
|
| 18 | - * Retourne une unique instance du requêteur |
|
| 19 | - * |
|
| 20 | - * Retourne une instance unique du requêteur pour une connexion SQLite |
|
| 21 | - * donnée |
|
| 22 | - * |
|
| 23 | - * @param string $serveur |
|
| 24 | - * Nom du connecteur |
|
| 25 | - * @return Requeteur |
|
| 26 | - * Instance unique du requêteur |
|
| 27 | - **/ |
|
| 28 | - public static function requeteur($serveur) { |
|
| 29 | - if (!isset(static::$requeteurs[$serveur])) { |
|
| 30 | - static::$requeteurs[$serveur] = new Requeteur($serveur); |
|
| 31 | - } |
|
| 17 | + /** |
|
| 18 | + * Retourne une unique instance du requêteur |
|
| 19 | + * |
|
| 20 | + * Retourne une instance unique du requêteur pour une connexion SQLite |
|
| 21 | + * donnée |
|
| 22 | + * |
|
| 23 | + * @param string $serveur |
|
| 24 | + * Nom du connecteur |
|
| 25 | + * @return Requeteur |
|
| 26 | + * Instance unique du requêteur |
|
| 27 | + **/ |
|
| 28 | + public static function requeteur($serveur) { |
|
| 29 | + if (!isset(static::$requeteurs[$serveur])) { |
|
| 30 | + static::$requeteurs[$serveur] = new Requeteur($serveur); |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - return static::$requeteurs[$serveur]; |
|
| 34 | - } |
|
| 33 | + return static::$requeteurs[$serveur]; |
|
| 34 | + } |
|
| 35 | 35 | |
| 36 | - /** |
|
| 37 | - * Prépare le texte d'une requête avant son exécution |
|
| 38 | - * |
|
| 39 | - * Adapte la requête au format plus ou moins MySQL par un format |
|
| 40 | - * compris de SQLite. |
|
| 41 | - * |
|
| 42 | - * Change les préfixes de tables SPIP par ceux véritables |
|
| 43 | - * |
|
| 44 | - * @param string $query Requête à préparer |
|
| 45 | - * @param string $serveur Nom de la connexion |
|
| 46 | - * @return string Requête préparée |
|
| 47 | - */ |
|
| 48 | - public static function traduire_requete($query, $serveur) { |
|
| 49 | - $requeteur = static::requeteur($serveur); |
|
| 50 | - $traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version); |
|
| 36 | + /** |
|
| 37 | + * Prépare le texte d'une requête avant son exécution |
|
| 38 | + * |
|
| 39 | + * Adapte la requête au format plus ou moins MySQL par un format |
|
| 40 | + * compris de SQLite. |
|
| 41 | + * |
|
| 42 | + * Change les préfixes de tables SPIP par ceux véritables |
|
| 43 | + * |
|
| 44 | + * @param string $query Requête à préparer |
|
| 45 | + * @param string $serveur Nom de la connexion |
|
| 46 | + * @return string Requête préparée |
|
| 47 | + */ |
|
| 48 | + public static function traduire_requete($query, $serveur) { |
|
| 49 | + $requeteur = static::requeteur($serveur); |
|
| 50 | + $traducteur = new Traducteur($query, $requeteur->prefixe, $requeteur->sqlite_version); |
|
| 51 | 51 | |
| 52 | - return $traducteur->traduire_requete(); |
|
| 53 | - } |
|
| 52 | + return $traducteur->traduire_requete(); |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | - /** |
|
| 56 | - * Démarre une transaction |
|
| 57 | - * |
|
| 58 | - * @param string $serveur Nom de la connexion |
|
| 59 | - **/ |
|
| 60 | - public static function demarrer_transaction($serveur) { |
|
| 61 | - Sqlite::executer_requete('BEGIN TRANSACTION', $serveur); |
|
| 62 | - Sqlite::$transaction_en_cours[$serveur] = true; |
|
| 63 | - } |
|
| 55 | + /** |
|
| 56 | + * Démarre une transaction |
|
| 57 | + * |
|
| 58 | + * @param string $serveur Nom de la connexion |
|
| 59 | + **/ |
|
| 60 | + public static function demarrer_transaction($serveur) { |
|
| 61 | + Sqlite::executer_requete('BEGIN TRANSACTION', $serveur); |
|
| 62 | + Sqlite::$transaction_en_cours[$serveur] = true; |
|
| 63 | + } |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * Exécute la requête donnée |
|
| 67 | - * |
|
| 68 | - * @param string $query Requête |
|
| 69 | - * @param string $serveur Nom de la connexion |
|
| 70 | - * @param null|bool $tracer Demander des statistiques (temps) ? |
|
| 71 | - **/ |
|
| 72 | - public static function executer_requete($query, $serveur, $tracer = null) { |
|
| 73 | - $requeteur = Sqlite::requeteur($serveur); |
|
| 65 | + /** |
|
| 66 | + * Exécute la requête donnée |
|
| 67 | + * |
|
| 68 | + * @param string $query Requête |
|
| 69 | + * @param string $serveur Nom de la connexion |
|
| 70 | + * @param null|bool $tracer Demander des statistiques (temps) ? |
|
| 71 | + **/ |
|
| 72 | + public static function executer_requete($query, $serveur, $tracer = null) { |
|
| 73 | + $requeteur = Sqlite::requeteur($serveur); |
|
| 74 | 74 | |
| 75 | - return $requeteur->executer_requete($query, $tracer); |
|
| 76 | - } |
|
| 75 | + return $requeteur->executer_requete($query, $tracer); |
|
| 76 | + } |
|
| 77 | 77 | |
| 78 | - /** |
|
| 79 | - * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 80 | - * |
|
| 81 | - * @param string $serveur Nom de la connexion |
|
| 82 | - * return int Identifiant |
|
| 83 | - **/ |
|
| 84 | - public static function last_insert_id($serveur) { |
|
| 85 | - $requeteur = Sqlite::requeteur($serveur); |
|
| 78 | + /** |
|
| 79 | + * Obtient l'identifiant de la dernière ligne insérée ou modifiée |
|
| 80 | + * |
|
| 81 | + * @param string $serveur Nom de la connexion |
|
| 82 | + * return int Identifiant |
|
| 83 | + **/ |
|
| 84 | + public static function last_insert_id($serveur) { |
|
| 85 | + $requeteur = Sqlite::requeteur($serveur); |
|
| 86 | 86 | |
| 87 | - return $requeteur->last_insert_id(); |
|
| 88 | - } |
|
| 87 | + return $requeteur->last_insert_id(); |
|
| 88 | + } |
|
| 89 | 89 | |
| 90 | - /** |
|
| 91 | - * Annule une transaction |
|
| 92 | - * |
|
| 93 | - * @param string $serveur Nom de la connexion |
|
| 94 | - **/ |
|
| 95 | - public static function annuler_transaction($serveur) { |
|
| 96 | - Sqlite::executer_requete('ROLLBACK', $serveur); |
|
| 97 | - Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 98 | - } |
|
| 90 | + /** |
|
| 91 | + * Annule une transaction |
|
| 92 | + * |
|
| 93 | + * @param string $serveur Nom de la connexion |
|
| 94 | + **/ |
|
| 95 | + public static function annuler_transaction($serveur) { |
|
| 96 | + Sqlite::executer_requete('ROLLBACK', $serveur); |
|
| 97 | + Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - /** |
|
| 101 | - * Termine une transaction |
|
| 102 | - * |
|
| 103 | - * @param string $serveur Nom de la connexion |
|
| 104 | - **/ |
|
| 105 | - public static function finir_transaction($serveur) { |
|
| 106 | - // si pas de transaction en cours, ne rien faire et le dire |
|
| 107 | - if ( |
|
| 108 | - !isset(Sqlite::$transaction_en_cours[$serveur]) |
|
| 109 | - || Sqlite::$transaction_en_cours[$serveur] == false |
|
| 110 | - ) { |
|
| 111 | - return false; |
|
| 112 | - } |
|
| 113 | - // sinon fermer la transaction et retourner true |
|
| 114 | - Sqlite::executer_requete('COMMIT', $serveur); |
|
| 115 | - Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 100 | + /** |
|
| 101 | + * Termine une transaction |
|
| 102 | + * |
|
| 103 | + * @param string $serveur Nom de la connexion |
|
| 104 | + **/ |
|
| 105 | + public static function finir_transaction($serveur) { |
|
| 106 | + // si pas de transaction en cours, ne rien faire et le dire |
|
| 107 | + if ( |
|
| 108 | + !isset(Sqlite::$transaction_en_cours[$serveur]) |
|
| 109 | + || Sqlite::$transaction_en_cours[$serveur] == false |
|
| 110 | + ) { |
|
| 111 | + return false; |
|
| 112 | + } |
|
| 113 | + // sinon fermer la transaction et retourner true |
|
| 114 | + Sqlite::executer_requete('COMMIT', $serveur); |
|
| 115 | + Sqlite::$transaction_en_cours[$serveur] = false; |
|
| 116 | 116 | |
| 117 | - return true; |
|
| 118 | - } |
|
| 117 | + return true; |
|
| 118 | + } |
|
| 119 | 119 | } |
@@ -6,10 +6,10 @@ |
||
| 6 | 6 | * Pouvoir retrouver le PDO utilisé pour générer un résultat de requête. |
| 7 | 7 | */ |
| 8 | 8 | final class PDOStatement extends \PDOStatement { |
| 9 | - private function __construct(private \PDO &$PDO) { |
|
| 10 | - } |
|
| 9 | + private function __construct(private \PDO &$PDO) { |
|
| 10 | + } |
|
| 11 | 11 | |
| 12 | - public function getPDO(): \PDO { |
|
| 13 | - return $this->PDO; |
|
| 14 | - } |
|
| 12 | + public function getPDO(): \PDO { |
|
| 13 | + return $this->PDO; |
|
| 14 | + } |
|
| 15 | 15 | } |
@@ -7,85 +7,85 @@ |
||
| 7 | 7 | **/ |
| 8 | 8 | class Idiome |
| 9 | 9 | { |
| 10 | - /** Type de noeud */ |
|
| 11 | - public string $type = 'idiome'; |
|
| 12 | - |
|
| 13 | - /** Clé de traduction demandée. Exemple 'item_oui' */ |
|
| 14 | - public string $nom_champ = ''; |
|
| 15 | - |
|
| 16 | - /** Module de langue où chercher la clé de traduction. Exemple 'medias' */ |
|
| 17 | - public string $module = ''; |
|
| 18 | - |
|
| 19 | - /** Arguments à passer à la chaîne */ |
|
| 20 | - public array $arg = []; |
|
| 21 | - |
|
| 22 | - /** |
|
| 23 | - * Filtres à appliquer au résultat |
|
| 24 | - * |
|
| 25 | - * |
|
| 26 | - * * FIXME: type unique. |
|
| 27 | - * @var false|array |
|
| 28 | - * - false: erreur de syntaxe |
|
| 29 | - */ |
|
| 30 | - public $param = []; |
|
| 31 | - |
|
| 32 | - /** Source des filtres (compatibilité) (?) */ |
|
| 33 | - public array $fonctions = []; |
|
| 34 | - |
|
| 35 | - /** |
|
| 36 | - * Inutilisé, propriété générique de l'AST |
|
| 37 | - * |
|
| 38 | - * @var string|array |
|
| 39 | - */ |
|
| 40 | - public $avant = ''; |
|
| 41 | - |
|
| 42 | - /** |
|
| 43 | - * Inutilisé, propriété générique de l'AST |
|
| 44 | - * |
|
| 45 | - * @var string|array |
|
| 46 | - */ |
|
| 47 | - public $apres = ''; |
|
| 48 | - |
|
| 49 | - /** Identifiant de la boucle */ |
|
| 50 | - public string $id_boucle = ''; |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * AST du squelette, liste de toutes les boucles |
|
| 54 | - * |
|
| 55 | - * @var Boucle[] |
|
| 56 | - */ |
|
| 57 | - public array $boucles; |
|
| 58 | - |
|
| 59 | - /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 60 | - public ?string $type_requete = null; |
|
| 61 | - |
|
| 62 | - /** Résultat de la compilation: toujours une expression PHP */ |
|
| 63 | - public string $code = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * Interdire les scripts |
|
| 67 | - * |
|
| 68 | - * @see interdire_scripts() |
|
| 69 | - */ |
|
| 70 | - public bool $interdire_scripts = false; |
|
| 71 | - |
|
| 72 | - /** |
|
| 73 | - * Description du squelette |
|
| 74 | - * |
|
| 75 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 76 | - * |
|
| 77 | - * Peut contenir les index : |
|
| 78 | - * - nom : Nom du fichier de cache |
|
| 79 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 80 | - * - sourcefile : Chemin du squelette |
|
| 81 | - * - squelette : Code du squelette |
|
| 82 | - * - id_mere : Identifiant de la boucle parente |
|
| 83 | - * - documents : Pour embed et img dans les textes |
|
| 84 | - * - session : Pour un cache sessionné par auteur |
|
| 85 | - * - niv : Niveau de tabulation |
|
| 86 | - */ |
|
| 87 | - public array $descr = []; |
|
| 88 | - |
|
| 89 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 90 | - public int $ligne = 0; |
|
| 10 | + /** Type de noeud */ |
|
| 11 | + public string $type = 'idiome'; |
|
| 12 | + |
|
| 13 | + /** Clé de traduction demandée. Exemple 'item_oui' */ |
|
| 14 | + public string $nom_champ = ''; |
|
| 15 | + |
|
| 16 | + /** Module de langue où chercher la clé de traduction. Exemple 'medias' */ |
|
| 17 | + public string $module = ''; |
|
| 18 | + |
|
| 19 | + /** Arguments à passer à la chaîne */ |
|
| 20 | + public array $arg = []; |
|
| 21 | + |
|
| 22 | + /** |
|
| 23 | + * Filtres à appliquer au résultat |
|
| 24 | + * |
|
| 25 | + * |
|
| 26 | + * * FIXME: type unique. |
|
| 27 | + * @var false|array |
|
| 28 | + * - false: erreur de syntaxe |
|
| 29 | + */ |
|
| 30 | + public $param = []; |
|
| 31 | + |
|
| 32 | + /** Source des filtres (compatibilité) (?) */ |
|
| 33 | + public array $fonctions = []; |
|
| 34 | + |
|
| 35 | + /** |
|
| 36 | + * Inutilisé, propriété générique de l'AST |
|
| 37 | + * |
|
| 38 | + * @var string|array |
|
| 39 | + */ |
|
| 40 | + public $avant = ''; |
|
| 41 | + |
|
| 42 | + /** |
|
| 43 | + * Inutilisé, propriété générique de l'AST |
|
| 44 | + * |
|
| 45 | + * @var string|array |
|
| 46 | + */ |
|
| 47 | + public $apres = ''; |
|
| 48 | + |
|
| 49 | + /** Identifiant de la boucle */ |
|
| 50 | + public string $id_boucle = ''; |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * AST du squelette, liste de toutes les boucles |
|
| 54 | + * |
|
| 55 | + * @var Boucle[] |
|
| 56 | + */ |
|
| 57 | + public array $boucles; |
|
| 58 | + |
|
| 59 | + /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 60 | + public ?string $type_requete = null; |
|
| 61 | + |
|
| 62 | + /** Résultat de la compilation: toujours une expression PHP */ |
|
| 63 | + public string $code = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * Interdire les scripts |
|
| 67 | + * |
|
| 68 | + * @see interdire_scripts() |
|
| 69 | + */ |
|
| 70 | + public bool $interdire_scripts = false; |
|
| 71 | + |
|
| 72 | + /** |
|
| 73 | + * Description du squelette |
|
| 74 | + * |
|
| 75 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 76 | + * |
|
| 77 | + * Peut contenir les index : |
|
| 78 | + * - nom : Nom du fichier de cache |
|
| 79 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 80 | + * - sourcefile : Chemin du squelette |
|
| 81 | + * - squelette : Code du squelette |
|
| 82 | + * - id_mere : Identifiant de la boucle parente |
|
| 83 | + * - documents : Pour embed et img dans les textes |
|
| 84 | + * - session : Pour un cache sessionné par auteur |
|
| 85 | + * - niv : Niveau de tabulation |
|
| 86 | + */ |
|
| 87 | + public array $descr = []; |
|
| 88 | + |
|
| 89 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 90 | + public int $ligne = 0; |
|
| 91 | 91 | } |
@@ -7,104 +7,104 @@ |
||
| 7 | 7 | */ |
| 8 | 8 | class Champ |
| 9 | 9 | { |
| 10 | - /** Type de noeud */ |
|
| 11 | - public string $type = 'champ'; |
|
| 12 | - |
|
| 13 | - /** Nom du champ demandé. Exemple 'ID_ARTICLE' */ |
|
| 14 | - public ?string $nom_champ = null; |
|
| 15 | - |
|
| 16 | - /** Identifiant de la boucle parente si explicité */ |
|
| 17 | - public ?string $nom_boucle = ''; |
|
| 18 | - |
|
| 19 | - /** |
|
| 20 | - * Partie optionnelle avant |
|
| 21 | - * |
|
| 22 | - * @var null|string|array |
|
| 23 | - */ |
|
| 24 | - public $avant; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Partie optionnelle après |
|
| 28 | - * |
|
| 29 | - * @var null|string|array |
|
| 30 | - */ |
|
| 31 | - public $apres; |
|
| 32 | - |
|
| 33 | - /** |
|
| 34 | - * Étoiles : annuler des automatismes |
|
| 35 | - * |
|
| 36 | - * - '*' annule les filtres automatiques |
|
| 37 | - * - '**' annule en plus les protections de scripts |
|
| 38 | - * |
|
| 39 | - * FIXME: type unique. |
|
| 40 | - */ |
|
| 41 | - public ?string $etoile = ''; |
|
| 42 | - |
|
| 43 | - /** |
|
| 44 | - * Arguments et filtres explicites sur la balise |
|
| 45 | - * |
|
| 46 | - * - $param[0] contient les arguments de la balise |
|
| 47 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 48 | - * |
|
| 49 | - * FIXME: type unique. |
|
| 50 | - * @var false|array |
|
| 51 | - * - false: erreur de syntaxe |
|
| 52 | - */ |
|
| 53 | - public $param = []; |
|
| 54 | - |
|
| 55 | - /** Source des filtres (compatibilité) (?) */ |
|
| 56 | - public array $fonctions = []; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Identifiant de la boucle |
|
| 60 | - * |
|
| 61 | - * @var string |
|
| 62 | - */ |
|
| 63 | - public $id_boucle = ''; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * AST du squelette, liste de toutes les boucles |
|
| 67 | - * |
|
| 68 | - * @var Boucle[] |
|
| 69 | - */ |
|
| 70 | - public array $boucles; |
|
| 71 | - |
|
| 72 | - /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 73 | - public ?string $type_requete = null; |
|
| 74 | - |
|
| 75 | - /** Résultat de la compilation: toujours une expression PHP */ |
|
| 76 | - public string $code = ''; |
|
| 77 | - |
|
| 78 | - /** |
|
| 79 | - * Interdire les scripts |
|
| 80 | - * |
|
| 81 | - * false si on est sûr de cette balise |
|
| 82 | - * |
|
| 83 | - * @see interdire_scripts() |
|
| 84 | - */ |
|
| 85 | - public bool $interdire_scripts = true; |
|
| 86 | - |
|
| 87 | - /** |
|
| 88 | - * Description du squelette |
|
| 89 | - * |
|
| 90 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 91 | - * |
|
| 92 | - * Peut contenir les index : |
|
| 93 | - * |
|
| 94 | - * - nom : Nom du fichier de cache |
|
| 95 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 96 | - * - sourcefile : Chemin du squelette |
|
| 97 | - * - squelette : Code du squelette |
|
| 98 | - * - id_mere : Identifiant de la boucle parente |
|
| 99 | - * - documents : Pour embed et img dans les textes |
|
| 100 | - * - session : Pour un cache sessionné par auteur |
|
| 101 | - * - niv : Niveau de tabulation |
|
| 102 | - */ |
|
| 103 | - public array $descr = []; |
|
| 104 | - |
|
| 105 | - /** Numéro de ligne dans le code source du squelette*/ |
|
| 106 | - public int $ligne = 0; |
|
| 107 | - |
|
| 108 | - /** Drapeau pour reperer les balises calculées par une fonction explicite */ |
|
| 109 | - public bool $balise_calculee = false; |
|
| 10 | + /** Type de noeud */ |
|
| 11 | + public string $type = 'champ'; |
|
| 12 | + |
|
| 13 | + /** Nom du champ demandé. Exemple 'ID_ARTICLE' */ |
|
| 14 | + public ?string $nom_champ = null; |
|
| 15 | + |
|
| 16 | + /** Identifiant de la boucle parente si explicité */ |
|
| 17 | + public ?string $nom_boucle = ''; |
|
| 18 | + |
|
| 19 | + /** |
|
| 20 | + * Partie optionnelle avant |
|
| 21 | + * |
|
| 22 | + * @var null|string|array |
|
| 23 | + */ |
|
| 24 | + public $avant; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Partie optionnelle après |
|
| 28 | + * |
|
| 29 | + * @var null|string|array |
|
| 30 | + */ |
|
| 31 | + public $apres; |
|
| 32 | + |
|
| 33 | + /** |
|
| 34 | + * Étoiles : annuler des automatismes |
|
| 35 | + * |
|
| 36 | + * - '*' annule les filtres automatiques |
|
| 37 | + * - '**' annule en plus les protections de scripts |
|
| 38 | + * |
|
| 39 | + * FIXME: type unique. |
|
| 40 | + */ |
|
| 41 | + public ?string $etoile = ''; |
|
| 42 | + |
|
| 43 | + /** |
|
| 44 | + * Arguments et filtres explicites sur la balise |
|
| 45 | + * |
|
| 46 | + * - $param[0] contient les arguments de la balise |
|
| 47 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 48 | + * |
|
| 49 | + * FIXME: type unique. |
|
| 50 | + * @var false|array |
|
| 51 | + * - false: erreur de syntaxe |
|
| 52 | + */ |
|
| 53 | + public $param = []; |
|
| 54 | + |
|
| 55 | + /** Source des filtres (compatibilité) (?) */ |
|
| 56 | + public array $fonctions = []; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Identifiant de la boucle |
|
| 60 | + * |
|
| 61 | + * @var string |
|
| 62 | + */ |
|
| 63 | + public $id_boucle = ''; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * AST du squelette, liste de toutes les boucles |
|
| 67 | + * |
|
| 68 | + * @var Boucle[] |
|
| 69 | + */ |
|
| 70 | + public array $boucles; |
|
| 71 | + |
|
| 72 | + /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 73 | + public ?string $type_requete = null; |
|
| 74 | + |
|
| 75 | + /** Résultat de la compilation: toujours une expression PHP */ |
|
| 76 | + public string $code = ''; |
|
| 77 | + |
|
| 78 | + /** |
|
| 79 | + * Interdire les scripts |
|
| 80 | + * |
|
| 81 | + * false si on est sûr de cette balise |
|
| 82 | + * |
|
| 83 | + * @see interdire_scripts() |
|
| 84 | + */ |
|
| 85 | + public bool $interdire_scripts = true; |
|
| 86 | + |
|
| 87 | + /** |
|
| 88 | + * Description du squelette |
|
| 89 | + * |
|
| 90 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 91 | + * |
|
| 92 | + * Peut contenir les index : |
|
| 93 | + * |
|
| 94 | + * - nom : Nom du fichier de cache |
|
| 95 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 96 | + * - sourcefile : Chemin du squelette |
|
| 97 | + * - squelette : Code du squelette |
|
| 98 | + * - id_mere : Identifiant de la boucle parente |
|
| 99 | + * - documents : Pour embed et img dans les textes |
|
| 100 | + * - session : Pour un cache sessionné par auteur |
|
| 101 | + * - niv : Niveau de tabulation |
|
| 102 | + */ |
|
| 103 | + public array $descr = []; |
|
| 104 | + |
|
| 105 | + /** Numéro de ligne dans le code source du squelette*/ |
|
| 106 | + public int $ligne = 0; |
|
| 107 | + |
|
| 108 | + /** Drapeau pour reperer les balises calculées par une fonction explicite */ |
|
| 109 | + public bool $balise_calculee = false; |
|
| 110 | 110 | } |
@@ -8,32 +8,32 @@ |
||
| 8 | 8 | * Sous-noeud de Boucle |
| 9 | 9 | **/ |
| 10 | 10 | class Critere { |
| 11 | - /** Type de noeud */ |
|
| 12 | - public string $type = 'critere'; |
|
| 13 | - |
|
| 14 | - /** Opérateur (>, <, >=, IN, ...) */ |
|
| 15 | - public ?string $op = null; |
|
| 16 | - |
|
| 17 | - /** Présence d'une négation (truc !op valeur) */ |
|
| 18 | - public bool $not = false; |
|
| 19 | - |
|
| 20 | - /** Présence d'une exclusion (!truc op valeur) */ |
|
| 21 | - public string $exclus = ''; |
|
| 22 | - |
|
| 23 | - /** Présence d'une condition dans le critère (truc ?) */ |
|
| 24 | - public bool $cond = false; |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * Paramètres du critère |
|
| 28 | - * - $param[0] : élément avant l'opérateur |
|
| 29 | - * - $param[1..n] : éléments après l'opérateur |
|
| 30 | - * |
|
| 31 | - * FIXME: type unique. |
|
| 32 | - * @var false|array |
|
| 33 | - * - false: erreur de syntaxe |
|
| 34 | - */ |
|
| 35 | - public $param = []; |
|
| 36 | - |
|
| 37 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 38 | - public int $ligne = 0; |
|
| 11 | + /** Type de noeud */ |
|
| 12 | + public string $type = 'critere'; |
|
| 13 | + |
|
| 14 | + /** Opérateur (>, <, >=, IN, ...) */ |
|
| 15 | + public ?string $op = null; |
|
| 16 | + |
|
| 17 | + /** Présence d'une négation (truc !op valeur) */ |
|
| 18 | + public bool $not = false; |
|
| 19 | + |
|
| 20 | + /** Présence d'une exclusion (!truc op valeur) */ |
|
| 21 | + public string $exclus = ''; |
|
| 22 | + |
|
| 23 | + /** Présence d'une condition dans le critère (truc ?) */ |
|
| 24 | + public bool $cond = false; |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * Paramètres du critère |
|
| 28 | + * - $param[0] : élément avant l'opérateur |
|
| 29 | + * - $param[1..n] : éléments après l'opérateur |
|
| 30 | + * |
|
| 31 | + * FIXME: type unique. |
|
| 32 | + * @var false|array |
|
| 33 | + * - false: erreur de syntaxe |
|
| 34 | + */ |
|
| 35 | + public $param = []; |
|
| 36 | + |
|
| 37 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 38 | + public int $ligne = 0; |
|
| 39 | 39 | } |
@@ -4,21 +4,21 @@ |
||
| 4 | 4 | |
| 5 | 5 | abstract class AbstractIterateur |
| 6 | 6 | { |
| 7 | - protected string $type; |
|
| 7 | + protected string $type; |
|
| 8 | 8 | |
| 9 | - /** |
|
| 10 | - * Calcul du total des elements |
|
| 11 | - * |
|
| 12 | - * @var int|null |
|
| 13 | - **/ |
|
| 14 | - public $total = null; |
|
| 9 | + /** |
|
| 10 | + * Calcul du total des elements |
|
| 11 | + * |
|
| 12 | + * @var int|null |
|
| 13 | + **/ |
|
| 14 | + public $total = null; |
|
| 15 | 15 | |
| 16 | - /** Erreur presente ? **/ |
|
| 17 | - public bool $err = false; |
|
| 16 | + /** Erreur presente ? **/ |
|
| 17 | + public bool $err = false; |
|
| 18 | 18 | |
| 19 | - public function __construct( |
|
| 20 | - protected array $command, |
|
| 21 | - protected array $info = [] |
|
| 22 | - ) { |
|
| 23 | - } |
|
| 19 | + public function __construct( |
|
| 20 | + protected array $command, |
|
| 21 | + protected array $info = [] |
|
| 22 | + ) { |
|
| 23 | + } |
|
| 24 | 24 | } |