@@ -17,13 +17,13 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('IMG_SVG')) { |
| 24 | - // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | - define('IMG_SVG', 128); |
|
| 26 | - define('IMAGETYPE_SVG', 19); |
|
| 24 | + // complete IMG_BMP | IMG_GIF | IMG_JPG | IMG_PNG | IMG_WBMP | IMG_XPM | IMG_WEBP |
|
| 25 | + define('IMG_SVG', 128); |
|
| 26 | + define('IMAGETYPE_SVG', 19); |
|
| 27 | 27 | } |
| 28 | 28 | |
| 29 | 29 | /** |
@@ -39,39 +39,39 @@ discard block |
||
| 39 | 39 | * false si on a pas pu charger l'image |
| 40 | 40 | */ |
| 41 | 41 | function svg_charger($fichier, $maxlen = null) { |
| 42 | - if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | - $image = explode(';', $fichier, 2); |
|
| 44 | - $image = end($image); |
|
| 45 | - if (strpos($image, 'base64,') === 0) { |
|
| 46 | - $image = base64_decode(substr($image, 7)); |
|
| 47 | - } |
|
| 48 | - if (strpos($image, '<svg') !== false) { |
|
| 49 | - return $image; |
|
| 50 | - } |
|
| 51 | - // encodage inconnu ou autre format d'image ? |
|
| 52 | - return false; |
|
| 53 | - } |
|
| 54 | - // c'est peut etre deja une image svg ? |
|
| 55 | - if (strpos($fichier, '<svg') !== false) { |
|
| 56 | - return $fichier; |
|
| 57 | - } |
|
| 58 | - if (!file_exists($fichier)) { |
|
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 60 | - if (!file_exists($fichier)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - if (is_null($maxlen)) { |
|
| 65 | - $image = file_get_contents($fichier); |
|
| 66 | - } |
|
| 67 | - else { |
|
| 68 | - $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | - } |
|
| 70 | - // est-ce bien une image svg ? |
|
| 71 | - if (strpos($image, '<svg') !== false) { |
|
| 72 | - return $image; |
|
| 73 | - } |
|
| 74 | - return false; |
|
| 42 | + if (strpos($fichier, 'data:image/svg+xml') === 0) { |
|
| 43 | + $image = explode(';', $fichier, 2); |
|
| 44 | + $image = end($image); |
|
| 45 | + if (strpos($image, 'base64,') === 0) { |
|
| 46 | + $image = base64_decode(substr($image, 7)); |
|
| 47 | + } |
|
| 48 | + if (strpos($image, '<svg') !== false) { |
|
| 49 | + return $image; |
|
| 50 | + } |
|
| 51 | + // encodage inconnu ou autre format d'image ? |
|
| 52 | + return false; |
|
| 53 | + } |
|
| 54 | + // c'est peut etre deja une image svg ? |
|
| 55 | + if (strpos($fichier, '<svg') !== false) { |
|
| 56 | + return $fichier; |
|
| 57 | + } |
|
| 58 | + if (!file_exists($fichier)) { |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | + if (!file_exists($fichier)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + if (is_null($maxlen)) { |
|
| 65 | + $image = file_get_contents($fichier); |
|
| 66 | + } |
|
| 67 | + else { |
|
| 68 | + $image = file_get_contents($fichier, false, null, 0, $maxlen); |
|
| 69 | + } |
|
| 70 | + // est-ce bien une image svg ? |
|
| 71 | + if (strpos($image, '<svg') !== false) { |
|
| 72 | + return $image; |
|
| 73 | + } |
|
| 74 | + return false; |
|
| 75 | 75 | } |
| 76 | 76 | |
| 77 | 77 | /** |
@@ -80,28 +80,28 @@ discard block |
||
| 80 | 80 | * @return array|bool |
| 81 | 81 | */ |
| 82 | 82 | function svg_lire_balise_svg($fichier) { |
| 83 | - if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | - return false; |
|
| 85 | - } |
|
| 86 | - |
|
| 87 | - if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | - $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | - $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | - |
|
| 91 | - if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | - if (!function_exists('extraire_attribut')) { |
|
| 93 | - include_spip('inc/filtres'); |
|
| 94 | - } |
|
| 95 | - $attributs = []; |
|
| 96 | - foreach ($matches[1] as $att) { |
|
| 97 | - $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | - } |
|
| 99 | - |
|
| 100 | - return [$balise_svg, $attributs]; |
|
| 101 | - } |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - return false; |
|
| 83 | + if (!$debut_fichier = svg_charger($fichier, 4096)) { |
|
| 84 | + return false; |
|
| 85 | + } |
|
| 86 | + |
|
| 87 | + if (($ps = stripos($debut_fichier, '<svg')) !== false) { |
|
| 88 | + $pe = stripos($debut_fichier, '>', $ps); |
|
| 89 | + $balise_svg = substr($debut_fichier, $ps, $pe - $ps + 1); |
|
| 90 | + |
|
| 91 | + if (preg_match_all(',([\w:\-]+)=,Uims', $balise_svg, $matches)) { |
|
| 92 | + if (!function_exists('extraire_attribut')) { |
|
| 93 | + include_spip('inc/filtres'); |
|
| 94 | + } |
|
| 95 | + $attributs = []; |
|
| 96 | + foreach ($matches[1] as $att) { |
|
| 97 | + $attributs[$att] = extraire_attribut($balise_svg, $att); |
|
| 98 | + } |
|
| 99 | + |
|
| 100 | + return [$balise_svg, $attributs]; |
|
| 101 | + } |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + return false; |
|
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | /** |
@@ -111,12 +111,12 @@ discard block |
||
| 111 | 111 | */ |
| 112 | 112 | function svg_lire_attributs($img) { |
| 113 | 113 | |
| 114 | - if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | - return $attributs; |
|
| 117 | - } |
|
| 114 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 116 | + return $attributs; |
|
| 117 | + } |
|
| 118 | 118 | |
| 119 | - return false; |
|
| 119 | + return false; |
|
| 120 | 120 | } |
| 121 | 121 | |
| 122 | 122 | /** |
@@ -126,38 +126,38 @@ discard block |
||
| 126 | 126 | * @return bool|float|int |
| 127 | 127 | */ |
| 128 | 128 | function svg_dimension_to_pixels($dimension, $precision = 2) { |
| 129 | - if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | - switch (strtolower($m[2])) { |
|
| 131 | - case '%': |
|
| 132 | - // on ne sait pas faire :( |
|
| 133 | - return false; |
|
| 134 | - break; |
|
| 135 | - case 'em': |
|
| 136 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | - break; |
|
| 138 | - case 'ex': |
|
| 139 | - return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | - break; |
|
| 141 | - case 'pc': |
|
| 142 | - return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | - break; |
|
| 144 | - case 'cm': |
|
| 145 | - return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | - break; |
|
| 147 | - case 'mm': |
|
| 148 | - return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | - break; |
|
| 150 | - case 'in': |
|
| 151 | - return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | - break; |
|
| 153 | - case 'px': |
|
| 154 | - case 'pt': |
|
| 155 | - default: |
|
| 156 | - return $m[1]; |
|
| 157 | - break; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - return false; |
|
| 129 | + if (preg_match(',^(-?\d+(\.\d+)?)([^\d]*),i', trim($dimension), $m)) { |
|
| 130 | + switch (strtolower($m[2])) { |
|
| 131 | + case '%': |
|
| 132 | + // on ne sait pas faire :( |
|
| 133 | + return false; |
|
| 134 | + break; |
|
| 135 | + case 'em': |
|
| 136 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 137 | + break; |
|
| 138 | + case 'ex': |
|
| 139 | + return round($m[1] * 16, $precision); // 16px font-size par defaut |
|
| 140 | + break; |
|
| 141 | + case 'pc': |
|
| 142 | + return round($m[1] * 16, $precision); // 1/6 inch = 96px/6 in CSS |
|
| 143 | + break; |
|
| 144 | + case 'cm': |
|
| 145 | + return round($m[1] * 96 / 2.54, $precision); // 96px / 2.54cm; |
|
| 146 | + break; |
|
| 147 | + case 'mm': |
|
| 148 | + return round($m[1] * 96 / 25.4, $precision); // 96px / 25.4mm; |
|
| 149 | + break; |
|
| 150 | + case 'in': |
|
| 151 | + return round($m[1] * 96, $precision); // 1 inch = 96px in CSS |
|
| 152 | + break; |
|
| 153 | + case 'px': |
|
| 154 | + case 'pt': |
|
| 155 | + default: |
|
| 156 | + return $m[1]; |
|
| 157 | + break; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + return false; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -168,15 +168,15 @@ discard block |
||
| 168 | 168 | * @return string |
| 169 | 169 | */ |
| 170 | 170 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 171 | - $new_balise_svg = '<svg'; |
|
| 172 | - foreach ($attributs as $k => $v) { |
|
| 173 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | - } |
|
| 175 | - $new_balise_svg .= '>'; |
|
| 176 | - |
|
| 177 | - $p = strpos($svg, $old_balise_svg); |
|
| 178 | - $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | - return $svg; |
|
| 171 | + $new_balise_svg = '<svg'; |
|
| 172 | + foreach ($attributs as $k => $v) { |
|
| 173 | + $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 174 | + } |
|
| 175 | + $new_balise_svg .= '>'; |
|
| 176 | + |
|
| 177 | + $p = strpos($svg, $old_balise_svg); |
|
| 178 | + $svg = substr_replace($svg, $new_balise_svg, $p, strlen($old_balise_svg)); |
|
| 179 | + return $svg; |
|
| 180 | 180 | } |
| 181 | 181 | |
| 182 | 182 | /** |
@@ -188,15 +188,15 @@ discard block |
||
| 188 | 188 | */ |
| 189 | 189 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 190 | 190 | |
| 191 | - if ($start === false or $start === 'end') { |
|
| 192 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | - } |
|
| 194 | - else { |
|
| 195 | - $p = stripos($svg, '<svg'); |
|
| 196 | - $p = strpos($svg, '>', $p); |
|
| 197 | - $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | - } |
|
| 199 | - return $svg; |
|
| 191 | + if ($start === false or $start === 'end') { |
|
| 192 | + $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 193 | + } |
|
| 194 | + else { |
|
| 195 | + $p = stripos($svg, '<svg'); |
|
| 196 | + $p = strpos($svg, '>', $p); |
|
| 197 | + $svg = substr_replace($svg, $shapes, $p + 1, 0); |
|
| 198 | + } |
|
| 199 | + return $svg; |
|
| 200 | 200 | } |
| 201 | 201 | |
| 202 | 202 | /** |
@@ -209,13 +209,13 @@ discard block |
||
| 209 | 209 | * @return string |
| 210 | 210 | */ |
| 211 | 211 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 212 | - $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | - $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | - $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | - return $svg; |
|
| 212 | + $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
|
| 213 | + $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 214 | + $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
|
| 215 | + $g = "<g clip-path=\"url(#$id)\">"; |
|
| 216 | + $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 217 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 218 | + return $svg; |
|
| 219 | 219 | } |
| 220 | 220 | |
| 221 | 221 | /** |
@@ -226,22 +226,22 @@ discard block |
||
| 226 | 226 | * @return bool|string |
| 227 | 227 | */ |
| 228 | 228 | function svg_redimensionner($img, $new_width, $new_height) { |
| 229 | - if ( |
|
| 230 | - $svg = svg_charger($img) |
|
| 231 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | - ) { |
|
| 233 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | - if (!isset($attributs['viewBox'])) { |
|
| 235 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | - } |
|
| 237 | - $attributs['width'] = strval($new_width); |
|
| 238 | - $attributs['height'] = strval($new_height); |
|
| 239 | - |
|
| 240 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | - return $svg; |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - return $img; |
|
| 229 | + if ( |
|
| 230 | + $svg = svg_charger($img) |
|
| 231 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 232 | + ) { |
|
| 233 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 234 | + if (!isset($attributs['viewBox'])) { |
|
| 235 | + $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 236 | + } |
|
| 237 | + $attributs['width'] = strval($new_width); |
|
| 238 | + $attributs['height'] = strval($new_height); |
|
| 239 | + |
|
| 240 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 241 | + return $svg; |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + return $img; |
|
| 245 | 245 | } |
| 246 | 246 | |
| 247 | 247 | /** |
@@ -250,15 +250,15 @@ discard block |
||
| 250 | 250 | * @return string |
| 251 | 251 | */ |
| 252 | 252 | function svg_couleur_to_hexa($couleur) { |
| 253 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | - $c = explode(',', substr($couleur, 4)); |
|
| 255 | - $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | - } |
|
| 257 | - else { |
|
| 258 | - $couleur = couleur_html_to_hex($couleur); |
|
| 259 | - } |
|
| 260 | - $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | - return $couleur; |
|
| 253 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 254 | + $c = explode(',', substr($couleur, 4)); |
|
| 255 | + $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
|
| 256 | + } |
|
| 257 | + else { |
|
| 258 | + $couleur = couleur_html_to_hex($couleur); |
|
| 259 | + } |
|
| 260 | + $couleur = '#' . ltrim($couleur, '#'); |
|
| 261 | + return $couleur; |
|
| 262 | 262 | } |
| 263 | 263 | |
| 264 | 264 | /** |
@@ -267,11 +267,11 @@ discard block |
||
| 267 | 267 | * @return array |
| 268 | 268 | */ |
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | - if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | - $c = explode(',', substr($couleur, 4)); |
|
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | - } |
|
| 274 | - return _couleur_hex_to_dec($couleur); |
|
| 270 | + if (strpos($couleur, 'rgb(') === 0) { |
|
| 271 | + $c = explode(',', substr($couleur, 4)); |
|
| 272 | + return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 273 | + } |
|
| 274 | + return _couleur_hex_to_dec($couleur); |
|
| 275 | 275 | } |
| 276 | 276 | |
| 277 | 277 | |
@@ -281,70 +281,70 @@ discard block |
||
| 281 | 281 | * @return array |
| 282 | 282 | */ |
| 283 | 283 | function svg_getimagesize_from_attr($attributs) { |
| 284 | - $width = 350; // default width |
|
| 285 | - $height = 150; // default height |
|
| 286 | - |
|
| 287 | - $viewBox = "0 0 $width $height"; |
|
| 288 | - if (isset($attributs['viewBox'])) { |
|
| 289 | - $viewBox = $attributs['viewBox']; |
|
| 290 | - $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | - } |
|
| 292 | - // et on la convertit en px |
|
| 293 | - $viewBox = explode(' ', $viewBox); |
|
| 294 | - $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | - if (!$viewBox[2]) { |
|
| 296 | - $viewBox[2] = $width; |
|
| 297 | - } |
|
| 298 | - if (!$viewBox[3]) { |
|
| 299 | - $viewBox[3] = $height; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - $coeff = 1; |
|
| 303 | - if ( |
|
| 304 | - isset($attributs['width']) |
|
| 305 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | - ) { |
|
| 307 | - $width = $w; |
|
| 308 | - } |
|
| 309 | - else { |
|
| 310 | - // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | - $width = $viewBox[2]; |
|
| 312 | - if ($width < 1) { |
|
| 313 | - $coeff = max($coeff, 1000); |
|
| 314 | - } |
|
| 315 | - elseif ($width < 10) { |
|
| 316 | - $coeff = max($coeff, 100); |
|
| 317 | - } |
|
| 318 | - elseif ($width < 100) { |
|
| 319 | - $coeff = max($coeff, 10); |
|
| 320 | - } |
|
| 321 | - } |
|
| 322 | - if ( |
|
| 323 | - isset($attributs['height']) |
|
| 324 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | - ) { |
|
| 326 | - $height = $h; |
|
| 327 | - } |
|
| 328 | - else { |
|
| 329 | - $height = $viewBox[3]; |
|
| 330 | - if ($height < 1) { |
|
| 331 | - $coeff = max($coeff, 1000); |
|
| 332 | - } |
|
| 333 | - elseif ($height < 10) { |
|
| 334 | - $coeff = max($coeff, 100); |
|
| 335 | - } |
|
| 336 | - elseif ($height < 100) { |
|
| 337 | - $coeff = max($coeff, 10); |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - // arrondir le width et height en pixel in fine |
|
| 342 | - $width = round($coeff * $width); |
|
| 343 | - $height = round($coeff * $height); |
|
| 344 | - |
|
| 345 | - $viewBox = implode(' ', $viewBox); |
|
| 346 | - |
|
| 347 | - return [$width, $height, $viewBox]; |
|
| 284 | + $width = 350; // default width |
|
| 285 | + $height = 150; // default height |
|
| 286 | + |
|
| 287 | + $viewBox = "0 0 $width $height"; |
|
| 288 | + if (isset($attributs['viewBox'])) { |
|
| 289 | + $viewBox = $attributs['viewBox']; |
|
| 290 | + $viewBox = preg_replace(',\s+,', ' ', $viewBox); |
|
| 291 | + } |
|
| 292 | + // et on la convertit en px |
|
| 293 | + $viewBox = explode(' ', $viewBox); |
|
| 294 | + $viewBox = array_map('svg_dimension_to_pixels', $viewBox); |
|
| 295 | + if (!$viewBox[2]) { |
|
| 296 | + $viewBox[2] = $width; |
|
| 297 | + } |
|
| 298 | + if (!$viewBox[3]) { |
|
| 299 | + $viewBox[3] = $height; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + $coeff = 1; |
|
| 303 | + if ( |
|
| 304 | + isset($attributs['width']) |
|
| 305 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 306 | + ) { |
|
| 307 | + $width = $w; |
|
| 308 | + } |
|
| 309 | + else { |
|
| 310 | + // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
|
| 311 | + $width = $viewBox[2]; |
|
| 312 | + if ($width < 1) { |
|
| 313 | + $coeff = max($coeff, 1000); |
|
| 314 | + } |
|
| 315 | + elseif ($width < 10) { |
|
| 316 | + $coeff = max($coeff, 100); |
|
| 317 | + } |
|
| 318 | + elseif ($width < 100) { |
|
| 319 | + $coeff = max($coeff, 10); |
|
| 320 | + } |
|
| 321 | + } |
|
| 322 | + if ( |
|
| 323 | + isset($attributs['height']) |
|
| 324 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 325 | + ) { |
|
| 326 | + $height = $h; |
|
| 327 | + } |
|
| 328 | + else { |
|
| 329 | + $height = $viewBox[3]; |
|
| 330 | + if ($height < 1) { |
|
| 331 | + $coeff = max($coeff, 1000); |
|
| 332 | + } |
|
| 333 | + elseif ($height < 10) { |
|
| 334 | + $coeff = max($coeff, 100); |
|
| 335 | + } |
|
| 336 | + elseif ($height < 100) { |
|
| 337 | + $coeff = max($coeff, 10); |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + // arrondir le width et height en pixel in fine |
|
| 342 | + $width = round($coeff * $width); |
|
| 343 | + $height = round($coeff * $height); |
|
| 344 | + |
|
| 345 | + $viewBox = implode(' ', $viewBox); |
|
| 346 | + |
|
| 347 | + return [$width, $height, $viewBox]; |
|
| 348 | 348 | } |
| 349 | 349 | |
| 350 | 350 | /** |
@@ -360,25 +360,25 @@ discard block |
||
| 360 | 360 | * @return string |
| 361 | 361 | */ |
| 362 | 362 | function svg_force_viewBox_px($img, $force_width_and_height = false) { |
| 363 | - if ( |
|
| 364 | - $svg = svg_charger($img) |
|
| 365 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | - ) { |
|
| 367 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 363 | + if ( |
|
| 364 | + $svg = svg_charger($img) |
|
| 365 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | + ) { |
|
| 367 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 368 | 368 | |
| 369 | - [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 369 | + [$width, $height, $viewBox] = svg_getimagesize_from_attr($attributs); |
|
| 370 | 370 | |
| 371 | - if ($force_width_and_height) { |
|
| 372 | - $attributs['width'] = $width; |
|
| 373 | - $attributs['height'] = $height; |
|
| 374 | - } |
|
| 371 | + if ($force_width_and_height) { |
|
| 372 | + $attributs['width'] = $width; |
|
| 373 | + $attributs['height'] = $height; |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - $attributs['viewBox'] = $viewBox; |
|
| 376 | + $attributs['viewBox'] = $viewBox; |
|
| 377 | 377 | |
| 378 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | - return $svg; |
|
| 380 | - } |
|
| 381 | - return $img; |
|
| 378 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 379 | + return $svg; |
|
| 380 | + } |
|
| 381 | + return $img; |
|
| 382 | 382 | } |
| 383 | 383 | |
| 384 | 384 | /** |
@@ -387,12 +387,12 @@ discard block |
||
| 387 | 387 | * @return array|mixed |
| 388 | 388 | */ |
| 389 | 389 | function svg_extract_couleurs($img) { |
| 390 | - if ($svg = svg_charger($img)) { |
|
| 391 | - if (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)) { |
|
| 392 | - return $matches[0]; |
|
| 393 | - } |
|
| 394 | - } |
|
| 395 | - return []; |
|
| 390 | + if ($svg = svg_charger($img)) { |
|
| 391 | + if (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)) { |
|
| 392 | + return $matches[0]; |
|
| 393 | + } |
|
| 394 | + } |
|
| 395 | + return []; |
|
| 396 | 396 | } |
| 397 | 397 | |
| 398 | 398 | /** |
@@ -403,58 +403,58 @@ discard block |
||
| 403 | 403 | * @return bool|string |
| 404 | 404 | */ |
| 405 | 405 | function svg_recadrer($img, $new_width, $new_height, $offset_width, $offset_height, $background_color = '') { |
| 406 | - if ( |
|
| 407 | - $svg = svg_force_viewBox_px($img) |
|
| 408 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | - ) { |
|
| 410 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | - |
|
| 413 | - $viewport_w = $new_width; |
|
| 414 | - $viewport_h = $new_height; |
|
| 415 | - $viewport_ox = $offset_width; |
|
| 416 | - $viewport_oy = $offset_height; |
|
| 417 | - |
|
| 418 | - // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | - if ( |
|
| 420 | - isset($attributs['width']) |
|
| 421 | - and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | - and isset($attributs['height']) |
|
| 423 | - and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | - ) { |
|
| 425 | - $xscale = $viewBox[2] / $w; |
|
| 426 | - $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | - $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | - $yscale = $viewBox[3] / $h; |
|
| 429 | - $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | - $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | - } |
|
| 432 | - |
|
| 433 | - if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | - $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | - } |
|
| 436 | - |
|
| 437 | - // maintenant on redefinit la viewBox |
|
| 438 | - $viewBox[0] += $viewport_ox; |
|
| 439 | - $viewBox[1] += $viewport_oy; |
|
| 440 | - $viewBox[2] = $viewport_w; |
|
| 441 | - $viewBox[3] = $viewport_h; |
|
| 442 | - |
|
| 443 | - $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | - $attributs['width'] = strval($new_width); |
|
| 445 | - $attributs['height'] = strval($new_height); |
|
| 446 | - |
|
| 447 | - $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | - |
|
| 449 | - // ajouter un background |
|
| 450 | - if ($background_color and $background_color !== 'transparent') { |
|
| 451 | - $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | - } |
|
| 453 | - |
|
| 454 | - return $svg; |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - return $img; |
|
| 406 | + if ( |
|
| 407 | + $svg = svg_force_viewBox_px($img) |
|
| 408 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 409 | + ) { |
|
| 410 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 411 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 412 | + |
|
| 413 | + $viewport_w = $new_width; |
|
| 414 | + $viewport_h = $new_height; |
|
| 415 | + $viewport_ox = $offset_width; |
|
| 416 | + $viewport_oy = $offset_height; |
|
| 417 | + |
|
| 418 | + // si on a un width/height qui rescale, il faut rescaler |
|
| 419 | + if ( |
|
| 420 | + isset($attributs['width']) |
|
| 421 | + and $w = svg_dimension_to_pixels($attributs['width']) |
|
| 422 | + and isset($attributs['height']) |
|
| 423 | + and $h = svg_dimension_to_pixels($attributs['height']) |
|
| 424 | + ) { |
|
| 425 | + $xscale = $viewBox[2] / $w; |
|
| 426 | + $viewport_w = round($viewport_w * $xscale, 2); |
|
| 427 | + $viewport_ox = round($viewport_ox * $xscale, 2); |
|
| 428 | + $yscale = $viewBox[3] / $h; |
|
| 429 | + $viewport_h = round($viewport_h * $yscale, 2); |
|
| 430 | + $viewport_oy = round($viewport_oy * $yscale, 2); |
|
| 431 | + } |
|
| 432 | + |
|
| 433 | + if ($viewport_w > $viewBox[2] or $viewport_h > $viewBox[3]) { |
|
| 434 | + $svg = svg_clip_in_box($svg, $viewBox[0], $viewBox[1], $viewBox[2], $viewBox[3]); |
|
| 435 | + } |
|
| 436 | + |
|
| 437 | + // maintenant on redefinit la viewBox |
|
| 438 | + $viewBox[0] += $viewport_ox; |
|
| 439 | + $viewBox[1] += $viewport_oy; |
|
| 440 | + $viewBox[2] = $viewport_w; |
|
| 441 | + $viewBox[3] = $viewport_h; |
|
| 442 | + |
|
| 443 | + $attributs['viewBox'] = implode(' ', $viewBox); |
|
| 444 | + $attributs['width'] = strval($new_width); |
|
| 445 | + $attributs['height'] = strval($new_height); |
|
| 446 | + |
|
| 447 | + $svg = svg_change_balise_svg($svg, $balise_svg, $attributs); |
|
| 448 | + |
|
| 449 | + // ajouter un background |
|
| 450 | + if ($background_color and $background_color !== 'transparent') { |
|
| 451 | + $svg = svg_ajouter_background($svg, $background_color); |
|
| 452 | + } |
|
| 453 | + |
|
| 454 | + return $svg; |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + return $img; |
|
| 458 | 458 | } |
| 459 | 459 | |
| 460 | 460 | /** |
@@ -464,26 +464,26 @@ discard block |
||
| 464 | 464 | * @return bool|string |
| 465 | 465 | */ |
| 466 | 466 | function svg_ajouter_background($img, $background_color) { |
| 467 | - if ( |
|
| 468 | - $svg = svg_charger($img) |
|
| 469 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | - ) { |
|
| 471 | - if ($background_color and $background_color !== 'transparent') { |
|
| 472 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | - |
|
| 474 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | - if (isset($attributs['viewBox'])) { |
|
| 476 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | - } |
|
| 479 | - else { |
|
| 480 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | - } |
|
| 482 | - $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | - } |
|
| 484 | - return $svg; |
|
| 485 | - } |
|
| 486 | - return $img; |
|
| 467 | + if ( |
|
| 468 | + $svg = svg_charger($img) |
|
| 469 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 470 | + ) { |
|
| 471 | + if ($background_color and $background_color !== 'transparent') { |
|
| 472 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 473 | + |
|
| 474 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 475 | + if (isset($attributs['viewBox'])) { |
|
| 476 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 477 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 478 | + } |
|
| 479 | + else { |
|
| 480 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 481 | + } |
|
| 482 | + $svg = svg_insert_shapes($svg, $rect); |
|
| 483 | + } |
|
| 484 | + return $svg; |
|
| 485 | + } |
|
| 486 | + return $img; |
|
| 487 | 487 | } |
| 488 | 488 | |
| 489 | 489 | |
@@ -494,26 +494,26 @@ discard block |
||
| 494 | 494 | * @return bool|string |
| 495 | 495 | */ |
| 496 | 496 | function svg_ajouter_voile($img, $background_color, $opacity) { |
| 497 | - if ( |
|
| 498 | - $svg = svg_charger($img) |
|
| 499 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | - ) { |
|
| 501 | - if ($background_color and $background_color !== 'transparent') { |
|
| 502 | - [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | - |
|
| 504 | - $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | - if (isset($attributs['viewBox'])) { |
|
| 506 | - $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | - } |
|
| 509 | - else { |
|
| 510 | - $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | - } |
|
| 512 | - $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | - } |
|
| 514 | - return $svg; |
|
| 515 | - } |
|
| 516 | - return $img; |
|
| 497 | + if ( |
|
| 498 | + $svg = svg_charger($img) |
|
| 499 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 500 | + ) { |
|
| 501 | + if ($background_color and $background_color !== 'transparent') { |
|
| 502 | + [$balise_svg, $attributs] = $svg_infos; |
|
| 503 | + |
|
| 504 | + $background_color = svg_couleur_to_hexa($background_color); |
|
| 505 | + if (isset($attributs['viewBox'])) { |
|
| 506 | + $viewBox = explode(' ', $attributs['viewBox']); |
|
| 507 | + $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | + } |
|
| 509 | + else { |
|
| 510 | + $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
|
| 511 | + } |
|
| 512 | + $svg = svg_insert_shapes($svg, $rect, false); |
|
| 513 | + } |
|
| 514 | + return $svg; |
|
| 515 | + } |
|
| 516 | + return $img; |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | |
@@ -524,27 +524,27 @@ discard block |
||
| 524 | 524 | * @return bool|string |
| 525 | 525 | */ |
| 526 | 526 | function svg_transformer($img, $attributs) { |
| 527 | - if ( |
|
| 528 | - $svg = svg_charger($img) |
|
| 529 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | - ) { |
|
| 531 | - if ($attributs) { |
|
| 532 | - [$balise_svg, ] = $svg_infos; |
|
| 533 | - $g = '<g'; |
|
| 534 | - foreach ($attributs as $k => $v) { |
|
| 535 | - if (strlen($v)) { |
|
| 536 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | - } |
|
| 538 | - } |
|
| 539 | - if (strlen($g) > 2) { |
|
| 540 | - $g .= '>'; |
|
| 541 | - $svg = svg_insert_shapes($svg, $g); |
|
| 542 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - return $svg; |
|
| 546 | - } |
|
| 547 | - return $img; |
|
| 527 | + if ( |
|
| 528 | + $svg = svg_charger($img) |
|
| 529 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 530 | + ) { |
|
| 531 | + if ($attributs) { |
|
| 532 | + [$balise_svg, ] = $svg_infos; |
|
| 533 | + $g = '<g'; |
|
| 534 | + foreach ($attributs as $k => $v) { |
|
| 535 | + if (strlen($v)) { |
|
| 536 | + $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 537 | + } |
|
| 538 | + } |
|
| 539 | + if (strlen($g) > 2) { |
|
| 540 | + $g .= '>'; |
|
| 541 | + $svg = svg_insert_shapes($svg, $g); |
|
| 542 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + return $svg; |
|
| 546 | + } |
|
| 547 | + return $img; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | /** |
@@ -555,21 +555,21 @@ discard block |
||
| 555 | 555 | * @return bool|string |
| 556 | 556 | */ |
| 557 | 557 | function svg_apply_filter($img, $filter_def) { |
| 558 | - if ( |
|
| 559 | - $svg = svg_charger($img) |
|
| 560 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | - ) { |
|
| 562 | - if ($filter_def) { |
|
| 563 | - [$balise_svg, ] = $svg_infos; |
|
| 564 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | - $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | - $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | - $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | - } |
|
| 570 | - return $svg; |
|
| 571 | - } |
|
| 572 | - return $img; |
|
| 558 | + if ( |
|
| 559 | + $svg = svg_charger($img) |
|
| 560 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 561 | + ) { |
|
| 562 | + if ($filter_def) { |
|
| 563 | + [$balise_svg, ] = $svg_infos; |
|
| 564 | + $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 565 | + $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
|
| 566 | + $g = "<g filter=\"url(#$filter_id)\">"; |
|
| 567 | + $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 568 | + $svg = svg_insert_shapes($svg, '</g>', false); |
|
| 569 | + } |
|
| 570 | + return $svg; |
|
| 571 | + } |
|
| 572 | + return $img; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
@@ -579,8 +579,8 @@ discard block |
||
| 579 | 579 | * @return string |
| 580 | 580 | */ |
| 581 | 581 | function svg_filter_blur($img, $blur_width) { |
| 582 | - $blur_width = intval($blur_width); |
|
| 583 | - return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 582 | + $blur_width = intval($blur_width); |
|
| 583 | + return svg_apply_filter($img, "<feGaussianBlur stdDeviation=\"$blur_width\"/>"); |
|
| 584 | 584 | } |
| 585 | 585 | |
| 586 | 586 | /** |
@@ -590,10 +590,10 @@ discard block |
||
| 590 | 590 | * @return bool|string |
| 591 | 591 | */ |
| 592 | 592 | function svg_filter_grayscale($img, $intensity) { |
| 593 | - $value = round(1.0 - $intensity, 2); |
|
| 594 | - //$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\"/>"; |
|
| 595 | - $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | - return svg_apply_filter($img, $filter); |
|
| 593 | + $value = round(1.0 - $intensity, 2); |
|
| 594 | + //$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\"/>"; |
|
| 595 | + $filter = "<feColorMatrix type=\"saturate\" values=\"$value\"/>"; |
|
| 596 | + return svg_apply_filter($img, $filter); |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | /** |
@@ -603,8 +603,8 @@ discard block |
||
| 603 | 603 | * @return bool|string |
| 604 | 604 | */ |
| 605 | 605 | function svg_filter_sepia($img, $intensity) { |
| 606 | - $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"/>'; |
|
| 607 | - return svg_apply_filter($img, $filter); |
|
| 606 | + $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"/>'; |
|
| 607 | + return svg_apply_filter($img, $filter); |
|
| 608 | 608 | } |
| 609 | 609 | |
| 610 | 610 | /** |
@@ -614,31 +614,31 @@ discard block |
||
| 614 | 614 | * @return bool|string |
| 615 | 615 | */ |
| 616 | 616 | function svg_flip($img, $HorV) { |
| 617 | - if ( |
|
| 618 | - $svg = svg_force_viewBox_px($img) |
|
| 619 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | - ) { |
|
| 621 | - [$balise_svg, $atts] = $svg_infos; |
|
| 622 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | - |
|
| 624 | - if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | - $transform = 'scale(-1,1)'; |
|
| 626 | - |
|
| 627 | - $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | - $mx = -$x; |
|
| 629 | - $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | - } |
|
| 631 | - else { |
|
| 632 | - $transform = 'scale(1,-1)'; |
|
| 633 | - |
|
| 634 | - $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | - $my = -$y; |
|
| 636 | - $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | - } |
|
| 638 | - $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | - return $svg; |
|
| 640 | - } |
|
| 641 | - return $img; |
|
| 617 | + if ( |
|
| 618 | + $svg = svg_force_viewBox_px($img) |
|
| 619 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 620 | + ) { |
|
| 621 | + [$balise_svg, $atts] = $svg_infos; |
|
| 622 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 623 | + |
|
| 624 | + if (!in_array($HorV, ['h', 'H'])) { |
|
| 625 | + $transform = 'scale(-1,1)'; |
|
| 626 | + |
|
| 627 | + $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
|
| 628 | + $mx = -$x; |
|
| 629 | + $transform = "translate($x, 0) $transform translate($mx, 0)"; |
|
| 630 | + } |
|
| 631 | + else { |
|
| 632 | + $transform = 'scale(1,-1)'; |
|
| 633 | + |
|
| 634 | + $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
|
| 635 | + $my = -$y; |
|
| 636 | + $transform = "translate(0, $y) $transform translate(0, $my)"; |
|
| 637 | + } |
|
| 638 | + $svg = svg_transformer($svg, ['transform' => $transform]); |
|
| 639 | + return $svg; |
|
| 640 | + } |
|
| 641 | + return $img; |
|
| 642 | 642 | } |
| 643 | 643 | |
| 644 | 644 | /** |
@@ -652,20 +652,20 @@ discard block |
||
| 652 | 652 | * @return bool|string |
| 653 | 653 | */ |
| 654 | 654 | function svg_rotate($img, $angle, $center_x, $center_y) { |
| 655 | - if ( |
|
| 656 | - $svg = svg_force_viewBox_px($img) |
|
| 657 | - and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | - ) { |
|
| 659 | - [$balise_svg, $atts] = $svg_infos; |
|
| 660 | - $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | - |
|
| 662 | - $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | - $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | - $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | - |
|
| 666 | - return $svg; |
|
| 667 | - } |
|
| 668 | - return $img; |
|
| 655 | + if ( |
|
| 656 | + $svg = svg_force_viewBox_px($img) |
|
| 657 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 658 | + ) { |
|
| 659 | + [$balise_svg, $atts] = $svg_infos; |
|
| 660 | + $viewBox = explode(' ', $atts['viewBox']); |
|
| 661 | + |
|
| 662 | + $center_x = round($viewBox[0] + $center_x * $viewBox[2]); |
|
| 663 | + $center_y = round($viewBox[1] + $center_y * $viewBox[3]); |
|
| 664 | + $svg = svg_transformer($svg, ['transform' => "rotate($angle $center_x $center_y)"]); |
|
| 665 | + |
|
| 666 | + return $svg; |
|
| 667 | + } |
|
| 668 | + return $img; |
|
| 669 | 669 | } |
| 670 | 670 | |
| 671 | 671 | /** |
@@ -677,41 +677,41 @@ discard block |
||
| 677 | 677 | * @return bool|mixed|string |
| 678 | 678 | */ |
| 679 | 679 | function svg_filtrer_couleurs($img, $callback_filter) { |
| 680 | - if ( |
|
| 681 | - $svg = svg_force_viewBox_px($img) |
|
| 682 | - and $colors = svg_extract_couleurs($svg) |
|
| 683 | - ) { |
|
| 684 | - $colors = array_unique($colors); |
|
| 685 | - |
|
| 686 | - $short = []; |
|
| 687 | - $long = []; |
|
| 688 | - while (count($colors)) { |
|
| 689 | - $c = array_shift($colors); |
|
| 690 | - if (strlen($c) == 4) { |
|
| 691 | - $short[] = $c; |
|
| 692 | - } |
|
| 693 | - else { |
|
| 694 | - $long[] = $c; |
|
| 695 | - } |
|
| 696 | - } |
|
| 697 | - |
|
| 698 | - $colors = [...$long, ...$short]; |
|
| 699 | - $new_colors = []; |
|
| 700 | - $colors = array_flip($colors); |
|
| 701 | - foreach ($colors as $c => $k) { |
|
| 702 | - $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | - } |
|
| 704 | - |
|
| 705 | - |
|
| 706 | - foreach ($colors as $original => $replace) { |
|
| 707 | - $new = svg_couleur_to_hexa($original); |
|
| 708 | - $new_colors[$replace] = $callback_filter($new); |
|
| 709 | - } |
|
| 710 | - |
|
| 711 | - $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | - $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | - |
|
| 714 | - return $svg; |
|
| 715 | - } |
|
| 716 | - return $img; |
|
| 680 | + if ( |
|
| 681 | + $svg = svg_force_viewBox_px($img) |
|
| 682 | + and $colors = svg_extract_couleurs($svg) |
|
| 683 | + ) { |
|
| 684 | + $colors = array_unique($colors); |
|
| 685 | + |
|
| 686 | + $short = []; |
|
| 687 | + $long = []; |
|
| 688 | + while (count($colors)) { |
|
| 689 | + $c = array_shift($colors); |
|
| 690 | + if (strlen($c) == 4) { |
|
| 691 | + $short[] = $c; |
|
| 692 | + } |
|
| 693 | + else { |
|
| 694 | + $long[] = $c; |
|
| 695 | + } |
|
| 696 | + } |
|
| 697 | + |
|
| 698 | + $colors = [...$long, ...$short]; |
|
| 699 | + $new_colors = []; |
|
| 700 | + $colors = array_flip($colors); |
|
| 701 | + foreach ($colors as $c => $k) { |
|
| 702 | + $colors[$c] = "@@@COLOR$$k$@@@"; |
|
| 703 | + } |
|
| 704 | + |
|
| 705 | + |
|
| 706 | + foreach ($colors as $original => $replace) { |
|
| 707 | + $new = svg_couleur_to_hexa($original); |
|
| 708 | + $new_colors[$replace] = $callback_filter($new); |
|
| 709 | + } |
|
| 710 | + |
|
| 711 | + $svg = str_replace(array_keys($colors), array_values($colors), $svg); |
|
| 712 | + $svg = str_replace(array_keys($new_colors), array_values($new_colors), $svg); |
|
| 713 | + |
|
| 714 | + return $svg; |
|
| 715 | + } |
|
| 716 | + return $img; |
|
| 717 | 717 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | **/ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | |
| 24 | 24 | |
@@ -44,18 +44,18 @@ discard block |
||
| 44 | 44 | * Pile complétée par le code à générer |
| 45 | 45 | */ |
| 46 | 46 | function balise_BOITE_OUVRIR_dist($p) { |
| 47 | - $_titre = interprete_argument_balise(1, $p); |
|
| 48 | - $_class = interprete_argument_balise(2, $p); |
|
| 49 | - $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | - $_titre = ($_titre ?: "''"); |
|
| 51 | - $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | - $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | - |
|
| 54 | - $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | - $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | - $p->interdire_scripts = false; |
|
| 57 | - |
|
| 58 | - return $p; |
|
| 47 | + $_titre = interprete_argument_balise(1, $p); |
|
| 48 | + $_class = interprete_argument_balise(2, $p); |
|
| 49 | + $_head_class = interprete_argument_balise(3, $p); |
|
| 50 | + $_titre = ($_titre ?: "''"); |
|
| 51 | + $_class = ($_class ? ", $_class" : ", 'simple'"); |
|
| 52 | + $_head_class = ($_head_class ? ", $_head_class" : ''); |
|
| 53 | + |
|
| 54 | + $f = chercher_filtre('boite_ouvrir'); |
|
| 55 | + $p->code = "$f($_titre$_class$_head_class)"; |
|
| 56 | + $p->interdire_scripts = false; |
|
| 57 | + |
|
| 58 | + return $p; |
|
| 59 | 59 | } |
| 60 | 60 | |
| 61 | 61 | /** |
@@ -75,14 +75,14 @@ discard block |
||
| 75 | 75 | * Pile complétée par le code à générer |
| 76 | 76 | */ |
| 77 | 77 | function balise_BOITE_PIED_dist($p) { |
| 78 | - $_class = interprete_argument_balise(1, $p); |
|
| 79 | - $_class = ($_class ? "$_class" : ''); |
|
| 78 | + $_class = interprete_argument_balise(1, $p); |
|
| 79 | + $_class = ($_class ? "$_class" : ''); |
|
| 80 | 80 | |
| 81 | - $f = chercher_filtre('boite_pied'); |
|
| 82 | - $p->code = "$f($_class)"; |
|
| 83 | - $p->interdire_scripts = false; |
|
| 81 | + $f = chercher_filtre('boite_pied'); |
|
| 82 | + $p->code = "$f($_class)"; |
|
| 83 | + $p->interdire_scripts = false; |
|
| 84 | 84 | |
| 85 | - return $p; |
|
| 85 | + return $p; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * Pile complétée par le code à générer |
| 103 | 103 | */ |
| 104 | 104 | function balise_BOITE_FERMER_dist($p) { |
| 105 | - $f = chercher_filtre('boite_fermer'); |
|
| 106 | - $p->code = "$f()"; |
|
| 107 | - $p->interdire_scripts = false; |
|
| 105 | + $f = chercher_filtre('boite_fermer'); |
|
| 106 | + $p->code = "$f()"; |
|
| 107 | + $p->interdire_scripts = false; |
|
| 108 | 108 | |
| 109 | - return $p; |
|
| 109 | + return $p; |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -128,16 +128,16 @@ discard block |
||
| 128 | 128 | * HTML du début de la boîte |
| 129 | 129 | */ |
| 130 | 130 | function boite_ouvrir($titre, $class = '', $head_class = '', $id = '') { |
| 131 | - $class = "box $class"; |
|
| 132 | - $head_class = "box__header $head_class clearfix"; |
|
| 133 | - // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | - if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | - $titre = "<h3>$titre</h3>"; |
|
| 136 | - } |
|
| 137 | - |
|
| 138 | - return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | - . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | - . '<div class="box__body clearfix">'; |
|
| 131 | + $class = "box $class"; |
|
| 132 | + $head_class = "box__header $head_class clearfix"; |
|
| 133 | + // dans l'espace prive, titrer en h3 si pas de balise <hn> |
|
| 134 | + if (test_espace_prive() and strlen($titre) and strpos($titre, '<h') === false) { |
|
| 135 | + $titre = "<h3>$titre</h3>"; |
|
| 136 | + } |
|
| 137 | + |
|
| 138 | + return '<div class="' . $class . ($id ? "\" id=\"$id" : '') . '">' |
|
| 139 | + . ($titre ? "<div class=\"$head_class\">$titre<!--/hd--></div>" : '') |
|
| 140 | + . '<div class="box__body clearfix">'; |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -154,10 +154,10 @@ discard block |
||
| 154 | 154 | * HTML de transition vers le pied de la boîte |
| 155 | 155 | */ |
| 156 | 156 | function boite_pied($class = 'act') { |
| 157 | - $class = "box__footer $class"; |
|
| 157 | + $class = "box__footer $class"; |
|
| 158 | 158 | |
| 159 | - return '</div>' |
|
| 160 | - . "<div class=\"$class clearfix\">"; |
|
| 159 | + return '</div>' |
|
| 160 | + . "<div class=\"$class clearfix\">"; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | |
@@ -172,6 +172,6 @@ discard block |
||
| 172 | 172 | * HTML de fin de la boîte |
| 173 | 173 | */ |
| 174 | 174 | function boite_fermer() { |
| 175 | - return '</div>' |
|
| 176 | - . '</div>'; |
|
| 175 | + return '</div>' |
|
| 176 | + . '</div>'; |
|
| 177 | 177 | } |
@@ -28,7 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | |
| 30 | 30 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 31 | - return; |
|
| 31 | + return; |
|
| 32 | 32 | } |
| 33 | 33 | |
| 34 | 34 | |
@@ -48,55 +48,55 @@ discard block |
||
| 48 | 48 | * array : description des roles applicables dans 3 index : colonne, titres, roles |
| 49 | 49 | **/ |
| 50 | 50 | function roles_presents($objet, $objet_destination = '') { |
| 51 | - $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | - |
|
| 53 | - // pas de liste de roles, on sort |
|
| 54 | - if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | - return false; |
|
| 56 | - } |
|
| 57 | - |
|
| 58 | - // on vérifie que la table de liaison existe |
|
| 59 | - include_spip('action/editer_liens'); |
|
| 60 | - if (!$lien = objet_associable($objet)) { |
|
| 61 | - return false; |
|
| 62 | - } |
|
| 63 | - |
|
| 64 | - // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | - $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | - [, $table_lien] = $lien; |
|
| 68 | - $desc_lien = $trouver_table($table_lien); |
|
| 69 | - if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | - return false; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | - if (!$application = $desc['roles_objets']) { |
|
| 75 | - return false; |
|
| 76 | - } |
|
| 77 | - |
|
| 78 | - // destination presente, on restreint si possible |
|
| 79 | - if ($objet_destination) { |
|
| 80 | - $objet_destination = table_objet($objet_destination); |
|
| 81 | - |
|
| 82 | - // pour l'objet |
|
| 83 | - if (isset($application[$objet_destination])) { |
|
| 84 | - $application = $application[$objet_destination]; |
|
| 85 | - // sinon pour tous les objets |
|
| 86 | - } elseif (isset($application['*'])) { |
|
| 87 | - $application = $application['*']; |
|
| 88 | - } // sinon tant pis |
|
| 89 | - else { |
|
| 90 | - return false; |
|
| 91 | - } |
|
| 92 | - } |
|
| 93 | - |
|
| 94 | - // tout est ok |
|
| 95 | - return [ |
|
| 96 | - 'titres' => $titres, |
|
| 97 | - 'roles' => $application, |
|
| 98 | - 'colonne' => $colonne |
|
| 99 | - ]; |
|
| 51 | + $desc = lister_tables_objets_sql(table_objet_sql($objet)); |
|
| 52 | + |
|
| 53 | + // pas de liste de roles, on sort |
|
| 54 | + if (!isset($desc['roles_titres']) or !($titres = $desc['roles_titres'])) { |
|
| 55 | + return false; |
|
| 56 | + } |
|
| 57 | + |
|
| 58 | + // on vérifie que la table de liaison existe |
|
| 59 | + include_spip('action/editer_liens'); |
|
| 60 | + if (!$lien = objet_associable($objet)) { |
|
| 61 | + return false; |
|
| 62 | + } |
|
| 63 | + |
|
| 64 | + // on cherche ensuite si la colonne existe bien dans la table de liaison (par défaut 'role') |
|
| 65 | + $colonne = $desc['roles_colonne'] ?? 'role'; |
|
| 66 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 67 | + [, $table_lien] = $lien; |
|
| 68 | + $desc_lien = $trouver_table($table_lien); |
|
| 69 | + if (!isset($desc_lien['field'][$colonne])) { |
|
| 70 | + return false; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // sur quoi peuvent s'appliquer nos rôles |
|
| 74 | + if (!$application = $desc['roles_objets']) { |
|
| 75 | + return false; |
|
| 76 | + } |
|
| 77 | + |
|
| 78 | + // destination presente, on restreint si possible |
|
| 79 | + if ($objet_destination) { |
|
| 80 | + $objet_destination = table_objet($objet_destination); |
|
| 81 | + |
|
| 82 | + // pour l'objet |
|
| 83 | + if (isset($application[$objet_destination])) { |
|
| 84 | + $application = $application[$objet_destination]; |
|
| 85 | + // sinon pour tous les objets |
|
| 86 | + } elseif (isset($application['*'])) { |
|
| 87 | + $application = $application['*']; |
|
| 88 | + } // sinon tant pis |
|
| 89 | + else { |
|
| 90 | + return false; |
|
| 91 | + } |
|
| 92 | + } |
|
| 93 | + |
|
| 94 | + // tout est ok |
|
| 95 | + return [ |
|
| 96 | + 'titres' => $titres, |
|
| 97 | + 'roles' => $application, |
|
| 98 | + 'colonne' => $colonne |
|
| 99 | + ]; |
|
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | /** |
@@ -110,11 +110,11 @@ discard block |
||
| 110 | 110 | * Nom de la colonne, sinon vide |
| 111 | 111 | **/ |
| 112 | 112 | function roles_colonne($objet, $objet_destination) { |
| 113 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | - return $roles['colonne']; |
|
| 115 | - } |
|
| 113 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 114 | + return $roles['colonne']; |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - return ''; |
|
| 117 | + return ''; |
|
| 118 | 118 | } |
| 119 | 119 | |
| 120 | 120 | |
@@ -136,24 +136,24 @@ discard block |
||
| 136 | 136 | * Liste ('', '', array()) sinon. |
| 137 | 137 | **/ |
| 138 | 138 | function roles_trouver_dans_qualif($objet, $objet_destination, $qualif = []) { |
| 139 | - // si des rôles sont possibles, on les utilise |
|
| 140 | - $role = $colonne_role = ''; # role défini |
|
| 141 | - // condition du where par defaut |
|
| 142 | - $cond = []; |
|
| 143 | - if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | - $colonne_role = $roles['colonne']; |
|
| 145 | - // qu'il n'est pas défini |
|
| 146 | - if ( |
|
| 147 | - !isset($qualif[$colonne_role]) |
|
| 148 | - or !($role = $qualif[$colonne_role]) |
|
| 149 | - ) { |
|
| 150 | - $role = $roles['roles']['defaut']; |
|
| 151 | - } |
|
| 152 | - // where |
|
| 153 | - $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | - } |
|
| 155 | - |
|
| 156 | - return [$role, $colonne_role, $cond]; |
|
| 139 | + // si des rôles sont possibles, on les utilise |
|
| 140 | + $role = $colonne_role = ''; # role défini |
|
| 141 | + // condition du where par defaut |
|
| 142 | + $cond = []; |
|
| 143 | + if ($roles = roles_presents($objet, $objet_destination)) { |
|
| 144 | + $colonne_role = $roles['colonne']; |
|
| 145 | + // qu'il n'est pas défini |
|
| 146 | + if ( |
|
| 147 | + !isset($qualif[$colonne_role]) |
|
| 148 | + or !($role = $qualif[$colonne_role]) |
|
| 149 | + ) { |
|
| 150 | + $role = $roles['roles']['defaut']; |
|
| 151 | + } |
|
| 152 | + // where |
|
| 153 | + $cond = ["$colonne_role=" . sql_quote($role)]; |
|
| 154 | + } |
|
| 155 | + |
|
| 156 | + return [$role, $colonne_role, $cond]; |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -175,21 +175,21 @@ discard block |
||
| 175 | 175 | * Liste (Tableau de conditions where complété du role, Colonne du role, role utilisé) |
| 176 | 176 | **/ |
| 177 | 177 | function roles_creer_condition_role($objet_source, $objet, $cond, $tous_si_absent = false) { |
| 178 | - // role par défaut, colonne |
|
| 179 | - [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 178 | + // role par défaut, colonne |
|
| 179 | + [$role_defaut, $colonne_role] = roles_trouver_dans_qualif($objet_source, $objet); |
|
| 180 | 180 | |
| 181 | - // chercher d'eventuels rôles transmis |
|
| 182 | - $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | - unset($cond['role']); // cette condition est particuliere... |
|
| 181 | + // chercher d'eventuels rôles transmis |
|
| 182 | + $role = ($cond['role'] ?? ($tous_si_absent ? '*' : $role_defaut)); |
|
| 183 | + unset($cond['role']); // cette condition est particuliere... |
|
| 184 | 184 | |
| 185 | - if ($colonne_role) { |
|
| 186 | - // on ajoute la condition du role aux autres conditions. |
|
| 187 | - if ($role != '*') { |
|
| 188 | - $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | - } |
|
| 190 | - } |
|
| 185 | + if ($colonne_role) { |
|
| 186 | + // on ajoute la condition du role aux autres conditions. |
|
| 187 | + if ($role != '*') { |
|
| 188 | + $cond[] = "$colonne_role=" . sql_quote($role); |
|
| 189 | + } |
|
| 190 | + } |
|
| 191 | 191 | |
| 192 | - return [$cond, $colonne_role, $role]; |
|
| 192 | + return [$cond, $colonne_role, $role]; |
|
| 193 | 193 | } |
| 194 | 194 | |
| 195 | 195 | /** |
@@ -211,28 +211,28 @@ discard block |
||
| 211 | 211 | */ |
| 212 | 212 | function roles_complets($objet_source, $objet, $id_objet, $objet_lien) { |
| 213 | 213 | |
| 214 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | - if ($presents === false) { |
|
| 217 | - return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | - } |
|
| 219 | - |
|
| 220 | - // types de roles possibles |
|
| 221 | - $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | - // couples id / roles |
|
| 223 | - $ids = $presents['ids']; |
|
| 224 | - |
|
| 225 | - // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | - // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | - // n'est pas complet |
|
| 228 | - $complets = []; |
|
| 229 | - foreach ($ids as $id => $roles_presents) { |
|
| 230 | - if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | - $complets[] = $id; |
|
| 232 | - } |
|
| 233 | - } |
|
| 234 | - |
|
| 235 | - return $complets; |
|
| 214 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 215 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 216 | + if ($presents === false) { |
|
| 217 | + return lister_objets_lies($objet_source, $objet, $id_objet, $objet_lien); |
|
| 218 | + } |
|
| 219 | + |
|
| 220 | + // types de roles possibles |
|
| 221 | + $roles_possibles = $presents['roles']['roles']['choix']; |
|
| 222 | + // couples id / roles |
|
| 223 | + $ids = $presents['ids']; |
|
| 224 | + |
|
| 225 | + // pour chaque groupe, on fait le diff entre tous les roles possibles |
|
| 226 | + // et les roles attribués à l'élément : s'il en reste, c'est que l'élément |
|
| 227 | + // n'est pas complet |
|
| 228 | + $complets = []; |
|
| 229 | + foreach ($ids as $id => $roles_presents) { |
|
| 230 | + if (!array_diff($roles_possibles, $roles_presents)) { |
|
| 231 | + $complets[] = $id; |
|
| 232 | + } |
|
| 233 | + } |
|
| 234 | + |
|
| 235 | + return $complets; |
|
| 236 | 236 | } |
| 237 | 237 | |
| 238 | 238 | |
@@ -249,17 +249,17 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function roles_presents_sur_id($id_objet_source, $objet_source, $objet, $id_objet, $objet_lien) { |
| 251 | 251 | |
| 252 | - $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | - // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | - if ($presents === false) { |
|
| 255 | - return []; |
|
| 256 | - } |
|
| 252 | + $presents = roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien); |
|
| 253 | + // pas de roles sur ces objets => la liste par defaut, comme sans role |
|
| 254 | + if ($presents === false) { |
|
| 255 | + return []; |
|
| 256 | + } |
|
| 257 | 257 | |
| 258 | - if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | - return []; |
|
| 260 | - } |
|
| 258 | + if (!isset($presents['ids'][$id_objet_source])) { |
|
| 259 | + return []; |
|
| 260 | + } |
|
| 261 | 261 | |
| 262 | - return $presents['ids'][$id_objet_source]; |
|
| 262 | + return $presents['ids'][$id_objet_source]; |
|
| 263 | 263 | } |
| 264 | 264 | |
| 265 | 265 | |
@@ -287,47 +287,47 @@ discard block |
||
| 287 | 287 | * - False si pas de role déclarés |
| 288 | 288 | */ |
| 289 | 289 | function roles_presents_liaisons($objet_source, $objet, $id_objet, $objet_lien) { |
| 290 | - static $done = []; |
|
| 291 | - |
|
| 292 | - // stocker le résultat |
|
| 293 | - $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | - if (isset($done[$hash])) { |
|
| 295 | - return $done[$hash]; |
|
| 296 | - } |
|
| 297 | - |
|
| 298 | - // pas de roles sur ces objets, on sort |
|
| 299 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | - if (!$roles) { |
|
| 301 | - return $done[$hash] = false; |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - // inspiré de lister_objets_lies() |
|
| 305 | - if ($objet_lien == $objet) { |
|
| 306 | - $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | - } else { |
|
| 308 | - $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | - } |
|
| 310 | - |
|
| 311 | - // types de roles possibles |
|
| 312 | - $roles_possibles = $roles['roles']['choix']; |
|
| 313 | - // colonne du role |
|
| 314 | - $colonne = $roles['colonne']; |
|
| 315 | - |
|
| 316 | - // on recupere par id, et role existant |
|
| 317 | - $ids = []; |
|
| 318 | - while ($row = array_shift($res)) { |
|
| 319 | - $id = $row[$objet_source]; |
|
| 320 | - if (!isset($ids[$id])) { |
|
| 321 | - $ids[$id] = []; |
|
| 322 | - } |
|
| 323 | - // tableau des roles présents |
|
| 324 | - $ids[$id][] = $row[$colonne]; |
|
| 325 | - } |
|
| 326 | - |
|
| 327 | - return $done[$hash] = [ |
|
| 328 | - 'roles' => $roles, |
|
| 329 | - 'ids' => $ids |
|
| 330 | - ]; |
|
| 290 | + static $done = []; |
|
| 291 | + |
|
| 292 | + // stocker le résultat |
|
| 293 | + $hash = "$objet_source-$objet-$id_objet-$objet_lien"; |
|
| 294 | + if (isset($done[$hash])) { |
|
| 295 | + return $done[$hash]; |
|
| 296 | + } |
|
| 297 | + |
|
| 298 | + // pas de roles sur ces objets, on sort |
|
| 299 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 300 | + if (!$roles) { |
|
| 301 | + return $done[$hash] = false; |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + // inspiré de lister_objets_lies() |
|
| 305 | + if ($objet_lien == $objet) { |
|
| 306 | + $res = objet_trouver_liens([$objet => $id_objet], [$objet_source => '*']); |
|
| 307 | + } else { |
|
| 308 | + $res = objet_trouver_liens([$objet_source => '*'], [$objet => $id_objet]); |
|
| 309 | + } |
|
| 310 | + |
|
| 311 | + // types de roles possibles |
|
| 312 | + $roles_possibles = $roles['roles']['choix']; |
|
| 313 | + // colonne du role |
|
| 314 | + $colonne = $roles['colonne']; |
|
| 315 | + |
|
| 316 | + // on recupere par id, et role existant |
|
| 317 | + $ids = []; |
|
| 318 | + while ($row = array_shift($res)) { |
|
| 319 | + $id = $row[$objet_source]; |
|
| 320 | + if (!isset($ids[$id])) { |
|
| 321 | + $ids[$id] = []; |
|
| 322 | + } |
|
| 323 | + // tableau des roles présents |
|
| 324 | + $ids[$id][] = $row[$colonne]; |
|
| 325 | + } |
|
| 326 | + |
|
| 327 | + return $done[$hash] = [ |
|
| 328 | + 'roles' => $roles, |
|
| 329 | + 'ids' => $ids |
|
| 330 | + ]; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -345,33 +345,33 @@ discard block |
||
| 345 | 345 | * - false si pas de role déclarés |
| 346 | 346 | */ |
| 347 | 347 | function roles_connus_en_base($objet_source, $objet, $objet_lien) { |
| 348 | - static $done = []; |
|
| 349 | - |
|
| 350 | - // stocker le résultat |
|
| 351 | - $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | - if (isset($done[$hash])) { |
|
| 353 | - return $done[$hash]; |
|
| 354 | - } |
|
| 355 | - |
|
| 356 | - if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | - return $done[$hash] = false; |
|
| 358 | - } |
|
| 359 | - |
|
| 360 | - // pas de roles sur ces objets, on sort |
|
| 361 | - $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | - if (!$roles) { |
|
| 363 | - return $done[$hash] = false; |
|
| 364 | - } |
|
| 365 | - |
|
| 366 | - [$primary, $l] = $lien; |
|
| 367 | - $colone_role = $roles['colonne']; |
|
| 368 | - |
|
| 369 | - $all = sql_allfetsel( |
|
| 370 | - "DISTINCT $colone_role", |
|
| 371 | - $l, |
|
| 372 | - 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | - ); |
|
| 374 | - $done[$hash] = array_map('reset', $all); |
|
| 375 | - |
|
| 376 | - return $done[$hash]; |
|
| 348 | + static $done = []; |
|
| 349 | + |
|
| 350 | + // stocker le résultat |
|
| 351 | + $hash = "$objet_source-$objet-$objet_lien"; |
|
| 352 | + if (isset($done[$hash])) { |
|
| 353 | + return $done[$hash]; |
|
| 354 | + } |
|
| 355 | + |
|
| 356 | + if (!$lien = objet_associable($objet_lien)) { |
|
| 357 | + return $done[$hash] = false; |
|
| 358 | + } |
|
| 359 | + |
|
| 360 | + // pas de roles sur ces objets, on sort |
|
| 361 | + $roles = roles_presents($objet_lien, ($objet_lien == $objet) ? $objet_source : $objet); |
|
| 362 | + if (!$roles) { |
|
| 363 | + return $done[$hash] = false; |
|
| 364 | + } |
|
| 365 | + |
|
| 366 | + [$primary, $l] = $lien; |
|
| 367 | + $colone_role = $roles['colonne']; |
|
| 368 | + |
|
| 369 | + $all = sql_allfetsel( |
|
| 370 | + "DISTINCT $colone_role", |
|
| 371 | + $l, |
|
| 372 | + 'objet=' . sql_quote(($objet_source == $objet_lien) ? $objet : $objet_source) |
|
| 373 | + ); |
|
| 374 | + $done[$hash] = array_map('reset', $all); |
|
| 375 | + |
|
| 376 | + return $done[$hash]; |
|
| 377 | 377 | } |
@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - [$primary, $table_liens] = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - [$primary, $table_liens] = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_${table}_${table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_${table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_${table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + [$primary, $table_liens] = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + [$primary, $table_liens] = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |
@@ -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 | include_spip('inc/texte_mini'); |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return array Tablea ('','') |
| 35 | 35 | */ |
| 36 | 36 | function definir_raccourcis_alineas() { |
| 37 | - return ['', '']; |
|
| 37 | + return ['', '']; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | * @return string |
| 48 | 48 | */ |
| 49 | 49 | function traiter_tableau($bloc) { |
| 50 | - return $bloc; |
|
| 50 | + return $bloc; |
|
| 51 | 51 | } |
| 52 | 52 | |
| 53 | 53 | |
@@ -61,7 +61,7 @@ discard block |
||
| 61 | 61 | * @return string |
| 62 | 62 | */ |
| 63 | 63 | function traiter_listes($texte) { |
| 64 | - return $texte; |
|
| 64 | + return $texte; |
|
| 65 | 65 | } |
| 66 | 66 | |
| 67 | 67 | /** |
@@ -77,16 +77,16 @@ discard block |
||
| 77 | 77 | */ |
| 78 | 78 | function traiter_raccourcis($letexte) { |
| 79 | 79 | |
| 80 | - // Appeler les fonctions de pre_traitement |
|
| 81 | - $letexte = pipeline('pre_propre', $letexte); |
|
| 80 | + // Appeler les fonctions de pre_traitement |
|
| 81 | + $letexte = pipeline('pre_propre', $letexte); |
|
| 82 | 82 | |
| 83 | - // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | - // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 83 | + // APPELER ICI UN PIPELINE traiter_raccourcis ? |
|
| 84 | + // $letexte = pipeline('traiter_raccourcis', $letexte); |
|
| 85 | 85 | |
| 86 | - // Appeler les fonctions de post-traitement |
|
| 87 | - $letexte = pipeline('post_propre', $letexte); |
|
| 86 | + // Appeler les fonctions de post-traitement |
|
| 87 | + $letexte = pipeline('post_propre', $letexte); |
|
| 88 | 88 | |
| 89 | - return $letexte; |
|
| 89 | + return $letexte; |
|
| 90 | 90 | } |
| 91 | 91 | |
| 92 | 92 | /************************************************************************************************************************* |
@@ -102,22 +102,22 @@ discard block |
||
| 102 | 102 | * @return string |
| 103 | 103 | */ |
| 104 | 104 | function echappe_js($t, $class = ' class = "echappe-js"') { |
| 105 | - foreach (['script', 'iframe'] as $tag) { |
|
| 106 | - if ( |
|
| 107 | - stripos($t, (string) "<$tag") !== false |
|
| 108 | - and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | - ) { |
|
| 110 | - foreach ($r as $regs) { |
|
| 111 | - $t = str_replace( |
|
| 112 | - $regs[0], |
|
| 113 | - "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | - $t |
|
| 115 | - ); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - |
|
| 120 | - return $t; |
|
| 105 | + foreach (['script', 'iframe'] as $tag) { |
|
| 106 | + if ( |
|
| 107 | + stripos($t, (string) "<$tag") !== false |
|
| 108 | + and preg_match_all(',<' . $tag . '.*?($|</' . $tag . '.),isS', $t, $r, PREG_SET_ORDER) |
|
| 109 | + ) { |
|
| 110 | + foreach ($r as $regs) { |
|
| 111 | + $t = str_replace( |
|
| 112 | + $regs[0], |
|
| 113 | + "<code$class>" . nl2br(spip_htmlspecialchars($regs[0])) . '</code>', |
|
| 114 | + $t |
|
| 115 | + ); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + |
|
| 120 | + return $t; |
|
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | |
@@ -146,55 +146,55 @@ discard block |
||
| 146 | 146 | * Code protégé |
| 147 | 147 | **/ |
| 148 | 148 | function interdire_scripts($arg, $mode_filtre = null) { |
| 149 | - // on memorise le resultat sur les arguments non triviaux |
|
| 150 | - static $dejavu = []; |
|
| 151 | - |
|
| 152 | - // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | - if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | - return $arg; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | - $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | - return $dejavu[$mode_filtre][$arg]; |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // echapper les tags asp/php |
|
| 166 | - $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | - |
|
| 168 | - // echapper le php |
|
| 169 | - $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | - |
|
| 171 | - // echapper le < script language=php > |
|
| 172 | - $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | - |
|
| 174 | - // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | - switch ($mode_filtre) { |
|
| 176 | - case 0: |
|
| 177 | - if (!_DIR_RESTREINT) { |
|
| 178 | - $t = echappe_js($t); |
|
| 179 | - } |
|
| 180 | - break; |
|
| 181 | - case -1: |
|
| 182 | - $t = echappe_js($t); |
|
| 183 | - break; |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - // pas de <base href /> svp ! |
|
| 187 | - $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | - |
|
| 189 | - // Reinserer les echappements des modeles |
|
| 190 | - if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | - $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | - } |
|
| 193 | - if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | - $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | - } |
|
| 196 | - |
|
| 197 | - return $dejavu[$mode_filtre][$arg] = $t; |
|
| 149 | + // on memorise le resultat sur les arguments non triviaux |
|
| 150 | + static $dejavu = []; |
|
| 151 | + |
|
| 152 | + // Attention, si ce n'est pas une chaine, laisser intact |
|
| 153 | + if (!$arg or !is_string($arg) or !strstr($arg, '<')) { |
|
| 154 | + return $arg; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + if (is_null($mode_filtre) or !in_array($mode_filtre, [-1, 0, 1])) { |
|
| 158 | + $mode_filtre = $GLOBALS['filtrer_javascript']; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + if (isset($dejavu[$mode_filtre][$arg])) { |
|
| 162 | + return $dejavu[$mode_filtre][$arg]; |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // echapper les tags asp/php |
|
| 166 | + $t = str_replace('<' . '%', '<%', $arg); |
|
| 167 | + |
|
| 168 | + // echapper le php |
|
| 169 | + $t = str_replace('<' . '?', '<?', $t); |
|
| 170 | + |
|
| 171 | + // echapper le < script language=php > |
|
| 172 | + $t = preg_replace(',<(script\b[^>]+\blanguage\b[^\w>]+php\b),UimsS', '<\1', $t); |
|
| 173 | + |
|
| 174 | + // Pour le js, trois modes : parano (-1), prive (0), ok (1) |
|
| 175 | + switch ($mode_filtre) { |
|
| 176 | + case 0: |
|
| 177 | + if (!_DIR_RESTREINT) { |
|
| 178 | + $t = echappe_js($t); |
|
| 179 | + } |
|
| 180 | + break; |
|
| 181 | + case -1: |
|
| 182 | + $t = echappe_js($t); |
|
| 183 | + break; |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + // pas de <base href /> svp ! |
|
| 187 | + $t = preg_replace(',<(base\b),iS', '<\1', $t); |
|
| 188 | + |
|
| 189 | + // Reinserer les echappements des modeles |
|
| 190 | + if (defined('_PROTEGE_JS_MODELES')) { |
|
| 191 | + $t = echappe_retour($t, 'javascript' . _PROTEGE_JS_MODELES); |
|
| 192 | + } |
|
| 193 | + if (defined('_PROTEGE_PHP_MODELES')) { |
|
| 194 | + $t = echappe_retour($t, 'php' . _PROTEGE_PHP_MODELES); |
|
| 195 | + } |
|
| 196 | + |
|
| 197 | + return $dejavu[$mode_filtre][$arg] = $t; |
|
| 198 | 198 | } |
| 199 | 199 | |
| 200 | 200 | |
@@ -223,66 +223,66 @@ discard block |
||
| 223 | 223 | * Texte transformé |
| 224 | 224 | **/ |
| 225 | 225 | function typo($letexte, $echapper = true, $connect = null, $env = []) { |
| 226 | - // Plus vite ! |
|
| 227 | - if (!$letexte) { |
|
| 228 | - return $letexte; |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | - // prive etant historiquement ecrit sans argment $connect |
|
| 233 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | - // ou il faut passer interdire_script explicitement |
|
| 235 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | - // ne seront pas perturbes |
|
| 237 | - $interdire_script = false; |
|
| 238 | - if (is_null($connect)) { |
|
| 239 | - $connect = ''; |
|
| 240 | - $interdire_script = true; |
|
| 241 | - $env['espace_prive'] = test_espace_prive(); |
|
| 242 | - } |
|
| 243 | - |
|
| 244 | - // Echapper les codes <html> etc |
|
| 245 | - if ($echapper) { |
|
| 246 | - $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | - } |
|
| 248 | - |
|
| 249 | - // |
|
| 250 | - // Installer les modeles, notamment images et documents ; |
|
| 251 | - // |
|
| 252 | - // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | - // cf. inc/lien |
|
| 254 | - |
|
| 255 | - $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | - if ($letexte != $mem) { |
|
| 257 | - $echapper = true; |
|
| 258 | - } |
|
| 259 | - unset($mem); |
|
| 260 | - |
|
| 261 | - $letexte = corriger_typo($letexte); |
|
| 262 | - $letexte = echapper_faux_tags($letexte); |
|
| 263 | - |
|
| 264 | - // reintegrer les echappements |
|
| 265 | - if ($echapper) { |
|
| 266 | - $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | - } |
|
| 268 | - |
|
| 269 | - // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | - if ($interdire_script) { |
|
| 271 | - $letexte = interdire_scripts($letexte); |
|
| 272 | - } |
|
| 273 | - |
|
| 274 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | - // https://core.spip.net/issues/3371 |
|
| 276 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | - // https://core.spip.net/issues/4166 |
|
| 278 | - if ( |
|
| 279 | - $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | - ) { |
|
| 282 | - $letexte = echapper_html_suspect($letexte); |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - return $letexte; |
|
| 226 | + // Plus vite ! |
|
| 227 | + if (!$letexte) { |
|
| 228 | + return $letexte; |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 232 | + // prive etant historiquement ecrit sans argment $connect |
|
| 233 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 234 | + // ou il faut passer interdire_script explicitement |
|
| 235 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 236 | + // ne seront pas perturbes |
|
| 237 | + $interdire_script = false; |
|
| 238 | + if (is_null($connect)) { |
|
| 239 | + $connect = ''; |
|
| 240 | + $interdire_script = true; |
|
| 241 | + $env['espace_prive'] = test_espace_prive(); |
|
| 242 | + } |
|
| 243 | + |
|
| 244 | + // Echapper les codes <html> etc |
|
| 245 | + if ($echapper) { |
|
| 246 | + $letexte = echappe_html($letexte, 'TYPO'); |
|
| 247 | + } |
|
| 248 | + |
|
| 249 | + // |
|
| 250 | + // Installer les modeles, notamment images et documents ; |
|
| 251 | + // |
|
| 252 | + // NOTE : propre() ne passe pas par ici mais directement par corriger_typo |
|
| 253 | + // cf. inc/lien |
|
| 254 | + |
|
| 255 | + $letexte = traiter_modeles($mem = $letexte, false, $echapper ? 'TYPO' : '', $connect, null, $env); |
|
| 256 | + if ($letexte != $mem) { |
|
| 257 | + $echapper = true; |
|
| 258 | + } |
|
| 259 | + unset($mem); |
|
| 260 | + |
|
| 261 | + $letexte = corriger_typo($letexte); |
|
| 262 | + $letexte = echapper_faux_tags($letexte); |
|
| 263 | + |
|
| 264 | + // reintegrer les echappements |
|
| 265 | + if ($echapper) { |
|
| 266 | + $letexte = echappe_retour($letexte, 'TYPO'); |
|
| 267 | + } |
|
| 268 | + |
|
| 269 | + // Dans les appels directs hors squelette, securiser ici aussi |
|
| 270 | + if ($interdire_script) { |
|
| 271 | + $letexte = interdire_scripts($letexte); |
|
| 272 | + } |
|
| 273 | + |
|
| 274 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 275 | + // https://core.spip.net/issues/3371 |
|
| 276 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 277 | + // https://core.spip.net/issues/4166 |
|
| 278 | + if ( |
|
| 279 | + $GLOBALS['filtrer_javascript'] == -1 |
|
| 280 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 281 | + ) { |
|
| 282 | + $letexte = echapper_html_suspect($letexte); |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + return $letexte; |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | // Correcteur typographique |
@@ -307,57 +307,57 @@ discard block |
||
| 307 | 307 | */ |
| 308 | 308 | function corriger_typo($letexte, $lang = '') { |
| 309 | 309 | |
| 310 | - // Plus vite ! |
|
| 311 | - if (!$letexte) { |
|
| 312 | - return $letexte; |
|
| 313 | - } |
|
| 314 | - |
|
| 315 | - $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | - |
|
| 317 | - // Caracteres de controle "illegaux" |
|
| 318 | - $letexte = corriger_caracteres($letexte); |
|
| 319 | - |
|
| 320 | - // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | - if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | - foreach ($regs as $reg) { |
|
| 323 | - $insert = $reg[0]; |
|
| 324 | - // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | - // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | - $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | - $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | - } |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - // trouver les blocs idiomes et les traiter à part |
|
| 332 | - $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | - $ei = ($ei !== $letexte); |
|
| 334 | - |
|
| 335 | - // trouver les blocs multi et les traiter a part |
|
| 336 | - $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | - $em = ($em !== $letexte); |
|
| 338 | - |
|
| 339 | - // Charger & appliquer les fonctions de typographie |
|
| 340 | - $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | - $letexte = $typographie($letexte); |
|
| 342 | - |
|
| 343 | - // Les citations en une autre langue, s'il y a lieu |
|
| 344 | - if ($em) { |
|
| 345 | - $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | - } |
|
| 347 | - if ($ei) { |
|
| 348 | - $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | - } |
|
| 350 | - |
|
| 351 | - // Retablir les caracteres proteges |
|
| 352 | - $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | - |
|
| 354 | - // pipeline |
|
| 355 | - $letexte = pipeline('post_typo', $letexte); |
|
| 356 | - |
|
| 357 | - # un message pour abs_url - on est passe en mode texte |
|
| 358 | - $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | - |
|
| 360 | - return $letexte; |
|
| 310 | + // Plus vite ! |
|
| 311 | + if (!$letexte) { |
|
| 312 | + return $letexte; |
|
| 313 | + } |
|
| 314 | + |
|
| 315 | + $letexte = pipeline('pre_typo', $letexte); |
|
| 316 | + |
|
| 317 | + // Caracteres de controle "illegaux" |
|
| 318 | + $letexte = corriger_caracteres($letexte); |
|
| 319 | + |
|
| 320 | + // Proteger les caracteres typographiques a l'interieur des tags html |
|
| 321 | + if (preg_match_all(_TYPO_BALISE, $letexte, $regs, PREG_SET_ORDER)) { |
|
| 322 | + foreach ($regs as $reg) { |
|
| 323 | + $insert = $reg[0]; |
|
| 324 | + // hack: on transforme les caracteres a proteger en les remplacant |
|
| 325 | + // par des caracteres "illegaux". (cf corriger_caracteres()) |
|
| 326 | + $insert = strtr($insert, _TYPO_PROTEGER, _TYPO_PROTECTEUR); |
|
| 327 | + $letexte = str_replace($reg[0], $insert, $letexte); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + // trouver les blocs idiomes et les traiter à part |
|
| 332 | + $letexte = extraire_idiome($ei = $letexte, $lang, true); |
|
| 333 | + $ei = ($ei !== $letexte); |
|
| 334 | + |
|
| 335 | + // trouver les blocs multi et les traiter a part |
|
| 336 | + $letexte = extraire_multi($em = $letexte, $lang, true); |
|
| 337 | + $em = ($em !== $letexte); |
|
| 338 | + |
|
| 339 | + // Charger & appliquer les fonctions de typographie |
|
| 340 | + $typographie = charger_fonction(lang_typo($lang), 'typographie'); |
|
| 341 | + $letexte = $typographie($letexte); |
|
| 342 | + |
|
| 343 | + // Les citations en une autre langue, s'il y a lieu |
|
| 344 | + if ($em) { |
|
| 345 | + $letexte = echappe_retour($letexte, 'multi'); |
|
| 346 | + } |
|
| 347 | + if ($ei) { |
|
| 348 | + $letexte = echappe_retour($letexte, 'idiome'); |
|
| 349 | + } |
|
| 350 | + |
|
| 351 | + // Retablir les caracteres proteges |
|
| 352 | + $letexte = strtr($letexte, _TYPO_PROTECTEUR, _TYPO_PROTEGER); |
|
| 353 | + |
|
| 354 | + // pipeline |
|
| 355 | + $letexte = pipeline('post_typo', $letexte); |
|
| 356 | + |
|
| 357 | + # un message pour abs_url - on est passe en mode texte |
|
| 358 | + $GLOBALS['mode_abs_url'] = 'texte'; |
|
| 359 | + |
|
| 360 | + return $letexte; |
|
| 361 | 361 | } |
| 362 | 362 | |
| 363 | 363 | |
@@ -373,7 +373,7 @@ discard block |
||
| 373 | 373 | * @return string |
| 374 | 374 | */ |
| 375 | 375 | function paragrapher($letexte, $forcer = true) { |
| 376 | - return $letexte; |
|
| 376 | + return $letexte; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -385,11 +385,11 @@ discard block |
||
| 385 | 385 | * @return string Texte |
| 386 | 386 | **/ |
| 387 | 387 | function traiter_retours_chariots($letexte) { |
| 388 | - $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | - $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | - $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 388 | + $letexte = preg_replace(",\r\n?,S", "\n", $letexte); |
|
| 389 | + $letexte = preg_replace(',<p[>[:space:]],iS', "\n\n\\0", $letexte); |
|
| 390 | + $letexte = preg_replace(',</p[>[:space:]],iS', "\\0\n\n", $letexte); |
|
| 391 | 391 | |
| 392 | - return $letexte; |
|
| 392 | + return $letexte; |
|
| 393 | 393 | } |
| 394 | 394 | |
| 395 | 395 | |
@@ -415,39 +415,39 @@ discard block |
||
| 415 | 415 | * Texte transformé |
| 416 | 416 | **/ |
| 417 | 417 | function propre($t, $connect = null, $env = []) { |
| 418 | - // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | - // prive etant historiquement ecrits sans argment $connect |
|
| 420 | - // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | - // ou il faut passer interdire_script explicitement |
|
| 422 | - // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | - // ne seront pas perturbes |
|
| 424 | - $interdire_script = false; |
|
| 425 | - if (is_null($connect)) { |
|
| 426 | - $connect = ''; |
|
| 427 | - $interdire_script = true; |
|
| 428 | - } |
|
| 429 | - |
|
| 430 | - if (!$t) { |
|
| 431 | - return strval($t); |
|
| 432 | - } |
|
| 433 | - |
|
| 434 | - // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | - // avant echappement des balises <html> |
|
| 436 | - // https://core.spip.net/issues/3371 |
|
| 437 | - // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | - // https://core.spip.net/issues/4166 |
|
| 439 | - if ( |
|
| 440 | - $interdire_script |
|
| 441 | - or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | - or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | - or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | - ) { |
|
| 445 | - $t = echapper_html_suspect($t, false); |
|
| 446 | - } |
|
| 447 | - $t = echappe_html($t); |
|
| 448 | - $t = expanser_liens($t, $connect, $env); |
|
| 449 | - $t = traiter_raccourcis($t); |
|
| 450 | - $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | - |
|
| 452 | - return $t; |
|
| 418 | + // les appels directs a cette fonction depuis le php de l'espace |
|
| 419 | + // prive etant historiquement ecrits sans argment $connect |
|
| 420 | + // on utilise la presence de celui-ci pour distinguer les cas |
|
| 421 | + // ou il faut passer interdire_script explicitement |
|
| 422 | + // les appels dans les squelettes (de l'espace prive) fournissant un $connect |
|
| 423 | + // ne seront pas perturbes |
|
| 424 | + $interdire_script = false; |
|
| 425 | + if (is_null($connect)) { |
|
| 426 | + $connect = ''; |
|
| 427 | + $interdire_script = true; |
|
| 428 | + } |
|
| 429 | + |
|
| 430 | + if (!$t) { |
|
| 431 | + return strval($t); |
|
| 432 | + } |
|
| 433 | + |
|
| 434 | + // Dans l'espace prive on se mefie de tout contenu dangereux |
|
| 435 | + // avant echappement des balises <html> |
|
| 436 | + // https://core.spip.net/issues/3371 |
|
| 437 | + // et aussi dans l'espace public si la globale filtrer_javascript = -1 |
|
| 438 | + // https://core.spip.net/issues/4166 |
|
| 439 | + if ( |
|
| 440 | + $interdire_script |
|
| 441 | + or $GLOBALS['filtrer_javascript'] == -1 |
|
| 442 | + or (isset($env['espace_prive']) and $env['espace_prive'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 443 | + or (isset($env['wysiwyg']) and $env['wysiwyg'] and $GLOBALS['filtrer_javascript'] <= 0) |
|
| 444 | + ) { |
|
| 445 | + $t = echapper_html_suspect($t, false); |
|
| 446 | + } |
|
| 447 | + $t = echappe_html($t); |
|
| 448 | + $t = expanser_liens($t, $connect, $env); |
|
| 449 | + $t = traiter_raccourcis($t); |
|
| 450 | + $t = echappe_retour_modeles($t, $interdire_script); |
|
| 451 | + |
|
| 452 | + return $t; |
|
| 453 | 453 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | if (!defined('_TEST_FILE_EXISTS')) { |
| 24 | - /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | - define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 24 | + /** Permettre d'éviter des tests file_exists sur certains hébergeurs */ |
|
| 25 | + define('_TEST_FILE_EXISTS', preg_match(',(online|free)[.]fr$,', $_ENV['HTTP_HOST'] ?? '')); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | #define('_SPIP_LOCK_MODE',0); // ne pas utiliser de lock (deconseille) |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | #define('_SPIP_LOCK_MODE',2); // utiliser le nfslock de spip |
| 31 | 31 | |
| 32 | 32 | if (_SPIP_LOCK_MODE == 2) { |
| 33 | - include_spip('inc/nfslock'); |
|
| 33 | + include_spip('inc/nfslock'); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | $GLOBALS['liste_verrous'] = []; |
@@ -53,24 +53,24 @@ discard block |
||
| 53 | 53 | * Ressource sur le fichier ouvert, sinon false. |
| 54 | 54 | **/ |
| 55 | 55 | function spip_fopen_lock($fichier, $mode, $verrou) { |
| 56 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | - if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | - // verrou |
|
| 59 | - @flock($fl, $verrou); |
|
| 60 | - } |
|
| 61 | - |
|
| 62 | - return $fl; |
|
| 63 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | - if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | - $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | - |
|
| 67 | - return $fl; |
|
| 68 | - } else { |
|
| 69 | - return false; |
|
| 70 | - } |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - return @fopen($fichier, $mode); |
|
| 56 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 57 | + if ($fl = @fopen($fichier, $mode)) { |
|
| 58 | + // verrou |
|
| 59 | + @flock($fl, $verrou); |
|
| 60 | + } |
|
| 61 | + |
|
| 62 | + return $fl; |
|
| 63 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 64 | + if (($verrou = spip_nfslock($fichier)) && ($fl = @fopen($fichier, $mode))) { |
|
| 65 | + $GLOBALS['liste_verrous'][$fl] = [$fichier, $verrou]; |
|
| 66 | + |
|
| 67 | + return $fl; |
|
| 68 | + } else { |
|
| 69 | + return false; |
|
| 70 | + } |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + return @fopen($fichier, $mode); |
|
| 74 | 74 | } |
| 75 | 75 | |
| 76 | 76 | /** |
@@ -85,14 +85,14 @@ discard block |
||
| 85 | 85 | * true si succès, false sinon. |
| 86 | 86 | **/ |
| 87 | 87 | function spip_fclose_unlock($handle) { |
| 88 | - if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | - @flock($handle, LOCK_UN); |
|
| 90 | - } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | - spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | - unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return @fclose($handle); |
|
| 88 | + if (_SPIP_LOCK_MODE == 1) { |
|
| 89 | + @flock($handle, LOCK_UN); |
|
| 90 | + } elseif (_SPIP_LOCK_MODE == 2) { |
|
| 91 | + spip_nfsunlock(reset($GLOBALS['liste_verrous'][$handle]), end($GLOBALS['liste_verrous'][$handle])); |
|
| 92 | + unset($GLOBALS['liste_verrous'][$handle]); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return @fclose($handle); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | |
@@ -106,23 +106,23 @@ discard block |
||
| 106 | 106 | * Contenu du fichier |
| 107 | 107 | **/ |
| 108 | 108 | function spip_file_get_contents($fichier) { |
| 109 | - if (substr($fichier, -3) != '.gz') { |
|
| 110 | - if (function_exists('file_get_contents')) { |
|
| 111 | - // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | - // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | - // sinon on fait un file() pour avoir le coeur net |
|
| 114 | - $contenu = @file_get_contents($fichier); |
|
| 115 | - if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | - $contenu = @file($fichier); |
|
| 117 | - } |
|
| 118 | - } else { |
|
| 119 | - $contenu = @file($fichier); |
|
| 120 | - } |
|
| 121 | - } else { |
|
| 122 | - $contenu = @gzfile($fichier); |
|
| 123 | - } |
|
| 124 | - |
|
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 109 | + if (substr($fichier, -3) != '.gz') { |
|
| 110 | + if (function_exists('file_get_contents')) { |
|
| 111 | + // quand on est sous windows on ne sait pas si file_get_contents marche |
|
| 112 | + // on essaye : si ca retourne du contenu alors c'est bon |
|
| 113 | + // sinon on fait un file() pour avoir le coeur net |
|
| 114 | + $contenu = @file_get_contents($fichier); |
|
| 115 | + if (!$contenu and _OS_SERVEUR == 'windows') { |
|
| 116 | + $contenu = @file($fichier); |
|
| 117 | + } |
|
| 118 | + } else { |
|
| 119 | + $contenu = @file($fichier); |
|
| 120 | + } |
|
| 121 | + } else { |
|
| 122 | + $contenu = @gzfile($fichier); |
|
| 123 | + } |
|
| 124 | + |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -147,48 +147,48 @@ discard block |
||
| 147 | 147 | * true si l'opération a réussie, false sinon. |
| 148 | 148 | **/ |
| 149 | 149 | function lire_fichier($fichier, &$contenu, $options = []) { |
| 150 | - $contenu = ''; |
|
| 151 | - // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | - // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | - if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | - return false; |
|
| 155 | - } |
|
| 156 | - |
|
| 157 | - #spip_timer('lire_fichier'); |
|
| 158 | - |
|
| 159 | - // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | - if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | - // lire le fichier avant tout |
|
| 162 | - $contenu = spip_file_get_contents($fichier); |
|
| 163 | - |
|
| 164 | - // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | - // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | - // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | - // et eviter un acces disque |
|
| 168 | - if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | - spip_fclose_unlock($fl); |
|
| 170 | - |
|
| 171 | - return false; |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - // liberer le verrou |
|
| 175 | - spip_fclose_unlock($fl); |
|
| 176 | - |
|
| 177 | - // Verifications |
|
| 178 | - $ok = true; |
|
| 179 | - if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | - $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | - } |
|
| 182 | - |
|
| 183 | - #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | - if (!$ok) { |
|
| 185 | - spip_log("echec lecture $fichier"); |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $ok; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return false; |
|
| 150 | + $contenu = ''; |
|
| 151 | + // inutile car si le fichier n'existe pas, le lock va renvoyer false juste apres |
|
| 152 | + // economisons donc les acces disque, sauf chez free qui rale pour un rien |
|
| 153 | + if (_TEST_FILE_EXISTS and !@file_exists($fichier)) { |
|
| 154 | + return false; |
|
| 155 | + } |
|
| 156 | + |
|
| 157 | + #spip_timer('lire_fichier'); |
|
| 158 | + |
|
| 159 | + // pas de @ sur spip_fopen_lock qui est silencieux de toute facon |
|
| 160 | + if ($fl = spip_fopen_lock($fichier, 'r', LOCK_SH)) { |
|
| 161 | + // lire le fichier avant tout |
|
| 162 | + $contenu = spip_file_get_contents($fichier); |
|
| 163 | + |
|
| 164 | + // le fichier a-t-il ete supprime par le locker ? |
|
| 165 | + // on ne verifie que si la tentative de lecture a echoue |
|
| 166 | + // pour discriminer un contenu vide d'un fichier absent |
|
| 167 | + // et eviter un acces disque |
|
| 168 | + if (!$contenu and !@file_exists($fichier)) { |
|
| 169 | + spip_fclose_unlock($fl); |
|
| 170 | + |
|
| 171 | + return false; |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + // liberer le verrou |
|
| 175 | + spip_fclose_unlock($fl); |
|
| 176 | + |
|
| 177 | + // Verifications |
|
| 178 | + $ok = true; |
|
| 179 | + if (isset($options['phpcheck']) and $options['phpcheck'] == 'oui') { |
|
| 180 | + $ok &= (preg_match(",[?]>\n?$,", $contenu)); |
|
| 181 | + } |
|
| 182 | + |
|
| 183 | + #spip_log("$fread $fichier ".spip_timer('lire_fichier')); |
|
| 184 | + if (!$ok) { |
|
| 185 | + spip_log("echec lecture $fichier"); |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $ok; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return false; |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | |
@@ -216,85 +216,85 @@ discard block |
||
| 216 | 216 | **/ |
| 217 | 217 | function ecrire_fichier($fichier, $contenu, $ignorer_echec = false, $truncate = true) { |
| 218 | 218 | |
| 219 | - #spip_timer('ecrire_fichier'); |
|
| 220 | - |
|
| 221 | - // verrouiller le fichier destination |
|
| 222 | - if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | - // ecrire les donnees, compressees le cas echeant |
|
| 224 | - // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | - // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | - if (substr($fichier, -3) == '.gz') { |
|
| 227 | - $contenu = gzencode($contenu); |
|
| 228 | - } |
|
| 229 | - // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | - // pour etre sur d'avoir une operation atomique |
|
| 231 | - // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | - // sauf sous wintruc ou ca ne marche pas |
|
| 233 | - $ok = false; |
|
| 234 | - if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | - if (!function_exists('creer_uniqid')) { |
|
| 236 | - include_spip('inc/acces'); |
|
| 237 | - } |
|
| 238 | - $id = creer_uniqid(); |
|
| 239 | - // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | - if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | - $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | - $ok = ($s == $a); |
|
| 243 | - spip_fclose_unlock($fp2); |
|
| 244 | - spip_fclose_unlock($fp); |
|
| 245 | - // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | - // a priori pas besoin car rename ecrase la cible |
|
| 247 | - // @unlink($fichier); |
|
| 248 | - // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | - // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | - // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | - @rename("$fichier.$id", $fichier); |
|
| 252 | - // precaution en cas d'echec du rename |
|
| 253 | - if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | - @unlink("$fichier.$id"); |
|
| 255 | - } |
|
| 256 | - if ($ok) { |
|
| 257 | - $ok = file_exists($fichier); |
|
| 258 | - } |
|
| 259 | - } else // echec mais penser a fermer .. |
|
| 260 | - { |
|
| 261 | - spip_fclose_unlock($fp); |
|
| 262 | - } |
|
| 263 | - } |
|
| 264 | - // sinon ou si methode precedente a echoueee |
|
| 265 | - // on se rabat sur la methode ancienne |
|
| 266 | - if (!$ok) { |
|
| 267 | - // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | - if ($truncate) { |
|
| 269 | - @ftruncate($fp, 0); |
|
| 270 | - } |
|
| 271 | - $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | - |
|
| 273 | - $ok = ($s == $a); |
|
| 274 | - spip_fclose_unlock($fp); |
|
| 275 | - } |
|
| 276 | - |
|
| 277 | - // liberer le verrou et fermer le fichier |
|
| 278 | - @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | - if ($ok) { |
|
| 280 | - if (strpos($fichier, '.php') !== false) { |
|
| 281 | - spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | - } |
|
| 283 | - |
|
| 284 | - return $ok; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - |
|
| 288 | - if (!$ignorer_echec) { |
|
| 289 | - include_spip('inc/autoriser'); |
|
| 290 | - if (autoriser('chargerftp')) { |
|
| 291 | - raler_fichier($fichier); |
|
| 292 | - } |
|
| 293 | - spip_unlink($fichier); |
|
| 294 | - } |
|
| 295 | - spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | - |
|
| 297 | - return false; |
|
| 219 | + #spip_timer('ecrire_fichier'); |
|
| 220 | + |
|
| 221 | + // verrouiller le fichier destination |
|
| 222 | + if ($fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 223 | + // ecrire les donnees, compressees le cas echeant |
|
| 224 | + // (on ouvre un nouveau pointeur sur le fichier, ce qui a l'avantage |
|
| 225 | + // de le recreer si le locker qui nous precede l'avait supprime...) |
|
| 226 | + if (substr($fichier, -3) == '.gz') { |
|
| 227 | + $contenu = gzencode($contenu); |
|
| 228 | + } |
|
| 229 | + // si c'est une ecriture avec troncation , on fait plutot une ecriture complete a cote suivie unlink+rename |
|
| 230 | + // pour etre sur d'avoir une operation atomique |
|
| 231 | + // y compris en NFS : http://www.ietf.org/rfc/rfc1094.txt |
|
| 232 | + // sauf sous wintruc ou ca ne marche pas |
|
| 233 | + $ok = false; |
|
| 234 | + if ($truncate and _OS_SERVEUR != 'windows') { |
|
| 235 | + if (!function_exists('creer_uniqid')) { |
|
| 236 | + include_spip('inc/acces'); |
|
| 237 | + } |
|
| 238 | + $id = creer_uniqid(); |
|
| 239 | + // on ouvre un pointeur sur un fichier temporaire en ecriture +raz |
|
| 240 | + if ($fp2 = spip_fopen_lock("$fichier.$id", 'w', LOCK_EX)) { |
|
| 241 | + $s = @fputs($fp2, $contenu, $a = strlen($contenu)); |
|
| 242 | + $ok = ($s == $a); |
|
| 243 | + spip_fclose_unlock($fp2); |
|
| 244 | + spip_fclose_unlock($fp); |
|
| 245 | + // unlink direct et pas spip_unlink car on avait deja le verrou |
|
| 246 | + // a priori pas besoin car rename ecrase la cible |
|
| 247 | + // @unlink($fichier); |
|
| 248 | + // le rename aussitot, atomique quand on est pas sous windows |
|
| 249 | + // au pire on arrive en second en cas de concourance, et le rename echoue |
|
| 250 | + // --> on a la version de l'autre process qui doit etre identique |
|
| 251 | + @rename("$fichier.$id", $fichier); |
|
| 252 | + // precaution en cas d'echec du rename |
|
| 253 | + if (!_TEST_FILE_EXISTS or @file_exists("$fichier.$id")) { |
|
| 254 | + @unlink("$fichier.$id"); |
|
| 255 | + } |
|
| 256 | + if ($ok) { |
|
| 257 | + $ok = file_exists($fichier); |
|
| 258 | + } |
|
| 259 | + } else // echec mais penser a fermer .. |
|
| 260 | + { |
|
| 261 | + spip_fclose_unlock($fp); |
|
| 262 | + } |
|
| 263 | + } |
|
| 264 | + // sinon ou si methode precedente a echoueee |
|
| 265 | + // on se rabat sur la methode ancienne |
|
| 266 | + if (!$ok) { |
|
| 267 | + // ici on est en ajout ou sous windows, cas desespere |
|
| 268 | + if ($truncate) { |
|
| 269 | + @ftruncate($fp, 0); |
|
| 270 | + } |
|
| 271 | + $s = @fputs($fp, $contenu, $a = strlen($contenu)); |
|
| 272 | + |
|
| 273 | + $ok = ($s == $a); |
|
| 274 | + spip_fclose_unlock($fp); |
|
| 275 | + } |
|
| 276 | + |
|
| 277 | + // liberer le verrou et fermer le fichier |
|
| 278 | + @chmod($fichier, _SPIP_CHMOD & 0666); |
|
| 279 | + if ($ok) { |
|
| 280 | + if (strpos($fichier, '.php') !== false) { |
|
| 281 | + spip_clear_opcode_cache(realpath($fichier)); |
|
| 282 | + } |
|
| 283 | + |
|
| 284 | + return $ok; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + |
|
| 288 | + if (!$ignorer_echec) { |
|
| 289 | + include_spip('inc/autoriser'); |
|
| 290 | + if (autoriser('chargerftp')) { |
|
| 291 | + raler_fichier($fichier); |
|
| 292 | + } |
|
| 293 | + spip_unlink($fichier); |
|
| 294 | + } |
|
| 295 | + spip_log("Ecriture fichier $fichier impossible", _LOG_INFO_IMPORTANTE); |
|
| 296 | + |
|
| 297 | + return false; |
|
| 298 | 298 | } |
| 299 | 299 | |
| 300 | 300 | /** |
@@ -314,12 +314,12 @@ discard block |
||
| 314 | 314 | * Écriture avec troncation ? |
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | - if (substr($fichier, -4) !== '.php') { |
|
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | - } |
|
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 317 | + if (substr($fichier, -4) !== '.php') { |
|
| 318 | + spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 319 | + } |
|
| 320 | + $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 321 | 321 | |
| 322 | - return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 322 | + return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
|
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | |
@@ -330,25 +330,25 @@ discard block |
||
| 330 | 330 | * @return bool |
| 331 | 331 | */ |
| 332 | 332 | function ecrire_fichier_calcule_si_modifie($fichier, $contenu, $force = false, $use_copy = false) { |
| 333 | - $fichier_tmp = $fichier . '.last'; |
|
| 334 | - if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | - return false; |
|
| 336 | - } |
|
| 337 | - if ( |
|
| 338 | - $force |
|
| 339 | - or !file_exists($fichier) |
|
| 340 | - or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | - ) { |
|
| 342 | - if ($use_copy) { |
|
| 343 | - @copy($fichier_tmp, $fichier); |
|
| 344 | - } |
|
| 345 | - else { |
|
| 346 | - @rename($fichier_tmp, $fichier); |
|
| 347 | - } |
|
| 348 | - // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | - clearstatcache(true, $fichier); |
|
| 350 | - } |
|
| 351 | - return true; |
|
| 333 | + $fichier_tmp = $fichier . '.last'; |
|
| 334 | + if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
|
| 335 | + return false; |
|
| 336 | + } |
|
| 337 | + if ( |
|
| 338 | + $force |
|
| 339 | + or !file_exists($fichier) |
|
| 340 | + or md5_file($fichier) != md5_file($fichier_tmp) |
|
| 341 | + ) { |
|
| 342 | + if ($use_copy) { |
|
| 343 | + @copy($fichier_tmp, $fichier); |
|
| 344 | + } |
|
| 345 | + else { |
|
| 346 | + @rename($fichier_tmp, $fichier); |
|
| 347 | + } |
|
| 348 | + // eviter que PHP ne reserve le vieux timestamp |
|
| 349 | + clearstatcache(true, $fichier); |
|
| 350 | + } |
|
| 351 | + return true; |
|
| 352 | 352 | } |
| 353 | 353 | |
| 354 | 354 | |
@@ -369,11 +369,11 @@ discard block |
||
| 369 | 369 | * true si l'opération a réussie, false sinon. |
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | - if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | - } |
|
| 372 | + if ($res = lire_fichier($fichier, $contenu, $options)) { |
|
| 373 | + $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 374 | + } |
|
| 375 | 375 | |
| 376 | - return $res; |
|
| 376 | + return $res; |
|
| 377 | 377 | } |
| 378 | 378 | |
| 379 | 379 | /** |
@@ -388,25 +388,25 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | - spip_initialisation_suite(); |
|
| 393 | - } |
|
| 394 | - include_spip('inc/minipres'); |
|
| 395 | - $dir = dirname($fichier); |
|
| 396 | - http_response_code(401); |
|
| 397 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | - . " <a href='" |
|
| 400 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | - . "'>" |
|
| 402 | - . _T('texte_inc_meta_2') |
|
| 403 | - . '</a> ' |
|
| 404 | - . _T( |
|
| 405 | - 'texte_inc_meta_3', |
|
| 406 | - ['repertoire' => joli_repertoire($dir)] |
|
| 407 | - ) |
|
| 408 | - . "</h4>\n"); |
|
| 409 | - exit; |
|
| 391 | + if (!defined('_SPIP_ECRIRE_SCRIPT')) { |
|
| 392 | + spip_initialisation_suite(); |
|
| 393 | + } |
|
| 394 | + include_spip('inc/minipres'); |
|
| 395 | + $dir = dirname($fichier); |
|
| 396 | + http_response_code(401); |
|
| 397 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 398 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 399 | + . " <a href='" |
|
| 400 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 401 | + . "'>" |
|
| 402 | + . _T('texte_inc_meta_2') |
|
| 403 | + . '</a> ' |
|
| 404 | + . _T( |
|
| 405 | + 'texte_inc_meta_3', |
|
| 406 | + ['repertoire' => joli_repertoire($dir)] |
|
| 407 | + ) |
|
| 408 | + . "</h4>\n"); |
|
| 409 | + exit; |
|
| 410 | 410 | } |
| 411 | 411 | |
| 412 | 412 | |
@@ -421,14 +421,14 @@ discard block |
||
| 421 | 421 | * - true si récent, false sinon |
| 422 | 422 | */ |
| 423 | 423 | function jeune_fichier($fichier, $n) { |
| 424 | - if (!file_exists($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - if (!$c = @filemtime($fichier)) { |
|
| 428 | - return false; |
|
| 429 | - } |
|
| 430 | - |
|
| 431 | - return (time() - $n <= $c); |
|
| 424 | + if (!file_exists($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + if (!$c = @filemtime($fichier)) { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 430 | + |
|
| 431 | + return (time() - $n <= $c); |
|
| 432 | 432 | } |
| 433 | 433 | |
| 434 | 434 | /** |
@@ -443,22 +443,22 @@ discard block |
||
| 443 | 443 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 444 | 444 | */ |
| 445 | 445 | function supprimer_fichier($fichier, $lock = true) { |
| 446 | - if (!@file_exists($fichier)) { |
|
| 447 | - return true; |
|
| 448 | - } |
|
| 449 | - |
|
| 450 | - if ($lock) { |
|
| 451 | - // verrouiller le fichier destination |
|
| 452 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | - return false; |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - // liberer le verrou |
|
| 457 | - spip_fclose_unlock($fp); |
|
| 458 | - } |
|
| 459 | - |
|
| 460 | - // supprimer |
|
| 461 | - return @unlink($fichier); |
|
| 446 | + if (!@file_exists($fichier)) { |
|
| 447 | + return true; |
|
| 448 | + } |
|
| 449 | + |
|
| 450 | + if ($lock) { |
|
| 451 | + // verrouiller le fichier destination |
|
| 452 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 453 | + return false; |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + // liberer le verrou |
|
| 457 | + spip_fclose_unlock($fp); |
|
| 458 | + } |
|
| 459 | + |
|
| 460 | + // supprimer |
|
| 461 | + return @unlink($fichier); |
|
| 462 | 462 | } |
| 463 | 463 | |
| 464 | 464 | /** |
@@ -468,12 +468,12 @@ discard block |
||
| 468 | 468 | * Chemin du fichier |
| 469 | 469 | */ |
| 470 | 470 | function spip_unlink($f) { |
| 471 | - if (!is_dir($f)) { |
|
| 472 | - supprimer_fichier($f, false); |
|
| 473 | - } else { |
|
| 474 | - @unlink("$f/.ok"); |
|
| 475 | - @rmdir($f); |
|
| 476 | - } |
|
| 471 | + if (!is_dir($f)) { |
|
| 472 | + supprimer_fichier($f, false); |
|
| 473 | + } else { |
|
| 474 | + @unlink("$f/.ok"); |
|
| 475 | + @rmdir($f); |
|
| 476 | + } |
|
| 477 | 477 | } |
| 478 | 478 | |
| 479 | 479 | /** |
@@ -487,26 +487,26 @@ discard block |
||
| 487 | 487 | * The absolute path of the PHP file to invalidate. |
| 488 | 488 | */ |
| 489 | 489 | function spip_clear_opcode_cache($filepath) { |
| 490 | - clearstatcache(true, $filepath); |
|
| 491 | - |
|
| 492 | - // Zend OPcache |
|
| 493 | - if (function_exists('opcache_invalidate')) { |
|
| 494 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | - // si l'invalidation a echoue lever un flag |
|
| 496 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | - } |
|
| 499 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | - } |
|
| 503 | - // APC. |
|
| 504 | - if (function_exists('apc_delete_file')) { |
|
| 505 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | - // not compiled yet. |
|
| 507 | - // @see http://php.net/apc-delete-file |
|
| 508 | - @apc_delete_file($filepath); |
|
| 509 | - } |
|
| 490 | + clearstatcache(true, $filepath); |
|
| 491 | + |
|
| 492 | + // Zend OPcache |
|
| 493 | + if (function_exists('opcache_invalidate')) { |
|
| 494 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 495 | + // si l'invalidation a echoue lever un flag |
|
| 496 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 498 | + } |
|
| 499 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 500 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 501 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 502 | + } |
|
| 503 | + // APC. |
|
| 504 | + if (function_exists('apc_delete_file')) { |
|
| 505 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 506 | + // not compiled yet. |
|
| 507 | + // @see http://php.net/apc-delete-file |
|
| 508 | + @apc_delete_file($filepath); |
|
| 509 | + } |
|
| 510 | 510 | } |
| 511 | 511 | |
| 512 | 512 | /** |
@@ -529,25 +529,25 @@ discard block |
||
| 529 | 529 | * |
| 530 | 530 | */ |
| 531 | 531 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 532 | - if ( |
|
| 533 | - function_exists('opcache_get_configuration') |
|
| 534 | - and @ini_get('opcache.enable') |
|
| 535 | - and @ini_get('opcache.validate_timestamps') |
|
| 536 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | - ) { |
|
| 539 | - $wait = $duree + 1; |
|
| 540 | - if ($timestamp) { |
|
| 541 | - $wait -= (time() - $timestamp); |
|
| 542 | - if ($wait < 0) { |
|
| 543 | - $wait = 0; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | - if ($wait) { |
|
| 548 | - sleep($duree + 1); |
|
| 549 | - } |
|
| 550 | - } |
|
| 532 | + if ( |
|
| 533 | + function_exists('opcache_get_configuration') |
|
| 534 | + and @ini_get('opcache.enable') |
|
| 535 | + and @ini_get('opcache.validate_timestamps') |
|
| 536 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 537 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 538 | + ) { |
|
| 539 | + $wait = $duree + 1; |
|
| 540 | + if ($timestamp) { |
|
| 541 | + $wait -= (time() - $timestamp); |
|
| 542 | + if ($wait < 0) { |
|
| 543 | + $wait = 0; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 547 | + if ($wait) { |
|
| 548 | + sleep($duree + 1); |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | 551 | } |
| 552 | 552 | |
| 553 | 553 | |
@@ -560,26 +560,26 @@ discard block |
||
| 560 | 560 | * @return bool Suppression reussie. |
| 561 | 561 | */ |
| 562 | 562 | function supprimer_repertoire($dir) { |
| 563 | - if (!file_exists($dir)) { |
|
| 564 | - return true; |
|
| 565 | - } |
|
| 566 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | - return @unlink($dir); |
|
| 568 | - } |
|
| 569 | - |
|
| 570 | - foreach (scandir($dir) as $item) { |
|
| 571 | - if ($item == '.' || $item == '..') { |
|
| 572 | - continue; |
|
| 573 | - } |
|
| 574 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | - @chmod($dir . '/' . $item, 0777); |
|
| 576 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | - return false; |
|
| 578 | - } |
|
| 579 | - }; |
|
| 580 | - } |
|
| 581 | - |
|
| 582 | - return @rmdir($dir); |
|
| 563 | + if (!file_exists($dir)) { |
|
| 564 | + return true; |
|
| 565 | + } |
|
| 566 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 567 | + return @unlink($dir); |
|
| 568 | + } |
|
| 569 | + |
|
| 570 | + foreach (scandir($dir) as $item) { |
|
| 571 | + if ($item == '.' || $item == '..') { |
|
| 572 | + continue; |
|
| 573 | + } |
|
| 574 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 575 | + @chmod($dir . '/' . $item, 0777); |
|
| 576 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 577 | + return false; |
|
| 578 | + } |
|
| 579 | + }; |
|
| 580 | + } |
|
| 581 | + |
|
| 582 | + return @rmdir($dir); |
|
| 583 | 583 | } |
| 584 | 584 | |
| 585 | 585 | |
@@ -608,57 +608,57 @@ discard block |
||
| 608 | 608 | * Chemin du répertoire créé. |
| 609 | 609 | **/ |
| 610 | 610 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 611 | - static $dirs = []; |
|
| 612 | - |
|
| 613 | - $base = str_replace('//', '/', $base); |
|
| 614 | - |
|
| 615 | - # suppr le dernier caractere si c'est un / |
|
| 616 | - $base = rtrim($base, '/'); |
|
| 617 | - |
|
| 618 | - if (!strlen($subdir)) { |
|
| 619 | - $n = strrpos($base, '/'); |
|
| 620 | - if ($n === false) { |
|
| 621 | - return $nobase ? '' : ($base . '/'); |
|
| 622 | - } |
|
| 623 | - $subdir = substr($base, $n + 1); |
|
| 624 | - $base = substr($base, 0, $n + 1); |
|
| 625 | - } else { |
|
| 626 | - $base .= '/'; |
|
| 627 | - $subdir = str_replace('/', '', $subdir); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - $baseaff = $nobase ? '' : $base; |
|
| 631 | - if (isset($dirs[$base . $subdir])) { |
|
| 632 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | - |
|
| 637 | - if (file_exists("$path/.ok")) { |
|
| 638 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | - } |
|
| 640 | - |
|
| 641 | - @mkdir($path, _SPIP_CHMOD); |
|
| 642 | - @chmod($path, _SPIP_CHMOD); |
|
| 643 | - |
|
| 644 | - if (is_dir($path) && is_writable($path)) { |
|
| 645 | - @touch("$path/.ok"); |
|
| 646 | - spip_log("creation $base$subdir/"); |
|
| 647 | - |
|
| 648 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | - } |
|
| 650 | - |
|
| 651 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | - spip_log("echec creation $base${subdir}"); |
|
| 654 | - if ($tantpis) { |
|
| 655 | - return ''; |
|
| 656 | - } |
|
| 657 | - if (!_DIR_RESTREINT) { |
|
| 658 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | - } |
|
| 660 | - $base .= $subdir; |
|
| 661 | - raler_fichier($base . '/.ok'); |
|
| 611 | + static $dirs = []; |
|
| 612 | + |
|
| 613 | + $base = str_replace('//', '/', $base); |
|
| 614 | + |
|
| 615 | + # suppr le dernier caractere si c'est un / |
|
| 616 | + $base = rtrim($base, '/'); |
|
| 617 | + |
|
| 618 | + if (!strlen($subdir)) { |
|
| 619 | + $n = strrpos($base, '/'); |
|
| 620 | + if ($n === false) { |
|
| 621 | + return $nobase ? '' : ($base . '/'); |
|
| 622 | + } |
|
| 623 | + $subdir = substr($base, $n + 1); |
|
| 624 | + $base = substr($base, 0, $n + 1); |
|
| 625 | + } else { |
|
| 626 | + $base .= '/'; |
|
| 627 | + $subdir = str_replace('/', '', $subdir); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + $baseaff = $nobase ? '' : $base; |
|
| 631 | + if (isset($dirs[$base . $subdir])) { |
|
| 632 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 636 | + |
|
| 637 | + if (file_exists("$path/.ok")) { |
|
| 638 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 639 | + } |
|
| 640 | + |
|
| 641 | + @mkdir($path, _SPIP_CHMOD); |
|
| 642 | + @chmod($path, _SPIP_CHMOD); |
|
| 643 | + |
|
| 644 | + if (is_dir($path) && is_writable($path)) { |
|
| 645 | + @touch("$path/.ok"); |
|
| 646 | + spip_log("creation $base$subdir/"); |
|
| 647 | + |
|
| 648 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 649 | + } |
|
| 650 | + |
|
| 651 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 652 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 653 | + spip_log("echec creation $base${subdir}"); |
|
| 654 | + if ($tantpis) { |
|
| 655 | + return ''; |
|
| 656 | + } |
|
| 657 | + if (!_DIR_RESTREINT) { |
|
| 658 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 659 | + } |
|
| 660 | + $base .= $subdir; |
|
| 661 | + raler_fichier($base . '/.ok'); |
|
| 662 | 662 | } |
| 663 | 663 | |
| 664 | 664 | |
@@ -691,56 +691,56 @@ discard block |
||
| 691 | 691 | * Chemins des fichiers trouvés. |
| 692 | 692 | **/ |
| 693 | 693 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 694 | - $nbfiles = 0; |
|
| 695 | - if ($pattern == -1) { |
|
| 696 | - $pattern = "^$dir"; |
|
| 697 | - } |
|
| 698 | - $fichiers = []; |
|
| 699 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | - if ($dir == '') { |
|
| 703 | - $dir = '.'; |
|
| 704 | - } |
|
| 705 | - |
|
| 706 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | - if ( |
|
| 709 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | - and $f != 'CVS' |
|
| 711 | - and $f != 'remove.txt' |
|
| 712 | - and is_readable($f = "$dir/$f") |
|
| 713 | - ) { |
|
| 714 | - if (is_file($f)) { |
|
| 715 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | - $fichiers[] = $f; |
|
| 717 | - $nbfiles++; |
|
| 718 | - } |
|
| 719 | - } else { |
|
| 720 | - if (is_dir($f) and is_array($recurs)) { |
|
| 721 | - $rp = @realpath($f); |
|
| 722 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | - $rp = $f; |
|
| 724 | - } # realpath n'est peut etre pas autorise |
|
| 725 | - if (!isset($recurs[$rp])) { |
|
| 726 | - $recurs[$rp] = true; |
|
| 727 | - $beginning = $fichiers; |
|
| 728 | - $end = preg_files( |
|
| 729 | - "$f/", |
|
| 730 | - $pattern, |
|
| 731 | - $maxfiles - $nbfiles, |
|
| 732 | - $recurs |
|
| 733 | - ); |
|
| 734 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | - $nbfiles = count($fichiers); |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - } |
|
| 739 | - } |
|
| 740 | - } |
|
| 741 | - closedir($d); |
|
| 742 | - } |
|
| 743 | - sort($fichiers); |
|
| 744 | - |
|
| 745 | - return $fichiers; |
|
| 694 | + $nbfiles = 0; |
|
| 695 | + if ($pattern == -1) { |
|
| 696 | + $pattern = "^$dir"; |
|
| 697 | + } |
|
| 698 | + $fichiers = []; |
|
| 699 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 700 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 701 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 702 | + if ($dir == '') { |
|
| 703 | + $dir = '.'; |
|
| 704 | + } |
|
| 705 | + |
|
| 706 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 707 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 708 | + if ( |
|
| 709 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 710 | + and $f != 'CVS' |
|
| 711 | + and $f != 'remove.txt' |
|
| 712 | + and is_readable($f = "$dir/$f") |
|
| 713 | + ) { |
|
| 714 | + if (is_file($f)) { |
|
| 715 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 716 | + $fichiers[] = $f; |
|
| 717 | + $nbfiles++; |
|
| 718 | + } |
|
| 719 | + } else { |
|
| 720 | + if (is_dir($f) and is_array($recurs)) { |
|
| 721 | + $rp = @realpath($f); |
|
| 722 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 723 | + $rp = $f; |
|
| 724 | + } # realpath n'est peut etre pas autorise |
|
| 725 | + if (!isset($recurs[$rp])) { |
|
| 726 | + $recurs[$rp] = true; |
|
| 727 | + $beginning = $fichiers; |
|
| 728 | + $end = preg_files( |
|
| 729 | + "$f/", |
|
| 730 | + $pattern, |
|
| 731 | + $maxfiles - $nbfiles, |
|
| 732 | + $recurs |
|
| 733 | + ); |
|
| 734 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 735 | + $nbfiles = count($fichiers); |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + } |
|
| 739 | + } |
|
| 740 | + } |
|
| 741 | + closedir($d); |
|
| 742 | + } |
|
| 743 | + sort($fichiers); |
|
| 744 | + |
|
| 745 | + return $fichiers; |
|
| 746 | 746 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Logos |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -37,34 +37,34 @@ discard block |
||
| 37 | 37 | **/ |
| 38 | 38 | function inc_chercher_logo_dist($id, $_id_objet, $mode = 'on', $compat_old_logos = true) { |
| 39 | 39 | |
| 40 | - $mode = preg_replace(',\W,', '', $mode); |
|
| 41 | - if ($mode) { |
|
| 42 | - // chercher dans la base |
|
| 43 | - $mode_document = 'logo' . $mode; |
|
| 44 | - $objet = objet_type($_id_objet); |
|
| 45 | - $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . intval($id)); |
|
| 46 | - if ($doc) { |
|
| 47 | - include_spip('inc/documents'); |
|
| 48 | - $d = get_spip_doc($doc['fichier']); |
|
| 49 | - return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc]; |
|
| 50 | - } |
|
| 40 | + $mode = preg_replace(',\W,', '', $mode); |
|
| 41 | + if ($mode) { |
|
| 42 | + // chercher dans la base |
|
| 43 | + $mode_document = 'logo' . $mode; |
|
| 44 | + $objet = objet_type($_id_objet); |
|
| 45 | + $doc = sql_fetsel('D.*', 'spip_documents AS D JOIN spip_documents_liens AS L ON L.id_document=D.id_document', 'D.mode=' . sql_quote($mode_document) . ' AND L.objet=' . sql_quote($objet) . ' AND id_objet=' . intval($id)); |
|
| 46 | + if ($doc) { |
|
| 47 | + include_spip('inc/documents'); |
|
| 48 | + $d = get_spip_doc($doc['fichier']); |
|
| 49 | + return [$d, _DIR_IMG, basename($d), $doc['extension'], @filemtime($d), $doc]; |
|
| 50 | + } |
|
| 51 | 51 | |
| 52 | - # deprecated TODO remove |
|
| 53 | - if ($compat_old_logos) { |
|
| 54 | - # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 55 | - $type = type_du_logo($_id_objet); |
|
| 56 | - $nom = $type . $mode . intval($id); |
|
| 52 | + # deprecated TODO remove |
|
| 53 | + if ($compat_old_logos) { |
|
| 54 | + # attention au cas $id = '0' pour LOGO_SITE_SPIP : utiliser intval() |
|
| 55 | + $type = type_du_logo($_id_objet); |
|
| 56 | + $nom = $type . $mode . intval($id); |
|
| 57 | 57 | |
| 58 | - foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 59 | - if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 60 | - return [$d, _DIR_LOGOS, $nom, $format, @filemtime($d)]; |
|
| 61 | - } |
|
| 62 | - } |
|
| 63 | - } |
|
| 64 | - } |
|
| 58 | + foreach ($GLOBALS['formats_logos'] as $format) { |
|
| 59 | + if (@file_exists($d = (_DIR_LOGOS . $nom . '.' . $format))) { |
|
| 60 | + return [$d, _DIR_LOGOS, $nom, $format, @filemtime($d)]; |
|
| 61 | + } |
|
| 62 | + } |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - # coherence de type pour servir comme filtre (formulaire_login) |
|
| 67 | - return []; |
|
| 66 | + # coherence de type pour servir comme filtre (formulaire_login) |
|
| 67 | + return []; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | /** |
@@ -83,13 +83,13 @@ discard block |
||
| 83 | 83 | * @deprecated 4.0 MAIS NE PAS SUPPRIMER CAR SERT POUR L'UPGRADE des logos et leur mise en base |
| 84 | 84 | **/ |
| 85 | 85 | function type_du_logo($_id_objet) { |
| 86 | - return $GLOBALS['table_logos'][$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 86 | + return $GLOBALS['table_logos'][$_id_objet] ?? objet_type(preg_replace(',^id_,', '', $_id_objet)); |
|
| 87 | 87 | } |
| 88 | 88 | |
| 89 | 89 | // Exceptions standards (historique) |
| 90 | 90 | $GLOBALS['table_logos'] = [ |
| 91 | - 'id_article' => 'art', |
|
| 92 | - 'id_auteur' => 'aut', |
|
| 93 | - 'id_rubrique' => 'rub', |
|
| 94 | - 'id_groupe' => 'groupe', |
|
| 91 | + 'id_article' => 'art', |
|
| 92 | + 'id_auteur' => 'aut', |
|
| 93 | + 'id_rubrique' => 'rub', |
|
| 94 | + 'id_groupe' => 'groupe', |
|
| 95 | 95 | ]; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Affichage |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -25,7 +25,7 @@ discard block |
||
| 25 | 25 | * @return string Code HTML |
| 26 | 26 | */ |
| 27 | 27 | function debut_grand_cadre() { |
| 28 | - return "\n<div class = 'table_page'>\n"; |
|
| 28 | + return "\n<div class = 'table_page'>\n"; |
|
| 29 | 29 | } |
| 30 | 30 | |
| 31 | 31 | /** |
@@ -34,7 +34,7 @@ discard block |
||
| 34 | 34 | * @return string Code HTML |
| 35 | 35 | */ |
| 36 | 36 | function fin_grand_cadre() { |
| 37 | - return "\n</div>"; |
|
| 37 | + return "\n</div>"; |
|
| 38 | 38 | } |
| 39 | 39 | |
| 40 | 40 | // Debut de la colonne de gauche |
@@ -49,7 +49,7 @@ discard block |
||
| 49 | 49 | * @return string Code HTML |
| 50 | 50 | */ |
| 51 | 51 | function debut_gauche() { |
| 52 | - return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 52 | + return "<div id = 'conteneur' class = ''>\n<div id = 'navigation' class = 'lat' role = 'contentinfo'>\n"; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | * @return string Code HTML |
| 59 | 59 | */ |
| 60 | 60 | function fin_gauche() { |
| 61 | - return "</div></div><br class = 'nettoyeur' />"; |
|
| 61 | + return "</div></div><br class = 'nettoyeur' />"; |
|
| 62 | 62 | } |
| 63 | 63 | |
| 64 | 64 | /** |
@@ -67,13 +67,13 @@ discard block |
||
| 67 | 67 | * @return string Code HTML |
| 68 | 68 | */ |
| 69 | 69 | function creer_colonne_droite() { |
| 70 | - static $deja_colonne_droite; |
|
| 71 | - if ($deja_colonne_droite) { |
|
| 72 | - return ''; |
|
| 73 | - } |
|
| 74 | - $deja_colonne_droite = true; |
|
| 70 | + static $deja_colonne_droite; |
|
| 71 | + if ($deja_colonne_droite) { |
|
| 72 | + return ''; |
|
| 73 | + } |
|
| 74 | + $deja_colonne_droite = true; |
|
| 75 | 75 | |
| 76 | - return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 76 | + return "\n</div><div id='extra' class='lat' role='complementary'>"; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | /** |
@@ -82,10 +82,10 @@ discard block |
||
| 82 | 82 | * @return string Code HTML |
| 83 | 83 | */ |
| 84 | 84 | function debut_droite() { |
| 85 | - return liste_objets_bloques(_request('exec')) |
|
| 86 | - . creer_colonne_droite() |
|
| 87 | - . '</div>' |
|
| 88 | - . "\n<div id='contenu'>"; |
|
| 85 | + return liste_objets_bloques(_request('exec')) |
|
| 86 | + . creer_colonne_droite() |
|
| 87 | + . '</div>' |
|
| 88 | + . "\n<div id='contenu'>"; |
|
| 89 | 89 | } |
| 90 | 90 | |
| 91 | 91 | /** |
@@ -107,31 +107,31 @@ discard block |
||
| 107 | 107 | * Code HTML |
| 108 | 108 | **/ |
| 109 | 109 | function liste_objets_bloques($exec, $contexte = [], $auteur = null) { |
| 110 | - $res = ''; |
|
| 111 | - if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | - include_spip('inc/drapeau_edition'); |
|
| 113 | - if (is_null($auteur)) { |
|
| 114 | - $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | - } |
|
| 116 | - if ( |
|
| 117 | - $en_cours = trouver_objet_exec($exec) |
|
| 118 | - and $en_cours['edition'] |
|
| 119 | - and $type = $en_cours['type'] |
|
| 120 | - and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | - or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | - ) { |
|
| 123 | - // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | - // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | - signale_edition($id, $auteur, $type); |
|
| 126 | - } |
|
| 127 | - |
|
| 128 | - $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | - if (count($objets_ouverts)) { |
|
| 130 | - $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | - } |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - return $res; |
|
| 110 | + $res = ''; |
|
| 111 | + if ($GLOBALS['meta']['articles_modif'] != 'non') { |
|
| 112 | + include_spip('inc/drapeau_edition'); |
|
| 113 | + if (is_null($auteur)) { |
|
| 114 | + $auteur = $GLOBALS['visiteur_session']; |
|
| 115 | + } |
|
| 116 | + if ( |
|
| 117 | + $en_cours = trouver_objet_exec($exec) |
|
| 118 | + and $en_cours['edition'] |
|
| 119 | + and $type = $en_cours['type'] |
|
| 120 | + and ((isset($contexte[$en_cours['id_table_objet']]) and $id = $contexte[$en_cours['id_table_objet']]) |
|
| 121 | + or $id = _request($en_cours['id_table_objet'])) |
|
| 122 | + ) { |
|
| 123 | + // marquer le fait que l'objet est ouvert en edition par toto |
|
| 124 | + // a telle date ; une alerte sera donnee aux autres redacteurs |
|
| 125 | + signale_edition($id, $auteur, $type); |
|
| 126 | + } |
|
| 127 | + |
|
| 128 | + $objets_ouverts = liste_drapeau_edition($auteur['id_auteur']); |
|
| 129 | + if (count($objets_ouverts)) { |
|
| 130 | + $res .= recuperer_fond('prive/objets/liste/objets-en-edition', [], ['ajax' => true]); |
|
| 131 | + } |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + return $res; |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | |
@@ -145,20 +145,20 @@ discard block |
||
| 145 | 145 | * @return string Code HTML |
| 146 | 146 | **/ |
| 147 | 147 | function fin_page() { |
| 148 | - include_spip('inc/pipelines'); |
|
| 149 | - // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | - $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | - and ((_request('var_mode') == 'debug') |
|
| 152 | - or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | - and isset($_COOKIE['spip_admin']))); |
|
| 154 | - $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | - . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | - . '</div>' |
|
| 157 | - . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | - . ($debug ? erreur_squelette() : '') |
|
| 159 | - . "</body></html>\n"; |
|
| 160 | - |
|
| 161 | - return f_queue($t); |
|
| 148 | + include_spip('inc/pipelines'); |
|
| 149 | + // avec &var_profile=1 on a le tableau de mesures SQL |
|
| 150 | + $debug = ((_request('exec') !== 'valider_xml') |
|
| 151 | + and ((_request('var_mode') == 'debug') |
|
| 152 | + or (isset($GLOBALS['tableau_des_temps']) and $GLOBALS['tableau_des_temps']) |
|
| 153 | + and isset($_COOKIE['spip_admin']))); |
|
| 154 | + $t = '</div><div id="pied"><div class="largeur">' |
|
| 155 | + . recuperer_fond('prive/squelettes/inclure/pied') |
|
| 156 | + . '</div>' |
|
| 157 | + . '</div></div>' // cf. div#page et div.largeur ouvertes dans conmmencer_page() |
|
| 158 | + . ($debug ? erreur_squelette() : '') |
|
| 159 | + . "</body></html>\n"; |
|
| 160 | + |
|
| 161 | + return f_queue($t); |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | /** |
@@ -173,22 +173,22 @@ discard block |
||
| 173 | 173 | * @return string Code HTML |
| 174 | 174 | **/ |
| 175 | 175 | function html_tests_js() { |
| 176 | - if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | - // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | - define( |
|
| 179 | - '_TESTER_NOSCRIPT', |
|
| 180 | - "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | - . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | - . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | - ); |
|
| 184 | - } |
|
| 185 | - |
|
| 186 | - $rejouer = ''; |
|
| 187 | - if (defined('_SESSION_REJOUER')) { |
|
| 188 | - $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 176 | + if (_SPIP_AJAX and !defined('_TESTER_NOSCRIPT')) { |
|
| 177 | + // pour le pied de page (deja defini si on est validation XML) |
|
| 178 | + define( |
|
| 179 | + '_TESTER_NOSCRIPT', |
|
| 180 | + "<noscript>\n<div style='display:none;'><img src='" |
|
| 181 | + . generer_url_ecrire('test_ajax', 'js=-1') |
|
| 182 | + . "' width='1' height='1' alt='' /></div></noscript>\n" |
|
| 183 | + ); |
|
| 184 | + } |
|
| 185 | + |
|
| 186 | + $rejouer = ''; |
|
| 187 | + if (defined('_SESSION_REJOUER')) { |
|
| 188 | + $rejouer = (_SESSION_REJOUER === true) ? rejouer_session() : _SESSION_REJOUER; |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + return $rejouer . (defined('_TESTER_NOSCRIPT') ? _TESTER_NOSCRIPT : ''); |
|
| 192 | 192 | } |
| 193 | 193 | |
| 194 | 194 | /** |
@@ -198,25 +198,25 @@ discard block |
||
| 198 | 198 | **/ |
| 199 | 199 | function info_maj_spip() { |
| 200 | 200 | |
| 201 | - $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 202 | - if (!$maj) { |
|
| 203 | - return ''; |
|
| 204 | - } |
|
| 201 | + $maj = $GLOBALS['meta']['info_maj_spip'] ?? null; |
|
| 202 | + if (!$maj) { |
|
| 203 | + return ''; |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - $maj = explode('|', $maj); |
|
| 207 | - // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | - if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | - return ''; |
|
| 210 | - } |
|
| 206 | + $maj = explode('|', $maj); |
|
| 207 | + // c'est une ancienne notif, on a fait la maj depuis ! |
|
| 208 | + if ($GLOBALS['spip_version_branche'] !== reset($maj)) { |
|
| 209 | + return ''; |
|
| 210 | + } |
|
| 211 | 211 | |
| 212 | - if (!autoriser('webmestre')) { |
|
| 213 | - return ''; |
|
| 214 | - } |
|
| 212 | + if (!autoriser('webmestre')) { |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | 215 | |
| 216 | - array_shift($maj); |
|
| 217 | - $maj = implode('|', $maj); |
|
| 216 | + array_shift($maj); |
|
| 217 | + $maj = implode('|', $maj); |
|
| 218 | 218 | |
| 219 | - return "$maj<br />"; |
|
| 219 | + return "$maj<br />"; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | /** |
@@ -227,47 +227,47 @@ discard block |
||
| 227 | 227 | **/ |
| 228 | 228 | function info_copyright() { |
| 229 | 229 | |
| 230 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | - |
|
| 232 | - // |
|
| 233 | - // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | - // |
|
| 235 | - if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | - if ($vcs['vcs'] === 'GIT') { |
|
| 237 | - $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | - } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | - $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | - } else { |
|
| 241 | - $url = ''; |
|
| 242 | - } |
|
| 243 | - // affichage "GIT [master: abcdef]" |
|
| 244 | - $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 245 | - if ($url) { |
|
| 246 | - $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | - } |
|
| 248 | - if ($vcs['branch']) { |
|
| 249 | - $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | - } |
|
| 251 | - $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | - } |
|
| 253 | - |
|
| 254 | - // et la version de l'ecran de securite |
|
| 255 | - $secu = defined('_ECRAN_SECURITE') |
|
| 256 | - ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | - : ''; |
|
| 258 | - |
|
| 259 | - return _T( |
|
| 260 | - 'info_copyright', |
|
| 261 | - [ |
|
| 262 | - 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | - 'lien_gpl' => |
|
| 264 | - "<a href='" . generer_url_ecrire( |
|
| 265 | - 'aide', |
|
| 266 | - 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | - ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | - ] |
|
| 269 | - ) |
|
| 270 | - . $secu; |
|
| 230 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 231 | + |
|
| 232 | + // |
|
| 233 | + // Mention, le cas echeant, de la revision SVN courante |
|
| 234 | + // |
|
| 235 | + if ($vcs = version_vcs_courante(_DIR_RACINE, true)) { |
|
| 236 | + if ($vcs['vcs'] === 'GIT') { |
|
| 237 | + $url = 'https://git.spip.net/spip/spip/commit/' . $vcs['commit']; |
|
| 238 | + } elseif ($vcs['vcs'] === 'SVN') { |
|
| 239 | + $url = 'https://core.spip.net/projects/spip/repository/revisions/' . $vcs['commit']; |
|
| 240 | + } else { |
|
| 241 | + $url = ''; |
|
| 242 | + } |
|
| 243 | + // affichage "GIT [master: abcdef]" |
|
| 244 | + $commit = $vcs['commit_short'] ?? $vcs['commit']; |
|
| 245 | + if ($url) { |
|
| 246 | + $commit = "<a href=\"$url\" target=\"_blank\" rel=\"noopener noreferrer\">$commit</a>"; |
|
| 247 | + } |
|
| 248 | + if ($vcs['branch']) { |
|
| 249 | + $commit = $vcs['branch'] . ': ' . $commit; |
|
| 250 | + } |
|
| 251 | + $version .= " {$vcs['vcs']} [$commit]"; |
|
| 252 | + } |
|
| 253 | + |
|
| 254 | + // et la version de l'ecran de securite |
|
| 255 | + $secu = defined('_ECRAN_SECURITE') |
|
| 256 | + ? '<br />' . _T('ecran_securite', ['version' => _ECRAN_SECURITE]) |
|
| 257 | + : ''; |
|
| 258 | + |
|
| 259 | + return _T( |
|
| 260 | + 'info_copyright', |
|
| 261 | + [ |
|
| 262 | + 'spip' => "<b>SPIP $version</b> ", |
|
| 263 | + 'lien_gpl' => |
|
| 264 | + "<a href='" . generer_url_ecrire( |
|
| 265 | + 'aide', |
|
| 266 | + 'aide=licence&var_lang=' . $GLOBALS['spip_lang'] |
|
| 267 | + ) . "' class=\"aide popin\">" . _T('info_copyright_gpl') . '</a>' |
|
| 268 | + ] |
|
| 269 | + ) |
|
| 270 | + . $secu; |
|
| 271 | 271 | } |
| 272 | 272 | |
| 273 | 273 | /** |
@@ -282,17 +282,17 @@ discard block |
||
| 282 | 282 | * @return string Code HTML |
| 283 | 283 | **/ |
| 284 | 284 | function formulaire_recherche($page, $complement = '') { |
| 285 | - $recherche = _request('recherche'); |
|
| 286 | - $recherche_aff = entites_html($recherche); |
|
| 287 | - if (!strlen($recherche)) { |
|
| 288 | - $recherche_aff = _T('info_rechercher'); |
|
| 289 | - $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | - } else { |
|
| 291 | - $onfocus = ''; |
|
| 292 | - } |
|
| 293 | - |
|
| 294 | - $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | - $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | - |
|
| 297 | - return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 285 | + $recherche = _request('recherche'); |
|
| 286 | + $recherche_aff = entites_html($recherche); |
|
| 287 | + if (!strlen($recherche)) { |
|
| 288 | + $recherche_aff = _T('info_rechercher'); |
|
| 289 | + $onfocus = " onfocus=\"this.value='';\""; |
|
| 290 | + } else { |
|
| 291 | + $onfocus = ''; |
|
| 292 | + } |
|
| 293 | + |
|
| 294 | + $form = '<input type="text" size="10" value="' . $recherche_aff . '" name="recherche" class="recherche" accesskey="r"' . $onfocus . ' />'; |
|
| 295 | + $form .= "<input type='image' src='" . chemin_image('rechercher-20.png') . "' name='submit' class='submit' alt='" . _T('info_rechercher') . "' />"; |
|
| 296 | + |
|
| 297 | + return "<div class='spip_recherche'>" . generer_form_ecrire($page, $form . $complement, " method='get'") . '</div>'; |
|
| 298 | 298 | } |
@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres_images_lib_mini'); // par precaution |
| 24 | 24 | |
@@ -31,161 +31,161 @@ discard block |
||
| 31 | 31 | * Le code hexadécimal de la couleur (sans le #) ou le code couleur textuel si non trouvé |
| 32 | 32 | */ |
| 33 | 33 | function couleur_html_to_hex($couleur) { |
| 34 | - $couleurs_html = [ |
|
| 35 | - 'aliceblue' => 'F0F8FF', |
|
| 36 | - 'antiquewhite' => 'FAEBD7', |
|
| 37 | - 'aqua' => '00FFFF', |
|
| 38 | - 'aquamarine' => '7FFFD4', |
|
| 39 | - 'azure' => 'F0FFFF', |
|
| 40 | - 'beige' => 'F5F5DC', |
|
| 41 | - 'bisque' => 'FFE4C4', |
|
| 42 | - 'black' => '000000', |
|
| 43 | - 'blanchedalmond' => 'FFEBCD', |
|
| 44 | - 'blue' => '0000FF', |
|
| 45 | - 'blueviolet' => '8A2BE2', |
|
| 46 | - 'brown' => 'A52A2A', |
|
| 47 | - 'burlywood' => 'DEB887', |
|
| 48 | - 'cadetblue' => '5F9EA0', |
|
| 49 | - 'chartreuse' => '7FFF00', |
|
| 50 | - 'chocolate' => 'D2691E', |
|
| 51 | - 'coral' => 'FF7F50', |
|
| 52 | - 'cornflowerblue' => '6495ED', |
|
| 53 | - 'cornsilk' => 'FFF8DC', |
|
| 54 | - 'crimson' => 'DC143C', |
|
| 55 | - 'cyan' => '00FFFF', |
|
| 56 | - 'darkblue' => '00008B', |
|
| 57 | - 'darkcyan' => '008B8B', |
|
| 58 | - 'darkgoldenrod' => 'B8860B', |
|
| 59 | - 'darkgray' => 'A9A9A9', |
|
| 60 | - 'darkgreen' => '006400', |
|
| 61 | - 'darkgrey' => 'A9A9A9', |
|
| 62 | - 'darkkhaki' => 'BDB76B', |
|
| 63 | - 'darkmagenta' => '8B008B', |
|
| 64 | - 'darkolivegreen' => '556B2F', |
|
| 65 | - 'darkorange' => 'FF8C00', |
|
| 66 | - 'darkorchid' => '9932CC', |
|
| 67 | - 'darkred' => '8B0000', |
|
| 68 | - 'darksalmon' => 'E9967A', |
|
| 69 | - 'darkseagreen' => '8FBC8F', |
|
| 70 | - 'darkslateblue' => '483D8B', |
|
| 71 | - 'darkslategray' => '2F4F4F', |
|
| 72 | - 'darkslategrey' => '2F4F4F', |
|
| 73 | - 'darkturquoise' => '00CED1', |
|
| 74 | - 'darkviolet' => '9400D3', |
|
| 75 | - 'deeppink' => 'FF1493', |
|
| 76 | - 'deepskyblue' => '00BFFF', |
|
| 77 | - 'dimgray' => '696969', |
|
| 78 | - 'dimgrey' => '696969', |
|
| 79 | - 'dodgerblue' => '1E90FF', |
|
| 80 | - 'firebrick' => 'B22222', |
|
| 81 | - 'floralwhite' => 'FFFAF0', |
|
| 82 | - 'forestgreen' => '228B22', |
|
| 83 | - 'fuchsia' => 'FF00FF', |
|
| 84 | - 'gainsboro' => 'DCDCDC', |
|
| 85 | - 'ghostwhite' => 'F8F8FF', |
|
| 86 | - 'gold' => 'FFD700', |
|
| 87 | - 'goldenrod' => 'DAA520', |
|
| 88 | - 'gray' => '808080', |
|
| 89 | - 'green' => '008000', |
|
| 90 | - 'greenyellow' => 'ADFF2F', |
|
| 91 | - 'grey' => '808080', |
|
| 92 | - 'honeydew' => 'F0FFF0', |
|
| 93 | - 'hotpink' => 'FF69B4', |
|
| 94 | - 'indianred' => 'CD5C5C', |
|
| 95 | - 'indigo' => '4B0082', |
|
| 96 | - 'ivory' => 'FFFFF0', |
|
| 97 | - 'khaki' => 'F0E68C', |
|
| 98 | - 'lavender' => 'E6E6FA', |
|
| 99 | - 'lavenderblush' => 'FFF0F5', |
|
| 100 | - 'lawngreen' => '7CFC00', |
|
| 101 | - 'lemonchiffon' => 'FFFACD', |
|
| 102 | - 'lightblue' => 'ADD8E6', |
|
| 103 | - 'lightcoral' => 'F08080', |
|
| 104 | - 'lightcyan' => 'E0FFFF', |
|
| 105 | - 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | - 'lightgray' => 'D3D3D3', |
|
| 107 | - 'lightgreen' => '90EE90', |
|
| 108 | - 'lightgrey' => 'D3D3D3', |
|
| 109 | - 'lightpink' => 'FFB6C1', |
|
| 110 | - 'lightsalmon' => 'FFA07A', |
|
| 111 | - 'lightseagreen' => '20B2AA', |
|
| 112 | - 'lightskyblue' => '87CEFA', |
|
| 113 | - 'lightslategray' => '778899', |
|
| 114 | - 'lightslategrey' => '778899', |
|
| 115 | - 'lightsteelblue' => 'B0C4DE', |
|
| 116 | - 'lightyellow' => 'FFFFE0', |
|
| 117 | - 'lime' => '00FF00', |
|
| 118 | - 'limegreen' => '32CD32', |
|
| 119 | - 'linen' => 'FAF0E6', |
|
| 120 | - 'magenta' => 'FF00FF', |
|
| 121 | - 'maroon' => '800000', |
|
| 122 | - 'mediumaquamarine' => '66CDAA', |
|
| 123 | - 'mediumblue' => '0000CD', |
|
| 124 | - 'mediumorchid' => 'BA55D3', |
|
| 125 | - 'mediumpurple' => '9370DB', |
|
| 126 | - 'mediumseagreen' => '3CB371', |
|
| 127 | - 'mediumslateblue' => '7B68EE', |
|
| 128 | - 'mediumspringgreen' => '00FA9A', |
|
| 129 | - 'mediumturquoise' => '48D1CC', |
|
| 130 | - 'mediumvioletred' => 'C71585', |
|
| 131 | - 'midnightblue' => '191970', |
|
| 132 | - 'mintcream' => 'F5FFFA', |
|
| 133 | - 'mistyrose' => 'FFE4E1', |
|
| 134 | - 'moccasin' => 'FFE4B5', |
|
| 135 | - 'navajowhite' => 'FFDEAD', |
|
| 136 | - 'navy' => '000080', |
|
| 137 | - 'oldlace' => 'FDF5E6', |
|
| 138 | - 'olive' => '808000', |
|
| 139 | - 'olivedrab' => '6B8E23', |
|
| 140 | - 'orange' => 'FFA500', |
|
| 141 | - 'orangered' => 'FF4500', |
|
| 142 | - 'orchid' => 'DA70D6', |
|
| 143 | - 'palegoldenrod' => 'EEE8AA', |
|
| 144 | - 'palegreen' => '98FB98', |
|
| 145 | - 'paleturquoise' => 'AFEEEE', |
|
| 146 | - 'palevioletred' => 'DB7093', |
|
| 147 | - 'papayawhip' => 'FFEFD5', |
|
| 148 | - 'peachpuff' => 'FFDAB9', |
|
| 149 | - 'peru' => 'CD853F', |
|
| 150 | - 'pink' => 'FFC0CB', |
|
| 151 | - 'plum' => 'DDA0DD', |
|
| 152 | - 'powderblue' => 'B0E0E6', |
|
| 153 | - 'purple' => '800080', |
|
| 154 | - 'rebeccapurple' => '663399', |
|
| 155 | - 'red' => 'FF0000', |
|
| 156 | - 'rosybrown' => 'BC8F8F', |
|
| 157 | - 'royalblue' => '4169E1', |
|
| 158 | - 'saddlebrown' => '8B4513', |
|
| 159 | - 'salmon' => 'FA8072', |
|
| 160 | - 'sandybrown' => 'F4A460', |
|
| 161 | - 'seagreen' => '2E8B57', |
|
| 162 | - 'seashell' => 'FFF5EE', |
|
| 163 | - 'sienna' => 'A0522D', |
|
| 164 | - 'silver' => 'C0C0C0', |
|
| 165 | - 'skyblue' => '87CEEB', |
|
| 166 | - 'slateblue' => '6A5ACD', |
|
| 167 | - 'slategray' => '708090', |
|
| 168 | - 'slategrey' => '708090', |
|
| 169 | - 'snow' => 'FFFAFA', |
|
| 170 | - 'springgreen' => '00FF7F', |
|
| 171 | - 'steelblue' => '4682B4', |
|
| 172 | - 'tan' => 'D2B48C', |
|
| 173 | - 'teal' => '008080', |
|
| 174 | - 'thistle' => 'D8BFD8', |
|
| 175 | - 'tomato' => 'FF6347', |
|
| 176 | - 'turquoise' => '40E0D0', |
|
| 177 | - 'violet' => 'EE82EE', |
|
| 178 | - 'wheat' => 'F5DEB3', |
|
| 179 | - 'white' => 'FFFFFF', |
|
| 180 | - 'whitesmoke' => 'F5F5F5', |
|
| 181 | - 'yellow' => 'FFFF00', |
|
| 182 | - 'yellowgreen' => '9ACD32', |
|
| 183 | - ]; |
|
| 184 | - if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | - return $couleurs_html[$lc]; |
|
| 186 | - } |
|
| 187 | - |
|
| 188 | - return $couleur; |
|
| 34 | + $couleurs_html = [ |
|
| 35 | + 'aliceblue' => 'F0F8FF', |
|
| 36 | + 'antiquewhite' => 'FAEBD7', |
|
| 37 | + 'aqua' => '00FFFF', |
|
| 38 | + 'aquamarine' => '7FFFD4', |
|
| 39 | + 'azure' => 'F0FFFF', |
|
| 40 | + 'beige' => 'F5F5DC', |
|
| 41 | + 'bisque' => 'FFE4C4', |
|
| 42 | + 'black' => '000000', |
|
| 43 | + 'blanchedalmond' => 'FFEBCD', |
|
| 44 | + 'blue' => '0000FF', |
|
| 45 | + 'blueviolet' => '8A2BE2', |
|
| 46 | + 'brown' => 'A52A2A', |
|
| 47 | + 'burlywood' => 'DEB887', |
|
| 48 | + 'cadetblue' => '5F9EA0', |
|
| 49 | + 'chartreuse' => '7FFF00', |
|
| 50 | + 'chocolate' => 'D2691E', |
|
| 51 | + 'coral' => 'FF7F50', |
|
| 52 | + 'cornflowerblue' => '6495ED', |
|
| 53 | + 'cornsilk' => 'FFF8DC', |
|
| 54 | + 'crimson' => 'DC143C', |
|
| 55 | + 'cyan' => '00FFFF', |
|
| 56 | + 'darkblue' => '00008B', |
|
| 57 | + 'darkcyan' => '008B8B', |
|
| 58 | + 'darkgoldenrod' => 'B8860B', |
|
| 59 | + 'darkgray' => 'A9A9A9', |
|
| 60 | + 'darkgreen' => '006400', |
|
| 61 | + 'darkgrey' => 'A9A9A9', |
|
| 62 | + 'darkkhaki' => 'BDB76B', |
|
| 63 | + 'darkmagenta' => '8B008B', |
|
| 64 | + 'darkolivegreen' => '556B2F', |
|
| 65 | + 'darkorange' => 'FF8C00', |
|
| 66 | + 'darkorchid' => '9932CC', |
|
| 67 | + 'darkred' => '8B0000', |
|
| 68 | + 'darksalmon' => 'E9967A', |
|
| 69 | + 'darkseagreen' => '8FBC8F', |
|
| 70 | + 'darkslateblue' => '483D8B', |
|
| 71 | + 'darkslategray' => '2F4F4F', |
|
| 72 | + 'darkslategrey' => '2F4F4F', |
|
| 73 | + 'darkturquoise' => '00CED1', |
|
| 74 | + 'darkviolet' => '9400D3', |
|
| 75 | + 'deeppink' => 'FF1493', |
|
| 76 | + 'deepskyblue' => '00BFFF', |
|
| 77 | + 'dimgray' => '696969', |
|
| 78 | + 'dimgrey' => '696969', |
|
| 79 | + 'dodgerblue' => '1E90FF', |
|
| 80 | + 'firebrick' => 'B22222', |
|
| 81 | + 'floralwhite' => 'FFFAF0', |
|
| 82 | + 'forestgreen' => '228B22', |
|
| 83 | + 'fuchsia' => 'FF00FF', |
|
| 84 | + 'gainsboro' => 'DCDCDC', |
|
| 85 | + 'ghostwhite' => 'F8F8FF', |
|
| 86 | + 'gold' => 'FFD700', |
|
| 87 | + 'goldenrod' => 'DAA520', |
|
| 88 | + 'gray' => '808080', |
|
| 89 | + 'green' => '008000', |
|
| 90 | + 'greenyellow' => 'ADFF2F', |
|
| 91 | + 'grey' => '808080', |
|
| 92 | + 'honeydew' => 'F0FFF0', |
|
| 93 | + 'hotpink' => 'FF69B4', |
|
| 94 | + 'indianred' => 'CD5C5C', |
|
| 95 | + 'indigo' => '4B0082', |
|
| 96 | + 'ivory' => 'FFFFF0', |
|
| 97 | + 'khaki' => 'F0E68C', |
|
| 98 | + 'lavender' => 'E6E6FA', |
|
| 99 | + 'lavenderblush' => 'FFF0F5', |
|
| 100 | + 'lawngreen' => '7CFC00', |
|
| 101 | + 'lemonchiffon' => 'FFFACD', |
|
| 102 | + 'lightblue' => 'ADD8E6', |
|
| 103 | + 'lightcoral' => 'F08080', |
|
| 104 | + 'lightcyan' => 'E0FFFF', |
|
| 105 | + 'lightgoldenrodyellow' => 'FAFAD2', |
|
| 106 | + 'lightgray' => 'D3D3D3', |
|
| 107 | + 'lightgreen' => '90EE90', |
|
| 108 | + 'lightgrey' => 'D3D3D3', |
|
| 109 | + 'lightpink' => 'FFB6C1', |
|
| 110 | + 'lightsalmon' => 'FFA07A', |
|
| 111 | + 'lightseagreen' => '20B2AA', |
|
| 112 | + 'lightskyblue' => '87CEFA', |
|
| 113 | + 'lightslategray' => '778899', |
|
| 114 | + 'lightslategrey' => '778899', |
|
| 115 | + 'lightsteelblue' => 'B0C4DE', |
|
| 116 | + 'lightyellow' => 'FFFFE0', |
|
| 117 | + 'lime' => '00FF00', |
|
| 118 | + 'limegreen' => '32CD32', |
|
| 119 | + 'linen' => 'FAF0E6', |
|
| 120 | + 'magenta' => 'FF00FF', |
|
| 121 | + 'maroon' => '800000', |
|
| 122 | + 'mediumaquamarine' => '66CDAA', |
|
| 123 | + 'mediumblue' => '0000CD', |
|
| 124 | + 'mediumorchid' => 'BA55D3', |
|
| 125 | + 'mediumpurple' => '9370DB', |
|
| 126 | + 'mediumseagreen' => '3CB371', |
|
| 127 | + 'mediumslateblue' => '7B68EE', |
|
| 128 | + 'mediumspringgreen' => '00FA9A', |
|
| 129 | + 'mediumturquoise' => '48D1CC', |
|
| 130 | + 'mediumvioletred' => 'C71585', |
|
| 131 | + 'midnightblue' => '191970', |
|
| 132 | + 'mintcream' => 'F5FFFA', |
|
| 133 | + 'mistyrose' => 'FFE4E1', |
|
| 134 | + 'moccasin' => 'FFE4B5', |
|
| 135 | + 'navajowhite' => 'FFDEAD', |
|
| 136 | + 'navy' => '000080', |
|
| 137 | + 'oldlace' => 'FDF5E6', |
|
| 138 | + 'olive' => '808000', |
|
| 139 | + 'olivedrab' => '6B8E23', |
|
| 140 | + 'orange' => 'FFA500', |
|
| 141 | + 'orangered' => 'FF4500', |
|
| 142 | + 'orchid' => 'DA70D6', |
|
| 143 | + 'palegoldenrod' => 'EEE8AA', |
|
| 144 | + 'palegreen' => '98FB98', |
|
| 145 | + 'paleturquoise' => 'AFEEEE', |
|
| 146 | + 'palevioletred' => 'DB7093', |
|
| 147 | + 'papayawhip' => 'FFEFD5', |
|
| 148 | + 'peachpuff' => 'FFDAB9', |
|
| 149 | + 'peru' => 'CD853F', |
|
| 150 | + 'pink' => 'FFC0CB', |
|
| 151 | + 'plum' => 'DDA0DD', |
|
| 152 | + 'powderblue' => 'B0E0E6', |
|
| 153 | + 'purple' => '800080', |
|
| 154 | + 'rebeccapurple' => '663399', |
|
| 155 | + 'red' => 'FF0000', |
|
| 156 | + 'rosybrown' => 'BC8F8F', |
|
| 157 | + 'royalblue' => '4169E1', |
|
| 158 | + 'saddlebrown' => '8B4513', |
|
| 159 | + 'salmon' => 'FA8072', |
|
| 160 | + 'sandybrown' => 'F4A460', |
|
| 161 | + 'seagreen' => '2E8B57', |
|
| 162 | + 'seashell' => 'FFF5EE', |
|
| 163 | + 'sienna' => 'A0522D', |
|
| 164 | + 'silver' => 'C0C0C0', |
|
| 165 | + 'skyblue' => '87CEEB', |
|
| 166 | + 'slateblue' => '6A5ACD', |
|
| 167 | + 'slategray' => '708090', |
|
| 168 | + 'slategrey' => '708090', |
|
| 169 | + 'snow' => 'FFFAFA', |
|
| 170 | + 'springgreen' => '00FF7F', |
|
| 171 | + 'steelblue' => '4682B4', |
|
| 172 | + 'tan' => 'D2B48C', |
|
| 173 | + 'teal' => '008080', |
|
| 174 | + 'thistle' => 'D8BFD8', |
|
| 175 | + 'tomato' => 'FF6347', |
|
| 176 | + 'turquoise' => '40E0D0', |
|
| 177 | + 'violet' => 'EE82EE', |
|
| 178 | + 'wheat' => 'F5DEB3', |
|
| 179 | + 'white' => 'FFFFFF', |
|
| 180 | + 'whitesmoke' => 'F5F5F5', |
|
| 181 | + 'yellow' => 'FFFF00', |
|
| 182 | + 'yellowgreen' => '9ACD32', |
|
| 183 | + ]; |
|
| 184 | + if (isset($couleurs_html[$lc = strtolower($couleur)])) { |
|
| 185 | + return $couleurs_html[$lc]; |
|
| 186 | + } |
|
| 187 | + |
|
| 188 | + return $couleur; |
|
| 189 | 189 | } |
| 190 | 190 | |
| 191 | 191 | /** |
@@ -201,16 +201,16 @@ discard block |
||
| 201 | 201 | * @return string Couleur tel que "hsl(200, 40%, 34%)" ou valeur formattée |
| 202 | 202 | */ |
| 203 | 203 | function couleur_hex_to_hsl($couleur, $format = null) { |
| 204 | - $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | - $hsl = [ |
|
| 206 | - 'h' => round($hsl['h'] * 360), |
|
| 207 | - 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | - 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | - ]; |
|
| 210 | - if ($format === null) { |
|
| 211 | - return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | - } |
|
| 213 | - return str_replace(array_keys($hsl), $hsl, $format); |
|
| 204 | + $hsl = _couleur_hex_to_hsl($couleur); |
|
| 205 | + $hsl = [ |
|
| 206 | + 'h' => round($hsl['h'] * 360), |
|
| 207 | + 's' => round($hsl['s'] * 100) . '%', |
|
| 208 | + 'l' => round($hsl['l'] * 100) . '%' |
|
| 209 | + ]; |
|
| 210 | + if ($format === null) { |
|
| 211 | + return "hsl({$hsl['h']}, {$hsl['s']}, {$hsl['l']})"; |
|
| 212 | + } |
|
| 213 | + return str_replace(array_keys($hsl), $hsl, $format); |
|
| 214 | 214 | } |
| 215 | 215 | |
| 216 | 216 | |
@@ -227,16 +227,16 @@ discard block |
||
| 227 | 227 | * @return string Couleur tel que "rgb(200, 40, 84)" ou valeur formattée |
| 228 | 228 | */ |
| 229 | 229 | function couleur_hex_to_rgb($couleur, $format = null) { |
| 230 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | - $rgb = [ |
|
| 232 | - 'r' => $rgb['red'], |
|
| 233 | - 'g' => $rgb['green'], |
|
| 234 | - 'b' => $rgb['blue'], |
|
| 235 | - ]; |
|
| 236 | - if ($format === null) { |
|
| 237 | - return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | - } |
|
| 239 | - return str_replace(array_keys($rgb), $rgb, $format); |
|
| 230 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 231 | + $rgb = [ |
|
| 232 | + 'r' => $rgb['red'], |
|
| 233 | + 'g' => $rgb['green'], |
|
| 234 | + 'b' => $rgb['blue'], |
|
| 235 | + ]; |
|
| 236 | + if ($format === null) { |
|
| 237 | + return "rgb({$rgb['r']}, {$rgb['g']}, {$rgb['b']})"; |
|
| 238 | + } |
|
| 239 | + return str_replace(array_keys($rgb), $rgb, $format); |
|
| 240 | 240 | } |
| 241 | 241 | |
| 242 | 242 | /** |
@@ -252,15 +252,15 @@ discard block |
||
| 252 | 252 | * Code hexadécimal de la couleur plus foncée |
| 253 | 253 | */ |
| 254 | 254 | function couleur_foncer($couleur, $coeff = 0.5) { |
| 255 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 255 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 256 | 256 | |
| 257 | - $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | - $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | - $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 257 | + $red = $couleurs['red'] - round(($couleurs['red']) * $coeff); |
|
| 258 | + $green = $couleurs['green'] - round(($couleurs['green']) * $coeff); |
|
| 259 | + $blue = $couleurs['blue'] - round(($couleurs['blue']) * $coeff); |
|
| 260 | 260 | |
| 261 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 261 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 262 | 262 | |
| 263 | - return $couleur; |
|
| 263 | + return $couleur; |
|
| 264 | 264 | } |
| 265 | 265 | |
| 266 | 266 | /** |
@@ -276,15 +276,15 @@ discard block |
||
| 276 | 276 | * Code hexadécimal de la couleur éclaircie |
| 277 | 277 | */ |
| 278 | 278 | function couleur_eclaircir($couleur, $coeff = 0.5) { |
| 279 | - $couleurs = _couleur_hex_to_dec($couleur); |
|
| 279 | + $couleurs = _couleur_hex_to_dec($couleur); |
|
| 280 | 280 | |
| 281 | - $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | - $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | - $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 281 | + $red = $couleurs['red'] + round((255 - $couleurs['red']) * $coeff); |
|
| 282 | + $green = $couleurs['green'] + round((255 - $couleurs['green']) * $coeff); |
|
| 283 | + $blue = $couleurs['blue'] + round((255 - $couleurs['blue']) * $coeff); |
|
| 284 | 284 | |
| 285 | - $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 285 | + $couleur = _couleur_dec_to_hex($red, $green, $blue); |
|
| 286 | 286 | |
| 287 | - return $couleur; |
|
| 287 | + return $couleur; |
|
| 288 | 288 | } |
| 289 | 289 | |
| 290 | 290 | /** |
@@ -307,28 +307,28 @@ discard block |
||
| 307 | 307 | * Le tag html `<img src=... />` avec une class `filtre_inactif` ou pas |
| 308 | 308 | */ |
| 309 | 309 | function image_select($img, $width_min = 0, $height_min = 0, $width_max = 10000, $height_max = 1000) { |
| 310 | - if (!$img) { |
|
| 311 | - return $img; |
|
| 312 | - } |
|
| 313 | - [$h, $l] = taille_image($img); |
|
| 314 | - $select = true; |
|
| 315 | - if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | - $select = false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $class = extraire_attribut($img, 'class'); |
|
| 320 | - $p = strpos($class, 'filtre_inactif'); |
|
| 321 | - if (($select == false) and ($p === false)) { |
|
| 322 | - $class .= ' filtre_inactif'; |
|
| 323 | - $img = inserer_attribut($img, 'class', $class); |
|
| 324 | - } |
|
| 325 | - if (($select == true) and ($p !== false)) { |
|
| 326 | - // no_image_filtrer : historique, a virer |
|
| 327 | - $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | - $img = inserer_attribut($img, 'class', $class); |
|
| 329 | - } |
|
| 330 | - |
|
| 331 | - return $img; |
|
| 310 | + if (!$img) { |
|
| 311 | + return $img; |
|
| 312 | + } |
|
| 313 | + [$h, $l] = taille_image($img); |
|
| 314 | + $select = true; |
|
| 315 | + if ($l < $width_min or $l > $width_max or $h < $height_min or $h > $height_max) { |
|
| 316 | + $select = false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $class = extraire_attribut($img, 'class'); |
|
| 320 | + $p = strpos($class, 'filtre_inactif'); |
|
| 321 | + if (($select == false) and ($p === false)) { |
|
| 322 | + $class .= ' filtre_inactif'; |
|
| 323 | + $img = inserer_attribut($img, 'class', $class); |
|
| 324 | + } |
|
| 325 | + if (($select == true) and ($p !== false)) { |
|
| 326 | + // no_image_filtrer : historique, a virer |
|
| 327 | + $class = preg_replace(',\s*(filtre_inactif|no_image_filtrer),', '', $class); |
|
| 328 | + $img = inserer_attribut($img, 'class', $class); |
|
| 329 | + } |
|
| 330 | + |
|
| 331 | + return $img; |
|
| 332 | 332 | } |
| 333 | 333 | |
| 334 | 334 | /** |
@@ -376,45 +376,45 @@ discard block |
||
| 376 | 376 | * Code HTML de l'image ou du texte. |
| 377 | 377 | **/ |
| 378 | 378 | function image_passe_partout( |
| 379 | - $img, |
|
| 380 | - $taille_x = -1, |
|
| 381 | - $taille_y = -1, |
|
| 382 | - $force = false, |
|
| 383 | - $cherche_image = false, |
|
| 384 | - $process = 'AUTO' |
|
| 379 | + $img, |
|
| 380 | + $taille_x = -1, |
|
| 381 | + $taille_y = -1, |
|
| 382 | + $force = false, |
|
| 383 | + $cherche_image = false, |
|
| 384 | + $process = 'AUTO' |
|
| 385 | 385 | ) { |
| 386 | - // PHP 7+ type hint |
|
| 387 | - $img = (string)$img; |
|
| 388 | - $taille_x = (int)$taille_x; |
|
| 389 | - $taille_y = (int)$taille_y; |
|
| 390 | - $force = (bool)$force; |
|
| 391 | - $process = (string)$process; |
|
| 392 | - |
|
| 393 | - if (!$img) { |
|
| 394 | - return ''; |
|
| 395 | - } |
|
| 396 | - [$hauteur, $largeur] = taille_image($img); |
|
| 397 | - if ($taille_x === -1) { |
|
| 398 | - $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | - } |
|
| 400 | - if ($taille_y === -1) { |
|
| 401 | - $taille_y = $taille_x; |
|
| 402 | - } |
|
| 403 | - |
|
| 404 | - if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | - $taille_x = 1; |
|
| 406 | - } # {0,300} -> c'est 300 qui compte |
|
| 407 | - elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | - $taille_y = 1; |
|
| 409 | - } # {300,0} -> c'est 300 qui compte |
|
| 410 | - elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | - return ''; |
|
| 412 | - } |
|
| 413 | - |
|
| 414 | - [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | - $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | - |
|
| 417 | - return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 386 | + // PHP 7+ type hint |
|
| 387 | + $img = (string)$img; |
|
| 388 | + $taille_x = (int)$taille_x; |
|
| 389 | + $taille_y = (int)$taille_y; |
|
| 390 | + $force = (bool)$force; |
|
| 391 | + $process = (string)$process; |
|
| 392 | + |
|
| 393 | + if (!$img) { |
|
| 394 | + return ''; |
|
| 395 | + } |
|
| 396 | + [$hauteur, $largeur] = taille_image($img); |
|
| 397 | + if ($taille_x === -1) { |
|
| 398 | + $taille_x = $GLOBALS['meta']['taille_preview'] ?? 150; |
|
| 399 | + } |
|
| 400 | + if ($taille_y === -1) { |
|
| 401 | + $taille_y = $taille_x; |
|
| 402 | + } |
|
| 403 | + |
|
| 404 | + if ($taille_x === 0 and $taille_y > 0) { |
|
| 405 | + $taille_x = 1; |
|
| 406 | + } # {0,300} -> c'est 300 qui compte |
|
| 407 | + elseif ($taille_x > 0 and $taille_y === 0) { |
|
| 408 | + $taille_y = 1; |
|
| 409 | + } # {300,0} -> c'est 300 qui compte |
|
| 410 | + elseif ($taille_x == 0 and $taille_y === 0) { |
|
| 411 | + return ''; |
|
| 412 | + } |
|
| 413 | + |
|
| 414 | + [$destWidth, $destHeight, $ratio] = ratio_passe_partout($largeur ?? 0, $hauteur ?? 0, $taille_x, $taille_y); |
|
| 415 | + $fonction = ['image_passe_partout', func_get_args()]; |
|
| 416 | + |
|
| 417 | + return process_image_reduire($fonction, $img, $destWidth, $destHeight, $force, $process); |
|
| 418 | 418 | } |
| 419 | 419 | |
| 420 | 420 | /** |
@@ -457,44 +457,44 @@ discard block |
||
| 457 | 457 | * Code HTML de l'image ou du texte. |
| 458 | 458 | **/ |
| 459 | 459 | function image_reduire( |
| 460 | - $img, |
|
| 461 | - $taille = -1, |
|
| 462 | - $taille_y = -1, |
|
| 463 | - $force = false, |
|
| 464 | - $cherche_image = false, |
|
| 465 | - $process = 'AUTO' |
|
| 460 | + $img, |
|
| 461 | + $taille = -1, |
|
| 462 | + $taille_y = -1, |
|
| 463 | + $force = false, |
|
| 464 | + $cherche_image = false, |
|
| 465 | + $process = 'AUTO' |
|
| 466 | 466 | ) { |
| 467 | - // PHP 7+ type hint |
|
| 468 | - $img = (string)$img; |
|
| 469 | - $taille = (int)$taille; |
|
| 470 | - $taille_y = (int)$taille_y; |
|
| 471 | - $force = (bool)$force; |
|
| 472 | - $process = (string)$process; |
|
| 473 | - |
|
| 474 | - // Determiner la taille x,y maxi |
|
| 475 | - // prendre le reglage de previsu par defaut |
|
| 476 | - if ($taille === -1) { |
|
| 477 | - $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | - ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | - : 150; |
|
| 480 | - } |
|
| 481 | - if ($taille_y === -1) { |
|
| 482 | - $taille_y = $taille; |
|
| 483 | - } |
|
| 484 | - |
|
| 485 | - if ($taille === 0 and $taille_y > 0) { |
|
| 486 | - $taille = 10000; |
|
| 487 | - } # {0,300} -> c'est 300 qui compte |
|
| 488 | - elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | - $taille_y = 10000; |
|
| 490 | - } # {300,0} -> c'est 300 qui compte |
|
| 491 | - elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | - return ''; |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | - |
|
| 497 | - return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 467 | + // PHP 7+ type hint |
|
| 468 | + $img = (string)$img; |
|
| 469 | + $taille = (int)$taille; |
|
| 470 | + $taille_y = (int)$taille_y; |
|
| 471 | + $force = (bool)$force; |
|
| 472 | + $process = (string)$process; |
|
| 473 | + |
|
| 474 | + // Determiner la taille x,y maxi |
|
| 475 | + // prendre le reglage de previsu par defaut |
|
| 476 | + if ($taille === -1) { |
|
| 477 | + $taille = (isset($GLOBALS['meta']['taille_preview']) and intval($GLOBALS['meta']['taille_preview'])) |
|
| 478 | + ? intval($GLOBALS['meta']['taille_preview']) |
|
| 479 | + : 150; |
|
| 480 | + } |
|
| 481 | + if ($taille_y === -1) { |
|
| 482 | + $taille_y = $taille; |
|
| 483 | + } |
|
| 484 | + |
|
| 485 | + if ($taille === 0 and $taille_y > 0) { |
|
| 486 | + $taille = 10000; |
|
| 487 | + } # {0,300} -> c'est 300 qui compte |
|
| 488 | + elseif ($taille > 0 and $taille_y === 0) { |
|
| 489 | + $taille_y = 10000; |
|
| 490 | + } # {300,0} -> c'est 300 qui compte |
|
| 491 | + elseif ($taille == 0 and $taille_y === 0) { |
|
| 492 | + return ''; |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + $fonction = ['image_reduire', func_get_args()]; |
|
| 496 | + |
|
| 497 | + return process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process); |
|
| 498 | 498 | } |
| 499 | 499 | |
| 500 | 500 | /** |
@@ -505,16 +505,16 @@ discard block |
||
| 505 | 505 | * |
| 506 | 506 | **/ |
| 507 | 507 | function image_recadre_avec_fallback( |
| 508 | - $im, |
|
| 509 | - $width, |
|
| 510 | - $height = '-', |
|
| 511 | - $position = 'focus', |
|
| 512 | - $background_color = 'white' |
|
| 508 | + $im, |
|
| 509 | + $width, |
|
| 510 | + $height = '-', |
|
| 511 | + $position = 'focus', |
|
| 512 | + $background_color = 'white' |
|
| 513 | 513 | ) { |
| 514 | - if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | - return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | - } else { return image_passe_partout($im, $width, $height); |
|
| 517 | - } |
|
| 514 | + if (function_exists('image_recadre') && ($GLOBALS['meta']['image_process'] ?? '') === 'gd2') { |
|
| 515 | + return image_reduire(image_recadre($im, $width . ':' . $height, '-', $position, $background_color), $width, $height); |
|
| 516 | + } else { return image_passe_partout($im, $width, $height); |
|
| 517 | + } |
|
| 518 | 518 | } |
| 519 | 519 | |
| 520 | 520 | /** |
@@ -532,25 +532,25 @@ discard block |
||
| 532 | 532 | * Code HTML de l'image ou du texte. |
| 533 | 533 | **/ |
| 534 | 534 | function image_reduire_par($img, $val = 1, $force = false) { |
| 535 | - // PHP 7+ type hint |
|
| 536 | - $img = (string)$img; |
|
| 537 | - $val = (int)$val; |
|
| 538 | - $force = (bool)$force; |
|
| 535 | + // PHP 7+ type hint |
|
| 536 | + $img = (string)$img; |
|
| 537 | + $val = (int)$val; |
|
| 538 | + $force = (bool)$force; |
|
| 539 | 539 | |
| 540 | - [$hauteur, $largeur] = taille_image($img); |
|
| 540 | + [$hauteur, $largeur] = taille_image($img); |
|
| 541 | 541 | |
| 542 | - $l = round($largeur / $val); |
|
| 543 | - $h = round($hauteur / $val); |
|
| 542 | + $l = round($largeur / $val); |
|
| 543 | + $h = round($hauteur / $val); |
|
| 544 | 544 | |
| 545 | - if ($l > $h) { |
|
| 546 | - $h = 0; |
|
| 547 | - } else { |
|
| 548 | - $l = 0; |
|
| 549 | - } |
|
| 545 | + if ($l > $h) { |
|
| 546 | + $h = 0; |
|
| 547 | + } else { |
|
| 548 | + $l = 0; |
|
| 549 | + } |
|
| 550 | 550 | |
| 551 | - $img = image_reduire($img, $l, $h, $force); |
|
| 551 | + $img = image_reduire($img, $l, $h, $force); |
|
| 552 | 552 | |
| 553 | - return $img; |
|
| 553 | + return $img; |
|
| 554 | 554 | } |
| 555 | 555 | |
| 556 | 556 | /** |
@@ -573,10 +573,10 @@ discard block |
||
| 573 | 573 | * Couleur en écriture hexadécimale. |
| 574 | 574 | **/ |
| 575 | 575 | function filtre_couleur_saturation_dist($couleur, $val, $strict = false) { |
| 576 | - if (function_exists('couleur_saturation')) { |
|
| 577 | - return couleur_saturation($couleur, $val, $strict); |
|
| 578 | - } |
|
| 579 | - return $couleur; |
|
| 576 | + if (function_exists('couleur_saturation')) { |
|
| 577 | + return couleur_saturation($couleur, $val, $strict); |
|
| 578 | + } |
|
| 579 | + return $couleur; |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | /** |
@@ -597,8 +597,8 @@ discard block |
||
| 597 | 597 | * Couleur en écriture hexadécimale. |
| 598 | 598 | **/ |
| 599 | 599 | function filtre_couleur_luminance_dist($couleur, $val) { |
| 600 | - if (function_exists('couleur_luminance')) { |
|
| 601 | - return couleur_luminance($couleur, $val); |
|
| 602 | - } |
|
| 603 | - return $couleur; |
|
| 600 | + if (function_exists('couleur_luminance')) { |
|
| 601 | + return couleur_luminance($couleur, $val); |
|
| 602 | + } |
|
| 603 | + return $couleur; |
|
| 604 | 604 | } |