@@ -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 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 116 | - return $attributs; |
|
| 117 | - } |
|
| 114 | + if ($svg_infos = svg_lire_balise_svg($img)) { |
|
| 115 | + list($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 | - list($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 | + list($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 | - list($balise_svg, $attributs) = $svg_infos; |
|
| 363 | + if ( |
|
| 364 | + $svg = svg_charger($img) |
|
| 365 | + and $svg_infos = svg_lire_balise_svg($svg) |
|
| 366 | + ) { |
|
| 367 | + list($balise_svg, $attributs) = $svg_infos; |
|
| 368 | 368 | |
| 369 | - list($width, $height, $viewBox) = svg_getimagesize_from_attr($attributs); |
|
| 369 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 | - list($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 | + list($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 = array_merge($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 = array_merge($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 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | return $fichier; |
| 57 | 57 | } |
| 58 | 58 | if (!file_exists($fichier)) { |
| 59 | - $fichier = supprimer_timestamp($fichier); |
|
| 59 | + $fichier = supprimer_timestamp($fichier); |
|
| 60 | 60 | if (!file_exists($fichier)) { |
| 61 | 61 | return false; |
| 62 | 62 | } |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | function svg_change_balise_svg($svg, $old_balise_svg, $attributs) { |
| 171 | 171 | $new_balise_svg = '<svg'; |
| 172 | 172 | foreach ($attributs as $k => $v) { |
| 173 | - $new_balise_svg .= " $k=\"" . entites_html($v) . '"'; |
|
| 173 | + $new_balise_svg .= " $k=\"".entites_html($v).'"'; |
|
| 174 | 174 | } |
| 175 | 175 | $new_balise_svg .= '>'; |
| 176 | 176 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | function svg_insert_shapes($svg, $shapes, $start = true) { |
| 190 | 190 | |
| 191 | 191 | if ($start === false or $start === 'end') { |
| 192 | - $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
|
| 192 | + $svg = str_replace('</svg>', $shapes.'</svg>', $svg); |
|
| 193 | 193 | } |
| 194 | 194 | else { |
| 195 | 195 | $p = stripos($svg, '<svg'); |
@@ -210,10 +210,10 @@ discard block |
||
| 210 | 210 | */ |
| 211 | 211 | function svg_clip_in_box($svg, $x, $y, $width, $height) { |
| 212 | 212 | $rect = "<rect x=\"$x\" y=\"$y\" width=\"$width\" height=\"$height\" />"; |
| 213 | - $id = 'clip-' . substr(md5($rect . strlen($svg)), 0, 8); |
|
| 213 | + $id = 'clip-'.substr(md5($rect.strlen($svg)), 0, 8); |
|
| 214 | 214 | $clippath = "<clipPath id=\"$id\">$rect</clipPath>"; |
| 215 | 215 | $g = "<g clip-path=\"url(#$id)\">"; |
| 216 | - $svg = svg_insert_shapes($svg, $clippath . $g); |
|
| 216 | + $svg = svg_insert_shapes($svg, $clippath.$g); |
|
| 217 | 217 | $svg = svg_insert_shapes($svg, '</g>', false); |
| 218 | 218 | return $svg; |
| 219 | 219 | } |
@@ -232,7 +232,7 @@ discard block |
||
| 232 | 232 | ) { |
| 233 | 233 | list($balise_svg, $attributs) = $svg_infos; |
| 234 | 234 | if (!isset($attributs['viewBox'])) { |
| 235 | - $attributs['viewBox'] = '0 0 ' . $attributs['width'] . ' ' . $attributs['height']; |
|
| 235 | + $attributs['viewBox'] = '0 0 '.$attributs['width'].' '.$attributs['height']; |
|
| 236 | 236 | } |
| 237 | 237 | $attributs['width'] = strval($new_width); |
| 238 | 238 | $attributs['height'] = strval($new_height); |
@@ -257,7 +257,7 @@ discard block |
||
| 257 | 257 | else { |
| 258 | 258 | $couleur = couleur_html_to_hex($couleur); |
| 259 | 259 | } |
| 260 | - $couleur = '#' . ltrim($couleur, '#'); |
|
| 260 | + $couleur = '#'.ltrim($couleur, '#'); |
|
| 261 | 261 | return $couleur; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -269,7 +269,7 @@ discard block |
||
| 269 | 269 | function svg_couleur_to_rgb($couleur) { |
| 270 | 270 | if (strpos($couleur, 'rgb(') === 0) { |
| 271 | 271 | $c = explode(',', substr($couleur, 4)); |
| 272 | - return ['red' => intval($c[0]),'green' => intval($c[1]),'blue' => intval($c[2])]; |
|
| 272 | + return ['red' => intval($c[0]), 'green' => intval($c[1]), 'blue' => intval($c[2])]; |
|
| 273 | 273 | } |
| 274 | 274 | return _couleur_hex_to_dec($couleur); |
| 275 | 275 | } |
@@ -474,7 +474,7 @@ discard block |
||
| 474 | 474 | $background_color = svg_couleur_to_hexa($background_color); |
| 475 | 475 | if (isset($attributs['viewBox'])) { |
| 476 | 476 | $viewBox = explode(' ', $attributs['viewBox']); |
| 477 | - $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
|
| 477 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\"/>"; |
|
| 478 | 478 | } |
| 479 | 479 | else { |
| 480 | 480 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | $background_color = svg_couleur_to_hexa($background_color); |
| 505 | 505 | if (isset($attributs['viewBox'])) { |
| 506 | 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\"/>"; |
|
| 507 | + $rect = '<rect x="'.$viewBox[0].'" y="'.$viewBox[1].'" width="'.$viewBox[2].'" height="'.$viewBox[3]."\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
|
| 508 | 508 | } |
| 509 | 509 | else { |
| 510 | 510 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
@@ -529,11 +529,11 @@ discard block |
||
| 529 | 529 | and $svg_infos = svg_lire_balise_svg($svg) |
| 530 | 530 | ) { |
| 531 | 531 | if ($attributs) { |
| 532 | - list($balise_svg, ) = $svg_infos; |
|
| 532 | + list($balise_svg,) = $svg_infos; |
|
| 533 | 533 | $g = '<g'; |
| 534 | 534 | foreach ($attributs as $k => $v) { |
| 535 | 535 | if (strlen($v)) { |
| 536 | - $g .= " $k=\"" . attribut_html($v) . '"'; |
|
| 536 | + $g .= " $k=\"".attribut_html($v).'"'; |
|
| 537 | 537 | } |
| 538 | 538 | } |
| 539 | 539 | if (strlen($g) > 2) { |
@@ -560,11 +560,11 @@ discard block |
||
| 560 | 560 | and $svg_infos = svg_lire_balise_svg($svg) |
| 561 | 561 | ) { |
| 562 | 562 | if ($filter_def) { |
| 563 | - list($balise_svg, ) = $svg_infos; |
|
| 564 | - $filter_id = 'filter-' . substr(md5($filter_def . strlen($svg)), 0, 8); |
|
| 563 | + list($balise_svg,) = $svg_infos; |
|
| 564 | + $filter_id = 'filter-'.substr(md5($filter_def.strlen($svg)), 0, 8); |
|
| 565 | 565 | $filter = "<defs><filter id=\"$filter_id\">$filter_def</filter></defs>"; |
| 566 | 566 | $g = "<g filter=\"url(#$filter_id)\">"; |
| 567 | - $svg = svg_insert_shapes($svg, $filter . $g); |
|
| 567 | + $svg = svg_insert_shapes($svg, $filter.$g); |
|
| 568 | 568 | $svg = svg_insert_shapes($svg, '</g>', false); |
| 569 | 569 | } |
| 570 | 570 | return $svg; |
@@ -63,8 +63,7 @@ discard block |
||
| 63 | 63 | } |
| 64 | 64 | if (is_null($maxlen)) { |
| 65 | 65 | $image = file_get_contents($fichier); |
| 66 | - } |
|
| 67 | - else { |
|
| 66 | + } else { |
|
| 68 | 67 | $image = file_get_contents($fichier, false, null, 0, $maxlen); |
| 69 | 68 | } |
| 70 | 69 | // est-ce bien une image svg ? |
@@ -190,8 +189,7 @@ discard block |
||
| 190 | 189 | |
| 191 | 190 | if ($start === false or $start === 'end') { |
| 192 | 191 | $svg = str_replace('</svg>', $shapes . '</svg>', $svg); |
| 193 | - } |
|
| 194 | - else { |
|
| 192 | + } else { |
|
| 195 | 193 | $p = stripos($svg, '<svg'); |
| 196 | 194 | $p = strpos($svg, '>', $p); |
| 197 | 195 | $svg = substr_replace($svg, $shapes, $p + 1, 0); |
@@ -253,8 +251,7 @@ discard block |
||
| 253 | 251 | if (strpos($couleur, 'rgb(') === 0) { |
| 254 | 252 | $c = explode(',', substr($couleur, 4)); |
| 255 | 253 | $couleur = _couleur_dec_to_hex(intval($c[0]), intval($c[1]), intval($c[2])); |
| 256 | - } |
|
| 257 | - else { |
|
| 254 | + } else { |
|
| 258 | 255 | $couleur = couleur_html_to_hex($couleur); |
| 259 | 256 | } |
| 260 | 257 | $couleur = '#' . ltrim($couleur, '#'); |
@@ -305,17 +302,14 @@ discard block |
||
| 305 | 302 | and $w = svg_dimension_to_pixels($attributs['width']) |
| 306 | 303 | ) { |
| 307 | 304 | $width = $w; |
| 308 | - } |
|
| 309 | - else { |
|
| 305 | + } else { |
|
| 310 | 306 | // si on recupere la taille de la viewbox mais si la viewbox est petite on met un multiplicateur pour la taille finale |
| 311 | 307 | $width = $viewBox[2]; |
| 312 | 308 | if ($width < 1) { |
| 313 | 309 | $coeff = max($coeff, 1000); |
| 314 | - } |
|
| 315 | - elseif ($width < 10) { |
|
| 310 | + } elseif ($width < 10) { |
|
| 316 | 311 | $coeff = max($coeff, 100); |
| 317 | - } |
|
| 318 | - elseif ($width < 100) { |
|
| 312 | + } elseif ($width < 100) { |
|
| 319 | 313 | $coeff = max($coeff, 10); |
| 320 | 314 | } |
| 321 | 315 | } |
@@ -324,16 +318,13 @@ discard block |
||
| 324 | 318 | and $h = svg_dimension_to_pixels($attributs['height']) |
| 325 | 319 | ) { |
| 326 | 320 | $height = $h; |
| 327 | - } |
|
| 328 | - else { |
|
| 321 | + } else { |
|
| 329 | 322 | $height = $viewBox[3]; |
| 330 | 323 | if ($height < 1) { |
| 331 | 324 | $coeff = max($coeff, 1000); |
| 332 | - } |
|
| 333 | - elseif ($height < 10) { |
|
| 325 | + } elseif ($height < 10) { |
|
| 334 | 326 | $coeff = max($coeff, 100); |
| 335 | - } |
|
| 336 | - elseif ($height < 100) { |
|
| 327 | + } elseif ($height < 100) { |
|
| 337 | 328 | $coeff = max($coeff, 10); |
| 338 | 329 | } |
| 339 | 330 | } |
@@ -475,8 +466,7 @@ discard block |
||
| 475 | 466 | if (isset($attributs['viewBox'])) { |
| 476 | 467 | $viewBox = explode(' ', $attributs['viewBox']); |
| 477 | 468 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\"/>"; |
| 478 | - } |
|
| 479 | - else { |
|
| 469 | + } else { |
|
| 480 | 470 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 481 | 471 | } |
| 482 | 472 | $svg = svg_insert_shapes($svg, $rect); |
@@ -505,8 +495,7 @@ discard block |
||
| 505 | 495 | if (isset($attributs['viewBox'])) { |
| 506 | 496 | $viewBox = explode(' ', $attributs['viewBox']); |
| 507 | 497 | $rect = '<rect x="' . $viewBox[0] . '" y="' . $viewBox[1] . '" width="' . $viewBox[2] . '" height="' . $viewBox[3] . "\" fill=\"$background_color\" opacity=\"$opacity\"/>"; |
| 508 | - } |
|
| 509 | - else { |
|
| 498 | + } else { |
|
| 510 | 499 | $rect = "<rect width=\"100%\" height=\"100%\" fill=\"$background_color\"/>"; |
| 511 | 500 | } |
| 512 | 501 | $svg = svg_insert_shapes($svg, $rect, false); |
@@ -627,8 +616,7 @@ discard block |
||
| 627 | 616 | $x = intval($viewBox[0]) + intval($viewBox[2] / 2); |
| 628 | 617 | $mx = -$x; |
| 629 | 618 | $transform = "translate($x, 0) $transform translate($mx, 0)"; |
| 630 | - } |
|
| 631 | - else { |
|
| 619 | + } else { |
|
| 632 | 620 | $transform = 'scale(1,-1)'; |
| 633 | 621 | |
| 634 | 622 | $y = intval($viewBox[1]) + intval($viewBox[3] / 2); |
@@ -689,8 +677,7 @@ discard block |
||
| 689 | 677 | $c = array_shift($colors); |
| 690 | 678 | if (strlen($c) == 4) { |
| 691 | 679 | $short[] = $c; |
| 692 | - } |
|
| 693 | - else { |
|
| 680 | + } else { |
|
| 694 | 681 | $long[] = $c; |
| 695 | 682 | } |
| 696 | 683 | } |
@@ -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 | |
@@ -40,29 +40,29 @@ discard block |
||
| 40 | 40 | * Code HTML de la liste |
| 41 | 41 | */ |
| 42 | 42 | function inc_lister_objets_dist($vue, $contexte = [], $force = false) { |
| 43 | - $res = ''; // debug |
|
| 44 | - if (!is_array($contexte)) { |
|
| 45 | - return _L('$contexte doit etre un tableau dans inc/lister_objets'); |
|
| 46 | - } |
|
| 43 | + $res = ''; // debug |
|
| 44 | + if (!is_array($contexte)) { |
|
| 45 | + return _L('$contexte doit etre un tableau dans inc/lister_objets'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $fond = "prive/objets/liste/$vue"; |
|
| 49 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 50 | - // traiter les cas particuliers |
|
| 51 | - include_spip('base/connect_sql'); |
|
| 52 | - $vue = table_objet($vue); |
|
| 53 | - $fond = "prive/objets/liste/$vue"; |
|
| 54 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 55 | - return _L("vue $vue introuvable pour lister les objets"); |
|
| 56 | - } |
|
| 57 | - } |
|
| 48 | + $fond = "prive/objets/liste/$vue"; |
|
| 49 | + if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 50 | + // traiter les cas particuliers |
|
| 51 | + include_spip('base/connect_sql'); |
|
| 52 | + $vue = table_objet($vue); |
|
| 53 | + $fond = "prive/objets/liste/$vue"; |
|
| 54 | + if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 55 | + return _L("vue $vue introuvable pour lister les objets"); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - $contexte['sinon'] = ($force ? $contexte['titre'] : ''); |
|
| 60 | + $contexte['sinon'] = ($force ? $contexte['titre'] : ''); |
|
| 61 | 61 | |
| 62 | - $res = recuperer_fond($fond, $contexte, ['ajax' => true]); |
|
| 63 | - if (_request('var_liste')) { |
|
| 64 | - echo var_export($contexte, true); |
|
| 65 | - } |
|
| 62 | + $res = recuperer_fond($fond, $contexte, ['ajax' => true]); |
|
| 63 | + if (_request('var_liste')) { |
|
| 64 | + echo var_export($contexte, true); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return $res; |
|
| 67 | + return $res; |
|
| 68 | 68 | } |
@@ -46,12 +46,12 @@ |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | $fond = "prive/objets/liste/$vue"; |
| 49 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 49 | + if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) { |
|
| 50 | 50 | // traiter les cas particuliers |
| 51 | 51 | include_spip('base/connect_sql'); |
| 52 | 52 | $vue = table_objet($vue); |
| 53 | 53 | $fond = "prive/objets/liste/$vue"; |
| 54 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 54 | + if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) { |
|
| 55 | 55 | return _L("vue $vue introuvable pour lister les objets"); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -36,37 +36,37 @@ discard block |
||
| 36 | 36 | * @return string Contenu complété des scripts javascripts, dont jQuery |
| 37 | 37 | **/ |
| 38 | 38 | function f_jQuery_prive($texte) { |
| 39 | - $x = ''; |
|
| 40 | - $jquery_plugins = pipeline( |
|
| 41 | - 'jquery_plugins', |
|
| 42 | - [ |
|
| 43 | - 'prive/javascript/jquery.js', |
|
| 44 | - 'prive/javascript/jquery.form.js', |
|
| 45 | - 'prive/javascript/jquery.autosave.js', |
|
| 46 | - 'prive/javascript/jquery.placeholder-label.js', |
|
| 47 | - 'prive/javascript/ajaxCallback.js', |
|
| 48 | - 'prive/javascript/js.cookie.js', |
|
| 49 | - 'prive/javascript/jquery.cookie.js', |
|
| 50 | - 'prive/javascript/spip_barre.js', |
|
| 51 | - ] |
|
| 52 | - ); |
|
| 53 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 54 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 55 | - $script = timestamp($script); |
|
| 56 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 57 | - } |
|
| 58 | - } |
|
| 59 | - // inserer avant le premier script externe ou a la fin |
|
| 60 | - if ( |
|
| 61 | - preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 62 | - and $p = strpos($texte, $match[0]) |
|
| 63 | - ) { |
|
| 64 | - $texte = substr_replace($texte, $x, $p, 0); |
|
| 65 | - } else { |
|
| 66 | - $texte .= $x; |
|
| 67 | - } |
|
| 39 | + $x = ''; |
|
| 40 | + $jquery_plugins = pipeline( |
|
| 41 | + 'jquery_plugins', |
|
| 42 | + [ |
|
| 43 | + 'prive/javascript/jquery.js', |
|
| 44 | + 'prive/javascript/jquery.form.js', |
|
| 45 | + 'prive/javascript/jquery.autosave.js', |
|
| 46 | + 'prive/javascript/jquery.placeholder-label.js', |
|
| 47 | + 'prive/javascript/ajaxCallback.js', |
|
| 48 | + 'prive/javascript/js.cookie.js', |
|
| 49 | + 'prive/javascript/jquery.cookie.js', |
|
| 50 | + 'prive/javascript/spip_barre.js', |
|
| 51 | + ] |
|
| 52 | + ); |
|
| 53 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 54 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 55 | + $script = timestamp($script); |
|
| 56 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 57 | + } |
|
| 58 | + } |
|
| 59 | + // inserer avant le premier script externe ou a la fin |
|
| 60 | + if ( |
|
| 61 | + preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 62 | + and $p = strpos($texte, $match[0]) |
|
| 63 | + ) { |
|
| 64 | + $texte = substr_replace($texte, $x, $p, 0); |
|
| 65 | + } else { |
|
| 66 | + $texte .= $x; |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - return $texte; |
|
| 69 | + return $texte; |
|
| 70 | 70 | } |
| 71 | 71 | |
| 72 | 72 | |
@@ -79,43 +79,43 @@ discard block |
||
| 79 | 79 | * @return string |
| 80 | 80 | */ |
| 81 | 81 | function affichage_final_prive_title_auto($texte) { |
| 82 | - if ( |
|
| 83 | - strpos($texte, '<title>') === false |
|
| 84 | - and |
|
| 85 | - (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 86 | - or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 87 | - and $match = textebrut(trim($match[1])) |
|
| 88 | - and ($p = strpos($texte, '<head>')) !== false |
|
| 89 | - ) { |
|
| 90 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 91 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 92 | - } |
|
| 82 | + if ( |
|
| 83 | + strpos($texte, '<title>') === false |
|
| 84 | + and |
|
| 85 | + (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 86 | + or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 87 | + and $match = textebrut(trim($match[1])) |
|
| 88 | + and ($p = strpos($texte, '<head>')) !== false |
|
| 89 | + ) { |
|
| 90 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 91 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 92 | + } |
|
| 93 | 93 | |
| 94 | - $titre = '<title>[' |
|
| 95 | - . $nom_site_spip |
|
| 96 | - . '] ' . $match |
|
| 97 | - . '</title>'; |
|
| 94 | + $titre = '<title>[' |
|
| 95 | + . $nom_site_spip |
|
| 96 | + . '] ' . $match |
|
| 97 | + . '</title>'; |
|
| 98 | 98 | |
| 99 | - $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 100 | - } |
|
| 99 | + $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 100 | + } |
|
| 101 | 101 | |
| 102 | - return $texte; |
|
| 102 | + return $texte; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | |
| 106 | 106 | // Fonction standard pour le pipeline 'boite_infos' |
| 107 | 107 | // https://code.spip.net/@f_boite_infos |
| 108 | 108 | function f_boite_infos($flux) { |
| 109 | - $args = $flux['args']; |
|
| 110 | - $type = $args['type']; |
|
| 111 | - unset($args['row']); |
|
| 112 | - if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 113 | - $type = 'objet'; |
|
| 114 | - } |
|
| 115 | - $args['espace_prive'] = 1; |
|
| 116 | - $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 109 | + $args = $flux['args']; |
|
| 110 | + $type = $args['type']; |
|
| 111 | + unset($args['row']); |
|
| 112 | + if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 113 | + $type = 'objet'; |
|
| 114 | + } |
|
| 115 | + $args['espace_prive'] = 1; |
|
| 116 | + $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 117 | 117 | |
| 118 | - return $flux; |
|
| 118 | + return $flux; |
|
| 119 | 119 | } |
| 120 | 120 | |
| 121 | 121 | |
@@ -134,97 +134,97 @@ discard block |
||
| 134 | 134 | * @return array Données du pipeline |
| 135 | 135 | */ |
| 136 | 136 | function f_afficher_blocs_ecrire($flux) { |
| 137 | - static $o = []; |
|
| 138 | - if (is_string($fond = $flux['args']['fond'])) { |
|
| 139 | - $exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec'); |
|
| 140 | - if (!isset($o[$exec])) { |
|
| 141 | - $o[$exec] = trouver_objet_exec($exec); |
|
| 142 | - } |
|
| 143 | - // cas particulier |
|
| 144 | - if ($exec == 'infos_perso') { |
|
| 145 | - $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 146 | - } |
|
| 147 | - $typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec); |
|
| 148 | - if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 149 | - $flux['data']['texte'] = pipeline( |
|
| 150 | - 'affiche_gauche', |
|
| 151 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 152 | - ); |
|
| 153 | - } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 154 | - include_spip('inc/presentation_mini'); |
|
| 155 | - $flux['data']['texte'] = pipeline( |
|
| 156 | - 'affiche_droite', |
|
| 157 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 158 | - ) . liste_objets_bloques( |
|
| 159 | - $exec, |
|
| 160 | - $flux['args']['contexte'] |
|
| 161 | - ); |
|
| 162 | - } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 163 | - // id non defini sur les formulaire de nouveaux objets |
|
| 164 | - $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 165 | - $flux['data']['texte'] = pipeline( |
|
| 166 | - 'affiche_hierarchie', |
|
| 167 | - ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 168 | - ); |
|
| 169 | - } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 170 | - // Préparation du marqueur affiche_milieu |
|
| 171 | - // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 172 | - $est_page_objet = !empty($o[$exec]['type']); |
|
| 173 | - $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 174 | - $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 175 | - $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 176 | - $flux['data']['texte'], |
|
| 177 | - '<!--affiche_milieu-->', |
|
| 178 | - '<div id=["\']wysiwyg', |
|
| 179 | - $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 180 | - $encapsuler_milieu ? '</div>' : '' |
|
| 181 | - ); |
|
| 182 | - if ( |
|
| 183 | - $o[$exec] |
|
| 184 | - and $objet = $o[$exec]['type'] |
|
| 185 | - and $o[$exec]['edition'] == false |
|
| 186 | - and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 187 | - and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 188 | - ) { |
|
| 189 | - // inserer le formulaire de traduction |
|
| 190 | - $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 191 | - 'prive/objets/editer/traductions', |
|
| 192 | - ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 193 | - ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | - $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 195 | - 'args' => [ |
|
| 196 | - 'contexte' => $flux['args']['contexte'], |
|
| 197 | - 'type' => $objet, |
|
| 198 | - 'id' => $id |
|
| 199 | - ], |
|
| 200 | - 'data' => $flux['data']['texte'] |
|
| 201 | - ]); |
|
| 202 | - } |
|
| 203 | - $flux['data']['texte'] = pipeline( |
|
| 204 | - 'affiche_milieu', |
|
| 205 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 206 | - ); |
|
| 207 | - } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 208 | - $flux['data']['texte'] = pipeline( |
|
| 209 | - 'affiche_pied', |
|
| 210 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 211 | - ); |
|
| 212 | - } elseif ( |
|
| 213 | - strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 214 | - and $objet = basename($fond) |
|
| 215 | - and $objet == substr($fond, 21) |
|
| 216 | - and isset($o[$objet]) |
|
| 217 | - and $o[$objet] |
|
| 218 | - ) { |
|
| 219 | - $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 220 | - $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 221 | - 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 222 | - 'data' => $flux['data']['texte'] |
|
| 223 | - ]); |
|
| 224 | - } |
|
| 225 | - } |
|
| 137 | + static $o = []; |
|
| 138 | + if (is_string($fond = $flux['args']['fond'])) { |
|
| 139 | + $exec = isset($flux['args']['contexte']['exec']) ? $flux['args']['contexte']['exec'] : _request('exec'); |
|
| 140 | + if (!isset($o[$exec])) { |
|
| 141 | + $o[$exec] = trouver_objet_exec($exec); |
|
| 142 | + } |
|
| 143 | + // cas particulier |
|
| 144 | + if ($exec == 'infos_perso') { |
|
| 145 | + $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 146 | + } |
|
| 147 | + $typepage = (isset($flux['args']['contexte']['type-page']) ? $flux['args']['contexte']['type-page'] : $exec); |
|
| 148 | + if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 149 | + $flux['data']['texte'] = pipeline( |
|
| 150 | + 'affiche_gauche', |
|
| 151 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 152 | + ); |
|
| 153 | + } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 154 | + include_spip('inc/presentation_mini'); |
|
| 155 | + $flux['data']['texte'] = pipeline( |
|
| 156 | + 'affiche_droite', |
|
| 157 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 158 | + ) . liste_objets_bloques( |
|
| 159 | + $exec, |
|
| 160 | + $flux['args']['contexte'] |
|
| 161 | + ); |
|
| 162 | + } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 163 | + // id non defini sur les formulaire de nouveaux objets |
|
| 164 | + $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 165 | + $flux['data']['texte'] = pipeline( |
|
| 166 | + 'affiche_hierarchie', |
|
| 167 | + ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 168 | + ); |
|
| 169 | + } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 170 | + // Préparation du marqueur affiche_milieu |
|
| 171 | + // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 172 | + $est_page_objet = !empty($o[$exec]['type']); |
|
| 173 | + $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 174 | + $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 175 | + $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 176 | + $flux['data']['texte'], |
|
| 177 | + '<!--affiche_milieu-->', |
|
| 178 | + '<div id=["\']wysiwyg', |
|
| 179 | + $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 180 | + $encapsuler_milieu ? '</div>' : '' |
|
| 181 | + ); |
|
| 182 | + if ( |
|
| 183 | + $o[$exec] |
|
| 184 | + and $objet = $o[$exec]['type'] |
|
| 185 | + and $o[$exec]['edition'] == false |
|
| 186 | + and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 187 | + and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 188 | + ) { |
|
| 189 | + // inserer le formulaire de traduction |
|
| 190 | + $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 191 | + 'prive/objets/editer/traductions', |
|
| 192 | + ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 193 | + ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | + $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 195 | + 'args' => [ |
|
| 196 | + 'contexte' => $flux['args']['contexte'], |
|
| 197 | + 'type' => $objet, |
|
| 198 | + 'id' => $id |
|
| 199 | + ], |
|
| 200 | + 'data' => $flux['data']['texte'] |
|
| 201 | + ]); |
|
| 202 | + } |
|
| 203 | + $flux['data']['texte'] = pipeline( |
|
| 204 | + 'affiche_milieu', |
|
| 205 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 206 | + ); |
|
| 207 | + } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 208 | + $flux['data']['texte'] = pipeline( |
|
| 209 | + 'affiche_pied', |
|
| 210 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 211 | + ); |
|
| 212 | + } elseif ( |
|
| 213 | + strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 214 | + and $objet = basename($fond) |
|
| 215 | + and $objet == substr($fond, 21) |
|
| 216 | + and isset($o[$objet]) |
|
| 217 | + and $o[$objet] |
|
| 218 | + ) { |
|
| 219 | + $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 220 | + $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 221 | + 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 222 | + 'data' => $flux['data']['texte'] |
|
| 223 | + ]); |
|
| 224 | + } |
|
| 225 | + } |
|
| 226 | 226 | |
| 227 | - return $flux; |
|
| 227 | + return $flux; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | /** |
@@ -252,36 +252,36 @@ discard block |
||
| 252 | 252 | */ |
| 253 | 253 | function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string { |
| 254 | 254 | |
| 255 | - if ($texte) { |
|
| 256 | - $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 257 | - $marqueur_pos = strpos($texte, $marqueur); |
|
| 258 | - $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 255 | + if ($texte) { |
|
| 256 | + $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 257 | + $marqueur_pos = strpos($texte, $marqueur); |
|
| 258 | + $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 259 | 259 | |
| 260 | - // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 261 | - if ($marqueur_pos === false) { |
|
| 262 | - $texte = preg_replace( |
|
| 263 | - ",$inserer_avant,", |
|
| 264 | - "$full_marqueur\\0", |
|
| 265 | - $texte |
|
| 266 | - ); |
|
| 267 | - // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 268 | - // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 269 | - // Il ne faut donc aucun espace blanc en trop. |
|
| 270 | - } elseif ( |
|
| 271 | - $marqueur_pos !== false |
|
| 272 | - and $encapsuler |
|
| 273 | - and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 274 | - ) { |
|
| 275 | - $texte = substr_replace( |
|
| 276 | - $texte, |
|
| 277 | - $full_marqueur, |
|
| 278 | - $marqueur_pos, |
|
| 279 | - strlen($marqueur) |
|
| 280 | - ); |
|
| 281 | - } |
|
| 282 | - } |
|
| 260 | + // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 261 | + if ($marqueur_pos === false) { |
|
| 262 | + $texte = preg_replace( |
|
| 263 | + ",$inserer_avant,", |
|
| 264 | + "$full_marqueur\\0", |
|
| 265 | + $texte |
|
| 266 | + ); |
|
| 267 | + // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 268 | + // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 269 | + // Il ne faut donc aucun espace blanc en trop. |
|
| 270 | + } elseif ( |
|
| 271 | + $marqueur_pos !== false |
|
| 272 | + and $encapsuler |
|
| 273 | + and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 274 | + ) { |
|
| 275 | + $texte = substr_replace( |
|
| 276 | + $texte, |
|
| 277 | + $full_marqueur, |
|
| 278 | + $marqueur_pos, |
|
| 279 | + strlen($marqueur) |
|
| 280 | + ); |
|
| 281 | + } |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - return $texte; |
|
| 284 | + return $texte; |
|
| 285 | 285 | } |
| 286 | 286 | |
| 287 | 287 | /** |
@@ -292,23 +292,23 @@ discard block |
||
| 292 | 292 | * @return string |
| 293 | 293 | */ |
| 294 | 294 | function f_queue_affiche_milieu($flux) { |
| 295 | - $args = $flux['args']; |
|
| 296 | - $res = ''; |
|
| 297 | - foreach ($args as $key => $arg) { |
|
| 298 | - if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 299 | - $objet = preg_replace(',^id_,', '', $key); |
|
| 300 | - $res .= recuperer_fond( |
|
| 301 | - 'modeles/object_jobs_list', |
|
| 302 | - ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 303 | - ['ajax' => true] |
|
| 304 | - ); |
|
| 305 | - } |
|
| 306 | - } |
|
| 307 | - if ($res) { |
|
| 308 | - $flux['data'] = $res . $flux['data']; |
|
| 309 | - } |
|
| 295 | + $args = $flux['args']; |
|
| 296 | + $res = ''; |
|
| 297 | + foreach ($args as $key => $arg) { |
|
| 298 | + if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 299 | + $objet = preg_replace(',^id_,', '', $key); |
|
| 300 | + $res .= recuperer_fond( |
|
| 301 | + 'modeles/object_jobs_list', |
|
| 302 | + ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 303 | + ['ajax' => true] |
|
| 304 | + ); |
|
| 305 | + } |
|
| 306 | + } |
|
| 307 | + if ($res) { |
|
| 308 | + $flux['data'] = $res . $flux['data']; |
|
| 309 | + } |
|
| 310 | 310 | |
| 311 | - return $flux; |
|
| 311 | + return $flux; |
|
| 312 | 312 | } |
| 313 | 313 | |
| 314 | 314 | /** |
@@ -322,39 +322,39 @@ discard block |
||
| 322 | 322 | * @return array|bool |
| 323 | 323 | */ |
| 324 | 324 | function trouver_objet_exec($exec) { |
| 325 | - static $objet_exec = []; |
|
| 326 | - if (!$exec) { |
|
| 327 | - return false; |
|
| 328 | - } |
|
| 329 | - // cas particulier |
|
| 330 | - if ($exec == 'infos_perso') { |
|
| 331 | - $exec = 'auteur'; |
|
| 332 | - set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 333 | - } |
|
| 334 | - if (!isset($objet_exec[$exec])) { |
|
| 335 | - $objet_exec[$exec] = false; |
|
| 336 | - $infos = lister_tables_objets_sql(); |
|
| 337 | - foreach ($infos as $t => $info) { |
|
| 338 | - if ($exec == $info['url_edit'] and $info['editable']) { |
|
| 339 | - return $objet_exec[$exec] = [ |
|
| 340 | - 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 341 | - 'table_objet_sql' => $t, |
|
| 342 | - 'table' => $info['table_objet'], |
|
| 343 | - 'type' => $info['type'], |
|
| 344 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 345 | - ]; |
|
| 346 | - } |
|
| 347 | - if ($exec == $info['url_voir']) { |
|
| 348 | - return $objet_exec[$exec] = [ |
|
| 349 | - 'edition' => false, |
|
| 350 | - 'table_objet_sql' => $t, |
|
| 351 | - 'table' => $info['table_objet'], |
|
| 352 | - 'type' => $info['type'], |
|
| 353 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 354 | - ]; |
|
| 355 | - } |
|
| 356 | - } |
|
| 357 | - } |
|
| 325 | + static $objet_exec = []; |
|
| 326 | + if (!$exec) { |
|
| 327 | + return false; |
|
| 328 | + } |
|
| 329 | + // cas particulier |
|
| 330 | + if ($exec == 'infos_perso') { |
|
| 331 | + $exec = 'auteur'; |
|
| 332 | + set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 333 | + } |
|
| 334 | + if (!isset($objet_exec[$exec])) { |
|
| 335 | + $objet_exec[$exec] = false; |
|
| 336 | + $infos = lister_tables_objets_sql(); |
|
| 337 | + foreach ($infos as $t => $info) { |
|
| 338 | + if ($exec == $info['url_edit'] and $info['editable']) { |
|
| 339 | + return $objet_exec[$exec] = [ |
|
| 340 | + 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 341 | + 'table_objet_sql' => $t, |
|
| 342 | + 'table' => $info['table_objet'], |
|
| 343 | + 'type' => $info['type'], |
|
| 344 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 345 | + ]; |
|
| 346 | + } |
|
| 347 | + if ($exec == $info['url_voir']) { |
|
| 348 | + return $objet_exec[$exec] = [ |
|
| 349 | + 'edition' => false, |
|
| 350 | + 'table_objet_sql' => $t, |
|
| 351 | + 'table' => $info['table_objet'], |
|
| 352 | + 'type' => $info['type'], |
|
| 353 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 354 | + ]; |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | + } |
|
| 358 | 358 | |
| 359 | - return $objet_exec[$exec]; |
|
| 359 | + return $objet_exec[$exec]; |
|
| 360 | 360 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | $titre = '<title>[' |
| 95 | 95 | . $nom_site_spip |
| 96 | - . '] ' . $match |
|
| 96 | + . '] '.$match |
|
| 97 | 97 | . '</title>'; |
| 98 | 98 | |
| 99 | 99 | $texte = substr_replace($texte, $titre, $p + 6, 0); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $flux['data']['texte'] = pipeline( |
| 156 | 156 | 'affiche_droite', |
| 157 | 157 | ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
| 158 | - ) . liste_objets_bloques( |
|
| 158 | + ).liste_objets_bloques( |
|
| 159 | 159 | $exec, |
| 160 | 160 | $flux['args']['contexte'] |
| 161 | 161 | ); |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
| 191 | 191 | 'prive/objets/editer/traductions', |
| 192 | 192 | ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
| 193 | - ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 193 | + ).'<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | 194 | $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
| 195 | 195 | 'args' => [ |
| 196 | 196 | 'contexte' => $flux['args']['contexte'], |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $full_marqueur = "$ouvrir$marqueur$fermer"; |
| 259 | 259 | |
| 260 | 260 | // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
| 261 | - if ($marqueur_pos === false) { |
|
| 261 | + if ($marqueur_pos === false) { |
|
| 262 | 262 | $texte = preg_replace( |
| 263 | 263 | ",$inserer_avant,", |
| 264 | 264 | "$full_marqueur\\0", |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | if ($res) { |
| 308 | - $flux['data'] = $res . $flux['data']; |
|
| 308 | + $flux['data'] = $res.$flux['data']; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | return $flux; |
@@ -11,74 +11,74 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | # Les information d'une rubrique selectionnee dans le mini navigateur |
| 18 | 18 | |
| 19 | 19 | // https://code.spip.net/@inc_informer_dist |
| 20 | 20 | function inc_informer_dist($id, $col, $exclus, $rac, $type, $do = 'aff') { |
| 21 | - include_spip('inc/texte'); |
|
| 22 | - $titre = $descriptif = ''; |
|
| 23 | - if ($type == 'rubrique') { |
|
| 24 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 25 | - if ($row) { |
|
| 26 | - $titre = typo($row['titre']); |
|
| 27 | - $descriptif = propre($row['descriptif']); |
|
| 28 | - } else { |
|
| 29 | - $titre = _T('info_racine_site'); |
|
| 30 | - } |
|
| 31 | - } |
|
| 21 | + include_spip('inc/texte'); |
|
| 22 | + $titre = $descriptif = ''; |
|
| 23 | + if ($type == 'rubrique') { |
|
| 24 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 25 | + if ($row) { |
|
| 26 | + $titre = typo($row['titre']); |
|
| 27 | + $descriptif = propre($row['descriptif']); |
|
| 28 | + } else { |
|
| 29 | + $titre = _T('info_racine_site'); |
|
| 30 | + } |
|
| 31 | + } |
|
| 32 | 32 | |
| 33 | - $res = ''; |
|
| 34 | - if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) { |
|
| 35 | - if ($GLOBALS['meta']['image_process'] != 'non') { |
|
| 36 | - $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | - if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 38 | - list($fid, $dir, $nom, $format) = $res; |
|
| 39 | - include_spip('inc/filtres_images_mini'); |
|
| 40 | - $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 41 | - if ($res) { |
|
| 42 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 43 | - } |
|
| 44 | - } |
|
| 45 | - } |
|
| 46 | - } |
|
| 33 | + $res = ''; |
|
| 34 | + if ($type == 'rubrique' and $GLOBALS['spip_display'] != 1 and isset($GLOBALS['meta']['image_process'])) { |
|
| 35 | + if ($GLOBALS['meta']['image_process'] != 'non') { |
|
| 36 | + $chercher_logo = charger_fonction('chercher_logo', 'inc'); |
|
| 37 | + if ($res = $chercher_logo($id, 'id_rubrique', 'on')) { |
|
| 38 | + list($fid, $dir, $nom, $format) = $res; |
|
| 39 | + include_spip('inc/filtres_images_mini'); |
|
| 40 | + $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
|
| 41 | + if ($res) { |
|
| 42 | + $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 43 | + } |
|
| 44 | + } |
|
| 45 | + } |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 49 | - $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 50 | - $id = intval($id); |
|
| 48 | + $rac = spip_htmlentities($rac, ENT_QUOTES); |
|
| 49 | + $do = spip_htmlentities($do, ENT_QUOTES); |
|
| 50 | + $id = intval($id); |
|
| 51 | 51 | |
| 52 | 52 | # ce lien provoque la selection (directe) de la rubrique cliquee |
| 53 | 53 | # et l'affichage de son titre dans le bandeau |
| 54 | - $titre = strtr( |
|
| 55 | - str_replace( |
|
| 56 | - "'", |
|
| 57 | - '’', |
|
| 58 | - str_replace('"', '"', textebrut($titre)) |
|
| 59 | - ), |
|
| 60 | - "\n\r", |
|
| 61 | - ' ' |
|
| 62 | - ); |
|
| 54 | + $titre = strtr( |
|
| 55 | + str_replace( |
|
| 56 | + "'", |
|
| 57 | + '’', |
|
| 58 | + str_replace('"', '"', textebrut($titre)) |
|
| 59 | + ), |
|
| 60 | + "\n\r", |
|
| 61 | + ' ' |
|
| 62 | + ); |
|
| 63 | 63 | |
| 64 | - $js_func = $do . '_selection_titre'; |
|
| 64 | + $js_func = $do . '_selection_titre'; |
|
| 65 | 65 | |
| 66 | - return "<div style='display: none;'>" |
|
| 67 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 68 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 69 | - . entites_html($titre) |
|
| 70 | - . '" />' |
|
| 71 | - . '</div>' |
|
| 72 | - . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 73 | - . '<div class="informer__item">' |
|
| 74 | - . (!$res ? '' : $res) |
|
| 75 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 76 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 77 | - . '</div>' |
|
| 78 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 79 | - . "<input type='submit' class='fondo btn submit' value='" |
|
| 80 | - . _T('bouton_choisir') |
|
| 81 | - . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 82 | - . '</div>' |
|
| 83 | - . '</div>'; |
|
| 66 | + return "<div style='display: none;'>" |
|
| 67 | + . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 68 | + . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 69 | + . entites_html($titre) |
|
| 70 | + . '" />' |
|
| 71 | + . '</div>' |
|
| 72 | + . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
|
| 73 | + . '<div class="informer__item">' |
|
| 74 | + . (!$res ? '' : $res) |
|
| 75 | + . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 76 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 77 | + . '</div>' |
|
| 78 | + . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 79 | + . "<input type='submit' class='fondo btn submit' value='" |
|
| 80 | + . _T('bouton_choisir') |
|
| 81 | + . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
|
| 82 | + . '</div>' |
|
| 83 | + . '</div>'; |
|
| 84 | 84 | } |
@@ -21,7 +21,7 @@ discard block |
||
| 21 | 21 | include_spip('inc/texte'); |
| 22 | 22 | $titre = $descriptif = ''; |
| 23 | 23 | if ($type == 'rubrique') { |
| 24 | - $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = ' . intval($id)); |
|
| 24 | + $row = sql_fetsel('titre, descriptif', 'spip_rubriques', 'id_rubrique = '.intval($id)); |
|
| 25 | 25 | if ($row) { |
| 26 | 26 | $titre = typo($row['titre']); |
| 27 | 27 | $descriptif = propre($row['descriptif']); |
@@ -39,7 +39,7 @@ discard block |
||
| 39 | 39 | include_spip('inc/filtres_images_mini'); |
| 40 | 40 | $res = image_reduire("<img src='$fid' alt='' />", 100, 48); |
| 41 | 41 | if ($res) { |
| 42 | - $res = "<div class='informer__media' style='float: " . $GLOBALS['spip_lang_right'] . '; margin-' . $GLOBALS['spip_lang_right'] . ": -5px; margin-top: -5px;'>$res</div>"; |
|
| 42 | + $res = "<div class='informer__media' style='float: ".$GLOBALS['spip_lang_right'].'; margin-'.$GLOBALS['spip_lang_right'].": -5px; margin-top: -5px;'>$res</div>"; |
|
| 43 | 43 | } |
| 44 | 44 | } |
| 45 | 45 | } |
@@ -61,21 +61,21 @@ discard block |
||
| 61 | 61 | ' ' |
| 62 | 62 | ); |
| 63 | 63 | |
| 64 | - $js_func = $do . '_selection_titre'; |
|
| 64 | + $js_func = $do.'_selection_titre'; |
|
| 65 | 65 | |
| 66 | 66 | return "<div style='display: none;'>" |
| 67 | - . "<input type='text' id='" . $rac . "_sel' value='$id' />" |
|
| 68 | - . "<input type='text' id='" . $rac . "_sel2' value=\"" |
|
| 67 | + . "<input type='text' id='".$rac."_sel' value='$id' />" |
|
| 68 | + . "<input type='text' id='".$rac."_sel2' value=\"" |
|
| 69 | 69 | . entites_html($titre) |
| 70 | 70 | . '" />' |
| 71 | 71 | . '</div>' |
| 72 | 72 | . "<div class='informer' style='padding: 5px; border-top: 0px;'>" |
| 73 | 73 | . '<div class="informer__item">' |
| 74 | 74 | . (!$res ? '' : $res) |
| 75 | - . "<p class='informer__titre'><b>" . safehtml($titre) . '</b></p>' |
|
| 76 | - . (!$descriptif ? '' : "<div class='informer__descriptif'>" . safehtml($descriptif) . '</div>') |
|
| 75 | + . "<p class='informer__titre'><b>".safehtml($titre).'</b></p>' |
|
| 76 | + . (!$descriptif ? '' : "<div class='informer__descriptif'>".safehtml($descriptif).'</div>') |
|
| 77 | 77 | . '</div>' |
| 78 | - . "<div class='informer__action' style='clear:both; text-align: " . $GLOBALS['spip_lang_right'] . ";'>" |
|
| 78 | + . "<div class='informer__action' style='clear:both; text-align: ".$GLOBALS['spip_lang_right'].";'>" |
|
| 79 | 79 | . "<input type='submit' class='fondo btn submit' value='" |
| 80 | 80 | . _T('bouton_choisir') |
| 81 | 81 | . "'\nonclick=\"$js_func('$titre',$id,'selection_rubrique','id_parent'); return false;\" />" |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -45,29 +45,29 @@ discard block |
||
| 45 | 45 | * sinon code HTML de la page après le traitement effectué. |
| 46 | 46 | **/ |
| 47 | 47 | function inc_admin_dist($script, $titre, $comment = '', $anonymous = false) { |
| 48 | - $reprise = true; |
|
| 49 | - if ( |
|
| 50 | - !isset($GLOBALS['meta'][$script]) |
|
| 51 | - or !isset($GLOBALS['meta']['admin']) |
|
| 52 | - ) { |
|
| 53 | - $reprise = false; |
|
| 54 | - $res = debut_admin($script, $titre, $comment); |
|
| 55 | - if ($res) { |
|
| 56 | - return $res; |
|
| 57 | - } |
|
| 58 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 59 | - ecrire_meta($script, serialize($_POST)); |
|
| 60 | - } |
|
| 48 | + $reprise = true; |
|
| 49 | + if ( |
|
| 50 | + !isset($GLOBALS['meta'][$script]) |
|
| 51 | + or !isset($GLOBALS['meta']['admin']) |
|
| 52 | + ) { |
|
| 53 | + $reprise = false; |
|
| 54 | + $res = debut_admin($script, $titre, $comment); |
|
| 55 | + if ($res) { |
|
| 56 | + return $res; |
|
| 57 | + } |
|
| 58 | + spip_log("meta: $script " . print_r($_POST, true)); |
|
| 59 | + ecrire_meta($script, serialize($_POST)); |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $res = admin_verifie_session($script, $anonymous); |
|
| 63 | - if ($res) { |
|
| 64 | - return $res; |
|
| 65 | - } |
|
| 66 | - $base = charger_fonction($script, 'base'); |
|
| 67 | - $base($titre, $reprise); |
|
| 68 | - fin_admin($script); |
|
| 62 | + $res = admin_verifie_session($script, $anonymous); |
|
| 63 | + if ($res) { |
|
| 64 | + return $res; |
|
| 65 | + } |
|
| 66 | + $base = charger_fonction($script, 'base'); |
|
| 67 | + $base($titre, $reprise); |
|
| 68 | + fin_admin($script); |
|
| 69 | 69 | |
| 70 | - return ''; |
|
| 70 | + return ''; |
|
| 71 | 71 | } |
| 72 | 72 | |
| 73 | 73 | /** |
@@ -98,35 +98,35 @@ discard block |
||
| 98 | 98 | * Code HTML si message d'erreur, '' sinon; |
| 99 | 99 | */ |
| 100 | 100 | function admin_verifie_session($script, $anonymous = false) { |
| 101 | - include_spip('base/abstract_sql'); |
|
| 102 | - $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 103 | - $signal = fichier_admin($script, "$script$pref"); |
|
| 104 | - $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 105 | - if ($valeur === null) { |
|
| 106 | - ecrire_meta('admin', $signal, 'non'); |
|
| 107 | - } else { |
|
| 108 | - if (!$anonymous and ($valeur != $signal)) { |
|
| 109 | - if ( |
|
| 110 | - !preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l) |
|
| 111 | - or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 112 | - ) { |
|
| 113 | - include_spip('inc/minipres'); |
|
| 114 | - spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 101 | + include_spip('base/abstract_sql'); |
|
| 102 | + $pref = sprintf('_%d_', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 103 | + $signal = fichier_admin($script, "$script$pref"); |
|
| 104 | + $valeur = sql_getfetsel('valeur', 'spip_meta', "nom='admin'"); |
|
| 105 | + if ($valeur === null) { |
|
| 106 | + ecrire_meta('admin', $signal, 'non'); |
|
| 107 | + } else { |
|
| 108 | + if (!$anonymous and ($valeur != $signal)) { |
|
| 109 | + if ( |
|
| 110 | + !preg_match('/^(.*)_(\d+)_/', $GLOBALS['meta']['admin'], $l) |
|
| 111 | + or intval($l[2]) != $GLOBALS['visiteur_session']['id_auteur'] |
|
| 112 | + ) { |
|
| 113 | + include_spip('inc/minipres'); |
|
| 114 | + spip_log("refus de lancer $script, priorite a $valeur"); |
|
| 115 | 115 | |
| 116 | - return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 117 | - } |
|
| 118 | - } |
|
| 119 | - } |
|
| 120 | - $journal = 'spip'; |
|
| 121 | - if (autoriser('configurer')) { |
|
| 122 | - // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | - $journal = 'webmestre'; |
|
| 124 | - } |
|
| 125 | - // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 116 | + return minipres(_T('info_travaux_texte'), '', ['status' => 503]); |
|
| 117 | + } |
|
| 118 | + } |
|
| 119 | + } |
|
| 120 | + $journal = 'spip'; |
|
| 121 | + if (autoriser('configurer')) { |
|
| 122 | + // c'est une action webmestre, soit par ftp soit par statut webmestre |
|
| 123 | + $journal = 'webmestre'; |
|
| 124 | + } |
|
| 125 | + // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
|
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | - return ''; |
|
| 129 | + return ''; |
|
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | /** |
@@ -139,11 +139,11 @@ discard block |
||
| 139 | 139 | * Chemin du répertoire. |
| 140 | 140 | **/ |
| 141 | 141 | function dir_admin() { |
| 142 | - if (autoriser('configurer')) { |
|
| 143 | - return _DIR_TMP; |
|
| 144 | - } else { |
|
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | - } |
|
| 142 | + if (autoriser('configurer')) { |
|
| 143 | + return _DIR_TMP; |
|
| 144 | + } else { |
|
| 145 | + return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 146 | + } |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref . |
|
| 164 | + substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -187,73 +187,73 @@ discard block |
||
| 187 | 187 | * sinon chaîne vide si déjà fait. |
| 188 | 188 | **/ |
| 189 | 189 | function debut_admin($script, $action = '', $corps = '') { |
| 190 | - if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) { |
|
| 191 | - include_spip('inc/minipres'); |
|
| 190 | + if ((!$action) || !(autoriser('webmestre') or autoriser('chargerftp'))) { |
|
| 191 | + include_spip('inc/minipres'); |
|
| 192 | 192 | |
| 193 | - return minipres(); |
|
| 194 | - } else { |
|
| 195 | - $dir = dir_admin(); |
|
| 196 | - $signal = fichier_admin($script); |
|
| 197 | - if (@file_exists($dir . $signal)) { |
|
| 198 | - spip_log("Action admin: $action"); |
|
| 193 | + return minipres(); |
|
| 194 | + } else { |
|
| 195 | + $dir = dir_admin(); |
|
| 196 | + $signal = fichier_admin($script); |
|
| 197 | + if (@file_exists($dir . $signal)) { |
|
| 198 | + spip_log("Action admin: $action"); |
|
| 199 | 199 | |
| 200 | - return ''; |
|
| 201 | - } |
|
| 202 | - include_spip('inc/minipres'); |
|
| 200 | + return ''; |
|
| 201 | + } |
|
| 202 | + include_spip('inc/minipres'); |
|
| 203 | 203 | |
| 204 | - // Si on est un super-admin, un bouton de validation suffit |
|
| 205 | - // sauf dans les cas destroy |
|
| 206 | - if ( |
|
| 207 | - (autoriser('webmestre') or $script === 'repair') |
|
| 208 | - and $script != 'delete_all' |
|
| 209 | - ) { |
|
| 210 | - if (_request('validation_admin') == $signal) { |
|
| 211 | - spip_log("Action super-admin: $action"); |
|
| 204 | + // Si on est un super-admin, un bouton de validation suffit |
|
| 205 | + // sauf dans les cas destroy |
|
| 206 | + if ( |
|
| 207 | + (autoriser('webmestre') or $script === 'repair') |
|
| 208 | + and $script != 'delete_all' |
|
| 209 | + ) { |
|
| 210 | + if (_request('validation_admin') == $signal) { |
|
| 211 | + spip_log("Action super-admin: $action"); |
|
| 212 | 212 | |
| 213 | - return ''; |
|
| 214 | - } |
|
| 215 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 216 | - $suivant = _T('bouton_valider'); |
|
| 217 | - $js = ''; |
|
| 218 | - } else { |
|
| 219 | - // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 220 | - // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 221 | - // mais evite de l'embarquer dans toutes les pages minipres |
|
| 222 | - $corps .= http_script('', 'spip_barre.js'); |
|
| 213 | + return ''; |
|
| 214 | + } |
|
| 215 | + $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 216 | + $suivant = _T('bouton_valider'); |
|
| 217 | + $js = ''; |
|
| 218 | + } else { |
|
| 219 | + // cet appel permet d'assurer un copier-coller du nom du repertoire a creer dans tmp (esj) |
|
| 220 | + // l'insertion du script a cet endroit n'est pas xhtml licite |
|
| 221 | + // mais evite de l'embarquer dans toutes les pages minipres |
|
| 222 | + $corps .= http_script('', 'spip_barre.js'); |
|
| 223 | 223 | |
| 224 | - $corps .= '<fieldset><legend>' |
|
| 225 | - . _T('info_authentification_ftp') |
|
| 226 | - . aider('ftp_auth') |
|
| 227 | - . "</legend>\n<label for='fichier'>" |
|
| 228 | - . _T('info_creer_repertoire') |
|
| 229 | - . "</label>\n" |
|
| 230 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 231 | - . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 232 | - . $signal |
|
| 233 | - . "' />" |
|
| 234 | - . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 235 | - . '</fieldset>'; |
|
| 224 | + $corps .= '<fieldset><legend>' |
|
| 225 | + . _T('info_authentification_ftp') |
|
| 226 | + . aider('ftp_auth') |
|
| 227 | + . "</legend>\n<label for='fichier'>" |
|
| 228 | + . _T('info_creer_repertoire') |
|
| 229 | + . "</label>\n" |
|
| 230 | + . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 231 | + . "<input type='hidden' id='fichier' name='fichier' value='" |
|
| 232 | + . $signal |
|
| 233 | + . "' />" |
|
| 234 | + . _T('info_creer_repertoire_2', ['repertoire' => joli_repertoire($dir)]) |
|
| 235 | + . '</fieldset>'; |
|
| 236 | 236 | |
| 237 | - $suivant = _T('bouton_recharger_page'); |
|
| 237 | + $suivant = _T('bouton_recharger_page'); |
|
| 238 | 238 | |
| 239 | - // code volontairement tordu: |
|
| 240 | - // provoquer la copie dans le presse papier du nom du repertoire |
|
| 241 | - // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 242 | - // de JavaScript inactif. |
|
| 243 | - $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 244 | - } |
|
| 239 | + // code volontairement tordu: |
|
| 240 | + // provoquer la copie dans le presse papier du nom du repertoire |
|
| 241 | + // en remettant a vide le champ pour que ca marche aussi en cas |
|
| 242 | + // de JavaScript inactif. |
|
| 243 | + $js = " onload='var range=document.createRange(); var signal = document.getElementById(\"signal\"); var userSelection = window.getSelection(); range.setStart(signal,0); range.setEnd(signal,1); userSelection.addRange(range);'"; |
|
| 244 | + } |
|
| 245 | 245 | |
| 246 | - // admin/xxx correspond |
|
| 247 | - // a exec/base_xxx de preference |
|
| 248 | - // et exec/xxx sinon (compat) |
|
| 249 | - if (tester_url_ecrire("base_$script")) { |
|
| 250 | - $script = "base_$script"; |
|
| 251 | - } |
|
| 252 | - $form = copy_request($script, $corps, $suivant); |
|
| 253 | - $info_action = _T('info_action', ['action' => "$action"]); |
|
| 246 | + // admin/xxx correspond |
|
| 247 | + // a exec/base_xxx de preference |
|
| 248 | + // et exec/xxx sinon (compat) |
|
| 249 | + if (tester_url_ecrire("base_$script")) { |
|
| 250 | + $script = "base_$script"; |
|
| 251 | + } |
|
| 252 | + $form = copy_request($script, $corps, $suivant); |
|
| 253 | + $info_action = _T('info_action', ['action' => "$action"]); |
|
| 254 | 254 | |
| 255 | - return minipres($info_action, $form, $js); |
|
| 256 | - } |
|
| 255 | + return minipres($info_action, $form, $js); |
|
| 256 | + } |
|
| 257 | 257 | } |
| 258 | 258 | |
| 259 | 259 | /** |
@@ -264,13 +264,13 @@ discard block |
||
| 264 | 264 | * Nom de l'action (en base) qui a été exécutée |
| 265 | 265 | **/ |
| 266 | 266 | function fin_admin($action) { |
| 267 | - $signal = dir_admin() . fichier_admin($action); |
|
| 268 | - spip_unlink($signal); |
|
| 269 | - if ($action != 'delete_all') { |
|
| 270 | - effacer_meta($action); |
|
| 271 | - effacer_meta('admin'); |
|
| 272 | - spip_log("efface les meta admin et $action "); |
|
| 273 | - } |
|
| 267 | + $signal = dir_admin() . fichier_admin($action); |
|
| 268 | + spip_unlink($signal); |
|
| 269 | + if ($action != 'delete_all') { |
|
| 270 | + effacer_meta($action); |
|
| 271 | + effacer_meta('admin'); |
|
| 272 | + spip_log("efface les meta admin et $action "); |
|
| 273 | + } |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | /** |
@@ -289,14 +289,14 @@ discard block |
||
| 289 | 289 | * Code HTML du formulaire |
| 290 | 290 | **/ |
| 291 | 291 | function copy_request($script, $suite, $submit = '') { |
| 292 | - include_spip('inc/filtres'); |
|
| 293 | - foreach (array_merge($_POST, $_GET) as $n => $c) { |
|
| 294 | - if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) { |
|
| 295 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 296 | - entites_html($c) . |
|
| 297 | - "' />"; |
|
| 298 | - } |
|
| 299 | - } |
|
| 292 | + include_spip('inc/filtres'); |
|
| 293 | + foreach (array_merge($_POST, $_GET) as $n => $c) { |
|
| 294 | + if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) { |
|
| 295 | + $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 296 | + entites_html($c) . |
|
| 297 | + "' />"; |
|
| 298 | + } |
|
| 299 | + } |
|
| 300 | 300 | |
| 301 | - return generer_form_ecrire($script, $suite, '', $submit); |
|
| 301 | + return generer_form_ecrire($script, $suite, '', $submit); |
|
| 302 | 302 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | if ($res) { |
| 56 | 56 | return $res; |
| 57 | 57 | } |
| 58 | - spip_log("meta: $script " . print_r($_POST, true)); |
|
| 58 | + spip_log("meta: $script ".print_r($_POST, true)); |
|
| 59 | 59 | ecrire_meta($script, serialize($_POST)); |
| 60 | 60 | } |
| 61 | 61 | |
@@ -124,7 +124,7 @@ discard block |
||
| 124 | 124 | } |
| 125 | 125 | // on pourrait statuer automatiquement les webmestres a l'init d'une action auth par ftp ... ? |
| 126 | 126 | |
| 127 | - spip_log("admin $pref" . ($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 127 | + spip_log("admin $pref".($valeur ? ' (reprise)' : ' (init)'), $journal); |
|
| 128 | 128 | |
| 129 | 129 | return ''; |
| 130 | 130 | } |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | if (autoriser('configurer')) { |
| 143 | 143 | return _DIR_TMP; |
| 144 | 144 | } else { |
| 145 | - return _DIR_TRANSFERT . $GLOBALS['visiteur_session']['login'] . '/'; |
|
| 145 | + return _DIR_TRANSFERT.$GLOBALS['visiteur_session']['login'].'/'; |
|
| 146 | 146 | } |
| 147 | 147 | } |
| 148 | 148 | |
@@ -160,8 +160,8 @@ discard block |
||
| 160 | 160 | * Nom du fichier |
| 161 | 161 | **/ |
| 162 | 162 | function fichier_admin($action, $pref = 'admin_') { |
| 163 | - return $pref . |
|
| 164 | - substr(md5($action . (time() & ~2047) . $GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 163 | + return $pref. |
|
| 164 | + substr(md5($action.(time() & ~2047).$GLOBALS['visiteur_session']['login']), 0, 10); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -194,7 +194,7 @@ discard block |
||
| 194 | 194 | } else { |
| 195 | 195 | $dir = dir_admin(); |
| 196 | 196 | $signal = fichier_admin($script); |
| 197 | - if (@file_exists($dir . $signal)) { |
|
| 197 | + if (@file_exists($dir.$signal)) { |
|
| 198 | 198 | spip_log("Action admin: $action"); |
| 199 | 199 | |
| 200 | 200 | return ''; |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | |
| 213 | 213 | return ''; |
| 214 | 214 | } |
| 215 | - $corps .= '<input type="hidden" name="validation_admin" value="' . $signal . '" />'; |
|
| 215 | + $corps .= '<input type="hidden" name="validation_admin" value="'.$signal.'" />'; |
|
| 216 | 216 | $suivant = _T('bouton_valider'); |
| 217 | 217 | $js = ''; |
| 218 | 218 | } else { |
@@ -227,7 +227,7 @@ discard block |
||
| 227 | 227 | . "</legend>\n<label for='fichier'>" |
| 228 | 228 | . _T('info_creer_repertoire') |
| 229 | 229 | . "</label>\n" |
| 230 | - . "<span id='signal' class='formo'>" . $signal . '</span>' |
|
| 230 | + . "<span id='signal' class='formo'>".$signal.'</span>' |
|
| 231 | 231 | . "<input type='hidden' id='fichier' name='fichier' value='" |
| 232 | 232 | . $signal |
| 233 | 233 | . "' />" |
@@ -264,7 +264,7 @@ discard block |
||
| 264 | 264 | * Nom de l'action (en base) qui a été exécutée |
| 265 | 265 | **/ |
| 266 | 266 | function fin_admin($action) { |
| 267 | - $signal = dir_admin() . fichier_admin($action); |
|
| 267 | + $signal = dir_admin().fichier_admin($action); |
|
| 268 | 268 | spip_unlink($signal); |
| 269 | 269 | if ($action != 'delete_all') { |
| 270 | 270 | effacer_meta($action); |
@@ -292,8 +292,8 @@ discard block |
||
| 292 | 292 | include_spip('inc/filtres'); |
| 293 | 293 | foreach (array_merge($_POST, $_GET) as $n => $c) { |
| 294 | 294 | if (!in_array($n, ['fichier', 'exec', 'validation_admin']) and !is_array($c)) { |
| 295 | - $suite .= "\n<input type='hidden' name='" . spip_htmlspecialchars($n) . "' value='" . |
|
| 296 | - entites_html($c) . |
|
| 295 | + $suite .= "\n<input type='hidden' name='".spip_htmlspecialchars($n)."' value='". |
|
| 296 | + entites_html($c). |
|
| 297 | 297 | "' />"; |
| 298 | 298 | } |
| 299 | 299 | } |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | $contenu = @gzfile($fichier); |
| 123 | 123 | } |
| 124 | 124 | |
| 125 | - return is_array($contenu) ? join('', $contenu) : (string)$contenu; |
|
| 125 | + return is_array($contenu) ? join('', $contenu) : (string) $contenu; |
|
| 126 | 126 | } |
| 127 | 127 | |
| 128 | 128 | |
@@ -315,9 +315,9 @@ discard block |
||
| 315 | 315 | */ |
| 316 | 316 | function ecrire_fichier_securise($fichier, $contenu, $ecrire_quand_meme = false, $truncate = true) { |
| 317 | 317 | if (substr($fichier, -4) !== '.php') { |
| 318 | - spip_log('Erreur de programmation: ' . $fichier . ' doit finir par .php'); |
|
| 318 | + spip_log('Erreur de programmation: '.$fichier.' doit finir par .php'); |
|
| 319 | 319 | } |
| 320 | - $contenu = '<' . "?php die ('Acces interdit'); ?" . ">\n" . $contenu; |
|
| 320 | + $contenu = '<'."?php die ('Acces interdit'); ?".">\n".$contenu; |
|
| 321 | 321 | |
| 322 | 322 | return ecrire_fichier($fichier, $contenu, $ecrire_quand_meme, $truncate); |
| 323 | 323 | } |
@@ -330,7 +330,7 @@ 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'; |
|
| 333 | + $fichier_tmp = $fichier.'.last'; |
|
| 334 | 334 | if (!ecrire_fichier($fichier_tmp, $contenu, true)) { |
| 335 | 335 | return false; |
| 336 | 336 | } |
@@ -370,7 +370,7 @@ discard block |
||
| 370 | 370 | */ |
| 371 | 371 | function lire_fichier_securise($fichier, &$contenu, $options = []) { |
| 372 | 372 | if ($res = lire_fichier($fichier, $contenu, $options)) { |
| 373 | - $contenu = substr($contenu, strlen('<' . "?php die ('Acces interdit'); ?" . ">\n")); |
|
| 373 | + $contenu = substr($contenu, strlen('<'."?php die ('Acces interdit'); ?".">\n")); |
|
| 374 | 374 | } |
| 375 | 375 | |
| 376 | 376 | return $res; |
@@ -540,7 +540,7 @@ discard block |
||
| 540 | 540 | $wait = 0; |
| 541 | 541 | } |
| 542 | 542 | } |
| 543 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 543 | + spip_log('Probleme de configuration opcache.revalidate_freq '.$duree.'s : on attend '.$wait.'s', _LOG_INFO_IMPORTANTE); |
|
| 544 | 544 | if ($wait) { |
| 545 | 545 | sleep($duree + 1); |
| 546 | 546 | } |
@@ -568,9 +568,9 @@ discard block |
||
| 568 | 568 | if ($item == '.' || $item == '..') { |
| 569 | 569 | continue; |
| 570 | 570 | } |
| 571 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 572 | - @chmod($dir . '/' . $item, 0777); |
|
| 573 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 571 | + if (!supprimer_repertoire($dir.'/'.$item)) { |
|
| 572 | + @chmod($dir.'/'.$item, 0777); |
|
| 573 | + if (!supprimer_repertoire($dir.'/'.$item)) { |
|
| 574 | 574 | return false; |
| 575 | 575 | } |
| 576 | 576 | }; |
@@ -615,7 +615,7 @@ discard block |
||
| 615 | 615 | if (!strlen($subdir)) { |
| 616 | 616 | $n = strrpos($base, '/'); |
| 617 | 617 | if ($n === false) { |
| 618 | - return $nobase ? '' : ($base . '/'); |
|
| 618 | + return $nobase ? '' : ($base.'/'); |
|
| 619 | 619 | } |
| 620 | 620 | $subdir = substr($base, $n + 1); |
| 621 | 621 | $base = substr($base, 0, $n + 1); |
@@ -625,14 +625,14 @@ discard block |
||
| 625 | 625 | } |
| 626 | 626 | |
| 627 | 627 | $baseaff = $nobase ? '' : $base; |
| 628 | - if (isset($dirs[$base . $subdir])) { |
|
| 629 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 628 | + if (isset($dirs[$base.$subdir])) { |
|
| 629 | + return $baseaff.$dirs[$base.$subdir]; |
|
| 630 | 630 | } |
| 631 | 631 | |
| 632 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 632 | + $path = $base.$subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 633 | 633 | |
| 634 | 634 | if (file_exists("$path/.ok")) { |
| 635 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 635 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 636 | 636 | } |
| 637 | 637 | |
| 638 | 638 | @mkdir($path, _SPIP_CHMOD); |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | @touch("$path/.ok"); |
| 643 | 643 | spip_log("creation $base$subdir/"); |
| 644 | 644 | |
| 645 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 645 | + return $baseaff.($dirs[$base.$subdir] = "$subdir/"); |
|
| 646 | 646 | } |
| 647 | 647 | |
| 648 | 648 | // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
@@ -652,10 +652,10 @@ discard block |
||
| 652 | 652 | return ''; |
| 653 | 653 | } |
| 654 | 654 | if (!_DIR_RESTREINT) { |
| 655 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 655 | + $base = preg_replace(',^'._DIR_RACINE.',', '', $base); |
|
| 656 | 656 | } |
| 657 | 657 | $base .= $subdir; |
| 658 | - raler_fichier($base . '/.ok'); |
|
| 658 | + raler_fichier($base.'/.ok'); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -728,7 +728,7 @@ discard block |
||
| 728 | 728 | $maxfiles - $nbfiles, |
| 729 | 729 | $recurs |
| 730 | 730 | ); |
| 731 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 731 | + $fichiers = array_merge((array) $beginning, (array) $end); |
|
| 732 | 732 | $nbfiles = count($fichiers); |
| 733 | 733 | } |
| 734 | 734 | } |
@@ -341,8 +341,7 @@ |
||
| 341 | 341 | ) { |
| 342 | 342 | if ($use_copy) { |
| 343 | 343 | @copy($fichier_tmp, $fichier); |
| 344 | - } |
|
| 345 | - else { |
|
| 344 | + } else { |
|
| 346 | 345 | @rename($fichier_tmp, $fichier); |
| 347 | 346 | } |
| 348 | 347 | // eviter que PHP ne reserve le vieux timestamp |
@@ -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$,', isset($_ENV['HTTP_HOST']) ? $_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$,', isset($_ENV['HTTP_HOST']) ? $_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,22 +388,22 @@ discard block |
||
| 388 | 388 | * Chemin du fichier |
| 389 | 389 | **/ |
| 390 | 390 | function raler_fichier($fichier) { |
| 391 | - include_spip('inc/minipres'); |
|
| 392 | - $dir = dirname($fichier); |
|
| 393 | - http_response_code(401); |
|
| 394 | - echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 395 | - . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 396 | - . " <a href='" |
|
| 397 | - . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 398 | - . "'>" |
|
| 399 | - . _T('texte_inc_meta_2') |
|
| 400 | - . '</a> ' |
|
| 401 | - . _T( |
|
| 402 | - 'texte_inc_meta_3', |
|
| 403 | - ['repertoire' => joli_repertoire($dir)] |
|
| 404 | - ) |
|
| 405 | - . "</h4>\n"); |
|
| 406 | - exit; |
|
| 391 | + include_spip('inc/minipres'); |
|
| 392 | + $dir = dirname($fichier); |
|
| 393 | + http_response_code(401); |
|
| 394 | + echo minipres(_T('texte_inc_meta_2'), "<h4 style='color: red'>" |
|
| 395 | + . _T('texte_inc_meta_1', ['fichier' => $fichier]) |
|
| 396 | + . " <a href='" |
|
| 397 | + . generer_url_ecrire('install', "etape=chmod&test_dir=$dir") |
|
| 398 | + . "'>" |
|
| 399 | + . _T('texte_inc_meta_2') |
|
| 400 | + . '</a> ' |
|
| 401 | + . _T( |
|
| 402 | + 'texte_inc_meta_3', |
|
| 403 | + ['repertoire' => joli_repertoire($dir)] |
|
| 404 | + ) |
|
| 405 | + . "</h4>\n"); |
|
| 406 | + exit; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | 409 | |
@@ -418,14 +418,14 @@ discard block |
||
| 418 | 418 | * - true si récent, false sinon |
| 419 | 419 | */ |
| 420 | 420 | function jeune_fichier($fichier, $n) { |
| 421 | - if (!file_exists($fichier)) { |
|
| 422 | - return false; |
|
| 423 | - } |
|
| 424 | - if (!$c = @filemtime($fichier)) { |
|
| 425 | - return false; |
|
| 426 | - } |
|
| 427 | - |
|
| 428 | - return (time() - $n <= $c); |
|
| 421 | + if (!file_exists($fichier)) { |
|
| 422 | + return false; |
|
| 423 | + } |
|
| 424 | + if (!$c = @filemtime($fichier)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 427 | + |
|
| 428 | + return (time() - $n <= $c); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -440,22 +440,22 @@ discard block |
||
| 440 | 440 | * - false si on n'arrive pas poser le verrou ou si la suppression échoue |
| 441 | 441 | */ |
| 442 | 442 | function supprimer_fichier($fichier, $lock = true) { |
| 443 | - if (!@file_exists($fichier)) { |
|
| 444 | - return true; |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - if ($lock) { |
|
| 448 | - // verrouiller le fichier destination |
|
| 449 | - if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 450 | - return false; |
|
| 451 | - } |
|
| 452 | - |
|
| 453 | - // liberer le verrou |
|
| 454 | - spip_fclose_unlock($fp); |
|
| 455 | - } |
|
| 456 | - |
|
| 457 | - // supprimer |
|
| 458 | - return @unlink($fichier); |
|
| 443 | + if (!@file_exists($fichier)) { |
|
| 444 | + return true; |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + if ($lock) { |
|
| 448 | + // verrouiller le fichier destination |
|
| 449 | + if (!$fp = spip_fopen_lock($fichier, 'a', LOCK_EX)) { |
|
| 450 | + return false; |
|
| 451 | + } |
|
| 452 | + |
|
| 453 | + // liberer le verrou |
|
| 454 | + spip_fclose_unlock($fp); |
|
| 455 | + } |
|
| 456 | + |
|
| 457 | + // supprimer |
|
| 458 | + return @unlink($fichier); |
|
| 459 | 459 | } |
| 460 | 460 | |
| 461 | 461 | /** |
@@ -465,12 +465,12 @@ discard block |
||
| 465 | 465 | * Chemin du fichier |
| 466 | 466 | */ |
| 467 | 467 | function spip_unlink($f) { |
| 468 | - if (!is_dir($f)) { |
|
| 469 | - supprimer_fichier($f, false); |
|
| 470 | - } else { |
|
| 471 | - @unlink("$f/.ok"); |
|
| 472 | - @rmdir($f); |
|
| 473 | - } |
|
| 468 | + if (!is_dir($f)) { |
|
| 469 | + supprimer_fichier($f, false); |
|
| 470 | + } else { |
|
| 471 | + @unlink("$f/.ok"); |
|
| 472 | + @rmdir($f); |
|
| 473 | + } |
|
| 474 | 474 | } |
| 475 | 475 | |
| 476 | 476 | /** |
@@ -484,26 +484,26 @@ discard block |
||
| 484 | 484 | * The absolute path of the PHP file to invalidate. |
| 485 | 485 | */ |
| 486 | 486 | function spip_clear_opcode_cache($filepath) { |
| 487 | - clearstatcache(true, $filepath); |
|
| 488 | - |
|
| 489 | - // Zend OPcache |
|
| 490 | - if (function_exists('opcache_invalidate')) { |
|
| 491 | - $invalidate = @opcache_invalidate($filepath, true); |
|
| 492 | - // si l'invalidation a echoue lever un flag |
|
| 493 | - if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 494 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 495 | - } |
|
| 496 | - } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | - // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 498 | - define('_spip_attend_invalidation_opcode_cache', true); |
|
| 499 | - } |
|
| 500 | - // APC. |
|
| 501 | - if (function_exists('apc_delete_file')) { |
|
| 502 | - // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 503 | - // not compiled yet. |
|
| 504 | - // @see http://php.net/apc-delete-file |
|
| 505 | - @apc_delete_file($filepath); |
|
| 506 | - } |
|
| 487 | + clearstatcache(true, $filepath); |
|
| 488 | + |
|
| 489 | + // Zend OPcache |
|
| 490 | + if (function_exists('opcache_invalidate')) { |
|
| 491 | + $invalidate = @opcache_invalidate($filepath, true); |
|
| 492 | + // si l'invalidation a echoue lever un flag |
|
| 493 | + if (!$invalidate and !defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 494 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 495 | + } |
|
| 496 | + } elseif (!defined('_spip_attend_invalidation_opcode_cache')) { |
|
| 497 | + // n'agira que si opcache est effectivement actif (il semble qu'on a pas toujours la fonction opcache_invalidate) |
|
| 498 | + define('_spip_attend_invalidation_opcode_cache', true); |
|
| 499 | + } |
|
| 500 | + // APC. |
|
| 501 | + if (function_exists('apc_delete_file')) { |
|
| 502 | + // apc_delete_file() throws a PHP warning in case the specified file was |
|
| 503 | + // not compiled yet. |
|
| 504 | + // @see http://php.net/apc-delete-file |
|
| 505 | + @apc_delete_file($filepath); |
|
| 506 | + } |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | /** |
@@ -526,25 +526,25 @@ discard block |
||
| 526 | 526 | * |
| 527 | 527 | */ |
| 528 | 528 | function spip_attend_invalidation_opcode_cache($timestamp = null) { |
| 529 | - if ( |
|
| 530 | - function_exists('opcache_get_configuration') |
|
| 531 | - and @ini_get('opcache.enable') |
|
| 532 | - and @ini_get('opcache.validate_timestamps') |
|
| 533 | - and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 534 | - and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 535 | - ) { |
|
| 536 | - $wait = $duree + 1; |
|
| 537 | - if ($timestamp) { |
|
| 538 | - $wait -= (time() - $timestamp); |
|
| 539 | - if ($wait < 0) { |
|
| 540 | - $wait = 0; |
|
| 541 | - } |
|
| 542 | - } |
|
| 543 | - spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 544 | - if ($wait) { |
|
| 545 | - sleep($duree + 1); |
|
| 546 | - } |
|
| 547 | - } |
|
| 529 | + if ( |
|
| 530 | + function_exists('opcache_get_configuration') |
|
| 531 | + and @ini_get('opcache.enable') |
|
| 532 | + and @ini_get('opcache.validate_timestamps') |
|
| 533 | + and ($duree = intval(@ini_get('opcache.revalidate_freq')) or $duree = 2) |
|
| 534 | + and defined('_spip_attend_invalidation_opcode_cache') // des invalidations ont echouees |
|
| 535 | + ) { |
|
| 536 | + $wait = $duree + 1; |
|
| 537 | + if ($timestamp) { |
|
| 538 | + $wait -= (time() - $timestamp); |
|
| 539 | + if ($wait < 0) { |
|
| 540 | + $wait = 0; |
|
| 541 | + } |
|
| 542 | + } |
|
| 543 | + spip_log('Probleme de configuration opcache.revalidate_freq ' . $duree . 's : on attend ' . $wait . 's', _LOG_INFO_IMPORTANTE); |
|
| 544 | + if ($wait) { |
|
| 545 | + sleep($duree + 1); |
|
| 546 | + } |
|
| 547 | + } |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -557,26 +557,26 @@ discard block |
||
| 557 | 557 | * @return bool Suppression reussie. |
| 558 | 558 | */ |
| 559 | 559 | function supprimer_repertoire($dir) { |
| 560 | - if (!file_exists($dir)) { |
|
| 561 | - return true; |
|
| 562 | - } |
|
| 563 | - if (!is_dir($dir) || is_link($dir)) { |
|
| 564 | - return @unlink($dir); |
|
| 565 | - } |
|
| 566 | - |
|
| 567 | - foreach (scandir($dir) as $item) { |
|
| 568 | - if ($item == '.' || $item == '..') { |
|
| 569 | - continue; |
|
| 570 | - } |
|
| 571 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 572 | - @chmod($dir . '/' . $item, 0777); |
|
| 573 | - if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 574 | - return false; |
|
| 575 | - } |
|
| 576 | - }; |
|
| 577 | - } |
|
| 578 | - |
|
| 579 | - return @rmdir($dir); |
|
| 560 | + if (!file_exists($dir)) { |
|
| 561 | + return true; |
|
| 562 | + } |
|
| 563 | + if (!is_dir($dir) || is_link($dir)) { |
|
| 564 | + return @unlink($dir); |
|
| 565 | + } |
|
| 566 | + |
|
| 567 | + foreach (scandir($dir) as $item) { |
|
| 568 | + if ($item == '.' || $item == '..') { |
|
| 569 | + continue; |
|
| 570 | + } |
|
| 571 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 572 | + @chmod($dir . '/' . $item, 0777); |
|
| 573 | + if (!supprimer_repertoire($dir . '/' . $item)) { |
|
| 574 | + return false; |
|
| 575 | + } |
|
| 576 | + }; |
|
| 577 | + } |
|
| 578 | + |
|
| 579 | + return @rmdir($dir); |
|
| 580 | 580 | } |
| 581 | 581 | |
| 582 | 582 | |
@@ -605,57 +605,57 @@ discard block |
||
| 605 | 605 | * Chemin du répertoire créé. |
| 606 | 606 | **/ |
| 607 | 607 | function sous_repertoire($base, $subdir = '', $nobase = false, $tantpis = false) { |
| 608 | - static $dirs = []; |
|
| 609 | - |
|
| 610 | - $base = str_replace('//', '/', $base); |
|
| 611 | - |
|
| 612 | - # suppr le dernier caractere si c'est un / |
|
| 613 | - $base = rtrim($base, '/'); |
|
| 614 | - |
|
| 615 | - if (!strlen($subdir)) { |
|
| 616 | - $n = strrpos($base, '/'); |
|
| 617 | - if ($n === false) { |
|
| 618 | - return $nobase ? '' : ($base . '/'); |
|
| 619 | - } |
|
| 620 | - $subdir = substr($base, $n + 1); |
|
| 621 | - $base = substr($base, 0, $n + 1); |
|
| 622 | - } else { |
|
| 623 | - $base .= '/'; |
|
| 624 | - $subdir = str_replace('/', '', $subdir); |
|
| 625 | - } |
|
| 626 | - |
|
| 627 | - $baseaff = $nobase ? '' : $base; |
|
| 628 | - if (isset($dirs[$base . $subdir])) { |
|
| 629 | - return $baseaff . $dirs[$base . $subdir]; |
|
| 630 | - } |
|
| 631 | - |
|
| 632 | - $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 633 | - |
|
| 634 | - if (file_exists("$path/.ok")) { |
|
| 635 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 636 | - } |
|
| 637 | - |
|
| 638 | - @mkdir($path, _SPIP_CHMOD); |
|
| 639 | - @chmod($path, _SPIP_CHMOD); |
|
| 640 | - |
|
| 641 | - if (is_dir($path) && is_writable($path)) { |
|
| 642 | - @touch("$path/.ok"); |
|
| 643 | - spip_log("creation $base$subdir/"); |
|
| 644 | - |
|
| 645 | - return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 649 | - // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 650 | - spip_log("echec creation $base${subdir}"); |
|
| 651 | - if ($tantpis) { |
|
| 652 | - return ''; |
|
| 653 | - } |
|
| 654 | - if (!_DIR_RESTREINT) { |
|
| 655 | - $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 656 | - } |
|
| 657 | - $base .= $subdir; |
|
| 658 | - raler_fichier($base . '/.ok'); |
|
| 608 | + static $dirs = []; |
|
| 609 | + |
|
| 610 | + $base = str_replace('//', '/', $base); |
|
| 611 | + |
|
| 612 | + # suppr le dernier caractere si c'est un / |
|
| 613 | + $base = rtrim($base, '/'); |
|
| 614 | + |
|
| 615 | + if (!strlen($subdir)) { |
|
| 616 | + $n = strrpos($base, '/'); |
|
| 617 | + if ($n === false) { |
|
| 618 | + return $nobase ? '' : ($base . '/'); |
|
| 619 | + } |
|
| 620 | + $subdir = substr($base, $n + 1); |
|
| 621 | + $base = substr($base, 0, $n + 1); |
|
| 622 | + } else { |
|
| 623 | + $base .= '/'; |
|
| 624 | + $subdir = str_replace('/', '', $subdir); |
|
| 625 | + } |
|
| 626 | + |
|
| 627 | + $baseaff = $nobase ? '' : $base; |
|
| 628 | + if (isset($dirs[$base . $subdir])) { |
|
| 629 | + return $baseaff . $dirs[$base . $subdir]; |
|
| 630 | + } |
|
| 631 | + |
|
| 632 | + $path = $base . $subdir; # $path = 'IMG/distant/pdf' ou 'IMG/distant_pdf' |
|
| 633 | + |
|
| 634 | + if (file_exists("$path/.ok")) { |
|
| 635 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 636 | + } |
|
| 637 | + |
|
| 638 | + @mkdir($path, _SPIP_CHMOD); |
|
| 639 | + @chmod($path, _SPIP_CHMOD); |
|
| 640 | + |
|
| 641 | + if (is_dir($path) && is_writable($path)) { |
|
| 642 | + @touch("$path/.ok"); |
|
| 643 | + spip_log("creation $base$subdir/"); |
|
| 644 | + |
|
| 645 | + return $baseaff . ($dirs[$base . $subdir] = "$subdir/"); |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + // en cas d'echec c'est peut etre tout simplement que le disque est plein : |
|
| 649 | + // l'inode du fichier dir_test existe, mais impossible d'y mettre du contenu |
|
| 650 | + spip_log("echec creation $base${subdir}"); |
|
| 651 | + if ($tantpis) { |
|
| 652 | + return ''; |
|
| 653 | + } |
|
| 654 | + if (!_DIR_RESTREINT) { |
|
| 655 | + $base = preg_replace(',^' . _DIR_RACINE . ',', '', $base); |
|
| 656 | + } |
|
| 657 | + $base .= $subdir; |
|
| 658 | + raler_fichier($base . '/.ok'); |
|
| 659 | 659 | } |
| 660 | 660 | |
| 661 | 661 | |
@@ -688,56 +688,56 @@ discard block |
||
| 688 | 688 | * Chemins des fichiers trouvés. |
| 689 | 689 | **/ |
| 690 | 690 | function preg_files($dir, $pattern = -1 /* AUTO */, $maxfiles = 10000, $recurs = []) { |
| 691 | - $nbfiles = 0; |
|
| 692 | - if ($pattern == -1) { |
|
| 693 | - $pattern = "^$dir"; |
|
| 694 | - } |
|
| 695 | - $fichiers = []; |
|
| 696 | - // revenir au repertoire racine si on a recu dossier/truc |
|
| 697 | - // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 698 | - $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 699 | - if ($dir == '') { |
|
| 700 | - $dir = '.'; |
|
| 701 | - } |
|
| 702 | - |
|
| 703 | - if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 704 | - while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 705 | - if ( |
|
| 706 | - $f[0] != '.' # ignorer . .. .svn etc |
|
| 707 | - and $f != 'CVS' |
|
| 708 | - and $f != 'remove.txt' |
|
| 709 | - and is_readable($f = "$dir/$f") |
|
| 710 | - ) { |
|
| 711 | - if (is_file($f)) { |
|
| 712 | - if (preg_match(";$pattern;iS", $f)) { |
|
| 713 | - $fichiers[] = $f; |
|
| 714 | - $nbfiles++; |
|
| 715 | - } |
|
| 716 | - } else { |
|
| 717 | - if (is_dir($f) and is_array($recurs)) { |
|
| 718 | - $rp = @realpath($f); |
|
| 719 | - if (!is_string($rp) or !strlen($rp)) { |
|
| 720 | - $rp = $f; |
|
| 721 | - } # realpath n'est peut etre pas autorise |
|
| 722 | - if (!isset($recurs[$rp])) { |
|
| 723 | - $recurs[$rp] = true; |
|
| 724 | - $beginning = $fichiers; |
|
| 725 | - $end = preg_files( |
|
| 726 | - "$f/", |
|
| 727 | - $pattern, |
|
| 728 | - $maxfiles - $nbfiles, |
|
| 729 | - $recurs |
|
| 730 | - ); |
|
| 731 | - $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 732 | - $nbfiles = count($fichiers); |
|
| 733 | - } |
|
| 734 | - } |
|
| 735 | - } |
|
| 736 | - } |
|
| 737 | - } |
|
| 738 | - closedir($d); |
|
| 739 | - } |
|
| 740 | - sort($fichiers); |
|
| 741 | - |
|
| 742 | - return $fichiers; |
|
| 691 | + $nbfiles = 0; |
|
| 692 | + if ($pattern == -1) { |
|
| 693 | + $pattern = "^$dir"; |
|
| 694 | + } |
|
| 695 | + $fichiers = []; |
|
| 696 | + // revenir au repertoire racine si on a recu dossier/truc |
|
| 697 | + // pour regarder dossier/truc/ ne pas oublier le / final |
|
| 698 | + $dir = preg_replace(',/[^/]*$,', '', $dir); |
|
| 699 | + if ($dir == '') { |
|
| 700 | + $dir = '.'; |
|
| 701 | + } |
|
| 702 | + |
|
| 703 | + if (@is_dir($dir) and is_readable($dir) and $d = opendir($dir)) { |
|
| 704 | + while (($f = readdir($d)) !== false && ($nbfiles < $maxfiles)) { |
|
| 705 | + if ( |
|
| 706 | + $f[0] != '.' # ignorer . .. .svn etc |
|
| 707 | + and $f != 'CVS' |
|
| 708 | + and $f != 'remove.txt' |
|
| 709 | + and is_readable($f = "$dir/$f") |
|
| 710 | + ) { |
|
| 711 | + if (is_file($f)) { |
|
| 712 | + if (preg_match(";$pattern;iS", $f)) { |
|
| 713 | + $fichiers[] = $f; |
|
| 714 | + $nbfiles++; |
|
| 715 | + } |
|
| 716 | + } else { |
|
| 717 | + if (is_dir($f) and is_array($recurs)) { |
|
| 718 | + $rp = @realpath($f); |
|
| 719 | + if (!is_string($rp) or !strlen($rp)) { |
|
| 720 | + $rp = $f; |
|
| 721 | + } # realpath n'est peut etre pas autorise |
|
| 722 | + if (!isset($recurs[$rp])) { |
|
| 723 | + $recurs[$rp] = true; |
|
| 724 | + $beginning = $fichiers; |
|
| 725 | + $end = preg_files( |
|
| 726 | + "$f/", |
|
| 727 | + $pattern, |
|
| 728 | + $maxfiles - $nbfiles, |
|
| 729 | + $recurs |
|
| 730 | + ); |
|
| 731 | + $fichiers = array_merge((array)$beginning, (array)$end); |
|
| 732 | + $nbfiles = count($fichiers); |
|
| 733 | + } |
|
| 734 | + } |
|
| 735 | + } |
|
| 736 | + } |
|
| 737 | + } |
|
| 738 | + closedir($d); |
|
| 739 | + } |
|
| 740 | + sort($fichiers); |
|
| 741 | + |
|
| 742 | + return $fichiers; |
|
| 743 | 743 | } |
@@ -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 | /** |
@@ -38,70 +38,70 @@ discard block |
||
| 38 | 38 | * @return array|string |
| 39 | 39 | */ |
| 40 | 40 | function inc_couleurs_dist($choix = null, $ajouter = false) { |
| 41 | - static $couleurs_spip = [ |
|
| 42 | - // Violet soutenu |
|
| 43 | - 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 44 | - // Violet rosé |
|
| 45 | - 4 => ['couleur_theme' => '#c464cb'], |
|
| 46 | - // Rose interface SPIP |
|
| 47 | - 2 => ['couleur_theme' => '#F02364'], |
|
| 48 | - // Rouge |
|
| 49 | - 8 => ['couleur_theme' => '#ff4524'], |
|
| 50 | - // Orange |
|
| 51 | - 3 => ['couleur_theme' => '#c97500'], |
|
| 52 | - // Vert SPIP |
|
| 53 | - 1 => ['couleur_theme' => '#9dba00'], |
|
| 54 | - // Vert Troglo |
|
| 55 | - 7 => ['couleur_theme' => '#419a2c'], |
|
| 56 | - // Bleu-vert |
|
| 57 | - 12 => ['couleur_theme' => '#269681'], |
|
| 58 | - // Bleu pastel |
|
| 59 | - 5 => ['couleur_theme' => '#3190ae'], |
|
| 60 | - // Bleu Kermesse |
|
| 61 | - 11 => ['couleur_theme' => '#288bdd'], |
|
| 62 | - // Gris bleuté |
|
| 63 | - 6 => ['couleur_theme' => '#7d90a2'], |
|
| 64 | - // Gris |
|
| 65 | - 10 => ['couleur_theme' => '#909090'], |
|
| 66 | - ]; |
|
| 41 | + static $couleurs_spip = [ |
|
| 42 | + // Violet soutenu |
|
| 43 | + 9 => ['couleur_theme' => '#9a6ef2'], |
|
| 44 | + // Violet rosé |
|
| 45 | + 4 => ['couleur_theme' => '#c464cb'], |
|
| 46 | + // Rose interface SPIP |
|
| 47 | + 2 => ['couleur_theme' => '#F02364'], |
|
| 48 | + // Rouge |
|
| 49 | + 8 => ['couleur_theme' => '#ff4524'], |
|
| 50 | + // Orange |
|
| 51 | + 3 => ['couleur_theme' => '#c97500'], |
|
| 52 | + // Vert SPIP |
|
| 53 | + 1 => ['couleur_theme' => '#9dba00'], |
|
| 54 | + // Vert Troglo |
|
| 55 | + 7 => ['couleur_theme' => '#419a2c'], |
|
| 56 | + // Bleu-vert |
|
| 57 | + 12 => ['couleur_theme' => '#269681'], |
|
| 58 | + // Bleu pastel |
|
| 59 | + 5 => ['couleur_theme' => '#3190ae'], |
|
| 60 | + // Bleu Kermesse |
|
| 61 | + 11 => ['couleur_theme' => '#288bdd'], |
|
| 62 | + // Gris bleuté |
|
| 63 | + 6 => ['couleur_theme' => '#7d90a2'], |
|
| 64 | + // Gris |
|
| 65 | + 10 => ['couleur_theme' => '#909090'], |
|
| 66 | + ]; |
|
| 67 | 67 | |
| 68 | - if (is_numeric($choix)) { |
|
| 69 | - $c = $couleurs_spip[$choix]; |
|
| 70 | - // compat < SPIP 3.3 |
|
| 71 | - include_spip('inc/filtres_images_mini'); |
|
| 72 | - $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 73 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 68 | + if (is_numeric($choix)) { |
|
| 69 | + $c = $couleurs_spip[$choix]; |
|
| 70 | + // compat < SPIP 3.3 |
|
| 71 | + include_spip('inc/filtres_images_mini'); |
|
| 72 | + $c['couleur_foncee'] = $c['couleur_theme']; |
|
| 73 | + $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 74 | 74 | |
| 75 | - return |
|
| 76 | - 'couleur_theme=' . substr($c['couleur_theme'], 1) |
|
| 77 | - // compat < SPIP 3.3 |
|
| 78 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 79 | - . '&couleur_foncee=' . substr($c['couleur_foncee'], 1); |
|
| 80 | - } else { |
|
| 81 | - if (is_array($choix)) { |
|
| 82 | - // compat < SPIP 3.3 |
|
| 83 | - $compat_spip_33 = function ($c) { |
|
| 84 | - if (!isset($c['couleur_theme'])) { |
|
| 85 | - $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 86 | - unset($c['couleur_foncee']); |
|
| 87 | - unset($c['couleur_claire']); |
|
| 88 | - unset($c['couleur_lien']); |
|
| 89 | - unset($c['couleur_lien_off']); |
|
| 90 | - } |
|
| 91 | - return $c; |
|
| 92 | - }; |
|
| 93 | - if ($ajouter) { |
|
| 94 | - foreach ($choix as $c) { |
|
| 95 | - $couleurs_spip[] = $compat_spip_33($c); |
|
| 96 | - } |
|
| 75 | + return |
|
| 76 | + 'couleur_theme=' . substr($c['couleur_theme'], 1) |
|
| 77 | + // compat < SPIP 3.3 |
|
| 78 | + . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 79 | + . '&couleur_foncee=' . substr($c['couleur_foncee'], 1); |
|
| 80 | + } else { |
|
| 81 | + if (is_array($choix)) { |
|
| 82 | + // compat < SPIP 3.3 |
|
| 83 | + $compat_spip_33 = function ($c) { |
|
| 84 | + if (!isset($c['couleur_theme'])) { |
|
| 85 | + $c['couleur_theme'] = $c['couleur_foncee']; |
|
| 86 | + unset($c['couleur_foncee']); |
|
| 87 | + unset($c['couleur_claire']); |
|
| 88 | + unset($c['couleur_lien']); |
|
| 89 | + unset($c['couleur_lien_off']); |
|
| 90 | + } |
|
| 91 | + return $c; |
|
| 92 | + }; |
|
| 93 | + if ($ajouter) { |
|
| 94 | + foreach ($choix as $c) { |
|
| 95 | + $couleurs_spip[] = $compat_spip_33($c); |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - return $couleurs_spip; |
|
| 99 | - } else { |
|
| 100 | - $choix = array_map($compat_spip_33, $choix); |
|
| 101 | - return $couleurs_spip = $choix; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - } |
|
| 98 | + return $couleurs_spip; |
|
| 99 | + } else { |
|
| 100 | + $choix = array_map($compat_spip_33, $choix); |
|
| 101 | + return $couleurs_spip = $choix; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | - return $couleurs_spip; |
|
| 106 | + return $couleurs_spip; |
|
| 107 | 107 | } |
@@ -70,17 +70,17 @@ |
||
| 70 | 70 | // compat < SPIP 3.3 |
| 71 | 71 | include_spip('inc/filtres_images_mini'); |
| 72 | 72 | $c['couleur_foncee'] = $c['couleur_theme']; |
| 73 | - $c['couleur_claire'] = '#' . couleur_eclaircir($c['couleur_theme'], .5); |
|
| 73 | + $c['couleur_claire'] = '#'.couleur_eclaircir($c['couleur_theme'], .5); |
|
| 74 | 74 | |
| 75 | 75 | return |
| 76 | - 'couleur_theme=' . substr($c['couleur_theme'], 1) |
|
| 76 | + 'couleur_theme='.substr($c['couleur_theme'], 1) |
|
| 77 | 77 | // compat < SPIP 3.3 |
| 78 | - . '&couleur_claire=' . substr($c['couleur_claire'], 1) |
|
| 79 | - . '&couleur_foncee=' . substr($c['couleur_foncee'], 1); |
|
| 78 | + . '&couleur_claire='.substr($c['couleur_claire'], 1) |
|
| 79 | + . '&couleur_foncee='.substr($c['couleur_foncee'], 1); |
|
| 80 | 80 | } else { |
| 81 | 81 | if (is_array($choix)) { |
| 82 | 82 | // compat < SPIP 3.3 |
| 83 | - $compat_spip_33 = function ($c) { |
|
| 83 | + $compat_spip_33 = function($c) { |
|
| 84 | 84 | if (!isset($c['couleur_theme'])) { |
| 85 | 85 | $c['couleur_theme'] = $c['couleur_foncee']; |
| 86 | 86 | unset($c['couleur_foncee']); |
@@ -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/actions'); |
@@ -36,11 +36,11 @@ discard block |
||
| 36 | 36 | * - ou tableau d'information sur le squelette. |
| 37 | 37 | */ |
| 38 | 38 | function inc_iconifier_dist($objet, $id, $script, $visible = false, $flag_modif = true) { |
| 39 | - // compat avec anciens appels |
|
| 40 | - $objet = objet_type($objet); |
|
| 39 | + // compat avec anciens appels |
|
| 40 | + $objet = objet_type($objet); |
|
| 41 | 41 | |
| 42 | - return recuperer_fond( |
|
| 43 | - 'prive/objets/editer/logo', |
|
| 44 | - ['objet' => $objet, 'id_objet' => $id, 'editable' => $flag_modif] |
|
| 45 | - ); |
|
| 42 | + return recuperer_fond( |
|
| 43 | + 'prive/objets/editer/logo', |
|
| 44 | + ['objet' => $objet, 'id_objet' => $id, 'editable' => $flag_modif] |
|
| 45 | + ); |
|
| 46 | 46 | } |
@@ -96,7 +96,7 @@ discard block |
||
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | include_fichiers_fonctions(); |
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 99 | + foreach (['filtre_'.$fonc, 'filtre_'.$fonc.'_dist', $fonc] as $f) { |
|
| 100 | 100 | trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
| 101 | 101 | // fonction ou name\space\fonction |
| 102 | 102 | if (is_callable($f)) { |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | // affichage "GIT [master: abcdef]" |
| 224 | 224 | $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
| 225 | 225 | if ($desc['branch']) { |
| 226 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 226 | + $commit = $desc['branch'].': '.$commit; |
|
| 227 | 227 | } |
| 228 | 228 | return "{$desc['vcs']} [$commit]"; |
| 229 | 229 | } |
@@ -242,9 +242,9 @@ discard block |
||
| 242 | 242 | } |
| 243 | 243 | |
| 244 | 244 | // version installee par GIT |
| 245 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 245 | + if (lire_fichier($dir.'/.git/HEAD', $c)) { |
|
| 246 | 246 | $currentHead = trim(substr($c, 4)); |
| 247 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 247 | + if (lire_fichier($dir.'/.git/'.$currentHead, $hash)) { |
|
| 248 | 248 | return [ |
| 249 | 249 | 'vcs' => 'GIT', |
| 250 | 250 | 'branch' => basename($currentHead), |
@@ -271,8 +271,8 @@ discard block |
||
| 271 | 271 | $dir = '.'; |
| 272 | 272 | } |
| 273 | 273 | // version installee par SVN |
| 274 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 274 | + if (file_exists($dir.'/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | + $db = new SQLite3($dir.'/.svn/wc.db'); |
|
| 276 | 276 | $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
| 277 | 277 | if ($result) { |
| 278 | 278 | $row = $result->fetchArray(); |
@@ -290,12 +290,12 @@ discard block |
||
| 290 | 290 | |
| 291 | 291 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
| 292 | 292 | // et laisser passer les fonctions personnelles baptisees image_... |
| 293 | -$GLOBALS['spip_matrice']['image_graver'] = true;//'inc/filtres_images_mini.php'; |
|
| 294 | -$GLOBALS['spip_matrice']['image_select'] = true;//'inc/filtres_images_mini.php'; |
|
| 295 | -$GLOBALS['spip_matrice']['image_reduire'] = true;//'inc/filtres_images_mini.php'; |
|
| 296 | -$GLOBALS['spip_matrice']['image_reduire_par'] = true;//'inc/filtres_images_mini.php'; |
|
| 297 | -$GLOBALS['spip_matrice']['image_passe_partout'] = true;//'inc/filtres_images_mini.php'; |
|
| 298 | -$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true;//'inc/filtres_images_mini.php'; |
|
| 293 | +$GLOBALS['spip_matrice']['image_graver'] = true; //'inc/filtres_images_mini.php'; |
|
| 294 | +$GLOBALS['spip_matrice']['image_select'] = true; //'inc/filtres_images_mini.php'; |
|
| 295 | +$GLOBALS['spip_matrice']['image_reduire'] = true; //'inc/filtres_images_mini.php'; |
|
| 296 | +$GLOBALS['spip_matrice']['image_reduire_par'] = true; //'inc/filtres_images_mini.php'; |
|
| 297 | +$GLOBALS['spip_matrice']['image_passe_partout'] = true; //'inc/filtres_images_mini.php'; |
|
| 298 | +$GLOBALS['spip_matrice']['image_recadre_avec_fallback'] = true; //'inc/filtres_images_mini.php'; |
|
| 299 | 299 | |
| 300 | 300 | $GLOBALS['spip_matrice']['couleur_html_to_hex'] = 'inc/filtres_images_mini.php'; |
| 301 | 301 | $GLOBALS['spip_matrice']['couleur_hex_to_hsl'] = 'inc/filtres_images_mini.php'; |
@@ -454,8 +454,8 @@ discard block |
||
| 454 | 454 | */ |
| 455 | 455 | function filtre_debug($val, $key = null) { |
| 456 | 456 | $debug = ( |
| 457 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 458 | - ) . var_export($val, true); |
|
| 457 | + is_null($key) ? '' : (var_export($key, true).' = ') |
|
| 458 | + ).var_export($val, true); |
|
| 459 | 459 | |
| 460 | 460 | include_spip('inc/autoriser'); |
| 461 | 461 | if (autoriser('webmestre')) { |
@@ -509,7 +509,7 @@ discard block |
||
| 509 | 509 | $is_file = false; |
| 510 | 510 | } |
| 511 | 511 | if ($is_file) { |
| 512 | - $is_local_file = function ($path) { |
|
| 512 | + $is_local_file = function($path) { |
|
| 513 | 513 | if (strpos($path, '?') !== false) { |
| 514 | 514 | $path = supprimer_timestamp($path); |
| 515 | 515 | // remove ?24px added by find_in_theme on .svg files |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
| 562 | 562 | $srcover = $match[1]; |
| 563 | 563 | array_shift($args); |
| 564 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 564 | + array_unshift($args, "<img src='".$match[1]."' />"); |
|
| 565 | 565 | $srcover_filter = call_user_func_array($filtre, $args); |
| 566 | 566 | $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
| 567 | 567 | $reduit = str_replace($srcover, $srcover_filter, $reduit); |
@@ -925,7 +925,7 @@ discard block |
||
| 925 | 925 | // " -> " et tout ce genre de choses |
| 926 | 926 | $u = $GLOBALS['meta']['pcre_u']; |
| 927 | 927 | $texte = str_replace(' ', ' ', $texte); |
| 928 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 928 | + $texte = preg_replace('/\s{2,}/S'.$u, ' ', $texte); |
|
| 929 | 929 | // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
| 930 | 930 | $texte = entites_html($texte, false, false); |
| 931 | 931 | // mais bien echapper les double quotes ! |
@@ -985,7 +985,7 @@ discard block |
||
| 985 | 985 | **/ |
| 986 | 986 | function supprimer_numero($texte) { |
| 987 | 987 | return preg_replace( |
| 988 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 988 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 989 | 989 | '', |
| 990 | 990 | $texte |
| 991 | 991 | ); |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | function recuperer_numero($texte) { |
| 1014 | 1014 | if ( |
| 1015 | 1015 | preg_match( |
| 1016 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1016 | + ',^[[:space:]]*([0-9]+)([.)]|'.chr(194).'?'.chr(176).')[[:space:]]+,S', |
|
| 1017 | 1017 | $texte, |
| 1018 | 1018 | $regs |
| 1019 | 1019 | ) |
@@ -1101,8 +1101,8 @@ discard block |
||
| 1101 | 1101 | **/ |
| 1102 | 1102 | function textebrut($texte) { |
| 1103 | 1103 | $u = $GLOBALS['meta']['pcre_u']; |
| 1104 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1105 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1104 | + $texte = preg_replace('/\s+/S'.$u, ' ', $texte); |
|
| 1105 | + $texte = preg_replace('/<(p|br)( [^>]*)?'.'>/iS', "\n\n", $texte); |
|
| 1106 | 1106 | $texte = preg_replace("/^\n+/", '', $texte); |
| 1107 | 1107 | $texte = preg_replace("/\n+$/", '', $texte); |
| 1108 | 1108 | $texte = preg_replace("/\n +/", "\n", $texte); |
@@ -1136,7 +1136,7 @@ discard block |
||
| 1136 | 1136 | ) |
| 1137 | 1137 | ) { |
| 1138 | 1138 | foreach ($liens[0] as $a) { |
| 1139 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1139 | + $rel = 'noopener noreferrer '.extraire_attribut($a, 'rel'); |
|
| 1140 | 1140 | $ablank = inserer_attribut($a, 'rel', $rel); |
| 1141 | 1141 | $ablank = inserer_attribut($ablank, 'target', '_blank'); |
| 1142 | 1142 | $texte = str_replace($a, $ablank, $texte); |
@@ -1161,7 +1161,7 @@ discard block |
||
| 1161 | 1161 | foreach ($regs[0] as $a) { |
| 1162 | 1162 | $rel = extraire_attribut($a, 'rel'); |
| 1163 | 1163 | if (strpos($rel, 'nofollow') === false) { |
| 1164 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1164 | + $rel = 'nofollow'.($rel ? " $rel" : ''); |
|
| 1165 | 1165 | $anofollow = inserer_attribut($a, 'rel', $rel); |
| 1166 | 1166 | $texte = str_replace($a, $anofollow, $texte); |
| 1167 | 1167 | } |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | $u = $GLOBALS['meta']['pcre_u']; |
| 1191 | 1191 | $texte = preg_replace('@</p>@iS', "\n", $texte); |
| 1192 | 1192 | $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
| 1193 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1193 | + $texte = preg_replace('@^\s*<br />@S'.$u, '', $texte); |
|
| 1194 | 1194 | |
| 1195 | 1195 | return $texte; |
| 1196 | 1196 | } |
@@ -1221,7 +1221,7 @@ discard block |
||
| 1221 | 1221 | return $texte; |
| 1222 | 1222 | } |
| 1223 | 1223 | include_spip('inc/texte'); |
| 1224 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1224 | + $tag = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $texte) ? |
|
| 1225 | 1225 | 'div' : 'span'; |
| 1226 | 1226 | |
| 1227 | 1227 | return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
@@ -1330,7 +1330,7 @@ discard block |
||
| 1330 | 1330 | function attribut_html($texte, $textebrut = true) { |
| 1331 | 1331 | $u = $GLOBALS['meta']['pcre_u']; |
| 1332 | 1332 | if ($textebrut) { |
| 1333 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1333 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS'.$u], [' ', ''], textebrut($texte)); |
|
| 1334 | 1334 | } |
| 1335 | 1335 | $texte = texte_backend($texte); |
| 1336 | 1336 | $texte = str_replace(["'", '"'], [''', '"'], $texte); |
@@ -1362,7 +1362,7 @@ discard block |
||
| 1362 | 1362 | # un message pour abs_url |
| 1363 | 1363 | $GLOBALS['mode_abs_url'] = 'url'; |
| 1364 | 1364 | $url = trim($url); |
| 1365 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1365 | + $r = ',^(?:'._PROTOCOLES_STD.'):?/?/?$,iS'; |
|
| 1366 | 1366 | |
| 1367 | 1367 | return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
| 1368 | 1368 | } |
@@ -1564,14 +1564,14 @@ discard block |
||
| 1564 | 1564 | if (strpos($texte, '<') !== false) { |
| 1565 | 1565 | include_spip('inc/lien'); |
| 1566 | 1566 | if (defined('_PREG_MODELE')) { |
| 1567 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1567 | + $preg_modeles = '@'._PREG_MODELE.'@imsS'; |
|
| 1568 | 1568 | $texte = echappe_html($texte, '', true, $preg_modeles); |
| 1569 | 1569 | } |
| 1570 | 1570 | } |
| 1571 | 1571 | |
| 1572 | 1572 | $debut = ''; |
| 1573 | 1573 | $suite = $texte; |
| 1574 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1574 | + while ($t = strpos('-'.$suite, "\n", 1)) { |
|
| 1575 | 1575 | $debut .= substr($suite, 0, $t - 1); |
| 1576 | 1576 | $suite = substr($suite, $t); |
| 1577 | 1577 | $car = substr($suite, 0, 1); |
@@ -1589,11 +1589,11 @@ discard block |
||
| 1589 | 1589 | $suite = substr($suite, strlen($regs[0])); |
| 1590 | 1590 | } |
| 1591 | 1591 | } |
| 1592 | - $texte = $debut . $suite; |
|
| 1592 | + $texte = $debut.$suite; |
|
| 1593 | 1593 | |
| 1594 | 1594 | $texte = echappe_retour($texte); |
| 1595 | 1595 | |
| 1596 | - return $texte . $fin; |
|
| 1596 | + return $texte.$fin; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | |
@@ -1655,7 +1655,7 @@ discard block |
||
| 1655 | 1655 | } |
| 1656 | 1656 | |
| 1657 | 1657 | foreach ($regs as $reg) { |
| 1658 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1658 | + $cle = ($reg[1] ? $reg[1].':' : '').$reg[2]; |
|
| 1659 | 1659 | $desc = $traduire($cle, $lang, true); |
| 1660 | 1660 | $l = $desc->langue; |
| 1661 | 1661 | // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
@@ -1769,9 +1769,9 @@ discard block |
||
| 1769 | 1769 | // il ne faut pas echapper en div si propre produit un seul paragraphe |
| 1770 | 1770 | include_spip('inc/texte'); |
| 1771 | 1771 | $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
| 1772 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1772 | + $mode = preg_match(',</?('._BALISES_BLOCS.')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1773 | 1773 | if ($mode === 'div') { |
| 1774 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1774 | + $trad = rtrim($trad)."\n\n"; |
|
| 1775 | 1775 | } |
| 1776 | 1776 | $trad = code_echappement($trad, 'multi', false, $mode); |
| 1777 | 1777 | $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
@@ -1965,7 +1965,7 @@ discard block |
||
| 1965 | 1965 | if (is_array($balise)) { |
| 1966 | 1966 | array_walk( |
| 1967 | 1967 | $balise, |
| 1968 | - function (&$a, $key, $t) { |
|
| 1968 | + function(&$a, $key, $t) { |
|
| 1969 | 1969 | $a = extraire_attribut($a, $t); |
| 1970 | 1970 | }, |
| 1971 | 1971 | $attribut |
@@ -2055,14 +2055,14 @@ discard block |
||
| 2055 | 2055 | |
| 2056 | 2056 | if ($old !== null) { |
| 2057 | 2057 | // Remplacer l'ancien attribut du meme nom |
| 2058 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2058 | + $balise = $r[1].$insert.$r[5]; |
|
| 2059 | 2059 | } else { |
| 2060 | 2060 | // preferer une balise " />" (comme <img />) |
| 2061 | 2061 | if (preg_match(',/>,', $balise)) { |
| 2062 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2062 | + $balise = preg_replace(',\s?/>,S', $insert.' />', $balise, 1); |
|
| 2063 | 2063 | } // sinon une balise <a ...> ... </a> |
| 2064 | 2064 | else { |
| 2065 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2065 | + $balise = preg_replace(',\s?>,S', $insert.'>', $balise, 1); |
|
| 2066 | 2066 | } |
| 2067 | 2067 | } |
| 2068 | 2068 | |
@@ -2116,7 +2116,7 @@ discard block |
||
| 2116 | 2116 | $is_class_presente = false; |
| 2117 | 2117 | if ( |
| 2118 | 2118 | strpos($class_courante, $c) !== false |
| 2119 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2119 | + and preg_match('/(^|\s)'.preg_quote($c).'($|\s)/', $class_courante) |
|
| 2120 | 2120 | ) { |
| 2121 | 2121 | $is_class_presente = true; |
| 2122 | 2122 | } |
@@ -2124,13 +2124,13 @@ discard block |
||
| 2124 | 2124 | in_array($operation, ['ajouter', 'commuter']) |
| 2125 | 2125 | and !$is_class_presente |
| 2126 | 2126 | ) { |
| 2127 | - $class_new = rtrim($class_new) . ' ' . $c; |
|
| 2127 | + $class_new = rtrim($class_new).' '.$c; |
|
| 2128 | 2128 | } |
| 2129 | 2129 | elseif ( |
| 2130 | 2130 | in_array($operation, ['supprimer', 'commuter']) |
| 2131 | 2131 | and $is_class_presente |
| 2132 | 2132 | ) { |
| 2133 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2133 | + $class_new = trim(preg_replace('/(^|\s)'.preg_quote($c).'($|\s)/', "\\1", $class_new)); |
|
| 2134 | 2134 | } |
| 2135 | 2135 | } |
| 2136 | 2136 | } |
@@ -2196,7 +2196,7 @@ discard block |
||
| 2196 | 2196 | // Quelques fonctions de calcul arithmetique |
| 2197 | 2197 | // |
| 2198 | 2198 | function floatstr($a) { |
| 2199 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2199 | + return str_replace(',', '.', (string) floatval($a)); |
|
| 2200 | 2200 | } |
| 2201 | 2201 | function strize($f, $a, $b) { |
| 2202 | 2202 | return floatstr($f(floatstr($a), floatstr($b))); |
@@ -2330,13 +2330,13 @@ discard block |
||
| 2330 | 2330 | if (!defined('_TAGS_NOM_AUTEUR')) { |
| 2331 | 2331 | define('_TAGS_NOM_AUTEUR', ''); |
| 2332 | 2332 | } |
| 2333 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2333 | + $tags_acceptes = array_unique(explode(',', 'multi,'._TAGS_NOM_AUTEUR)); |
|
| 2334 | 2334 | foreach ($tags_acceptes as $tag) { |
| 2335 | 2335 | if (strlen($tag)) { |
| 2336 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2337 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2338 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2339 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2336 | + $remp1[] = '<'.trim($tag).'>'; |
|
| 2337 | + $remp1[] = '</'.trim($tag).'>'; |
|
| 2338 | + $remp2[] = '\x60'.trim($tag).'\x61'; |
|
| 2339 | + $remp2[] = '\x60/'.trim($tag).'\x61'; |
|
| 2340 | 2340 | } |
| 2341 | 2341 | } |
| 2342 | 2342 | $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
@@ -2390,7 +2390,7 @@ discard block |
||
| 2390 | 2390 | . http_img_pack( |
| 2391 | 2391 | 'attachment-16.png', |
| 2392 | 2392 | $t, |
| 2393 | - 'title="' . attribut_html($t) . '"' |
|
| 2393 | + 'title="'.attribut_html($t).'"' |
|
| 2394 | 2394 | ) |
| 2395 | 2395 | . '</a>', |
| 2396 | 2396 | $tag |
@@ -2454,10 +2454,10 @@ discard block |
||
| 2454 | 2454 | $fichier = basename($url); |
| 2455 | 2455 | |
| 2456 | 2456 | return '<a rel="enclosure"' |
| 2457 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2458 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2459 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2460 | - . '>' . $fichier . '</a>'; |
|
| 2457 | + . ($url ? ' href="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2458 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2459 | + . ($length ? ' title="'.spip_htmlspecialchars($length).'"' : '') |
|
| 2460 | + . '>'.$fichier.'</a>'; |
|
| 2461 | 2461 | } |
| 2462 | 2462 | |
| 2463 | 2463 | /** |
@@ -2485,9 +2485,9 @@ discard block |
||
| 2485 | 2485 | } # vieux data |
| 2486 | 2486 | $fichier = basename($url); |
| 2487 | 2487 | $enclosures[] = '<enclosure' |
| 2488 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2489 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2490 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2488 | + . ($url ? ' url="'.spip_htmlspecialchars($url).'"' : '') |
|
| 2489 | + . ($type ? ' type="'.spip_htmlspecialchars($type).'"' : '') |
|
| 2490 | + . ($length ? ' length="'.$length.'"' : '') |
|
| 2491 | 2491 | . ' />'; |
| 2492 | 2492 | } |
| 2493 | 2493 | } |
@@ -2513,7 +2513,7 @@ discard block |
||
| 2513 | 2513 | if (extraire_attribut($e, 'rel') == 'tag') { |
| 2514 | 2514 | $subjects .= '<dc:subject>' |
| 2515 | 2515 | . texte_backend(textebrut($e)) |
| 2516 | - . '</dc:subject>' . "\n"; |
|
| 2516 | + . '</dc:subject>'."\n"; |
|
| 2517 | 2517 | } |
| 2518 | 2518 | } |
| 2519 | 2519 | |
@@ -2549,7 +2549,7 @@ discard block |
||
| 2549 | 2549 | if (is_array($texte)) { |
| 2550 | 2550 | array_walk( |
| 2551 | 2551 | $texte, |
| 2552 | - function (&$a, $key, $t) { |
|
| 2552 | + function(&$a, $key, $t) { |
|
| 2553 | 2553 | $a = extraire_balise($a, $t); |
| 2554 | 2554 | }, |
| 2555 | 2555 | $tag |
@@ -2597,7 +2597,7 @@ discard block |
||
| 2597 | 2597 | if (is_array($texte)) { |
| 2598 | 2598 | array_walk( |
| 2599 | 2599 | $texte, |
| 2600 | - function (&$a, $key, $t) { |
|
| 2600 | + function(&$a, $key, $t) { |
|
| 2601 | 2601 | $a = extraire_balises($a, $t); |
| 2602 | 2602 | }, |
| 2603 | 2603 | $tag |
@@ -2729,7 +2729,7 @@ discard block |
||
| 2729 | 2729 | if ($fond != '404') { |
| 2730 | 2730 | $contexte = array_shift($p); |
| 2731 | 2731 | $contexte['page'] = $fond; |
| 2732 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2732 | + $action = preg_replace('/([?]'.preg_quote($fond).'[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2733 | 2733 | } |
| 2734 | 2734 | } |
| 2735 | 2735 | // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
@@ -2784,9 +2784,9 @@ discard block |
||
| 2784 | 2784 | . '"' |
| 2785 | 2785 | . (is_null($val) |
| 2786 | 2786 | ? '' |
| 2787 | - : ' value="' . entites_html($val) . '"' |
|
| 2787 | + : ' value="'.entites_html($val).'"' |
|
| 2788 | 2788 | ) |
| 2789 | - . ' type="hidden"' . "\n/>"; |
|
| 2789 | + . ' type="hidden"'."\n/>"; |
|
| 2790 | 2790 | } |
| 2791 | 2791 | |
| 2792 | 2792 | return join('', $hidden); |
@@ -2896,8 +2896,8 @@ discard block |
||
| 2896 | 2896 | |
| 2897 | 2897 | return preg_replace_callback( |
| 2898 | 2898 | ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
| 2899 | - function ($x) use ($path) { |
|
| 2900 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2899 | + function($x) use ($path) { |
|
| 2900 | + return "url('".suivre_lien($path, $x[1])."')"; |
|
| 2901 | 2901 | }, |
| 2902 | 2902 | $contenu |
| 2903 | 2903 | ); |
@@ -2959,14 +2959,14 @@ discard block |
||
| 2959 | 2959 | ) { |
| 2960 | 2960 | $distant = true; |
| 2961 | 2961 | $cssf = parse_url($css); |
| 2962 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2962 | + $cssf = $cssf['path'].($cssf['query'] ? '?'.$cssf['query'] : ''); |
|
| 2963 | 2963 | $cssf = preg_replace(',[?:&=],', '_', $cssf); |
| 2964 | 2964 | } else { |
| 2965 | 2965 | $distant = false; |
| 2966 | 2966 | $cssf = $css; |
| 2967 | 2967 | // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
| 2968 | 2968 | //propose (rien a faire dans ce cas) |
| 2969 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2969 | + $f = preg_replace(',(_rtl)?\.css$,i', '_'.$ndir.'.css', $css); |
|
| 2970 | 2970 | if (@file_exists($f)) { |
| 2971 | 2971 | return $f; |
| 2972 | 2972 | } |
@@ -2976,7 +2976,7 @@ discard block |
||
| 2976 | 2976 | $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
| 2977 | 2977 | $f = $dir_var |
| 2978 | 2978 | . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
| 2979 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2979 | + . '.'.substr(md5($cssf), 0, 4).'_'.$ndir.'.css'; |
|
| 2980 | 2980 | |
| 2981 | 2981 | // la css peut etre distante (url absolue !) |
| 2982 | 2982 | if ($distant) { |
@@ -3022,8 +3022,8 @@ discard block |
||
| 3022 | 3022 | } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
| 3023 | 3023 | elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
| 3024 | 3024 | $css_direction = substr($css_direction, strlen($dir_var)); |
| 3025 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3026 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3025 | + $src_faux_abs['/@@@@@@/'.$css_direction] = $css_direction; |
|
| 3026 | + $css_direction = '/@@@@@@/'.$css_direction; |
|
| 3027 | 3027 | } |
| 3028 | 3028 | $src[] = $regs[0][$k]; |
| 3029 | 3029 | $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
@@ -3072,7 +3072,7 @@ discard block |
||
| 3072 | 3072 | |
| 3073 | 3073 | $f = basename($css, '.css'); |
| 3074 | 3074 | $f = sous_repertoire(_DIR_VAR, 'cache-css') |
| 3075 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3075 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-".substr(md5("$css-urlabs"), 0, 4)."\\2", $f) |
|
| 3076 | 3076 | . '.css'; |
| 3077 | 3077 | |
| 3078 | 3078 | if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
@@ -3082,7 +3082,7 @@ discard block |
||
| 3082 | 3082 | if ($url_absolue_css == $css) { |
| 3083 | 3083 | if ( |
| 3084 | 3084 | strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
| 3085 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3085 | + or !lire_fichier(_DIR_RACINE.substr($css, $l), $contenu) |
|
| 3086 | 3086 | ) { |
| 3087 | 3087 | include_spip('inc/distant'); |
| 3088 | 3088 | $contenu = recuperer_url($css); |
@@ -3194,7 +3194,7 @@ discard block |
||
| 3194 | 3194 | $expression = str_replace('\/', '/', $expression); |
| 3195 | 3195 | $expression = str_replace('/', '\/', $expression); |
| 3196 | 3196 | |
| 3197 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3197 | + if (preg_match('/'.$expression.'/'.$modif, $texte, $r)) { |
|
| 3198 | 3198 | if (isset($r[$capte])) { |
| 3199 | 3199 | return $r[$capte]; |
| 3200 | 3200 | } else { |
@@ -3232,7 +3232,7 @@ discard block |
||
| 3232 | 3232 | $expression = str_replace('\/', '/', $expression); |
| 3233 | 3233 | $expression = str_replace('/', '\/', $expression); |
| 3234 | 3234 | |
| 3235 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3235 | + return preg_replace('/'.$expression.'/'.$modif, $replace, $texte); |
|
| 3236 | 3236 | } |
| 3237 | 3237 | |
| 3238 | 3238 | |
@@ -3251,7 +3251,7 @@ discard block |
||
| 3251 | 3251 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3252 | 3252 | |
| 3253 | 3253 | // Verifier dans le texte & les notes (pas beau, helas) |
| 3254 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3254 | + $t = $letexte.$GLOBALS['les_notes']; |
|
| 3255 | 3255 | |
| 3256 | 3256 | if ( |
| 3257 | 3257 | strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
@@ -3265,7 +3265,7 @@ discard block |
||
| 3265 | 3265 | if (!isset($doublons['documents'])) { |
| 3266 | 3266 | $doublons['documents'] = ''; |
| 3267 | 3267 | } |
| 3268 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3268 | + $doublons['documents'] .= ','.join(',', $matches[1]); |
|
| 3269 | 3269 | } |
| 3270 | 3270 | |
| 3271 | 3271 | return $letexte; |
@@ -3322,7 +3322,7 @@ discard block |
||
| 3322 | 3322 | if ($env) { |
| 3323 | 3323 | foreach ($env as $i => $j) { |
| 3324 | 3324 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3325 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3325 | + $texte .= "<param name='".attribut_html($i)."'\n\tvalue='".attribut_html($j)."' />"; |
|
| 3326 | 3326 | } |
| 3327 | 3327 | } |
| 3328 | 3328 | } |
@@ -3361,7 +3361,7 @@ discard block |
||
| 3361 | 3361 | if ($env) { |
| 3362 | 3362 | foreach ($env as $i => $j) { |
| 3363 | 3363 | if (is_string($j) and !in_array($i, $ignore_params)) { |
| 3364 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3364 | + $texte .= attribut_html($i)."='".attribut_html($j)."' "; |
|
| 3365 | 3365 | } |
| 3366 | 3366 | } |
| 3367 | 3367 | } |
@@ -3435,10 +3435,10 @@ discard block |
||
| 3435 | 3435 | // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
| 3436 | 3436 | if ( |
| 3437 | 3437 | preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
| 3438 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3438 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])).'-xx.svg' |
|
| 3439 | 3439 | and file_exists($variante_svg_generique) |
| 3440 | 3440 | ) { |
| 3441 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3441 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6).$m[1].'.svg' and file_exists($variante_svg_size)) { |
|
| 3442 | 3442 | $img_file = $variante_svg_size; |
| 3443 | 3443 | } |
| 3444 | 3444 | else { |
@@ -3496,7 +3496,7 @@ discard block |
||
| 3496 | 3496 | return ''; |
| 3497 | 3497 | } |
| 3498 | 3498 | } |
| 3499 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3499 | + $atts .= " width='".$largeur."' height='".$hauteur."'"; |
|
| 3500 | 3500 | } |
| 3501 | 3501 | |
| 3502 | 3502 | if (file_exists($img_file)) { |
@@ -3506,14 +3506,14 @@ discard block |
||
| 3506 | 3506 | $alt = ''; |
| 3507 | 3507 | } |
| 3508 | 3508 | elseif ($alt or $alt === '') { |
| 3509 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3509 | + $alt = " alt='".attribut_html($alt)."'"; |
|
| 3510 | 3510 | } |
| 3511 | 3511 | else { |
| 3512 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3512 | + $alt = " alt='".attribut_html($title)."'"; |
|
| 3513 | 3513 | } |
| 3514 | 3514 | return "<img src='$img_file'$alt" |
| 3515 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3516 | - . ' ' . ltrim($atts) |
|
| 3515 | + . ($title ? ' title="'.attribut_html($title).'"' : '') |
|
| 3516 | + . ' '.ltrim($atts) |
|
| 3517 | 3517 | . ' />'; |
| 3518 | 3518 | } |
| 3519 | 3519 | |
@@ -3527,10 +3527,10 @@ discard block |
||
| 3527 | 3527 | */ |
| 3528 | 3528 | function http_style_background($img, $att = '', $size = null) { |
| 3529 | 3529 | if ($size and is_numeric($size)) { |
| 3530 | - $size = trim($size) . 'px'; |
|
| 3530 | + $size = trim($size).'px'; |
|
| 3531 | 3531 | } |
| 3532 | - return " style='background" . |
|
| 3533 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3532 | + return " style='background". |
|
| 3533 | + ($att ? '' : '-image').': url("'.chemin_image($img).'")'.($att ? (' '.$att) : '').';' |
|
| 3534 | 3534 | . ($size ? "background-size:{$size};" : '') |
| 3535 | 3535 | . "'"; |
| 3536 | 3536 | } |
@@ -3645,7 +3645,7 @@ discard block |
||
| 3645 | 3645 | $img = http_img_pack( |
| 3646 | 3646 | $img, |
| 3647 | 3647 | $alt, |
| 3648 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3648 | + $class ? " class='".attribut_html($class)."'" : '', |
|
| 3649 | 3649 | '', |
| 3650 | 3650 | ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
| 3651 | 3651 | ); |
@@ -3717,7 +3717,7 @@ discard block |
||
| 3717 | 3717 | $balise_svg_source = $balise_svg; |
| 3718 | 3718 | |
| 3719 | 3719 | // entete XML à supprimer |
| 3720 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3720 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?'.'>,', '', $svg); |
|
| 3721 | 3721 | |
| 3722 | 3722 | // IE est toujours mon ami |
| 3723 | 3723 | $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
@@ -3735,9 +3735,9 @@ discard block |
||
| 3735 | 3735 | // regler le alt |
| 3736 | 3736 | if ($alt) { |
| 3737 | 3737 | $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
| 3738 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3738 | + $id = 'img-svg-title-'.substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3739 | 3739 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3740 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3740 | + $title = "<title id=\"$id\">".entites_html($alt)."</title>\n"; |
|
| 3741 | 3741 | $balise_svg .= $title; |
| 3742 | 3742 | } |
| 3743 | 3743 | else { |
@@ -3785,7 +3785,7 @@ discard block |
||
| 3785 | 3785 | if (is_array($tableau)) { |
| 3786 | 3786 | foreach ($tableau as $k => $v) { |
| 3787 | 3787 | $res = recuperer_fond( |
| 3788 | - 'modeles/' . $modele, |
|
| 3788 | + 'modeles/'.$modele, |
|
| 3789 | 3789 | array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
| 3790 | 3790 | ); |
| 3791 | 3791 | $texte .= $res; |
@@ -3969,7 +3969,7 @@ discard block |
||
| 3969 | 3969 | } |
| 3970 | 3970 | |
| 3971 | 3971 | $c = serialize($c); |
| 3972 | - $cle = calculer_cle_action($form . $c); |
|
| 3972 | + $cle = calculer_cle_action($form.$c); |
|
| 3973 | 3973 | $c = "$cle:$c"; |
| 3974 | 3974 | |
| 3975 | 3975 | // on ne stocke pas les contextes dans des fichiers en cache |
@@ -4027,15 +4027,15 @@ discard block |
||
| 4027 | 4027 | } |
| 4028 | 4028 | // toujours encoder l'url source dans le bloc ajax |
| 4029 | 4029 | $r = self(); |
| 4030 | - $r = ' data-origin="' . $r . '"'; |
|
| 4030 | + $r = ' data-origin="'.$r.'"'; |
|
| 4031 | 4031 | $class = 'ajaxbloc'; |
| 4032 | 4032 | if ($ajaxid and is_string($ajaxid)) { |
| 4033 | 4033 | // ajaxid est normalement conforme a un nom de classe css |
| 4034 | 4034 | // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
| 4035 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4035 | + $class .= ' ajax-id-'.entites_html($ajaxid); |
|
| 4036 | 4036 | } |
| 4037 | 4037 | |
| 4038 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4038 | + return "<div class='$class' "."data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4039 | 4039 | } |
| 4040 | 4040 | |
| 4041 | 4041 | /** |
@@ -4079,7 +4079,7 @@ discard block |
||
| 4079 | 4079 | $cle = substr($c, 0, $p); |
| 4080 | 4080 | $c = substr($c, $p + 1); |
| 4081 | 4081 | |
| 4082 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4082 | + if ($cle == calculer_cle_action($form.$c)) { |
|
| 4083 | 4083 | $env = @unserialize($c); |
| 4084 | 4084 | return $env; |
| 4085 | 4085 | } |
@@ -4200,13 +4200,13 @@ discard block |
||
| 4200 | 4200 | } |
| 4201 | 4201 | } |
| 4202 | 4202 | } |
| 4203 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4203 | + $att .= 'class="'.($class ? attribut_html($class).' ' : '').(defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on').'"'; |
|
| 4204 | 4204 | } else { |
| 4205 | 4205 | $bal = 'a'; |
| 4206 | 4206 | $att = "href='$url'" |
| 4207 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4208 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4209 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4207 | + . ($title ? " title='".attribut_html($title)."'" : '') |
|
| 4208 | + . ($class ? " class='".attribut_html($class)."'" : '') |
|
| 4209 | + . ($rel ? " rel='".attribut_html($rel)."'" : '') |
|
| 4210 | 4210 | . $evt; |
| 4211 | 4211 | } |
| 4212 | 4212 | if ($libelle === null) { |
@@ -4345,7 +4345,7 @@ discard block |
||
| 4345 | 4345 | |
| 4346 | 4346 | // Icône |
| 4347 | 4347 | $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
| 4348 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4348 | + $icone = '<span class="icone-image'.($fonction ? " icone-fonction icone-fonction-$fonction" : '')."\">$icone</span>"; |
|
| 4349 | 4349 | |
| 4350 | 4350 | // Markup final |
| 4351 | 4351 | if ($type == 'lien') { |
@@ -4622,20 +4622,20 @@ discard block |
||
| 4622 | 4622 | $class_form = 'ajax'; |
| 4623 | 4623 | $class = str_replace('ajax', '', $class); |
| 4624 | 4624 | } |
| 4625 | - $class_btn = 'submit ' . trim($class); |
|
| 4625 | + $class_btn = 'submit '.trim($class); |
|
| 4626 | 4626 | |
| 4627 | 4627 | if ($confirm) { |
| 4628 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4628 | + $confirm = 'confirm("'.attribut_html($confirm).'")'; |
|
| 4629 | 4629 | if ($callback) { |
| 4630 | 4630 | $callback = "$confirm?($callback):false"; |
| 4631 | 4631 | } else { |
| 4632 | 4632 | $callback = $confirm; |
| 4633 | 4633 | } |
| 4634 | 4634 | } |
| 4635 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4635 | + $onclick = $callback ? " onclick='return ".addcslashes($callback, "'")."'" : ''; |
|
| 4636 | 4636 | $title = $title ? " title='$title'" : ''; |
| 4637 | 4637 | |
| 4638 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4638 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>".form_hidden($url) |
|
| 4639 | 4639 | . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
| 4640 | 4640 | } |
| 4641 | 4641 | |
@@ -4700,14 +4700,14 @@ discard block |
||
| 4700 | 4700 | $champ_titre = ''; |
| 4701 | 4701 | if ($demande_titre) { |
| 4702 | 4702 | // si pas de titre declare mais champ titre, il sera peuple par le select * |
| 4703 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4703 | + $champ_titre = (!empty($desc['titre'])) ? ', '.$desc['titre'] : ''; |
|
| 4704 | 4704 | } |
| 4705 | 4705 | include_spip('base/abstract_sql'); |
| 4706 | 4706 | include_spip('base/connect_sql'); |
| 4707 | 4707 | $objets[$type_objet][$id_objet] = sql_fetsel( |
| 4708 | - '*' . $champ_titre, |
|
| 4708 | + '*'.$champ_titre, |
|
| 4709 | 4709 | $desc['table_sql'], |
| 4710 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4710 | + id_table_objet($type_objet).' = '.intval($id_objet) |
|
| 4711 | 4711 | ); |
| 4712 | 4712 | |
| 4713 | 4713 | // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
@@ -4785,8 +4785,7 @@ discard block |
||
| 4785 | 4785 | if (isset($ligne_sql['chapo'])) { |
| 4786 | 4786 | $chapo = $ligne_sql['chapo']; |
| 4787 | 4787 | $texte = strlen($descriptif) ? |
| 4788 | - '' : |
|
| 4789 | - "$chapo \n\n $texte"; |
|
| 4788 | + '' : "$chapo \n\n $texte"; |
|
| 4790 | 4789 | } |
| 4791 | 4790 | |
| 4792 | 4791 | // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
@@ -4853,7 +4852,7 @@ discard block |
||
| 4853 | 4852 | return $texte; |
| 4854 | 4853 | } |
| 4855 | 4854 | |
| 4856 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4855 | + $traitement = str_replace('%s', "'".texte_script($texte)."'", $traitement); |
|
| 4857 | 4856 | |
| 4858 | 4857 | // Fournir $connect et $Pile[0] au traitement si besoin |
| 4859 | 4858 | $Pile = [0 => $env]; |
@@ -4887,7 +4886,7 @@ discard block |
||
| 4887 | 4886 | } |
| 4888 | 4887 | $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
| 4889 | 4888 | |
| 4890 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4889 | + return "<a href='$url' class='$objet'>".couper($titre, $longueur).'</a>'; |
|
| 4891 | 4890 | } |
| 4892 | 4891 | |
| 4893 | 4892 | |
@@ -4906,10 +4905,10 @@ discard block |
||
| 4906 | 4905 | function wrap($texte, $wrap) { |
| 4907 | 4906 | $balises = extraire_balises($wrap); |
| 4908 | 4907 | if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
| 4909 | - $texte = $wrap . $texte; |
|
| 4908 | + $texte = $wrap.$texte; |
|
| 4910 | 4909 | $regs = array_reverse($regs[1]); |
| 4911 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4912 | - $texte = $texte . $wrap; |
|
| 4910 | + $wrap = '</'.implode('></', $regs).'>'; |
|
| 4911 | + $texte = $texte.$wrap; |
|
| 4913 | 4912 | } |
| 4914 | 4913 | |
| 4915 | 4914 | return $texte; |
@@ -4940,7 +4939,7 @@ discard block |
||
| 4940 | 4939 | |
| 4941 | 4940 | // caster $u en array si besoin |
| 4942 | 4941 | if (is_object($u)) { |
| 4943 | - $u = (array)$u; |
|
| 4942 | + $u = (array) $u; |
|
| 4944 | 4943 | } |
| 4945 | 4944 | |
| 4946 | 4945 | if (is_array($u)) { |
@@ -4962,7 +4961,7 @@ discard block |
||
| 4962 | 4961 | // sinon on passe a la ligne et on indente |
| 4963 | 4962 | $i_str = str_pad('', $indent, ' '); |
| 4964 | 4963 | foreach ($u as $k => $v) { |
| 4965 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4964 | + $out .= $join.$i_str."$k: ".filtre_print_dist($v, $join, $indent + 2); |
|
| 4966 | 4965 | } |
| 4967 | 4966 | |
| 4968 | 4967 | return $out; |
@@ -5016,7 +5015,7 @@ discard block |
||
| 5016 | 5015 | * @return string |
| 5017 | 5016 | */ |
| 5018 | 5017 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5019 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5018 | + $icone = objet_info($objet, 'icone_objet').'-'.$taille.'.png'; |
|
| 5020 | 5019 | $icone = chemin_image($icone); |
| 5021 | 5020 | $balise_img = charger_filtre('balise_img'); |
| 5022 | 5021 | |
@@ -5042,7 +5041,7 @@ discard block |
||
| 5042 | 5041 | */ |
| 5043 | 5042 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5044 | 5043 | $chaine = explode(':', $chaine); |
| 5045 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5044 | + if ($t = _T($objet.':'.end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5046 | 5045 | return $t; |
| 5047 | 5046 | } |
| 5048 | 5047 | $chaine = implode(':', $chaine); |
@@ -5108,7 +5107,7 @@ discard block |
||
| 5108 | 5107 | $cache = recuperer_fond($fond, $contexte, $options, $connect); |
| 5109 | 5108 | |
| 5110 | 5109 | // calculer le nom de la css |
| 5111 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5110 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-'.$extension); |
|
| 5112 | 5111 | $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
| 5113 | 5112 | $contexte_implicite = calculer_contexte_implicite(); |
| 5114 | 5113 | |
@@ -5116,14 +5115,14 @@ discard block |
||
| 5116 | 5115 | // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
| 5117 | 5116 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5118 | 5117 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5119 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5118 | + $hash = md5($contexte_implicite['host'].'::'.$cache); |
|
| 5120 | 5119 | } |
| 5121 | 5120 | else { |
| 5122 | 5121 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5123 | 5122 | ksort($contexte); |
| 5124 | - $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 5123 | + $hash = md5($fond.json_encode($contexte_implicite).json_encode($contexte).$connect); |
|
| 5125 | 5124 | } |
| 5126 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5125 | + $filename = $dir_var.$extension."dyn-$nom_safe-".substr($hash, 0, 8).".$extension"; |
|
| 5127 | 5126 | |
| 5128 | 5127 | // mettre a jour le fichier si il n'existe pas |
| 5129 | 5128 | // ou trop ancien |
@@ -5131,8 +5130,8 @@ discard block |
||
| 5131 | 5130 | // et recopie sur le fichier cible uniquement si il change |
| 5132 | 5131 | if ( |
| 5133 | 5132 | !file_exists($filename) |
| 5134 | - or !file_exists($filename . '.last') |
|
| 5135 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5133 | + or !file_exists($filename.'.last') |
|
| 5134 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename.'.last') < $cache['lastmodified']) |
|
| 5136 | 5135 | or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
| 5137 | 5136 | ) { |
| 5138 | 5137 | $contenu = $cache['texte']; |
@@ -5153,10 +5152,10 @@ discard block |
||
| 5153 | 5152 | } |
| 5154 | 5153 | // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
| 5155 | 5154 | // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
| 5156 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5155 | + $comment .= "}\n md5:".md5($contenu)." */\n"; |
|
| 5157 | 5156 | } |
| 5158 | 5157 | // et ecrire le fichier si il change |
| 5159 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5158 | + ecrire_fichier_calcule_si_modifie($filename, $comment.$contenu, false, true); |
|
| 5160 | 5159 | } |
| 5161 | 5160 | |
| 5162 | 5161 | return timestamp($filename); |
@@ -5382,7 +5381,7 @@ discard block |
||
| 5382 | 5381 | if ($e > 0 and strlen($mid) > 8) { |
| 5383 | 5382 | $mid = '***...***'; |
| 5384 | 5383 | } |
| 5385 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5384 | + return substr($passe, 0, $e).$mid.($e > 0 ? substr($passe, -$e) : ''); |
|
| 5386 | 5385 | } |
| 5387 | 5386 | |
| 5388 | 5387 | |
@@ -5444,7 +5443,7 @@ discard block |
||
| 5444 | 5443 | case 'id': |
| 5445 | 5444 | case 'anchor': |
| 5446 | 5445 | if (preg_match(',^\d,', $texte)) { |
| 5447 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5446 | + $texte = substr($type, 0, 1).$texte; |
|
| 5448 | 5447 | } |
| 5449 | 5448 | } |
| 5450 | 5449 | |
@@ -5454,9 +5453,9 @@ discard block |
||
| 5454 | 5453 | |
| 5455 | 5454 | if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
| 5456 | 5455 | if (preg_match(',^\d,', $texte)) { |
| 5457 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5456 | + $texte = ($type ? substr($type, 0, 1) : 's').$texte; |
|
| 5458 | 5457 | } |
| 5459 | - $texte .= $separateur . md5($original); |
|
| 5458 | + $texte .= $separateur.md5($original); |
|
| 5460 | 5459 | $texte = substr($texte, 0, $longueur_mini); |
| 5461 | 5460 | } |
| 5462 | 5461 | |
@@ -631,8 +631,7 @@ discard block |
||
| 631 | 631 | if (!$srcHeight) { |
| 632 | 632 | $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
| 633 | 633 | } |
| 634 | - } |
|
| 635 | - elseif (strpos($src, '<svg') !== false) { |
|
| 634 | + } elseif (strpos($src, '<svg') !== false) { |
|
| 636 | 635 | include_spip('inc/svg'); |
| 637 | 636 | if ($attrs = svg_lire_attributs($src)) { |
| 638 | 637 | list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
@@ -2125,8 +2124,7 @@ discard block |
||
| 2125 | 2124 | and !$is_class_presente |
| 2126 | 2125 | ) { |
| 2127 | 2126 | $class_new = rtrim($class_new) . ' ' . $c; |
| 2128 | - } |
|
| 2129 | - elseif ( |
|
| 2127 | + } elseif ( |
|
| 2130 | 2128 | in_array($operation, ['supprimer', 'commuter']) |
| 2131 | 2129 | and $is_class_presente |
| 2132 | 2130 | ) { |
@@ -2138,8 +2136,7 @@ discard block |
||
| 2138 | 2136 | if ($class_new !== $class_courante) { |
| 2139 | 2137 | if (strlen($class_new)) { |
| 2140 | 2138 | $balise = inserer_attribut($balise, 'class', $class_new); |
| 2141 | - } |
|
| 2142 | - elseif ($class_courante) { |
|
| 2139 | + } elseif ($class_courante) { |
|
| 2143 | 2140 | $balise = vider_attribut($balise, 'class'); |
| 2144 | 2141 | } |
| 2145 | 2142 | } |
@@ -3440,8 +3437,7 @@ discard block |
||
| 3440 | 3437 | ) { |
| 3441 | 3438 | if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
| 3442 | 3439 | $img_file = $variante_svg_size; |
| 3443 | - } |
|
| 3444 | - else { |
|
| 3440 | + } else { |
|
| 3445 | 3441 | $img_file = $variante_svg_generique; |
| 3446 | 3442 | } |
| 3447 | 3443 | } |
@@ -3473,8 +3469,7 @@ discard block |
||
| 3473 | 3469 | } |
| 3474 | 3470 | if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
| 3475 | 3471 | $img_file = chemin_image($img); |
| 3476 | - } |
|
| 3477 | - else { |
|
| 3472 | + } else { |
|
| 3478 | 3473 | if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
| 3479 | 3474 | $img_file = http_img_variante_svg_si_possible($img_file); |
| 3480 | 3475 | } |
@@ -3504,11 +3499,9 @@ discard block |
||
| 3504 | 3499 | } |
| 3505 | 3500 | if ($alt === false) { |
| 3506 | 3501 | $alt = ''; |
| 3507 | - } |
|
| 3508 | - elseif ($alt or $alt === '') { |
|
| 3502 | + } elseif ($alt or $alt === '') { |
|
| 3509 | 3503 | $alt = " alt='" . attribut_html($alt) . "'"; |
| 3510 | - } |
|
| 3511 | - else { |
|
| 3504 | + } else { |
|
| 3512 | 3505 | $alt = " alt='" . attribut_html($title) . "'"; |
| 3513 | 3506 | } |
| 3514 | 3507 | return "<img src='$img_file'$alt" |
@@ -3635,13 +3628,11 @@ discard block |
||
| 3635 | 3628 | if (!is_null($class)) { |
| 3636 | 3629 | if (strlen($class)) { |
| 3637 | 3630 | $img = inserer_attribut($img, 'class', $class); |
| 3638 | - } |
|
| 3639 | - else { |
|
| 3631 | + } else { |
|
| 3640 | 3632 | $img = vider_attribut($img, 'class'); |
| 3641 | 3633 | } |
| 3642 | 3634 | } |
| 3643 | - } |
|
| 3644 | - else { |
|
| 3635 | + } else { |
|
| 3645 | 3636 | $img = http_img_pack( |
| 3646 | 3637 | $img, |
| 3647 | 3638 | $alt, |
@@ -3726,8 +3717,7 @@ discard block |
||
| 3726 | 3717 | if (!is_null($class)) { |
| 3727 | 3718 | if (strlen($class)) { |
| 3728 | 3719 | $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
| 3729 | - } |
|
| 3730 | - else { |
|
| 3720 | + } else { |
|
| 3731 | 3721 | $balise_svg = vider_attribut($balise_svg, 'class'); |
| 3732 | 3722 | } |
| 3733 | 3723 | } |
@@ -3739,8 +3729,7 @@ discard block |
||
| 3739 | 3729 | $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
| 3740 | 3730 | $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
| 3741 | 3731 | $balise_svg .= $title; |
| 3742 | - } |
|
| 3743 | - else { |
|
| 3732 | + } else { |
|
| 3744 | 3733 | $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
| 3745 | 3734 | } |
| 3746 | 3735 | |
@@ -5117,8 +5106,7 @@ discard block |
||
| 5117 | 5106 | // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
| 5118 | 5107 | if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
| 5119 | 5108 | $hash = md5($contexte_implicite['host'] . '::' . $cache); |
| 5120 | - } |
|
| 5121 | - else { |
|
| 5109 | + } else { |
|
| 5122 | 5110 | unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
| 5123 | 5111 | ksort($contexte); |
| 5124 | 5112 | $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Filtres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/charsets'); |
@@ -42,8 +42,8 @@ discard block |
||
| 42 | 42 | * @return string Fonction PHP correspondante du filtre |
| 43 | 43 | */ |
| 44 | 44 | function charger_filtre($fonc, $default = 'filtre_identite_dist') { |
| 45 | - include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | - return chercher_filtre($fonc, $default); |
|
| 45 | + include_fichiers_fonctions(); // inclure les fichiers fonctions |
|
| 46 | + return chercher_filtre($fonc, $default); |
|
| 47 | 47 | } |
| 48 | 48 | |
| 49 | 49 | /** |
@@ -53,7 +53,7 @@ discard block |
||
| 53 | 53 | * @return string Texte |
| 54 | 54 | **/ |
| 55 | 55 | function filtre_identite_dist($texte) { |
| 56 | - return $texte; |
|
| 56 | + return $texte; |
|
| 57 | 57 | } |
| 58 | 58 | |
| 59 | 59 | /** |
@@ -77,38 +77,38 @@ discard block |
||
| 77 | 77 | * Fonction PHP correspondante du filtre demandé |
| 78 | 78 | */ |
| 79 | 79 | function chercher_filtre($fonc, $default = null) { |
| 80 | - if (!$fonc) { |
|
| 81 | - return $default; |
|
| 82 | - } |
|
| 83 | - // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | - // Foo::Bar |
|
| 85 | - // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | - if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | - $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | - $f = chercher_filtre($nom); |
|
| 89 | - // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | - // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | - if (!$f and $nom !== $fonc) { |
|
| 92 | - $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | - } |
|
| 94 | - |
|
| 95 | - return $f; |
|
| 96 | - } |
|
| 97 | - |
|
| 98 | - include_fichiers_fonctions(); |
|
| 99 | - foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | - trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | - // fonction ou name\space\fonction |
|
| 102 | - if (is_callable($f)) { |
|
| 103 | - return $f; |
|
| 104 | - } |
|
| 105 | - // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | - elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | - return $f; |
|
| 108 | - } |
|
| 109 | - } |
|
| 110 | - |
|
| 111 | - return $default; |
|
| 80 | + if (!$fonc) { |
|
| 81 | + return $default; |
|
| 82 | + } |
|
| 83 | + // Cas des types mime, sans confondre avec les appels de fonction de classe |
|
| 84 | + // Foo::Bar |
|
| 85 | + // qui peuvent etre avec un namespace : space\Foo::Bar |
|
| 86 | + if (preg_match(',^[\w]+/,', $fonc)) { |
|
| 87 | + $nom = preg_replace(',\W,', '_', $fonc); |
|
| 88 | + $f = chercher_filtre($nom); |
|
| 89 | + // cas du sous-type MIME sans filtre associe, passer au type: |
|
| 90 | + // si filtre_text_plain pas defini, passe a filtre_text |
|
| 91 | + if (!$f and $nom !== $fonc) { |
|
| 92 | + $f = chercher_filtre(preg_replace(',\W.*$,', '', $fonc)); |
|
| 93 | + } |
|
| 94 | + |
|
| 95 | + return $f; |
|
| 96 | + } |
|
| 97 | + |
|
| 98 | + include_fichiers_fonctions(); |
|
| 99 | + foreach (['filtre_' . $fonc, 'filtre_' . $fonc . '_dist', $fonc] as $f) { |
|
| 100 | + trouver_filtre_matrice($f); // charge des fichiers spécifiques éventuels |
|
| 101 | + // fonction ou name\space\fonction |
|
| 102 | + if (is_callable($f)) { |
|
| 103 | + return $f; |
|
| 104 | + } |
|
| 105 | + // méthode statique d'une classe Classe::methode ou name\space\Classe::methode |
|
| 106 | + elseif (false === strpos($f, '::') and is_callable([$f])) { |
|
| 107 | + return $f; |
|
| 108 | + } |
|
| 109 | + } |
|
| 110 | + |
|
| 111 | + return $default; |
|
| 112 | 112 | } |
| 113 | 113 | |
| 114 | 114 | /** |
@@ -152,8 +152,8 @@ discard block |
||
| 152 | 152 | * Chaîne vide sinon. |
| 153 | 153 | **/ |
| 154 | 154 | function appliquer_filtre($arg, $filtre) { |
| 155 | - $args = func_get_args(); |
|
| 156 | - return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 155 | + $args = func_get_args(); |
|
| 156 | + return appliquer_filtre_sinon($arg, $filtre, $args, ''); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | /** |
@@ -178,8 +178,8 @@ discard block |
||
| 178 | 178 | * Texte d'origine sinon |
| 179 | 179 | **/ |
| 180 | 180 | function appliquer_si_filtre($arg, $filtre) { |
| 181 | - $args = func_get_args(); |
|
| 182 | - return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 181 | + $args = func_get_args(); |
|
| 182 | + return appliquer_filtre_sinon($arg, $filtre, $args, $arg); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -195,12 +195,12 @@ discard block |
||
| 195 | 195 | * Version de SPIP |
| 196 | 196 | **/ |
| 197 | 197 | function spip_version() { |
| 198 | - $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | - if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | - $version .= " $vcs_version"; |
|
| 201 | - } |
|
| 198 | + $version = $GLOBALS['spip_version_affichee']; |
|
| 199 | + if ($vcs_version = version_vcs_courante(_DIR_RACINE)) { |
|
| 200 | + $version .= " $vcs_version"; |
|
| 201 | + } |
|
| 202 | 202 | |
| 203 | - return $version; |
|
| 203 | + return $version; |
|
| 204 | 204 | } |
| 205 | 205 | |
| 206 | 206 | /** |
@@ -213,19 +213,19 @@ discard block |
||
| 213 | 213 | * - string|null si $raw = false |
| 214 | 214 | */ |
| 215 | 215 | function version_vcs_courante($dir, $raw = false) { |
| 216 | - $desc = decrire_version_git($dir); |
|
| 217 | - if ($desc === null) { |
|
| 218 | - $desc = decrire_version_svn($dir); |
|
| 219 | - } |
|
| 220 | - if ($desc === null or $raw) { |
|
| 221 | - return $desc; |
|
| 222 | - } |
|
| 223 | - // affichage "GIT [master: abcdef]" |
|
| 224 | - $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 225 | - if ($desc['branch']) { |
|
| 226 | - $commit = $desc['branch'] . ': ' . $commit; |
|
| 227 | - } |
|
| 228 | - return "{$desc['vcs']} [$commit]"; |
|
| 216 | + $desc = decrire_version_git($dir); |
|
| 217 | + if ($desc === null) { |
|
| 218 | + $desc = decrire_version_svn($dir); |
|
| 219 | + } |
|
| 220 | + if ($desc === null or $raw) { |
|
| 221 | + return $desc; |
|
| 222 | + } |
|
| 223 | + // affichage "GIT [master: abcdef]" |
|
| 224 | + $commit = isset($desc['commit_short']) ? $desc['commit_short'] : $desc['commit']; |
|
| 225 | + if ($desc['branch']) { |
|
| 226 | + $commit = $desc['branch'] . ': ' . $commit; |
|
| 227 | + } |
|
| 228 | + return "{$desc['vcs']} [$commit]"; |
|
| 229 | 229 | } |
| 230 | 230 | |
| 231 | 231 | /** |
@@ -237,24 +237,24 @@ discard block |
||
| 237 | 237 | * array ['branch' => xx, 'commit' => yy] sinon. |
| 238 | 238 | **/ |
| 239 | 239 | function decrire_version_git($dir) { |
| 240 | - if (!$dir) { |
|
| 241 | - $dir = '.'; |
|
| 242 | - } |
|
| 240 | + if (!$dir) { |
|
| 241 | + $dir = '.'; |
|
| 242 | + } |
|
| 243 | 243 | |
| 244 | - // version installee par GIT |
|
| 245 | - if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 246 | - $currentHead = trim(substr($c, 4)); |
|
| 247 | - if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 248 | - return [ |
|
| 249 | - 'vcs' => 'GIT', |
|
| 250 | - 'branch' => basename($currentHead), |
|
| 251 | - 'commit' => trim($hash), |
|
| 252 | - 'commit_short' => substr(trim($hash), 0, 8), |
|
| 253 | - ]; |
|
| 254 | - } |
|
| 255 | - } |
|
| 244 | + // version installee par GIT |
|
| 245 | + if (lire_fichier($dir . '/.git/HEAD', $c)) { |
|
| 246 | + $currentHead = trim(substr($c, 4)); |
|
| 247 | + if (lire_fichier($dir . '/.git/' . $currentHead, $hash)) { |
|
| 248 | + return [ |
|
| 249 | + 'vcs' => 'GIT', |
|
| 250 | + 'branch' => basename($currentHead), |
|
| 251 | + 'commit' => trim($hash), |
|
| 252 | + 'commit_short' => substr(trim($hash), 0, 8), |
|
| 253 | + ]; |
|
| 254 | + } |
|
| 255 | + } |
|
| 256 | 256 | |
| 257 | - return null; |
|
| 257 | + return null; |
|
| 258 | 258 | } |
| 259 | 259 | |
| 260 | 260 | |
@@ -267,25 +267,25 @@ discard block |
||
| 267 | 267 | * array ['commit' => yy, 'date' => xx, 'author' => xx] sinon. |
| 268 | 268 | **/ |
| 269 | 269 | function decrire_version_svn($dir) { |
| 270 | - if (!$dir) { |
|
| 271 | - $dir = '.'; |
|
| 272 | - } |
|
| 273 | - // version installee par SVN |
|
| 274 | - if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | - $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 276 | - $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 277 | - if ($result) { |
|
| 278 | - $row = $result->fetchArray(); |
|
| 279 | - if ($row['changed_revision'] != '') { |
|
| 280 | - return [ |
|
| 281 | - 'vcs' => 'SVN', |
|
| 282 | - 'branch' => '', |
|
| 283 | - 'commit' => $row['changed_revision'], |
|
| 284 | - ]; |
|
| 285 | - } |
|
| 286 | - } |
|
| 287 | - } |
|
| 288 | - return null; |
|
| 270 | + if (!$dir) { |
|
| 271 | + $dir = '.'; |
|
| 272 | + } |
|
| 273 | + // version installee par SVN |
|
| 274 | + if (file_exists($dir . '/.svn/wc.db') && class_exists('SQLite3')) { |
|
| 275 | + $db = new SQLite3($dir . '/.svn/wc.db'); |
|
| 276 | + $result = $db->query('SELECT changed_revision FROM nodes WHERE local_relpath = "" LIMIT 1'); |
|
| 277 | + if ($result) { |
|
| 278 | + $row = $result->fetchArray(); |
|
| 279 | + if ($row['changed_revision'] != '') { |
|
| 280 | + return [ |
|
| 281 | + 'vcs' => 'SVN', |
|
| 282 | + 'branch' => '', |
|
| 283 | + 'commit' => $row['changed_revision'], |
|
| 284 | + ]; |
|
| 285 | + } |
|
| 286 | + } |
|
| 287 | + } |
|
| 288 | + return null; |
|
| 289 | 289 | } |
| 290 | 290 | |
| 291 | 291 | // La matrice est necessaire pour ne filtrer _que_ des fonctions definies dans filtres_images |
@@ -332,18 +332,18 @@ discard block |
||
| 332 | 332 | * Code HTML retourné par le filtre |
| 333 | 333 | **/ |
| 334 | 334 | function filtrer($filtre) { |
| 335 | - $tous = func_get_args(); |
|
| 336 | - if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 337 | - return image_filtrer($tous); |
|
| 338 | - } elseif ($f = chercher_filtre($filtre)) { |
|
| 339 | - array_shift($tous); |
|
| 340 | - return call_user_func_array($f, $tous); |
|
| 341 | - } else { |
|
| 342 | - // le filtre n'existe pas, on provoque une erreur |
|
| 343 | - $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 344 | - erreur_squelette($msg); |
|
| 345 | - return ''; |
|
| 346 | - } |
|
| 335 | + $tous = func_get_args(); |
|
| 336 | + if (trouver_filtre_matrice($filtre) and substr($filtre, 0, 6) == 'image_') { |
|
| 337 | + return image_filtrer($tous); |
|
| 338 | + } elseif ($f = chercher_filtre($filtre)) { |
|
| 339 | + array_shift($tous); |
|
| 340 | + return call_user_func_array($f, $tous); |
|
| 341 | + } else { |
|
| 342 | + // le filtre n'existe pas, on provoque une erreur |
|
| 343 | + $msg = ['zbug_erreur_filtre', ['filtre' => texte_script($filtre)]]; |
|
| 344 | + erreur_squelette($msg); |
|
| 345 | + return ''; |
|
| 346 | + } |
|
| 347 | 347 | } |
| 348 | 348 | |
| 349 | 349 | /** |
@@ -360,11 +360,11 @@ discard block |
||
| 360 | 360 | * @return bool true si on trouve le filtre dans la matrice, false sinon. |
| 361 | 361 | */ |
| 362 | 362 | function trouver_filtre_matrice($filtre) { |
| 363 | - if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 364 | - find_in_path($f, '', true); |
|
| 365 | - $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 366 | - } |
|
| 367 | - return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 363 | + if (isset($GLOBALS['spip_matrice'][$filtre]) and is_string($f = $GLOBALS['spip_matrice'][$filtre])) { |
|
| 364 | + find_in_path($f, '', true); |
|
| 365 | + $GLOBALS['spip_matrice'][$filtre] = true; |
|
| 366 | + } |
|
| 367 | + return !empty($GLOBALS['spip_matrice'][$filtre]); |
|
| 368 | 368 | } |
| 369 | 369 | |
| 370 | 370 | |
@@ -392,8 +392,8 @@ discard block |
||
| 392 | 392 | * @return mixed |
| 393 | 393 | */ |
| 394 | 394 | function filtre_set(&$Pile, $val, $key, $continue = null) { |
| 395 | - $Pile['vars'][$key] = $val; |
|
| 396 | - return $continue ? $val : ''; |
|
| 395 | + $Pile['vars'][$key] = $val; |
|
| 396 | + return $continue ? $val : ''; |
|
| 397 | 397 | } |
| 398 | 398 | |
| 399 | 399 | /** |
@@ -419,8 +419,8 @@ discard block |
||
| 419 | 419 | * @return string|mixed Retourne `$val` si `$continue` présent, sinon ''. |
| 420 | 420 | */ |
| 421 | 421 | function filtre_setenv(&$Pile, $val, $key, $continue = null) { |
| 422 | - $Pile[0][$key] = $val; |
|
| 423 | - return $continue ? $val : ''; |
|
| 422 | + $Pile[0][$key] = $val; |
|
| 423 | + return $continue ? $val : ''; |
|
| 424 | 424 | } |
| 425 | 425 | |
| 426 | 426 | /** |
@@ -429,8 +429,8 @@ discard block |
||
| 429 | 429 | * @return string |
| 430 | 430 | */ |
| 431 | 431 | function filtre_sanitize_env(&$Pile, $keys) { |
| 432 | - $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 433 | - return ''; |
|
| 432 | + $Pile[0] = spip_sanitize_from_request($Pile[0], $keys); |
|
| 433 | + return ''; |
|
| 434 | 434 | } |
| 435 | 435 | |
| 436 | 436 | |
@@ -453,18 +453,18 @@ discard block |
||
| 453 | 453 | * @return mixed Retourne la valeur (sans la modifier). |
| 454 | 454 | */ |
| 455 | 455 | function filtre_debug($val, $key = null) { |
| 456 | - $debug = ( |
|
| 457 | - is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 458 | - ) . var_export($val, true); |
|
| 456 | + $debug = ( |
|
| 457 | + is_null($key) ? '' : (var_export($key, true) . ' = ') |
|
| 458 | + ) . var_export($val, true); |
|
| 459 | 459 | |
| 460 | - include_spip('inc/autoriser'); |
|
| 461 | - if (autoriser('webmestre')) { |
|
| 462 | - echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 463 | - } |
|
| 460 | + include_spip('inc/autoriser'); |
|
| 461 | + if (autoriser('webmestre')) { |
|
| 462 | + echo "<div class='spip_debug'>\n", $debug, "</div>\n"; |
|
| 463 | + } |
|
| 464 | 464 | |
| 465 | - spip_log($debug, 'debug'); |
|
| 465 | + spip_log($debug, 'debug'); |
|
| 466 | 466 | |
| 467 | - return $val; |
|
| 467 | + return $val; |
|
| 468 | 468 | } |
| 469 | 469 | |
| 470 | 470 | |
@@ -492,89 +492,89 @@ discard block |
||
| 492 | 492 | * Texte qui a reçu les filtres |
| 493 | 493 | **/ |
| 494 | 494 | function image_filtrer($args) { |
| 495 | - $filtre = array_shift($args); # enlever $filtre |
|
| 496 | - $texte = array_shift($args); |
|
| 497 | - if (!strlen($texte)) { |
|
| 498 | - return; |
|
| 499 | - } |
|
| 500 | - find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 501 | - statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 502 | - // Cas du nom de fichier local |
|
| 503 | - $is_file = trim($texte); |
|
| 504 | - if ( |
|
| 505 | - strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 506 | - or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 507 | - or strpos($is_file, '/') === 0 |
|
| 508 | - ) { |
|
| 509 | - $is_file = false; |
|
| 510 | - } |
|
| 511 | - if ($is_file) { |
|
| 512 | - $is_local_file = function ($path) { |
|
| 513 | - if (strpos($path, '?') !== false) { |
|
| 514 | - $path = supprimer_timestamp($path); |
|
| 515 | - // remove ?24px added by find_in_theme on .svg files |
|
| 516 | - $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 517 | - } |
|
| 518 | - return file_exists($path); |
|
| 519 | - }; |
|
| 520 | - if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 521 | - array_unshift($args, "<img src='$is_file' />"); |
|
| 522 | - $res = call_user_func_array($filtre, $args); |
|
| 523 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 524 | - return $res; |
|
| 525 | - } |
|
| 526 | - } |
|
| 527 | - |
|
| 528 | - // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 529 | - if ( |
|
| 530 | - preg_match_all( |
|
| 531 | - ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 532 | - $texte, |
|
| 533 | - $tags, |
|
| 534 | - PREG_SET_ORDER |
|
| 535 | - ) |
|
| 536 | - ) { |
|
| 537 | - foreach ($tags as $tag) { |
|
| 538 | - $class = extraire_attribut($tag[3], 'class'); |
|
| 539 | - if ( |
|
| 540 | - !$class or |
|
| 541 | - (strpos($class, 'filtre_inactif') === false |
|
| 542 | - // compat historique a virer en 3.2 |
|
| 543 | - and strpos($class, 'no_image_filtrer') === false) |
|
| 544 | - ) { |
|
| 545 | - array_unshift($args, $tag[3]); |
|
| 546 | - if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 547 | - // En cas de span spip_documents, modifier le style=...width: |
|
| 548 | - if ($tag[1]) { |
|
| 549 | - $w = extraire_attribut($reduit, 'width'); |
|
| 550 | - if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 551 | - $w = $regs[1]; |
|
| 552 | - } |
|
| 553 | - if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 554 | - $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 555 | - $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 556 | - $texte = str_replace($tag[1], $replace, $texte); |
|
| 557 | - } |
|
| 558 | - } |
|
| 559 | - // traiter aussi un eventuel mouseover |
|
| 560 | - if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 561 | - if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 562 | - $srcover = $match[1]; |
|
| 563 | - array_shift($args); |
|
| 564 | - array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 565 | - $srcover_filter = call_user_func_array($filtre, $args); |
|
| 566 | - $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 567 | - $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 568 | - } |
|
| 569 | - } |
|
| 570 | - $texte = str_replace($tag[3], $reduit, $texte); |
|
| 571 | - } |
|
| 572 | - array_shift($args); |
|
| 573 | - } |
|
| 574 | - } |
|
| 575 | - } |
|
| 576 | - statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 577 | - return $texte; |
|
| 495 | + $filtre = array_shift($args); # enlever $filtre |
|
| 496 | + $texte = array_shift($args); |
|
| 497 | + if (!strlen($texte)) { |
|
| 498 | + return; |
|
| 499 | + } |
|
| 500 | + find_in_path('filtres_images_mini.php', 'inc/', true); |
|
| 501 | + statut_effacer_images_temporaires(true); // activer la suppression des images temporaires car le compilo finit la chaine par un image_graver |
|
| 502 | + // Cas du nom de fichier local |
|
| 503 | + $is_file = trim($texte); |
|
| 504 | + if ( |
|
| 505 | + strpos(substr($is_file, strlen(_DIR_RACINE)), '..') !== false |
|
| 506 | + or strpbrk($is_file, "<>\n\r\t") !== false |
|
| 507 | + or strpos($is_file, '/') === 0 |
|
| 508 | + ) { |
|
| 509 | + $is_file = false; |
|
| 510 | + } |
|
| 511 | + if ($is_file) { |
|
| 512 | + $is_local_file = function ($path) { |
|
| 513 | + if (strpos($path, '?') !== false) { |
|
| 514 | + $path = supprimer_timestamp($path); |
|
| 515 | + // remove ?24px added by find_in_theme on .svg files |
|
| 516 | + $path = preg_replace(',\?[[:digit:]]+(px)$,', '', $path); |
|
| 517 | + } |
|
| 518 | + return file_exists($path); |
|
| 519 | + }; |
|
| 520 | + if ($is_local_file($is_file) or tester_url_absolue($is_file)) { |
|
| 521 | + array_unshift($args, "<img src='$is_file' />"); |
|
| 522 | + $res = call_user_func_array($filtre, $args); |
|
| 523 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 524 | + return $res; |
|
| 525 | + } |
|
| 526 | + } |
|
| 527 | + |
|
| 528 | + // Cas general : trier toutes les images, avec eventuellement leur <span> |
|
| 529 | + if ( |
|
| 530 | + preg_match_all( |
|
| 531 | + ',(<([a-z]+) [^<>]*spip_documents[^<>]*>)?\s*(<img\s.*>),UimsS', |
|
| 532 | + $texte, |
|
| 533 | + $tags, |
|
| 534 | + PREG_SET_ORDER |
|
| 535 | + ) |
|
| 536 | + ) { |
|
| 537 | + foreach ($tags as $tag) { |
|
| 538 | + $class = extraire_attribut($tag[3], 'class'); |
|
| 539 | + if ( |
|
| 540 | + !$class or |
|
| 541 | + (strpos($class, 'filtre_inactif') === false |
|
| 542 | + // compat historique a virer en 3.2 |
|
| 543 | + and strpos($class, 'no_image_filtrer') === false) |
|
| 544 | + ) { |
|
| 545 | + array_unshift($args, $tag[3]); |
|
| 546 | + if ($reduit = call_user_func_array($filtre, $args)) { |
|
| 547 | + // En cas de span spip_documents, modifier le style=...width: |
|
| 548 | + if ($tag[1]) { |
|
| 549 | + $w = extraire_attribut($reduit, 'width'); |
|
| 550 | + if (!$w and preg_match(',width:\s*(\d+)px,S', extraire_attribut($reduit, 'style'), $regs)) { |
|
| 551 | + $w = $regs[1]; |
|
| 552 | + } |
|
| 553 | + if ($w and ($style = extraire_attribut($tag[1], 'style'))) { |
|
| 554 | + $style = preg_replace(',width:\s*\d+px,S', "width:${w}px", $style); |
|
| 555 | + $replace = inserer_attribut($tag[1], 'style', $style); |
|
| 556 | + $texte = str_replace($tag[1], $replace, $texte); |
|
| 557 | + } |
|
| 558 | + } |
|
| 559 | + // traiter aussi un eventuel mouseover |
|
| 560 | + if ($mouseover = extraire_attribut($reduit, 'onmouseover')) { |
|
| 561 | + if (preg_match(",this[.]src=['\"]([^'\"]+)['\"],ims", $mouseover, $match)) { |
|
| 562 | + $srcover = $match[1]; |
|
| 563 | + array_shift($args); |
|
| 564 | + array_unshift($args, "<img src='" . $match[1] . "' />"); |
|
| 565 | + $srcover_filter = call_user_func_array($filtre, $args); |
|
| 566 | + $srcover_filter = extraire_attribut($srcover_filter, 'src'); |
|
| 567 | + $reduit = str_replace($srcover, $srcover_filter, $reduit); |
|
| 568 | + } |
|
| 569 | + } |
|
| 570 | + $texte = str_replace($tag[3], $reduit, $texte); |
|
| 571 | + } |
|
| 572 | + array_shift($args); |
|
| 573 | + } |
|
| 574 | + } |
|
| 575 | + } |
|
| 576 | + statut_effacer_images_temporaires(false); // desactiver pour les appels hors compilo |
|
| 577 | + return $texte; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
@@ -589,78 +589,78 @@ discard block |
||
| 589 | 589 | **/ |
| 590 | 590 | function taille_image($img, $force_refresh = false) { |
| 591 | 591 | |
| 592 | - static $largeur_img = [], $hauteur_img = []; |
|
| 593 | - $srcWidth = 0; |
|
| 594 | - $srcHeight = 0; |
|
| 595 | - |
|
| 596 | - $src = extraire_attribut($img, 'src'); |
|
| 597 | - |
|
| 598 | - if (!$src) { |
|
| 599 | - $src = $img; |
|
| 600 | - } else { |
|
| 601 | - $srcWidth = extraire_attribut($img, 'width'); |
|
| 602 | - $srcHeight = extraire_attribut($img, 'height'); |
|
| 603 | - } |
|
| 604 | - |
|
| 605 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 606 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 607 | - if (tester_url_absolue($src)) { |
|
| 608 | - include_spip('inc/distant'); |
|
| 609 | - $fichier = copie_locale($src); |
|
| 610 | - $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 611 | - } |
|
| 612 | - if (($p = strpos($src, '?')) !== false) { |
|
| 613 | - $src = substr($src, 0, $p); |
|
| 614 | - } |
|
| 615 | - |
|
| 616 | - $srcsize = false; |
|
| 617 | - if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 618 | - $srcWidth = $largeur_img[$src]; |
|
| 619 | - } |
|
| 620 | - if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 621 | - $srcHeight = $hauteur_img[$src]; |
|
| 622 | - } |
|
| 623 | - if (!$srcWidth or !$srcHeight) { |
|
| 624 | - if ( |
|
| 625 | - file_exists($src) |
|
| 626 | - and $srcsize = spip_getimagesize($src) |
|
| 627 | - ) { |
|
| 628 | - if (!$srcWidth) { |
|
| 629 | - $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 630 | - } |
|
| 631 | - if (!$srcHeight) { |
|
| 632 | - $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 633 | - } |
|
| 634 | - } |
|
| 635 | - elseif (strpos($src, '<svg') !== false) { |
|
| 636 | - include_spip('inc/svg'); |
|
| 637 | - if ($attrs = svg_lire_attributs($src)) { |
|
| 638 | - list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 639 | - if (!$srcWidth) { |
|
| 640 | - $largeur_img[$src] = $srcWidth = $width; |
|
| 641 | - } |
|
| 642 | - if (!$srcHeight) { |
|
| 643 | - $hauteur_img[$src] = $srcHeight = $height; |
|
| 644 | - } |
|
| 645 | - } |
|
| 646 | - } |
|
| 647 | - // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 648 | - // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 649 | - elseif ( |
|
| 650 | - @file_exists($f = "$src.src") |
|
| 651 | - and lire_fichier($f, $valeurs) |
|
| 652 | - and $valeurs = unserialize($valeurs) |
|
| 653 | - ) { |
|
| 654 | - if (!$srcWidth) { |
|
| 655 | - $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 656 | - } |
|
| 657 | - if (!$srcHeight) { |
|
| 658 | - $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 659 | - } |
|
| 660 | - } |
|
| 661 | - } |
|
| 662 | - |
|
| 663 | - return [$srcHeight, $srcWidth]; |
|
| 592 | + static $largeur_img = [], $hauteur_img = []; |
|
| 593 | + $srcWidth = 0; |
|
| 594 | + $srcHeight = 0; |
|
| 595 | + |
|
| 596 | + $src = extraire_attribut($img, 'src'); |
|
| 597 | + |
|
| 598 | + if (!$src) { |
|
| 599 | + $src = $img; |
|
| 600 | + } else { |
|
| 601 | + $srcWidth = extraire_attribut($img, 'width'); |
|
| 602 | + $srcHeight = extraire_attribut($img, 'height'); |
|
| 603 | + } |
|
| 604 | + |
|
| 605 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 606 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 607 | + if (tester_url_absolue($src)) { |
|
| 608 | + include_spip('inc/distant'); |
|
| 609 | + $fichier = copie_locale($src); |
|
| 610 | + $src = $fichier ? _DIR_RACINE . $fichier : $src; |
|
| 611 | + } |
|
| 612 | + if (($p = strpos($src, '?')) !== false) { |
|
| 613 | + $src = substr($src, 0, $p); |
|
| 614 | + } |
|
| 615 | + |
|
| 616 | + $srcsize = false; |
|
| 617 | + if (isset($largeur_img[$src]) and !$force_refresh) { |
|
| 618 | + $srcWidth = $largeur_img[$src]; |
|
| 619 | + } |
|
| 620 | + if (isset($hauteur_img[$src]) and !$force_refresh) { |
|
| 621 | + $srcHeight = $hauteur_img[$src]; |
|
| 622 | + } |
|
| 623 | + if (!$srcWidth or !$srcHeight) { |
|
| 624 | + if ( |
|
| 625 | + file_exists($src) |
|
| 626 | + and $srcsize = spip_getimagesize($src) |
|
| 627 | + ) { |
|
| 628 | + if (!$srcWidth) { |
|
| 629 | + $largeur_img[$src] = $srcWidth = $srcsize[0]; |
|
| 630 | + } |
|
| 631 | + if (!$srcHeight) { |
|
| 632 | + $hauteur_img[$src] = $srcHeight = $srcsize[1]; |
|
| 633 | + } |
|
| 634 | + } |
|
| 635 | + elseif (strpos($src, '<svg') !== false) { |
|
| 636 | + include_spip('inc/svg'); |
|
| 637 | + if ($attrs = svg_lire_attributs($src)) { |
|
| 638 | + list($width, $height, $viewbox) = svg_getimagesize_from_attr($attrs); |
|
| 639 | + if (!$srcWidth) { |
|
| 640 | + $largeur_img[$src] = $srcWidth = $width; |
|
| 641 | + } |
|
| 642 | + if (!$srcHeight) { |
|
| 643 | + $hauteur_img[$src] = $srcHeight = $height; |
|
| 644 | + } |
|
| 645 | + } |
|
| 646 | + } |
|
| 647 | + // $src peut etre une reference a une image temporaire dont a n'a que le log .src |
|
| 648 | + // on s'y refere, l'image sera reconstruite en temps utile si necessaire |
|
| 649 | + elseif ( |
|
| 650 | + @file_exists($f = "$src.src") |
|
| 651 | + and lire_fichier($f, $valeurs) |
|
| 652 | + and $valeurs = unserialize($valeurs) |
|
| 653 | + ) { |
|
| 654 | + if (!$srcWidth) { |
|
| 655 | + $largeur_img[$src] = $srcWidth = $valeurs['largeur_dest']; |
|
| 656 | + } |
|
| 657 | + if (!$srcHeight) { |
|
| 658 | + $hauteur_img[$src] = $srcHeight = $valeurs['hauteur_dest']; |
|
| 659 | + } |
|
| 660 | + } |
|
| 661 | + } |
|
| 662 | + |
|
| 663 | + return [$srcHeight, $srcWidth]; |
|
| 664 | 664 | } |
| 665 | 665 | |
| 666 | 666 | |
@@ -678,12 +678,12 @@ discard block |
||
| 678 | 678 | * Largeur en pixels, NULL ou 0 si aucune image. |
| 679 | 679 | **/ |
| 680 | 680 | function largeur($img) { |
| 681 | - if (!$img) { |
|
| 682 | - return; |
|
| 683 | - } |
|
| 684 | - list($h, $l) = taille_image($img); |
|
| 681 | + if (!$img) { |
|
| 682 | + return; |
|
| 683 | + } |
|
| 684 | + list($h, $l) = taille_image($img); |
|
| 685 | 685 | |
| 686 | - return $l; |
|
| 686 | + return $l; |
|
| 687 | 687 | } |
| 688 | 688 | |
| 689 | 689 | /** |
@@ -700,12 +700,12 @@ discard block |
||
| 700 | 700 | * Hauteur en pixels, NULL ou 0 si aucune image. |
| 701 | 701 | **/ |
| 702 | 702 | function hauteur($img) { |
| 703 | - if (!$img) { |
|
| 704 | - return; |
|
| 705 | - } |
|
| 706 | - list($h, $l) = taille_image($img); |
|
| 703 | + if (!$img) { |
|
| 704 | + return; |
|
| 705 | + } |
|
| 706 | + list($h, $l) = taille_image($img); |
|
| 707 | 707 | |
| 708 | - return $h; |
|
| 708 | + return $h; |
|
| 709 | 709 | } |
| 710 | 710 | |
| 711 | 711 | |
@@ -725,11 +725,11 @@ discard block |
||
| 725 | 725 | * @return string |
| 726 | 726 | **/ |
| 727 | 727 | function corriger_entites_html($texte) { |
| 728 | - if (strpos($texte, '&') === false) { |
|
| 729 | - return $texte; |
|
| 730 | - } |
|
| 728 | + if (strpos($texte, '&') === false) { |
|
| 729 | + return $texte; |
|
| 730 | + } |
|
| 731 | 731 | |
| 732 | - return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 732 | + return preg_replace(',&(#[0-9][0-9][0-9]+;|amp;),iS', '&\1', $texte); |
|
| 733 | 733 | } |
| 734 | 734 | |
| 735 | 735 | /** |
@@ -744,11 +744,11 @@ discard block |
||
| 744 | 744 | * @return string |
| 745 | 745 | **/ |
| 746 | 746 | function corriger_toutes_entites_html($texte) { |
| 747 | - if (strpos($texte, '&') === false) { |
|
| 748 | - return $texte; |
|
| 749 | - } |
|
| 747 | + if (strpos($texte, '&') === false) { |
|
| 748 | + return $texte; |
|
| 749 | + } |
|
| 750 | 750 | |
| 751 | - return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 751 | + return preg_replace(',&(#?[a-z0-9]+;),iS', '&\1', $texte); |
|
| 752 | 752 | } |
| 753 | 753 | |
| 754 | 754 | /** |
@@ -758,7 +758,7 @@ discard block |
||
| 758 | 758 | * @return string |
| 759 | 759 | **/ |
| 760 | 760 | function proteger_amp($texte) { |
| 761 | - return str_replace('&', '&', $texte); |
|
| 761 | + return str_replace('&', '&', $texte); |
|
| 762 | 762 | } |
| 763 | 763 | |
| 764 | 764 | |
@@ -789,21 +789,21 @@ discard block |
||
| 789 | 789 | * @return mixed|string |
| 790 | 790 | */ |
| 791 | 791 | function entites_html($texte, $tout = false, $quote = true) { |
| 792 | - if ( |
|
| 793 | - !is_string($texte) or !$texte |
|
| 794 | - or strpbrk($texte, "&\"'<>") == false |
|
| 795 | - ) { |
|
| 796 | - return $texte; |
|
| 797 | - } |
|
| 798 | - include_spip('inc/texte'); |
|
| 799 | - $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 800 | - $flags |= ENT_HTML401; |
|
| 801 | - $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 802 | - if ($tout) { |
|
| 803 | - return corriger_toutes_entites_html($texte); |
|
| 804 | - } else { |
|
| 805 | - return corriger_entites_html($texte); |
|
| 806 | - } |
|
| 792 | + if ( |
|
| 793 | + !is_string($texte) or !$texte |
|
| 794 | + or strpbrk($texte, "&\"'<>") == false |
|
| 795 | + ) { |
|
| 796 | + return $texte; |
|
| 797 | + } |
|
| 798 | + include_spip('inc/texte'); |
|
| 799 | + $flags = ($quote ? ENT_QUOTES : ENT_NOQUOTES); |
|
| 800 | + $flags |= ENT_HTML401; |
|
| 801 | + $texte = spip_htmlspecialchars(echappe_retour(echappe_html($texte, '', true), '', 'proteger_amp'), $flags); |
|
| 802 | + if ($tout) { |
|
| 803 | + return corriger_toutes_entites_html($texte); |
|
| 804 | + } else { |
|
| 805 | + return corriger_entites_html($texte); |
|
| 806 | + } |
|
| 807 | 807 | } |
| 808 | 808 | |
| 809 | 809 | /** |
@@ -822,37 +822,37 @@ discard block |
||
| 822 | 822 | * Texte converti |
| 823 | 823 | **/ |
| 824 | 824 | function filtrer_entites($texte) { |
| 825 | - if (strpos($texte, '&') === false) { |
|
| 826 | - return $texte; |
|
| 827 | - } |
|
| 828 | - // filtrer |
|
| 829 | - $texte = html2unicode($texte); |
|
| 830 | - // remettre le tout dans le charset cible |
|
| 831 | - $texte = unicode2charset($texte); |
|
| 832 | - // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 833 | - // (on le faisait deja avec un ") |
|
| 834 | - if (strpos($texte, '&#') !== false) { |
|
| 835 | - $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 836 | - } |
|
| 825 | + if (strpos($texte, '&') === false) { |
|
| 826 | + return $texte; |
|
| 827 | + } |
|
| 828 | + // filtrer |
|
| 829 | + $texte = html2unicode($texte); |
|
| 830 | + // remettre le tout dans le charset cible |
|
| 831 | + $texte = unicode2charset($texte); |
|
| 832 | + // cas particulier des " et ' qu'il faut filtrer aussi |
|
| 833 | + // (on le faisait deja avec un ") |
|
| 834 | + if (strpos($texte, '&#') !== false) { |
|
| 835 | + $texte = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $texte); |
|
| 836 | + } |
|
| 837 | 837 | |
| 838 | - return $texte; |
|
| 838 | + return $texte; |
|
| 839 | 839 | } |
| 840 | 840 | |
| 841 | 841 | |
| 842 | 842 | if (!function_exists('filtre_filtrer_entites_dist')) { |
| 843 | - /** |
|
| 844 | - * Version sécurisée de filtrer_entites |
|
| 845 | - * |
|
| 846 | - * @uses interdire_scripts() |
|
| 847 | - * @uses filtrer_entites() |
|
| 848 | - * |
|
| 849 | - * @param string $t |
|
| 850 | - * @return string |
|
| 851 | - */ |
|
| 852 | - function filtre_filtrer_entites_dist($t) { |
|
| 853 | - include_spip('inc/texte'); |
|
| 854 | - return interdire_scripts(filtrer_entites($t)); |
|
| 855 | - } |
|
| 843 | + /** |
|
| 844 | + * Version sécurisée de filtrer_entites |
|
| 845 | + * |
|
| 846 | + * @uses interdire_scripts() |
|
| 847 | + * @uses filtrer_entites() |
|
| 848 | + * |
|
| 849 | + * @param string $t |
|
| 850 | + * @return string |
|
| 851 | + */ |
|
| 852 | + function filtre_filtrer_entites_dist($t) { |
|
| 853 | + include_spip('inc/texte'); |
|
| 854 | + return interdire_scripts(filtrer_entites($t)); |
|
| 855 | + } |
|
| 856 | 856 | } |
| 857 | 857 | |
| 858 | 858 | |
@@ -867,18 +867,18 @@ discard block |
||
| 867 | 867 | * @return string|array |
| 868 | 868 | **/ |
| 869 | 869 | function supprimer_caracteres_illegaux($texte) { |
| 870 | - static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 871 | - static $to = null; |
|
| 870 | + static $from = "\x0\x1\x2\x3\x4\x5\x6\x7\x8\xB\xC\xE\xF\x10\x11\x12\x13\x14\x15\x16\x17\x18\x19\x1A\x1B\x1C\x1D\x1E\x1F"; |
|
| 871 | + static $to = null; |
|
| 872 | 872 | |
| 873 | - if (is_array($texte)) { |
|
| 874 | - return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 875 | - } |
|
| 873 | + if (is_array($texte)) { |
|
| 874 | + return array_map('supprimer_caracteres_illegaux', $texte); |
|
| 875 | + } |
|
| 876 | 876 | |
| 877 | - if (!$to) { |
|
| 878 | - $to = str_repeat('-', strlen($from)); |
|
| 879 | - } |
|
| 877 | + if (!$to) { |
|
| 878 | + $to = str_repeat('-', strlen($from)); |
|
| 879 | + } |
|
| 880 | 880 | |
| 881 | - return strtr($texte, $from, $to); |
|
| 881 | + return strtr($texte, $from, $to); |
|
| 882 | 882 | } |
| 883 | 883 | |
| 884 | 884 | /** |
@@ -890,10 +890,10 @@ discard block |
||
| 890 | 890 | * @return string|array |
| 891 | 891 | **/ |
| 892 | 892 | function corriger_caracteres($texte) { |
| 893 | - $texte = corriger_caracteres_windows($texte); |
|
| 894 | - $texte = supprimer_caracteres_illegaux($texte); |
|
| 893 | + $texte = corriger_caracteres_windows($texte); |
|
| 894 | + $texte = supprimer_caracteres_illegaux($texte); |
|
| 895 | 895 | |
| 896 | - return $texte; |
|
| 896 | + return $texte; |
|
| 897 | 897 | } |
| 898 | 898 | |
| 899 | 899 | /** |
@@ -911,40 +911,40 @@ discard block |
||
| 911 | 911 | */ |
| 912 | 912 | function texte_backend($texte) { |
| 913 | 913 | |
| 914 | - static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 914 | + static $apostrophe = ['’', "'"]; # n'allouer qu'une fois |
|
| 915 | 915 | |
| 916 | - // si on a des liens ou des images, les passer en absolu |
|
| 917 | - $texte = liens_absolus($texte); |
|
| 916 | + // si on a des liens ou des images, les passer en absolu |
|
| 917 | + $texte = liens_absolus($texte); |
|
| 918 | 918 | |
| 919 | - // echapper les tags > < |
|
| 920 | - $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 919 | + // echapper les tags > < |
|
| 920 | + $texte = preg_replace(',&(gt|lt);,S', '&\1;', $texte); |
|
| 921 | 921 | |
| 922 | - // importer les é |
|
| 923 | - $texte = filtrer_entites($texte); |
|
| 922 | + // importer les é |
|
| 923 | + $texte = filtrer_entites($texte); |
|
| 924 | 924 | |
| 925 | - // " -> " et tout ce genre de choses |
|
| 926 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 927 | - $texte = str_replace(' ', ' ', $texte); |
|
| 928 | - $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 929 | - // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 930 | - $texte = entites_html($texte, false, false); |
|
| 931 | - // mais bien echapper les double quotes ! |
|
| 932 | - $texte = str_replace('"', '"', $texte); |
|
| 925 | + // " -> " et tout ce genre de choses |
|
| 926 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 927 | + $texte = str_replace(' ', ' ', $texte); |
|
| 928 | + $texte = preg_replace('/\s{2,}/S' . $u, ' ', $texte); |
|
| 929 | + // ne pas echapper les sinqle quotes car certains outils de syndication gerent mal |
|
| 930 | + $texte = entites_html($texte, false, false); |
|
| 931 | + // mais bien echapper les double quotes ! |
|
| 932 | + $texte = str_replace('"', '"', $texte); |
|
| 933 | 933 | |
| 934 | - // verifier le charset |
|
| 935 | - $texte = charset2unicode($texte); |
|
| 934 | + // verifier le charset |
|
| 935 | + $texte = charset2unicode($texte); |
|
| 936 | 936 | |
| 937 | - // Caracteres problematiques en iso-latin 1 |
|
| 938 | - if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 939 | - $texte = str_replace(chr(156), 'œ', $texte); |
|
| 940 | - $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 941 | - $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 942 | - } |
|
| 937 | + // Caracteres problematiques en iso-latin 1 |
|
| 938 | + if (isset($GLOBALS['meta']['charset']) and $GLOBALS['meta']['charset'] == 'iso-8859-1') { |
|
| 939 | + $texte = str_replace(chr(156), 'œ', $texte); |
|
| 940 | + $texte = str_replace(chr(140), 'Œ', $texte); |
|
| 941 | + $texte = str_replace(chr(159), 'Ÿ', $texte); |
|
| 942 | + } |
|
| 943 | 943 | |
| 944 | - // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 945 | - // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 946 | - // ==> on les remplace par l'entite HTML |
|
| 947 | - return str_replace($apostrophe, "'", $texte); |
|
| 944 | + // l'apostrophe curly pose probleme a certains lecteure de RSS |
|
| 945 | + // et le caractere apostrophe alourdit les squelettes avec PHP |
|
| 946 | + // ==> on les remplace par l'entite HTML |
|
| 947 | + return str_replace($apostrophe, "'", $texte); |
|
| 948 | 948 | } |
| 949 | 949 | |
| 950 | 950 | /** |
@@ -961,7 +961,7 @@ discard block |
||
| 961 | 961 | * Texte encodé et quote pour XML |
| 962 | 962 | */ |
| 963 | 963 | function texte_backendq($texte) { |
| 964 | - return addslashes(texte_backend($texte)); |
|
| 964 | + return addslashes(texte_backend($texte)); |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | |
@@ -984,11 +984,11 @@ discard block |
||
| 984 | 984 | * Numéro de titre, sinon chaîne vide |
| 985 | 985 | **/ |
| 986 | 986 | function supprimer_numero($texte) { |
| 987 | - return preg_replace( |
|
| 988 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 989 | - '', |
|
| 990 | - $texte |
|
| 991 | - ); |
|
| 987 | + return preg_replace( |
|
| 988 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 989 | + '', |
|
| 990 | + $texte |
|
| 991 | + ); |
|
| 992 | 992 | } |
| 993 | 993 | |
| 994 | 994 | /** |
@@ -1011,17 +1011,17 @@ discard block |
||
| 1011 | 1011 | * Numéro de titre, sinon chaîne vide |
| 1012 | 1012 | **/ |
| 1013 | 1013 | function recuperer_numero($texte) { |
| 1014 | - if ( |
|
| 1015 | - preg_match( |
|
| 1016 | - ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1017 | - $texte, |
|
| 1018 | - $regs |
|
| 1019 | - ) |
|
| 1020 | - ) { |
|
| 1021 | - return strval($regs[1]); |
|
| 1022 | - } else { |
|
| 1023 | - return ''; |
|
| 1024 | - } |
|
| 1014 | + if ( |
|
| 1015 | + preg_match( |
|
| 1016 | + ',^[[:space:]]*([0-9]+)([.)]|' . chr(194) . '?' . chr(176) . ')[[:space:]]+,S', |
|
| 1017 | + $texte, |
|
| 1018 | + $regs |
|
| 1019 | + ) |
|
| 1020 | + ) { |
|
| 1021 | + return strval($regs[1]); |
|
| 1022 | + } else { |
|
| 1023 | + return ''; |
|
| 1024 | + } |
|
| 1025 | 1025 | } |
| 1026 | 1026 | |
| 1027 | 1027 | /** |
@@ -1048,13 +1048,13 @@ discard block |
||
| 1048 | 1048 | * Texte converti |
| 1049 | 1049 | **/ |
| 1050 | 1050 | function supprimer_tags($texte, $rempl = '') { |
| 1051 | - $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1052 | - // ne pas oublier un < final non ferme car coupe |
|
| 1053 | - $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1054 | - // mais qui peut aussi etre un simple signe plus petit que |
|
| 1055 | - $texte = str_replace('<', '<', $texte); |
|
| 1051 | + $texte = preg_replace(',<(!--|\w|/|!\[endif|!\[if)[^>]*>,US', $rempl, $texte); |
|
| 1052 | + // ne pas oublier un < final non ferme car coupe |
|
| 1053 | + $texte = preg_replace(',<(!--|\w|/).*$,US', $rempl, $texte); |
|
| 1054 | + // mais qui peut aussi etre un simple signe plus petit que |
|
| 1055 | + $texte = str_replace('<', '<', $texte); |
|
| 1056 | 1056 | |
| 1057 | - return $texte; |
|
| 1057 | + return $texte; |
|
| 1058 | 1058 | } |
| 1059 | 1059 | |
| 1060 | 1060 | /** |
@@ -1077,9 +1077,9 @@ discard block |
||
| 1077 | 1077 | * Texte converti |
| 1078 | 1078 | **/ |
| 1079 | 1079 | function echapper_tags($texte, $rempl = '') { |
| 1080 | - $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1080 | + $texte = preg_replace('/<([^>]*)>/', "<\\1>", $texte); |
|
| 1081 | 1081 | |
| 1082 | - return $texte; |
|
| 1082 | + return $texte; |
|
| 1083 | 1083 | } |
| 1084 | 1084 | |
| 1085 | 1085 | /** |
@@ -1100,18 +1100,18 @@ discard block |
||
| 1100 | 1100 | * Texte converti |
| 1101 | 1101 | **/ |
| 1102 | 1102 | function textebrut($texte) { |
| 1103 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1104 | - $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1105 | - $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1106 | - $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1107 | - $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1108 | - $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1109 | - $texte = supprimer_tags($texte); |
|
| 1110 | - $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1111 | - // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1112 | - $texte = str_replace('’', "'", $texte); |
|
| 1103 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1104 | + $texte = preg_replace('/\s+/S' . $u, ' ', $texte); |
|
| 1105 | + $texte = preg_replace('/<(p|br)( [^>]*)?' . '>/iS', "\n\n", $texte); |
|
| 1106 | + $texte = preg_replace("/^\n+/", '', $texte); |
|
| 1107 | + $texte = preg_replace("/\n+$/", '', $texte); |
|
| 1108 | + $texte = preg_replace("/\n +/", "\n", $texte); |
|
| 1109 | + $texte = supprimer_tags($texte); |
|
| 1110 | + $texte = preg_replace('/( | )+/S', ' ', $texte); |
|
| 1111 | + // nettoyer l'apostrophe curly qui pose probleme a certains rss-readers, lecteurs de mail... |
|
| 1112 | + $texte = str_replace('’', "'", $texte); |
|
| 1113 | 1113 | |
| 1114 | - return $texte; |
|
| 1114 | + return $texte; |
|
| 1115 | 1115 | } |
| 1116 | 1116 | |
| 1117 | 1117 | |
@@ -1127,23 +1127,23 @@ discard block |
||
| 1127 | 1127 | * Texte avec liens ouvrants |
| 1128 | 1128 | **/ |
| 1129 | 1129 | function liens_ouvrants($texte) { |
| 1130 | - if ( |
|
| 1131 | - preg_match_all( |
|
| 1132 | - ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1133 | - $texte, |
|
| 1134 | - $liens, |
|
| 1135 | - PREG_PATTERN_ORDER |
|
| 1136 | - ) |
|
| 1137 | - ) { |
|
| 1138 | - foreach ($liens[0] as $a) { |
|
| 1139 | - $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1140 | - $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1141 | - $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1142 | - $texte = str_replace($a, $ablank, $texte); |
|
| 1143 | - } |
|
| 1144 | - } |
|
| 1145 | - |
|
| 1146 | - return $texte; |
|
| 1130 | + if ( |
|
| 1131 | + preg_match_all( |
|
| 1132 | + ",(<a\s+[^>]*https?://[^>]*class=[\"']spip_(out|url)\b[^>]+>),imsS", |
|
| 1133 | + $texte, |
|
| 1134 | + $liens, |
|
| 1135 | + PREG_PATTERN_ORDER |
|
| 1136 | + ) |
|
| 1137 | + ) { |
|
| 1138 | + foreach ($liens[0] as $a) { |
|
| 1139 | + $rel = 'noopener noreferrer ' . extraire_attribut($a, 'rel'); |
|
| 1140 | + $ablank = inserer_attribut($a, 'rel', $rel); |
|
| 1141 | + $ablank = inserer_attribut($ablank, 'target', '_blank'); |
|
| 1142 | + $texte = str_replace($a, $ablank, $texte); |
|
| 1143 | + } |
|
| 1144 | + } |
|
| 1145 | + |
|
| 1146 | + return $texte; |
|
| 1147 | 1147 | } |
| 1148 | 1148 | |
| 1149 | 1149 | /** |
@@ -1153,22 +1153,22 @@ discard block |
||
| 1153 | 1153 | * @return string |
| 1154 | 1154 | */ |
| 1155 | 1155 | function liens_nofollow($texte) { |
| 1156 | - if (stripos($texte, '<a') === false) { |
|
| 1157 | - return $texte; |
|
| 1158 | - } |
|
| 1156 | + if (stripos($texte, '<a') === false) { |
|
| 1157 | + return $texte; |
|
| 1158 | + } |
|
| 1159 | 1159 | |
| 1160 | - if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1161 | - foreach ($regs[0] as $a) { |
|
| 1162 | - $rel = extraire_attribut($a, 'rel'); |
|
| 1163 | - if (strpos($rel, 'nofollow') === false) { |
|
| 1164 | - $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1165 | - $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1166 | - $texte = str_replace($a, $anofollow, $texte); |
|
| 1167 | - } |
|
| 1168 | - } |
|
| 1169 | - } |
|
| 1160 | + if (preg_match_all(",<a\b[^>]*>,UimsS", $texte, $regs, PREG_PATTERN_ORDER)) { |
|
| 1161 | + foreach ($regs[0] as $a) { |
|
| 1162 | + $rel = extraire_attribut($a, 'rel'); |
|
| 1163 | + if (strpos($rel, 'nofollow') === false) { |
|
| 1164 | + $rel = 'nofollow' . ($rel ? " $rel" : ''); |
|
| 1165 | + $anofollow = inserer_attribut($a, 'rel', $rel); |
|
| 1166 | + $texte = str_replace($a, $anofollow, $texte); |
|
| 1167 | + } |
|
| 1168 | + } |
|
| 1169 | + } |
|
| 1170 | 1170 | |
| 1171 | - return $texte; |
|
| 1171 | + return $texte; |
|
| 1172 | 1172 | } |
| 1173 | 1173 | |
| 1174 | 1174 | /** |
@@ -1187,12 +1187,12 @@ discard block |
||
| 1187 | 1187 | * Texte sans paraghaphes |
| 1188 | 1188 | **/ |
| 1189 | 1189 | function PtoBR($texte) { |
| 1190 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1191 | - $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1192 | - $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1193 | - $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1190 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1191 | + $texte = preg_replace('@</p>@iS', "\n", $texte); |
|
| 1192 | + $texte = preg_replace("@<p\b.*>@UiS", '<br />', $texte); |
|
| 1193 | + $texte = preg_replace('@^\s*<br />@S' . $u, '', $texte); |
|
| 1194 | 1194 | |
| 1195 | - return $texte; |
|
| 1195 | + return $texte; |
|
| 1196 | 1196 | } |
| 1197 | 1197 | |
| 1198 | 1198 | |
@@ -1217,14 +1217,14 @@ discard block |
||
| 1217 | 1217 | * @return string Texte encadré du style CSS |
| 1218 | 1218 | */ |
| 1219 | 1219 | function lignes_longues($texte) { |
| 1220 | - if (!strlen(trim($texte))) { |
|
| 1221 | - return $texte; |
|
| 1222 | - } |
|
| 1223 | - include_spip('inc/texte'); |
|
| 1224 | - $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1225 | - 'div' : 'span'; |
|
| 1220 | + if (!strlen(trim($texte))) { |
|
| 1221 | + return $texte; |
|
| 1222 | + } |
|
| 1223 | + include_spip('inc/texte'); |
|
| 1224 | + $tag = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $texte) ? |
|
| 1225 | + 'div' : 'span'; |
|
| 1226 | 1226 | |
| 1227 | - return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1227 | + return "<$tag style='word-wrap:break-word;'>$texte</$tag>"; |
|
| 1228 | 1228 | } |
| 1229 | 1229 | |
| 1230 | 1230 | /** |
@@ -1243,30 +1243,30 @@ discard block |
||
| 1243 | 1243 | * @return string Texte en majuscule |
| 1244 | 1244 | */ |
| 1245 | 1245 | function majuscules($texte) { |
| 1246 | - if (!strlen($texte)) { |
|
| 1247 | - return ''; |
|
| 1248 | - } |
|
| 1246 | + if (!strlen($texte)) { |
|
| 1247 | + return ''; |
|
| 1248 | + } |
|
| 1249 | 1249 | |
| 1250 | - // Cas du turc |
|
| 1251 | - if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1252 | - # remplacer hors des tags et des entites |
|
| 1253 | - if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1254 | - foreach ($regs as $n => $match) { |
|
| 1255 | - $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1256 | - } |
|
| 1257 | - } |
|
| 1250 | + // Cas du turc |
|
| 1251 | + if ($GLOBALS['spip_lang'] == 'tr') { |
|
| 1252 | + # remplacer hors des tags et des entites |
|
| 1253 | + if (preg_match_all(',<[^<>]+>|&[^;]+;,S', $texte, $regs, PREG_SET_ORDER)) { |
|
| 1254 | + foreach ($regs as $n => $match) { |
|
| 1255 | + $texte = str_replace($match[0], "@@SPIP_TURC$n@@", $texte); |
|
| 1256 | + } |
|
| 1257 | + } |
|
| 1258 | 1258 | |
| 1259 | - $texte = str_replace('i', 'İ', $texte); |
|
| 1259 | + $texte = str_replace('i', 'İ', $texte); |
|
| 1260 | 1260 | |
| 1261 | - if ($regs) { |
|
| 1262 | - foreach ($regs as $n => $match) { |
|
| 1263 | - $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1264 | - } |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1261 | + if ($regs) { |
|
| 1262 | + foreach ($regs as $n => $match) { |
|
| 1263 | + $texte = str_replace("@@SPIP_TURC$n@@", $match[0], $texte); |
|
| 1264 | + } |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | 1267 | |
| 1268 | - // Cas general |
|
| 1269 | - return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1268 | + // Cas general |
|
| 1269 | + return "<span style='text-transform: uppercase;'>$texte</span>"; |
|
| 1270 | 1270 | } |
| 1271 | 1271 | |
| 1272 | 1272 | /** |
@@ -1284,29 +1284,29 @@ discard block |
||
| 1284 | 1284 | * @return string |
| 1285 | 1285 | **/ |
| 1286 | 1286 | function taille_en_octets($taille) { |
| 1287 | - if (!defined('_KILOBYTE')) { |
|
| 1288 | - /** |
|
| 1289 | - * Définit le nombre d'octets dans un Kilobyte |
|
| 1290 | - * |
|
| 1291 | - * @var int |
|
| 1292 | - **/ |
|
| 1293 | - define('_KILOBYTE', 1024); |
|
| 1294 | - } |
|
| 1287 | + if (!defined('_KILOBYTE')) { |
|
| 1288 | + /** |
|
| 1289 | + * Définit le nombre d'octets dans un Kilobyte |
|
| 1290 | + * |
|
| 1291 | + * @var int |
|
| 1292 | + **/ |
|
| 1293 | + define('_KILOBYTE', 1024); |
|
| 1294 | + } |
|
| 1295 | 1295 | |
| 1296 | - if ($taille < 1) { |
|
| 1297 | - return ''; |
|
| 1298 | - } |
|
| 1299 | - if ($taille < _KILOBYTE) { |
|
| 1300 | - $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1301 | - } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1302 | - $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1303 | - } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1304 | - $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1305 | - } else { |
|
| 1306 | - $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1307 | - } |
|
| 1296 | + if ($taille < 1) { |
|
| 1297 | + return ''; |
|
| 1298 | + } |
|
| 1299 | + if ($taille < _KILOBYTE) { |
|
| 1300 | + $taille = _T('taille_octets', ['taille' => $taille]); |
|
| 1301 | + } elseif ($taille < _KILOBYTE * _KILOBYTE) { |
|
| 1302 | + $taille = _T('taille_ko', ['taille' => round($taille / _KILOBYTE, 1)]); |
|
| 1303 | + } elseif ($taille < _KILOBYTE * _KILOBYTE * _KILOBYTE) { |
|
| 1304 | + $taille = _T('taille_mo', ['taille' => round($taille / _KILOBYTE / _KILOBYTE, 1)]); |
|
| 1305 | + } else { |
|
| 1306 | + $taille = _T('taille_go', ['taille' => round($taille / _KILOBYTE / _KILOBYTE / _KILOBYTE, 2)]); |
|
| 1307 | + } |
|
| 1308 | 1308 | |
| 1309 | - return $taille; |
|
| 1309 | + return $taille; |
|
| 1310 | 1310 | } |
| 1311 | 1311 | |
| 1312 | 1312 | |
@@ -1328,18 +1328,18 @@ discard block |
||
| 1328 | 1328 | * Texte prêt pour être utilisé en attribut HTML |
| 1329 | 1329 | **/ |
| 1330 | 1330 | function attribut_html($texte, $textebrut = true) { |
| 1331 | - $u = $GLOBALS['meta']['pcre_u']; |
|
| 1332 | - if ($textebrut) { |
|
| 1333 | - $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1334 | - } |
|
| 1335 | - $texte = texte_backend($texte); |
|
| 1336 | - $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1331 | + $u = $GLOBALS['meta']['pcre_u']; |
|
| 1332 | + if ($textebrut) { |
|
| 1333 | + $texte = preg_replace([",\n,", ',\s(?=\s),msS' . $u], [' ', ''], textebrut($texte)); |
|
| 1334 | + } |
|
| 1335 | + $texte = texte_backend($texte); |
|
| 1336 | + $texte = str_replace(["'", '"'], [''', '"'], $texte); |
|
| 1337 | 1337 | |
| 1338 | - return preg_replace( |
|
| 1339 | - ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1340 | - ['&', '&'], |
|
| 1341 | - $texte |
|
| 1342 | - ); |
|
| 1338 | + return preg_replace( |
|
| 1339 | + ['/&(amp;|#38;)/', '/&(?![A-Za-z]{0,4}\w{2,3};|#[0-9]{2,5};)/'], |
|
| 1340 | + ['&', '&'], |
|
| 1341 | + $texte |
|
| 1342 | + ); |
|
| 1343 | 1343 | } |
| 1344 | 1344 | |
| 1345 | 1345 | |
@@ -1359,12 +1359,12 @@ discard block |
||
| 1359 | 1359 | * URL ou chaîne vide |
| 1360 | 1360 | **/ |
| 1361 | 1361 | function vider_url($url, $entites = true) { |
| 1362 | - # un message pour abs_url |
|
| 1363 | - $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1364 | - $url = trim($url); |
|
| 1365 | - $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1362 | + # un message pour abs_url |
|
| 1363 | + $GLOBALS['mode_abs_url'] = 'url'; |
|
| 1364 | + $url = trim($url); |
|
| 1365 | + $r = ',^(?:' . _PROTOCOLES_STD . '):?/?/?$,iS'; |
|
| 1366 | 1366 | |
| 1367 | - return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1367 | + return preg_match($r, $url) ? '' : ($entites ? entites_html($url) : $url); |
|
| 1368 | 1368 | } |
| 1369 | 1369 | |
| 1370 | 1370 | |
@@ -1379,10 +1379,10 @@ discard block |
||
| 1379 | 1379 | * @return string Adresse email maquillée |
| 1380 | 1380 | **/ |
| 1381 | 1381 | function antispam($texte) { |
| 1382 | - include_spip('inc/acces'); |
|
| 1383 | - $masque = creer_pass_aleatoire(3); |
|
| 1382 | + include_spip('inc/acces'); |
|
| 1383 | + $masque = creer_pass_aleatoire(3); |
|
| 1384 | 1384 | |
| 1385 | - return preg_replace('/@/', " $masque ", $texte); |
|
| 1385 | + return preg_replace('/@/', " $masque ", $texte); |
|
| 1386 | 1386 | } |
| 1387 | 1387 | |
| 1388 | 1388 | /** |
@@ -1414,12 +1414,12 @@ discard block |
||
| 1414 | 1414 | * True si on a le droit d'accès, false sinon. |
| 1415 | 1415 | **/ |
| 1416 | 1416 | function securiser_acces($id_auteur, $cle, $dir, $op = '', $args = '') { |
| 1417 | - include_spip('inc/acces'); |
|
| 1418 | - if ($op) { |
|
| 1419 | - $dir .= " $op $args"; |
|
| 1420 | - } |
|
| 1417 | + include_spip('inc/acces'); |
|
| 1418 | + if ($op) { |
|
| 1419 | + $dir .= " $op $args"; |
|
| 1420 | + } |
|
| 1421 | 1421 | |
| 1422 | - return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1422 | + return verifier_low_sec($id_auteur, $cle, $dir); |
|
| 1423 | 1423 | } |
| 1424 | 1424 | |
| 1425 | 1425 | /** |
@@ -1444,11 +1444,11 @@ discard block |
||
| 1444 | 1444 | * Retourne $texte, sinon $sinon. |
| 1445 | 1445 | **/ |
| 1446 | 1446 | function sinon($texte, $sinon = '') { |
| 1447 | - if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1448 | - return $texte; |
|
| 1449 | - } else { |
|
| 1450 | - return $sinon; |
|
| 1451 | - } |
|
| 1447 | + if ($texte or (!is_array($texte) and strlen($texte))) { |
|
| 1448 | + return $texte; |
|
| 1449 | + } else { |
|
| 1450 | + return $sinon; |
|
| 1451 | + } |
|
| 1452 | 1452 | } |
| 1453 | 1453 | |
| 1454 | 1454 | /** |
@@ -1472,7 +1472,7 @@ discard block |
||
| 1472 | 1472 | * @return mixed |
| 1473 | 1473 | **/ |
| 1474 | 1474 | function choixsivide($a, $vide, $pasvide) { |
| 1475 | - return $a ? $pasvide : $vide; |
|
| 1475 | + return $a ? $pasvide : $vide; |
|
| 1476 | 1476 | } |
| 1477 | 1477 | |
| 1478 | 1478 | /** |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | * @return mixed |
| 1497 | 1497 | **/ |
| 1498 | 1498 | function choixsiegal($a1, $a2, $v, $f) { |
| 1499 | - return ($a1 == $a2) ? $v : $f; |
|
| 1499 | + return ($a1 == $a2) ? $v : $f; |
|
| 1500 | 1500 | } |
| 1501 | 1501 | |
| 1502 | 1502 | // |
@@ -1515,13 +1515,13 @@ discard block |
||
| 1515 | 1515 | * @return string |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function filtrer_ical($texte) { |
| 1518 | - #include_spip('inc/charsets'); |
|
| 1519 | - $texte = html2unicode($texte); |
|
| 1520 | - $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1521 | - $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1522 | - $texte = preg_replace('/,/', '\,', $texte); |
|
| 1518 | + #include_spip('inc/charsets'); |
|
| 1519 | + $texte = html2unicode($texte); |
|
| 1520 | + $texte = unicode2charset(charset2unicode($texte, $GLOBALS['meta']['charset'], 1), 'utf-8'); |
|
| 1521 | + $texte = preg_replace("/\n/", ' ', $texte); |
|
| 1522 | + $texte = preg_replace('/,/', '\,', $texte); |
|
| 1523 | 1523 | |
| 1524 | - return $texte; |
|
| 1524 | + return $texte; |
|
| 1525 | 1525 | } |
| 1526 | 1526 | |
| 1527 | 1527 | |
@@ -1546,54 +1546,54 @@ discard block |
||
| 1546 | 1546 | * @return string |
| 1547 | 1547 | **/ |
| 1548 | 1548 | function post_autobr($texte, $delim = "\n_ ") { |
| 1549 | - if (!function_exists('echappe_html')) { |
|
| 1550 | - include_spip('inc/texte_mini'); |
|
| 1551 | - } |
|
| 1552 | - $texte = str_replace("\r\n", "\r", $texte); |
|
| 1553 | - $texte = str_replace("\r", "\n", $texte); |
|
| 1554 | - |
|
| 1555 | - if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1556 | - $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1557 | - } else { |
|
| 1558 | - $fin = ''; |
|
| 1559 | - } |
|
| 1560 | - |
|
| 1561 | - $texte = echappe_html($texte, '', true); |
|
| 1562 | - |
|
| 1563 | - // echapper les modeles |
|
| 1564 | - if (strpos($texte, '<') !== false) { |
|
| 1565 | - include_spip('inc/lien'); |
|
| 1566 | - if (defined('_PREG_MODELE')) { |
|
| 1567 | - $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1568 | - $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1569 | - } |
|
| 1570 | - } |
|
| 1571 | - |
|
| 1572 | - $debut = ''; |
|
| 1573 | - $suite = $texte; |
|
| 1574 | - while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1575 | - $debut .= substr($suite, 0, $t - 1); |
|
| 1576 | - $suite = substr($suite, $t); |
|
| 1577 | - $car = substr($suite, 0, 1); |
|
| 1578 | - if ( |
|
| 1579 | - ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1580 | - and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1581 | - and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1582 | - ) { |
|
| 1583 | - $debut .= $delim; |
|
| 1584 | - } else { |
|
| 1585 | - $debut .= "\n"; |
|
| 1586 | - } |
|
| 1587 | - if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1588 | - $debut .= $regs[0]; |
|
| 1589 | - $suite = substr($suite, strlen($regs[0])); |
|
| 1590 | - } |
|
| 1591 | - } |
|
| 1592 | - $texte = $debut . $suite; |
|
| 1593 | - |
|
| 1594 | - $texte = echappe_retour($texte); |
|
| 1595 | - |
|
| 1596 | - return $texte . $fin; |
|
| 1549 | + if (!function_exists('echappe_html')) { |
|
| 1550 | + include_spip('inc/texte_mini'); |
|
| 1551 | + } |
|
| 1552 | + $texte = str_replace("\r\n", "\r", $texte); |
|
| 1553 | + $texte = str_replace("\r", "\n", $texte); |
|
| 1554 | + |
|
| 1555 | + if (preg_match(",\n+$,", $texte, $fin)) { |
|
| 1556 | + $texte = substr($texte, 0, -strlen($fin = $fin[0])); |
|
| 1557 | + } else { |
|
| 1558 | + $fin = ''; |
|
| 1559 | + } |
|
| 1560 | + |
|
| 1561 | + $texte = echappe_html($texte, '', true); |
|
| 1562 | + |
|
| 1563 | + // echapper les modeles |
|
| 1564 | + if (strpos($texte, '<') !== false) { |
|
| 1565 | + include_spip('inc/lien'); |
|
| 1566 | + if (defined('_PREG_MODELE')) { |
|
| 1567 | + $preg_modeles = '@' . _PREG_MODELE . '@imsS'; |
|
| 1568 | + $texte = echappe_html($texte, '', true, $preg_modeles); |
|
| 1569 | + } |
|
| 1570 | + } |
|
| 1571 | + |
|
| 1572 | + $debut = ''; |
|
| 1573 | + $suite = $texte; |
|
| 1574 | + while ($t = strpos('-' . $suite, "\n", 1)) { |
|
| 1575 | + $debut .= substr($suite, 0, $t - 1); |
|
| 1576 | + $suite = substr($suite, $t); |
|
| 1577 | + $car = substr($suite, 0, 1); |
|
| 1578 | + if ( |
|
| 1579 | + ($car <> '-') and ($car <> '_') and ($car <> "\n") and ($car <> '|') and ($car <> '}') |
|
| 1580 | + and !preg_match(',^\s*(\n|</?(quote|div|dl|dt|dd)|$),S', ($suite)) |
|
| 1581 | + and !preg_match(',</?(quote|div|dl|dt|dd)> *$,iS', $debut) |
|
| 1582 | + ) { |
|
| 1583 | + $debut .= $delim; |
|
| 1584 | + } else { |
|
| 1585 | + $debut .= "\n"; |
|
| 1586 | + } |
|
| 1587 | + if (preg_match(",^\n+,", $suite, $regs)) { |
|
| 1588 | + $debut .= $regs[0]; |
|
| 1589 | + $suite = substr($suite, strlen($regs[0])); |
|
| 1590 | + } |
|
| 1591 | + } |
|
| 1592 | + $texte = $debut . $suite; |
|
| 1593 | + |
|
| 1594 | + $texte = echappe_retour($texte); |
|
| 1595 | + |
|
| 1596 | + return $texte . $fin; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | |
@@ -1634,47 +1634,47 @@ discard block |
||
| 1634 | 1634 | * @return string |
| 1635 | 1635 | **/ |
| 1636 | 1636 | function extraire_idiome($letexte, $lang = null, $options = []) { |
| 1637 | - static $traduire = false; |
|
| 1638 | - if ( |
|
| 1639 | - $letexte |
|
| 1640 | - and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1641 | - ) { |
|
| 1642 | - if (!$traduire) { |
|
| 1643 | - $traduire = charger_fonction('traduire', 'inc'); |
|
| 1644 | - include_spip('inc/lang'); |
|
| 1645 | - } |
|
| 1646 | - if (!$lang) { |
|
| 1647 | - $lang = $GLOBALS['spip_lang']; |
|
| 1648 | - } |
|
| 1649 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1650 | - if (is_bool($options)) { |
|
| 1651 | - $options = ['echappe_span' => $options]; |
|
| 1652 | - } |
|
| 1653 | - if (!isset($options['echappe_span'])) { |
|
| 1654 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1655 | - } |
|
| 1656 | - |
|
| 1657 | - foreach ($regs as $reg) { |
|
| 1658 | - $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1659 | - $desc = $traduire($cle, $lang, true); |
|
| 1660 | - $l = $desc->langue; |
|
| 1661 | - // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1662 | - if (strlen($desc->texte)) { |
|
| 1663 | - $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1664 | - if ($l !== $lang) { |
|
| 1665 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1666 | - } |
|
| 1667 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1668 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1669 | - } |
|
| 1670 | - if (!$options['echappe_span']) { |
|
| 1671 | - $trad = echappe_retour($trad, 'idiome'); |
|
| 1672 | - } |
|
| 1673 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1674 | - } |
|
| 1675 | - } |
|
| 1676 | - } |
|
| 1677 | - return $letexte; |
|
| 1637 | + static $traduire = false; |
|
| 1638 | + if ( |
|
| 1639 | + $letexte |
|
| 1640 | + and preg_match_all(_EXTRAIRE_IDIOME, $letexte, $regs, PREG_SET_ORDER) |
|
| 1641 | + ) { |
|
| 1642 | + if (!$traduire) { |
|
| 1643 | + $traduire = charger_fonction('traduire', 'inc'); |
|
| 1644 | + include_spip('inc/lang'); |
|
| 1645 | + } |
|
| 1646 | + if (!$lang) { |
|
| 1647 | + $lang = $GLOBALS['spip_lang']; |
|
| 1648 | + } |
|
| 1649 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1650 | + if (is_bool($options)) { |
|
| 1651 | + $options = ['echappe_span' => $options]; |
|
| 1652 | + } |
|
| 1653 | + if (!isset($options['echappe_span'])) { |
|
| 1654 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1655 | + } |
|
| 1656 | + |
|
| 1657 | + foreach ($regs as $reg) { |
|
| 1658 | + $cle = ($reg[1] ? $reg[1] . ':' : '') . $reg[2]; |
|
| 1659 | + $desc = $traduire($cle, $lang, true); |
|
| 1660 | + $l = $desc->langue; |
|
| 1661 | + // si pas de traduction, on laissera l'écriture de l'idiome entier dans le texte. |
|
| 1662 | + if (strlen($desc->texte)) { |
|
| 1663 | + $trad = code_echappement($desc->texte, 'idiome', false); |
|
| 1664 | + if ($l !== $lang) { |
|
| 1665 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1666 | + } |
|
| 1667 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1668 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1669 | + } |
|
| 1670 | + if (!$options['echappe_span']) { |
|
| 1671 | + $trad = echappe_retour($trad, 'idiome'); |
|
| 1672 | + } |
|
| 1673 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1674 | + } |
|
| 1675 | + } |
|
| 1676 | + } |
|
| 1677 | + return $letexte; |
|
| 1678 | 1678 | } |
| 1679 | 1679 | |
| 1680 | 1680 | /** |
@@ -1726,68 +1726,68 @@ discard block |
||
| 1726 | 1726 | **/ |
| 1727 | 1727 | function extraire_multi($letexte, $lang = null, $options = []) { |
| 1728 | 1728 | |
| 1729 | - if ( |
|
| 1730 | - $letexte |
|
| 1731 | - and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1732 | - ) { |
|
| 1733 | - if (!$lang) { |
|
| 1734 | - $lang = $GLOBALS['spip_lang']; |
|
| 1735 | - } |
|
| 1736 | - |
|
| 1737 | - // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1738 | - if (is_bool($options)) { |
|
| 1739 | - $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1740 | - } |
|
| 1741 | - if (!isset($options['echappe_span'])) { |
|
| 1742 | - $options = array_merge($options, ['echappe_span' => false]); |
|
| 1743 | - } |
|
| 1744 | - if (!isset($options['lang_defaut'])) { |
|
| 1745 | - $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1746 | - } |
|
| 1747 | - |
|
| 1748 | - include_spip('inc/lang'); |
|
| 1749 | - foreach ($regs as $reg) { |
|
| 1750 | - // chercher la version de la langue courante |
|
| 1751 | - $trads = extraire_trads($reg[1]); |
|
| 1752 | - if ($l = approcher_langue($trads, $lang)) { |
|
| 1753 | - $trad = $trads[$l]; |
|
| 1754 | - } else { |
|
| 1755 | - if ($options['lang_defaut'] == 'aucune') { |
|
| 1756 | - $trad = ''; |
|
| 1757 | - } else { |
|
| 1758 | - // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1759 | - // ou la premiere dispo |
|
| 1760 | - // mais typographier le texte selon les regles de celle-ci |
|
| 1761 | - // Attention aux blocs multi sur plusieurs lignes |
|
| 1762 | - if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1763 | - $l = key($trads); |
|
| 1764 | - } |
|
| 1765 | - $trad = $trads[$l]; |
|
| 1766 | - $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1767 | - $trad = $typographie($trad); |
|
| 1768 | - // Tester si on echappe en span ou en div |
|
| 1769 | - // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1770 | - include_spip('inc/texte'); |
|
| 1771 | - $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1772 | - $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1773 | - if ($mode === 'div') { |
|
| 1774 | - $trad = rtrim($trad) . "\n\n"; |
|
| 1775 | - } |
|
| 1776 | - $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1777 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1778 | - if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1779 | - $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1780 | - } |
|
| 1781 | - if (!$options['echappe_span']) { |
|
| 1782 | - $trad = echappe_retour($trad, 'multi'); |
|
| 1783 | - } |
|
| 1784 | - } |
|
| 1785 | - } |
|
| 1786 | - $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1787 | - } |
|
| 1788 | - } |
|
| 1789 | - |
|
| 1790 | - return $letexte; |
|
| 1729 | + if ( |
|
| 1730 | + $letexte |
|
| 1731 | + and preg_match_all(_EXTRAIRE_MULTI, $letexte, $regs, PREG_SET_ORDER) |
|
| 1732 | + ) { |
|
| 1733 | + if (!$lang) { |
|
| 1734 | + $lang = $GLOBALS['spip_lang']; |
|
| 1735 | + } |
|
| 1736 | + |
|
| 1737 | + // Compatibilité avec le prototype de fonction précédente qui utilisait un boolean |
|
| 1738 | + if (is_bool($options)) { |
|
| 1739 | + $options = ['echappe_span' => $options, 'lang_defaut' => _LANGUE_PAR_DEFAUT]; |
|
| 1740 | + } |
|
| 1741 | + if (!isset($options['echappe_span'])) { |
|
| 1742 | + $options = array_merge($options, ['echappe_span' => false]); |
|
| 1743 | + } |
|
| 1744 | + if (!isset($options['lang_defaut'])) { |
|
| 1745 | + $options = array_merge($options, ['lang_defaut' => _LANGUE_PAR_DEFAUT]); |
|
| 1746 | + } |
|
| 1747 | + |
|
| 1748 | + include_spip('inc/lang'); |
|
| 1749 | + foreach ($regs as $reg) { |
|
| 1750 | + // chercher la version de la langue courante |
|
| 1751 | + $trads = extraire_trads($reg[1]); |
|
| 1752 | + if ($l = approcher_langue($trads, $lang)) { |
|
| 1753 | + $trad = $trads[$l]; |
|
| 1754 | + } else { |
|
| 1755 | + if ($options['lang_defaut'] == 'aucune') { |
|
| 1756 | + $trad = ''; |
|
| 1757 | + } else { |
|
| 1758 | + // langue absente, prendre le fr ou une langue précisée (meme comportement que inc/traduire.php) |
|
| 1759 | + // ou la premiere dispo |
|
| 1760 | + // mais typographier le texte selon les regles de celle-ci |
|
| 1761 | + // Attention aux blocs multi sur plusieurs lignes |
|
| 1762 | + if (!$l = approcher_langue($trads, $options['lang_defaut'])) { |
|
| 1763 | + $l = key($trads); |
|
| 1764 | + } |
|
| 1765 | + $trad = $trads[$l]; |
|
| 1766 | + $typographie = charger_fonction(lang_typo($l), 'typographie'); |
|
| 1767 | + $trad = $typographie($trad); |
|
| 1768 | + // Tester si on echappe en span ou en div |
|
| 1769 | + // il ne faut pas echapper en div si propre produit un seul paragraphe |
|
| 1770 | + include_spip('inc/texte'); |
|
| 1771 | + $trad_propre = preg_replace(',(^<p[^>]*>|</p>$),Uims', '', propre($trad)); |
|
| 1772 | + $mode = preg_match(',</?(' . _BALISES_BLOCS . ')[>[:space:]],iS', $trad_propre) ? 'div' : 'span'; |
|
| 1773 | + if ($mode === 'div') { |
|
| 1774 | + $trad = rtrim($trad) . "\n\n"; |
|
| 1775 | + } |
|
| 1776 | + $trad = code_echappement($trad, 'multi', false, $mode); |
|
| 1777 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'lang', $l)); |
|
| 1778 | + if (lang_dir($l) !== lang_dir($lang)) { |
|
| 1779 | + $trad = str_replace("'", '"', inserer_attribut($trad, 'dir', lang_dir($l))); |
|
| 1780 | + } |
|
| 1781 | + if (!$options['echappe_span']) { |
|
| 1782 | + $trad = echappe_retour($trad, 'multi'); |
|
| 1783 | + } |
|
| 1784 | + } |
|
| 1785 | + } |
|
| 1786 | + $letexte = str_replace($reg[0], $trad, $letexte); |
|
| 1787 | + } |
|
| 1788 | + } |
|
| 1789 | + |
|
| 1790 | + return $letexte; |
|
| 1791 | 1791 | } |
| 1792 | 1792 | |
| 1793 | 1793 | /** |
@@ -1803,20 +1803,20 @@ discard block |
||
| 1803 | 1803 | * Peut retourner un code de langue vide, lorsqu'un texte par défaut est indiqué. |
| 1804 | 1804 | **/ |
| 1805 | 1805 | function extraire_trads($bloc) { |
| 1806 | - $lang = ''; |
|
| 1806 | + $lang = ''; |
|
| 1807 | 1807 | // ce reg fait planter l'analyse multi s'il y a de l'{italique} dans le champ |
| 1808 | 1808 | // while (preg_match("/^(.*?)[{\[]([a-z_]+)[}\]]/siS", $bloc, $regs)) { |
| 1809 | - while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1810 | - $texte = trim($regs[1]); |
|
| 1811 | - if ($texte or $lang) { |
|
| 1812 | - $trads[$lang] = $texte; |
|
| 1813 | - } |
|
| 1814 | - $bloc = substr($bloc, strlen($regs[0])); |
|
| 1815 | - $lang = $regs[2]; |
|
| 1816 | - } |
|
| 1817 | - $trads[$lang] = $bloc; |
|
| 1809 | + while (preg_match('/^(.*?)[\[]([a-z_]+)[\]]/siS', $bloc, $regs)) { |
|
| 1810 | + $texte = trim($regs[1]); |
|
| 1811 | + if ($texte or $lang) { |
|
| 1812 | + $trads[$lang] = $texte; |
|
| 1813 | + } |
|
| 1814 | + $bloc = substr($bloc, strlen($regs[0])); |
|
| 1815 | + $lang = $regs[2]; |
|
| 1816 | + } |
|
| 1817 | + $trads[$lang] = $bloc; |
|
| 1818 | 1818 | |
| 1819 | - return $trads; |
|
| 1819 | + return $trads; |
|
| 1820 | 1820 | } |
| 1821 | 1821 | |
| 1822 | 1822 | |
@@ -1827,7 +1827,7 @@ discard block |
||
| 1827 | 1827 | * @return string L'initiale en majuscule |
| 1828 | 1828 | */ |
| 1829 | 1829 | function filtre_initiale($nom) { |
| 1830 | - return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1830 | + return spip_substr(trim(strtoupper(extraire_multi($nom))), 0, 1); |
|
| 1831 | 1831 | } |
| 1832 | 1832 | |
| 1833 | 1833 | |
@@ -1872,33 +1872,33 @@ discard block |
||
| 1872 | 1872 | * - null (interne) : si on empile |
| 1873 | 1873 | **/ |
| 1874 | 1874 | function unique($donnee, $famille = '', $cpt = false) { |
| 1875 | - static $mem = []; |
|
| 1876 | - // permettre de vider la pile et de la restaurer |
|
| 1877 | - // pour le calcul de introduction... |
|
| 1878 | - if ($famille == '_spip_raz_') { |
|
| 1879 | - $tmp = $mem; |
|
| 1880 | - $mem = []; |
|
| 1881 | - |
|
| 1882 | - return $tmp; |
|
| 1883 | - } elseif ($famille == '_spip_set_') { |
|
| 1884 | - $mem = $donnee; |
|
| 1885 | - |
|
| 1886 | - return; |
|
| 1887 | - } |
|
| 1888 | - // eviter une notice |
|
| 1889 | - if (!isset($mem[$famille])) { |
|
| 1890 | - $mem[$famille] = []; |
|
| 1891 | - } |
|
| 1892 | - if ($cpt) { |
|
| 1893 | - return count($mem[$famille]); |
|
| 1894 | - } |
|
| 1895 | - // eviter une notice |
|
| 1896 | - if (!isset($mem[$famille][$donnee])) { |
|
| 1897 | - $mem[$famille][$donnee] = 0; |
|
| 1898 | - } |
|
| 1899 | - if (!($mem[$famille][$donnee]++)) { |
|
| 1900 | - return $donnee; |
|
| 1901 | - } |
|
| 1875 | + static $mem = []; |
|
| 1876 | + // permettre de vider la pile et de la restaurer |
|
| 1877 | + // pour le calcul de introduction... |
|
| 1878 | + if ($famille == '_spip_raz_') { |
|
| 1879 | + $tmp = $mem; |
|
| 1880 | + $mem = []; |
|
| 1881 | + |
|
| 1882 | + return $tmp; |
|
| 1883 | + } elseif ($famille == '_spip_set_') { |
|
| 1884 | + $mem = $donnee; |
|
| 1885 | + |
|
| 1886 | + return; |
|
| 1887 | + } |
|
| 1888 | + // eviter une notice |
|
| 1889 | + if (!isset($mem[$famille])) { |
|
| 1890 | + $mem[$famille] = []; |
|
| 1891 | + } |
|
| 1892 | + if ($cpt) { |
|
| 1893 | + return count($mem[$famille]); |
|
| 1894 | + } |
|
| 1895 | + // eviter une notice |
|
| 1896 | + if (!isset($mem[$famille][$donnee])) { |
|
| 1897 | + $mem[$famille][$donnee] = 0; |
|
| 1898 | + } |
|
| 1899 | + if (!($mem[$famille][$donnee]++)) { |
|
| 1900 | + return $donnee; |
|
| 1901 | + } |
|
| 1902 | 1902 | } |
| 1903 | 1903 | |
| 1904 | 1904 | |
@@ -1928,16 +1928,16 @@ discard block |
||
| 1928 | 1928 | * Une des valeurs en fonction du compteur. |
| 1929 | 1929 | **/ |
| 1930 | 1930 | function alterner($i, ...$args) { |
| 1931 | - // recuperer les arguments (attention fonctions un peu space) |
|
| 1932 | - $num = count($args); |
|
| 1931 | + // recuperer les arguments (attention fonctions un peu space) |
|
| 1932 | + $num = count($args); |
|
| 1933 | 1933 | |
| 1934 | - if ($num === 1 && is_array($args[0])) { |
|
| 1935 | - $args = $args[0]; |
|
| 1936 | - $num = count($args); |
|
| 1937 | - } |
|
| 1934 | + if ($num === 1 && is_array($args[0])) { |
|
| 1935 | + $args = $args[0]; |
|
| 1936 | + $num = count($args); |
|
| 1937 | + } |
|
| 1938 | 1938 | |
| 1939 | - // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1940 | - return $args[(intval($i) - 1) % $num]; |
|
| 1939 | + // renvoyer le i-ieme argument, modulo le nombre d'arguments |
|
| 1940 | + return $args[(intval($i) - 1) % $num]; |
|
| 1941 | 1941 | } |
| 1942 | 1942 | |
| 1943 | 1943 | |
@@ -1962,49 +1962,49 @@ discard block |
||
| 1962 | 1962 | * - Tableau complet (si 2e argument) |
| 1963 | 1963 | **/ |
| 1964 | 1964 | function extraire_attribut($balise, $attribut, $complet = false) { |
| 1965 | - if (is_array($balise)) { |
|
| 1966 | - array_walk( |
|
| 1967 | - $balise, |
|
| 1968 | - function (&$a, $key, $t) { |
|
| 1969 | - $a = extraire_attribut($a, $t); |
|
| 1970 | - }, |
|
| 1971 | - $attribut |
|
| 1972 | - ); |
|
| 1973 | - |
|
| 1974 | - return $balise; |
|
| 1975 | - } |
|
| 1976 | - if ( |
|
| 1977 | - preg_match( |
|
| 1978 | - ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1979 | - . $attribut |
|
| 1980 | - . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1981 | - $balise, |
|
| 1982 | - $r |
|
| 1983 | - ) |
|
| 1984 | - ) { |
|
| 1985 | - if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1986 | - $r[4] = substr($r[3], 1, -1); |
|
| 1987 | - $r[3] = $r[3][0]; |
|
| 1988 | - } elseif ($r[3] !== '') { |
|
| 1989 | - $r[4] = $r[3]; |
|
| 1990 | - $r[3] = ''; |
|
| 1991 | - } else { |
|
| 1992 | - $r[4] = trim($r[2]); |
|
| 1993 | - } |
|
| 1994 | - $att = $r[4]; |
|
| 1995 | - if (strpos($att, '&#') !== false) { |
|
| 1996 | - $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1997 | - } |
|
| 1998 | - $att = filtrer_entites($att); |
|
| 1999 | - } else { |
|
| 2000 | - $att = null; |
|
| 2001 | - } |
|
| 2002 | - |
|
| 2003 | - if ($complet) { |
|
| 2004 | - return [$att, $r]; |
|
| 2005 | - } else { |
|
| 2006 | - return $att; |
|
| 2007 | - } |
|
| 1965 | + if (is_array($balise)) { |
|
| 1966 | + array_walk( |
|
| 1967 | + $balise, |
|
| 1968 | + function (&$a, $key, $t) { |
|
| 1969 | + $a = extraire_attribut($a, $t); |
|
| 1970 | + }, |
|
| 1971 | + $attribut |
|
| 1972 | + ); |
|
| 1973 | + |
|
| 1974 | + return $balise; |
|
| 1975 | + } |
|
| 1976 | + if ( |
|
| 1977 | + preg_match( |
|
| 1978 | + ',(^.*?<(?:(?>\s*)(?>[\w:.-]+)(?>(?:=(?:"[^"]*"|\'[^\']*\'|[^\'"]\S*))?))*?)(\s+' |
|
| 1979 | + . $attribut |
|
| 1980 | + . '(?:=\s*("[^"]*"|\'[^\']*\'|[^\'"]\S*))?)()((?:[\s/][^>]*)?>.*),isS', |
|
| 1981 | + $balise, |
|
| 1982 | + $r |
|
| 1983 | + ) |
|
| 1984 | + ) { |
|
| 1985 | + if (isset($r[3][0]) and ($r[3][0] == '"' || $r[3][0] == "'")) { |
|
| 1986 | + $r[4] = substr($r[3], 1, -1); |
|
| 1987 | + $r[3] = $r[3][0]; |
|
| 1988 | + } elseif ($r[3] !== '') { |
|
| 1989 | + $r[4] = $r[3]; |
|
| 1990 | + $r[3] = ''; |
|
| 1991 | + } else { |
|
| 1992 | + $r[4] = trim($r[2]); |
|
| 1993 | + } |
|
| 1994 | + $att = $r[4]; |
|
| 1995 | + if (strpos($att, '&#') !== false) { |
|
| 1996 | + $att = str_replace([''', ''', '"', '"'], ["'", "'", '"', '"'], $att); |
|
| 1997 | + } |
|
| 1998 | + $att = filtrer_entites($att); |
|
| 1999 | + } else { |
|
| 2000 | + $att = null; |
|
| 2001 | + } |
|
| 2002 | + |
|
| 2003 | + if ($complet) { |
|
| 2004 | + return [$att, $r]; |
|
| 2005 | + } else { |
|
| 2006 | + return $att; |
|
| 2007 | + } |
|
| 2008 | 2008 | } |
| 2009 | 2009 | |
| 2010 | 2010 | /** |
@@ -2036,37 +2036,37 @@ discard block |
||
| 2036 | 2036 | * Code html modifié |
| 2037 | 2037 | **/ |
| 2038 | 2038 | function inserer_attribut($balise, $attribut, $val, $proteger = true, $vider = false) { |
| 2039 | - // preparer l'attribut |
|
| 2040 | - // supprimer les etc mais pas les balises html |
|
| 2041 | - // qui ont un sens dans un attribut value d'un input |
|
| 2042 | - if ($proteger) { |
|
| 2043 | - $val = attribut_html($val, false); |
|
| 2044 | - } |
|
| 2045 | - |
|
| 2046 | - // echapper les ' pour eviter tout bug |
|
| 2047 | - $val = str_replace("'", ''', $val); |
|
| 2048 | - if ($vider and strlen($val) == 0) { |
|
| 2049 | - $insert = ''; |
|
| 2050 | - } else { |
|
| 2051 | - $insert = " $attribut='$val'"; |
|
| 2052 | - } |
|
| 2053 | - |
|
| 2054 | - list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 2055 | - |
|
| 2056 | - if ($old !== null) { |
|
| 2057 | - // Remplacer l'ancien attribut du meme nom |
|
| 2058 | - $balise = $r[1] . $insert . $r[5]; |
|
| 2059 | - } else { |
|
| 2060 | - // preferer une balise " />" (comme <img />) |
|
| 2061 | - if (preg_match(',/>,', $balise)) { |
|
| 2062 | - $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2063 | - } // sinon une balise <a ...> ... </a> |
|
| 2064 | - else { |
|
| 2065 | - $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2066 | - } |
|
| 2067 | - } |
|
| 2068 | - |
|
| 2069 | - return $balise; |
|
| 2039 | + // preparer l'attribut |
|
| 2040 | + // supprimer les etc mais pas les balises html |
|
| 2041 | + // qui ont un sens dans un attribut value d'un input |
|
| 2042 | + if ($proteger) { |
|
| 2043 | + $val = attribut_html($val, false); |
|
| 2044 | + } |
|
| 2045 | + |
|
| 2046 | + // echapper les ' pour eviter tout bug |
|
| 2047 | + $val = str_replace("'", ''', $val); |
|
| 2048 | + if ($vider and strlen($val) == 0) { |
|
| 2049 | + $insert = ''; |
|
| 2050 | + } else { |
|
| 2051 | + $insert = " $attribut='$val'"; |
|
| 2052 | + } |
|
| 2053 | + |
|
| 2054 | + list($old, $r) = extraire_attribut($balise, $attribut, true); |
|
| 2055 | + |
|
| 2056 | + if ($old !== null) { |
|
| 2057 | + // Remplacer l'ancien attribut du meme nom |
|
| 2058 | + $balise = $r[1] . $insert . $r[5]; |
|
| 2059 | + } else { |
|
| 2060 | + // preferer une balise " />" (comme <img />) |
|
| 2061 | + if (preg_match(',/>,', $balise)) { |
|
| 2062 | + $balise = preg_replace(',\s?/>,S', $insert . ' />', $balise, 1); |
|
| 2063 | + } // sinon une balise <a ...> ... </a> |
|
| 2064 | + else { |
|
| 2065 | + $balise = preg_replace(',\s?>,S', $insert . '>', $balise, 1); |
|
| 2066 | + } |
|
| 2067 | + } |
|
| 2068 | + |
|
| 2069 | + return $balise; |
|
| 2070 | 2070 | } |
| 2071 | 2071 | |
| 2072 | 2072 | /** |
@@ -2084,7 +2084,7 @@ discard block |
||
| 2084 | 2084 | * @return string Code HTML sans l'attribut |
| 2085 | 2085 | **/ |
| 2086 | 2086 | function vider_attribut($balise, $attribut) { |
| 2087 | - return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2087 | + return inserer_attribut($balise, $attribut, '', false, true); |
|
| 2088 | 2088 | } |
| 2089 | 2089 | |
| 2090 | 2090 | /** |
@@ -2096,56 +2096,56 @@ discard block |
||
| 2096 | 2096 | * @return string |
| 2097 | 2097 | */ |
| 2098 | 2098 | function modifier_class($balise, $class, $operation = 'ajouter') { |
| 2099 | - if (is_string($class)) { |
|
| 2100 | - $class = explode(' ', trim($class)); |
|
| 2101 | - } |
|
| 2102 | - $class = array_filter($class); |
|
| 2103 | - |
|
| 2104 | - // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2105 | - if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2106 | - return $balise; |
|
| 2107 | - } |
|
| 2108 | - |
|
| 2109 | - if ($class) { |
|
| 2110 | - $class = array_unique($class); |
|
| 2111 | - $class_courante = extraire_attribut($balise, 'class'); |
|
| 2112 | - |
|
| 2113 | - $class_new = $class_courante; |
|
| 2114 | - foreach ($class as $c) { |
|
| 2115 | - if ($c) { |
|
| 2116 | - $is_class_presente = false; |
|
| 2117 | - if ( |
|
| 2118 | - strpos($class_courante, $c) !== false |
|
| 2119 | - and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2120 | - ) { |
|
| 2121 | - $is_class_presente = true; |
|
| 2122 | - } |
|
| 2123 | - if ( |
|
| 2124 | - in_array($operation, ['ajouter', 'commuter']) |
|
| 2125 | - and !$is_class_presente |
|
| 2126 | - ) { |
|
| 2127 | - $class_new = rtrim($class_new) . ' ' . $c; |
|
| 2128 | - } |
|
| 2129 | - elseif ( |
|
| 2130 | - in_array($operation, ['supprimer', 'commuter']) |
|
| 2131 | - and $is_class_presente |
|
| 2132 | - ) { |
|
| 2133 | - $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2134 | - } |
|
| 2135 | - } |
|
| 2136 | - } |
|
| 2137 | - |
|
| 2138 | - if ($class_new !== $class_courante) { |
|
| 2139 | - if (strlen($class_new)) { |
|
| 2140 | - $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2141 | - } |
|
| 2142 | - elseif ($class_courante) { |
|
| 2143 | - $balise = vider_attribut($balise, 'class'); |
|
| 2144 | - } |
|
| 2145 | - } |
|
| 2146 | - } |
|
| 2147 | - |
|
| 2148 | - return $balise; |
|
| 2099 | + if (is_string($class)) { |
|
| 2100 | + $class = explode(' ', trim($class)); |
|
| 2101 | + } |
|
| 2102 | + $class = array_filter($class); |
|
| 2103 | + |
|
| 2104 | + // si la ou les classes ont des caracteres invalides on ne fait rien |
|
| 2105 | + if (preg_match(',[^\w-],', implode('', $class))) { |
|
| 2106 | + return $balise; |
|
| 2107 | + } |
|
| 2108 | + |
|
| 2109 | + if ($class) { |
|
| 2110 | + $class = array_unique($class); |
|
| 2111 | + $class_courante = extraire_attribut($balise, 'class'); |
|
| 2112 | + |
|
| 2113 | + $class_new = $class_courante; |
|
| 2114 | + foreach ($class as $c) { |
|
| 2115 | + if ($c) { |
|
| 2116 | + $is_class_presente = false; |
|
| 2117 | + if ( |
|
| 2118 | + strpos($class_courante, $c) !== false |
|
| 2119 | + and preg_match('/(^|\s)' . preg_quote($c) . '($|\s)/', $class_courante) |
|
| 2120 | + ) { |
|
| 2121 | + $is_class_presente = true; |
|
| 2122 | + } |
|
| 2123 | + if ( |
|
| 2124 | + in_array($operation, ['ajouter', 'commuter']) |
|
| 2125 | + and !$is_class_presente |
|
| 2126 | + ) { |
|
| 2127 | + $class_new = rtrim($class_new) . ' ' . $c; |
|
| 2128 | + } |
|
| 2129 | + elseif ( |
|
| 2130 | + in_array($operation, ['supprimer', 'commuter']) |
|
| 2131 | + and $is_class_presente |
|
| 2132 | + ) { |
|
| 2133 | + $class_new = trim(preg_replace('/(^|\s)' . preg_quote($c) . '($|\s)/', "\\1", $class_new)); |
|
| 2134 | + } |
|
| 2135 | + } |
|
| 2136 | + } |
|
| 2137 | + |
|
| 2138 | + if ($class_new !== $class_courante) { |
|
| 2139 | + if (strlen($class_new)) { |
|
| 2140 | + $balise = inserer_attribut($balise, 'class', $class_new); |
|
| 2141 | + } |
|
| 2142 | + elseif ($class_courante) { |
|
| 2143 | + $balise = vider_attribut($balise, 'class'); |
|
| 2144 | + } |
|
| 2145 | + } |
|
| 2146 | + } |
|
| 2147 | + |
|
| 2148 | + return $balise; |
|
| 2149 | 2149 | } |
| 2150 | 2150 | |
| 2151 | 2151 | /** |
@@ -2155,7 +2155,7 @@ discard block |
||
| 2155 | 2155 | * @return string |
| 2156 | 2156 | */ |
| 2157 | 2157 | function ajouter_class($balise, $class) { |
| 2158 | - return modifier_class($balise, $class, 'ajouter'); |
|
| 2158 | + return modifier_class($balise, $class, 'ajouter'); |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | /** |
@@ -2165,7 +2165,7 @@ discard block |
||
| 2165 | 2165 | * @return string |
| 2166 | 2166 | */ |
| 2167 | 2167 | function supprimer_class($balise, $class) { |
| 2168 | - return modifier_class($balise, $class, 'supprimer'); |
|
| 2168 | + return modifier_class($balise, $class, 'supprimer'); |
|
| 2169 | 2169 | } |
| 2170 | 2170 | |
| 2171 | 2171 | /** |
@@ -2176,7 +2176,7 @@ discard block |
||
| 2176 | 2176 | * @return string |
| 2177 | 2177 | */ |
| 2178 | 2178 | function commuter_class($balise, $class) { |
| 2179 | - return modifier_class($balise, $class, 'commuter'); |
|
| 2179 | + return modifier_class($balise, $class, 'commuter'); |
|
| 2180 | 2180 | } |
| 2181 | 2181 | |
| 2182 | 2182 | /** |
@@ -2187,19 +2187,19 @@ discard block |
||
| 2187 | 2187 | * @return string |
| 2188 | 2188 | */ |
| 2189 | 2189 | function tester_config($id, $mode = '') { |
| 2190 | - include_spip('action/inscrire_auteur'); |
|
| 2190 | + include_spip('action/inscrire_auteur'); |
|
| 2191 | 2191 | |
| 2192 | - return tester_statut_inscription($mode, $id); |
|
| 2192 | + return tester_statut_inscription($mode, $id); |
|
| 2193 | 2193 | } |
| 2194 | 2194 | |
| 2195 | 2195 | // |
| 2196 | 2196 | // Quelques fonctions de calcul arithmetique |
| 2197 | 2197 | // |
| 2198 | 2198 | function floatstr($a) { |
| 2199 | - return str_replace(',', '.', (string)floatval($a)); |
|
| 2199 | + return str_replace(',', '.', (string)floatval($a)); |
|
| 2200 | 2200 | } |
| 2201 | 2201 | function strize($f, $a, $b) { |
| 2202 | - return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2202 | + return floatstr($f(floatstr($a), floatstr($b))); |
|
| 2203 | 2203 | } |
| 2204 | 2204 | |
| 2205 | 2205 | /** |
@@ -2218,7 +2218,7 @@ discard block |
||
| 2218 | 2218 | * @return int $a+$b |
| 2219 | 2219 | **/ |
| 2220 | 2220 | function plus($a, $b) { |
| 2221 | - return $a + $b; |
|
| 2221 | + return $a + $b; |
|
| 2222 | 2222 | } |
| 2223 | 2223 | function strplus($a, $b) { |
| 2224 | 2224 | return strize('plus', $a, $b); |
@@ -2239,7 +2239,7 @@ discard block |
||
| 2239 | 2239 | * @return int $a-$b |
| 2240 | 2240 | **/ |
| 2241 | 2241 | function moins($a, $b) { |
| 2242 | - return $a - $b; |
|
| 2242 | + return $a - $b; |
|
| 2243 | 2243 | } |
| 2244 | 2244 | function strmoins($a, $b) { |
| 2245 | 2245 | return strize('moins', $a, $b); |
@@ -2262,7 +2262,7 @@ discard block |
||
| 2262 | 2262 | * @return int $a*$b |
| 2263 | 2263 | **/ |
| 2264 | 2264 | function mult($a, $b) { |
| 2265 | - return $a * $b; |
|
| 2265 | + return $a * $b; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | function strmult($a, $b) { |
| 2268 | 2268 | return strize('mult', $a, $b); |
@@ -2285,7 +2285,7 @@ discard block |
||
| 2285 | 2285 | * @return int $a/$b (ou 0 si $b est nul) |
| 2286 | 2286 | **/ |
| 2287 | 2287 | function div($a, $b) { |
| 2288 | - return $b ? $a / $b : 0; |
|
| 2288 | + return $b ? $a / $b : 0; |
|
| 2289 | 2289 | } |
| 2290 | 2290 | function strdiv($a, $b) { |
| 2291 | 2291 | return strize('div', $a, $b); |
@@ -2309,7 +2309,7 @@ discard block |
||
| 2309 | 2309 | * @return int ($nb % $mod) + $add |
| 2310 | 2310 | **/ |
| 2311 | 2311 | function modulo($nb, $mod, $add = 0) { |
| 2312 | - return ($mod ? $nb % $mod : 0) + $add; |
|
| 2312 | + return ($mod ? $nb % $mod : 0) + $add; |
|
| 2313 | 2313 | } |
| 2314 | 2314 | |
| 2315 | 2315 | |
@@ -2324,24 +2324,24 @@ discard block |
||
| 2324 | 2324 | * - true sinon |
| 2325 | 2325 | **/ |
| 2326 | 2326 | function nom_acceptable($nom) { |
| 2327 | - if (!is_string($nom)) { |
|
| 2328 | - return false; |
|
| 2329 | - } |
|
| 2330 | - if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2331 | - define('_TAGS_NOM_AUTEUR', ''); |
|
| 2332 | - } |
|
| 2333 | - $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2334 | - foreach ($tags_acceptes as $tag) { |
|
| 2335 | - if (strlen($tag)) { |
|
| 2336 | - $remp1[] = '<' . trim($tag) . '>'; |
|
| 2337 | - $remp1[] = '</' . trim($tag) . '>'; |
|
| 2338 | - $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2339 | - $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2340 | - } |
|
| 2341 | - } |
|
| 2342 | - $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2327 | + if (!is_string($nom)) { |
|
| 2328 | + return false; |
|
| 2329 | + } |
|
| 2330 | + if (!defined('_TAGS_NOM_AUTEUR')) { |
|
| 2331 | + define('_TAGS_NOM_AUTEUR', ''); |
|
| 2332 | + } |
|
| 2333 | + $tags_acceptes = array_unique(explode(',', 'multi,' . _TAGS_NOM_AUTEUR)); |
|
| 2334 | + foreach ($tags_acceptes as $tag) { |
|
| 2335 | + if (strlen($tag)) { |
|
| 2336 | + $remp1[] = '<' . trim($tag) . '>'; |
|
| 2337 | + $remp1[] = '</' . trim($tag) . '>'; |
|
| 2338 | + $remp2[] = '\x60' . trim($tag) . '\x61'; |
|
| 2339 | + $remp2[] = '\x60/' . trim($tag) . '\x61'; |
|
| 2340 | + } |
|
| 2341 | + } |
|
| 2342 | + $v_nom = str_replace($remp2, $remp1, supprimer_tags(str_replace($remp1, $remp2, $nom))); |
|
| 2343 | 2343 | |
| 2344 | - return str_replace('<', '<', $v_nom) == $nom; |
|
| 2344 | + return str_replace('<', '<', $v_nom) == $nom; |
|
| 2345 | 2345 | } |
| 2346 | 2346 | |
| 2347 | 2347 | |
@@ -2357,14 +2357,14 @@ discard block |
||
| 2357 | 2357 | * - renvoie un tableau si l'entree est un tableau |
| 2358 | 2358 | **/ |
| 2359 | 2359 | function email_valide($adresses) { |
| 2360 | - if (is_array($adresses)) { |
|
| 2361 | - $adresses = array_map('email_valide', $adresses); |
|
| 2362 | - $adresses = array_filter($adresses); |
|
| 2363 | - return $adresses; |
|
| 2364 | - } |
|
| 2360 | + if (is_array($adresses)) { |
|
| 2361 | + $adresses = array_map('email_valide', $adresses); |
|
| 2362 | + $adresses = array_filter($adresses); |
|
| 2363 | + return $adresses; |
|
| 2364 | + } |
|
| 2365 | 2365 | |
| 2366 | - $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2367 | - return $email_valide($adresses); |
|
| 2366 | + $email_valide = charger_fonction('email_valide', 'inc'); |
|
| 2367 | + return $email_valide($adresses); |
|
| 2368 | 2368 | } |
| 2369 | 2369 | |
| 2370 | 2370 | /** |
@@ -2378,27 +2378,27 @@ discard block |
||
| 2378 | 2378 | * @return string Texte |
| 2379 | 2379 | **/ |
| 2380 | 2380 | function afficher_enclosures($tags) { |
| 2381 | - $s = []; |
|
| 2382 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2383 | - if ( |
|
| 2384 | - extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2385 | - and $t = extraire_attribut($tag, 'href') |
|
| 2386 | - ) { |
|
| 2387 | - $s[] = preg_replace( |
|
| 2388 | - ',>[^<]+</a>,S', |
|
| 2389 | - '>' |
|
| 2390 | - . http_img_pack( |
|
| 2391 | - 'attachment-16.png', |
|
| 2392 | - $t, |
|
| 2393 | - 'title="' . attribut_html($t) . '"' |
|
| 2394 | - ) |
|
| 2395 | - . '</a>', |
|
| 2396 | - $tag |
|
| 2397 | - ); |
|
| 2398 | - } |
|
| 2399 | - } |
|
| 2400 | - |
|
| 2401 | - return join(' ', $s); |
|
| 2381 | + $s = []; |
|
| 2382 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2383 | + if ( |
|
| 2384 | + extraire_attribut($tag, 'rel') == 'enclosure' |
|
| 2385 | + and $t = extraire_attribut($tag, 'href') |
|
| 2386 | + ) { |
|
| 2387 | + $s[] = preg_replace( |
|
| 2388 | + ',>[^<]+</a>,S', |
|
| 2389 | + '>' |
|
| 2390 | + . http_img_pack( |
|
| 2391 | + 'attachment-16.png', |
|
| 2392 | + $t, |
|
| 2393 | + 'title="' . attribut_html($t) . '"' |
|
| 2394 | + ) |
|
| 2395 | + . '</a>', |
|
| 2396 | + $tag |
|
| 2397 | + ); |
|
| 2398 | + } |
|
| 2399 | + } |
|
| 2400 | + |
|
| 2401 | + return join(' ', $s); |
|
| 2402 | 2402 | } |
| 2403 | 2403 | |
| 2404 | 2404 | /** |
@@ -2413,15 +2413,15 @@ discard block |
||
| 2413 | 2413 | * @return string Liens trouvés |
| 2414 | 2414 | **/ |
| 2415 | 2415 | function afficher_tags($tags, $rels = 'tag,directory') { |
| 2416 | - $s = []; |
|
| 2417 | - foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2418 | - $rel = extraire_attribut($tag, 'rel'); |
|
| 2419 | - if (strstr(",$rels,", ",$rel,")) { |
|
| 2420 | - $s[] = $tag; |
|
| 2421 | - } |
|
| 2422 | - } |
|
| 2416 | + $s = []; |
|
| 2417 | + foreach (extraire_balises($tags, 'a') as $tag) { |
|
| 2418 | + $rel = extraire_attribut($tag, 'rel'); |
|
| 2419 | + if (strstr(",$rels,", ",$rel,")) { |
|
| 2420 | + $s[] = $tag; |
|
| 2421 | + } |
|
| 2422 | + } |
|
| 2423 | 2423 | |
| 2424 | - return join(', ', $s); |
|
| 2424 | + return join(', ', $s); |
|
| 2425 | 2425 | } |
| 2426 | 2426 | |
| 2427 | 2427 | |
@@ -2443,21 +2443,21 @@ discard block |
||
| 2443 | 2443 | * @return string Tag HTML `<a>` avec microformat. |
| 2444 | 2444 | **/ |
| 2445 | 2445 | function enclosure2microformat($e) { |
| 2446 | - if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2447 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2448 | - } |
|
| 2449 | - $type = extraire_attribut($e, 'type'); |
|
| 2450 | - if (!$length = extraire_attribut($e, 'length')) { |
|
| 2451 | - # <media:content : longeur dans fileSize. On tente. |
|
| 2452 | - $length = extraire_attribut($e, 'fileSize'); |
|
| 2453 | - } |
|
| 2454 | - $fichier = basename($url); |
|
| 2446 | + if (!$url = filtrer_entites(extraire_attribut($e, 'url'))) { |
|
| 2447 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2448 | + } |
|
| 2449 | + $type = extraire_attribut($e, 'type'); |
|
| 2450 | + if (!$length = extraire_attribut($e, 'length')) { |
|
| 2451 | + # <media:content : longeur dans fileSize. On tente. |
|
| 2452 | + $length = extraire_attribut($e, 'fileSize'); |
|
| 2453 | + } |
|
| 2454 | + $fichier = basename($url); |
|
| 2455 | 2455 | |
| 2456 | - return '<a rel="enclosure"' |
|
| 2457 | - . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2458 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2459 | - . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2460 | - . '>' . $fichier . '</a>'; |
|
| 2456 | + return '<a rel="enclosure"' |
|
| 2457 | + . ($url ? ' href="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2458 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2459 | + . ($length ? ' title="' . spip_htmlspecialchars($length) . '"' : '') |
|
| 2460 | + . '>' . $fichier . '</a>'; |
|
| 2461 | 2461 | } |
| 2462 | 2462 | |
| 2463 | 2463 | /** |
@@ -2475,24 +2475,24 @@ discard block |
||
| 2475 | 2475 | * @return string Tags RSS `<enclosure>`. |
| 2476 | 2476 | **/ |
| 2477 | 2477 | function microformat2enclosure($tags) { |
| 2478 | - $enclosures = []; |
|
| 2479 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2480 | - if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2481 | - $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2482 | - $type = extraire_attribut($e, 'type'); |
|
| 2483 | - if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2484 | - $length = intval(extraire_attribut($e, 'length')); |
|
| 2485 | - } # vieux data |
|
| 2486 | - $fichier = basename($url); |
|
| 2487 | - $enclosures[] = '<enclosure' |
|
| 2488 | - . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2489 | - . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2490 | - . ($length ? ' length="' . $length . '"' : '') |
|
| 2491 | - . ' />'; |
|
| 2492 | - } |
|
| 2493 | - } |
|
| 2478 | + $enclosures = []; |
|
| 2479 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2480 | + if (extraire_attribut($e, 'rel') == 'enclosure') { |
|
| 2481 | + $url = filtrer_entites(extraire_attribut($e, 'href')); |
|
| 2482 | + $type = extraire_attribut($e, 'type'); |
|
| 2483 | + if (!$length = intval(extraire_attribut($e, 'title'))) { |
|
| 2484 | + $length = intval(extraire_attribut($e, 'length')); |
|
| 2485 | + } # vieux data |
|
| 2486 | + $fichier = basename($url); |
|
| 2487 | + $enclosures[] = '<enclosure' |
|
| 2488 | + . ($url ? ' url="' . spip_htmlspecialchars($url) . '"' : '') |
|
| 2489 | + . ($type ? ' type="' . spip_htmlspecialchars($type) . '"' : '') |
|
| 2490 | + . ($length ? ' length="' . $length . '"' : '') |
|
| 2491 | + . ' />'; |
|
| 2492 | + } |
|
| 2493 | + } |
|
| 2494 | 2494 | |
| 2495 | - return join("\n", $enclosures); |
|
| 2495 | + return join("\n", $enclosures); |
|
| 2496 | 2496 | } |
| 2497 | 2497 | |
| 2498 | 2498 | |
@@ -2508,16 +2508,16 @@ discard block |
||
| 2508 | 2508 | * @return string Tags RSS Atom `<dc:subject>`. |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function tags2dcsubject($tags) { |
| 2511 | - $subjects = ''; |
|
| 2512 | - foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2513 | - if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2514 | - $subjects .= '<dc:subject>' |
|
| 2515 | - . texte_backend(textebrut($e)) |
|
| 2516 | - . '</dc:subject>' . "\n"; |
|
| 2517 | - } |
|
| 2518 | - } |
|
| 2511 | + $subjects = ''; |
|
| 2512 | + foreach (extraire_balises($tags, 'a') as $e) { |
|
| 2513 | + if (extraire_attribut($e, 'rel') == 'tag') { |
|
| 2514 | + $subjects .= '<dc:subject>' |
|
| 2515 | + . texte_backend(textebrut($e)) |
|
| 2516 | + . '</dc:subject>' . "\n"; |
|
| 2517 | + } |
|
| 2518 | + } |
|
| 2519 | 2519 | |
| 2520 | - return $subjects; |
|
| 2520 | + return $subjects; |
|
| 2521 | 2521 | } |
| 2522 | 2522 | |
| 2523 | 2523 | /** |
@@ -2546,27 +2546,27 @@ discard block |
||
| 2546 | 2546 | * - Tableau de résultats, si tableau en entrée. |
| 2547 | 2547 | **/ |
| 2548 | 2548 | function extraire_balise($texte, $tag = 'a') { |
| 2549 | - if (is_array($texte)) { |
|
| 2550 | - array_walk( |
|
| 2551 | - $texte, |
|
| 2552 | - function (&$a, $key, $t) { |
|
| 2553 | - $a = extraire_balise($a, $t); |
|
| 2554 | - }, |
|
| 2555 | - $tag |
|
| 2556 | - ); |
|
| 2557 | - |
|
| 2558 | - return $texte; |
|
| 2559 | - } |
|
| 2560 | - |
|
| 2561 | - if ( |
|
| 2562 | - preg_match( |
|
| 2563 | - ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2564 | - $texte, |
|
| 2565 | - $regs |
|
| 2566 | - ) |
|
| 2567 | - ) { |
|
| 2568 | - return $regs[0]; |
|
| 2569 | - } |
|
| 2549 | + if (is_array($texte)) { |
|
| 2550 | + array_walk( |
|
| 2551 | + $texte, |
|
| 2552 | + function (&$a, $key, $t) { |
|
| 2553 | + $a = extraire_balise($a, $t); |
|
| 2554 | + }, |
|
| 2555 | + $tag |
|
| 2556 | + ); |
|
| 2557 | + |
|
| 2558 | + return $texte; |
|
| 2559 | + } |
|
| 2560 | + |
|
| 2561 | + if ( |
|
| 2562 | + preg_match( |
|
| 2563 | + ",<$tag\b[^>]*(/>|>.*</$tag\b[^>]*>|>),UimsS", |
|
| 2564 | + $texte, |
|
| 2565 | + $regs |
|
| 2566 | + ) |
|
| 2567 | + ) { |
|
| 2568 | + return $regs[0]; |
|
| 2569 | + } |
|
| 2570 | 2570 | } |
| 2571 | 2571 | |
| 2572 | 2572 | /** |
@@ -2594,30 +2594,30 @@ discard block |
||
| 2594 | 2594 | * - Tableau de résultats, si tableau en entrée. |
| 2595 | 2595 | **/ |
| 2596 | 2596 | function extraire_balises($texte, $tag = 'a') { |
| 2597 | - if (is_array($texte)) { |
|
| 2598 | - array_walk( |
|
| 2599 | - $texte, |
|
| 2600 | - function (&$a, $key, $t) { |
|
| 2601 | - $a = extraire_balises($a, $t); |
|
| 2602 | - }, |
|
| 2603 | - $tag |
|
| 2604 | - ); |
|
| 2605 | - |
|
| 2606 | - return $texte; |
|
| 2607 | - } |
|
| 2608 | - |
|
| 2609 | - if ( |
|
| 2610 | - preg_match_all( |
|
| 2611 | - ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2612 | - $texte, |
|
| 2613 | - $regs, |
|
| 2614 | - PREG_PATTERN_ORDER |
|
| 2615 | - ) |
|
| 2616 | - ) { |
|
| 2617 | - return $regs[0]; |
|
| 2618 | - } else { |
|
| 2619 | - return []; |
|
| 2620 | - } |
|
| 2597 | + if (is_array($texte)) { |
|
| 2598 | + array_walk( |
|
| 2599 | + $texte, |
|
| 2600 | + function (&$a, $key, $t) { |
|
| 2601 | + $a = extraire_balises($a, $t); |
|
| 2602 | + }, |
|
| 2603 | + $tag |
|
| 2604 | + ); |
|
| 2605 | + |
|
| 2606 | + return $texte; |
|
| 2607 | + } |
|
| 2608 | + |
|
| 2609 | + if ( |
|
| 2610 | + preg_match_all( |
|
| 2611 | + ",<${tag}\b[^>]*(/>|>.*</${tag}\b[^>]*>|>),UimsS", |
|
| 2612 | + $texte, |
|
| 2613 | + $regs, |
|
| 2614 | + PREG_PATTERN_ORDER |
|
| 2615 | + ) |
|
| 2616 | + ) { |
|
| 2617 | + return $regs[0]; |
|
| 2618 | + } else { |
|
| 2619 | + return []; |
|
| 2620 | + } |
|
| 2621 | 2621 | } |
| 2622 | 2622 | |
| 2623 | 2623 | /** |
@@ -2646,11 +2646,11 @@ discard block |
||
| 2646 | 2646 | * - `$def` si on n'a pas transmis de tableau |
| 2647 | 2647 | **/ |
| 2648 | 2648 | function in_any($val, $vals, $def = '') { |
| 2649 | - if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2650 | - $vals = $v; |
|
| 2651 | - } |
|
| 2649 | + if (!is_array($vals) and $v = unserialize($vals)) { |
|
| 2650 | + $vals = $v; |
|
| 2651 | + } |
|
| 2652 | 2652 | |
| 2653 | - return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2653 | + return (!is_array($vals) ? $def : (in_array($val, $vals) ? ' ' : '')); |
|
| 2654 | 2654 | } |
| 2655 | 2655 | |
| 2656 | 2656 | |
@@ -2671,12 +2671,12 @@ discard block |
||
| 2671 | 2671 | * Résultat du calcul |
| 2672 | 2672 | **/ |
| 2673 | 2673 | function valeur_numerique($expr) { |
| 2674 | - $a = 0; |
|
| 2675 | - if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2676 | - eval("\$a = $expr;"); |
|
| 2677 | - } |
|
| 2674 | + $a = 0; |
|
| 2675 | + if (preg_match(',^[0-9]+(\s*[+*-]\s*[0-9]+)*$,S', trim($expr))) { |
|
| 2676 | + eval("\$a = $expr;"); |
|
| 2677 | + } |
|
| 2678 | 2678 | |
| 2679 | - return intval($a); |
|
| 2679 | + return intval($a); |
|
| 2680 | 2680 | } |
| 2681 | 2681 | |
| 2682 | 2682 | /** |
@@ -2695,7 +2695,7 @@ discard block |
||
| 2695 | 2695 | * Retourne `$a*$b/$c` |
| 2696 | 2696 | **/ |
| 2697 | 2697 | function regledetrois($a, $b, $c) { |
| 2698 | - return round($a * $b / $c); |
|
| 2698 | + return round($a * $b / $c); |
|
| 2699 | 2699 | } |
| 2700 | 2700 | |
| 2701 | 2701 | |
@@ -2719,77 +2719,77 @@ discard block |
||
| 2719 | 2719 | **/ |
| 2720 | 2720 | function form_hidden($action) { |
| 2721 | 2721 | |
| 2722 | - $contexte = []; |
|
| 2723 | - include_spip('inc/urls'); |
|
| 2724 | - if ( |
|
| 2725 | - $p = urls_decoder_url($action, '') |
|
| 2726 | - and reset($p) |
|
| 2727 | - ) { |
|
| 2728 | - $fond = array_shift($p); |
|
| 2729 | - if ($fond != '404') { |
|
| 2730 | - $contexte = array_shift($p); |
|
| 2731 | - $contexte['page'] = $fond; |
|
| 2732 | - $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2733 | - } |
|
| 2734 | - } |
|
| 2735 | - // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2736 | - if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2737 | - unset($contexte['type']); |
|
| 2738 | - } |
|
| 2739 | - if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2740 | - unset($contexte['type-page']); |
|
| 2741 | - } |
|
| 2742 | - |
|
| 2743 | - // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2744 | - // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2745 | - $values = []; |
|
| 2746 | - |
|
| 2747 | - // d'abord avec celles de l'url |
|
| 2748 | - if (false !== ($p = strpos($action, '?'))) { |
|
| 2749 | - foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2750 | - $c = explode('=', $c, 2); |
|
| 2751 | - $var = array_shift($c); |
|
| 2752 | - $val = array_shift($c); |
|
| 2753 | - if ($var) { |
|
| 2754 | - $val = rawurldecode($val); |
|
| 2755 | - $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2756 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2757 | - $values[] = [$var, $val]; |
|
| 2758 | - } else { |
|
| 2759 | - if (!isset($values[$var])) { |
|
| 2760 | - $values[$var] = [$var, $val]; |
|
| 2761 | - } |
|
| 2762 | - } |
|
| 2763 | - } |
|
| 2764 | - } |
|
| 2765 | - } |
|
| 2766 | - |
|
| 2767 | - // ensuite avec celles du contexte, sans doublonner ! |
|
| 2768 | - foreach ($contexte as $var => $val) { |
|
| 2769 | - if (preg_match(',\[\]$,S', $var)) { |
|
| 2770 | - $values[] = [$var, $val]; |
|
| 2771 | - } else { |
|
| 2772 | - if (!isset($values[$var])) { |
|
| 2773 | - $values[$var] = [$var, $val]; |
|
| 2774 | - } |
|
| 2775 | - } |
|
| 2776 | - } |
|
| 2777 | - |
|
| 2778 | - // puis on rassemble le tout |
|
| 2779 | - $hidden = []; |
|
| 2780 | - foreach ($values as $value) { |
|
| 2781 | - list($var, $val) = $value; |
|
| 2782 | - $hidden[] = '<input name="' |
|
| 2783 | - . entites_html($var) |
|
| 2784 | - . '"' |
|
| 2785 | - . (is_null($val) |
|
| 2786 | - ? '' |
|
| 2787 | - : ' value="' . entites_html($val) . '"' |
|
| 2788 | - ) |
|
| 2789 | - . ' type="hidden"' . "\n/>"; |
|
| 2790 | - } |
|
| 2791 | - |
|
| 2792 | - return join('', $hidden); |
|
| 2722 | + $contexte = []; |
|
| 2723 | + include_spip('inc/urls'); |
|
| 2724 | + if ( |
|
| 2725 | + $p = urls_decoder_url($action, '') |
|
| 2726 | + and reset($p) |
|
| 2727 | + ) { |
|
| 2728 | + $fond = array_shift($p); |
|
| 2729 | + if ($fond != '404') { |
|
| 2730 | + $contexte = array_shift($p); |
|
| 2731 | + $contexte['page'] = $fond; |
|
| 2732 | + $action = preg_replace('/([?]' . preg_quote($fond) . '[^&=]*[0-9]+)(&|$)/', '?&', $action); |
|
| 2733 | + } |
|
| 2734 | + } |
|
| 2735 | + // defaire ce qu'a injecte urls_decoder_url : a revoir en modifiant la signature de urls_decoder_url |
|
| 2736 | + if (defined('_DEFINIR_CONTEXTE_TYPE') and _DEFINIR_CONTEXTE_TYPE) { |
|
| 2737 | + unset($contexte['type']); |
|
| 2738 | + } |
|
| 2739 | + if (!defined('_DEFINIR_CONTEXTE_TYPE_PAGE') or _DEFINIR_CONTEXTE_TYPE_PAGE) { |
|
| 2740 | + unset($contexte['type-page']); |
|
| 2741 | + } |
|
| 2742 | + |
|
| 2743 | + // on va remplir un tableau de valeurs en prenant bien soin de ne pas |
|
| 2744 | + // ecraser les elements de la forme mots[]=1&mots[]=2 |
|
| 2745 | + $values = []; |
|
| 2746 | + |
|
| 2747 | + // d'abord avec celles de l'url |
|
| 2748 | + if (false !== ($p = strpos($action, '?'))) { |
|
| 2749 | + foreach (preg_split('/&(amp;)?/S', substr($action, $p + 1)) as $c) { |
|
| 2750 | + $c = explode('=', $c, 2); |
|
| 2751 | + $var = array_shift($c); |
|
| 2752 | + $val = array_shift($c); |
|
| 2753 | + if ($var) { |
|
| 2754 | + $val = rawurldecode($val); |
|
| 2755 | + $var = rawurldecode($var); // decoder les [] eventuels |
|
| 2756 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2757 | + $values[] = [$var, $val]; |
|
| 2758 | + } else { |
|
| 2759 | + if (!isset($values[$var])) { |
|
| 2760 | + $values[$var] = [$var, $val]; |
|
| 2761 | + } |
|
| 2762 | + } |
|
| 2763 | + } |
|
| 2764 | + } |
|
| 2765 | + } |
|
| 2766 | + |
|
| 2767 | + // ensuite avec celles du contexte, sans doublonner ! |
|
| 2768 | + foreach ($contexte as $var => $val) { |
|
| 2769 | + if (preg_match(',\[\]$,S', $var)) { |
|
| 2770 | + $values[] = [$var, $val]; |
|
| 2771 | + } else { |
|
| 2772 | + if (!isset($values[$var])) { |
|
| 2773 | + $values[$var] = [$var, $val]; |
|
| 2774 | + } |
|
| 2775 | + } |
|
| 2776 | + } |
|
| 2777 | + |
|
| 2778 | + // puis on rassemble le tout |
|
| 2779 | + $hidden = []; |
|
| 2780 | + foreach ($values as $value) { |
|
| 2781 | + list($var, $val) = $value; |
|
| 2782 | + $hidden[] = '<input name="' |
|
| 2783 | + . entites_html($var) |
|
| 2784 | + . '"' |
|
| 2785 | + . (is_null($val) |
|
| 2786 | + ? '' |
|
| 2787 | + : ' value="' . entites_html($val) . '"' |
|
| 2788 | + ) |
|
| 2789 | + . ' type="hidden"' . "\n/>"; |
|
| 2790 | + } |
|
| 2791 | + |
|
| 2792 | + return join('', $hidden); |
|
| 2793 | 2793 | } |
| 2794 | 2794 | |
| 2795 | 2795 | |
@@ -2811,7 +2811,7 @@ discard block |
||
| 2811 | 2811 | * - la première valeur du tableau sinon. |
| 2812 | 2812 | **/ |
| 2813 | 2813 | function filtre_reset($array) { |
| 2814 | - return !is_array($array) ? null : reset($array); |
|
| 2814 | + return !is_array($array) ? null : reset($array); |
|
| 2815 | 2815 | } |
| 2816 | 2816 | |
| 2817 | 2817 | /** |
@@ -2832,7 +2832,7 @@ discard block |
||
| 2832 | 2832 | * - la dernière valeur du tableau sinon. |
| 2833 | 2833 | **/ |
| 2834 | 2834 | function filtre_end($array) { |
| 2835 | - return !is_array($array) ? null : end($array); |
|
| 2835 | + return !is_array($array) ? null : end($array); |
|
| 2836 | 2836 | } |
| 2837 | 2837 | |
| 2838 | 2838 | /** |
@@ -2852,11 +2852,11 @@ discard block |
||
| 2852 | 2852 | * |
| 2853 | 2853 | **/ |
| 2854 | 2854 | function filtre_push($array, $val) { |
| 2855 | - if (!is_array($array) or !array_push($array, $val)) { |
|
| 2856 | - return ''; |
|
| 2857 | - } |
|
| 2855 | + if (!is_array($array) or !array_push($array, $val)) { |
|
| 2856 | + return ''; |
|
| 2857 | + } |
|
| 2858 | 2858 | |
| 2859 | - return $array; |
|
| 2859 | + return $array; |
|
| 2860 | 2860 | } |
| 2861 | 2861 | |
| 2862 | 2862 | /** |
@@ -2875,7 +2875,7 @@ discard block |
||
| 2875 | 2875 | * - `true` si la valeur existe dans le tableau, `false` sinon. |
| 2876 | 2876 | **/ |
| 2877 | 2877 | function filtre_find($array, $val) { |
| 2878 | - return (is_array($array) and in_array($val, $array)); |
|
| 2878 | + return (is_array($array) and in_array($val, $array)); |
|
| 2879 | 2879 | } |
| 2880 | 2880 | |
| 2881 | 2881 | |
@@ -2892,15 +2892,15 @@ discard block |
||
| 2892 | 2892 | * Contenu avec urls en absolus |
| 2893 | 2893 | **/ |
| 2894 | 2894 | function urls_absolues_css($contenu, $source) { |
| 2895 | - $path = suivre_lien(url_absolue($source), './'); |
|
| 2895 | + $path = suivre_lien(url_absolue($source), './'); |
|
| 2896 | 2896 | |
| 2897 | - return preg_replace_callback( |
|
| 2898 | - ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2899 | - function ($x) use ($path) { |
|
| 2900 | - return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2901 | - }, |
|
| 2902 | - $contenu |
|
| 2903 | - ); |
|
| 2897 | + return preg_replace_callback( |
|
| 2898 | + ",url\s*\(\s*['\"]?([^'\"/#\s][^:]*)['\"]?\s*\),Uims", |
|
| 2899 | + function ($x) use ($path) { |
|
| 2900 | + return "url('" . suivre_lien($path, $x[1]) . "')"; |
|
| 2901 | + }, |
|
| 2902 | + $contenu |
|
| 2903 | + ); |
|
| 2904 | 2904 | } |
| 2905 | 2905 | |
| 2906 | 2906 | |
@@ -2929,119 +2929,119 @@ discard block |
||
| 2929 | 2929 | * Chemin du fichier CSS inversé |
| 2930 | 2930 | **/ |
| 2931 | 2931 | function direction_css($css, $voulue = '') { |
| 2932 | - if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2933 | - return $css; |
|
| 2934 | - } |
|
| 2935 | - include_spip('inc/lang'); |
|
| 2936 | - // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2937 | - if ($voulue = strtolower($voulue)) { |
|
| 2938 | - if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2939 | - $voulue = lang_dir($voulue); |
|
| 2940 | - } |
|
| 2941 | - } else { |
|
| 2942 | - $voulue = lang_dir(); |
|
| 2943 | - } |
|
| 2944 | - |
|
| 2945 | - $r = count($r) > 1; |
|
| 2946 | - $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2947 | - $dir = $r ? 'rtl' : 'ltr'; |
|
| 2948 | - $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2949 | - |
|
| 2950 | - if ($voulue == $dir) { |
|
| 2951 | - return $css; |
|
| 2952 | - } |
|
| 2953 | - |
|
| 2954 | - if ( |
|
| 2955 | - // url absolue |
|
| 2956 | - preg_match(',^https?:,i', $css) |
|
| 2957 | - // ou qui contient un ? |
|
| 2958 | - or (($p = strpos($css, '?')) !== false) |
|
| 2959 | - ) { |
|
| 2960 | - $distant = true; |
|
| 2961 | - $cssf = parse_url($css); |
|
| 2962 | - $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2963 | - $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2964 | - } else { |
|
| 2965 | - $distant = false; |
|
| 2966 | - $cssf = $css; |
|
| 2967 | - // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2968 | - //propose (rien a faire dans ce cas) |
|
| 2969 | - $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2970 | - if (@file_exists($f)) { |
|
| 2971 | - return $f; |
|
| 2972 | - } |
|
| 2973 | - } |
|
| 2974 | - |
|
| 2975 | - // 2. |
|
| 2976 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2977 | - $f = $dir_var |
|
| 2978 | - . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2979 | - . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2980 | - |
|
| 2981 | - // la css peut etre distante (url absolue !) |
|
| 2982 | - if ($distant) { |
|
| 2983 | - include_spip('inc/distant'); |
|
| 2984 | - $res = recuperer_url($css); |
|
| 2985 | - if (!$res or !$contenu = $res['page']) { |
|
| 2986 | - return $css; |
|
| 2987 | - } |
|
| 2988 | - } else { |
|
| 2989 | - if ( |
|
| 2990 | - (@filemtime($f) > @filemtime($css)) |
|
| 2991 | - and (_VAR_MODE != 'recalcul') |
|
| 2992 | - ) { |
|
| 2993 | - return $f; |
|
| 2994 | - } |
|
| 2995 | - if (!lire_fichier($css, $contenu)) { |
|
| 2996 | - return $css; |
|
| 2997 | - } |
|
| 2998 | - } |
|
| 2999 | - |
|
| 3000 | - |
|
| 3001 | - // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3002 | - include_spip('lib/csstidy/class.csstidy'); |
|
| 3003 | - $parser = new csstidy(); |
|
| 3004 | - $parser->set_cfg('optimise_shorthands', 0); |
|
| 3005 | - $parser->set_cfg('reverse_left_and_right', true); |
|
| 3006 | - $parser->parse($contenu); |
|
| 3007 | - |
|
| 3008 | - $contenu = $parser->print->plain(); |
|
| 3009 | - |
|
| 3010 | - |
|
| 3011 | - // reperer les @import auxquels il faut propager le direction_css |
|
| 3012 | - preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3013 | - $src = []; |
|
| 3014 | - $src_direction_css = []; |
|
| 3015 | - $src_faux_abs = []; |
|
| 3016 | - $d = dirname($css); |
|
| 3017 | - foreach ($regs[1] as $k => $import_css) { |
|
| 3018 | - $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3019 | - // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3020 | - if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3021 | - $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3022 | - } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3023 | - elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3024 | - $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3025 | - $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3026 | - $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3027 | - } |
|
| 3028 | - $src[] = $regs[0][$k]; |
|
| 3029 | - $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3030 | - } |
|
| 3031 | - $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3032 | - |
|
| 3033 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3034 | - |
|
| 3035 | - // virer les fausses url absolues que l'on a mis dans les import |
|
| 3036 | - if (count($src_faux_abs)) { |
|
| 3037 | - $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3038 | - } |
|
| 3039 | - |
|
| 3040 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3041 | - return $css; |
|
| 3042 | - } |
|
| 3043 | - |
|
| 3044 | - return $f; |
|
| 2932 | + if (!preg_match(',(_rtl)?\.css$,i', $css, $r)) { |
|
| 2933 | + return $css; |
|
| 2934 | + } |
|
| 2935 | + include_spip('inc/lang'); |
|
| 2936 | + // si on a precise le sens voulu en argument, le prendre en compte |
|
| 2937 | + if ($voulue = strtolower($voulue)) { |
|
| 2938 | + if ($voulue != 'rtl' and $voulue != 'ltr') { |
|
| 2939 | + $voulue = lang_dir($voulue); |
|
| 2940 | + } |
|
| 2941 | + } else { |
|
| 2942 | + $voulue = lang_dir(); |
|
| 2943 | + } |
|
| 2944 | + |
|
| 2945 | + $r = count($r) > 1; |
|
| 2946 | + $right = $r ? 'left' : 'right'; // 'right' de la css lue en entree |
|
| 2947 | + $dir = $r ? 'rtl' : 'ltr'; |
|
| 2948 | + $ndir = $r ? 'ltr' : 'rtl'; |
|
| 2949 | + |
|
| 2950 | + if ($voulue == $dir) { |
|
| 2951 | + return $css; |
|
| 2952 | + } |
|
| 2953 | + |
|
| 2954 | + if ( |
|
| 2955 | + // url absolue |
|
| 2956 | + preg_match(',^https?:,i', $css) |
|
| 2957 | + // ou qui contient un ? |
|
| 2958 | + or (($p = strpos($css, '?')) !== false) |
|
| 2959 | + ) { |
|
| 2960 | + $distant = true; |
|
| 2961 | + $cssf = parse_url($css); |
|
| 2962 | + $cssf = $cssf['path'] . ($cssf['query'] ? '?' . $cssf['query'] : ''); |
|
| 2963 | + $cssf = preg_replace(',[?:&=],', '_', $cssf); |
|
| 2964 | + } else { |
|
| 2965 | + $distant = false; |
|
| 2966 | + $cssf = $css; |
|
| 2967 | + // 1. regarder d'abord si un fichier avec la bonne direction n'est pas aussi |
|
| 2968 | + //propose (rien a faire dans ce cas) |
|
| 2969 | + $f = preg_replace(',(_rtl)?\.css$,i', '_' . $ndir . '.css', $css); |
|
| 2970 | + if (@file_exists($f)) { |
|
| 2971 | + return $f; |
|
| 2972 | + } |
|
| 2973 | + } |
|
| 2974 | + |
|
| 2975 | + // 2. |
|
| 2976 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-css'); |
|
| 2977 | + $f = $dir_var |
|
| 2978 | + . preg_replace(',.*/(.*?)(_rtl)?\.css,', '\1', $cssf) |
|
| 2979 | + . '.' . substr(md5($cssf), 0, 4) . '_' . $ndir . '.css'; |
|
| 2980 | + |
|
| 2981 | + // la css peut etre distante (url absolue !) |
|
| 2982 | + if ($distant) { |
|
| 2983 | + include_spip('inc/distant'); |
|
| 2984 | + $res = recuperer_url($css); |
|
| 2985 | + if (!$res or !$contenu = $res['page']) { |
|
| 2986 | + return $css; |
|
| 2987 | + } |
|
| 2988 | + } else { |
|
| 2989 | + if ( |
|
| 2990 | + (@filemtime($f) > @filemtime($css)) |
|
| 2991 | + and (_VAR_MODE != 'recalcul') |
|
| 2992 | + ) { |
|
| 2993 | + return $f; |
|
| 2994 | + } |
|
| 2995 | + if (!lire_fichier($css, $contenu)) { |
|
| 2996 | + return $css; |
|
| 2997 | + } |
|
| 2998 | + } |
|
| 2999 | + |
|
| 3000 | + |
|
| 3001 | + // Inverser la direction gauche-droite en utilisant CSSTidy qui gere aussi les shorthands |
|
| 3002 | + include_spip('lib/csstidy/class.csstidy'); |
|
| 3003 | + $parser = new csstidy(); |
|
| 3004 | + $parser->set_cfg('optimise_shorthands', 0); |
|
| 3005 | + $parser->set_cfg('reverse_left_and_right', true); |
|
| 3006 | + $parser->parse($contenu); |
|
| 3007 | + |
|
| 3008 | + $contenu = $parser->print->plain(); |
|
| 3009 | + |
|
| 3010 | + |
|
| 3011 | + // reperer les @import auxquels il faut propager le direction_css |
|
| 3012 | + preg_match_all(",\@import\s*url\s*\(\s*['\"]?([^'\"/][^:]*)['\"]?\s*\),Uims", $contenu, $regs); |
|
| 3013 | + $src = []; |
|
| 3014 | + $src_direction_css = []; |
|
| 3015 | + $src_faux_abs = []; |
|
| 3016 | + $d = dirname($css); |
|
| 3017 | + foreach ($regs[1] as $k => $import_css) { |
|
| 3018 | + $css_direction = direction_css("$d/$import_css", $voulue); |
|
| 3019 | + // si la css_direction est dans le meme path que la css d'origine, on tronque le path, elle sera passee en absolue |
|
| 3020 | + if (substr($css_direction, 0, strlen($d) + 1) == "$d/") { |
|
| 3021 | + $css_direction = substr($css_direction, strlen($d) + 1); |
|
| 3022 | + } // si la css_direction commence par $dir_var on la fait passer pour une absolue |
|
| 3023 | + elseif (substr($css_direction, 0, strlen($dir_var)) == $dir_var) { |
|
| 3024 | + $css_direction = substr($css_direction, strlen($dir_var)); |
|
| 3025 | + $src_faux_abs['/@@@@@@/' . $css_direction] = $css_direction; |
|
| 3026 | + $css_direction = '/@@@@@@/' . $css_direction; |
|
| 3027 | + } |
|
| 3028 | + $src[] = $regs[0][$k]; |
|
| 3029 | + $src_direction_css[] = str_replace($import_css, $css_direction, $regs[0][$k]); |
|
| 3030 | + } |
|
| 3031 | + $contenu = str_replace($src, $src_direction_css, $contenu); |
|
| 3032 | + |
|
| 3033 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3034 | + |
|
| 3035 | + // virer les fausses url absolues que l'on a mis dans les import |
|
| 3036 | + if (count($src_faux_abs)) { |
|
| 3037 | + $contenu = str_replace(array_keys($src_faux_abs), $src_faux_abs, $contenu); |
|
| 3038 | + } |
|
| 3039 | + |
|
| 3040 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3041 | + return $css; |
|
| 3042 | + } |
|
| 3043 | + |
|
| 3044 | + return $f; |
|
| 3045 | 3045 | } |
| 3046 | 3046 | |
| 3047 | 3047 | |
@@ -3064,46 +3064,46 @@ discard block |
||
| 3064 | 3064 | * - Chemin ou URL du fichier CSS source sinon. |
| 3065 | 3065 | **/ |
| 3066 | 3066 | function url_absolue_css($css) { |
| 3067 | - if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3068 | - return $css; |
|
| 3069 | - } |
|
| 3067 | + if (!preg_match(',\.css$,i', $css, $r)) { |
|
| 3068 | + return $css; |
|
| 3069 | + } |
|
| 3070 | 3070 | |
| 3071 | - $url_absolue_css = url_absolue($css); |
|
| 3071 | + $url_absolue_css = url_absolue($css); |
|
| 3072 | 3072 | |
| 3073 | - $f = basename($css, '.css'); |
|
| 3074 | - $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3075 | - . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3076 | - . '.css'; |
|
| 3073 | + $f = basename($css, '.css'); |
|
| 3074 | + $f = sous_repertoire(_DIR_VAR, 'cache-css') |
|
| 3075 | + . preg_replace(',(.*?)(_rtl|_ltr)?$,', "\\1-urlabs-" . substr(md5("$css-urlabs"), 0, 4) . "\\2", $f) |
|
| 3076 | + . '.css'; |
|
| 3077 | 3077 | |
| 3078 | - if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3079 | - return $f; |
|
| 3080 | - } |
|
| 3078 | + if ((@filemtime($f) > @filemtime($css)) and (_VAR_MODE != 'recalcul')) { |
|
| 3079 | + return $f; |
|
| 3080 | + } |
|
| 3081 | 3081 | |
| 3082 | - if ($url_absolue_css == $css) { |
|
| 3083 | - if ( |
|
| 3084 | - strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3085 | - or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3086 | - ) { |
|
| 3087 | - include_spip('inc/distant'); |
|
| 3088 | - $contenu = recuperer_url($css); |
|
| 3089 | - $contenu = $contenu['page'] ?? ''; |
|
| 3090 | - if (!$contenu) { |
|
| 3091 | - return $css; |
|
| 3092 | - } |
|
| 3093 | - } |
|
| 3094 | - } elseif (!lire_fichier($css, $contenu)) { |
|
| 3095 | - return $css; |
|
| 3096 | - } |
|
| 3082 | + if ($url_absolue_css == $css) { |
|
| 3083 | + if ( |
|
| 3084 | + strncmp($GLOBALS['meta']['adresse_site'], $css, $l = strlen($GLOBALS['meta']['adresse_site'])) != 0 |
|
| 3085 | + or !lire_fichier(_DIR_RACINE . substr($css, $l), $contenu) |
|
| 3086 | + ) { |
|
| 3087 | + include_spip('inc/distant'); |
|
| 3088 | + $contenu = recuperer_url($css); |
|
| 3089 | + $contenu = $contenu['page'] ?? ''; |
|
| 3090 | + if (!$contenu) { |
|
| 3091 | + return $css; |
|
| 3092 | + } |
|
| 3093 | + } |
|
| 3094 | + } elseif (!lire_fichier($css, $contenu)) { |
|
| 3095 | + return $css; |
|
| 3096 | + } |
|
| 3097 | 3097 | |
| 3098 | - // passer les url relatives a la css d'origine en url absolues |
|
| 3099 | - $contenu = urls_absolues_css($contenu, $css); |
|
| 3098 | + // passer les url relatives a la css d'origine en url absolues |
|
| 3099 | + $contenu = urls_absolues_css($contenu, $css); |
|
| 3100 | 3100 | |
| 3101 | - // ecrire la css |
|
| 3102 | - if (!ecrire_fichier($f, $contenu)) { |
|
| 3103 | - return $css; |
|
| 3104 | - } |
|
| 3101 | + // ecrire la css |
|
| 3102 | + if (!ecrire_fichier($f, $contenu)) { |
|
| 3103 | + return $css; |
|
| 3104 | + } |
|
| 3105 | 3105 | |
| 3106 | - return $f; |
|
| 3106 | + return $f; |
|
| 3107 | 3107 | } |
| 3108 | 3108 | |
| 3109 | 3109 | |
@@ -3137,24 +3137,24 @@ discard block |
||
| 3137 | 3137 | * Valeur trouvée ou valeur par défaut. |
| 3138 | 3138 | **/ |
| 3139 | 3139 | function table_valeur($table, $cle, $defaut = '', $conserver_null = false) { |
| 3140 | - foreach (explode('/', $cle) as $k) { |
|
| 3141 | - $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3140 | + foreach (explode('/', $cle) as $k) { |
|
| 3141 | + $table = (is_string($table) ? @unserialize($table) : $table); |
|
| 3142 | 3142 | |
| 3143 | - if (is_object($table)) { |
|
| 3144 | - $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3145 | - } elseif (is_array($table)) { |
|
| 3146 | - if ($conserver_null) { |
|
| 3147 | - $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3148 | - } else { |
|
| 3149 | - $table = ($table[$k] ?? $defaut); |
|
| 3150 | - } |
|
| 3151 | - } else { |
|
| 3152 | - $table = $defaut; |
|
| 3153 | - break; |
|
| 3154 | - } |
|
| 3155 | - } |
|
| 3143 | + if (is_object($table)) { |
|
| 3144 | + $table = (($k !== '') and isset($table->$k)) ? $table->$k : $defaut; |
|
| 3145 | + } elseif (is_array($table)) { |
|
| 3146 | + if ($conserver_null) { |
|
| 3147 | + $table = array_key_exists($k, $table) ? $table[$k] : $defaut; |
|
| 3148 | + } else { |
|
| 3149 | + $table = ($table[$k] ?? $defaut); |
|
| 3150 | + } |
|
| 3151 | + } else { |
|
| 3152 | + $table = $defaut; |
|
| 3153 | + break; |
|
| 3154 | + } |
|
| 3155 | + } |
|
| 3156 | 3156 | |
| 3157 | - return $table; |
|
| 3157 | + return $table; |
|
| 3158 | 3158 | } |
| 3159 | 3159 | |
| 3160 | 3160 | /** |
@@ -3187,22 +3187,22 @@ discard block |
||
| 3187 | 3187 | * - string : expression trouvée. |
| 3188 | 3188 | **/ |
| 3189 | 3189 | function filtre_match_dist($texte, $expression, $modif = 'UimsS', $capte = 0) { |
| 3190 | - if (intval($modif) and $capte == 0) { |
|
| 3191 | - $capte = $modif; |
|
| 3192 | - $modif = 'UimsS'; |
|
| 3193 | - } |
|
| 3194 | - $expression = str_replace('\/', '/', $expression); |
|
| 3195 | - $expression = str_replace('/', '\/', $expression); |
|
| 3190 | + if (intval($modif) and $capte == 0) { |
|
| 3191 | + $capte = $modif; |
|
| 3192 | + $modif = 'UimsS'; |
|
| 3193 | + } |
|
| 3194 | + $expression = str_replace('\/', '/', $expression); |
|
| 3195 | + $expression = str_replace('/', '\/', $expression); |
|
| 3196 | 3196 | |
| 3197 | - if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3198 | - if (isset($r[$capte])) { |
|
| 3199 | - return $r[$capte]; |
|
| 3200 | - } else { |
|
| 3201 | - return true; |
|
| 3202 | - } |
|
| 3203 | - } |
|
| 3197 | + if (preg_match('/' . $expression . '/' . $modif, $texte, $r)) { |
|
| 3198 | + if (isset($r[$capte])) { |
|
| 3199 | + return $r[$capte]; |
|
| 3200 | + } else { |
|
| 3201 | + return true; |
|
| 3202 | + } |
|
| 3203 | + } |
|
| 3204 | 3204 | |
| 3205 | - return false; |
|
| 3205 | + return false; |
|
| 3206 | 3206 | } |
| 3207 | 3207 | |
| 3208 | 3208 | |
@@ -3229,10 +3229,10 @@ discard block |
||
| 3229 | 3229 | * Texte |
| 3230 | 3230 | **/ |
| 3231 | 3231 | function replace($texte, $expression, $replace = '', $modif = 'UimsS') { |
| 3232 | - $expression = str_replace('\/', '/', $expression); |
|
| 3233 | - $expression = str_replace('/', '\/', $expression); |
|
| 3232 | + $expression = str_replace('\/', '/', $expression); |
|
| 3233 | + $expression = str_replace('/', '\/', $expression); |
|
| 3234 | 3234 | |
| 3235 | - return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3235 | + return preg_replace('/' . $expression . '/' . $modif, $replace, $texte); |
|
| 3236 | 3236 | } |
| 3237 | 3237 | |
| 3238 | 3238 | |
@@ -3250,25 +3250,25 @@ discard block |
||
| 3250 | 3250 | **/ |
| 3251 | 3251 | function traiter_doublons_documents(&$doublons, $letexte) { |
| 3252 | 3252 | |
| 3253 | - // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3254 | - $t = $letexte . $GLOBALS['les_notes']; |
|
| 3253 | + // Verifier dans le texte & les notes (pas beau, helas) |
|
| 3254 | + $t = $letexte . $GLOBALS['les_notes']; |
|
| 3255 | 3255 | |
| 3256 | - if ( |
|
| 3257 | - strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3258 | - and preg_match_all( |
|
| 3259 | - ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3260 | - $t, |
|
| 3261 | - $matches, |
|
| 3262 | - PREG_PATTERN_ORDER |
|
| 3263 | - ) |
|
| 3264 | - ) { |
|
| 3265 | - if (!isset($doublons['documents'])) { |
|
| 3266 | - $doublons['documents'] = ''; |
|
| 3267 | - } |
|
| 3268 | - $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3269 | - } |
|
| 3256 | + if ( |
|
| 3257 | + strstr($t, 'spip_document_') // evite le preg_match_all si inutile |
|
| 3258 | + and preg_match_all( |
|
| 3259 | + ',<[^>]+\sclass=["\']spip_document_([0-9]+)[\s"\'],imsS', |
|
| 3260 | + $t, |
|
| 3261 | + $matches, |
|
| 3262 | + PREG_PATTERN_ORDER |
|
| 3263 | + ) |
|
| 3264 | + ) { |
|
| 3265 | + if (!isset($doublons['documents'])) { |
|
| 3266 | + $doublons['documents'] = ''; |
|
| 3267 | + } |
|
| 3268 | + $doublons['documents'] .= ',' . join(',', $matches[1]); |
|
| 3269 | + } |
|
| 3270 | 3270 | |
| 3271 | - return $letexte; |
|
| 3271 | + return $letexte; |
|
| 3272 | 3272 | } |
| 3273 | 3273 | |
| 3274 | 3274 | /** |
@@ -3282,7 +3282,7 @@ discard block |
||
| 3282 | 3282 | * @return string Chaîne vide |
| 3283 | 3283 | **/ |
| 3284 | 3284 | function vide($texte) { |
| 3285 | - return ''; |
|
| 3285 | + return ''; |
|
| 3286 | 3286 | } |
| 3287 | 3287 | |
| 3288 | 3288 | // |
@@ -3311,23 +3311,23 @@ discard block |
||
| 3311 | 3311 | * Code HTML résultant |
| 3312 | 3312 | **/ |
| 3313 | 3313 | function env_to_params($env, $ignore_params = []) { |
| 3314 | - $ignore_params = array_merge( |
|
| 3315 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3316 | - $ignore_params |
|
| 3317 | - ); |
|
| 3318 | - if (!is_array($env)) { |
|
| 3319 | - $env = unserialize($env); |
|
| 3320 | - } |
|
| 3321 | - $texte = ''; |
|
| 3322 | - if ($env) { |
|
| 3323 | - foreach ($env as $i => $j) { |
|
| 3324 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3325 | - $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3326 | - } |
|
| 3327 | - } |
|
| 3328 | - } |
|
| 3329 | - |
|
| 3330 | - return $texte; |
|
| 3314 | + $ignore_params = array_merge( |
|
| 3315 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3316 | + $ignore_params |
|
| 3317 | + ); |
|
| 3318 | + if (!is_array($env)) { |
|
| 3319 | + $env = unserialize($env); |
|
| 3320 | + } |
|
| 3321 | + $texte = ''; |
|
| 3322 | + if ($env) { |
|
| 3323 | + foreach ($env as $i => $j) { |
|
| 3324 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3325 | + $texte .= "<param name='" . attribut_html($i) . "'\n\tvalue='" . attribut_html($j) . "' />"; |
|
| 3326 | + } |
|
| 3327 | + } |
|
| 3328 | + } |
|
| 3329 | + |
|
| 3330 | + return $texte; |
|
| 3331 | 3331 | } |
| 3332 | 3332 | |
| 3333 | 3333 | /** |
@@ -3350,23 +3350,23 @@ discard block |
||
| 3350 | 3350 | * Code HTML résultant |
| 3351 | 3351 | **/ |
| 3352 | 3352 | function env_to_attributs($env, $ignore_params = []) { |
| 3353 | - $ignore_params = array_merge( |
|
| 3354 | - ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3355 | - $ignore_params |
|
| 3356 | - ); |
|
| 3357 | - if (!is_array($env)) { |
|
| 3358 | - $env = unserialize($env); |
|
| 3359 | - } |
|
| 3360 | - $texte = ''; |
|
| 3361 | - if ($env) { |
|
| 3362 | - foreach ($env as $i => $j) { |
|
| 3363 | - if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3364 | - $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3365 | - } |
|
| 3366 | - } |
|
| 3367 | - } |
|
| 3353 | + $ignore_params = array_merge( |
|
| 3354 | + ['id', 'lang', 'id_document', 'date', 'date_redac', 'align', 'fond', '', 'recurs', 'emb', 'dir_racine'], |
|
| 3355 | + $ignore_params |
|
| 3356 | + ); |
|
| 3357 | + if (!is_array($env)) { |
|
| 3358 | + $env = unserialize($env); |
|
| 3359 | + } |
|
| 3360 | + $texte = ''; |
|
| 3361 | + if ($env) { |
|
| 3362 | + foreach ($env as $i => $j) { |
|
| 3363 | + if (is_string($j) and !in_array($i, $ignore_params)) { |
|
| 3364 | + $texte .= attribut_html($i) . "='" . attribut_html($j) . "' "; |
|
| 3365 | + } |
|
| 3366 | + } |
|
| 3367 | + } |
|
| 3368 | 3368 | |
| 3369 | - return $texte; |
|
| 3369 | + return $texte; |
|
| 3370 | 3370 | } |
| 3371 | 3371 | |
| 3372 | 3372 | |
@@ -3384,7 +3384,7 @@ discard block |
||
| 3384 | 3384 | * @return string Chaînes concaténés |
| 3385 | 3385 | **/ |
| 3386 | 3386 | function concat(...$args): string { |
| 3387 | - return join('', $args); |
|
| 3387 | + return join('', $args); |
|
| 3388 | 3388 | } |
| 3389 | 3389 | |
| 3390 | 3390 | |
@@ -3404,23 +3404,23 @@ discard block |
||
| 3404 | 3404 | * Contenu du ou des fichiers, concaténé |
| 3405 | 3405 | **/ |
| 3406 | 3406 | function charge_scripts($files, $script = true) { |
| 3407 | - $flux = ''; |
|
| 3408 | - foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3409 | - if (!is_string($file)) { |
|
| 3410 | - continue; |
|
| 3411 | - } |
|
| 3412 | - if ($script) { |
|
| 3413 | - $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3414 | - } |
|
| 3415 | - if ($file) { |
|
| 3416 | - $path = find_in_path($file); |
|
| 3417 | - if ($path) { |
|
| 3418 | - $flux .= spip_file_get_contents($path); |
|
| 3419 | - } |
|
| 3420 | - } |
|
| 3421 | - } |
|
| 3422 | - |
|
| 3423 | - return $flux; |
|
| 3407 | + $flux = ''; |
|
| 3408 | + foreach (is_array($files) ? $files : explode('|', $files) as $file) { |
|
| 3409 | + if (!is_string($file)) { |
|
| 3410 | + continue; |
|
| 3411 | + } |
|
| 3412 | + if ($script) { |
|
| 3413 | + $file = preg_match(',^\w+$,', $file) ? "javascript/$file.js" : ''; |
|
| 3414 | + } |
|
| 3415 | + if ($file) { |
|
| 3416 | + $path = find_in_path($file); |
|
| 3417 | + if ($path) { |
|
| 3418 | + $flux .= spip_file_get_contents($path); |
|
| 3419 | + } |
|
| 3420 | + } |
|
| 3421 | + } |
|
| 3422 | + |
|
| 3423 | + return $flux; |
|
| 3424 | 3424 | } |
| 3425 | 3425 | |
| 3426 | 3426 | /** |
@@ -3431,22 +3431,22 @@ discard block |
||
| 3431 | 3431 | * @return string |
| 3432 | 3432 | */ |
| 3433 | 3433 | function http_img_variante_svg_si_possible($img_file) { |
| 3434 | - // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3435 | - // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3436 | - if ( |
|
| 3437 | - preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3438 | - and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3439 | - and file_exists($variante_svg_generique) |
|
| 3440 | - ) { |
|
| 3441 | - if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3442 | - $img_file = $variante_svg_size; |
|
| 3443 | - } |
|
| 3444 | - else { |
|
| 3445 | - $img_file = $variante_svg_generique; |
|
| 3446 | - } |
|
| 3447 | - } |
|
| 3434 | + // on peut fournir une icone generique -xx.svg qui fera le job dans toutes les tailles, et qui est prioritaire sur le png |
|
| 3435 | + // si il y a un .svg a la bonne taille (-16.svg) a cote, on l'utilise en remplacement du -16.png |
|
| 3436 | + if ( |
|
| 3437 | + preg_match(',-(\d+)[.](png|gif|svg)$,', $img_file, $m) |
|
| 3438 | + and $variante_svg_generique = substr($img_file, 0, -strlen($m[0])) . '-xx.svg' |
|
| 3439 | + and file_exists($variante_svg_generique) |
|
| 3440 | + ) { |
|
| 3441 | + if ($variante_svg_size = substr($variante_svg_generique, 0, -6) . $m[1] . '.svg' and file_exists($variante_svg_size)) { |
|
| 3442 | + $img_file = $variante_svg_size; |
|
| 3443 | + } |
|
| 3444 | + else { |
|
| 3445 | + $img_file = $variante_svg_generique; |
|
| 3446 | + } |
|
| 3447 | + } |
|
| 3448 | 3448 | |
| 3449 | - return $img_file; |
|
| 3449 | + return $img_file; |
|
| 3450 | 3450 | } |
| 3451 | 3451 | |
| 3452 | 3452 | /** |
@@ -3467,54 +3467,54 @@ discard block |
||
| 3467 | 3467 | */ |
| 3468 | 3468 | function http_img_pack($img, $alt, $atts = '', $title = '', $options = []) { |
| 3469 | 3469 | |
| 3470 | - $img_file = $img; |
|
| 3471 | - if ($p = strpos($img_file, '?')) { |
|
| 3472 | - $img_file = substr($img_file, 0, $p); |
|
| 3473 | - } |
|
| 3474 | - if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3475 | - $img_file = chemin_image($img); |
|
| 3476 | - } |
|
| 3477 | - else { |
|
| 3478 | - if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3479 | - $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3480 | - } |
|
| 3481 | - } |
|
| 3482 | - if (stripos($atts, 'width') === false) { |
|
| 3483 | - // utiliser directement l'info de taille presente dans le nom |
|
| 3484 | - if ( |
|
| 3485 | - (!isset($options['utiliser_suffixe_size']) |
|
| 3486 | - or $options['utiliser_suffixe_size'] == true |
|
| 3487 | - or strpos($img_file, '-xx.svg') !== false) |
|
| 3488 | - and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3489 | - or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3490 | - ) { |
|
| 3491 | - $largeur = $hauteur = intval($regs[1]); |
|
| 3492 | - } else { |
|
| 3493 | - $taille = taille_image($img_file); |
|
| 3494 | - list($hauteur, $largeur) = $taille; |
|
| 3495 | - if (!$hauteur or !$largeur) { |
|
| 3496 | - return ''; |
|
| 3497 | - } |
|
| 3498 | - } |
|
| 3499 | - $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3500 | - } |
|
| 3501 | - |
|
| 3502 | - if (file_exists($img_file)) { |
|
| 3503 | - $img_file = timestamp($img_file); |
|
| 3504 | - } |
|
| 3505 | - if ($alt === false) { |
|
| 3506 | - $alt = ''; |
|
| 3507 | - } |
|
| 3508 | - elseif ($alt or $alt === '') { |
|
| 3509 | - $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3510 | - } |
|
| 3511 | - else { |
|
| 3512 | - $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3513 | - } |
|
| 3514 | - return "<img src='$img_file'$alt" |
|
| 3515 | - . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3516 | - . ' ' . ltrim($atts) |
|
| 3517 | - . ' />'; |
|
| 3470 | + $img_file = $img; |
|
| 3471 | + if ($p = strpos($img_file, '?')) { |
|
| 3472 | + $img_file = substr($img_file, 0, $p); |
|
| 3473 | + } |
|
| 3474 | + if (!isset($options['chemin_image']) or $options['chemin_image'] == true) { |
|
| 3475 | + $img_file = chemin_image($img); |
|
| 3476 | + } |
|
| 3477 | + else { |
|
| 3478 | + if (!isset($options['variante_svg_si_possible']) or $options['variante_svg_si_possible'] == true) { |
|
| 3479 | + $img_file = http_img_variante_svg_si_possible($img_file); |
|
| 3480 | + } |
|
| 3481 | + } |
|
| 3482 | + if (stripos($atts, 'width') === false) { |
|
| 3483 | + // utiliser directement l'info de taille presente dans le nom |
|
| 3484 | + if ( |
|
| 3485 | + (!isset($options['utiliser_suffixe_size']) |
|
| 3486 | + or $options['utiliser_suffixe_size'] == true |
|
| 3487 | + or strpos($img_file, '-xx.svg') !== false) |
|
| 3488 | + and (preg_match(',-([0-9]+)[.](png|gif|svg)$,', $img, $regs) |
|
| 3489 | + or preg_match(',\?([0-9]+)px$,', $img, $regs)) |
|
| 3490 | + ) { |
|
| 3491 | + $largeur = $hauteur = intval($regs[1]); |
|
| 3492 | + } else { |
|
| 3493 | + $taille = taille_image($img_file); |
|
| 3494 | + list($hauteur, $largeur) = $taille; |
|
| 3495 | + if (!$hauteur or !$largeur) { |
|
| 3496 | + return ''; |
|
| 3497 | + } |
|
| 3498 | + } |
|
| 3499 | + $atts .= " width='" . $largeur . "' height='" . $hauteur . "'"; |
|
| 3500 | + } |
|
| 3501 | + |
|
| 3502 | + if (file_exists($img_file)) { |
|
| 3503 | + $img_file = timestamp($img_file); |
|
| 3504 | + } |
|
| 3505 | + if ($alt === false) { |
|
| 3506 | + $alt = ''; |
|
| 3507 | + } |
|
| 3508 | + elseif ($alt or $alt === '') { |
|
| 3509 | + $alt = " alt='" . attribut_html($alt) . "'"; |
|
| 3510 | + } |
|
| 3511 | + else { |
|
| 3512 | + $alt = " alt='" . attribut_html($title) . "'"; |
|
| 3513 | + } |
|
| 3514 | + return "<img src='$img_file'$alt" |
|
| 3515 | + . ($title ? ' title="' . attribut_html($title) . '"' : '') |
|
| 3516 | + . ' ' . ltrim($atts) |
|
| 3517 | + . ' />'; |
|
| 3518 | 3518 | } |
| 3519 | 3519 | |
| 3520 | 3520 | /** |
@@ -3526,70 +3526,70 @@ discard block |
||
| 3526 | 3526 | * @return string |
| 3527 | 3527 | */ |
| 3528 | 3528 | function http_style_background($img, $att = '', $size = null) { |
| 3529 | - if ($size and is_numeric($size)) { |
|
| 3530 | - $size = trim($size) . 'px'; |
|
| 3531 | - } |
|
| 3532 | - return " style='background" . |
|
| 3533 | - ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3534 | - . ($size ? "background-size:{$size};" : '') |
|
| 3535 | - . "'"; |
|
| 3529 | + if ($size and is_numeric($size)) { |
|
| 3530 | + $size = trim($size) . 'px'; |
|
| 3531 | + } |
|
| 3532 | + return " style='background" . |
|
| 3533 | + ($att ? '' : '-image') . ': url("' . chemin_image($img) . '")' . ($att ? (' ' . $att) : '') . ';' |
|
| 3534 | + . ($size ? "background-size:{$size};" : '') |
|
| 3535 | + . "'"; |
|
| 3536 | 3536 | } |
| 3537 | 3537 | |
| 3538 | 3538 | |
| 3539 | 3539 | function helper_filtre_balise_img_svg_arguments($alt_or_size, $class_or_size, $size) { |
| 3540 | - $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3541 | - while (is_null(end($args)) and count($args)) { |
|
| 3542 | - array_pop($args); |
|
| 3543 | - } |
|
| 3544 | - if (!count($args)) { |
|
| 3545 | - return [null, null, null]; |
|
| 3546 | - } |
|
| 3547 | - if (count($args) < 3) { |
|
| 3548 | - $maybe_size = array_pop($args); |
|
| 3549 | - // @2x |
|
| 3550 | - // @1.5x |
|
| 3551 | - // 512 |
|
| 3552 | - // 512x* |
|
| 3553 | - // 512x300 |
|
| 3554 | - if ( |
|
| 3555 | - !strlen($maybe_size) |
|
| 3556 | - or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3557 | - ) { |
|
| 3558 | - $args[] = $maybe_size; |
|
| 3559 | - $maybe_size = null; |
|
| 3560 | - } |
|
| 3561 | - while (count($args) < 2) { |
|
| 3562 | - $args[] = null; // default alt or class |
|
| 3563 | - } |
|
| 3564 | - $args[] = $maybe_size; |
|
| 3565 | - } |
|
| 3566 | - return $args; |
|
| 3540 | + $args = [$alt_or_size, $class_or_size, $size]; |
|
| 3541 | + while (is_null(end($args)) and count($args)) { |
|
| 3542 | + array_pop($args); |
|
| 3543 | + } |
|
| 3544 | + if (!count($args)) { |
|
| 3545 | + return [null, null, null]; |
|
| 3546 | + } |
|
| 3547 | + if (count($args) < 3) { |
|
| 3548 | + $maybe_size = array_pop($args); |
|
| 3549 | + // @2x |
|
| 3550 | + // @1.5x |
|
| 3551 | + // 512 |
|
| 3552 | + // 512x* |
|
| 3553 | + // 512x300 |
|
| 3554 | + if ( |
|
| 3555 | + !strlen($maybe_size) |
|
| 3556 | + or !preg_match(',^(@\d+(\.\d+)?x|\d+(x\*)?|\d+x\d+)$,', trim($maybe_size)) |
|
| 3557 | + ) { |
|
| 3558 | + $args[] = $maybe_size; |
|
| 3559 | + $maybe_size = null; |
|
| 3560 | + } |
|
| 3561 | + while (count($args) < 2) { |
|
| 3562 | + $args[] = null; // default alt or class |
|
| 3563 | + } |
|
| 3564 | + $args[] = $maybe_size; |
|
| 3565 | + } |
|
| 3566 | + return $args; |
|
| 3567 | 3567 | } |
| 3568 | 3568 | |
| 3569 | 3569 | function helper_filtre_balise_img_svg_size($img, $size) { |
| 3570 | - // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3571 | - if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3572 | - $coef = floatval(substr($size, 1, -1)); |
|
| 3573 | - list($h, $w) = taille_image($img); |
|
| 3574 | - $height = intval(round($h / $coef)); |
|
| 3575 | - $width = intval(round($w / $coef)); |
|
| 3576 | - } |
|
| 3577 | - // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3578 | - else { |
|
| 3579 | - $size = explode('x', $size, 2); |
|
| 3580 | - $size = array_map('trim', $size); |
|
| 3581 | - $height = $width = intval(array_shift($size)); |
|
| 3582 | - |
|
| 3583 | - if (count($size) and reset($size)) { |
|
| 3584 | - $height = array_shift($size); |
|
| 3585 | - if ($height === '*') { |
|
| 3586 | - list($h, $w) = taille_image($img); |
|
| 3587 | - $height = intval(round($h * $width / $w)); |
|
| 3588 | - } |
|
| 3589 | - } |
|
| 3590 | - } |
|
| 3591 | - |
|
| 3592 | - return [$width, $height]; |
|
| 3570 | + // si size est de la forme '@2x' c'est un coeff multiplicateur sur la densite |
|
| 3571 | + if (strpos($size, '@') === 0 and substr($size, -1) === 'x') { |
|
| 3572 | + $coef = floatval(substr($size, 1, -1)); |
|
| 3573 | + list($h, $w) = taille_image($img); |
|
| 3574 | + $height = intval(round($h / $coef)); |
|
| 3575 | + $width = intval(round($w / $coef)); |
|
| 3576 | + } |
|
| 3577 | + // sinon c'est une valeur seule si image caree ou largeurxhauteur |
|
| 3578 | + else { |
|
| 3579 | + $size = explode('x', $size, 2); |
|
| 3580 | + $size = array_map('trim', $size); |
|
| 3581 | + $height = $width = intval(array_shift($size)); |
|
| 3582 | + |
|
| 3583 | + if (count($size) and reset($size)) { |
|
| 3584 | + $height = array_shift($size); |
|
| 3585 | + if ($height === '*') { |
|
| 3586 | + list($h, $w) = taille_image($img); |
|
| 3587 | + $height = intval(round($h * $width / $w)); |
|
| 3588 | + } |
|
| 3589 | + } |
|
| 3590 | + } |
|
| 3591 | + |
|
| 3592 | + return [$width, $height]; |
|
| 3593 | 3593 | } |
| 3594 | 3594 | |
| 3595 | 3595 | /** |
@@ -3625,43 +3625,43 @@ discard block |
||
| 3625 | 3625 | */ |
| 3626 | 3626 | function filtre_balise_img_dist($img, $alt = '', $class = null, $size = null) { |
| 3627 | 3627 | |
| 3628 | - list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3629 | - |
|
| 3630 | - $img = trim($img); |
|
| 3631 | - if (strpos($img, '<img') === 0) { |
|
| 3632 | - if (!is_null($alt)) { |
|
| 3633 | - $img = inserer_attribut($img, 'alt', $alt); |
|
| 3634 | - } |
|
| 3635 | - if (!is_null($class)) { |
|
| 3636 | - if (strlen($class)) { |
|
| 3637 | - $img = inserer_attribut($img, 'class', $class); |
|
| 3638 | - } |
|
| 3639 | - else { |
|
| 3640 | - $img = vider_attribut($img, 'class'); |
|
| 3641 | - } |
|
| 3642 | - } |
|
| 3643 | - } |
|
| 3644 | - else { |
|
| 3645 | - $img = http_img_pack( |
|
| 3646 | - $img, |
|
| 3647 | - $alt, |
|
| 3648 | - $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3649 | - '', |
|
| 3650 | - ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3651 | - ); |
|
| 3652 | - if (is_null($alt)) { |
|
| 3653 | - $img = vider_attribut($img, 'alt'); |
|
| 3654 | - } |
|
| 3655 | - } |
|
| 3656 | - |
|
| 3657 | - if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3658 | - list($width, $height) = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3659 | - |
|
| 3660 | - $img = inserer_attribut($img, 'width', $width); |
|
| 3661 | - $img = inserer_attribut($img, 'height', $height); |
|
| 3662 | - } |
|
| 3663 | - |
|
| 3664 | - return $img; |
|
| 3628 | + list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3629 | + |
|
| 3630 | + $img = trim($img); |
|
| 3631 | + if (strpos($img, '<img') === 0) { |
|
| 3632 | + if (!is_null($alt)) { |
|
| 3633 | + $img = inserer_attribut($img, 'alt', $alt); |
|
| 3634 | + } |
|
| 3635 | + if (!is_null($class)) { |
|
| 3636 | + if (strlen($class)) { |
|
| 3637 | + $img = inserer_attribut($img, 'class', $class); |
|
| 3638 | + } |
|
| 3639 | + else { |
|
| 3640 | + $img = vider_attribut($img, 'class'); |
|
| 3641 | + } |
|
| 3642 | + } |
|
| 3643 | + } |
|
| 3644 | + else { |
|
| 3645 | + $img = http_img_pack( |
|
| 3646 | + $img, |
|
| 3647 | + $alt, |
|
| 3648 | + $class ? " class='" . attribut_html($class) . "'" : '', |
|
| 3649 | + '', |
|
| 3650 | + ['chemin_image' => false, 'utiliser_suffixe_size' => false] |
|
| 3651 | + ); |
|
| 3652 | + if (is_null($alt)) { |
|
| 3653 | + $img = vider_attribut($img, 'alt'); |
|
| 3654 | + } |
|
| 3655 | + } |
|
| 3656 | + |
|
| 3657 | + if ($img and !is_null($size) and strlen($size = trim($size))) { |
|
| 3658 | + list($width, $height) = helper_filtre_balise_img_svg_size($img, $size); |
|
| 3659 | + |
|
| 3660 | + $img = inserer_attribut($img, 'width', $width); |
|
| 3661 | + $img = inserer_attribut($img, 'height', $height); |
|
| 3662 | + } |
|
| 3663 | + |
|
| 3664 | + return $img; |
|
| 3665 | 3665 | } |
| 3666 | 3666 | |
| 3667 | 3667 | |
@@ -3695,79 +3695,79 @@ discard block |
||
| 3695 | 3695 | */ |
| 3696 | 3696 | function filtre_balise_svg_dist($img, $alt = '', $class = null, $size = null) { |
| 3697 | 3697 | |
| 3698 | - $img = trim($img); |
|
| 3699 | - $img_file = $img; |
|
| 3700 | - if (strpos($img, '<svg') === false) { |
|
| 3701 | - if ($p = strpos($img_file, '?')) { |
|
| 3702 | - $img_file = substr($img_file, 0, $p); |
|
| 3703 | - } |
|
| 3698 | + $img = trim($img); |
|
| 3699 | + $img_file = $img; |
|
| 3700 | + if (strpos($img, '<svg') === false) { |
|
| 3701 | + if ($p = strpos($img_file, '?')) { |
|
| 3702 | + $img_file = substr($img_file, 0, $p); |
|
| 3703 | + } |
|
| 3704 | 3704 | |
| 3705 | - // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3706 | - // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3707 | - if (tester_url_absolue($img_file)) { |
|
| 3708 | - include_spip('inc/distant'); |
|
| 3709 | - $fichier = copie_locale($img_file); |
|
| 3710 | - $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3711 | - } |
|
| 3705 | + // ne jamais operer directement sur une image distante pour des raisons de perfo |
|
| 3706 | + // la copie locale a toutes les chances d'etre la ou de resservir |
|
| 3707 | + if (tester_url_absolue($img_file)) { |
|
| 3708 | + include_spip('inc/distant'); |
|
| 3709 | + $fichier = copie_locale($img_file); |
|
| 3710 | + $img_file = ($fichier ? _DIR_RACINE . $fichier : $img_file); |
|
| 3711 | + } |
|
| 3712 | 3712 | |
| 3713 | - if ( |
|
| 3714 | - !$img_file |
|
| 3715 | - or !file_exists($img_file) |
|
| 3716 | - or !$svg = file_get_contents($img_file) |
|
| 3717 | - ) { |
|
| 3718 | - return ''; |
|
| 3719 | - } |
|
| 3720 | - } |
|
| 3713 | + if ( |
|
| 3714 | + !$img_file |
|
| 3715 | + or !file_exists($img_file) |
|
| 3716 | + or !$svg = file_get_contents($img_file) |
|
| 3717 | + ) { |
|
| 3718 | + return ''; |
|
| 3719 | + } |
|
| 3720 | + } |
|
| 3721 | 3721 | |
| 3722 | - if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3723 | - return ''; |
|
| 3724 | - } |
|
| 3722 | + if (!preg_match(",<svg\b[^>]*>,UimsS", $svg, $match)) { |
|
| 3723 | + return ''; |
|
| 3724 | + } |
|
| 3725 | 3725 | |
| 3726 | - list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3726 | + list($alt, $class, $size) = helper_filtre_balise_img_svg_arguments($alt, $class, $size); |
|
| 3727 | 3727 | |
| 3728 | - $balise_svg = $match[0]; |
|
| 3729 | - $balise_svg_source = $balise_svg; |
|
| 3728 | + $balise_svg = $match[0]; |
|
| 3729 | + $balise_svg_source = $balise_svg; |
|
| 3730 | 3730 | |
| 3731 | - // entete XML à supprimer |
|
| 3732 | - $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3731 | + // entete XML à supprimer |
|
| 3732 | + $svg = preg_replace(',^\s*<\?xml[^>]*\?' . '>,', '', $svg); |
|
| 3733 | 3733 | |
| 3734 | - // IE est toujours mon ami |
|
| 3735 | - $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3734 | + // IE est toujours mon ami |
|
| 3735 | + $balise_svg = inserer_attribut($balise_svg, 'focusable', 'false'); |
|
| 3736 | 3736 | |
| 3737 | - // regler la classe |
|
| 3738 | - if (!is_null($class)) { |
|
| 3739 | - if (strlen($class)) { |
|
| 3740 | - $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3741 | - } |
|
| 3742 | - else { |
|
| 3743 | - $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3744 | - } |
|
| 3745 | - } |
|
| 3737 | + // regler la classe |
|
| 3738 | + if (!is_null($class)) { |
|
| 3739 | + if (strlen($class)) { |
|
| 3740 | + $balise_svg = inserer_attribut($balise_svg, 'class', $class); |
|
| 3741 | + } |
|
| 3742 | + else { |
|
| 3743 | + $balise_svg = vider_attribut($balise_svg, 'class'); |
|
| 3744 | + } |
|
| 3745 | + } |
|
| 3746 | 3746 | |
| 3747 | - // regler le alt |
|
| 3748 | - if ($alt) { |
|
| 3749 | - $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3750 | - $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3751 | - $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3752 | - $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3753 | - $balise_svg .= $title; |
|
| 3754 | - } |
|
| 3755 | - else { |
|
| 3756 | - $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3757 | - } |
|
| 3747 | + // regler le alt |
|
| 3748 | + if ($alt) { |
|
| 3749 | + $balise_svg = inserer_attribut($balise_svg, 'role', 'img'); |
|
| 3750 | + $id = 'img-svg-title-' . substr(md5("$img_file:$svg:$alt"), 0, 4); |
|
| 3751 | + $balise_svg = inserer_attribut($balise_svg, 'aria-labelledby', $id); |
|
| 3752 | + $title = "<title id=\"$id\">" . entites_html($alt) . "</title>\n"; |
|
| 3753 | + $balise_svg .= $title; |
|
| 3754 | + } |
|
| 3755 | + else { |
|
| 3756 | + $balise_svg = inserer_attribut($balise_svg, 'aria-hidden', 'true'); |
|
| 3757 | + } |
|
| 3758 | 3758 | |
| 3759 | - $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3759 | + $svg = str_replace($balise_svg_source, $balise_svg, $svg); |
|
| 3760 | 3760 | |
| 3761 | - if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3762 | - list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3761 | + if (!is_null($size) and strlen($size = trim($size))) { |
|
| 3762 | + list($width, $height) = helper_filtre_balise_img_svg_size($svg, $size); |
|
| 3763 | 3763 | |
| 3764 | - if (!function_exists('svg_redimensionner')) { |
|
| 3765 | - include_spip('inc/svg'); |
|
| 3766 | - } |
|
| 3767 | - $svg = svg_redimensionner($svg, $width, $height); |
|
| 3768 | - } |
|
| 3764 | + if (!function_exists('svg_redimensionner')) { |
|
| 3765 | + include_spip('inc/svg'); |
|
| 3766 | + } |
|
| 3767 | + $svg = svg_redimensionner($svg, $width, $height); |
|
| 3768 | + } |
|
| 3769 | 3769 | |
| 3770 | - return $svg; |
|
| 3770 | + return $svg; |
|
| 3771 | 3771 | } |
| 3772 | 3772 | |
| 3773 | 3773 | |
@@ -3793,18 +3793,18 @@ discard block |
||
| 3793 | 3793 | * Code HTML résultant |
| 3794 | 3794 | **/ |
| 3795 | 3795 | function filtre_foreach_dist($tableau, $modele = 'foreach') { |
| 3796 | - $texte = ''; |
|
| 3797 | - if (is_array($tableau)) { |
|
| 3798 | - foreach ($tableau as $k => $v) { |
|
| 3799 | - $res = recuperer_fond( |
|
| 3800 | - 'modeles/' . $modele, |
|
| 3801 | - array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3802 | - ); |
|
| 3803 | - $texte .= $res; |
|
| 3804 | - } |
|
| 3805 | - } |
|
| 3796 | + $texte = ''; |
|
| 3797 | + if (is_array($tableau)) { |
|
| 3798 | + foreach ($tableau as $k => $v) { |
|
| 3799 | + $res = recuperer_fond( |
|
| 3800 | + 'modeles/' . $modele, |
|
| 3801 | + array_merge(['cle' => $k], (is_array($v) ? $v : ['valeur' => $v])) |
|
| 3802 | + ); |
|
| 3803 | + $texte .= $res; |
|
| 3804 | + } |
|
| 3805 | + } |
|
| 3806 | 3806 | |
| 3807 | - return $texte; |
|
| 3807 | + return $texte; |
|
| 3808 | 3808 | } |
| 3809 | 3809 | |
| 3810 | 3810 | |
@@ -3829,37 +3829,37 @@ discard block |
||
| 3829 | 3829 | * - tout : retourne toutes les informations du plugin actif |
| 3830 | 3830 | **/ |
| 3831 | 3831 | function filtre_info_plugin_dist($plugin, $type_info, $reload = false) { |
| 3832 | - include_spip('inc/plugin'); |
|
| 3833 | - $plugin = strtoupper($plugin); |
|
| 3834 | - $plugins_actifs = liste_plugin_actifs(); |
|
| 3835 | - |
|
| 3836 | - if (!$plugin) { |
|
| 3837 | - return serialize(array_keys($plugins_actifs)); |
|
| 3838 | - } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3839 | - return ''; |
|
| 3840 | - } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3841 | - return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3842 | - } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3843 | - return $plugins_actifs[$plugin][$type_info]; |
|
| 3844 | - } else { |
|
| 3845 | - $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3846 | - // On prend en compte les extensions |
|
| 3847 | - if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3848 | - $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3849 | - } else { |
|
| 3850 | - $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3851 | - } |
|
| 3852 | - if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3853 | - return ''; |
|
| 3854 | - } |
|
| 3855 | - if ($type_info == 'tout') { |
|
| 3856 | - return $infos; |
|
| 3857 | - } elseif ($type_info == 'est_actif') { |
|
| 3858 | - return $infos ? 1 : 0; |
|
| 3859 | - } else { |
|
| 3860 | - return strval($infos[$type_info]); |
|
| 3861 | - } |
|
| 3862 | - } |
|
| 3832 | + include_spip('inc/plugin'); |
|
| 3833 | + $plugin = strtoupper($plugin); |
|
| 3834 | + $plugins_actifs = liste_plugin_actifs(); |
|
| 3835 | + |
|
| 3836 | + if (!$plugin) { |
|
| 3837 | + return serialize(array_keys($plugins_actifs)); |
|
| 3838 | + } elseif (empty($plugins_actifs[$plugin]) and !$reload) { |
|
| 3839 | + return ''; |
|
| 3840 | + } elseif (($type_info == 'est_actif') and !$reload) { |
|
| 3841 | + return $plugins_actifs[$plugin] ? 1 : 0; |
|
| 3842 | + } elseif (isset($plugins_actifs[$plugin][$type_info]) and !$reload) { |
|
| 3843 | + return $plugins_actifs[$plugin][$type_info]; |
|
| 3844 | + } else { |
|
| 3845 | + $get_infos = charger_fonction('get_infos', 'plugins'); |
|
| 3846 | + // On prend en compte les extensions |
|
| 3847 | + if (!is_dir($plugins_actifs[$plugin]['dir_type'])) { |
|
| 3848 | + $dir_plugins = constant($plugins_actifs[$plugin]['dir_type']); |
|
| 3849 | + } else { |
|
| 3850 | + $dir_plugins = $plugins_actifs[$plugin]['dir_type']; |
|
| 3851 | + } |
|
| 3852 | + if (!$infos = $get_infos($plugins_actifs[$plugin]['dir'], $reload, $dir_plugins)) { |
|
| 3853 | + return ''; |
|
| 3854 | + } |
|
| 3855 | + if ($type_info == 'tout') { |
|
| 3856 | + return $infos; |
|
| 3857 | + } elseif ($type_info == 'est_actif') { |
|
| 3858 | + return $infos ? 1 : 0; |
|
| 3859 | + } else { |
|
| 3860 | + return strval($infos[$type_info]); |
|
| 3861 | + } |
|
| 3862 | + } |
|
| 3863 | 3863 | } |
| 3864 | 3864 | |
| 3865 | 3865 | |
@@ -3886,9 +3886,9 @@ discard block |
||
| 3886 | 3886 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3887 | 3887 | */ |
| 3888 | 3888 | function puce_changement_statut($id_objet, $statut, $id_rubrique, $type, $ajax = false) { |
| 3889 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3889 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3890 | 3890 | |
| 3891 | - return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3891 | + return $puce_statut($id_objet, $statut, $id_rubrique, $type, $ajax); |
|
| 3892 | 3892 | } |
| 3893 | 3893 | |
| 3894 | 3894 | |
@@ -3918,19 +3918,19 @@ discard block |
||
| 3918 | 3918 | * Code HTML de l'image de puce de statut à insérer (et du menu de changement si présent) |
| 3919 | 3919 | */ |
| 3920 | 3920 | function filtre_puce_statut_dist($statut, $objet, $id_objet = 0, $id_parent = 0) { |
| 3921 | - static $puce_statut = null; |
|
| 3922 | - if (!$puce_statut) { |
|
| 3923 | - $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3924 | - } |
|
| 3921 | + static $puce_statut = null; |
|
| 3922 | + if (!$puce_statut) { |
|
| 3923 | + $puce_statut = charger_fonction('puce_statut', 'inc'); |
|
| 3924 | + } |
|
| 3925 | 3925 | |
| 3926 | - return $puce_statut( |
|
| 3927 | - $id_objet, |
|
| 3928 | - $statut, |
|
| 3929 | - $id_parent, |
|
| 3930 | - $objet, |
|
| 3931 | - false, |
|
| 3932 | - objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3933 | - ); |
|
| 3926 | + return $puce_statut( |
|
| 3927 | + $id_objet, |
|
| 3928 | + $statut, |
|
| 3929 | + $id_parent, |
|
| 3930 | + $objet, |
|
| 3931 | + false, |
|
| 3932 | + objet_info($objet, 'editable') ? _ACTIVER_PUCE_RAPIDE : false |
|
| 3933 | + ); |
|
| 3934 | 3934 | } |
| 3935 | 3935 | |
| 3936 | 3936 | |
@@ -3957,97 +3957,97 @@ discard block |
||
| 3957 | 3957 | * hash du contexte |
| 3958 | 3958 | */ |
| 3959 | 3959 | function encoder_contexte_ajax($c, $form = '', $emboite = null, $ajaxid = '') { |
| 3960 | - if ( |
|
| 3961 | - is_string($c) |
|
| 3962 | - and @unserialize($c) !== false |
|
| 3963 | - ) { |
|
| 3964 | - $c = unserialize($c); |
|
| 3965 | - } |
|
| 3966 | - |
|
| 3967 | - // supprimer les parametres debut_x |
|
| 3968 | - // pour que la pagination ajax ne soit pas plantee |
|
| 3969 | - // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3970 | - // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3971 | - if (is_array($c)) { |
|
| 3972 | - foreach ($c as $k => $v) { |
|
| 3973 | - if (strpos($k, 'debut_') === 0) { |
|
| 3974 | - unset($c[$k]); |
|
| 3975 | - } |
|
| 3976 | - } |
|
| 3977 | - } |
|
| 3978 | - |
|
| 3979 | - if (!function_exists('calculer_cle_action')) { |
|
| 3980 | - include_spip('inc/securiser_action'); |
|
| 3981 | - } |
|
| 3982 | - |
|
| 3983 | - $c = serialize($c); |
|
| 3984 | - $cle = calculer_cle_action($form . $c); |
|
| 3985 | - $c = "$cle:$c"; |
|
| 3986 | - |
|
| 3987 | - // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3988 | - // par defaut, sauf si cette configuration a été forcée |
|
| 3989 | - // OU que la longueur de l’argument géneré est plus long |
|
| 3990 | - // que ce qui est toléré. |
|
| 3991 | - $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3992 | - if (!$cache_contextes_ajax) { |
|
| 3993 | - $env = $c; |
|
| 3994 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3995 | - $env = gzdeflate($env); |
|
| 3996 | - } |
|
| 3997 | - $env = _xor($env); |
|
| 3998 | - $env = base64_encode($env); |
|
| 3999 | - $len = strlen($env); |
|
| 4000 | - // Si l’url est trop longue pour le navigateur |
|
| 4001 | - $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4002 | - if ($len > $max_len) { |
|
| 4003 | - $cache_contextes_ajax = true; |
|
| 4004 | - spip_log( |
|
| 4005 | - 'Contextes AJAX forces en fichiers !' |
|
| 4006 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4007 | - . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4008 | - _LOG_AVERTISSEMENT |
|
| 4009 | - ); |
|
| 4010 | - } |
|
| 4011 | - // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4012 | - elseif ( |
|
| 4013 | - $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4014 | - and $max_len < $len |
|
| 4015 | - ) { |
|
| 4016 | - $cache_contextes_ajax = true; |
|
| 4017 | - spip_log('Contextes AJAX forces en fichiers !' |
|
| 4018 | - . ' Cela arrive lorsque la valeur du contexte' |
|
| 4019 | - . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4020 | - . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4021 | - . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4022 | - . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4023 | - } |
|
| 4024 | - } |
|
| 4025 | - |
|
| 4026 | - if ($cache_contextes_ajax) { |
|
| 4027 | - $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4028 | - // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4029 | - $md5 = md5($c); |
|
| 4030 | - ecrire_fichier("$dir/c$md5", $c); |
|
| 4031 | - $env = $md5; |
|
| 4032 | - } |
|
| 4033 | - |
|
| 4034 | - if ($emboite === null) { |
|
| 4035 | - return $env; |
|
| 4036 | - } |
|
| 4037 | - if (!trim($emboite)) { |
|
| 4038 | - return ''; |
|
| 4039 | - } |
|
| 4040 | - // toujours encoder l'url source dans le bloc ajax |
|
| 4041 | - $r = self(); |
|
| 4042 | - $r = ' data-origin="' . $r . '"'; |
|
| 4043 | - $class = 'ajaxbloc'; |
|
| 4044 | - if ($ajaxid and is_string($ajaxid)) { |
|
| 4045 | - // ajaxid est normalement conforme a un nom de classe css |
|
| 4046 | - // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4047 | - $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4048 | - } |
|
| 4049 | - |
|
| 4050 | - return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 3960 | + if ( |
|
| 3961 | + is_string($c) |
|
| 3962 | + and @unserialize($c) !== false |
|
| 3963 | + ) { |
|
| 3964 | + $c = unserialize($c); |
|
| 3965 | + } |
|
| 3966 | + |
|
| 3967 | + // supprimer les parametres debut_x |
|
| 3968 | + // pour que la pagination ajax ne soit pas plantee |
|
| 3969 | + // si on charge la page &debut_x=1 : car alors en cliquant sur l'item 0, |
|
| 3970 | + // le debut_x=0 n'existe pas, et on resterait sur 1 |
|
| 3971 | + if (is_array($c)) { |
|
| 3972 | + foreach ($c as $k => $v) { |
|
| 3973 | + if (strpos($k, 'debut_') === 0) { |
|
| 3974 | + unset($c[$k]); |
|
| 3975 | + } |
|
| 3976 | + } |
|
| 3977 | + } |
|
| 3978 | + |
|
| 3979 | + if (!function_exists('calculer_cle_action')) { |
|
| 3980 | + include_spip('inc/securiser_action'); |
|
| 3981 | + } |
|
| 3982 | + |
|
| 3983 | + $c = serialize($c); |
|
| 3984 | + $cle = calculer_cle_action($form . $c); |
|
| 3985 | + $c = "$cle:$c"; |
|
| 3986 | + |
|
| 3987 | + // on ne stocke pas les contextes dans des fichiers en cache |
|
| 3988 | + // par defaut, sauf si cette configuration a été forcée |
|
| 3989 | + // OU que la longueur de l’argument géneré est plus long |
|
| 3990 | + // que ce qui est toléré. |
|
| 3991 | + $cache_contextes_ajax = (defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX); |
|
| 3992 | + if (!$cache_contextes_ajax) { |
|
| 3993 | + $env = $c; |
|
| 3994 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 3995 | + $env = gzdeflate($env); |
|
| 3996 | + } |
|
| 3997 | + $env = _xor($env); |
|
| 3998 | + $env = base64_encode($env); |
|
| 3999 | + $len = strlen($env); |
|
| 4000 | + // Si l’url est trop longue pour le navigateur |
|
| 4001 | + $max_len = _CACHE_CONTEXTES_AJAX_SUR_LONGUEUR; |
|
| 4002 | + if ($len > $max_len) { |
|
| 4003 | + $cache_contextes_ajax = true; |
|
| 4004 | + spip_log( |
|
| 4005 | + 'Contextes AJAX forces en fichiers !' |
|
| 4006 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4007 | + . " depasse la longueur maximale autorisee ($max_len). Ici : $len.", |
|
| 4008 | + _LOG_AVERTISSEMENT |
|
| 4009 | + ); |
|
| 4010 | + } |
|
| 4011 | + // Sinon si Suhosin est actif et a une la valeur maximale des variables en GET... |
|
| 4012 | + elseif ( |
|
| 4013 | + $max_len = @ini_get('suhosin.get.max_value_length') |
|
| 4014 | + and $max_len < $len |
|
| 4015 | + ) { |
|
| 4016 | + $cache_contextes_ajax = true; |
|
| 4017 | + spip_log('Contextes AJAX forces en fichiers !' |
|
| 4018 | + . ' Cela arrive lorsque la valeur du contexte' |
|
| 4019 | + . ' depasse la longueur maximale autorisee par Suhosin' |
|
| 4020 | + . " ($max_len) dans 'suhosin.get.max_value_length'. Ici : $len." |
|
| 4021 | + . ' Vous devriez modifier les parametres de Suhosin' |
|
| 4022 | + . ' pour accepter au moins 1024 caracteres.', _LOG_AVERTISSEMENT); |
|
| 4023 | + } |
|
| 4024 | + } |
|
| 4025 | + |
|
| 4026 | + if ($cache_contextes_ajax) { |
|
| 4027 | + $dir = sous_repertoire(_DIR_CACHE, 'contextes'); |
|
| 4028 | + // stocker les contextes sur disque et ne passer qu'un hash dans l'url |
|
| 4029 | + $md5 = md5($c); |
|
| 4030 | + ecrire_fichier("$dir/c$md5", $c); |
|
| 4031 | + $env = $md5; |
|
| 4032 | + } |
|
| 4033 | + |
|
| 4034 | + if ($emboite === null) { |
|
| 4035 | + return $env; |
|
| 4036 | + } |
|
| 4037 | + if (!trim($emboite)) { |
|
| 4038 | + return ''; |
|
| 4039 | + } |
|
| 4040 | + // toujours encoder l'url source dans le bloc ajax |
|
| 4041 | + $r = self(); |
|
| 4042 | + $r = ' data-origin="' . $r . '"'; |
|
| 4043 | + $class = 'ajaxbloc'; |
|
| 4044 | + if ($ajaxid and is_string($ajaxid)) { |
|
| 4045 | + // ajaxid est normalement conforme a un nom de classe css |
|
| 4046 | + // on ne verifie pas la conformite, mais on passe entites_html par dessus par precaution |
|
| 4047 | + $class .= ' ajax-id-' . entites_html($ajaxid); |
|
| 4048 | + } |
|
| 4049 | + |
|
| 4050 | + return "<div class='$class' " . "data-ajax-env='$env'$r>\n$emboite</div><!--ajaxbloc-->\n"; |
|
| 4051 | 4051 | } |
| 4052 | 4052 | |
| 4053 | 4053 | /** |
@@ -4067,37 +4067,37 @@ discard block |
||
| 4067 | 4067 | * - false : erreur de décodage |
| 4068 | 4068 | */ |
| 4069 | 4069 | function decoder_contexte_ajax($c, $form = '') { |
| 4070 | - if (!function_exists('calculer_cle_action')) { |
|
| 4071 | - include_spip('inc/securiser_action'); |
|
| 4072 | - } |
|
| 4073 | - if ( |
|
| 4074 | - ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4075 | - and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4076 | - and lire_fichier("$dir/c$c", $contexte) |
|
| 4077 | - ) { |
|
| 4078 | - $c = $contexte; |
|
| 4079 | - } else { |
|
| 4080 | - $c = @base64_decode($c); |
|
| 4081 | - $c = _xor($c); |
|
| 4082 | - if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4083 | - $c = @gzinflate($c); |
|
| 4084 | - } |
|
| 4085 | - } |
|
| 4086 | - |
|
| 4087 | - // extraire la signature en debut de contexte |
|
| 4088 | - // et la verifier avant de deserializer |
|
| 4089 | - // format : signature:donneesserializees |
|
| 4090 | - if ($p = strpos($c, ':')) { |
|
| 4091 | - $cle = substr($c, 0, $p); |
|
| 4092 | - $c = substr($c, $p + 1); |
|
| 4093 | - |
|
| 4094 | - if ($cle == calculer_cle_action($form . $c)) { |
|
| 4095 | - $env = @unserialize($c); |
|
| 4096 | - return $env; |
|
| 4097 | - } |
|
| 4098 | - } |
|
| 4099 | - |
|
| 4100 | - return false; |
|
| 4070 | + if (!function_exists('calculer_cle_action')) { |
|
| 4071 | + include_spip('inc/securiser_action'); |
|
| 4072 | + } |
|
| 4073 | + if ( |
|
| 4074 | + ((defined('_CACHE_CONTEXTES_AJAX') and _CACHE_CONTEXTES_AJAX) or strlen($c) == 32) |
|
| 4075 | + and $dir = sous_repertoire(_DIR_CACHE, 'contextes') |
|
| 4076 | + and lire_fichier("$dir/c$c", $contexte) |
|
| 4077 | + ) { |
|
| 4078 | + $c = $contexte; |
|
| 4079 | + } else { |
|
| 4080 | + $c = @base64_decode($c); |
|
| 4081 | + $c = _xor($c); |
|
| 4082 | + if (function_exists('gzdeflate') && function_exists('gzinflate')) { |
|
| 4083 | + $c = @gzinflate($c); |
|
| 4084 | + } |
|
| 4085 | + } |
|
| 4086 | + |
|
| 4087 | + // extraire la signature en debut de contexte |
|
| 4088 | + // et la verifier avant de deserializer |
|
| 4089 | + // format : signature:donneesserializees |
|
| 4090 | + if ($p = strpos($c, ':')) { |
|
| 4091 | + $cle = substr($c, 0, $p); |
|
| 4092 | + $c = substr($c, $p + 1); |
|
| 4093 | + |
|
| 4094 | + if ($cle == calculer_cle_action($form . $c)) { |
|
| 4095 | + $env = @unserialize($c); |
|
| 4096 | + return $env; |
|
| 4097 | + } |
|
| 4098 | + } |
|
| 4099 | + |
|
| 4100 | + return false; |
|
| 4101 | 4101 | } |
| 4102 | 4102 | |
| 4103 | 4103 | |
@@ -4115,20 +4115,20 @@ discard block |
||
| 4115 | 4115 | * Message décrypté ou encrypté |
| 4116 | 4116 | **/ |
| 4117 | 4117 | function _xor($message, $key = null) { |
| 4118 | - if (is_null($key)) { |
|
| 4119 | - if (!function_exists('calculer_cle_action')) { |
|
| 4120 | - include_spip('inc/securiser_action'); |
|
| 4121 | - } |
|
| 4122 | - $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4123 | - } |
|
| 4118 | + if (is_null($key)) { |
|
| 4119 | + if (!function_exists('calculer_cle_action')) { |
|
| 4120 | + include_spip('inc/securiser_action'); |
|
| 4121 | + } |
|
| 4122 | + $key = pack('H*', calculer_cle_action('_xor')); |
|
| 4123 | + } |
|
| 4124 | 4124 | |
| 4125 | - $keylen = strlen($key); |
|
| 4126 | - $messagelen = strlen($message); |
|
| 4127 | - for ($i = 0; $i < $messagelen; $i++) { |
|
| 4128 | - $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4129 | - } |
|
| 4125 | + $keylen = strlen($key); |
|
| 4126 | + $messagelen = strlen($message); |
|
| 4127 | + for ($i = 0; $i < $messagelen; $i++) { |
|
| 4128 | + $message[$i] = ~($message[$i] ^ $key[$i % $keylen]); |
|
| 4129 | + } |
|
| 4130 | 4130 | |
| 4131 | - return $message; |
|
| 4131 | + return $message; |
|
| 4132 | 4132 | } |
| 4133 | 4133 | |
| 4134 | 4134 | /** |
@@ -4142,7 +4142,7 @@ discard block |
||
| 4142 | 4142 | * @return string |
| 4143 | 4143 | */ |
| 4144 | 4144 | function url_reponse_forum($texte) { |
| 4145 | - return $texte; |
|
| 4145 | + return $texte; |
|
| 4146 | 4146 | } |
| 4147 | 4147 | |
| 4148 | 4148 | /** |
@@ -4156,7 +4156,7 @@ discard block |
||
| 4156 | 4156 | * @return string |
| 4157 | 4157 | */ |
| 4158 | 4158 | function url_rss_forum($texte) { |
| 4159 | - return $texte; |
|
| 4159 | + return $texte; |
|
| 4160 | 4160 | } |
| 4161 | 4161 | |
| 4162 | 4162 | |
@@ -4195,37 +4195,37 @@ discard block |
||
| 4195 | 4195 | * Code HTML |
| 4196 | 4196 | */ |
| 4197 | 4197 | function lien_ou_expose($url, $libelle = null, $on = false, $class = '', $title = '', $rel = '', $evt = '') { |
| 4198 | - if ($on) { |
|
| 4199 | - $bal = 'strong'; |
|
| 4200 | - $class = ''; |
|
| 4201 | - $att = ''; |
|
| 4202 | - // si $on passe la balise et optionnelement une ou ++classe |
|
| 4203 | - // a.active span.selected.active etc.... |
|
| 4204 | - if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4205 | - $on = explode('.', $on); |
|
| 4206 | - // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4207 | - if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4208 | - $bal = array_shift($on); |
|
| 4209 | - $class = implode(' ', $on); |
|
| 4210 | - if ($bal == 'a') { |
|
| 4211 | - $att = 'href="#" '; |
|
| 4212 | - } |
|
| 4213 | - } |
|
| 4214 | - } |
|
| 4215 | - $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4216 | - } else { |
|
| 4217 | - $bal = 'a'; |
|
| 4218 | - $att = "href='$url'" |
|
| 4219 | - . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4220 | - . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4221 | - . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4222 | - . $evt; |
|
| 4223 | - } |
|
| 4224 | - if ($libelle === null) { |
|
| 4225 | - $libelle = $url; |
|
| 4226 | - } |
|
| 4227 | - |
|
| 4228 | - return "<$bal $att>$libelle</$bal>"; |
|
| 4198 | + if ($on) { |
|
| 4199 | + $bal = 'strong'; |
|
| 4200 | + $class = ''; |
|
| 4201 | + $att = ''; |
|
| 4202 | + // si $on passe la balise et optionnelement une ou ++classe |
|
| 4203 | + // a.active span.selected.active etc.... |
|
| 4204 | + if (is_string($on) and (strncmp($on, 'a', 1) == 0 or strncmp($on, 'span', 4) == 0 or strncmp($on, 'strong', 6) == 0)) { |
|
| 4205 | + $on = explode('.', $on); |
|
| 4206 | + // on verifie que c'est exactement une des 3 balises a, span ou strong |
|
| 4207 | + if (in_array(reset($on), ['a', 'span', 'strong'])) { |
|
| 4208 | + $bal = array_shift($on); |
|
| 4209 | + $class = implode(' ', $on); |
|
| 4210 | + if ($bal == 'a') { |
|
| 4211 | + $att = 'href="#" '; |
|
| 4212 | + } |
|
| 4213 | + } |
|
| 4214 | + } |
|
| 4215 | + $att .= 'class="' . ($class ? attribut_html($class) . ' ' : '') . (defined('_LIEN_OU_EXPOSE_CLASS_ON') ? _LIEN_OU_EXPOSE_CLASS_ON : 'on') . '"'; |
|
| 4216 | + } else { |
|
| 4217 | + $bal = 'a'; |
|
| 4218 | + $att = "href='$url'" |
|
| 4219 | + . ($title ? " title='" . attribut_html($title) . "'" : '') |
|
| 4220 | + . ($class ? " class='" . attribut_html($class) . "'" : '') |
|
| 4221 | + . ($rel ? " rel='" . attribut_html($rel) . "'" : '') |
|
| 4222 | + . $evt; |
|
| 4223 | + } |
|
| 4224 | + if ($libelle === null) { |
|
| 4225 | + $libelle = $url; |
|
| 4226 | + } |
|
| 4227 | + |
|
| 4228 | + return "<$bal $att>$libelle</$bal>"; |
|
| 4229 | 4229 | } |
| 4230 | 4230 | |
| 4231 | 4231 | |
@@ -4242,39 +4242,39 @@ discard block |
||
| 4242 | 4242 | * @return string : la chaine de langue finale en utilisant la fonction _T() |
| 4243 | 4243 | */ |
| 4244 | 4244 | function singulier_ou_pluriel($nb, $chaine_un, $chaine_plusieurs, $var = 'nb', $vars = []) { |
| 4245 | - static $local_singulier_ou_pluriel = []; |
|
| 4246 | - |
|
| 4247 | - // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4248 | - if (!is_numeric($nb) or $nb == 0) { |
|
| 4249 | - return ''; |
|
| 4250 | - } |
|
| 4251 | - if (!is_array($vars)) { |
|
| 4252 | - return ''; |
|
| 4253 | - } |
|
| 4254 | - |
|
| 4255 | - $langue = $GLOBALS['spip_lang']; |
|
| 4256 | - if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4257 | - $local_singulier_ou_pluriel[$langue] = false; |
|
| 4258 | - if ( |
|
| 4259 | - $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4260 | - or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4261 | - ) { |
|
| 4262 | - $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4263 | - } |
|
| 4264 | - } |
|
| 4265 | - |
|
| 4266 | - // si on a une surcharge on l'utilise |
|
| 4267 | - if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4268 | - return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4269 | - } |
|
| 4270 | - |
|
| 4271 | - // sinon traitement par defaut |
|
| 4272 | - $vars[$var] = $nb; |
|
| 4273 | - if ($nb >= 2) { |
|
| 4274 | - return _T($chaine_plusieurs, $vars); |
|
| 4275 | - } else { |
|
| 4276 | - return _T($chaine_un, $vars); |
|
| 4277 | - } |
|
| 4245 | + static $local_singulier_ou_pluriel = []; |
|
| 4246 | + |
|
| 4247 | + // si nb=0 ou pas de $vars valide on retourne une chaine vide, a traiter par un |sinon |
|
| 4248 | + if (!is_numeric($nb) or $nb == 0) { |
|
| 4249 | + return ''; |
|
| 4250 | + } |
|
| 4251 | + if (!is_array($vars)) { |
|
| 4252 | + return ''; |
|
| 4253 | + } |
|
| 4254 | + |
|
| 4255 | + $langue = $GLOBALS['spip_lang']; |
|
| 4256 | + if (!isset($local_singulier_ou_pluriel[$langue])) { |
|
| 4257 | + $local_singulier_ou_pluriel[$langue] = false; |
|
| 4258 | + if ( |
|
| 4259 | + $f = charger_fonction("singulier_ou_pluriel_${langue}", 'inc', true) |
|
| 4260 | + or $f = charger_fonction('singulier_ou_pluriel', 'inc', true) |
|
| 4261 | + ) { |
|
| 4262 | + $local_singulier_ou_pluriel[$langue] = $f; |
|
| 4263 | + } |
|
| 4264 | + } |
|
| 4265 | + |
|
| 4266 | + // si on a une surcharge on l'utilise |
|
| 4267 | + if ($local_singulier_ou_pluriel[$langue]) { |
|
| 4268 | + return ($local_singulier_ou_pluriel[$langue])($nb, $chaine_un, $chaine_plusieurs, $var, $vars); |
|
| 4269 | + } |
|
| 4270 | + |
|
| 4271 | + // sinon traitement par defaut |
|
| 4272 | + $vars[$var] = $nb; |
|
| 4273 | + if ($nb >= 2) { |
|
| 4274 | + return _T($chaine_plusieurs, $vars); |
|
| 4275 | + } else { |
|
| 4276 | + return _T($chaine_un, $vars); |
|
| 4277 | + } |
|
| 4278 | 4278 | } |
| 4279 | 4279 | |
| 4280 | 4280 | |
@@ -4302,73 +4302,73 @@ discard block |
||
| 4302 | 4302 | */ |
| 4303 | 4303 | function prepare_icone_base($type, $lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4304 | 4304 | |
| 4305 | - $class_lien = $class_bouton = $class; |
|
| 4306 | - |
|
| 4307 | - // Normaliser la fonction et compléter la classe en fonction |
|
| 4308 | - if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4309 | - $class_lien .= ' danger'; |
|
| 4310 | - $class_bouton .= ' btn_danger'; |
|
| 4311 | - } elseif ($fonction == 'rien.gif') { |
|
| 4312 | - $fonction = ''; |
|
| 4313 | - } elseif ($fonction == 'delsafe') { |
|
| 4314 | - $fonction = 'del'; |
|
| 4315 | - } |
|
| 4316 | - |
|
| 4317 | - $fond_origine = $fond; |
|
| 4318 | - // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4319 | - if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4320 | - list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 4321 | - } |
|
| 4322 | - |
|
| 4323 | - // Ajouter le type d'objet dans la classe |
|
| 4324 | - $objet_type = substr(basename($fond), 0, -4); |
|
| 4325 | - $class_lien .= " $objet_type"; |
|
| 4326 | - $class_bouton .= " $objet_type"; |
|
| 4327 | - |
|
| 4328 | - // Texte |
|
| 4329 | - $alt = attribut_html($texte); |
|
| 4330 | - $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4331 | - |
|
| 4332 | - // Liens : préparer les classes ajax |
|
| 4333 | - $ajax = ''; |
|
| 4334 | - if ($type === 'lien') { |
|
| 4335 | - if (strpos($class_lien, 'ajax') !== false) { |
|
| 4336 | - $ajax = 'ajax'; |
|
| 4337 | - if (strpos($class_lien, 'preload') !== false) { |
|
| 4338 | - $ajax .= ' preload'; |
|
| 4339 | - } |
|
| 4340 | - if (strpos($class_lien, 'nocache') !== false) { |
|
| 4341 | - $ajax .= ' nocache'; |
|
| 4342 | - } |
|
| 4343 | - $ajax = " class='$ajax'"; |
|
| 4344 | - } |
|
| 4345 | - } |
|
| 4346 | - |
|
| 4347 | - // Repérer la taille et l'ajouter dans la classe |
|
| 4348 | - $size = 24; |
|
| 4349 | - if ( |
|
| 4350 | - preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4351 | - or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4352 | - ) { |
|
| 4353 | - $size = $match[1]; |
|
| 4354 | - } |
|
| 4355 | - $class_lien .= " s$size"; |
|
| 4356 | - $class_bouton .= " s$size"; |
|
| 4357 | - |
|
| 4358 | - // Icône |
|
| 4359 | - $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4360 | - $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4361 | - |
|
| 4362 | - // Markup final |
|
| 4363 | - if ($type == 'lien') { |
|
| 4364 | - return "<span class='icone $class_lien'>" |
|
| 4365 | - . "<a href='$lien'$title$ajax$javascript>" |
|
| 4366 | - . $icone |
|
| 4367 | - . "<b>$texte</b>" |
|
| 4368 | - . "</a></span>\n"; |
|
| 4369 | - } else { |
|
| 4370 | - return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4371 | - } |
|
| 4305 | + $class_lien = $class_bouton = $class; |
|
| 4306 | + |
|
| 4307 | + // Normaliser la fonction et compléter la classe en fonction |
|
| 4308 | + if (in_array($fonction, ['del', 'supprimer.gif'])) { |
|
| 4309 | + $class_lien .= ' danger'; |
|
| 4310 | + $class_bouton .= ' btn_danger'; |
|
| 4311 | + } elseif ($fonction == 'rien.gif') { |
|
| 4312 | + $fonction = ''; |
|
| 4313 | + } elseif ($fonction == 'delsafe') { |
|
| 4314 | + $fonction = 'del'; |
|
| 4315 | + } |
|
| 4316 | + |
|
| 4317 | + $fond_origine = $fond; |
|
| 4318 | + // Remappage des icone : article-24.png+new => article-new-24.png |
|
| 4319 | + if ($icone_renommer = charger_fonction('icone_renommer', 'inc', true)) { |
|
| 4320 | + list($fond, $fonction) = $icone_renommer($fond, $fonction); |
|
| 4321 | + } |
|
| 4322 | + |
|
| 4323 | + // Ajouter le type d'objet dans la classe |
|
| 4324 | + $objet_type = substr(basename($fond), 0, -4); |
|
| 4325 | + $class_lien .= " $objet_type"; |
|
| 4326 | + $class_bouton .= " $objet_type"; |
|
| 4327 | + |
|
| 4328 | + // Texte |
|
| 4329 | + $alt = attribut_html($texte); |
|
| 4330 | + $title = " title=\"$alt\""; // est-ce pertinent de doubler le alt par un title ? |
|
| 4331 | + |
|
| 4332 | + // Liens : préparer les classes ajax |
|
| 4333 | + $ajax = ''; |
|
| 4334 | + if ($type === 'lien') { |
|
| 4335 | + if (strpos($class_lien, 'ajax') !== false) { |
|
| 4336 | + $ajax = 'ajax'; |
|
| 4337 | + if (strpos($class_lien, 'preload') !== false) { |
|
| 4338 | + $ajax .= ' preload'; |
|
| 4339 | + } |
|
| 4340 | + if (strpos($class_lien, 'nocache') !== false) { |
|
| 4341 | + $ajax .= ' nocache'; |
|
| 4342 | + } |
|
| 4343 | + $ajax = " class='$ajax'"; |
|
| 4344 | + } |
|
| 4345 | + } |
|
| 4346 | + |
|
| 4347 | + // Repérer la taille et l'ajouter dans la classe |
|
| 4348 | + $size = 24; |
|
| 4349 | + if ( |
|
| 4350 | + preg_match('/-([0-9]{1,3})[.](gif|png|svg)$/i', $fond, $match) |
|
| 4351 | + or preg_match('/-([0-9]{1,3})([.](gif|png|svg))?$/i', $fond_origine, $match) |
|
| 4352 | + ) { |
|
| 4353 | + $size = $match[1]; |
|
| 4354 | + } |
|
| 4355 | + $class_lien .= " s$size"; |
|
| 4356 | + $class_bouton .= " s$size"; |
|
| 4357 | + |
|
| 4358 | + // Icône |
|
| 4359 | + $icone = http_img_pack($fond, $alt, "width='$size' height='$size'"); |
|
| 4360 | + $icone = '<span class="icone-image' . ($fonction ? " icone-fonction icone-fonction-$fonction" : '') . "\">$icone</span>"; |
|
| 4361 | + |
|
| 4362 | + // Markup final |
|
| 4363 | + if ($type == 'lien') { |
|
| 4364 | + return "<span class='icone $class_lien'>" |
|
| 4365 | + . "<a href='$lien'$title$ajax$javascript>" |
|
| 4366 | + . $icone |
|
| 4367 | + . "<b>$texte</b>" |
|
| 4368 | + . "</a></span>\n"; |
|
| 4369 | + } else { |
|
| 4370 | + return bouton_action("$icone $texte", $lien, $class_bouton, $javascript, $alt); |
|
| 4371 | + } |
|
| 4372 | 4372 | } |
| 4373 | 4373 | |
| 4374 | 4374 | /** |
@@ -4392,7 +4392,7 @@ discard block |
||
| 4392 | 4392 | * Code HTML du lien |
| 4393 | 4393 | **/ |
| 4394 | 4394 | function icone_base($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4395 | - return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4395 | + return prepare_icone_base('lien', $lien, $texte, $fond, $fonction, $class, $javascript); |
|
| 4396 | 4396 | } |
| 4397 | 4397 | |
| 4398 | 4398 | /** |
@@ -4427,7 +4427,7 @@ discard block |
||
| 4427 | 4427 | * Code HTML du lien |
| 4428 | 4428 | **/ |
| 4429 | 4429 | function filtre_icone_verticale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4430 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4430 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $class", $javascript); |
|
| 4431 | 4431 | } |
| 4432 | 4432 | |
| 4433 | 4433 | /** |
@@ -4472,7 +4472,7 @@ discard block |
||
| 4472 | 4472 | * Code HTML du lien |
| 4473 | 4473 | **/ |
| 4474 | 4474 | function filtre_icone_horizontale_dist($lien, $texte, $fond, $fonction = '', $class = '', $javascript = '') { |
| 4475 | - return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4475 | + return icone_base($lien, $texte, $fond, $fonction, "horizontale $class", $javascript); |
|
| 4476 | 4476 | } |
| 4477 | 4477 | |
| 4478 | 4478 | /** |
@@ -4503,7 +4503,7 @@ discard block |
||
| 4503 | 4503 | * Code HTML du lien |
| 4504 | 4504 | **/ |
| 4505 | 4505 | function filtre_bouton_action_horizontal_dist($lien, $texte, $fond, $fonction = '', $class = '', $confirm = '') { |
| 4506 | - return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4506 | + return prepare_icone_base('bouton', $lien, $texte, $fond, $fonction, $class, $confirm); |
|
| 4507 | 4507 | } |
| 4508 | 4508 | |
| 4509 | 4509 | /** |
@@ -4534,7 +4534,7 @@ discard block |
||
| 4534 | 4534 | * Code HTML du lien |
| 4535 | 4535 | */ |
| 4536 | 4536 | function filtre_icone_dist($lien, $texte, $fond, $align = '', $fonction = '', $class = '', $javascript = '') { |
| 4537 | - return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4537 | + return icone_base($lien, $texte, $fond, $fonction, "verticale $align $class", $javascript); |
|
| 4538 | 4538 | } |
| 4539 | 4539 | |
| 4540 | 4540 | |
@@ -4556,7 +4556,7 @@ discard block |
||
| 4556 | 4556 | * @return array Liste des éléments |
| 4557 | 4557 | */ |
| 4558 | 4558 | function filtre_explode_dist($a, $b) { |
| 4559 | - return explode($b, $a); |
|
| 4559 | + return explode($b, $a); |
|
| 4560 | 4560 | } |
| 4561 | 4561 | |
| 4562 | 4562 | /** |
@@ -4577,7 +4577,7 @@ discard block |
||
| 4577 | 4577 | * @return string Texte |
| 4578 | 4578 | */ |
| 4579 | 4579 | function filtre_implode_dist($a, $b) { |
| 4580 | - return is_array($a) ? implode($b, $a) : $a; |
|
| 4580 | + return is_array($a) ? implode($b, $a) : $a; |
|
| 4581 | 4581 | } |
| 4582 | 4582 | |
| 4583 | 4583 | /** |
@@ -4586,24 +4586,24 @@ discard block |
||
| 4586 | 4586 | * @return string Code CSS |
| 4587 | 4587 | */ |
| 4588 | 4588 | function bando_images_background() { |
| 4589 | - include_spip('inc/bandeau'); |
|
| 4590 | - // recuperer tous les boutons et leurs images |
|
| 4591 | - $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4589 | + include_spip('inc/bandeau'); |
|
| 4590 | + // recuperer tous les boutons et leurs images |
|
| 4591 | + $boutons = definir_barre_boutons(definir_barre_contexte(), true, false); |
|
| 4592 | 4592 | |
| 4593 | - $res = ''; |
|
| 4594 | - foreach ($boutons as $page => $detail) { |
|
| 4595 | - $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4596 | - if (is_array($detail->sousmenu)) { |
|
| 4597 | - foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4598 | - if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4599 | - $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4600 | - $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4601 | - } |
|
| 4602 | - } |
|
| 4603 | - } |
|
| 4604 | - } |
|
| 4593 | + $res = ''; |
|
| 4594 | + foreach ($boutons as $page => $detail) { |
|
| 4595 | + $selecteur = (in_array($page, ['outils_rapides', 'outils_collaboratifs']) ? '' : '.navigation_avec_icones '); |
|
| 4596 | + if (is_array($detail->sousmenu)) { |
|
| 4597 | + foreach ($detail->sousmenu as $souspage => $sousdetail) { |
|
| 4598 | + if ($sousdetail->icone and strlen(trim($sousdetail->icone))) { |
|
| 4599 | + $img = http_img_variante_svg_si_possible($sousdetail->icone); |
|
| 4600 | + $res .= "\n$selecteur.bando2_$souspage {background-image:url($img);}"; |
|
| 4601 | + } |
|
| 4602 | + } |
|
| 4603 | + } |
|
| 4604 | + } |
|
| 4605 | 4605 | |
| 4606 | - return $res; |
|
| 4606 | + return $res; |
|
| 4607 | 4607 | } |
| 4608 | 4608 | |
| 4609 | 4609 | /** |
@@ -4628,27 +4628,27 @@ discard block |
||
| 4628 | 4628 | */ |
| 4629 | 4629 | function bouton_action($libelle, $url, $class = '', $confirm = '', $title = '', $callback = '') { |
| 4630 | 4630 | |
| 4631 | - // Classes : dispatcher `ajax` sur le formulaire |
|
| 4632 | - $class_form = ''; |
|
| 4633 | - if (strpos($class, 'ajax') !== false) { |
|
| 4634 | - $class_form = 'ajax'; |
|
| 4635 | - $class = str_replace('ajax', '', $class); |
|
| 4636 | - } |
|
| 4637 | - $class_btn = 'submit ' . trim($class); |
|
| 4631 | + // Classes : dispatcher `ajax` sur le formulaire |
|
| 4632 | + $class_form = ''; |
|
| 4633 | + if (strpos($class, 'ajax') !== false) { |
|
| 4634 | + $class_form = 'ajax'; |
|
| 4635 | + $class = str_replace('ajax', '', $class); |
|
| 4636 | + } |
|
| 4637 | + $class_btn = 'submit ' . trim($class); |
|
| 4638 | 4638 | |
| 4639 | - if ($confirm) { |
|
| 4640 | - $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4641 | - if ($callback) { |
|
| 4642 | - $callback = "$confirm?($callback):false"; |
|
| 4643 | - } else { |
|
| 4644 | - $callback = $confirm; |
|
| 4645 | - } |
|
| 4646 | - } |
|
| 4647 | - $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4648 | - $title = $title ? " title='$title'" : ''; |
|
| 4639 | + if ($confirm) { |
|
| 4640 | + $confirm = 'confirm("' . attribut_html($confirm) . '")'; |
|
| 4641 | + if ($callback) { |
|
| 4642 | + $callback = "$confirm?($callback):false"; |
|
| 4643 | + } else { |
|
| 4644 | + $callback = $confirm; |
|
| 4645 | + } |
|
| 4646 | + } |
|
| 4647 | + $onclick = $callback ? " onclick='return " . addcslashes($callback, "'") . "'" : ''; |
|
| 4648 | + $title = $title ? " title='$title'" : ''; |
|
| 4649 | 4649 | |
| 4650 | - return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4651 | - . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4650 | + return "<form class='bouton_action_post $class_form' method='post' action='$url'><div>" . form_hidden($url) |
|
| 4651 | + . "<button type='submit' class='$class_btn'$title$onclick>$libelle</button></div></form>"; |
|
| 4652 | 4652 | } |
| 4653 | 4653 | |
| 4654 | 4654 | /** |
@@ -4671,94 +4671,94 @@ discard block |
||
| 4671 | 4671 | * @return string |
| 4672 | 4672 | */ |
| 4673 | 4673 | function generer_info_entite($id_objet, $type_objet, $info, $etoile = '', $params = []) { |
| 4674 | - static $trouver_table = null; |
|
| 4675 | - static $objets; |
|
| 4676 | - |
|
| 4677 | - // On verifie qu'on a tout ce qu'il faut |
|
| 4678 | - $id_objet = intval($id_objet); |
|
| 4679 | - if (!($id_objet and $type_objet and $info)) { |
|
| 4680 | - return ''; |
|
| 4681 | - } |
|
| 4682 | - |
|
| 4683 | - // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4684 | - if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4685 | - return ''; |
|
| 4686 | - } |
|
| 4687 | - |
|
| 4688 | - // Si on demande l'url, on retourne direct la fonction |
|
| 4689 | - if ($info == 'url') { |
|
| 4690 | - return generer_url_entite($id_objet, $type_objet, ...$params); |
|
| 4691 | - } |
|
| 4692 | - |
|
| 4693 | - // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4694 | - $demande_titre = ($info === 'titre'); |
|
| 4695 | - $demande_introduction = ($info === 'introduction'); |
|
| 4696 | - |
|
| 4697 | - // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4698 | - if ( |
|
| 4699 | - !isset($objets[$type_objet][$id_objet]) |
|
| 4700 | - or |
|
| 4701 | - ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4702 | - ) { |
|
| 4703 | - if (!$trouver_table) { |
|
| 4704 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4705 | - } |
|
| 4706 | - $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4707 | - if (!$desc) { |
|
| 4708 | - return $objets[$type_objet] = false; |
|
| 4709 | - } |
|
| 4710 | - |
|
| 4711 | - // Si on demande le titre, on le gere en interne |
|
| 4712 | - $champ_titre = ''; |
|
| 4713 | - if ($demande_titre) { |
|
| 4714 | - // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4715 | - $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4716 | - } |
|
| 4717 | - include_spip('base/abstract_sql'); |
|
| 4718 | - include_spip('base/connect_sql'); |
|
| 4719 | - $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4720 | - '*' . $champ_titre, |
|
| 4721 | - $desc['table_sql'], |
|
| 4722 | - id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4723 | - ); |
|
| 4724 | - |
|
| 4725 | - // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4726 | - $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4727 | - } |
|
| 4728 | - |
|
| 4729 | - // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4730 | - // ajouter la longueur au début des params supplémentaires |
|
| 4731 | - if ($demande_introduction) { |
|
| 4732 | - $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4733 | - array_unshift($params, $introduction_longueur); |
|
| 4734 | - } |
|
| 4735 | - |
|
| 4736 | - // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4737 | - if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4738 | - $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4739 | - } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4740 | - else { |
|
| 4741 | - if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4742 | - $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4743 | - } // Sinon on prend directement le champ SQL tel quel |
|
| 4744 | - else { |
|
| 4745 | - $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4746 | - } |
|
| 4747 | - } |
|
| 4748 | - |
|
| 4749 | - // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4750 | - if (!$etoile) { |
|
| 4751 | - // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4752 | - // mais ce fonctionnement est a ameliorer ! |
|
| 4753 | - $info_generee = appliquer_traitement_champ( |
|
| 4754 | - $info_generee, |
|
| 4755 | - $info, |
|
| 4756 | - table_objet($type_objet), |
|
| 4757 | - ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4758 | - ); |
|
| 4759 | - } |
|
| 4760 | - |
|
| 4761 | - return $info_generee; |
|
| 4674 | + static $trouver_table = null; |
|
| 4675 | + static $objets; |
|
| 4676 | + |
|
| 4677 | + // On verifie qu'on a tout ce qu'il faut |
|
| 4678 | + $id_objet = intval($id_objet); |
|
| 4679 | + if (!($id_objet and $type_objet and $info)) { |
|
| 4680 | + return ''; |
|
| 4681 | + } |
|
| 4682 | + |
|
| 4683 | + // si on a deja note que l'objet n'existe pas, ne pas aller plus loin |
|
| 4684 | + if (isset($objets[$type_objet]) and $objets[$type_objet] === false) { |
|
| 4685 | + return ''; |
|
| 4686 | + } |
|
| 4687 | + |
|
| 4688 | + // Si on demande l'url, on retourne direct la fonction |
|
| 4689 | + if ($info == 'url') { |
|
| 4690 | + return generer_url_entite($id_objet, $type_objet, ...$params); |
|
| 4691 | + } |
|
| 4692 | + |
|
| 4693 | + // Sinon on va tout chercher dans la table et on garde en memoire |
|
| 4694 | + $demande_titre = ($info === 'titre'); |
|
| 4695 | + $demande_introduction = ($info === 'introduction'); |
|
| 4696 | + |
|
| 4697 | + // On ne fait la requete que si on a pas deja l'objet ou si on demande le titre mais qu'on ne l'a pas encore |
|
| 4698 | + if ( |
|
| 4699 | + !isset($objets[$type_objet][$id_objet]) |
|
| 4700 | + or |
|
| 4701 | + ($demande_titre and !isset($objets[$type_objet][$id_objet]['titre'])) |
|
| 4702 | + ) { |
|
| 4703 | + if (!$trouver_table) { |
|
| 4704 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 4705 | + } |
|
| 4706 | + $desc = $trouver_table(table_objet_sql($type_objet)); |
|
| 4707 | + if (!$desc) { |
|
| 4708 | + return $objets[$type_objet] = false; |
|
| 4709 | + } |
|
| 4710 | + |
|
| 4711 | + // Si on demande le titre, on le gere en interne |
|
| 4712 | + $champ_titre = ''; |
|
| 4713 | + if ($demande_titre) { |
|
| 4714 | + // si pas de titre declare mais champ titre, il sera peuple par le select * |
|
| 4715 | + $champ_titre = (!empty($desc['titre'])) ? ', ' . $desc['titre'] : ''; |
|
| 4716 | + } |
|
| 4717 | + include_spip('base/abstract_sql'); |
|
| 4718 | + include_spip('base/connect_sql'); |
|
| 4719 | + $objets[$type_objet][$id_objet] = sql_fetsel( |
|
| 4720 | + '*' . $champ_titre, |
|
| 4721 | + $desc['table_sql'], |
|
| 4722 | + id_table_objet($type_objet) . ' = ' . intval($id_objet) |
|
| 4723 | + ); |
|
| 4724 | + |
|
| 4725 | + // Toujours noter la longueur d'introduction, même si pas demandé cette fois-ci |
|
| 4726 | + $objets[$type_objet]['introduction_longueur'] = $desc['introduction_longueur'] ?? null; |
|
| 4727 | + } |
|
| 4728 | + |
|
| 4729 | + // Pour les fonction generer_xxx, si on demande l'introduction, |
|
| 4730 | + // ajouter la longueur au début des params supplémentaires |
|
| 4731 | + if ($demande_introduction) { |
|
| 4732 | + $introduction_longueur = $objets[$type_objet]['introduction_longueur']; |
|
| 4733 | + array_unshift($params, $introduction_longueur); |
|
| 4734 | + } |
|
| 4735 | + |
|
| 4736 | + // Si la fonction generer_TRUC_TYPE existe, on l'utilise pour formater $info_generee |
|
| 4737 | + if ($generer = charger_fonction("generer_${info}_${type_objet}", '', true)) { |
|
| 4738 | + $info_generee = $generer($id_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4739 | + } // Si la fonction generer_TRUC_entite existe, on l'utilise pour formater $info_generee |
|
| 4740 | + else { |
|
| 4741 | + if ($generer = charger_fonction("generer_${info}_entite", '', true)) { |
|
| 4742 | + $info_generee = $generer($id_objet, $type_objet, $objets[$type_objet][$id_objet], ...$params); |
|
| 4743 | + } // Sinon on prend directement le champ SQL tel quel |
|
| 4744 | + else { |
|
| 4745 | + $info_generee = (isset($objets[$type_objet][$id_objet][$info]) ? $objets[$type_objet][$id_objet][$info] : ''); |
|
| 4746 | + } |
|
| 4747 | + } |
|
| 4748 | + |
|
| 4749 | + // On va ensuite appliquer les traitements automatiques si besoin |
|
| 4750 | + if (!$etoile) { |
|
| 4751 | + // FIXME: on fournit un ENV minimum avec id et type et connect='' |
|
| 4752 | + // mais ce fonctionnement est a ameliorer ! |
|
| 4753 | + $info_generee = appliquer_traitement_champ( |
|
| 4754 | + $info_generee, |
|
| 4755 | + $info, |
|
| 4756 | + table_objet($type_objet), |
|
| 4757 | + ['id_objet' => $id_objet, 'objet' => $type_objet, ''] |
|
| 4758 | + ); |
|
| 4759 | + } |
|
| 4760 | + |
|
| 4761 | + return $info_generee; |
|
| 4762 | 4762 | } |
| 4763 | 4763 | |
| 4764 | 4764 | /** |
@@ -4791,36 +4791,36 @@ discard block |
||
| 4791 | 4791 | */ |
| 4792 | 4792 | function generer_introduction_entite($id_objet, $type_objet, $ligne_sql, $introduction_longueur = null, $longueur_ou_suite = null, $suite = null, $connect = '') { |
| 4793 | 4793 | |
| 4794 | - $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4795 | - $texte = $ligne_sql['texte'] ?? ''; |
|
| 4796 | - // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4797 | - if (isset($ligne_sql['chapo'])) { |
|
| 4798 | - $chapo = $ligne_sql['chapo']; |
|
| 4799 | - $texte = strlen($descriptif) ? |
|
| 4800 | - '' : |
|
| 4801 | - "$chapo \n\n $texte"; |
|
| 4802 | - } |
|
| 4794 | + $descriptif = $ligne_sql['descriptif'] ?? ''; |
|
| 4795 | + $texte = $ligne_sql['texte'] ?? ''; |
|
| 4796 | + // En absence de descriptif, on se rabat sur chapo + texte |
|
| 4797 | + if (isset($ligne_sql['chapo'])) { |
|
| 4798 | + $chapo = $ligne_sql['chapo']; |
|
| 4799 | + $texte = strlen($descriptif) ? |
|
| 4800 | + '' : |
|
| 4801 | + "$chapo \n\n $texte"; |
|
| 4802 | + } |
|
| 4803 | 4803 | |
| 4804 | - // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4805 | - if (!intval($longueur_ou_suite)) { |
|
| 4806 | - $longueur = intval($introduction_longueur ?: 600); |
|
| 4807 | - } else { |
|
| 4808 | - $longueur = intval($longueur_ou_suite); |
|
| 4809 | - } |
|
| 4804 | + // Longueur en paramètre, sinon celle renseignée dans la description de l'objet, sinon valeur en dur |
|
| 4805 | + if (!intval($longueur_ou_suite)) { |
|
| 4806 | + $longueur = intval($introduction_longueur ?: 600); |
|
| 4807 | + } else { |
|
| 4808 | + $longueur = intval($longueur_ou_suite); |
|
| 4809 | + } |
|
| 4810 | 4810 | |
| 4811 | - // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4812 | - // Ex : #INTRODUCTION{...} |
|
| 4813 | - if ( |
|
| 4814 | - is_null($suite) |
|
| 4815 | - and !intval($longueur_ou_suite) |
|
| 4816 | - ) { |
|
| 4817 | - $suite = $longueur_ou_suite; |
|
| 4818 | - } |
|
| 4811 | + // On peut optionnellement passer la suite en 1er paramètre de la balise |
|
| 4812 | + // Ex : #INTRODUCTION{...} |
|
| 4813 | + if ( |
|
| 4814 | + is_null($suite) |
|
| 4815 | + and !intval($longueur_ou_suite) |
|
| 4816 | + ) { |
|
| 4817 | + $suite = $longueur_ou_suite; |
|
| 4818 | + } |
|
| 4819 | 4819 | |
| 4820 | - $f = chercher_filtre('introduction'); |
|
| 4821 | - $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4820 | + $f = chercher_filtre('introduction'); |
|
| 4821 | + $introduction = $f($descriptif, $texte, $longueur, $connect, $suite); |
|
| 4822 | 4822 | |
| 4823 | - return $introduction; |
|
| 4823 | + return $introduction; |
|
| 4824 | 4824 | } |
| 4825 | 4825 | |
| 4826 | 4826 | /** |
@@ -4834,44 +4834,44 @@ discard block |
||
| 4834 | 4834 | * @return string |
| 4835 | 4835 | */ |
| 4836 | 4836 | function appliquer_traitement_champ($texte, $champ, $table_objet = '', $env = [], $connect = '') { |
| 4837 | - if (!$champ) { |
|
| 4838 | - return $texte; |
|
| 4839 | - } |
|
| 4837 | + if (!$champ) { |
|
| 4838 | + return $texte; |
|
| 4839 | + } |
|
| 4840 | 4840 | |
| 4841 | - // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4842 | - // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4843 | - include_fichiers_fonctions(); |
|
| 4841 | + // On charge les définitions des traitements (inc/texte et fichiers de fonctions) |
|
| 4842 | + // car il ne faut pas partir du principe que c'est déjà chargé (form ajax, etc) |
|
| 4843 | + include_fichiers_fonctions(); |
|
| 4844 | 4844 | |
| 4845 | - $champ = strtoupper($champ); |
|
| 4846 | - $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4847 | - if (!$traitements or !is_array($traitements)) { |
|
| 4848 | - return $texte; |
|
| 4849 | - } |
|
| 4845 | + $champ = strtoupper($champ); |
|
| 4846 | + $traitements = isset($GLOBALS['table_des_traitements'][$champ]) ? $GLOBALS['table_des_traitements'][$champ] : false; |
|
| 4847 | + if (!$traitements or !is_array($traitements)) { |
|
| 4848 | + return $texte; |
|
| 4849 | + } |
|
| 4850 | 4850 | |
| 4851 | - $traitement = ''; |
|
| 4852 | - if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4853 | - // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4854 | - $table_objet = table_objet($table_objet); |
|
| 4855 | - if (isset($traitements[$table_objet])) { |
|
| 4856 | - $traitement = $traitements[$table_objet]; |
|
| 4857 | - } |
|
| 4858 | - } |
|
| 4859 | - if (!$traitement and isset($traitements[0])) { |
|
| 4860 | - $traitement = $traitements[0]; |
|
| 4861 | - } |
|
| 4862 | - // (sinon prendre le premier de la liste par defaut ?) |
|
| 4851 | + $traitement = ''; |
|
| 4852 | + if ($table_objet and (!isset($traitements[0]) or count($traitements) > 1)) { |
|
| 4853 | + // necessaire pour prendre en charge les vieux appels avec un table_objet_sql en 3e arg |
|
| 4854 | + $table_objet = table_objet($table_objet); |
|
| 4855 | + if (isset($traitements[$table_objet])) { |
|
| 4856 | + $traitement = $traitements[$table_objet]; |
|
| 4857 | + } |
|
| 4858 | + } |
|
| 4859 | + if (!$traitement and isset($traitements[0])) { |
|
| 4860 | + $traitement = $traitements[0]; |
|
| 4861 | + } |
|
| 4862 | + // (sinon prendre le premier de la liste par defaut ?) |
|
| 4863 | 4863 | |
| 4864 | - if (!$traitement) { |
|
| 4865 | - return $texte; |
|
| 4866 | - } |
|
| 4864 | + if (!$traitement) { |
|
| 4865 | + return $texte; |
|
| 4866 | + } |
|
| 4867 | 4867 | |
| 4868 | - $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4868 | + $traitement = str_replace('%s', "'" . texte_script($texte) . "'", $traitement); |
|
| 4869 | 4869 | |
| 4870 | - // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | - $Pile = [0 => $env]; |
|
| 4872 | - eval("\$texte = $traitement;"); |
|
| 4870 | + // Fournir $connect et $Pile[0] au traitement si besoin |
|
| 4871 | + $Pile = [0 => $env]; |
|
| 4872 | + eval("\$texte = $traitement;"); |
|
| 4873 | 4873 | |
| 4874 | - return $texte; |
|
| 4874 | + return $texte; |
|
| 4875 | 4875 | } |
| 4876 | 4876 | |
| 4877 | 4877 | |
@@ -4885,21 +4885,21 @@ discard block |
||
| 4885 | 4885 | * @return string |
| 4886 | 4886 | */ |
| 4887 | 4887 | function generer_lien_entite($id_objet, $objet, $longueur = 80, $connect = null) { |
| 4888 | - include_spip('inc/liens'); |
|
| 4889 | - $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | - // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | - // le raccourcis n'est plus valide |
|
| 4892 | - $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4893 | - // on essaye avec generer_info_entite ? |
|
| 4894 | - if (!strlen($titre) and !$connect) { |
|
| 4895 | - $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4896 | - } |
|
| 4897 | - if (!strlen($titre)) { |
|
| 4898 | - $titre = _T('info_sans_titre'); |
|
| 4899 | - } |
|
| 4900 | - $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4888 | + include_spip('inc/liens'); |
|
| 4889 | + $titre = traiter_raccourci_titre($id_objet, $objet, $connect); |
|
| 4890 | + // lorsque l'objet n'est plus declare (plugin desactive par exemple) |
|
| 4891 | + // le raccourcis n'est plus valide |
|
| 4892 | + $titre = isset($titre['titre']) ? typo($titre['titre']) : ''; |
|
| 4893 | + // on essaye avec generer_info_entite ? |
|
| 4894 | + if (!strlen($titre) and !$connect) { |
|
| 4895 | + $titre = generer_info_entite($id_objet, $objet, 'titre'); |
|
| 4896 | + } |
|
| 4897 | + if (!strlen($titre)) { |
|
| 4898 | + $titre = _T('info_sans_titre'); |
|
| 4899 | + } |
|
| 4900 | + $url = generer_url_entite($id_objet, $objet, '', '', $connect); |
|
| 4901 | 4901 | |
| 4902 | - return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4902 | + return "<a href='$url' class='$objet'>" . couper($titre, $longueur) . '</a>'; |
|
| 4903 | 4903 | } |
| 4904 | 4904 | |
| 4905 | 4905 | |
@@ -4916,15 +4916,15 @@ discard block |
||
| 4916 | 4916 | * @return string |
| 4917 | 4917 | */ |
| 4918 | 4918 | function wrap($texte, $wrap) { |
| 4919 | - $balises = extraire_balises($wrap); |
|
| 4920 | - if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | - $texte = $wrap . $texte; |
|
| 4922 | - $regs = array_reverse($regs[1]); |
|
| 4923 | - $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | - $texte = $texte . $wrap; |
|
| 4925 | - } |
|
| 4919 | + $balises = extraire_balises($wrap); |
|
| 4920 | + if (preg_match_all(",<([a-z]\w*)\b[^>]*>,UimsS", $wrap, $regs, PREG_PATTERN_ORDER)) { |
|
| 4921 | + $texte = $wrap . $texte; |
|
| 4922 | + $regs = array_reverse($regs[1]); |
|
| 4923 | + $wrap = '</' . implode('></', $regs) . '>'; |
|
| 4924 | + $texte = $texte . $wrap; |
|
| 4925 | + } |
|
| 4926 | 4926 | |
| 4927 | - return $texte; |
|
| 4927 | + return $texte; |
|
| 4928 | 4928 | } |
| 4929 | 4929 | |
| 4930 | 4930 | |
@@ -4944,44 +4944,44 @@ discard block |
||
| 4944 | 4944 | * @return array|mixed|string |
| 4945 | 4945 | */ |
| 4946 | 4946 | function filtre_print_dist($u, $join = '<br />', $indent = 0) { |
| 4947 | - if (is_string($u)) { |
|
| 4948 | - $u = typo($u); |
|
| 4947 | + if (is_string($u)) { |
|
| 4948 | + $u = typo($u); |
|
| 4949 | 4949 | |
| 4950 | - return $u; |
|
| 4951 | - } |
|
| 4950 | + return $u; |
|
| 4951 | + } |
|
| 4952 | 4952 | |
| 4953 | - // caster $u en array si besoin |
|
| 4954 | - if (is_object($u)) { |
|
| 4955 | - $u = (array)$u; |
|
| 4956 | - } |
|
| 4953 | + // caster $u en array si besoin |
|
| 4954 | + if (is_object($u)) { |
|
| 4955 | + $u = (array)$u; |
|
| 4956 | + } |
|
| 4957 | 4957 | |
| 4958 | - if (is_array($u)) { |
|
| 4959 | - $out = ''; |
|
| 4960 | - // toutes les cles sont numeriques ? |
|
| 4961 | - // et aucun enfant n'est un tableau |
|
| 4962 | - // liste simple separee par des virgules |
|
| 4963 | - $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | - $array_values = array_map('is_array', $u); |
|
| 4965 | - $object_values = array_map('is_object', $u); |
|
| 4966 | - if ( |
|
| 4967 | - array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | - and !array_sum($array_values) |
|
| 4969 | - and !array_sum($object_values) |
|
| 4970 | - ) { |
|
| 4971 | - return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | - } |
|
| 4958 | + if (is_array($u)) { |
|
| 4959 | + $out = ''; |
|
| 4960 | + // toutes les cles sont numeriques ? |
|
| 4961 | + // et aucun enfant n'est un tableau |
|
| 4962 | + // liste simple separee par des virgules |
|
| 4963 | + $numeric_keys = array_map('is_numeric', array_keys($u)); |
|
| 4964 | + $array_values = array_map('is_array', $u); |
|
| 4965 | + $object_values = array_map('is_object', $u); |
|
| 4966 | + if ( |
|
| 4967 | + array_sum($numeric_keys) == count($numeric_keys) |
|
| 4968 | + and !array_sum($array_values) |
|
| 4969 | + and !array_sum($object_values) |
|
| 4970 | + ) { |
|
| 4971 | + return join(', ', array_map('filtre_print_dist', $u)); |
|
| 4972 | + } |
|
| 4973 | 4973 | |
| 4974 | - // sinon on passe a la ligne et on indente |
|
| 4975 | - $i_str = str_pad('', $indent, ' '); |
|
| 4976 | - foreach ($u as $k => $v) { |
|
| 4977 | - $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | - } |
|
| 4974 | + // sinon on passe a la ligne et on indente |
|
| 4975 | + $i_str = str_pad('', $indent, ' '); |
|
| 4976 | + foreach ($u as $k => $v) { |
|
| 4977 | + $out .= $join . $i_str . "$k: " . filtre_print_dist($v, $join, $indent + 2); |
|
| 4978 | + } |
|
| 4979 | 4979 | |
| 4980 | - return $out; |
|
| 4981 | - } |
|
| 4980 | + return $out; |
|
| 4981 | + } |
|
| 4982 | 4982 | |
| 4983 | - // on sait pas quoi faire... |
|
| 4984 | - return $u; |
|
| 4983 | + // on sait pas quoi faire... |
|
| 4984 | + return $u; |
|
| 4985 | 4985 | } |
| 4986 | 4986 | |
| 4987 | 4987 | |
@@ -4994,10 +4994,10 @@ discard block |
||
| 4994 | 4994 | * @return string|array |
| 4995 | 4995 | */ |
| 4996 | 4996 | function objet_info($objet, $info) { |
| 4997 | - $table = table_objet_sql($objet); |
|
| 4998 | - $infos = lister_tables_objets_sql($table); |
|
| 4997 | + $table = table_objet_sql($objet); |
|
| 4998 | + $infos = lister_tables_objets_sql($table); |
|
| 4999 | 4999 | |
| 5000 | - return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 5000 | + return (isset($infos[$info]) ? $infos[$info] : ''); |
|
| 5001 | 5001 | } |
| 5002 | 5002 | |
| 5003 | 5003 | /** |
@@ -5012,11 +5012,11 @@ discard block |
||
| 5012 | 5012 | * Texte traduit du comptage, tel que '3 articles' |
| 5013 | 5013 | */ |
| 5014 | 5014 | function objet_afficher_nb($nb, $objet) { |
| 5015 | - if (!$nb) { |
|
| 5016 | - return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | - } else { |
|
| 5018 | - return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | - } |
|
| 5015 | + if (!$nb) { |
|
| 5016 | + return _T(objet_info($objet, 'info_aucun_objet')); |
|
| 5017 | + } else { |
|
| 5018 | + return _T(objet_info($objet, $nb == 1 ? 'info_1_objet' : 'info_nb_objets'), ['nb' => $nb]); |
|
| 5019 | + } |
|
| 5020 | 5020 | } |
| 5021 | 5021 | |
| 5022 | 5022 | /** |
@@ -5028,11 +5028,11 @@ discard block |
||
| 5028 | 5028 | * @return string |
| 5029 | 5029 | */ |
| 5030 | 5030 | function objet_icone($objet, $taille = 24, $class = '') { |
| 5031 | - $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | - $icone = chemin_image($icone); |
|
| 5033 | - $balise_img = charger_filtre('balise_img'); |
|
| 5031 | + $icone = objet_info($objet, 'icone_objet') . '-' . $taille . '.png'; |
|
| 5032 | + $icone = chemin_image($icone); |
|
| 5033 | + $balise_img = charger_filtre('balise_img'); |
|
| 5034 | 5034 | |
| 5035 | - return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5035 | + return $icone ? $balise_img($icone, _T(objet_info($objet, 'texte_objet')), $class, $taille) : ''; |
|
| 5036 | 5036 | } |
| 5037 | 5037 | |
| 5038 | 5038 | /** |
@@ -5053,12 +5053,12 @@ discard block |
||
| 5053 | 5053 | * @return string |
| 5054 | 5054 | */ |
| 5055 | 5055 | function objet_T($objet, $chaine, $args = [], $options = []) { |
| 5056 | - $chaine = explode(':', $chaine); |
|
| 5057 | - if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | - return $t; |
|
| 5059 | - } |
|
| 5060 | - $chaine = implode(':', $chaine); |
|
| 5061 | - return _T($chaine, $args, $options); |
|
| 5056 | + $chaine = explode(':', $chaine); |
|
| 5057 | + if ($t = _T($objet . ':' . end($chaine), $args, array_merge($options, ['force' => false]))) { |
|
| 5058 | + return $t; |
|
| 5059 | + } |
|
| 5060 | + $chaine = implode(':', $chaine); |
|
| 5061 | + return _T($chaine, $args, $options); |
|
| 5062 | 5062 | } |
| 5063 | 5063 | |
| 5064 | 5064 | /** |
@@ -5072,18 +5072,18 @@ discard block |
||
| 5072 | 5072 | * @return string Code HTML |
| 5073 | 5073 | */ |
| 5074 | 5074 | function insert_head_css_conditionnel($flux) { |
| 5075 | - if ( |
|
| 5076 | - strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | - and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | - ) { |
|
| 5079 | - // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | - if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | - $p = $p1; |
|
| 5082 | - } |
|
| 5083 | - $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | - } |
|
| 5075 | + if ( |
|
| 5076 | + strpos($flux, '<!-- insert_head_css -->') === false |
|
| 5077 | + and $p = strpos($flux, '<!-- insert_head -->') |
|
| 5078 | + ) { |
|
| 5079 | + // plutot avant le premier js externe (jquery) pour etre non bloquant |
|
| 5080 | + if ($p1 = stripos($flux, '<script src=') and $p1 < $p) { |
|
| 5081 | + $p = $p1; |
|
| 5082 | + } |
|
| 5083 | + $flux = substr_replace($flux, pipeline('insert_head_css', '<!-- insert_head_css -->'), $p, 0); |
|
| 5084 | + } |
|
| 5085 | 5085 | |
| 5086 | - return $flux; |
|
| 5086 | + return $flux; |
|
| 5087 | 5087 | } |
| 5088 | 5088 | |
| 5089 | 5089 | /** |
@@ -5106,72 +5106,72 @@ discard block |
||
| 5106 | 5106 | * @return string |
| 5107 | 5107 | */ |
| 5108 | 5108 | function produire_fond_statique($fond, $contexte = [], $options = [], $connect = '') { |
| 5109 | - if (isset($contexte['format'])) { |
|
| 5110 | - $extension = $contexte['format']; |
|
| 5111 | - unset($contexte['format']); |
|
| 5112 | - } else { |
|
| 5113 | - $extension = 'html'; |
|
| 5114 | - if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | - $extension = $m[1]; |
|
| 5116 | - } |
|
| 5117 | - } |
|
| 5118 | - // recuperer le contenu produit par le squelette |
|
| 5119 | - $options['raw'] = true; |
|
| 5120 | - $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | - |
|
| 5122 | - // calculer le nom de la css |
|
| 5123 | - $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | - $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | - $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | - |
|
| 5127 | - // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | - // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | - // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | - if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | - $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | - } |
|
| 5133 | - else { |
|
| 5134 | - unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | - ksort($contexte); |
|
| 5136 | - $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 5137 | - } |
|
| 5138 | - $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | - |
|
| 5140 | - // mettre a jour le fichier si il n'existe pas |
|
| 5141 | - // ou trop ancien |
|
| 5142 | - // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | - // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | - if ( |
|
| 5145 | - !file_exists($filename) |
|
| 5146 | - or !file_exists($filename . '.last') |
|
| 5147 | - or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | - ) { |
|
| 5150 | - $contenu = $cache['texte']; |
|
| 5151 | - // passer les urls en absolu si c'est une css |
|
| 5152 | - if ($extension == 'css') { |
|
| 5153 | - $contenu = urls_absolues_css( |
|
| 5154 | - $contenu, |
|
| 5155 | - test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | - ); |
|
| 5157 | - } |
|
| 5158 | - |
|
| 5159 | - $comment = ''; |
|
| 5160 | - // ne pas insérer de commentaire sur certains formats |
|
| 5161 | - if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | - $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | - foreach ($contexte as $k => $v) { |
|
| 5164 | - $comment .= ",$k=$v"; |
|
| 5165 | - } |
|
| 5166 | - // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5167 | - // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5168 | - $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5169 | - } |
|
| 5170 | - // et ecrire le fichier si il change |
|
| 5171 | - ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5172 | - } |
|
| 5173 | - |
|
| 5174 | - return timestamp($filename); |
|
| 5109 | + if (isset($contexte['format'])) { |
|
| 5110 | + $extension = $contexte['format']; |
|
| 5111 | + unset($contexte['format']); |
|
| 5112 | + } else { |
|
| 5113 | + $extension = 'html'; |
|
| 5114 | + if (preg_match(',[.](css|js|json|xml|svg)$,', $fond, $m)) { |
|
| 5115 | + $extension = $m[1]; |
|
| 5116 | + } |
|
| 5117 | + } |
|
| 5118 | + // recuperer le contenu produit par le squelette |
|
| 5119 | + $options['raw'] = true; |
|
| 5120 | + $cache = recuperer_fond($fond, $contexte, $options, $connect); |
|
| 5121 | + |
|
| 5122 | + // calculer le nom de la css |
|
| 5123 | + $dir_var = sous_repertoire(_DIR_VAR, 'cache-' . $extension); |
|
| 5124 | + $nom_safe = preg_replace(',\W,', '_', str_replace('.', '_', $fond)); |
|
| 5125 | + $contexte_implicite = calculer_contexte_implicite(); |
|
| 5126 | + |
|
| 5127 | + // par defaut on hash selon les contextes qui sont a priori moins variables |
|
| 5128 | + // mais on peut hasher selon le contenu a la demande, si plusieurs contextes produisent un meme contenu |
|
| 5129 | + // reduit la variabilite du nom et donc le nombre de css concatenees possibles in fine |
|
| 5130 | + if (isset($options['hash_on_content']) and $options['hash_on_content']) { |
|
| 5131 | + $hash = md5($contexte_implicite['host'] . '::' . $cache); |
|
| 5132 | + } |
|
| 5133 | + else { |
|
| 5134 | + unset($contexte_implicite['notes']); // pas pertinent pour signaler un changeemnt de contenu pour des css/js |
|
| 5135 | + ksort($contexte); |
|
| 5136 | + $hash = md5($fond . json_encode($contexte_implicite) . json_encode($contexte) . $connect); |
|
| 5137 | + } |
|
| 5138 | + $filename = $dir_var . $extension . "dyn-$nom_safe-" . substr($hash, 0, 8) . ".$extension"; |
|
| 5139 | + |
|
| 5140 | + // mettre a jour le fichier si il n'existe pas |
|
| 5141 | + // ou trop ancien |
|
| 5142 | + // le dernier fichier produit est toujours suffixe par .last |
|
| 5143 | + // et recopie sur le fichier cible uniquement si il change |
|
| 5144 | + if ( |
|
| 5145 | + !file_exists($filename) |
|
| 5146 | + or !file_exists($filename . '.last') |
|
| 5147 | + or (isset($cache['lastmodified']) and $cache['lastmodified'] and filemtime($filename . '.last') < $cache['lastmodified']) |
|
| 5148 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 5149 | + ) { |
|
| 5150 | + $contenu = $cache['texte']; |
|
| 5151 | + // passer les urls en absolu si c'est une css |
|
| 5152 | + if ($extension == 'css') { |
|
| 5153 | + $contenu = urls_absolues_css( |
|
| 5154 | + $contenu, |
|
| 5155 | + test_espace_prive() ? generer_url_ecrire('accueil') : generer_url_public($fond) |
|
| 5156 | + ); |
|
| 5157 | + } |
|
| 5158 | + |
|
| 5159 | + $comment = ''; |
|
| 5160 | + // ne pas insérer de commentaire sur certains formats |
|
| 5161 | + if (!in_array($extension, ['json', 'xml', 'svg'])) { |
|
| 5162 | + $comment = "/* #PRODUIRE{fond=$fond"; |
|
| 5163 | + foreach ($contexte as $k => $v) { |
|
| 5164 | + $comment .= ",$k=$v"; |
|
| 5165 | + } |
|
| 5166 | + // pas de date dans le commentaire car sinon ca invalide le md5 et force la maj |
|
| 5167 | + // mais on peut mettre un md5 du contenu, ce qui donne un aperu rapide si la feuille a change ou non |
|
| 5168 | + $comment .= "}\n md5:" . md5($contenu) . " */\n"; |
|
| 5169 | + } |
|
| 5170 | + // et ecrire le fichier si il change |
|
| 5171 | + ecrire_fichier_calcule_si_modifie($filename, $comment . $contenu, false, true); |
|
| 5172 | + } |
|
| 5173 | + |
|
| 5174 | + return timestamp($filename); |
|
| 5175 | 5175 | } |
| 5176 | 5176 | |
| 5177 | 5177 | /** |
@@ -5184,15 +5184,15 @@ discard block |
||
| 5184 | 5184 | * $fichier auquel on a ajouté le timestamp |
| 5185 | 5185 | */ |
| 5186 | 5186 | function timestamp($fichier) { |
| 5187 | - if ( |
|
| 5188 | - !$fichier |
|
| 5189 | - or !file_exists($fichier) |
|
| 5190 | - or !$m = filemtime($fichier) |
|
| 5191 | - ) { |
|
| 5192 | - return $fichier; |
|
| 5193 | - } |
|
| 5187 | + if ( |
|
| 5188 | + !$fichier |
|
| 5189 | + or !file_exists($fichier) |
|
| 5190 | + or !$m = filemtime($fichier) |
|
| 5191 | + ) { |
|
| 5192 | + return $fichier; |
|
| 5193 | + } |
|
| 5194 | 5194 | |
| 5195 | - return "$fichier?$m"; |
|
| 5195 | + return "$fichier?$m"; |
|
| 5196 | 5196 | } |
| 5197 | 5197 | |
| 5198 | 5198 | /** |
@@ -5202,11 +5202,11 @@ discard block |
||
| 5202 | 5202 | * @return string |
| 5203 | 5203 | */ |
| 5204 | 5204 | function supprimer_timestamp($url) { |
| 5205 | - if (strpos($url, '?') === false) { |
|
| 5206 | - return $url; |
|
| 5207 | - } |
|
| 5205 | + if (strpos($url, '?') === false) { |
|
| 5206 | + return $url; |
|
| 5207 | + } |
|
| 5208 | 5208 | |
| 5209 | - return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5209 | + return preg_replace(',\?[[:digit:]]+$,', '', $url); |
|
| 5210 | 5210 | } |
| 5211 | 5211 | |
| 5212 | 5212 | /** |
@@ -5221,9 +5221,9 @@ discard block |
||
| 5221 | 5221 | * @return string |
| 5222 | 5222 | */ |
| 5223 | 5223 | function filtre_nettoyer_titre_email_dist($titre) { |
| 5224 | - include_spip('inc/envoyer_mail'); |
|
| 5224 | + include_spip('inc/envoyer_mail'); |
|
| 5225 | 5225 | |
| 5226 | - return nettoyer_titre_email($titre); |
|
| 5226 | + return nettoyer_titre_email($titre); |
|
| 5227 | 5227 | } |
| 5228 | 5228 | |
| 5229 | 5229 | /** |
@@ -5245,27 +5245,27 @@ discard block |
||
| 5245 | 5245 | * @return string |
| 5246 | 5246 | */ |
| 5247 | 5247 | function filtre_chercher_rubrique_dist( |
| 5248 | - $titre, |
|
| 5249 | - $id_objet, |
|
| 5250 | - $id_parent, |
|
| 5251 | - $objet, |
|
| 5252 | - $id_secteur, |
|
| 5253 | - $restreint, |
|
| 5254 | - $actionable = false, |
|
| 5255 | - $retour_sans_cadre = false |
|
| 5248 | + $titre, |
|
| 5249 | + $id_objet, |
|
| 5250 | + $id_parent, |
|
| 5251 | + $objet, |
|
| 5252 | + $id_secteur, |
|
| 5253 | + $restreint, |
|
| 5254 | + $actionable = false, |
|
| 5255 | + $retour_sans_cadre = false |
|
| 5256 | 5256 | ) { |
| 5257 | - include_spip('inc/filtres_ecrire'); |
|
| 5257 | + include_spip('inc/filtres_ecrire'); |
|
| 5258 | 5258 | |
| 5259 | - return chercher_rubrique( |
|
| 5260 | - $titre, |
|
| 5261 | - $id_objet, |
|
| 5262 | - $id_parent, |
|
| 5263 | - $objet, |
|
| 5264 | - $id_secteur, |
|
| 5265 | - $restreint, |
|
| 5266 | - $actionable, |
|
| 5267 | - $retour_sans_cadre |
|
| 5268 | - ); |
|
| 5259 | + return chercher_rubrique( |
|
| 5260 | + $titre, |
|
| 5261 | + $id_objet, |
|
| 5262 | + $id_parent, |
|
| 5263 | + $objet, |
|
| 5264 | + $id_secteur, |
|
| 5265 | + $restreint, |
|
| 5266 | + $actionable, |
|
| 5267 | + $retour_sans_cadre |
|
| 5268 | + ); |
|
| 5269 | 5269 | } |
| 5270 | 5270 | |
| 5271 | 5271 | /** |
@@ -5294,56 +5294,56 @@ discard block |
||
| 5294 | 5294 | * Chaîne vide si l'accès est autorisé |
| 5295 | 5295 | */ |
| 5296 | 5296 | function sinon_interdire_acces($ok = false, $url = '', $statut = 0, $message = null) { |
| 5297 | - if ($ok) { |
|
| 5298 | - return ''; |
|
| 5299 | - } |
|
| 5300 | - |
|
| 5301 | - // Vider tous les tampons |
|
| 5302 | - $level = @ob_get_level(); |
|
| 5303 | - while ($level--) { |
|
| 5304 | - @ob_end_clean(); |
|
| 5305 | - } |
|
| 5306 | - |
|
| 5307 | - include_spip('inc/headers'); |
|
| 5308 | - |
|
| 5309 | - // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5310 | - if ($url) { |
|
| 5311 | - redirige_par_entete($url, '', $statut); |
|
| 5312 | - } |
|
| 5313 | - |
|
| 5314 | - // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5315 | - if (!is_numeric($statut) and is_null($message)) { |
|
| 5316 | - $message = $statut; |
|
| 5317 | - $statut = 0; |
|
| 5318 | - } |
|
| 5319 | - if (!$message) { |
|
| 5320 | - $message = ''; |
|
| 5321 | - } |
|
| 5322 | - $statut = intval($statut); |
|
| 5323 | - |
|
| 5324 | - // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5325 | - if (test_espace_prive()) { |
|
| 5326 | - if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5327 | - $statut = 403; |
|
| 5328 | - } |
|
| 5329 | - http_response_code(403); |
|
| 5330 | - $echec = charger_fonction('403', 'exec'); |
|
| 5331 | - $echec($message); |
|
| 5332 | - } else { |
|
| 5333 | - // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5334 | - if (!$statut) { |
|
| 5335 | - $statut = 404; |
|
| 5336 | - } |
|
| 5337 | - // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5338 | - http_response_code($statut); |
|
| 5339 | - // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5340 | - if ($statut >= 400) { |
|
| 5341 | - echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5342 | - } |
|
| 5343 | - } |
|
| 5344 | - |
|
| 5345 | - |
|
| 5346 | - exit; |
|
| 5297 | + if ($ok) { |
|
| 5298 | + return ''; |
|
| 5299 | + } |
|
| 5300 | + |
|
| 5301 | + // Vider tous les tampons |
|
| 5302 | + $level = @ob_get_level(); |
|
| 5303 | + while ($level--) { |
|
| 5304 | + @ob_end_clean(); |
|
| 5305 | + } |
|
| 5306 | + |
|
| 5307 | + include_spip('inc/headers'); |
|
| 5308 | + |
|
| 5309 | + // S'il y a une URL, on redirige (si pas de statut, la fonction mettra 302 par défaut) |
|
| 5310 | + if ($url) { |
|
| 5311 | + redirige_par_entete($url, '', $statut); |
|
| 5312 | + } |
|
| 5313 | + |
|
| 5314 | + // ecriture simplifiee avec message en 3eme argument (= statut 403) |
|
| 5315 | + if (!is_numeric($statut) and is_null($message)) { |
|
| 5316 | + $message = $statut; |
|
| 5317 | + $statut = 0; |
|
| 5318 | + } |
|
| 5319 | + if (!$message) { |
|
| 5320 | + $message = ''; |
|
| 5321 | + } |
|
| 5322 | + $statut = intval($statut); |
|
| 5323 | + |
|
| 5324 | + // Si on est dans l'espace privé, on génère du 403 Forbidden par defaut ou du 404 |
|
| 5325 | + if (test_espace_prive()) { |
|
| 5326 | + if (!$statut or !in_array($statut, [404, 403])) { |
|
| 5327 | + $statut = 403; |
|
| 5328 | + } |
|
| 5329 | + http_response_code(403); |
|
| 5330 | + $echec = charger_fonction('403', 'exec'); |
|
| 5331 | + $echec($message); |
|
| 5332 | + } else { |
|
| 5333 | + // Sinon dans l'espace public on redirige vers une 404 par défaut, car elle toujours présente normalement |
|
| 5334 | + if (!$statut) { |
|
| 5335 | + $statut = 404; |
|
| 5336 | + } |
|
| 5337 | + // Dans tous les cas on modifie l'entité avec ce qui est demandé |
|
| 5338 | + http_response_code($statut); |
|
| 5339 | + // Si le statut est une erreur et qu'il n'y a pas de redirection on va chercher le squelette du même nom |
|
| 5340 | + if ($statut >= 400) { |
|
| 5341 | + echo recuperer_fond("$statut", ['erreur' => $message]); |
|
| 5342 | + } |
|
| 5343 | + } |
|
| 5344 | + |
|
| 5345 | + |
|
| 5346 | + exit; |
|
| 5347 | 5347 | } |
| 5348 | 5348 | |
| 5349 | 5349 | /** |
@@ -5354,11 +5354,11 @@ discard block |
||
| 5354 | 5354 | * @return string |
| 5355 | 5355 | */ |
| 5356 | 5356 | function filtre_compacte_dist($source, $format = null) { |
| 5357 | - if (function_exists('compacte')) { |
|
| 5358 | - return compacte($source, $format); |
|
| 5359 | - } |
|
| 5357 | + if (function_exists('compacte')) { |
|
| 5358 | + return compacte($source, $format); |
|
| 5359 | + } |
|
| 5360 | 5360 | |
| 5361 | - return $source; |
|
| 5361 | + return $source; |
|
| 5362 | 5362 | } |
| 5363 | 5363 | |
| 5364 | 5364 | |
@@ -5370,31 +5370,31 @@ discard block |
||
| 5370 | 5370 | * @return string |
| 5371 | 5371 | */ |
| 5372 | 5372 | function spip_affiche_mot_de_passe_masque($passe, $afficher_partiellement = false, $portion_pourcent = null) { |
| 5373 | - $l = strlen($passe); |
|
| 5374 | - |
|
| 5375 | - if ($l <= 8 or !$afficher_partiellement) { |
|
| 5376 | - if (!$l) { |
|
| 5377 | - return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5378 | - } |
|
| 5379 | - return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5380 | - } |
|
| 5381 | - |
|
| 5382 | - if (is_null($portion_pourcent)) { |
|
| 5383 | - if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5384 | - define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5385 | - } |
|
| 5386 | - $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5387 | - } |
|
| 5388 | - if ($portion_pourcent >= 100) { |
|
| 5389 | - return $passe; |
|
| 5390 | - } |
|
| 5391 | - $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5392 | - $e = max($e, 0); |
|
| 5393 | - $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5394 | - if ($e > 0 and strlen($mid) > 8) { |
|
| 5395 | - $mid = '***...***'; |
|
| 5396 | - } |
|
| 5397 | - return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5373 | + $l = strlen($passe); |
|
| 5374 | + |
|
| 5375 | + if ($l <= 8 or !$afficher_partiellement) { |
|
| 5376 | + if (!$l) { |
|
| 5377 | + return ''; // montrer qu'il y a pas de mot de passe si il y en a pas |
|
| 5378 | + } |
|
| 5379 | + return str_pad('', $afficher_partiellement ? $l : 16, '*'); |
|
| 5380 | + } |
|
| 5381 | + |
|
| 5382 | + if (is_null($portion_pourcent)) { |
|
| 5383 | + if (!defined('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT')) { |
|
| 5384 | + define('_SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT', 20); // 20% |
|
| 5385 | + } |
|
| 5386 | + $portion_pourcent = _SPIP_AFFICHE_MOT_DE_PASSE_MASQUE_PERCENT; |
|
| 5387 | + } |
|
| 5388 | + if ($portion_pourcent >= 100) { |
|
| 5389 | + return $passe; |
|
| 5390 | + } |
|
| 5391 | + $e = intval(ceil($l * $portion_pourcent / 100 / 2)); |
|
| 5392 | + $e = max($e, 0); |
|
| 5393 | + $mid = str_pad('', $l - 2 * $e, '*'); |
|
| 5394 | + if ($e > 0 and strlen($mid) > 8) { |
|
| 5395 | + $mid = '***...***'; |
|
| 5396 | + } |
|
| 5397 | + return substr($passe, 0, $e) . $mid . ($e > 0 ? substr($passe, -$e) : ''); |
|
| 5398 | 5398 | } |
| 5399 | 5399 | |
| 5400 | 5400 | |
@@ -5415,64 +5415,64 @@ discard block |
||
| 5415 | 5415 | */ |
| 5416 | 5416 | function identifiant_slug($texte, $type = '', $options = []) { |
| 5417 | 5417 | |
| 5418 | - $original = $texte; |
|
| 5419 | - $separateur = (isset($options['separateur']) ? $options['separateur'] : '_'); |
|
| 5420 | - $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60); |
|
| 5421 | - $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0); |
|
| 5418 | + $original = $texte; |
|
| 5419 | + $separateur = (isset($options['separateur']) ? $options['separateur'] : '_'); |
|
| 5420 | + $longueur_maxi = (isset($options['longueur_maxi']) ? $options['longueur_maxi'] : 60); |
|
| 5421 | + $longueur_mini = (isset($options['longueur_mini']) ? $options['longueur_mini'] : 0); |
|
| 5422 | 5422 | |
| 5423 | - if (!function_exists('translitteration')) { |
|
| 5424 | - include_spip('inc/charsets'); |
|
| 5425 | - } |
|
| 5423 | + if (!function_exists('translitteration')) { |
|
| 5424 | + include_spip('inc/charsets'); |
|
| 5425 | + } |
|
| 5426 | 5426 | |
| 5427 | - // pas de balise html |
|
| 5428 | - if (strpos($texte, '<') !== false) { |
|
| 5429 | - $texte = strip_tags($texte); |
|
| 5430 | - } |
|
| 5431 | - if (strpos($texte, '&') !== false) { |
|
| 5432 | - $texte = unicode2charset($texte); |
|
| 5433 | - } |
|
| 5434 | - // On enlève les espaces indésirables |
|
| 5435 | - $texte = trim($texte); |
|
| 5427 | + // pas de balise html |
|
| 5428 | + if (strpos($texte, '<') !== false) { |
|
| 5429 | + $texte = strip_tags($texte); |
|
| 5430 | + } |
|
| 5431 | + if (strpos($texte, '&') !== false) { |
|
| 5432 | + $texte = unicode2charset($texte); |
|
| 5433 | + } |
|
| 5434 | + // On enlève les espaces indésirables |
|
| 5435 | + $texte = trim($texte); |
|
| 5436 | 5436 | |
| 5437 | - // On enlève les accents et cie |
|
| 5438 | - $texte = translitteration($texte); |
|
| 5437 | + // On enlève les accents et cie |
|
| 5438 | + $texte = translitteration($texte); |
|
| 5439 | 5439 | |
| 5440 | - // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5441 | - $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5440 | + // On remplace tout ce qui n'est pas un mot par un séparateur |
|
| 5441 | + $texte = preg_replace(',[\W_]+,ms', $separateur, $texte); |
|
| 5442 | 5442 | |
| 5443 | - // nettoyer les doubles occurences du separateur si besoin |
|
| 5444 | - while (strpos($texte, "$separateur$separateur") !== false) { |
|
| 5445 | - $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5446 | - } |
|
| 5443 | + // nettoyer les doubles occurences du separateur si besoin |
|
| 5444 | + while (strpos($texte, "$separateur$separateur") !== false) { |
|
| 5445 | + $texte = str_replace("$separateur$separateur", $separateur, $texte); |
|
| 5446 | + } |
|
| 5447 | 5447 | |
| 5448 | - // pas de separateur au debut ni a la fin |
|
| 5449 | - $texte = trim($texte, $separateur); |
|
| 5448 | + // pas de separateur au debut ni a la fin |
|
| 5449 | + $texte = trim($texte, $separateur); |
|
| 5450 | 5450 | |
| 5451 | - // en minuscules |
|
| 5452 | - $texte = strtolower($texte); |
|
| 5451 | + // en minuscules |
|
| 5452 | + $texte = strtolower($texte); |
|
| 5453 | 5453 | |
| 5454 | - switch ($type) { |
|
| 5455 | - case 'class': |
|
| 5456 | - case 'id': |
|
| 5457 | - case 'anchor': |
|
| 5458 | - if (preg_match(',^\d,', $texte)) { |
|
| 5459 | - $texte = substr($type, 0, 1) . $texte; |
|
| 5460 | - } |
|
| 5461 | - } |
|
| 5454 | + switch ($type) { |
|
| 5455 | + case 'class': |
|
| 5456 | + case 'id': |
|
| 5457 | + case 'anchor': |
|
| 5458 | + if (preg_match(',^\d,', $texte)) { |
|
| 5459 | + $texte = substr($type, 0, 1) . $texte; |
|
| 5460 | + } |
|
| 5461 | + } |
|
| 5462 | 5462 | |
| 5463 | - if (strlen($texte) > $longueur_maxi) { |
|
| 5464 | - $texte = substr($texte, 0, $longueur_maxi); |
|
| 5465 | - } |
|
| 5463 | + if (strlen($texte) > $longueur_maxi) { |
|
| 5464 | + $texte = substr($texte, 0, $longueur_maxi); |
|
| 5465 | + } |
|
| 5466 | 5466 | |
| 5467 | - if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5468 | - if (preg_match(',^\d,', $texte)) { |
|
| 5469 | - $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5470 | - } |
|
| 5471 | - $texte .= $separateur . md5($original); |
|
| 5472 | - $texte = substr($texte, 0, $longueur_mini); |
|
| 5473 | - } |
|
| 5467 | + if (strlen($texte) < $longueur_mini and $longueur_mini < $longueur_maxi) { |
|
| 5468 | + if (preg_match(',^\d,', $texte)) { |
|
| 5469 | + $texte = ($type ? substr($type, 0, 1) : 's') . $texte; |
|
| 5470 | + } |
|
| 5471 | + $texte .= $separateur . md5($original); |
|
| 5472 | + $texte = substr($texte, 0, $longueur_mini); |
|
| 5473 | + } |
|
| 5474 | 5474 | |
| 5475 | - return $texte; |
|
| 5475 | + return $texte; |
|
| 5476 | 5476 | } |
| 5477 | 5477 | |
| 5478 | 5478 | |
@@ -5493,11 +5493,11 @@ discard block |
||
| 5493 | 5493 | * @exemple `<:info_maximum|label_nettoyer:>` |
| 5494 | 5494 | */ |
| 5495 | 5495 | function label_nettoyer(string $text, bool $ucfirst = true): string { |
| 5496 | - $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5497 | - if ($ucfirst) { |
|
| 5498 | - $label = spip_ucfirst($label); |
|
| 5499 | - } |
|
| 5500 | - return $label; |
|
| 5496 | + $label = preg_replace('#([\s:]|\ )+$#u', '', $text); |
|
| 5497 | + if ($ucfirst) { |
|
| 5498 | + $label = spip_ucfirst($label); |
|
| 5499 | + } |
|
| 5500 | + return $label; |
|
| 5501 | 5501 | } |
| 5502 | 5502 | |
| 5503 | 5503 | /** |
@@ -5510,8 +5510,8 @@ discard block |
||
| 5510 | 5510 | * @exemple `<:info_maximum|label_ponctuer:>` |
| 5511 | 5511 | */ |
| 5512 | 5512 | function label_ponctuer(string $text, bool $ucfirst = true): string { |
| 5513 | - $label = label_nettoyer($text, $ucfirst); |
|
| 5514 | - return _T('label_ponctuer', ['label' => $label]); |
|
| 5513 | + $label = label_nettoyer($text, $ucfirst); |
|
| 5514 | + return _T('label_ponctuer', ['label' => $label]); |
|
| 5515 | 5515 | } |
| 5516 | 5516 | |
| 5517 | 5517 | |
@@ -5524,19 +5524,19 @@ discard block |
||
| 5524 | 5524 | * @return array |
| 5525 | 5525 | */ |
| 5526 | 5526 | function helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, $fonction) { |
| 5527 | - if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5528 | - return []; |
|
| 5529 | - } |
|
| 5527 | + if (!in_array($fonction, ['objet_lister_parents', 'objet_lister_enfants', 'objet_lister_parents_par_type', 'objet_lister_enfants_par_type'])) { |
|
| 5528 | + return []; |
|
| 5529 | + } |
|
| 5530 | 5530 | |
| 5531 | - // compatibilite signature inversee |
|
| 5532 | - if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5533 | - list($objet, $id_objet) = [$id_objet, $objet]; |
|
| 5534 | - } |
|
| 5531 | + // compatibilite signature inversee |
|
| 5532 | + if (is_numeric($objet) and !is_numeric($id_objet)) { |
|
| 5533 | + list($objet, $id_objet) = [$id_objet, $objet]; |
|
| 5534 | + } |
|
| 5535 | 5535 | |
| 5536 | - if (!function_exists($fonction)) { |
|
| 5537 | - include_spip('base/objets'); |
|
| 5538 | - } |
|
| 5539 | - return $fonction($objet, $id_objet); |
|
| 5536 | + if (!function_exists($fonction)) { |
|
| 5537 | + include_spip('base/objets'); |
|
| 5538 | + } |
|
| 5539 | + return $fonction($objet, $id_objet); |
|
| 5540 | 5540 | } |
| 5541 | 5541 | |
| 5542 | 5542 | |
@@ -5551,7 +5551,7 @@ discard block |
||
| 5551 | 5551 | * @return array |
| 5552 | 5552 | */ |
| 5553 | 5553 | function filtre_objet_lister_parents_dist($objet, $id_objet) { |
| 5554 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5554 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents'); |
|
| 5555 | 5555 | } |
| 5556 | 5556 | |
| 5557 | 5557 | /** |
@@ -5565,7 +5565,7 @@ discard block |
||
| 5565 | 5565 | * @return array |
| 5566 | 5566 | */ |
| 5567 | 5567 | function filtre_objet_lister_parents_par_type_dist($objet, $id_objet) { |
| 5568 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5568 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_parents_par_type'); |
|
| 5569 | 5569 | } |
| 5570 | 5570 | |
| 5571 | 5571 | /** |
@@ -5579,7 +5579,7 @@ discard block |
||
| 5579 | 5579 | * @return array |
| 5580 | 5580 | */ |
| 5581 | 5581 | function filtre_objet_lister_enfants_dist($objet, $id_objet) { |
| 5582 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5582 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants'); |
|
| 5583 | 5583 | } |
| 5584 | 5584 | |
| 5585 | 5585 | /** |
@@ -5593,5 +5593,5 @@ discard block |
||
| 5593 | 5593 | * @return array |
| 5594 | 5594 | */ |
| 5595 | 5595 | function filtre_objet_lister_enfants_par_type_dist($objet, $id_objet) { |
| 5596 | - return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5596 | + return helper_filtre_objet_lister_enfants_ou_parents($objet, $id_objet, 'objet_lister_enfants_par_type'); |
|
| 5597 | 5597 | } |