@@ -18,7 +18,7 @@ discard block |
||
| 18 | 18 | */ |
| 19 | 19 | |
| 20 | 20 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 21 | - return; |
|
| 21 | + return; |
|
| 22 | 22 | } |
| 23 | 23 | include_spip('inc/filtres'); // par precaution |
| 24 | 24 | include_spip('inc/filtres_images_mini'); // par precaution |
@@ -38,21 +38,21 @@ discard block |
||
| 38 | 38 | * Le code de la couleur en hexadécimal. |
| 39 | 39 | */ |
| 40 | 40 | function _couleur_dec_to_hex($red, $green, $blue) { |
| 41 | - $red = dechex($red); |
|
| 42 | - $green = dechex($green); |
|
| 43 | - $blue = dechex($blue); |
|
| 44 | - |
|
| 45 | - if (strlen($red) == 1) { |
|
| 46 | - $red = '0' . $red; |
|
| 47 | - } |
|
| 48 | - if (strlen($green) == 1) { |
|
| 49 | - $green = '0' . $green; |
|
| 50 | - } |
|
| 51 | - if (strlen($blue) == 1) { |
|
| 52 | - $blue = '0' . $blue; |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - return "$red$green$blue"; |
|
| 41 | + $red = dechex($red); |
|
| 42 | + $green = dechex($green); |
|
| 43 | + $blue = dechex($blue); |
|
| 44 | + |
|
| 45 | + if (strlen($red) == 1) { |
|
| 46 | + $red = '0' . $red; |
|
| 47 | + } |
|
| 48 | + if (strlen($green) == 1) { |
|
| 49 | + $green = '0' . $green; |
|
| 50 | + } |
|
| 51 | + if (strlen($blue) == 1) { |
|
| 52 | + $blue = '0' . $blue; |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + return "$red$green$blue"; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -64,17 +64,17 @@ discard block |
||
| 64 | 64 | * Un tableau des 3 éléments : rouge, vert, bleu. |
| 65 | 65 | */ |
| 66 | 66 | function _couleur_hex_to_dec($couleur) { |
| 67 | - $couleur = couleur_html_to_hex($couleur); |
|
| 68 | - $couleur = ltrim($couleur, '#'); |
|
| 69 | - if (strlen($couleur) === 3) { |
|
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | - } |
|
| 72 | - $retour = []; |
|
| 73 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | - |
|
| 77 | - return $retour; |
|
| 67 | + $couleur = couleur_html_to_hex($couleur); |
|
| 68 | + $couleur = ltrim($couleur, '#'); |
|
| 69 | + if (strlen($couleur) === 3) { |
|
| 70 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 71 | + } |
|
| 72 | + $retour = []; |
|
| 73 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 74 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 75 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 76 | + |
|
| 77 | + return $retour; |
|
| 78 | 78 | } |
| 79 | 79 | |
| 80 | 80 | |
@@ -91,8 +91,8 @@ discard block |
||
| 91 | 91 | * Le code de la couleur en hexadécimal. |
| 92 | 92 | */ |
| 93 | 93 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 94 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 94 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 95 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 96 | 96 | } |
| 97 | 97 | |
| 98 | 98 | /** |
@@ -104,8 +104,8 @@ discard block |
||
| 104 | 104 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 105 | 105 | */ |
| 106 | 106 | function _couleur_hex_to_hsl($couleur) { |
| 107 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 107 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 108 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | /** |
@@ -120,59 +120,59 @@ discard block |
||
| 120 | 120 | * @return array |
| 121 | 121 | */ |
| 122 | 122 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 123 | - $H = null; |
|
| 124 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | - $var_G = ($G / 255); |
|
| 126 | - $var_B = ($B / 255); |
|
| 127 | - |
|
| 128 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | - |
|
| 132 | - $L = ($var_Max + $var_Min) / 2; |
|
| 133 | - |
|
| 134 | - if ($del_Max == 0) { |
|
| 135 | - //This is a gray, no chroma... |
|
| 136 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | - $S = 0; |
|
| 138 | - } else { |
|
| 139 | - // Chromatic data... |
|
| 140 | - if ($L < 0.5) { |
|
| 141 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | - } else { |
|
| 143 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | - } |
|
| 145 | - |
|
| 146 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - |
|
| 150 | - if ($var_R == $var_Max) { |
|
| 151 | - $H = $del_B - $del_G; |
|
| 152 | - } else { |
|
| 153 | - if ($var_G == $var_Max) { |
|
| 154 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | - } else { |
|
| 156 | - if ($var_B == $var_Max) { |
|
| 157 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | - } |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - |
|
| 162 | - if ($H < 0) { |
|
| 163 | - $H += 1; |
|
| 164 | - } |
|
| 165 | - if ($H > 1) { |
|
| 166 | - $H -= 1; |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - |
|
| 170 | - $ret = []; |
|
| 171 | - $ret['h'] = $H; |
|
| 172 | - $ret['s'] = $S; |
|
| 173 | - $ret['l'] = $L; |
|
| 174 | - |
|
| 175 | - return $ret; |
|
| 123 | + $H = null; |
|
| 124 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 125 | + $var_G = ($G / 255); |
|
| 126 | + $var_B = ($B / 255); |
|
| 127 | + |
|
| 128 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 129 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 130 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 131 | + |
|
| 132 | + $L = ($var_Max + $var_Min) / 2; |
|
| 133 | + |
|
| 134 | + if ($del_Max == 0) { |
|
| 135 | + //This is a gray, no chroma... |
|
| 136 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 137 | + $S = 0; |
|
| 138 | + } else { |
|
| 139 | + // Chromatic data... |
|
| 140 | + if ($L < 0.5) { |
|
| 141 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 142 | + } else { |
|
| 143 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 144 | + } |
|
| 145 | + |
|
| 146 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 147 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + |
|
| 150 | + if ($var_R == $var_Max) { |
|
| 151 | + $H = $del_B - $del_G; |
|
| 152 | + } else { |
|
| 153 | + if ($var_G == $var_Max) { |
|
| 154 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 155 | + } else { |
|
| 156 | + if ($var_B == $var_Max) { |
|
| 157 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 158 | + } |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + |
|
| 162 | + if ($H < 0) { |
|
| 163 | + $H += 1; |
|
| 164 | + } |
|
| 165 | + if ($H > 1) { |
|
| 166 | + $H -= 1; |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + |
|
| 170 | + $ret = []; |
|
| 171 | + $ret['h'] = $H; |
|
| 172 | + $ret['s'] = $S; |
|
| 173 | + $ret['l'] = $L; |
|
| 174 | + |
|
| 175 | + return $ret; |
|
| 176 | 176 | } |
| 177 | 177 | |
| 178 | 178 | |
@@ -188,52 +188,52 @@ discard block |
||
| 188 | 188 | * @return array |
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | - // helper |
|
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | - if ($vH < 0) { |
|
| 194 | - $vH += 1; |
|
| 195 | - } |
|
| 196 | - if ($vH > 1) { |
|
| 197 | - $vH -= 1; |
|
| 198 | - } |
|
| 199 | - if ((6 * $vH) < 1) { |
|
| 200 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | - } |
|
| 202 | - if ((2 * $vH) < 1) { |
|
| 203 | - return ($v2); |
|
| 204 | - } |
|
| 205 | - if ((3 * $vH) < 2) { |
|
| 206 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | - } |
|
| 208 | - |
|
| 209 | - return ($v1); |
|
| 210 | - }; |
|
| 211 | - |
|
| 212 | - if ($S == 0) { |
|
| 213 | - // HSV values = 0 -> 1 |
|
| 214 | - $R = $L * 255; |
|
| 215 | - $G = $L * 255; |
|
| 216 | - $B = $L * 255; |
|
| 217 | - } else { |
|
| 218 | - if ($L < 0.5) { |
|
| 219 | - $var_2 = $L * (1 + $S); |
|
| 220 | - } else { |
|
| 221 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | - } |
|
| 223 | - |
|
| 224 | - $var_1 = 2 * $L - $var_2; |
|
| 225 | - |
|
| 226 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | - } |
|
| 230 | - |
|
| 231 | - $ret = []; |
|
| 232 | - $ret['r'] = floor($R); |
|
| 233 | - $ret['g'] = floor($G); |
|
| 234 | - $ret['b'] = floor($B); |
|
| 235 | - |
|
| 236 | - return $ret; |
|
| 191 | + // helper |
|
| 192 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 193 | + if ($vH < 0) { |
|
| 194 | + $vH += 1; |
|
| 195 | + } |
|
| 196 | + if ($vH > 1) { |
|
| 197 | + $vH -= 1; |
|
| 198 | + } |
|
| 199 | + if ((6 * $vH) < 1) { |
|
| 200 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 201 | + } |
|
| 202 | + if ((2 * $vH) < 1) { |
|
| 203 | + return ($v2); |
|
| 204 | + } |
|
| 205 | + if ((3 * $vH) < 2) { |
|
| 206 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 207 | + } |
|
| 208 | + |
|
| 209 | + return ($v1); |
|
| 210 | + }; |
|
| 211 | + |
|
| 212 | + if ($S == 0) { |
|
| 213 | + // HSV values = 0 -> 1 |
|
| 214 | + $R = $L * 255; |
|
| 215 | + $G = $L * 255; |
|
| 216 | + $B = $L * 255; |
|
| 217 | + } else { |
|
| 218 | + if ($L < 0.5) { |
|
| 219 | + $var_2 = $L * (1 + $S); |
|
| 220 | + } else { |
|
| 221 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 222 | + } |
|
| 223 | + |
|
| 224 | + $var_1 = 2 * $L - $var_2; |
|
| 225 | + |
|
| 226 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 227 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 228 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 229 | + } |
|
| 230 | + |
|
| 231 | + $ret = []; |
|
| 232 | + $ret['r'] = floor($R); |
|
| 233 | + $ret['g'] = floor($G); |
|
| 234 | + $ret['b'] = floor($B); |
|
| 235 | + |
|
| 236 | + return $ret; |
|
| 237 | 237 | } |
| 238 | 238 | |
| 239 | 239 | /** |
@@ -251,11 +251,11 @@ discard block |
||
| 251 | 251 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 252 | 252 | */ |
| 253 | 253 | function statut_effacer_images_temporaires($stat) { |
| 254 | - static $statut = false; // par defaut on grave toute les images |
|
| 255 | - if ($stat === 'get') { |
|
| 256 | - return $statut; |
|
| 257 | - } |
|
| 258 | - $statut = $stat ? true : false; |
|
| 254 | + static $statut = false; // par defaut on grave toute les images |
|
| 255 | + if ($stat === 'get') { |
|
| 256 | + return $statut; |
|
| 257 | + } |
|
| 258 | + $statut = $stat ? true : false; |
|
| 259 | 259 | } |
| 260 | 260 | |
| 261 | 261 | |
@@ -308,243 +308,243 @@ discard block |
||
| 308 | 308 | * - array : tableau décrivant de l'image |
| 309 | 309 | */ |
| 310 | 310 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 311 | - $ret = []; |
|
| 312 | - $f = null; |
|
| 313 | - static $images_recalcul = []; |
|
| 314 | - if (strlen($img) == 0) { |
|
| 315 | - return false; |
|
| 316 | - } |
|
| 317 | - |
|
| 318 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | - if (strlen($source) < 1) { |
|
| 320 | - $source = $img; |
|
| 321 | - $img = "<img src='$source' />"; |
|
| 322 | - } elseif ( |
|
| 323 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | - ) { |
|
| 327 | - # gerer img src="data:....base64" |
|
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | - if (!file_exists($local)) { |
|
| 330 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | - } |
|
| 332 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | - $sanitizer($local); |
|
| 334 | - } |
|
| 335 | - $source = $local; |
|
| 336 | - $img = inserer_attribut($img, 'src', $source); |
|
| 337 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | - $img = inserer_attribut($img, 'width', ''); |
|
| 339 | - $img = inserer_attribut($img, 'height', ''); |
|
| 340 | - } |
|
| 341 | - |
|
| 342 | - // les protocoles web prennent au moins 3 lettres |
|
| 343 | - if (tester_url_absolue($source)) { |
|
| 344 | - include_spip('inc/distant'); |
|
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | - if (!$fichier) { |
|
| 347 | - return ''; |
|
| 348 | - } |
|
| 349 | - if ( |
|
| 350 | - $extension = _image_trouver_extension($fichier) |
|
| 351 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | - ) { |
|
| 353 | - $sanitizer($fichier); |
|
| 354 | - } |
|
| 355 | - } else { |
|
| 356 | - // enlever le timestamp eventuel |
|
| 357 | - if (strpos($source, '?') !== false) { |
|
| 358 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | - } |
|
| 360 | - if ( |
|
| 361 | - strpos($source, '?') !== false |
|
| 362 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | - ) { |
|
| 365 | - $source = $f; |
|
| 366 | - } |
|
| 367 | - $fichier = $source; |
|
| 368 | - } |
|
| 369 | - |
|
| 370 | - $terminaison_dest = ''; |
|
| 371 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | - } |
|
| 374 | - |
|
| 375 | - if ( |
|
| 376 | - $forcer_format !== false |
|
| 377 | - // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | - ) { |
|
| 380 | - $terminaison_dest = $forcer_format; |
|
| 381 | - } |
|
| 382 | - |
|
| 383 | - if (!$terminaison_dest) { |
|
| 384 | - return false; |
|
| 385 | - } |
|
| 386 | - |
|
| 387 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | - $fichier_dest = $nom_fichier; |
|
| 389 | - if ( |
|
| 390 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | - or @file_exists($f = $fichier) |
|
| 392 | - ) { |
|
| 393 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | - // au lieu de faire un acces disque sur le fichier |
|
| 395 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | - $date_src = @filemtime($f); |
|
| 397 | - } elseif ( |
|
| 398 | - @file_exists($f = "$fichier.src") |
|
| 399 | - and lire_fichier($f, $valeurs) |
|
| 400 | - and $valeurs = unserialize($valeurs) |
|
| 401 | - and isset($valeurs['hauteur_dest']) |
|
| 402 | - and isset($valeurs['largeur_dest']) |
|
| 403 | - ) { |
|
| 404 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | - $date_src = $valeurs['date']; |
|
| 407 | - } // pas de fichier source par la |
|
| 408 | - else { |
|
| 409 | - return false; |
|
| 410 | - } |
|
| 411 | - |
|
| 412 | - // pas de taille mesurable |
|
| 413 | - if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 414 | - return false; |
|
| 415 | - } |
|
| 416 | - |
|
| 417 | - // les images calculees dependent du chemin du fichier source |
|
| 418 | - // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 419 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 420 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 421 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 422 | - // alors que ca concerne peu de site au final |
|
| 423 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 424 | - $identifiant = $fichier; |
|
| 425 | - |
|
| 426 | - // cas general : |
|
| 427 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 428 | - // cas particulier de reduire : |
|
| 429 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 430 | - $cache = 'cache-gd2'; |
|
| 431 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 432 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 433 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 434 | - $ret['largeur_dest'] = $destWidth; |
|
| 435 | - $ret['hauteur_dest'] = $destHeight; |
|
| 436 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 437 | - $cache = 'cache-vignettes'; |
|
| 438 | - $fichier_dest = basename($fichier_dest); |
|
| 439 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 440 | - // on garde la terminaison initiale car image simplement copiee |
|
| 441 | - // et on postfixe son nom avec un md5 du path |
|
| 442 | - $terminaison_dest = $terminaison; |
|
| 443 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 444 | - } else { |
|
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | - } |
|
| 447 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | - $cache = sous_repertoire($cache, $effet); |
|
| 449 | - } else { |
|
| 450 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 451 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 453 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 454 | - } |
|
| 455 | - |
|
| 456 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 457 | - |
|
| 458 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 459 | - |
|
| 460 | - $creer = true; |
|
| 461 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 462 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 463 | - $images_recalcul[$fichier_dest] = true; |
|
| 464 | - } else { |
|
| 465 | - if (@file_exists($f = $fichier_dest)) { |
|
| 466 | - if (filemtime($f) >= $date_src) { |
|
| 467 | - $creer = false; |
|
| 468 | - } |
|
| 469 | - } else { |
|
| 470 | - if ( |
|
| 471 | - @file_exists($f = "$fichier_dest.src") |
|
| 472 | - and lire_fichier($f, $valeurs) |
|
| 473 | - and $valeurs = unserialize($valeurs) |
|
| 474 | - and $valeurs['date'] >= $date_src |
|
| 475 | - ) { |
|
| 476 | - $creer = false; |
|
| 477 | - } |
|
| 478 | - } |
|
| 479 | - } |
|
| 480 | - if ($creer) { |
|
| 481 | - if (!@file_exists($fichier)) { |
|
| 482 | - if (!@file_exists("$fichier.src")) { |
|
| 483 | - spip_log("Image absente : $fichier"); |
|
| 484 | - |
|
| 485 | - return false; |
|
| 486 | - } |
|
| 487 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 488 | - reconstruire_image_intermediaire($fichier); |
|
| 489 | - } |
|
| 490 | - } |
|
| 491 | - |
|
| 492 | - if ($creer) { |
|
| 493 | - spip_log( |
|
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 496 | - ); |
|
| 497 | - } |
|
| 498 | - |
|
| 499 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | - $ret['fichier'] = $fichier; |
|
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | - $ret['format_dest'] = $terminaison_dest; |
|
| 506 | - $ret['date_src'] = $date_src; |
|
| 507 | - $ret['creer'] = $creer; |
|
| 508 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | - $ret['tag'] = $img; |
|
| 512 | - if ($fonction_creation) { |
|
| 513 | - $ret['reconstruction'] = $fonction_creation; |
|
| 514 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | - } |
|
| 519 | - |
|
| 520 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | - 'args' => [ |
|
| 522 | - 'img' => $img, |
|
| 523 | - 'effet' => $effet, |
|
| 524 | - 'forcer_format' => $forcer_format, |
|
| 525 | - 'fonction_creation' => $fonction_creation, |
|
| 526 | - 'find_in_path' => $find_in_path, |
|
| 527 | - ], |
|
| 528 | - 'data' => $ret |
|
| 529 | - ]); |
|
| 530 | - |
|
| 531 | - // une globale pour le debug en cas de crash memoire |
|
| 532 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | - |
|
| 534 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | - if ($term_fonction === 'svg') { |
|
| 536 | - if ($creer and !$support_svg) { |
|
| 537 | - process_image_svg_identite($ret); |
|
| 538 | - $ret['creer'] = false; |
|
| 539 | - } |
|
| 540 | - } |
|
| 541 | - else { |
|
| 542 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | - return false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - return $ret; |
|
| 311 | + $ret = []; |
|
| 312 | + $f = null; |
|
| 313 | + static $images_recalcul = []; |
|
| 314 | + if (strlen($img) == 0) { |
|
| 315 | + return false; |
|
| 316 | + } |
|
| 317 | + |
|
| 318 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 319 | + if (strlen($source) < 1) { |
|
| 320 | + $source = $img; |
|
| 321 | + $img = "<img src='$source' />"; |
|
| 322 | + } elseif ( |
|
| 323 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 325 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 326 | + ) { |
|
| 327 | + # gerer img src="data:....base64" |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 329 | + if (!file_exists($local)) { |
|
| 330 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 331 | + } |
|
| 332 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 333 | + $sanitizer($local); |
|
| 334 | + } |
|
| 335 | + $source = $local; |
|
| 336 | + $img = inserer_attribut($img, 'src', $source); |
|
| 337 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 338 | + $img = inserer_attribut($img, 'width', ''); |
|
| 339 | + $img = inserer_attribut($img, 'height', ''); |
|
| 340 | + } |
|
| 341 | + |
|
| 342 | + // les protocoles web prennent au moins 3 lettres |
|
| 343 | + if (tester_url_absolue($source)) { |
|
| 344 | + include_spip('inc/distant'); |
|
| 345 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 346 | + if (!$fichier) { |
|
| 347 | + return ''; |
|
| 348 | + } |
|
| 349 | + if ( |
|
| 350 | + $extension = _image_trouver_extension($fichier) |
|
| 351 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 352 | + ) { |
|
| 353 | + $sanitizer($fichier); |
|
| 354 | + } |
|
| 355 | + } else { |
|
| 356 | + // enlever le timestamp eventuel |
|
| 357 | + if (strpos($source, '?') !== false) { |
|
| 358 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 359 | + } |
|
| 360 | + if ( |
|
| 361 | + strpos($source, '?') !== false |
|
| 362 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 363 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 364 | + ) { |
|
| 365 | + $source = $f; |
|
| 366 | + } |
|
| 367 | + $fichier = $source; |
|
| 368 | + } |
|
| 369 | + |
|
| 370 | + $terminaison_dest = ''; |
|
| 371 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 372 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 373 | + } |
|
| 374 | + |
|
| 375 | + if ( |
|
| 376 | + $forcer_format !== false |
|
| 377 | + // ignorer forcer_format si on a une image svg, que le filtre appelant ne supporte pas SVG, et que le forcage est un autre format image |
|
| 378 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 379 | + ) { |
|
| 380 | + $terminaison_dest = $forcer_format; |
|
| 381 | + } |
|
| 382 | + |
|
| 383 | + if (!$terminaison_dest) { |
|
| 384 | + return false; |
|
| 385 | + } |
|
| 386 | + |
|
| 387 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 388 | + $fichier_dest = $nom_fichier; |
|
| 389 | + if ( |
|
| 390 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 391 | + or @file_exists($f = $fichier) |
|
| 392 | + ) { |
|
| 393 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 394 | + // au lieu de faire un acces disque sur le fichier |
|
| 395 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 396 | + $date_src = @filemtime($f); |
|
| 397 | + } elseif ( |
|
| 398 | + @file_exists($f = "$fichier.src") |
|
| 399 | + and lire_fichier($f, $valeurs) |
|
| 400 | + and $valeurs = unserialize($valeurs) |
|
| 401 | + and isset($valeurs['hauteur_dest']) |
|
| 402 | + and isset($valeurs['largeur_dest']) |
|
| 403 | + ) { |
|
| 404 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 405 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 406 | + $date_src = $valeurs['date']; |
|
| 407 | + } // pas de fichier source par la |
|
| 408 | + else { |
|
| 409 | + return false; |
|
| 410 | + } |
|
| 411 | + |
|
| 412 | + // pas de taille mesurable |
|
| 413 | + if (!($ret['hauteur'] or $ret['largeur'])) { |
|
| 414 | + return false; |
|
| 415 | + } |
|
| 416 | + |
|
| 417 | + // les images calculees dependent du chemin du fichier source |
|
| 418 | + // pour une meme image source et un meme filtre on aboutira a 2 fichiers selon si l'appel est dans le public ou dans le prive |
|
| 419 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 420 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 421 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 422 | + // alors que ca concerne peu de site au final |
|
| 423 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 424 | + $identifiant = $fichier; |
|
| 425 | + |
|
| 426 | + // cas general : |
|
| 427 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 428 | + // cas particulier de reduire : |
|
| 429 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 430 | + $cache = 'cache-gd2'; |
|
| 431 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 432 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 433 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 434 | + $ret['largeur_dest'] = $destWidth; |
|
| 435 | + $ret['hauteur_dest'] = $destHeight; |
|
| 436 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 437 | + $cache = 'cache-vignettes'; |
|
| 438 | + $fichier_dest = basename($fichier_dest); |
|
| 439 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 440 | + // on garde la terminaison initiale car image simplement copiee |
|
| 441 | + // et on postfixe son nom avec un md5 du path |
|
| 442 | + $terminaison_dest = $terminaison; |
|
| 443 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 444 | + } else { |
|
| 445 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | + } |
|
| 447 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 448 | + $cache = sous_repertoire($cache, $effet); |
|
| 449 | + } else { |
|
| 450 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 451 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 452 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 453 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 454 | + } |
|
| 455 | + |
|
| 456 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 457 | + |
|
| 458 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 459 | + |
|
| 460 | + $creer = true; |
|
| 461 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 462 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 463 | + $images_recalcul[$fichier_dest] = true; |
|
| 464 | + } else { |
|
| 465 | + if (@file_exists($f = $fichier_dest)) { |
|
| 466 | + if (filemtime($f) >= $date_src) { |
|
| 467 | + $creer = false; |
|
| 468 | + } |
|
| 469 | + } else { |
|
| 470 | + if ( |
|
| 471 | + @file_exists($f = "$fichier_dest.src") |
|
| 472 | + and lire_fichier($f, $valeurs) |
|
| 473 | + and $valeurs = unserialize($valeurs) |
|
| 474 | + and $valeurs['date'] >= $date_src |
|
| 475 | + ) { |
|
| 476 | + $creer = false; |
|
| 477 | + } |
|
| 478 | + } |
|
| 479 | + } |
|
| 480 | + if ($creer) { |
|
| 481 | + if (!@file_exists($fichier)) { |
|
| 482 | + if (!@file_exists("$fichier.src")) { |
|
| 483 | + spip_log("Image absente : $fichier"); |
|
| 484 | + |
|
| 485 | + return false; |
|
| 486 | + } |
|
| 487 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 488 | + reconstruire_image_intermediaire($fichier); |
|
| 489 | + } |
|
| 490 | + } |
|
| 491 | + |
|
| 492 | + if ($creer) { |
|
| 493 | + spip_log( |
|
| 494 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | + 'images' . _LOG_DEBUG |
|
| 496 | + ); |
|
| 497 | + } |
|
| 498 | + |
|
| 499 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 501 | + $ret['fichier'] = $fichier; |
|
| 502 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 503 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 504 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 505 | + $ret['format_dest'] = $terminaison_dest; |
|
| 506 | + $ret['date_src'] = $date_src; |
|
| 507 | + $ret['creer'] = $creer; |
|
| 508 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 509 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 510 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 511 | + $ret['tag'] = $img; |
|
| 512 | + if ($fonction_creation) { |
|
| 513 | + $ret['reconstruction'] = $fonction_creation; |
|
| 514 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 515 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 516 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 517 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 518 | + } |
|
| 519 | + |
|
| 520 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 521 | + 'args' => [ |
|
| 522 | + 'img' => $img, |
|
| 523 | + 'effet' => $effet, |
|
| 524 | + 'forcer_format' => $forcer_format, |
|
| 525 | + 'fonction_creation' => $fonction_creation, |
|
| 526 | + 'find_in_path' => $find_in_path, |
|
| 527 | + ], |
|
| 528 | + 'data' => $ret |
|
| 529 | + ]); |
|
| 530 | + |
|
| 531 | + // une globale pour le debug en cas de crash memoire |
|
| 532 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 533 | + |
|
| 534 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 535 | + if ($term_fonction === 'svg') { |
|
| 536 | + if ($creer and !$support_svg) { |
|
| 537 | + process_image_svg_identite($ret); |
|
| 538 | + $ret['creer'] = false; |
|
| 539 | + } |
|
| 540 | + } |
|
| 541 | + else { |
|
| 542 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 543 | + return false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + return $ret; |
|
| 548 | 548 | } |
| 549 | 549 | |
| 550 | 550 | |
@@ -553,54 +553,54 @@ discard block |
||
| 553 | 553 | * @return array |
| 554 | 554 | */ |
| 555 | 555 | function _image_extensions_acceptees_en_entree() { |
| 556 | - static $extensions = null; |
|
| 557 | - if (empty($extensions)) { |
|
| 558 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | - $extensions = array_map('trim', $extensions); |
|
| 563 | - $extensions = array_filter($extensions); |
|
| 564 | - if (in_array('jpg', $extensions)) { |
|
| 565 | - $extensions[] = 'jpeg'; |
|
| 566 | - } |
|
| 567 | - $extensions = array_unique($extensions); |
|
| 568 | - } |
|
| 569 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | - } |
|
| 571 | - |
|
| 572 | - return $extensions; |
|
| 556 | + static $extensions = null; |
|
| 557 | + if (empty($extensions)) { |
|
| 558 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 559 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 560 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 561 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 562 | + $extensions = array_map('trim', $extensions); |
|
| 563 | + $extensions = array_filter($extensions); |
|
| 564 | + if (in_array('jpg', $extensions)) { |
|
| 565 | + $extensions[] = 'jpeg'; |
|
| 566 | + } |
|
| 567 | + $extensions = array_unique($extensions); |
|
| 568 | + } |
|
| 569 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 570 | + } |
|
| 571 | + |
|
| 572 | + return $extensions; |
|
| 573 | 573 | } |
| 574 | 574 | |
| 575 | 575 | /** |
| 576 | 576 | * @return array|string[]|null |
| 577 | 577 | */ |
| 578 | 578 | function _image_extensions_acceptees_en_sortie() { |
| 579 | - static $extensions = null; |
|
| 580 | - if (empty($extensions)) { |
|
| 581 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 584 | - $extensions = array_diff($extensions, ['gif']); |
|
| 585 | - } |
|
| 586 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 587 | - $extensions = array_diff($extensions, ['webp']); |
|
| 588 | - } |
|
| 589 | - } |
|
| 590 | - |
|
| 591 | - return $extensions; |
|
| 579 | + static $extensions = null; |
|
| 580 | + if (empty($extensions)) { |
|
| 581 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 582 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 583 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 584 | + $extensions = array_diff($extensions, ['gif']); |
|
| 585 | + } |
|
| 586 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 587 | + $extensions = array_diff($extensions, ['webp']); |
|
| 588 | + } |
|
| 589 | + } |
|
| 590 | + |
|
| 591 | + return $extensions; |
|
| 592 | 592 | } |
| 593 | 593 | |
| 594 | 594 | function _image_extension_normalisee($extension) { |
| 595 | - $extension = strtolower($extension); |
|
| 596 | - if ($extension === 'jpeg') { |
|
| 597 | - $extension = 'jpg'; |
|
| 598 | - } |
|
| 599 | - return $extension; |
|
| 595 | + $extension = strtolower($extension); |
|
| 596 | + if ($extension === 'jpeg') { |
|
| 597 | + $extension = 'jpg'; |
|
| 598 | + } |
|
| 599 | + return $extension; |
|
| 600 | 600 | } |
| 601 | 601 | |
| 602 | 602 | function _image_extensions_conservent_transparence() { |
| 603 | - return ['png', 'webp']; |
|
| 603 | + return ['png', 'webp']; |
|
| 604 | 604 | } |
| 605 | 605 | |
| 606 | 606 | |
@@ -610,12 +610,12 @@ discard block |
||
| 610 | 610 | * @return string |
| 611 | 611 | */ |
| 612 | 612 | function _image_trouver_extension($path) { |
| 613 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | - $terminaison = strtolower($regs[1]); |
|
| 616 | - return $terminaison; |
|
| 617 | - } |
|
| 618 | - return ''; |
|
| 613 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 614 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 615 | + $terminaison = strtolower($regs[1]); |
|
| 616 | + return $terminaison; |
|
| 617 | + } |
|
| 618 | + return ''; |
|
| 619 | 619 | } |
| 620 | 620 | |
| 621 | 621 | /** |
@@ -626,33 +626,33 @@ discard block |
||
| 626 | 626 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 627 | 627 | */ |
| 628 | 628 | function _image_trouver_extension_pertinente($path) { |
| 629 | - $path = supprimer_timestamp($path); |
|
| 630 | - $terminaison = _image_trouver_extension($path); |
|
| 631 | - if ($terminaison == 'jpg') { |
|
| 632 | - $terminaison = 'jpeg'; |
|
| 633 | - } |
|
| 634 | - |
|
| 635 | - if (!file_exists($path)) { |
|
| 636 | - return $terminaison; |
|
| 637 | - } |
|
| 638 | - |
|
| 639 | - if (!$info = @spip_getimagesize($path)) { |
|
| 640 | - return $terminaison; |
|
| 641 | - } |
|
| 642 | - |
|
| 643 | - if (isset($info['mime'])) { |
|
| 644 | - $mime = $info['mime']; |
|
| 645 | - } |
|
| 646 | - else { |
|
| 647 | - $mime = image_type_to_mime_type($info[2]); |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 651 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 652 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 653 | - $terminaison = $_terminaison; |
|
| 654 | - } |
|
| 655 | - return $terminaison; |
|
| 629 | + $path = supprimer_timestamp($path); |
|
| 630 | + $terminaison = _image_trouver_extension($path); |
|
| 631 | + if ($terminaison == 'jpg') { |
|
| 632 | + $terminaison = 'jpeg'; |
|
| 633 | + } |
|
| 634 | + |
|
| 635 | + if (!file_exists($path)) { |
|
| 636 | + return $terminaison; |
|
| 637 | + } |
|
| 638 | + |
|
| 639 | + if (!$info = @spip_getimagesize($path)) { |
|
| 640 | + return $terminaison; |
|
| 641 | + } |
|
| 642 | + |
|
| 643 | + if (isset($info['mime'])) { |
|
| 644 | + $mime = $info['mime']; |
|
| 645 | + } |
|
| 646 | + else { |
|
| 647 | + $mime = image_type_to_mime_type($info[2]); |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 651 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 652 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 653 | + $terminaison = $_terminaison; |
|
| 654 | + } |
|
| 655 | + return $terminaison; |
|
| 656 | 656 | } |
| 657 | 657 | |
| 658 | 658 | /** |
@@ -660,36 +660,36 @@ discard block |
||
| 660 | 660 | * @return string |
| 661 | 661 | */ |
| 662 | 662 | function _image_trouver_extension_depuis_mime($mime) { |
| 663 | - switch (strtolower($mime)) { |
|
| 664 | - case 'image/png': |
|
| 665 | - case 'image/x-png': |
|
| 666 | - $terminaison = 'png'; |
|
| 667 | - break; |
|
| 668 | - |
|
| 669 | - case 'image/jpg': |
|
| 670 | - case 'image/jpeg': |
|
| 671 | - case 'image/pjpeg': |
|
| 672 | - $terminaison = 'jpeg'; |
|
| 673 | - break; |
|
| 674 | - |
|
| 675 | - case 'image/gif': |
|
| 676 | - $terminaison = 'gif'; |
|
| 677 | - break; |
|
| 678 | - |
|
| 679 | - case 'image/webp': |
|
| 680 | - case 'image/x-webp': |
|
| 681 | - $terminaison = 'webp'; |
|
| 682 | - break; |
|
| 683 | - |
|
| 684 | - case 'image/svg+xml': |
|
| 685 | - $terminaison = 'svg'; |
|
| 686 | - break; |
|
| 687 | - |
|
| 688 | - default: |
|
| 689 | - $terminaison = ''; |
|
| 690 | - } |
|
| 691 | - |
|
| 692 | - return $terminaison; |
|
| 663 | + switch (strtolower($mime)) { |
|
| 664 | + case 'image/png': |
|
| 665 | + case 'image/x-png': |
|
| 666 | + $terminaison = 'png'; |
|
| 667 | + break; |
|
| 668 | + |
|
| 669 | + case 'image/jpg': |
|
| 670 | + case 'image/jpeg': |
|
| 671 | + case 'image/pjpeg': |
|
| 672 | + $terminaison = 'jpeg'; |
|
| 673 | + break; |
|
| 674 | + |
|
| 675 | + case 'image/gif': |
|
| 676 | + $terminaison = 'gif'; |
|
| 677 | + break; |
|
| 678 | + |
|
| 679 | + case 'image/webp': |
|
| 680 | + case 'image/x-webp': |
|
| 681 | + $terminaison = 'webp'; |
|
| 682 | + break; |
|
| 683 | + |
|
| 684 | + case 'image/svg+xml': |
|
| 685 | + $terminaison = 'svg'; |
|
| 686 | + break; |
|
| 687 | + |
|
| 688 | + default: |
|
| 689 | + $terminaison = ''; |
|
| 690 | + } |
|
| 691 | + |
|
| 692 | + return $terminaison; |
|
| 693 | 693 | } |
| 694 | 694 | |
| 695 | 695 | |
@@ -709,18 +709,18 @@ discard block |
||
| 709 | 709 | * Une ressource de type Image GD. |
| 710 | 710 | */ |
| 711 | 711 | function _imagecreatefrom_func(string $func, string $filename) { |
| 712 | - if (!function_exists($func)) { |
|
| 713 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 714 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 715 | - return null; |
|
| 716 | - } |
|
| 717 | - $img = @$func($filename); |
|
| 718 | - if (!$img) { |
|
| 719 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 720 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 721 | - $img = imagecreate(10, 10); |
|
| 722 | - } |
|
| 723 | - return $img; |
|
| 712 | + if (!function_exists($func)) { |
|
| 713 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 714 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 715 | + return null; |
|
| 716 | + } |
|
| 717 | + $img = @$func($filename); |
|
| 718 | + if (!$img) { |
|
| 719 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 720 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 721 | + $img = imagecreate(10, 10); |
|
| 722 | + } |
|
| 723 | + return $img; |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -736,7 +736,7 @@ discard block |
||
| 736 | 736 | * Une ressource de type Image GD. |
| 737 | 737 | */ |
| 738 | 738 | function _imagecreatefromjpeg($filename) { |
| 739 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 739 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 740 | 740 | } |
| 741 | 741 | |
| 742 | 742 | /** |
@@ -752,7 +752,7 @@ discard block |
||
| 752 | 752 | * Une ressource de type Image GD. |
| 753 | 753 | */ |
| 754 | 754 | function _imagecreatefrompng($filename) { |
| 755 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 755 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | /** |
@@ -768,7 +768,7 @@ discard block |
||
| 768 | 768 | * Une ressource de type Image GD. |
| 769 | 769 | */ |
| 770 | 770 | function _imagecreatefromgif($filename) { |
| 771 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 771 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 772 | 772 | } |
| 773 | 773 | |
| 774 | 774 | |
@@ -785,7 +785,7 @@ discard block |
||
| 785 | 785 | * Une ressource de type Image GD. |
| 786 | 786 | */ |
| 787 | 787 | function _imagecreatefromwebp($filename) { |
| 788 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 788 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 789 | 789 | } |
| 790 | 790 | |
| 791 | 791 | /** |
@@ -803,24 +803,24 @@ discard block |
||
| 803 | 803 | * - true si une image est bien retournée. |
| 804 | 804 | */ |
| 805 | 805 | function _image_imagepng($img, $fichier) { |
| 806 | - if (!function_exists('imagepng')) { |
|
| 807 | - return false; |
|
| 808 | - } |
|
| 809 | - $tmp = $fichier . '.tmp'; |
|
| 810 | - $ret = imagepng($img, $tmp); |
|
| 811 | - if (file_exists($tmp)) { |
|
| 812 | - $taille_test = getimagesize($tmp); |
|
| 813 | - if ($taille_test[0] < 1) { |
|
| 814 | - return false; |
|
| 815 | - } |
|
| 816 | - |
|
| 817 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 818 | - @rename($tmp, $fichier); |
|
| 819 | - |
|
| 820 | - return $ret; |
|
| 821 | - } |
|
| 822 | - |
|
| 823 | - return false; |
|
| 806 | + if (!function_exists('imagepng')) { |
|
| 807 | + return false; |
|
| 808 | + } |
|
| 809 | + $tmp = $fichier . '.tmp'; |
|
| 810 | + $ret = imagepng($img, $tmp); |
|
| 811 | + if (file_exists($tmp)) { |
|
| 812 | + $taille_test = getimagesize($tmp); |
|
| 813 | + if ($taille_test[0] < 1) { |
|
| 814 | + return false; |
|
| 815 | + } |
|
| 816 | + |
|
| 817 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 818 | + @rename($tmp, $fichier); |
|
| 819 | + |
|
| 820 | + return $ret; |
|
| 821 | + } |
|
| 822 | + |
|
| 823 | + return false; |
|
| 824 | 824 | } |
| 825 | 825 | |
| 826 | 826 | /** |
@@ -838,24 +838,24 @@ discard block |
||
| 838 | 838 | * - true si une image est bien retournée. |
| 839 | 839 | */ |
| 840 | 840 | function _image_imagegif($img, $fichier) { |
| 841 | - if (!function_exists('imagegif')) { |
|
| 842 | - return false; |
|
| 843 | - } |
|
| 844 | - $tmp = $fichier . '.tmp'; |
|
| 845 | - $ret = imagegif($img, $tmp); |
|
| 846 | - if (file_exists($tmp)) { |
|
| 847 | - $taille_test = getimagesize($tmp); |
|
| 848 | - if ($taille_test[0] < 1) { |
|
| 849 | - return false; |
|
| 850 | - } |
|
| 851 | - |
|
| 852 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 853 | - @rename($tmp, $fichier); |
|
| 854 | - |
|
| 855 | - return $ret; |
|
| 856 | - } |
|
| 857 | - |
|
| 858 | - return false; |
|
| 841 | + if (!function_exists('imagegif')) { |
|
| 842 | + return false; |
|
| 843 | + } |
|
| 844 | + $tmp = $fichier . '.tmp'; |
|
| 845 | + $ret = imagegif($img, $tmp); |
|
| 846 | + if (file_exists($tmp)) { |
|
| 847 | + $taille_test = getimagesize($tmp); |
|
| 848 | + if ($taille_test[0] < 1) { |
|
| 849 | + return false; |
|
| 850 | + } |
|
| 851 | + |
|
| 852 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 853 | + @rename($tmp, $fichier); |
|
| 854 | + |
|
| 855 | + return $ret; |
|
| 856 | + } |
|
| 857 | + |
|
| 858 | + return false; |
|
| 859 | 859 | } |
| 860 | 860 | |
| 861 | 861 | /** |
@@ -878,29 +878,29 @@ discard block |
||
| 878 | 878 | * - true si une image est bien retournée. |
| 879 | 879 | */ |
| 880 | 880 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 881 | - if (!function_exists('imagejpeg')) { |
|
| 882 | - return false; |
|
| 883 | - } |
|
| 884 | - $tmp = $fichier . '.tmp'; |
|
| 881 | + if (!function_exists('imagejpeg')) { |
|
| 882 | + return false; |
|
| 883 | + } |
|
| 884 | + $tmp = $fichier . '.tmp'; |
|
| 885 | 885 | |
| 886 | - // Enable interlancing |
|
| 887 | - imageinterlace($img, true); |
|
| 886 | + // Enable interlancing |
|
| 887 | + imageinterlace($img, true); |
|
| 888 | 888 | |
| 889 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 889 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 890 | 890 | |
| 891 | - if (file_exists($tmp)) { |
|
| 892 | - $taille_test = getimagesize($tmp); |
|
| 893 | - if ($taille_test[0] < 1) { |
|
| 894 | - return false; |
|
| 895 | - } |
|
| 891 | + if (file_exists($tmp)) { |
|
| 892 | + $taille_test = getimagesize($tmp); |
|
| 893 | + if ($taille_test[0] < 1) { |
|
| 894 | + return false; |
|
| 895 | + } |
|
| 896 | 896 | |
| 897 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 898 | - @rename($tmp, $fichier); |
|
| 897 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 898 | + @rename($tmp, $fichier); |
|
| 899 | 899 | |
| 900 | - return $ret; |
|
| 901 | - } |
|
| 900 | + return $ret; |
|
| 901 | + } |
|
| 902 | 902 | |
| 903 | - return false; |
|
| 903 | + return false; |
|
| 904 | 904 | } |
| 905 | 905 | |
| 906 | 906 | /** |
@@ -918,9 +918,9 @@ discard block |
||
| 918 | 918 | * true si le fichier a bien été créé ; false sinon. |
| 919 | 919 | */ |
| 920 | 920 | function _image_imageico($img, $fichier) { |
| 921 | - $gd_image_array = [$img]; |
|
| 921 | + $gd_image_array = [$img]; |
|
| 922 | 922 | |
| 923 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 923 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -939,24 +939,24 @@ discard block |
||
| 939 | 939 | * - true si une image est bien retournée. |
| 940 | 940 | */ |
| 941 | 941 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 942 | - if (!function_exists('imagewebp')) { |
|
| 943 | - return false; |
|
| 944 | - } |
|
| 945 | - $tmp = $fichier . '.tmp'; |
|
| 946 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 947 | - if (file_exists($tmp)) { |
|
| 948 | - $taille_test = getimagesize($tmp); |
|
| 949 | - if ($taille_test[0] < 1) { |
|
| 950 | - return false; |
|
| 951 | - } |
|
| 952 | - |
|
| 953 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 954 | - @rename($tmp, $fichier); |
|
| 955 | - |
|
| 956 | - return $ret; |
|
| 957 | - } |
|
| 958 | - |
|
| 959 | - return false; |
|
| 942 | + if (!function_exists('imagewebp')) { |
|
| 943 | + return false; |
|
| 944 | + } |
|
| 945 | + $tmp = $fichier . '.tmp'; |
|
| 946 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 947 | + if (file_exists($tmp)) { |
|
| 948 | + $taille_test = getimagesize($tmp); |
|
| 949 | + if ($taille_test[0] < 1) { |
|
| 950 | + return false; |
|
| 951 | + } |
|
| 952 | + |
|
| 953 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 954 | + @rename($tmp, $fichier); |
|
| 955 | + |
|
| 956 | + return $ret; |
|
| 957 | + } |
|
| 958 | + |
|
| 959 | + return false; |
|
| 960 | 960 | } |
| 961 | 961 | |
| 962 | 962 | /** |
@@ -976,35 +976,35 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | function _image_imagesvg($img, $fichier) { |
| 978 | 978 | |
| 979 | - $tmp = $fichier . '.tmp'; |
|
| 980 | - if (strpos($img, '<') === false) { |
|
| 981 | - $img = supprimer_timestamp($img); |
|
| 982 | - if (!file_exists($img)) { |
|
| 983 | - return false; |
|
| 984 | - } |
|
| 985 | - @copy($img, $tmp); |
|
| 986 | - if (filesize($tmp) == filesize($img)) { |
|
| 987 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | - @rename($tmp, $fichier); |
|
| 989 | - return true; |
|
| 990 | - } |
|
| 991 | - return false; |
|
| 992 | - } |
|
| 993 | - |
|
| 994 | - file_put_contents($tmp, $img); |
|
| 995 | - if (file_exists($tmp)) { |
|
| 996 | - $taille_test = spip_getimagesize($tmp); |
|
| 997 | - if ($taille_test[0] < 1) { |
|
| 998 | - return false; |
|
| 999 | - } |
|
| 1000 | - |
|
| 1001 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1002 | - @rename($tmp, $fichier); |
|
| 1003 | - |
|
| 1004 | - return true; |
|
| 1005 | - } |
|
| 1006 | - |
|
| 1007 | - return false; |
|
| 979 | + $tmp = $fichier . '.tmp'; |
|
| 980 | + if (strpos($img, '<') === false) { |
|
| 981 | + $img = supprimer_timestamp($img); |
|
| 982 | + if (!file_exists($img)) { |
|
| 983 | + return false; |
|
| 984 | + } |
|
| 985 | + @copy($img, $tmp); |
|
| 986 | + if (filesize($tmp) == filesize($img)) { |
|
| 987 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 988 | + @rename($tmp, $fichier); |
|
| 989 | + return true; |
|
| 990 | + } |
|
| 991 | + return false; |
|
| 992 | + } |
|
| 993 | + |
|
| 994 | + file_put_contents($tmp, $img); |
|
| 995 | + if (file_exists($tmp)) { |
|
| 996 | + $taille_test = spip_getimagesize($tmp); |
|
| 997 | + if ($taille_test[0] < 1) { |
|
| 998 | + return false; |
|
| 999 | + } |
|
| 1000 | + |
|
| 1001 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1002 | + @rename($tmp, $fichier); |
|
| 1003 | + |
|
| 1004 | + return true; |
|
| 1005 | + } |
|
| 1006 | + |
|
| 1007 | + return false; |
|
| 1008 | 1008 | } |
| 1009 | 1009 | |
| 1010 | 1010 | |
@@ -1032,30 +1032,30 @@ discard block |
||
| 1032 | 1032 | * - false sinon. |
| 1033 | 1033 | */ |
| 1034 | 1034 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1035 | - if (is_null($fonction)) { |
|
| 1036 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1037 | - } |
|
| 1038 | - $ret = false; |
|
| 1039 | - #un flag pour reperer les images gravees |
|
| 1040 | - $lock = ( |
|
| 1041 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1042 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1043 | - ); |
|
| 1044 | - if ( |
|
| 1045 | - function_exists($fonction) |
|
| 1046 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1047 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1048 | - && !$lock |
|
| 1049 | - ) { |
|
| 1050 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1051 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1052 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1053 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1054 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1055 | - } |
|
| 1056 | - } |
|
| 1057 | - |
|
| 1058 | - return $ret; |
|
| 1035 | + if (is_null($fonction)) { |
|
| 1036 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1037 | + } |
|
| 1038 | + $ret = false; |
|
| 1039 | + #un flag pour reperer les images gravees |
|
| 1040 | + $lock = ( |
|
| 1041 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1042 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1043 | + ); |
|
| 1044 | + if ( |
|
| 1045 | + function_exists($fonction) |
|
| 1046 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1047 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1048 | + && !$lock |
|
| 1049 | + ) { |
|
| 1050 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1051 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1052 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1053 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1054 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1055 | + } |
|
| 1056 | + } |
|
| 1057 | + |
|
| 1058 | + return $ret; |
|
| 1059 | 1059 | } |
| 1060 | 1060 | |
| 1061 | 1061 | /** |
@@ -1068,27 +1068,27 @@ discard block |
||
| 1068 | 1068 | * Chemin vers le fichier manquant |
| 1069 | 1069 | **/ |
| 1070 | 1070 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1071 | - $reconstruire = []; |
|
| 1072 | - $fichier = $fichier_manquant; |
|
| 1073 | - while ( |
|
| 1074 | - strpos($fichier, '://') === false |
|
| 1075 | - and !@file_exists($fichier) |
|
| 1076 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1077 | - and $valeurs = unserialize($source) |
|
| 1078 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1079 | - ) { |
|
| 1080 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1081 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1082 | - } |
|
| 1083 | - while (count($reconstruire)) { |
|
| 1084 | - $r = array_pop($reconstruire); |
|
| 1085 | - $fonction = $r[0]; |
|
| 1086 | - $args = $r[1]; |
|
| 1087 | - $fonction(...$args); |
|
| 1088 | - } |
|
| 1089 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1090 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1091 | - ramasse_miettes($fichier_manquant); |
|
| 1071 | + $reconstruire = []; |
|
| 1072 | + $fichier = $fichier_manquant; |
|
| 1073 | + while ( |
|
| 1074 | + strpos($fichier, '://') === false |
|
| 1075 | + and !@file_exists($fichier) |
|
| 1076 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1077 | + and $valeurs = unserialize($source) |
|
| 1078 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1079 | + ) { |
|
| 1080 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1081 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1082 | + } |
|
| 1083 | + while (count($reconstruire)) { |
|
| 1084 | + $r = array_pop($reconstruire); |
|
| 1085 | + $fonction = $r[0]; |
|
| 1086 | + $args = $r[1]; |
|
| 1087 | + $fonction(...$args); |
|
| 1088 | + } |
|
| 1089 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1090 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1091 | + ramasse_miettes($fichier_manquant); |
|
| 1092 | 1092 | } |
| 1093 | 1093 | |
| 1094 | 1094 | /** |
@@ -1108,28 +1108,28 @@ discard block |
||
| 1108 | 1108 | * Chemin du fichier d'image calculé |
| 1109 | 1109 | **/ |
| 1110 | 1110 | function ramasse_miettes($fichier) { |
| 1111 | - if ( |
|
| 1112 | - strpos($fichier, '://') !== false |
|
| 1113 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1114 | - or !$valeurs = unserialize($source) |
|
| 1115 | - ) { |
|
| 1116 | - return; |
|
| 1117 | - } |
|
| 1118 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1119 | - while ( |
|
| 1120 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1121 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1122 | - and (lire_fichier( |
|
| 1123 | - $src = "$fichier.src", |
|
| 1124 | - $source |
|
| 1125 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1126 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1127 | - ) { |
|
| 1128 | - # on efface le fichier |
|
| 1129 | - spip_unlink($fichier); |
|
| 1130 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1131 | - #spip_unlink($src); |
|
| 1132 | - } |
|
| 1111 | + if ( |
|
| 1112 | + strpos($fichier, '://') !== false |
|
| 1113 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1114 | + or !$valeurs = unserialize($source) |
|
| 1115 | + ) { |
|
| 1116 | + return; |
|
| 1117 | + } |
|
| 1118 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1119 | + while ( |
|
| 1120 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1121 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1122 | + and (lire_fichier( |
|
| 1123 | + $src = "$fichier.src", |
|
| 1124 | + $source |
|
| 1125 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1126 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1127 | + ) { |
|
| 1128 | + # on efface le fichier |
|
| 1129 | + spip_unlink($fichier); |
|
| 1130 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1131 | + #spip_unlink($src); |
|
| 1132 | + } |
|
| 1133 | 1133 | } |
| 1134 | 1134 | |
| 1135 | 1135 | |
@@ -1154,31 +1154,31 @@ discard block |
||
| 1154 | 1154 | * Code HTML de l'image |
| 1155 | 1155 | **/ |
| 1156 | 1156 | function image_graver($img) { |
| 1157 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1158 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1159 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1160 | - |
|
| 1161 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1162 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1163 | - $fichier = substr($fichier, 0, $p); |
|
| 1164 | - } |
|
| 1165 | - if (strlen($fichier) < 1) { |
|
| 1166 | - $fichier = $img; |
|
| 1167 | - } |
|
| 1168 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1169 | - # et qu'il ne s'agit pas d'une URL |
|
| 1170 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1171 | - reconstruire_image_intermediaire($fichier); |
|
| 1172 | - } |
|
| 1173 | - ramasse_miettes($fichier); |
|
| 1174 | - |
|
| 1175 | - // ajouter le timestamp si besoin |
|
| 1176 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1177 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1178 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1179 | - } |
|
| 1180 | - |
|
| 1181 | - return $img; |
|
| 1157 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1158 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1159 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1160 | + |
|
| 1161 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1162 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1163 | + $fichier = substr($fichier, 0, $p); |
|
| 1164 | + } |
|
| 1165 | + if (strlen($fichier) < 1) { |
|
| 1166 | + $fichier = $img; |
|
| 1167 | + } |
|
| 1168 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1169 | + # et qu'il ne s'agit pas d'une URL |
|
| 1170 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1171 | + reconstruire_image_intermediaire($fichier); |
|
| 1172 | + } |
|
| 1173 | + ramasse_miettes($fichier); |
|
| 1174 | + |
|
| 1175 | + // ajouter le timestamp si besoin |
|
| 1176 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1177 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1178 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1179 | + } |
|
| 1180 | + |
|
| 1181 | + return $img; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1205,34 +1205,34 @@ discard block |
||
| 1205 | 1205 | * Code html modifié de la balise. |
| 1206 | 1206 | **/ |
| 1207 | 1207 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1208 | - if ($style === false) { |
|
| 1209 | - $style = extraire_attribut($tag, 'style'); |
|
| 1210 | - } |
|
| 1211 | - |
|
| 1212 | - // enlever le width et height du style |
|
| 1213 | - if ($style) { |
|
| 1214 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1215 | - } |
|
| 1216 | - if ($style and $style[0] === ';') { |
|
| 1217 | - $style = substr($style, 1); |
|
| 1218 | - } |
|
| 1219 | - |
|
| 1220 | - // mettre des attributs de width et height sur les images, |
|
| 1221 | - // ca accelere le rendu du navigateur |
|
| 1222 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1223 | - // quand on a desactive l'affichage des images. |
|
| 1224 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1225 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1226 | - |
|
| 1227 | - // attributs deprecies. Transformer en CSS |
|
| 1228 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1229 | - $style = "margin:{$espace}px;" . $style; |
|
| 1230 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1231 | - } |
|
| 1232 | - |
|
| 1233 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1234 | - |
|
| 1235 | - return $tag; |
|
| 1208 | + if ($style === false) { |
|
| 1209 | + $style = extraire_attribut($tag, 'style'); |
|
| 1210 | + } |
|
| 1211 | + |
|
| 1212 | + // enlever le width et height du style |
|
| 1213 | + if ($style) { |
|
| 1214 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1215 | + } |
|
| 1216 | + if ($style and $style[0] === ';') { |
|
| 1217 | + $style = substr($style, 1); |
|
| 1218 | + } |
|
| 1219 | + |
|
| 1220 | + // mettre des attributs de width et height sur les images, |
|
| 1221 | + // ca accelere le rendu du navigateur |
|
| 1222 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1223 | + // quand on a desactive l'affichage des images. |
|
| 1224 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1225 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1226 | + |
|
| 1227 | + // attributs deprecies. Transformer en CSS |
|
| 1228 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1229 | + $style = "margin:{$espace}px;" . $style; |
|
| 1230 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1231 | + } |
|
| 1232 | + |
|
| 1233 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1234 | + |
|
| 1235 | + return $tag; |
|
| 1236 | 1236 | } |
| 1237 | 1237 | |
| 1238 | 1238 | |
@@ -1258,72 +1258,72 @@ discard block |
||
| 1258 | 1258 | * Retourne le code HTML de l'image |
| 1259 | 1259 | **/ |
| 1260 | 1260 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1261 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1262 | - |
|
| 1263 | - // fermer les tags img pas bien fermes; |
|
| 1264 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1265 | - |
|
| 1266 | - // le style |
|
| 1267 | - $style = $valeurs['style']; |
|
| 1268 | - if (isset($surcharge['style'])) { |
|
| 1269 | - $style = $surcharge['style']; |
|
| 1270 | - unset($surcharge['style']); |
|
| 1271 | - } |
|
| 1272 | - |
|
| 1273 | - // traiter specifiquement la largeur et la hauteur |
|
| 1274 | - $width = $valeurs['largeur']; |
|
| 1275 | - if (isset($surcharge['width'])) { |
|
| 1276 | - $width = $surcharge['width']; |
|
| 1277 | - unset($surcharge['width']); |
|
| 1278 | - } |
|
| 1279 | - $height = $valeurs['hauteur']; |
|
| 1280 | - if (isset($surcharge['height'])) { |
|
| 1281 | - $height = $surcharge['height']; |
|
| 1282 | - unset($surcharge['height']); |
|
| 1283 | - } |
|
| 1284 | - |
|
| 1285 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1286 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1287 | - // on remplace toute les ref a src dans le tag |
|
| 1288 | - $src = extraire_attribut($tag, 'src'); |
|
| 1289 | - if (isset($surcharge['src'])) { |
|
| 1290 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1291 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1292 | - // pas garanti comme methode, mais mieux que rien |
|
| 1293 | - if (strpos($src, '&') !== false) { |
|
| 1294 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1295 | - } |
|
| 1296 | - $src = $surcharge['src']; |
|
| 1297 | - unset($surcharge['src']); |
|
| 1298 | - } |
|
| 1299 | - |
|
| 1300 | - $class = $valeurs['class']; |
|
| 1301 | - if (isset($surcharge['class'])) { |
|
| 1302 | - $class = $surcharge['class']; |
|
| 1303 | - unset($surcharge['class']); |
|
| 1304 | - } |
|
| 1305 | - if (is_scalar($class) && strlen($class)) { |
|
| 1306 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1307 | - } |
|
| 1308 | - |
|
| 1309 | - if (count($surcharge)) { |
|
| 1310 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1311 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1312 | - } |
|
| 1313 | - } |
|
| 1314 | - |
|
| 1315 | - $tag = pipeline( |
|
| 1316 | - 'image_ecrire_tag_finir', |
|
| 1317 | - [ |
|
| 1318 | - 'args' => [ |
|
| 1319 | - 'valeurs' => $valeurs, |
|
| 1320 | - 'surcharge' => $surcharge, |
|
| 1321 | - ], |
|
| 1322 | - 'data' => $tag |
|
| 1323 | - ] |
|
| 1324 | - ); |
|
| 1325 | - |
|
| 1326 | - return $tag; |
|
| 1261 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1262 | + |
|
| 1263 | + // fermer les tags img pas bien fermes; |
|
| 1264 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1265 | + |
|
| 1266 | + // le style |
|
| 1267 | + $style = $valeurs['style']; |
|
| 1268 | + if (isset($surcharge['style'])) { |
|
| 1269 | + $style = $surcharge['style']; |
|
| 1270 | + unset($surcharge['style']); |
|
| 1271 | + } |
|
| 1272 | + |
|
| 1273 | + // traiter specifiquement la largeur et la hauteur |
|
| 1274 | + $width = $valeurs['largeur']; |
|
| 1275 | + if (isset($surcharge['width'])) { |
|
| 1276 | + $width = $surcharge['width']; |
|
| 1277 | + unset($surcharge['width']); |
|
| 1278 | + } |
|
| 1279 | + $height = $valeurs['hauteur']; |
|
| 1280 | + if (isset($surcharge['height'])) { |
|
| 1281 | + $height = $surcharge['height']; |
|
| 1282 | + unset($surcharge['height']); |
|
| 1283 | + } |
|
| 1284 | + |
|
| 1285 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1286 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1287 | + // on remplace toute les ref a src dans le tag |
|
| 1288 | + $src = extraire_attribut($tag, 'src'); |
|
| 1289 | + if (isset($surcharge['src'])) { |
|
| 1290 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1291 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1292 | + // pas garanti comme methode, mais mieux que rien |
|
| 1293 | + if (strpos($src, '&') !== false) { |
|
| 1294 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1295 | + } |
|
| 1296 | + $src = $surcharge['src']; |
|
| 1297 | + unset($surcharge['src']); |
|
| 1298 | + } |
|
| 1299 | + |
|
| 1300 | + $class = $valeurs['class']; |
|
| 1301 | + if (isset($surcharge['class'])) { |
|
| 1302 | + $class = $surcharge['class']; |
|
| 1303 | + unset($surcharge['class']); |
|
| 1304 | + } |
|
| 1305 | + if (is_scalar($class) && strlen($class)) { |
|
| 1306 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1307 | + } |
|
| 1308 | + |
|
| 1309 | + if (count($surcharge)) { |
|
| 1310 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1311 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1312 | + } |
|
| 1313 | + } |
|
| 1314 | + |
|
| 1315 | + $tag = pipeline( |
|
| 1316 | + 'image_ecrire_tag_finir', |
|
| 1317 | + [ |
|
| 1318 | + 'args' => [ |
|
| 1319 | + 'valeurs' => $valeurs, |
|
| 1320 | + 'surcharge' => $surcharge, |
|
| 1321 | + ], |
|
| 1322 | + 'data' => $tag |
|
| 1323 | + ] |
|
| 1324 | + ); |
|
| 1325 | + |
|
| 1326 | + return $tag; |
|
| 1327 | 1327 | } |
| 1328 | 1328 | |
| 1329 | 1329 | /** |
@@ -1346,267 +1346,267 @@ discard block |
||
| 1346 | 1346 | * Description de l'image, sinon null. |
| 1347 | 1347 | **/ |
| 1348 | 1348 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1349 | - $srcHeight = null; |
|
| 1350 | - $retour = []; |
|
| 1351 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1352 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1353 | - $image = $valeurs['fichier']; |
|
| 1354 | - $format = $valeurs['format_source']; |
|
| 1355 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1356 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1357 | - |
|
| 1358 | - $format_sortie = $valeurs['format_dest']; |
|
| 1359 | - |
|
| 1360 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1361 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1365 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1366 | - return; |
|
| 1367 | - } |
|
| 1368 | - $destination = "$destdir/$destfile"; |
|
| 1369 | - |
|
| 1370 | - // calculer la taille |
|
| 1371 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1372 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1373 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1374 | - } |
|
| 1375 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1376 | - $destWidth = $maxWidth; |
|
| 1377 | - $destHeight = $maxHeight; |
|
| 1378 | - } else { |
|
| 1379 | - spip_log("echec $process sur $image"); |
|
| 1380 | - |
|
| 1381 | - return; |
|
| 1382 | - } |
|
| 1383 | - |
|
| 1384 | - $vignette = ''; |
|
| 1385 | - |
|
| 1386 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1387 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1388 | - $vignette = $destination . '.' . $format; |
|
| 1389 | - @copy($image, $vignette); |
|
| 1390 | - } |
|
| 1391 | - |
|
| 1392 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1393 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1394 | - $format_sortie = 'svg'; |
|
| 1395 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1396 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1397 | - _image_gd_output($svg, $valeurs); |
|
| 1398 | - } |
|
| 1399 | - } |
|
| 1400 | - |
|
| 1401 | - // imagemagick en ligne de commande |
|
| 1402 | - elseif ($process == 'convert') { |
|
| 1403 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1404 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1405 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1406 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1407 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1408 | - } |
|
| 1409 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1410 | - $commande = str_replace( |
|
| 1411 | - ['%x', '%y', '%src', '%dest'], |
|
| 1412 | - [ |
|
| 1413 | - $destWidth, |
|
| 1414 | - $destHeight, |
|
| 1415 | - escapeshellcmd($image), |
|
| 1416 | - escapeshellcmd($vignette) |
|
| 1417 | - ], |
|
| 1418 | - _RESIZE_COMMAND |
|
| 1419 | - ); |
|
| 1420 | - spip_log($commande); |
|
| 1421 | - exec($commande); |
|
| 1422 | - if (!@file_exists($vignette)) { |
|
| 1423 | - spip_log("echec convert sur $vignette"); |
|
| 1424 | - |
|
| 1425 | - return; // echec commande |
|
| 1426 | - } |
|
| 1427 | - } |
|
| 1428 | - |
|
| 1429 | - // php5 imagemagick |
|
| 1430 | - elseif ($process == 'imagick') { |
|
| 1431 | - if (!class_exists(\Imagick::class)) { |
|
| 1432 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1433 | - |
|
| 1434 | - return; |
|
| 1435 | - } |
|
| 1436 | - |
|
| 1437 | - // chemin compatible Windows |
|
| 1438 | - $output = realpath(dirname($destination)); |
|
| 1439 | - if (!$output) { |
|
| 1440 | - return; |
|
| 1441 | - } |
|
| 1442 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1443 | - |
|
| 1444 | - $imagick = new Imagick(); |
|
| 1445 | - $imagick->readImage(realpath($image)); |
|
| 1446 | - $imagick->resizeImage( |
|
| 1447 | - $destWidth, |
|
| 1448 | - $destHeight, |
|
| 1449 | - Imagick::FILTER_LANCZOS, |
|
| 1450 | - 1 |
|
| 1451 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1452 | - $imagick->writeImage($vignette); |
|
| 1453 | - |
|
| 1454 | - if (!@file_exists($vignette)) { |
|
| 1455 | - spip_log("echec imagick sur $vignette"); |
|
| 1456 | - |
|
| 1457 | - return; |
|
| 1458 | - } |
|
| 1459 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1460 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1461 | - } |
|
| 1462 | - |
|
| 1463 | - // netpbm |
|
| 1464 | - elseif ($process == 'netpbm') { |
|
| 1465 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1466 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1467 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1468 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1469 | - return; |
|
| 1470 | - } |
|
| 1471 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1472 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1473 | - if ($format == 'jpg') { |
|
| 1474 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1475 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1476 | - if (!($s = @filesize($vignette))) { |
|
| 1477 | - spip_unlink($vignette); |
|
| 1478 | - } |
|
| 1479 | - if (!@file_exists($vignette)) { |
|
| 1480 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1481 | - |
|
| 1482 | - return; |
|
| 1483 | - } |
|
| 1484 | - } else { |
|
| 1485 | - if ($format == 'gif') { |
|
| 1486 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1487 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1488 | - if (!($s = @filesize($vignette))) { |
|
| 1489 | - spip_unlink($vignette); |
|
| 1490 | - } |
|
| 1491 | - if (!@file_exists($vignette)) { |
|
| 1492 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1493 | - |
|
| 1494 | - return; |
|
| 1495 | - } |
|
| 1496 | - } else { |
|
| 1497 | - if ($format == 'png') { |
|
| 1498 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1499 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1500 | - if (!($s = @filesize($vignette))) { |
|
| 1501 | - spip_unlink($vignette); |
|
| 1502 | - } |
|
| 1503 | - if (!@file_exists($vignette)) { |
|
| 1504 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1505 | - |
|
| 1506 | - return; |
|
| 1507 | - } |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - } |
|
| 1512 | - |
|
| 1513 | - // gd ou gd2 |
|
| 1514 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1515 | - if (!function_exists('gd_info')) { |
|
| 1516 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1517 | - |
|
| 1518 | - return; |
|
| 1519 | - } |
|
| 1520 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1521 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1522 | - |
|
| 1523 | - return; |
|
| 1524 | - } |
|
| 1525 | - $destFormat = $format_sortie; |
|
| 1526 | - if (!$destFormat) { |
|
| 1527 | - spip_log("pas de format pour $image"); |
|
| 1528 | - |
|
| 1529 | - return; |
|
| 1530 | - } |
|
| 1531 | - |
|
| 1532 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1533 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1534 | - return; |
|
| 1535 | - } |
|
| 1536 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1537 | - if (!$srcImage) { |
|
| 1538 | - spip_log('echec gd1/gd2'); |
|
| 1539 | - |
|
| 1540 | - return; |
|
| 1541 | - } |
|
| 1542 | - |
|
| 1543 | - // Initialisation de l'image destination |
|
| 1544 | - $destImage = null; |
|
| 1545 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1546 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1547 | - } |
|
| 1548 | - if (!$destImage) { |
|
| 1549 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1550 | - } |
|
| 1551 | - |
|
| 1552 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1553 | - $ok = false; |
|
| 1554 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1555 | - if ($format == 'gif') { |
|
| 1556 | - // Si un GIF est transparent, |
|
| 1557 | - // fabriquer un PNG transparent |
|
| 1558 | - $transp = imagecolortransparent($srcImage); |
|
| 1559 | - if ($transp > 0) { |
|
| 1560 | - $destFormat = 'png'; |
|
| 1561 | - } |
|
| 1562 | - } |
|
| 1563 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1564 | - // Conserver la transparence |
|
| 1565 | - if (function_exists('imageAntiAlias')) { |
|
| 1566 | - imageAntiAlias($destImage, true); |
|
| 1567 | - } |
|
| 1568 | - @imagealphablending($destImage, false); |
|
| 1569 | - @imagesavealpha($destImage, true); |
|
| 1570 | - } |
|
| 1571 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1572 | - } |
|
| 1573 | - if (!$ok) { |
|
| 1574 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1575 | - } |
|
| 1576 | - |
|
| 1577 | - // Sauvegarde de l'image destination |
|
| 1578 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1579 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1580 | - _image_gd_output($destImage, $valeurs); |
|
| 1581 | - |
|
| 1582 | - if ($srcImage) { |
|
| 1583 | - ImageDestroy($srcImage); |
|
| 1584 | - } |
|
| 1585 | - ImageDestroy($destImage); |
|
| 1586 | - } |
|
| 1587 | - |
|
| 1588 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1589 | - $size = [$destWidth, $destHeight]; |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1593 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1594 | - if ($size[0] < 1) { |
|
| 1595 | - $size[0] = $destWidth; |
|
| 1596 | - } |
|
| 1597 | - if ($size[1] < 1) { |
|
| 1598 | - $size[1] = $destHeight; |
|
| 1599 | - } |
|
| 1600 | - |
|
| 1601 | - $retour['width'] = $largeur = $size[0]; |
|
| 1602 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1603 | - |
|
| 1604 | - $retour['fichier'] = $vignette; |
|
| 1605 | - $retour['format'] = $format; |
|
| 1606 | - $retour['date'] = @filemtime($vignette); |
|
| 1607 | - |
|
| 1608 | - // renvoyer l'image |
|
| 1609 | - return $retour; |
|
| 1349 | + $srcHeight = null; |
|
| 1350 | + $retour = []; |
|
| 1351 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1352 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1353 | + $image = $valeurs['fichier']; |
|
| 1354 | + $format = $valeurs['format_source']; |
|
| 1355 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1356 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1357 | + |
|
| 1358 | + $format_sortie = $valeurs['format_dest']; |
|
| 1359 | + |
|
| 1360 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1361 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1365 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1366 | + return; |
|
| 1367 | + } |
|
| 1368 | + $destination = "$destdir/$destfile"; |
|
| 1369 | + |
|
| 1370 | + // calculer la taille |
|
| 1371 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1372 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1373 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1374 | + } |
|
| 1375 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1376 | + $destWidth = $maxWidth; |
|
| 1377 | + $destHeight = $maxHeight; |
|
| 1378 | + } else { |
|
| 1379 | + spip_log("echec $process sur $image"); |
|
| 1380 | + |
|
| 1381 | + return; |
|
| 1382 | + } |
|
| 1383 | + |
|
| 1384 | + $vignette = ''; |
|
| 1385 | + |
|
| 1386 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1387 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1388 | + $vignette = $destination . '.' . $format; |
|
| 1389 | + @copy($image, $vignette); |
|
| 1390 | + } |
|
| 1391 | + |
|
| 1392 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1393 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1394 | + $format_sortie = 'svg'; |
|
| 1395 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1396 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1397 | + _image_gd_output($svg, $valeurs); |
|
| 1398 | + } |
|
| 1399 | + } |
|
| 1400 | + |
|
| 1401 | + // imagemagick en ligne de commande |
|
| 1402 | + elseif ($process == 'convert') { |
|
| 1403 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1404 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1405 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1406 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1407 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1408 | + } |
|
| 1409 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1410 | + $commande = str_replace( |
|
| 1411 | + ['%x', '%y', '%src', '%dest'], |
|
| 1412 | + [ |
|
| 1413 | + $destWidth, |
|
| 1414 | + $destHeight, |
|
| 1415 | + escapeshellcmd($image), |
|
| 1416 | + escapeshellcmd($vignette) |
|
| 1417 | + ], |
|
| 1418 | + _RESIZE_COMMAND |
|
| 1419 | + ); |
|
| 1420 | + spip_log($commande); |
|
| 1421 | + exec($commande); |
|
| 1422 | + if (!@file_exists($vignette)) { |
|
| 1423 | + spip_log("echec convert sur $vignette"); |
|
| 1424 | + |
|
| 1425 | + return; // echec commande |
|
| 1426 | + } |
|
| 1427 | + } |
|
| 1428 | + |
|
| 1429 | + // php5 imagemagick |
|
| 1430 | + elseif ($process == 'imagick') { |
|
| 1431 | + if (!class_exists(\Imagick::class)) { |
|
| 1432 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1433 | + |
|
| 1434 | + return; |
|
| 1435 | + } |
|
| 1436 | + |
|
| 1437 | + // chemin compatible Windows |
|
| 1438 | + $output = realpath(dirname($destination)); |
|
| 1439 | + if (!$output) { |
|
| 1440 | + return; |
|
| 1441 | + } |
|
| 1442 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1443 | + |
|
| 1444 | + $imagick = new Imagick(); |
|
| 1445 | + $imagick->readImage(realpath($image)); |
|
| 1446 | + $imagick->resizeImage( |
|
| 1447 | + $destWidth, |
|
| 1448 | + $destHeight, |
|
| 1449 | + Imagick::FILTER_LANCZOS, |
|
| 1450 | + 1 |
|
| 1451 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1452 | + $imagick->writeImage($vignette); |
|
| 1453 | + |
|
| 1454 | + if (!@file_exists($vignette)) { |
|
| 1455 | + spip_log("echec imagick sur $vignette"); |
|
| 1456 | + |
|
| 1457 | + return; |
|
| 1458 | + } |
|
| 1459 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1460 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1461 | + } |
|
| 1462 | + |
|
| 1463 | + // netpbm |
|
| 1464 | + elseif ($process == 'netpbm') { |
|
| 1465 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1466 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1467 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1468 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1469 | + return; |
|
| 1470 | + } |
|
| 1471 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1472 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1473 | + if ($format == 'jpg') { |
|
| 1474 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1475 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1476 | + if (!($s = @filesize($vignette))) { |
|
| 1477 | + spip_unlink($vignette); |
|
| 1478 | + } |
|
| 1479 | + if (!@file_exists($vignette)) { |
|
| 1480 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1481 | + |
|
| 1482 | + return; |
|
| 1483 | + } |
|
| 1484 | + } else { |
|
| 1485 | + if ($format == 'gif') { |
|
| 1486 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1487 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1488 | + if (!($s = @filesize($vignette))) { |
|
| 1489 | + spip_unlink($vignette); |
|
| 1490 | + } |
|
| 1491 | + if (!@file_exists($vignette)) { |
|
| 1492 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1493 | + |
|
| 1494 | + return; |
|
| 1495 | + } |
|
| 1496 | + } else { |
|
| 1497 | + if ($format == 'png') { |
|
| 1498 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1499 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1500 | + if (!($s = @filesize($vignette))) { |
|
| 1501 | + spip_unlink($vignette); |
|
| 1502 | + } |
|
| 1503 | + if (!@file_exists($vignette)) { |
|
| 1504 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1505 | + |
|
| 1506 | + return; |
|
| 1507 | + } |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + } |
|
| 1512 | + |
|
| 1513 | + // gd ou gd2 |
|
| 1514 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1515 | + if (!function_exists('gd_info')) { |
|
| 1516 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1517 | + |
|
| 1518 | + return; |
|
| 1519 | + } |
|
| 1520 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1521 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1522 | + |
|
| 1523 | + return; |
|
| 1524 | + } |
|
| 1525 | + $destFormat = $format_sortie; |
|
| 1526 | + if (!$destFormat) { |
|
| 1527 | + spip_log("pas de format pour $image"); |
|
| 1528 | + |
|
| 1529 | + return; |
|
| 1530 | + } |
|
| 1531 | + |
|
| 1532 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1533 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1534 | + return; |
|
| 1535 | + } |
|
| 1536 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1537 | + if (!$srcImage) { |
|
| 1538 | + spip_log('echec gd1/gd2'); |
|
| 1539 | + |
|
| 1540 | + return; |
|
| 1541 | + } |
|
| 1542 | + |
|
| 1543 | + // Initialisation de l'image destination |
|
| 1544 | + $destImage = null; |
|
| 1545 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1546 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1547 | + } |
|
| 1548 | + if (!$destImage) { |
|
| 1549 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1550 | + } |
|
| 1551 | + |
|
| 1552 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1553 | + $ok = false; |
|
| 1554 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1555 | + if ($format == 'gif') { |
|
| 1556 | + // Si un GIF est transparent, |
|
| 1557 | + // fabriquer un PNG transparent |
|
| 1558 | + $transp = imagecolortransparent($srcImage); |
|
| 1559 | + if ($transp > 0) { |
|
| 1560 | + $destFormat = 'png'; |
|
| 1561 | + } |
|
| 1562 | + } |
|
| 1563 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1564 | + // Conserver la transparence |
|
| 1565 | + if (function_exists('imageAntiAlias')) { |
|
| 1566 | + imageAntiAlias($destImage, true); |
|
| 1567 | + } |
|
| 1568 | + @imagealphablending($destImage, false); |
|
| 1569 | + @imagesavealpha($destImage, true); |
|
| 1570 | + } |
|
| 1571 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1572 | + } |
|
| 1573 | + if (!$ok) { |
|
| 1574 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1575 | + } |
|
| 1576 | + |
|
| 1577 | + // Sauvegarde de l'image destination |
|
| 1578 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1579 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1580 | + _image_gd_output($destImage, $valeurs); |
|
| 1581 | + |
|
| 1582 | + if ($srcImage) { |
|
| 1583 | + ImageDestroy($srcImage); |
|
| 1584 | + } |
|
| 1585 | + ImageDestroy($destImage); |
|
| 1586 | + } |
|
| 1587 | + |
|
| 1588 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1589 | + $size = [$destWidth, $destHeight]; |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1593 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1594 | + if ($size[0] < 1) { |
|
| 1595 | + $size[0] = $destWidth; |
|
| 1596 | + } |
|
| 1597 | + if ($size[1] < 1) { |
|
| 1598 | + $size[1] = $destHeight; |
|
| 1599 | + } |
|
| 1600 | + |
|
| 1601 | + $retour['width'] = $largeur = $size[0]; |
|
| 1602 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1603 | + |
|
| 1604 | + $retour['fichier'] = $vignette; |
|
| 1605 | + $retour['format'] = $format; |
|
| 1606 | + $retour['date'] = @filemtime($vignette); |
|
| 1607 | + |
|
| 1608 | + // renvoyer l'image |
|
| 1609 | + return $retour; |
|
| 1610 | 1610 | } |
| 1611 | 1611 | |
| 1612 | 1612 | /** |
@@ -1626,25 +1626,25 @@ discard block |
||
| 1626 | 1626 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1627 | 1627 | **/ |
| 1628 | 1628 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1629 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1630 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1631 | - |
|
| 1632 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1633 | - $destWidth = $srcWidth; |
|
| 1634 | - $destHeight = $srcHeight; |
|
| 1635 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1636 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1637 | - $destHeight = $maxHeight; |
|
| 1638 | - } else { |
|
| 1639 | - $destWidth = $maxWidth; |
|
| 1640 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1641 | - } |
|
| 1642 | - |
|
| 1643 | - return [ |
|
| 1644 | - intval(round($destWidth)), |
|
| 1645 | - intval(round($destHeight)), |
|
| 1646 | - max($ratioWidth, $ratioHeight) |
|
| 1647 | - ]; |
|
| 1629 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1630 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1631 | + |
|
| 1632 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1633 | + $destWidth = $srcWidth; |
|
| 1634 | + $destHeight = $srcHeight; |
|
| 1635 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1636 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1637 | + $destHeight = $maxHeight; |
|
| 1638 | + } else { |
|
| 1639 | + $destWidth = $maxWidth; |
|
| 1640 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1641 | + } |
|
| 1642 | + |
|
| 1643 | + return [ |
|
| 1644 | + intval(round($destWidth)), |
|
| 1645 | + intval(round($destHeight)), |
|
| 1646 | + max($ratioWidth, $ratioHeight) |
|
| 1647 | + ]; |
|
| 1648 | 1648 | } |
| 1649 | 1649 | |
| 1650 | 1650 | /** |
@@ -1664,25 +1664,25 @@ discard block |
||
| 1664 | 1664 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1665 | 1665 | **/ |
| 1666 | 1666 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1667 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1668 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1669 | - |
|
| 1670 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1671 | - $destWidth = $srcWidth; |
|
| 1672 | - $destHeight = $srcHeight; |
|
| 1673 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1674 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1675 | - $destHeight = $maxHeight; |
|
| 1676 | - } else { |
|
| 1677 | - $destWidth = $maxWidth; |
|
| 1678 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1679 | - } |
|
| 1680 | - |
|
| 1681 | - return [ |
|
| 1682 | - intval(round($destWidth)), |
|
| 1683 | - intval(round($destHeight)), |
|
| 1684 | - min($ratioWidth, $ratioHeight) |
|
| 1685 | - ]; |
|
| 1667 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1668 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1669 | + |
|
| 1670 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1671 | + $destWidth = $srcWidth; |
|
| 1672 | + $destHeight = $srcHeight; |
|
| 1673 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1674 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1675 | + $destHeight = $maxHeight; |
|
| 1676 | + } else { |
|
| 1677 | + $destWidth = $maxWidth; |
|
| 1678 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1679 | + } |
|
| 1680 | + |
|
| 1681 | + return [ |
|
| 1682 | + intval(round($destWidth)), |
|
| 1683 | + intval(round($destHeight)), |
|
| 1684 | + min($ratioWidth, $ratioHeight) |
|
| 1685 | + ]; |
|
| 1686 | 1686 | } |
| 1687 | 1687 | |
| 1688 | 1688 | |
@@ -1695,12 +1695,12 @@ discard block |
||
| 1695 | 1695 | * @return string |
| 1696 | 1696 | */ |
| 1697 | 1697 | function process_image_svg_identite($image) { |
| 1698 | - if ($image['creer']) { |
|
| 1699 | - $source = $image['fichier']; |
|
| 1700 | - _image_gd_output($source, $image); |
|
| 1701 | - } |
|
| 1698 | + if ($image['creer']) { |
|
| 1699 | + $source = $image['fichier']; |
|
| 1700 | + _image_gd_output($source, $image); |
|
| 1701 | + } |
|
| 1702 | 1702 | |
| 1703 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1703 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1704 | 1704 | } |
| 1705 | 1705 | |
| 1706 | 1706 | |
@@ -1733,109 +1733,109 @@ discard block |
||
| 1733 | 1733 | * Code HTML de la balise img produite |
| 1734 | 1734 | **/ |
| 1735 | 1735 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1736 | - $image = false; |
|
| 1737 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1738 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1739 | - } |
|
| 1740 | - # determiner le format de sortie |
|
| 1741 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1742 | - if ($process == 'netpbm') { |
|
| 1743 | - $format_sortie = 'jpg'; |
|
| 1744 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1745 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1746 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1747 | - $gd_formats = formats_image_acceptables(true); |
|
| 1748 | - if ( |
|
| 1749 | - is_array($image) |
|
| 1750 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1751 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1752 | - ) |
|
| 1753 | - ) { |
|
| 1754 | - if ($image['format_source'] == 'jpg') { |
|
| 1755 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1756 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1757 | - { |
|
| 1758 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1759 | - } |
|
| 1760 | - // Choisir le format destination |
|
| 1761 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1762 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1763 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1764 | - # pas *ecrire* |
|
| 1765 | - $format_sortie = ''; |
|
| 1766 | - foreach ($formats_sortie as $fmt) { |
|
| 1767 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1768 | - $format_sortie = $fmt; |
|
| 1769 | - break; |
|
| 1770 | - } |
|
| 1771 | - } |
|
| 1772 | - $image = false; |
|
| 1773 | - } |
|
| 1774 | - } |
|
| 1775 | - |
|
| 1776 | - if (!is_array($image)) { |
|
| 1777 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1778 | - } |
|
| 1779 | - |
|
| 1780 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1781 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1782 | - // on peut resizer en mode html si on dispose des elements |
|
| 1783 | - [$srcw, $srch] = taille_image($img); |
|
| 1784 | - if ($srcw and $srch) { |
|
| 1785 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1786 | - |
|
| 1787 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1788 | - } |
|
| 1789 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1790 | - // sous la forme style='max-width: NNpx;' |
|
| 1791 | - return inserer_attribut( |
|
| 1792 | - $img, |
|
| 1793 | - 'style', |
|
| 1794 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1795 | - ); |
|
| 1796 | - } |
|
| 1797 | - |
|
| 1798 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1799 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1800 | - if ($image['creer']) { |
|
| 1801 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1802 | - } |
|
| 1803 | - |
|
| 1804 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1805 | - } |
|
| 1806 | - |
|
| 1807 | - if ($image['creer'] == false && !$force) { |
|
| 1808 | - return _image_ecrire_tag( |
|
| 1809 | - $image, |
|
| 1810 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1811 | - ); |
|
| 1812 | - } |
|
| 1813 | - |
|
| 1814 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1815 | - $destWidth = $image['largeur_dest']; |
|
| 1816 | - $destHeight = $image['hauteur_dest']; |
|
| 1817 | - $logo = $image['fichier']; |
|
| 1818 | - $date = $image['date_src']; |
|
| 1819 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1820 | - |
|
| 1821 | - if ($preview && $preview['fichier']) { |
|
| 1822 | - $logo = $preview['fichier']; |
|
| 1823 | - $destWidth = $preview['width']; |
|
| 1824 | - $destHeight = $preview['height']; |
|
| 1825 | - $date = $preview['date']; |
|
| 1826 | - } |
|
| 1827 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1828 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1829 | - // quand on fait supprimer/reuploader un logo |
|
| 1830 | - // (pas de filemtime si SAFE MODE) |
|
| 1831 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1832 | - |
|
| 1833 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1834 | - } |
|
| 1835 | - else { |
|
| 1836 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1837 | - return $img; |
|
| 1838 | - } |
|
| 1736 | + $image = false; |
|
| 1737 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1738 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1739 | + } |
|
| 1740 | + # determiner le format de sortie |
|
| 1741 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1742 | + if ($process == 'netpbm') { |
|
| 1743 | + $format_sortie = 'jpg'; |
|
| 1744 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1745 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1746 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1747 | + $gd_formats = formats_image_acceptables(true); |
|
| 1748 | + if ( |
|
| 1749 | + is_array($image) |
|
| 1750 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1751 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1752 | + ) |
|
| 1753 | + ) { |
|
| 1754 | + if ($image['format_source'] == 'jpg') { |
|
| 1755 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1756 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1757 | + { |
|
| 1758 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1759 | + } |
|
| 1760 | + // Choisir le format destination |
|
| 1761 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1762 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1763 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1764 | + # pas *ecrire* |
|
| 1765 | + $format_sortie = ''; |
|
| 1766 | + foreach ($formats_sortie as $fmt) { |
|
| 1767 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1768 | + $format_sortie = $fmt; |
|
| 1769 | + break; |
|
| 1770 | + } |
|
| 1771 | + } |
|
| 1772 | + $image = false; |
|
| 1773 | + } |
|
| 1774 | + } |
|
| 1775 | + |
|
| 1776 | + if (!is_array($image)) { |
|
| 1777 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1778 | + } |
|
| 1779 | + |
|
| 1780 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1781 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1782 | + // on peut resizer en mode html si on dispose des elements |
|
| 1783 | + [$srcw, $srch] = taille_image($img); |
|
| 1784 | + if ($srcw and $srch) { |
|
| 1785 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1786 | + |
|
| 1787 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1788 | + } |
|
| 1789 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1790 | + // sous la forme style='max-width: NNpx;' |
|
| 1791 | + return inserer_attribut( |
|
| 1792 | + $img, |
|
| 1793 | + 'style', |
|
| 1794 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1795 | + ); |
|
| 1796 | + } |
|
| 1797 | + |
|
| 1798 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1799 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1800 | + if ($image['creer']) { |
|
| 1801 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1802 | + } |
|
| 1803 | + |
|
| 1804 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1805 | + } |
|
| 1806 | + |
|
| 1807 | + if ($image['creer'] == false && !$force) { |
|
| 1808 | + return _image_ecrire_tag( |
|
| 1809 | + $image, |
|
| 1810 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1811 | + ); |
|
| 1812 | + } |
|
| 1813 | + |
|
| 1814 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1815 | + $destWidth = $image['largeur_dest']; |
|
| 1816 | + $destHeight = $image['hauteur_dest']; |
|
| 1817 | + $logo = $image['fichier']; |
|
| 1818 | + $date = $image['date_src']; |
|
| 1819 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1820 | + |
|
| 1821 | + if ($preview && $preview['fichier']) { |
|
| 1822 | + $logo = $preview['fichier']; |
|
| 1823 | + $destWidth = $preview['width']; |
|
| 1824 | + $destHeight = $preview['height']; |
|
| 1825 | + $date = $preview['date']; |
|
| 1826 | + } |
|
| 1827 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1828 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1829 | + // quand on fait supprimer/reuploader un logo |
|
| 1830 | + // (pas de filemtime si SAFE MODE) |
|
| 1831 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1832 | + |
|
| 1833 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1834 | + } |
|
| 1835 | + else { |
|
| 1836 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1837 | + return $img; |
|
| 1838 | + } |
|
| 1839 | 1839 | } |
| 1840 | 1840 | |
| 1841 | 1841 | /** |
@@ -1849,145 +1849,145 @@ discard block |
||
| 1849 | 1849 | * Class phpthumb_functions |
| 1850 | 1850 | */ |
| 1851 | 1851 | class phpthumb_functions { |
| 1852 | - /** |
|
| 1853 | - * Retourne la couleur d'un pixel dans une image |
|
| 1854 | - * |
|
| 1855 | - * @param resource|GdImage $img |
|
| 1856 | - * @param int $x |
|
| 1857 | - * @param int $y |
|
| 1858 | - * @return array|bool |
|
| 1859 | - */ |
|
| 1860 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1861 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1862 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1863 | - } |
|
| 1864 | - return false; |
|
| 1865 | - } |
|
| 1866 | - |
|
| 1867 | - /** |
|
| 1868 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1869 | - * |
|
| 1870 | - * @param int $number |
|
| 1871 | - * @param int $minbytes |
|
| 1872 | - * @return string |
|
| 1873 | - */ |
|
| 1874 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1875 | - $intstring = ''; |
|
| 1876 | - while ($number > 0) { |
|
| 1877 | - $intstring = $intstring . chr($number & 255); |
|
| 1878 | - $number >>= 8; |
|
| 1879 | - } |
|
| 1880 | - |
|
| 1881 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1882 | - } |
|
| 1883 | - |
|
| 1884 | - /** |
|
| 1885 | - * Transforme une ressource GD en image au format ICO |
|
| 1886 | - * |
|
| 1887 | - * @param array $gd_image_array |
|
| 1888 | - * Tableau de ressources d'images GD |
|
| 1889 | - * @return string |
|
| 1890 | - * Image au format ICO |
|
| 1891 | - */ |
|
| 1892 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1893 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1894 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1895 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1896 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1897 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1898 | - |
|
| 1899 | - $icXOR[$key] = ''; |
|
| 1900 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1901 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1902 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1903 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1904 | - $r = $argb['red']; |
|
| 1905 | - $g = $argb['green']; |
|
| 1906 | - $b = $argb['blue']; |
|
| 1907 | - |
|
| 1908 | - if ($bpp[$key] == 32) { |
|
| 1909 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1910 | - } elseif ($bpp[$key] == 24) { |
|
| 1911 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1912 | - } |
|
| 1913 | - |
|
| 1914 | - if ($a < 128) { |
|
| 1915 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1916 | - } else { |
|
| 1917 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1918 | - } |
|
| 1919 | - } |
|
| 1920 | - // mask bits are 32-bit aligned per scanline |
|
| 1921 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1922 | - $icANDmask[$key][$y] .= '0'; |
|
| 1923 | - } |
|
| 1924 | - } |
|
| 1925 | - $icAND[$key] = ''; |
|
| 1926 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1927 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1928 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1929 | - } |
|
| 1930 | - } |
|
| 1931 | - } |
|
| 1932 | - |
|
| 1933 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1934 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1935 | - |
|
| 1936 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1937 | - $BitmapInfoHeader[$key] = ''; |
|
| 1938 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1940 | - // The biHeight member specifies the combined |
|
| 1941 | - // height of the XOR and AND masks. |
|
| 1942 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1943 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1944 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1945 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1946 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1947 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1948 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1949 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1950 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - |
|
| 1954 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1955 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1956 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1957 | - |
|
| 1958 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1959 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1960 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1961 | - |
|
| 1962 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1963 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1964 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1965 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1966 | - |
|
| 1967 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1969 | - |
|
| 1970 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1971 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1972 | - $dwBytesInRes, |
|
| 1973 | - 4 |
|
| 1974 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1975 | - |
|
| 1976 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | - $dwImageOffset, |
|
| 1978 | - 4 |
|
| 1979 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1980 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1981 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1982 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1983 | - } |
|
| 1984 | - |
|
| 1985 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1986 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1987 | - $icondata .= $icXOR[$key]; |
|
| 1988 | - $icondata .= $icAND[$key]; |
|
| 1989 | - } |
|
| 1990 | - |
|
| 1991 | - return $icondata; |
|
| 1992 | - } |
|
| 1852 | + /** |
|
| 1853 | + * Retourne la couleur d'un pixel dans une image |
|
| 1854 | + * |
|
| 1855 | + * @param resource|GdImage $img |
|
| 1856 | + * @param int $x |
|
| 1857 | + * @param int $y |
|
| 1858 | + * @return array|bool |
|
| 1859 | + */ |
|
| 1860 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1861 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1862 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1863 | + } |
|
| 1864 | + return false; |
|
| 1865 | + } |
|
| 1866 | + |
|
| 1867 | + /** |
|
| 1868 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1869 | + * |
|
| 1870 | + * @param int $number |
|
| 1871 | + * @param int $minbytes |
|
| 1872 | + * @return string |
|
| 1873 | + */ |
|
| 1874 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1875 | + $intstring = ''; |
|
| 1876 | + while ($number > 0) { |
|
| 1877 | + $intstring = $intstring . chr($number & 255); |
|
| 1878 | + $number >>= 8; |
|
| 1879 | + } |
|
| 1880 | + |
|
| 1881 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1882 | + } |
|
| 1883 | + |
|
| 1884 | + /** |
|
| 1885 | + * Transforme une ressource GD en image au format ICO |
|
| 1886 | + * |
|
| 1887 | + * @param array $gd_image_array |
|
| 1888 | + * Tableau de ressources d'images GD |
|
| 1889 | + * @return string |
|
| 1890 | + * Image au format ICO |
|
| 1891 | + */ |
|
| 1892 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1893 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1894 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1895 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1896 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1897 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1898 | + |
|
| 1899 | + $icXOR[$key] = ''; |
|
| 1900 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1901 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1902 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1903 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1904 | + $r = $argb['red']; |
|
| 1905 | + $g = $argb['green']; |
|
| 1906 | + $b = $argb['blue']; |
|
| 1907 | + |
|
| 1908 | + if ($bpp[$key] == 32) { |
|
| 1909 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1910 | + } elseif ($bpp[$key] == 24) { |
|
| 1911 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1912 | + } |
|
| 1913 | + |
|
| 1914 | + if ($a < 128) { |
|
| 1915 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1916 | + } else { |
|
| 1917 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1918 | + } |
|
| 1919 | + } |
|
| 1920 | + // mask bits are 32-bit aligned per scanline |
|
| 1921 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1922 | + $icANDmask[$key][$y] .= '0'; |
|
| 1923 | + } |
|
| 1924 | + } |
|
| 1925 | + $icAND[$key] = ''; |
|
| 1926 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1927 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1928 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1929 | + } |
|
| 1930 | + } |
|
| 1931 | + } |
|
| 1932 | + |
|
| 1933 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1934 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1935 | + |
|
| 1936 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1937 | + $BitmapInfoHeader[$key] = ''; |
|
| 1938 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1940 | + // The biHeight member specifies the combined |
|
| 1941 | + // height of the XOR and AND masks. |
|
| 1942 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1943 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1944 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1945 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1946 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1947 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1948 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1949 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1950 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + |
|
| 1954 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1955 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1956 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1957 | + |
|
| 1958 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1959 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1960 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1961 | + |
|
| 1962 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1963 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1964 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1965 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1966 | + |
|
| 1967 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1969 | + |
|
| 1970 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1971 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1972 | + $dwBytesInRes, |
|
| 1973 | + 4 |
|
| 1974 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1975 | + |
|
| 1976 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | + $dwImageOffset, |
|
| 1978 | + 4 |
|
| 1979 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1980 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1981 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1982 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1983 | + } |
|
| 1984 | + |
|
| 1985 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1986 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1987 | + $icondata .= $icXOR[$key]; |
|
| 1988 | + $icondata .= $icAND[$key]; |
|
| 1989 | + } |
|
| 1990 | + |
|
| 1991 | + return $icondata; |
|
| 1992 | + } |
|
| 1993 | 1993 | } |
@@ -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,20 +38,20 @@ discard block |
||
| 38 | 38 | * Liste des fichiers de langue trouvés, dans l'ordre des chemins |
| 39 | 39 | */ |
| 40 | 40 | function find_langs_in_path($file, $dirname = 'lang') { |
| 41 | - static $dirs = []; |
|
| 42 | - $liste = []; |
|
| 43 | - foreach (creer_chemin() as $dir) { |
|
| 44 | - if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | - $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | - } |
|
| 47 | - if ($dirs[$a]) { |
|
| 48 | - if (is_readable($a .= $file)) { |
|
| 49 | - $liste[] = $a; |
|
| 50 | - } |
|
| 51 | - } |
|
| 52 | - } |
|
| 41 | + static $dirs = []; |
|
| 42 | + $liste = []; |
|
| 43 | + foreach (creer_chemin() as $dir) { |
|
| 44 | + if (!isset($dirs[$a = $dir . $dirname])) { |
|
| 45 | + $dirs[$a] = (is_dir($a) || !$a); |
|
| 46 | + } |
|
| 47 | + if ($dirs[$a]) { |
|
| 48 | + if (is_readable($a .= $file)) { |
|
| 49 | + $liste[] = $a; |
|
| 50 | + } |
|
| 51 | + } |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - return array_reverse($liste); |
|
| 54 | + return array_reverse($liste); |
|
| 55 | 55 | } |
| 56 | 56 | |
| 57 | 57 | /** |
@@ -66,23 +66,23 @@ discard block |
||
| 66 | 66 | * Liste des fichiers touvés pour ce module et cette langue. |
| 67 | 67 | **/ |
| 68 | 68 | function chercher_module_lang($module, $lang = '') { |
| 69 | - if ($lang) { |
|
| 70 | - $lang = '_' . $lang; |
|
| 71 | - } |
|
| 69 | + if ($lang) { |
|
| 70 | + $lang = '_' . $lang; |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | - // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | - if ( |
|
| 75 | - $f = ($module == 'local' |
|
| 76 | - ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | - : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | - ) { |
|
| 79 | - return is_array($f) ? $f : [$f]; |
|
| 80 | - } |
|
| 73 | + // 1) dans un repertoire nomme lang/ se trouvant sur le chemin |
|
| 74 | + if ( |
|
| 75 | + $f = ($module == 'local' |
|
| 76 | + ? find_in_path($module . $lang . '.php', 'lang/') |
|
| 77 | + : find_langs_in_path($module . $lang . '.php', 'lang/')) |
|
| 78 | + ) { |
|
| 79 | + return is_array($f) ? $f : [$f]; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | - // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | - return (($module == 'local') or strpos($module, '/')) |
|
| 84 | - ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | - : false; |
|
| 82 | + // 2) directement dans le chemin (old style, uniquement pour local) |
|
| 83 | + return (($module == 'local') or strpos($module, '/')) |
|
| 84 | + ? (($f = find_in_path($module . $lang . '.php')) ? [$f] : false) |
|
| 85 | + : false; |
|
| 86 | 86 | } |
| 87 | 87 | |
| 88 | 88 | /** |
@@ -104,33 +104,33 @@ discard block |
||
| 104 | 104 | * @return void |
| 105 | 105 | **/ |
| 106 | 106 | function charger_langue($lang, $module = 'spip') { |
| 107 | - static $langs = []; |
|
| 108 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | - if (!isset($langs[$lang])) { |
|
| 110 | - $langs[$lang] = []; |
|
| 111 | - if ($lang) { |
|
| 112 | - $langs[$lang][] = $lang; |
|
| 113 | - if (strpos($lang, '_') !== false) { |
|
| 114 | - $l = explode('_', $lang); |
|
| 115 | - $langs[$lang][] = reset($l); |
|
| 116 | - } |
|
| 117 | - } |
|
| 118 | - $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | - $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | - } |
|
| 121 | - foreach ($langs[$lang] as $l) { |
|
| 122 | - if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | - $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | - $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | - surcharger_langue($fichiers_lang); |
|
| 126 | - if ($l !== $lang) { |
|
| 127 | - $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | - } |
|
| 129 | - $GLOBALS['lang_' . $var] = $l; |
|
| 130 | - #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | - break; |
|
| 132 | - } |
|
| 133 | - } |
|
| 107 | + static $langs = []; |
|
| 108 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 109 | + if (!isset($langs[$lang])) { |
|
| 110 | + $langs[$lang] = []; |
|
| 111 | + if ($lang) { |
|
| 112 | + $langs[$lang][] = $lang; |
|
| 113 | + if (strpos($lang, '_') !== false) { |
|
| 114 | + $l = explode('_', $lang); |
|
| 115 | + $langs[$lang][] = reset($l); |
|
| 116 | + } |
|
| 117 | + } |
|
| 118 | + $langs[$lang][] = $GLOBALS['meta']['langue_site']; |
|
| 119 | + $langs[$lang][] = _LANGUE_PAR_DEFAUT; |
|
| 120 | + } |
|
| 121 | + foreach ($langs[$lang] as $l) { |
|
| 122 | + if ($fichiers_lang = chercher_module_lang($module, $l)) { |
|
| 123 | + $GLOBALS['idx_lang'] = 'i18n_' . $module . '_' . $l; |
|
| 124 | + $GLOBALS[$GLOBALS['idx_lang']] = lire_fichier_langue(array_shift($fichiers_lang)); |
|
| 125 | + surcharger_langue($fichiers_lang); |
|
| 126 | + if ($l !== $lang) { |
|
| 127 | + $GLOBALS[$var] = &$GLOBALS['i18n_' . $module . '_' . $l]; |
|
| 128 | + } |
|
| 129 | + $GLOBALS['lang_' . $var] = $l; |
|
| 130 | + #spip_log("module de langue : {$module}_$l.php", 'traduire'); |
|
| 131 | + break; |
|
| 132 | + } |
|
| 133 | + } |
|
| 134 | 134 | } |
| 135 | 135 | |
| 136 | 136 | /** |
@@ -143,21 +143,21 @@ discard block |
||
| 143 | 143 | * @return array<string, string> |
| 144 | 144 | */ |
| 145 | 145 | function lire_fichier_langue(string $fichier): array { |
| 146 | - $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | - $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | - $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | - $idx_lang = include $fichier; |
|
| 150 | - $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | - if (!is_array($idx_lang)) { |
|
| 152 | - if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | - $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | - } else { |
|
| 155 | - $idx_lang = []; |
|
| 156 | - spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | - } |
|
| 158 | - unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | - } |
|
| 160 | - return $idx_lang; |
|
| 146 | + $idx_lang_before = $GLOBALS['idx_lang'] ?? null; |
|
| 147 | + $idx_lang_tmp = ($GLOBALS['idx_lang'] ?? 'lang') . '@temporaire'; |
|
| 148 | + $GLOBALS['idx_lang'] = $idx_lang_tmp; |
|
| 149 | + $idx_lang = include $fichier; |
|
| 150 | + $GLOBALS['idx_lang'] = $idx_lang_before; |
|
| 151 | + if (!is_array($idx_lang)) { |
|
| 152 | + if (isset($GLOBALS[$idx_lang_tmp]) and is_array($GLOBALS[$idx_lang_tmp])) { |
|
| 153 | + $idx_lang = $GLOBALS[$idx_lang_tmp]; |
|
| 154 | + } else { |
|
| 155 | + $idx_lang = []; |
|
| 156 | + spip_log(sprintf('Fichier de langue incorrect : %s', $fichier), _LOG_ERREUR); |
|
| 157 | + } |
|
| 158 | + unset($GLOBALS[$idx_lang_tmp]); |
|
| 159 | + } |
|
| 160 | + return $idx_lang; |
|
| 161 | 161 | } |
| 162 | 162 | |
| 163 | 163 | /** |
@@ -177,46 +177,46 @@ discard block |
||
| 177 | 177 | * Liste des chemins de fichiers de langue à surcharger. |
| 178 | 178 | **/ |
| 179 | 179 | function surcharger_langue($fichiers) { |
| 180 | - static $surcharges = []; |
|
| 181 | - if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | - return; |
|
| 183 | - } |
|
| 180 | + static $surcharges = []; |
|
| 181 | + if (!isset($GLOBALS['idx_lang'])) { |
|
| 182 | + return; |
|
| 183 | + } |
|
| 184 | 184 | |
| 185 | - if (!is_array($fichiers)) { |
|
| 186 | - $fichiers = [$fichiers]; |
|
| 187 | - } |
|
| 188 | - if (!count($fichiers)) { |
|
| 189 | - return; |
|
| 190 | - } |
|
| 191 | - foreach ($fichiers as $fichier) { |
|
| 192 | - if (!isset($surcharges[$fichier])) { |
|
| 193 | - $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | - } |
|
| 195 | - if (is_array($surcharges[$fichier])) { |
|
| 196 | - $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | - $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | - $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | - $surcharges[$fichier] |
|
| 200 | - ); |
|
| 201 | - } |
|
| 202 | - } |
|
| 185 | + if (!is_array($fichiers)) { |
|
| 186 | + $fichiers = [$fichiers]; |
|
| 187 | + } |
|
| 188 | + if (!count($fichiers)) { |
|
| 189 | + return; |
|
| 190 | + } |
|
| 191 | + foreach ($fichiers as $fichier) { |
|
| 192 | + if (!isset($surcharges[$fichier])) { |
|
| 193 | + $surcharges[$fichier] = lire_fichier_langue($fichier); |
|
| 194 | + } |
|
| 195 | + if (is_array($surcharges[$fichier])) { |
|
| 196 | + $GLOBALS[$GLOBALS['idx_lang']] ??= []; |
|
| 197 | + $GLOBALS[$GLOBALS['idx_lang']] = array_merge( |
|
| 198 | + $GLOBALS[$GLOBALS['idx_lang']], |
|
| 199 | + $surcharges[$fichier] |
|
| 200 | + ); |
|
| 201 | + } |
|
| 202 | + } |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | |
| 206 | 206 | |
| 207 | 207 | class SPIP_Traductions_Description { |
| 208 | - /** @var string code de langue (hors module) */ |
|
| 209 | - public $code; |
|
| 210 | - /** @var string nom du module de langue */ |
|
| 211 | - public $module; |
|
| 212 | - /** @var string langue de la traduction */ |
|
| 213 | - public $langue; |
|
| 214 | - /** @var string traduction */ |
|
| 215 | - public $texte; |
|
| 216 | - /** @var string var mode particulier appliqué ? */ |
|
| 217 | - public $mode; |
|
| 218 | - /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | - public $corrections = false; |
|
| 208 | + /** @var string code de langue (hors module) */ |
|
| 209 | + public $code; |
|
| 210 | + /** @var string nom du module de langue */ |
|
| 211 | + public $module; |
|
| 212 | + /** @var string langue de la traduction */ |
|
| 213 | + public $langue; |
|
| 214 | + /** @var string traduction */ |
|
| 215 | + public $texte; |
|
| 216 | + /** @var string var mode particulier appliqué ? */ |
|
| 217 | + public $mode; |
|
| 218 | + /** @var bool Corrections des textes appliqué ? */ |
|
| 219 | + public $corrections = false; |
|
| 220 | 220 | } |
| 221 | 221 | |
| 222 | 222 | |
@@ -258,99 +258,99 @@ discard block |
||
| 258 | 258 | * - SPIP_Traductions_Description : traduction et description (texte, module, langue) |
| 259 | 259 | **/ |
| 260 | 260 | function inc_traduire_dist($ori, $lang, $raw = false) { |
| 261 | - static $deja_vu = []; |
|
| 262 | - static $local = []; |
|
| 261 | + static $deja_vu = []; |
|
| 262 | + static $local = []; |
|
| 263 | 263 | |
| 264 | - if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | - return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | - } |
|
| 264 | + if (isset($deja_vu[$lang][$ori]) and (_request('var_mode') != 'traduction')) { |
|
| 265 | + return $raw ? $deja_vu[$lang][$ori] : $deja_vu[$lang][$ori]->texte; |
|
| 266 | + } |
|
| 267 | 267 | |
| 268 | - // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | - if (strpos($ori, ':')) { |
|
| 270 | - [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | - $modules = explode('|', $modules); |
|
| 272 | - $ori_complet = $ori; |
|
| 273 | - } else { |
|
| 274 | - $modules = ['spip', 'ecrire']; |
|
| 275 | - $code = $ori; |
|
| 276 | - $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | - } |
|
| 268 | + // modules demandes explicitement <xxx|yyy|zzz:code> cf MODULES_IDIOMES |
|
| 269 | + if (strpos($ori, ':')) { |
|
| 270 | + [$modules, $code] = explode(':', $ori, 2); |
|
| 271 | + $modules = explode('|', $modules); |
|
| 272 | + $ori_complet = $ori; |
|
| 273 | + } else { |
|
| 274 | + $modules = ['spip', 'ecrire']; |
|
| 275 | + $code = $ori; |
|
| 276 | + $ori_complet = implode('|', $modules) . ':' . $ori; |
|
| 277 | + } |
|
| 278 | 278 | |
| 279 | - $desc = new SPIP_Traductions_Description(); |
|
| 279 | + $desc = new SPIP_Traductions_Description(); |
|
| 280 | 280 | |
| 281 | - // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | - foreach ($modules as $module) { |
|
| 283 | - $var = 'i18n_' . $module . '_' . $lang; |
|
| 281 | + // parcourir tous les modules jusqu'a ce qu'on trouve |
|
| 282 | + foreach ($modules as $module) { |
|
| 283 | + $var = 'i18n_' . $module . '_' . $lang; |
|
| 284 | 284 | |
| 285 | - if (empty($GLOBALS[$var])) { |
|
| 286 | - charger_langue($lang, $module); |
|
| 287 | - // surcharges persos -- on cherche |
|
| 288 | - // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | - if (!isset($local['local_' . $lang])) { |
|
| 290 | - // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | - $GLOBALS['idx_lang'] = $var; |
|
| 292 | - // ... (lang/)local_xx.php |
|
| 293 | - $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | - } |
|
| 295 | - if ($local['local_' . $lang]) { |
|
| 296 | - surcharger_langue($local['local_' . $lang]); |
|
| 297 | - } |
|
| 298 | - // ... puis (lang/)local.php |
|
| 299 | - if (!isset($local['local'])) { |
|
| 300 | - $local['local'] = chercher_module_lang('local'); |
|
| 301 | - } |
|
| 302 | - if ($local['local']) { |
|
| 303 | - surcharger_langue($local['local']); |
|
| 304 | - } |
|
| 305 | - } |
|
| 285 | + if (empty($GLOBALS[$var])) { |
|
| 286 | + charger_langue($lang, $module); |
|
| 287 | + // surcharges persos -- on cherche |
|
| 288 | + // (lang/)local_xx.php et/ou (lang/)local.php ... |
|
| 289 | + if (!isset($local['local_' . $lang])) { |
|
| 290 | + // redéfinir la langue en cours pour les surcharges (chercher_langue a pu le changer) |
|
| 291 | + $GLOBALS['idx_lang'] = $var; |
|
| 292 | + // ... (lang/)local_xx.php |
|
| 293 | + $local['local_' . $lang] = chercher_module_lang('local', $lang); |
|
| 294 | + } |
|
| 295 | + if ($local['local_' . $lang]) { |
|
| 296 | + surcharger_langue($local['local_' . $lang]); |
|
| 297 | + } |
|
| 298 | + // ... puis (lang/)local.php |
|
| 299 | + if (!isset($local['local'])) { |
|
| 300 | + $local['local'] = chercher_module_lang('local'); |
|
| 301 | + } |
|
| 302 | + if ($local['local']) { |
|
| 303 | + surcharger_langue($local['local']); |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - if (isset($GLOBALS[$var][$code])) { |
|
| 308 | - $desc->code = $code; |
|
| 309 | - $desc->module = $module; |
|
| 310 | - $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | - $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | - break; |
|
| 313 | - } |
|
| 314 | - } |
|
| 307 | + if (isset($GLOBALS[$var][$code])) { |
|
| 308 | + $desc->code = $code; |
|
| 309 | + $desc->module = $module; |
|
| 310 | + $desc->langue = $GLOBALS['lang_' . $var] ?? $lang; |
|
| 311 | + $desc->texte = $GLOBALS[$var][$code]; |
|
| 312 | + break; |
|
| 313 | + } |
|
| 314 | + } |
|
| 315 | 315 | |
| 316 | - if (!$desc->corrections) { |
|
| 317 | - $desc->corrections = true; |
|
| 318 | - // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | - // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | - if ( |
|
| 321 | - ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | - and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | - ) { |
|
| 324 | - if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | - $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | - } else { |
|
| 327 | - $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | - } |
|
| 329 | - } |
|
| 316 | + if (!$desc->corrections) { |
|
| 317 | + $desc->corrections = true; |
|
| 318 | + // Retour aux sources si la chaine est absente dans la langue cible ; |
|
| 319 | + // on essaie d'abord la langue du site, puis a defaut la langue fr |
|
| 320 | + if ( |
|
| 321 | + ($desc->texte === null || !strlen($desc->texte)) |
|
| 322 | + and $lang !== _LANGUE_PAR_DEFAUT |
|
| 323 | + ) { |
|
| 324 | + if ($lang !== $GLOBALS['meta']['langue_site']) { |
|
| 325 | + $desc = inc_traduire_dist($ori, $GLOBALS['meta']['langue_site'], true); |
|
| 326 | + } else { |
|
| 327 | + $desc = inc_traduire_dist($ori, _LANGUE_PAR_DEFAUT, true); |
|
| 328 | + } |
|
| 329 | + } |
|
| 330 | 330 | |
| 331 | - // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | - if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | - $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | - } |
|
| 331 | + // Supprimer la mention <NEW> ou <MODIF> |
|
| 332 | + if ($desc->texte && substr($desc->texte, 0, 1) === '<') { |
|
| 333 | + $desc->texte = str_replace(['<NEW>', '<MODIF>'], [], $desc->texte); |
|
| 334 | + } |
|
| 335 | 335 | |
| 336 | - // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | - // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | - if ( |
|
| 339 | - (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | - and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | - ) { |
|
| 342 | - include_spip('inc/charsets'); |
|
| 343 | - $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | - } |
|
| 345 | - } |
|
| 336 | + // Si on n'est pas en utf-8, la chaine peut l'etre... |
|
| 337 | + // le cas echeant on la convertit en entites html &#xxx; |
|
| 338 | + if ( |
|
| 339 | + (!isset($GLOBALS['meta']['charset']) or $GLOBALS['meta']['charset'] !== 'utf-8') |
|
| 340 | + and preg_match(',[\x7f-\xff],S', $desc->texte) |
|
| 341 | + ) { |
|
| 342 | + include_spip('inc/charsets'); |
|
| 343 | + $desc->texte = charset2unicode($desc->texte, 'utf-8'); |
|
| 344 | + } |
|
| 345 | + } |
|
| 346 | 346 | |
| 347 | - if (_request('var_mode') == 'traduction') { |
|
| 348 | - $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | - } else { |
|
| 350 | - $deja_vu[$lang][$ori] = $desc; |
|
| 351 | - } |
|
| 347 | + if (_request('var_mode') == 'traduction') { |
|
| 348 | + $desc = definir_details_traduction($desc, $ori_complet); |
|
| 349 | + } else { |
|
| 350 | + $deja_vu[$lang][$ori] = $desc; |
|
| 351 | + } |
|
| 352 | 352 | |
| 353 | - return $raw ? $desc : $desc->texte; |
|
| 353 | + return $raw ? $desc : $desc->texte; |
|
| 354 | 354 | } |
| 355 | 355 | |
| 356 | 356 | /** |
@@ -362,23 +362,23 @@ discard block |
||
| 362 | 362 | * @return SPIP_Traductions_Description |
| 363 | 363 | */ |
| 364 | 364 | function definir_details_traduction($desc, $modules) { |
| 365 | - if (!$desc->mode and $desc->texte) { |
|
| 366 | - // ne pas modifier 2 fois l'affichage |
|
| 367 | - $desc->mode = 'traduction'; |
|
| 368 | - $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | - $desc->texte = '<span ' |
|
| 370 | - . 'lang=' . $desc->langue |
|
| 371 | - . ' class=' . $classe |
|
| 372 | - . ' data-module=' . $desc->module |
|
| 373 | - . ' data-code=' . $desc->code |
|
| 374 | - . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | - . $desc->texte |
|
| 376 | - . '</span>'; |
|
| 377 | - $desc->texte = str_replace( |
|
| 378 | - ["$desc->module:", "$desc->module|"], |
|
| 379 | - ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | - $desc->texte |
|
| 381 | - ); |
|
| 382 | - } |
|
| 383 | - return $desc; |
|
| 365 | + if (!$desc->mode and $desc->texte) { |
|
| 366 | + // ne pas modifier 2 fois l'affichage |
|
| 367 | + $desc->mode = 'traduction'; |
|
| 368 | + $classe = 'debug-traduction' . ($desc->module == 'ecrire' ? '-prive' : ''); |
|
| 369 | + $desc->texte = '<span ' |
|
| 370 | + . 'lang=' . $desc->langue |
|
| 371 | + . ' class=' . $classe |
|
| 372 | + . ' data-module=' . $desc->module |
|
| 373 | + . ' data-code=' . $desc->code |
|
| 374 | + . ' title=' . $modules . '(' . $desc->langue . ')>' |
|
| 375 | + . $desc->texte |
|
| 376 | + . '</span>'; |
|
| 377 | + $desc->texte = str_replace( |
|
| 378 | + ["$desc->module:", "$desc->module|"], |
|
| 379 | + ["*$desc->module*:", "*$desc->module*|"], |
|
| 380 | + $desc->texte |
|
| 381 | + ); |
|
| 382 | + } |
|
| 383 | + return $desc; |
|
| 384 | 384 | } |
@@ -17,11 +17,11 @@ 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('_DATA_SOURCE_MAX_SIZE')) { |
| 24 | - define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 24 | + define('_DATA_SOURCE_MAX_SIZE', 2 * 1_048_576); |
|
| 25 | 25 | } |
| 26 | 26 | |
| 27 | 27 | |
@@ -42,17 +42,17 @@ discard block |
||
| 42 | 42 | * Description de la boucle complétée des champs |
| 43 | 43 | */ |
| 44 | 44 | function iterateur_DATA_dist($b) { |
| 45 | - $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | - $b->show = [ |
|
| 47 | - 'field' => [ |
|
| 48 | - 'cle' => 'STRING', |
|
| 49 | - 'valeur' => 'STRING', |
|
| 50 | - '*' => 'ALL' // Champ joker * |
|
| 51 | - ] |
|
| 52 | - ]; |
|
| 53 | - $b->select[] = '.valeur'; |
|
| 54 | - |
|
| 55 | - return $b; |
|
| 45 | + $b->iterateur = 'DATA'; # designe la classe d'iterateur |
|
| 46 | + $b->show = [ |
|
| 47 | + 'field' => [ |
|
| 48 | + 'cle' => 'STRING', |
|
| 49 | + 'valeur' => 'STRING', |
|
| 50 | + '*' => 'ALL' // Champ joker * |
|
| 51 | + ] |
|
| 52 | + ]; |
|
| 53 | + $b->select[] = '.valeur'; |
|
| 54 | + |
|
| 55 | + return $b; |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | |
@@ -62,518 +62,518 @@ discard block |
||
| 62 | 62 | * Pour itérer sur des données quelconques (transformables en tableau) |
| 63 | 63 | */ |
| 64 | 64 | class IterateurDATA implements Iterator { |
| 65 | - /** Tableau de données */ |
|
| 66 | - protected array $tableau = []; |
|
| 67 | - |
|
| 68 | - /** |
|
| 69 | - * Conditions de filtrage |
|
| 70 | - * ie criteres de selection |
|
| 71 | - */ |
|
| 72 | - protected array $filtre = []; |
|
| 73 | - |
|
| 74 | - |
|
| 75 | - /** |
|
| 76 | - * Cle courante |
|
| 77 | - * |
|
| 78 | - * @var scalar |
|
| 79 | - */ |
|
| 80 | - protected $cle = null; |
|
| 81 | - |
|
| 82 | - /** |
|
| 83 | - * Valeur courante |
|
| 84 | - * |
|
| 85 | - * @var mixed |
|
| 86 | - */ |
|
| 87 | - protected $valeur = null; |
|
| 88 | - |
|
| 89 | - protected string $type = 'DATA'; |
|
| 90 | - |
|
| 91 | - protected array $command = []; |
|
| 92 | - |
|
| 93 | - protected array $info = []; |
|
| 94 | - |
|
| 95 | - /** Erreur presente ? */ |
|
| 96 | - public bool $err = false; |
|
| 97 | - |
|
| 98 | - /** |
|
| 99 | - * Calcul du total des elements |
|
| 100 | - * |
|
| 101 | - * @var int|null |
|
| 102 | - **/ |
|
| 103 | - public $total = null; |
|
| 104 | - |
|
| 105 | - /** |
|
| 106 | - * Constructeur |
|
| 107 | - * |
|
| 108 | - * @param $command |
|
| 109 | - * @param array $info |
|
| 110 | - */ |
|
| 111 | - public function __construct($command, $info = []) { |
|
| 112 | - $this->type = 'DATA'; |
|
| 113 | - $this->command = $command; |
|
| 114 | - $this->info = $info; |
|
| 115 | - |
|
| 116 | - $this->select($command); |
|
| 117 | - } |
|
| 118 | - |
|
| 119 | - /** |
|
| 120 | - * Revenir au depart |
|
| 121 | - * |
|
| 122 | - * @return void |
|
| 123 | - */ |
|
| 124 | - public function rewind(): void { |
|
| 125 | - reset($this->tableau); |
|
| 126 | - $this->cle = array_key_first($this->tableau); |
|
| 127 | - $this->valeur = current($this->tableau); |
|
| 128 | - next($this->tableau); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - /** |
|
| 132 | - * Déclarer les critères exceptions |
|
| 133 | - * |
|
| 134 | - * @return array |
|
| 135 | - */ |
|
| 136 | - public function exception_des_criteres() { |
|
| 137 | - return ['tableau']; |
|
| 138 | - } |
|
| 139 | - |
|
| 140 | - /** |
|
| 141 | - * Récupérer depuis le cache si possible |
|
| 142 | - * |
|
| 143 | - * @param string $cle |
|
| 144 | - * @return mixed |
|
| 145 | - */ |
|
| 146 | - protected function cache_get($cle) { |
|
| 147 | - if (!$cle) { |
|
| 148 | - return; |
|
| 149 | - } |
|
| 150 | - # utiliser memoization si dispo |
|
| 151 | - if (!function_exists('cache_get')) { |
|
| 152 | - return; |
|
| 153 | - } |
|
| 154 | - |
|
| 155 | - return cache_get($cle); |
|
| 156 | - } |
|
| 157 | - |
|
| 158 | - /** |
|
| 159 | - * Stocker en cache si possible |
|
| 160 | - * |
|
| 161 | - * @param string $cle |
|
| 162 | - * @param int $ttl |
|
| 163 | - * @param null|mixed $valeur |
|
| 164 | - * @return bool |
|
| 165 | - */ |
|
| 166 | - protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | - if (!$cle) { |
|
| 168 | - return; |
|
| 169 | - } |
|
| 170 | - if (is_null($valeur)) { |
|
| 171 | - $valeur = $this->tableau; |
|
| 172 | - } |
|
| 173 | - # utiliser memoization si dispo |
|
| 174 | - if (!function_exists('cache_set')) { |
|
| 175 | - return; |
|
| 176 | - } |
|
| 177 | - |
|
| 178 | - return cache_set( |
|
| 179 | - $cle, |
|
| 180 | - [ |
|
| 181 | - 'data' => $valeur, |
|
| 182 | - 'time' => time(), |
|
| 183 | - 'ttl' => $ttl |
|
| 184 | - ], |
|
| 185 | - 3600 + $ttl |
|
| 186 | - ); |
|
| 187 | - # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | - # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | - } |
|
| 190 | - |
|
| 191 | - /** |
|
| 192 | - * Aller chercher les données de la boucle DATA |
|
| 193 | - * |
|
| 194 | - * @throws Exception |
|
| 195 | - * @param array $command |
|
| 196 | - * @return void |
|
| 197 | - */ |
|
| 198 | - protected function select($command) { |
|
| 199 | - |
|
| 200 | - // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | - // le type se retrouve dans la commande 'from' |
|
| 202 | - // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | - if (isset($this->command['from'][0])) { |
|
| 204 | - if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | - array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | - } |
|
| 207 | - $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | - // les commandes connues pour l'iterateur DATA |
|
| 212 | - // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | - |
|
| 214 | - // {source format, [URL], [arg2]...} |
|
| 215 | - if ( |
|
| 216 | - isset($this->command['source']) |
|
| 217 | - and isset($this->command['sourcemode']) |
|
| 218 | - ) { |
|
| 219 | - $this->select_source(); |
|
| 220 | - } |
|
| 221 | - |
|
| 222 | - // Critere {liste X1, X2, X3} |
|
| 223 | - if (isset($this->command['liste'])) { |
|
| 224 | - $this->select_liste(); |
|
| 225 | - } |
|
| 226 | - if (isset($this->command['enum'])) { |
|
| 227 | - $this->select_enum(); |
|
| 228 | - } |
|
| 229 | - |
|
| 230 | - // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | - if (!is_array($this->tableau)) { |
|
| 232 | - $this->err = true; |
|
| 233 | - spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | - } |
|
| 235 | - |
|
| 236 | - // {datapath query.results} |
|
| 237 | - // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | - if ( |
|
| 239 | - !$this->err |
|
| 240 | - and isset($this->command['datapath']) |
|
| 241 | - and is_array($this->command['datapath']) |
|
| 242 | - ) { |
|
| 243 | - $this->select_datapath(); |
|
| 244 | - } |
|
| 245 | - |
|
| 246 | - // tri {par x} |
|
| 247 | - if ($this->command['orderby']) { |
|
| 248 | - $this->select_orderby(); |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | - if ($this->command['groupby']) { |
|
| 253 | - $this->select_groupby(); |
|
| 254 | - } |
|
| 255 | - |
|
| 256 | - $this->rewind(); |
|
| 257 | - #var_dump($this->tableau); |
|
| 258 | - } |
|
| 259 | - |
|
| 260 | - |
|
| 261 | - /** |
|
| 262 | - * Aller chercher les donnees de la boucle DATA |
|
| 263 | - * depuis une source |
|
| 264 | - * {source format, [URL], [arg2]...} |
|
| 265 | - */ |
|
| 266 | - protected function select_source() { |
|
| 267 | - # un peu crado : avant de charger le cache il faut charger |
|
| 268 | - # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | - # l'objet en cache ; cf plugins/icalendar |
|
| 270 | - # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | - if ( |
|
| 272 | - isset($this->command['sourcemode']) |
|
| 273 | - and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | - ) { |
|
| 275 | - charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | - } |
|
| 277 | - |
|
| 278 | - # le premier argument peut etre un array, une URL etc. |
|
| 279 | - $src = $this->command['source'][0]; |
|
| 280 | - |
|
| 281 | - # avons-nous un cache dispo ? |
|
| 282 | - $cle = null; |
|
| 283 | - if (is_string($src)) { |
|
| 284 | - $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | - } |
|
| 286 | - |
|
| 287 | - $cache = $this->cache_get($cle); |
|
| 288 | - if (isset($this->command['datacache'])) { |
|
| 289 | - $ttl = intval($this->command['datacache']); |
|
| 290 | - } |
|
| 291 | - if ( |
|
| 292 | - $cache |
|
| 293 | - and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | - > time()) |
|
| 295 | - and !(_request('var_mode') === 'recalcul' |
|
| 296 | - and include_spip('inc/autoriser') |
|
| 297 | - and autoriser('recalcul') |
|
| 298 | - ) |
|
| 299 | - ) { |
|
| 300 | - $this->tableau = $cache['data']; |
|
| 301 | - } else { |
|
| 302 | - try { |
|
| 303 | - if ( |
|
| 304 | - isset($this->command['sourcemode']) |
|
| 305 | - and in_array( |
|
| 306 | - $this->command['sourcemode'], |
|
| 307 | - ['table', 'array', 'tableau'] |
|
| 308 | - ) |
|
| 309 | - ) { |
|
| 310 | - if ( |
|
| 311 | - is_array($a = $src) |
|
| 312 | - or (is_string($a) |
|
| 313 | - and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | - and is_array($a = @unserialize($a))) |
|
| 315 | - ) { |
|
| 316 | - $this->tableau = $a; |
|
| 317 | - } |
|
| 318 | - } else { |
|
| 319 | - $data = $src; |
|
| 320 | - if (is_string($src)) { |
|
| 321 | - if (tester_url_absolue($src)) { |
|
| 322 | - include_spip('inc/distant'); |
|
| 323 | - $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | - $data = $data['page'] ?? ''; |
|
| 325 | - if (!$data) { |
|
| 326 | - throw new Exception('404'); |
|
| 327 | - } |
|
| 328 | - if (!isset($ttl)) { |
|
| 329 | - $ttl = 24 * 3600; |
|
| 330 | - } |
|
| 331 | - } elseif (@is_dir($src)) { |
|
| 332 | - $data = $src; |
|
| 333 | - } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | - $data = spip_file_get_contents($src); |
|
| 335 | - } |
|
| 336 | - if (!isset($ttl)) { |
|
| 337 | - $ttl = 10; |
|
| 338 | - } |
|
| 339 | - } |
|
| 340 | - |
|
| 341 | - if ( |
|
| 342 | - !$this->err |
|
| 343 | - and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | - ) { |
|
| 345 | - $args = $this->command['source']; |
|
| 346 | - $args[0] = $data; |
|
| 347 | - if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | - $this->tableau = $a; |
|
| 349 | - } |
|
| 350 | - } |
|
| 351 | - } |
|
| 352 | - |
|
| 353 | - if (!is_array($this->tableau)) { |
|
| 354 | - $this->err = true; |
|
| 355 | - } |
|
| 356 | - |
|
| 357 | - if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | - $this->cache_set($cle, $ttl); |
|
| 359 | - } |
|
| 360 | - } catch (Exception $e) { |
|
| 361 | - $e = $e->getMessage(); |
|
| 362 | - $err = sprintf( |
|
| 363 | - "[%s, %s] $e", |
|
| 364 | - $src, |
|
| 365 | - $this->command['sourcemode'] |
|
| 366 | - ); |
|
| 367 | - erreur_squelette([$err, []]); |
|
| 368 | - $this->err = true; |
|
| 369 | - } |
|
| 370 | - } |
|
| 371 | - |
|
| 372 | - # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | - if ( |
|
| 374 | - $this->err |
|
| 375 | - and $cache |
|
| 376 | - ) { |
|
| 377 | - $this->tableau = $cache['data']; |
|
| 378 | - $this->err = false; |
|
| 379 | - } |
|
| 380 | - } |
|
| 381 | - |
|
| 382 | - |
|
| 383 | - /** |
|
| 384 | - * Retourne un tableau donne depuis un critère liste |
|
| 385 | - * |
|
| 386 | - * Critère `{liste X1, X2, X3}` |
|
| 387 | - * |
|
| 388 | - * @see critere_DATA_liste_dist() |
|
| 389 | - * |
|
| 390 | - **/ |
|
| 391 | - protected function select_liste() { |
|
| 392 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | - if (!isset($this->command['liste'][1])) { |
|
| 394 | - if (!is_array($this->command['liste'][0])) { |
|
| 395 | - $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | - } else { |
|
| 397 | - $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | - } |
|
| 399 | - } |
|
| 400 | - $this->tableau = $this->command['liste']; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - /** |
|
| 404 | - * Retourne un tableau donne depuis un critere liste |
|
| 405 | - * Critere {enum Xmin, Xmax} |
|
| 406 | - * |
|
| 407 | - **/ |
|
| 408 | - protected function select_enum() { |
|
| 409 | - # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | - if (!isset($this->command['enum'][1])) { |
|
| 411 | - if (!is_array($this->command['enum'][0])) { |
|
| 412 | - $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | - } else { |
|
| 414 | - $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | - } |
|
| 416 | - } |
|
| 417 | - if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | - $enum = range( |
|
| 419 | - array_shift($this->command['enum']), |
|
| 420 | - array_shift($this->command['enum']), |
|
| 421 | - array_shift($this->command['enum']) |
|
| 422 | - ); |
|
| 423 | - } else { |
|
| 424 | - $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | - } |
|
| 426 | - $this->tableau = $enum; |
|
| 427 | - } |
|
| 428 | - |
|
| 429 | - |
|
| 430 | - /** |
|
| 431 | - * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | - * {datapath query.results} |
|
| 433 | - * |
|
| 434 | - **/ |
|
| 435 | - protected function select_datapath() { |
|
| 436 | - $base = reset($this->command['datapath']); |
|
| 437 | - if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | - $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | - if (!is_array($this->tableau)) { |
|
| 440 | - $this->tableau = []; |
|
| 441 | - $this->err = true; |
|
| 442 | - spip_log("datapath '$base' absent"); |
|
| 443 | - } |
|
| 444 | - } |
|
| 445 | - } |
|
| 446 | - |
|
| 447 | - /** |
|
| 448 | - * Ordonner les resultats |
|
| 449 | - * {par x} |
|
| 450 | - * |
|
| 451 | - **/ |
|
| 452 | - protected function select_orderby() { |
|
| 453 | - $sortfunc = ''; |
|
| 454 | - $aleas = 0; |
|
| 455 | - foreach ($this->command['orderby'] as $tri) { |
|
| 456 | - // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | - if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | - $r = array_pad($r, 3, null); |
|
| 459 | - |
|
| 460 | - // tri par cle |
|
| 461 | - if ($r[1] == 'cle') { |
|
| 462 | - if (isset($r[2]) and $r[2]) { |
|
| 463 | - krsort($this->tableau); |
|
| 464 | - } else { |
|
| 465 | - ksort($this->tableau); |
|
| 466 | - } |
|
| 467 | - } # {par hasard} |
|
| 468 | - else { |
|
| 469 | - if ($r[1] == 'hasard') { |
|
| 470 | - $k = array_keys($this->tableau); |
|
| 471 | - shuffle($k); |
|
| 472 | - $v = []; |
|
| 473 | - foreach ($k as $cle) { |
|
| 474 | - $v[$cle] = $this->tableau[$cle]; |
|
| 475 | - } |
|
| 476 | - $this->tableau = $v; |
|
| 477 | - } else { |
|
| 478 | - # {par valeur} |
|
| 479 | - if ($r[1] == 'valeur') { |
|
| 480 | - $tv = '%s'; |
|
| 481 | - } # {par valeur/xx/yy} ?? |
|
| 482 | - else { |
|
| 483 | - $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | - } |
|
| 485 | - $sortfunc .= ' |
|
| 65 | + /** Tableau de données */ |
|
| 66 | + protected array $tableau = []; |
|
| 67 | + |
|
| 68 | + /** |
|
| 69 | + * Conditions de filtrage |
|
| 70 | + * ie criteres de selection |
|
| 71 | + */ |
|
| 72 | + protected array $filtre = []; |
|
| 73 | + |
|
| 74 | + |
|
| 75 | + /** |
|
| 76 | + * Cle courante |
|
| 77 | + * |
|
| 78 | + * @var scalar |
|
| 79 | + */ |
|
| 80 | + protected $cle = null; |
|
| 81 | + |
|
| 82 | + /** |
|
| 83 | + * Valeur courante |
|
| 84 | + * |
|
| 85 | + * @var mixed |
|
| 86 | + */ |
|
| 87 | + protected $valeur = null; |
|
| 88 | + |
|
| 89 | + protected string $type = 'DATA'; |
|
| 90 | + |
|
| 91 | + protected array $command = []; |
|
| 92 | + |
|
| 93 | + protected array $info = []; |
|
| 94 | + |
|
| 95 | + /** Erreur presente ? */ |
|
| 96 | + public bool $err = false; |
|
| 97 | + |
|
| 98 | + /** |
|
| 99 | + * Calcul du total des elements |
|
| 100 | + * |
|
| 101 | + * @var int|null |
|
| 102 | + **/ |
|
| 103 | + public $total = null; |
|
| 104 | + |
|
| 105 | + /** |
|
| 106 | + * Constructeur |
|
| 107 | + * |
|
| 108 | + * @param $command |
|
| 109 | + * @param array $info |
|
| 110 | + */ |
|
| 111 | + public function __construct($command, $info = []) { |
|
| 112 | + $this->type = 'DATA'; |
|
| 113 | + $this->command = $command; |
|
| 114 | + $this->info = $info; |
|
| 115 | + |
|
| 116 | + $this->select($command); |
|
| 117 | + } |
|
| 118 | + |
|
| 119 | + /** |
|
| 120 | + * Revenir au depart |
|
| 121 | + * |
|
| 122 | + * @return void |
|
| 123 | + */ |
|
| 124 | + public function rewind(): void { |
|
| 125 | + reset($this->tableau); |
|
| 126 | + $this->cle = array_key_first($this->tableau); |
|
| 127 | + $this->valeur = current($this->tableau); |
|
| 128 | + next($this->tableau); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + /** |
|
| 132 | + * Déclarer les critères exceptions |
|
| 133 | + * |
|
| 134 | + * @return array |
|
| 135 | + */ |
|
| 136 | + public function exception_des_criteres() { |
|
| 137 | + return ['tableau']; |
|
| 138 | + } |
|
| 139 | + |
|
| 140 | + /** |
|
| 141 | + * Récupérer depuis le cache si possible |
|
| 142 | + * |
|
| 143 | + * @param string $cle |
|
| 144 | + * @return mixed |
|
| 145 | + */ |
|
| 146 | + protected function cache_get($cle) { |
|
| 147 | + if (!$cle) { |
|
| 148 | + return; |
|
| 149 | + } |
|
| 150 | + # utiliser memoization si dispo |
|
| 151 | + if (!function_exists('cache_get')) { |
|
| 152 | + return; |
|
| 153 | + } |
|
| 154 | + |
|
| 155 | + return cache_get($cle); |
|
| 156 | + } |
|
| 157 | + |
|
| 158 | + /** |
|
| 159 | + * Stocker en cache si possible |
|
| 160 | + * |
|
| 161 | + * @param string $cle |
|
| 162 | + * @param int $ttl |
|
| 163 | + * @param null|mixed $valeur |
|
| 164 | + * @return bool |
|
| 165 | + */ |
|
| 166 | + protected function cache_set($cle, $ttl, $valeur = null) { |
|
| 167 | + if (!$cle) { |
|
| 168 | + return; |
|
| 169 | + } |
|
| 170 | + if (is_null($valeur)) { |
|
| 171 | + $valeur = $this->tableau; |
|
| 172 | + } |
|
| 173 | + # utiliser memoization si dispo |
|
| 174 | + if (!function_exists('cache_set')) { |
|
| 175 | + return; |
|
| 176 | + } |
|
| 177 | + |
|
| 178 | + return cache_set( |
|
| 179 | + $cle, |
|
| 180 | + [ |
|
| 181 | + 'data' => $valeur, |
|
| 182 | + 'time' => time(), |
|
| 183 | + 'ttl' => $ttl |
|
| 184 | + ], |
|
| 185 | + 3600 + $ttl |
|
| 186 | + ); |
|
| 187 | + # conserver le cache 1h de plus que la validite demandee, |
|
| 188 | + # pour le cas ou le serveur distant ne reponde plus |
|
| 189 | + } |
|
| 190 | + |
|
| 191 | + /** |
|
| 192 | + * Aller chercher les données de la boucle DATA |
|
| 193 | + * |
|
| 194 | + * @throws Exception |
|
| 195 | + * @param array $command |
|
| 196 | + * @return void |
|
| 197 | + */ |
|
| 198 | + protected function select($command) { |
|
| 199 | + |
|
| 200 | + // l'iterateur DATA peut etre appele en passant (data:type) |
|
| 201 | + // le type se retrouve dans la commande 'from' |
|
| 202 | + // dans ce cas la le critere {source}, si present, n'a pas besoin du 1er argument |
|
| 203 | + if (isset($this->command['from'][0])) { |
|
| 204 | + if (isset($this->command['source']) and is_array($this->command['source'])) { |
|
| 205 | + array_unshift($this->command['source'], $this->command['sourcemode']); |
|
| 206 | + } |
|
| 207 | + $this->command['sourcemode'] = $this->command['from'][0]; |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + // cherchons differents moyens de creer le tableau de donnees |
|
| 211 | + // les commandes connues pour l'iterateur DATA |
|
| 212 | + // sont : {tableau #ARRAY} ; {cle=...} ; {valeur=...} |
|
| 213 | + |
|
| 214 | + // {source format, [URL], [arg2]...} |
|
| 215 | + if ( |
|
| 216 | + isset($this->command['source']) |
|
| 217 | + and isset($this->command['sourcemode']) |
|
| 218 | + ) { |
|
| 219 | + $this->select_source(); |
|
| 220 | + } |
|
| 221 | + |
|
| 222 | + // Critere {liste X1, X2, X3} |
|
| 223 | + if (isset($this->command['liste'])) { |
|
| 224 | + $this->select_liste(); |
|
| 225 | + } |
|
| 226 | + if (isset($this->command['enum'])) { |
|
| 227 | + $this->select_enum(); |
|
| 228 | + } |
|
| 229 | + |
|
| 230 | + // Si a ce stade on n'a pas de table, il y a un bug |
|
| 231 | + if (!is_array($this->tableau)) { |
|
| 232 | + $this->err = true; |
|
| 233 | + spip_log('erreur datasource ' . var_export($command, true)); |
|
| 234 | + } |
|
| 235 | + |
|
| 236 | + // {datapath query.results} |
|
| 237 | + // extraire le chemin "query.results" du tableau de donnees |
|
| 238 | + if ( |
|
| 239 | + !$this->err |
|
| 240 | + and isset($this->command['datapath']) |
|
| 241 | + and is_array($this->command['datapath']) |
|
| 242 | + ) { |
|
| 243 | + $this->select_datapath(); |
|
| 244 | + } |
|
| 245 | + |
|
| 246 | + // tri {par x} |
|
| 247 | + if ($this->command['orderby']) { |
|
| 248 | + $this->select_orderby(); |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + // grouper les resultats {fusion /x/y/z} ; |
|
| 252 | + if ($this->command['groupby']) { |
|
| 253 | + $this->select_groupby(); |
|
| 254 | + } |
|
| 255 | + |
|
| 256 | + $this->rewind(); |
|
| 257 | + #var_dump($this->tableau); |
|
| 258 | + } |
|
| 259 | + |
|
| 260 | + |
|
| 261 | + /** |
|
| 262 | + * Aller chercher les donnees de la boucle DATA |
|
| 263 | + * depuis une source |
|
| 264 | + * {source format, [URL], [arg2]...} |
|
| 265 | + */ |
|
| 266 | + protected function select_source() { |
|
| 267 | + # un peu crado : avant de charger le cache il faut charger |
|
| 268 | + # les class indispensables, sinon PHP ne saura pas gerer |
|
| 269 | + # l'objet en cache ; cf plugins/icalendar |
|
| 270 | + # perf : pas de fonction table_to_array ! (table est deja un array) |
|
| 271 | + if ( |
|
| 272 | + isset($this->command['sourcemode']) |
|
| 273 | + and !in_array($this->command['sourcemode'], ['table', 'array', 'tableau']) |
|
| 274 | + ) { |
|
| 275 | + charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true); |
|
| 276 | + } |
|
| 277 | + |
|
| 278 | + # le premier argument peut etre un array, une URL etc. |
|
| 279 | + $src = $this->command['source'][0]; |
|
| 280 | + |
|
| 281 | + # avons-nous un cache dispo ? |
|
| 282 | + $cle = null; |
|
| 283 | + if (is_string($src)) { |
|
| 284 | + $cle = 'datasource_' . md5($this->command['sourcemode'] . ':' . var_export($this->command['source'], true)); |
|
| 285 | + } |
|
| 286 | + |
|
| 287 | + $cache = $this->cache_get($cle); |
|
| 288 | + if (isset($this->command['datacache'])) { |
|
| 289 | + $ttl = intval($this->command['datacache']); |
|
| 290 | + } |
|
| 291 | + if ( |
|
| 292 | + $cache |
|
| 293 | + and ($cache['time'] + ($ttl ?? $cache['ttl']) |
|
| 294 | + > time()) |
|
| 295 | + and !(_request('var_mode') === 'recalcul' |
|
| 296 | + and include_spip('inc/autoriser') |
|
| 297 | + and autoriser('recalcul') |
|
| 298 | + ) |
|
| 299 | + ) { |
|
| 300 | + $this->tableau = $cache['data']; |
|
| 301 | + } else { |
|
| 302 | + try { |
|
| 303 | + if ( |
|
| 304 | + isset($this->command['sourcemode']) |
|
| 305 | + and in_array( |
|
| 306 | + $this->command['sourcemode'], |
|
| 307 | + ['table', 'array', 'tableau'] |
|
| 308 | + ) |
|
| 309 | + ) { |
|
| 310 | + if ( |
|
| 311 | + is_array($a = $src) |
|
| 312 | + or (is_string($a) |
|
| 313 | + and $a = str_replace('"', '"', $a) # fragile! |
|
| 314 | + and is_array($a = @unserialize($a))) |
|
| 315 | + ) { |
|
| 316 | + $this->tableau = $a; |
|
| 317 | + } |
|
| 318 | + } else { |
|
| 319 | + $data = $src; |
|
| 320 | + if (is_string($src)) { |
|
| 321 | + if (tester_url_absolue($src)) { |
|
| 322 | + include_spip('inc/distant'); |
|
| 323 | + $data = recuperer_url($src, ['taille_max' => _DATA_SOURCE_MAX_SIZE]); |
|
| 324 | + $data = $data['page'] ?? ''; |
|
| 325 | + if (!$data) { |
|
| 326 | + throw new Exception('404'); |
|
| 327 | + } |
|
| 328 | + if (!isset($ttl)) { |
|
| 329 | + $ttl = 24 * 3600; |
|
| 330 | + } |
|
| 331 | + } elseif (@is_dir($src)) { |
|
| 332 | + $data = $src; |
|
| 333 | + } elseif (@is_readable($src) && @is_file($src)) { |
|
| 334 | + $data = spip_file_get_contents($src); |
|
| 335 | + } |
|
| 336 | + if (!isset($ttl)) { |
|
| 337 | + $ttl = 10; |
|
| 338 | + } |
|
| 339 | + } |
|
| 340 | + |
|
| 341 | + if ( |
|
| 342 | + !$this->err |
|
| 343 | + and $data_to_array = charger_fonction($this->command['sourcemode'] . '_to_array', 'inc', true) |
|
| 344 | + ) { |
|
| 345 | + $args = $this->command['source']; |
|
| 346 | + $args[0] = $data; |
|
| 347 | + if (is_array($a = $data_to_array(...$args))) { |
|
| 348 | + $this->tableau = $a; |
|
| 349 | + } |
|
| 350 | + } |
|
| 351 | + } |
|
| 352 | + |
|
| 353 | + if (!is_array($this->tableau)) { |
|
| 354 | + $this->err = true; |
|
| 355 | + } |
|
| 356 | + |
|
| 357 | + if (!$this->err and isset($ttl) and $ttl > 0) { |
|
| 358 | + $this->cache_set($cle, $ttl); |
|
| 359 | + } |
|
| 360 | + } catch (Exception $e) { |
|
| 361 | + $e = $e->getMessage(); |
|
| 362 | + $err = sprintf( |
|
| 363 | + "[%s, %s] $e", |
|
| 364 | + $src, |
|
| 365 | + $this->command['sourcemode'] |
|
| 366 | + ); |
|
| 367 | + erreur_squelette([$err, []]); |
|
| 368 | + $this->err = true; |
|
| 369 | + } |
|
| 370 | + } |
|
| 371 | + |
|
| 372 | + # en cas d'erreur, utiliser le cache si encore dispo |
|
| 373 | + if ( |
|
| 374 | + $this->err |
|
| 375 | + and $cache |
|
| 376 | + ) { |
|
| 377 | + $this->tableau = $cache['data']; |
|
| 378 | + $this->err = false; |
|
| 379 | + } |
|
| 380 | + } |
|
| 381 | + |
|
| 382 | + |
|
| 383 | + /** |
|
| 384 | + * Retourne un tableau donne depuis un critère liste |
|
| 385 | + * |
|
| 386 | + * Critère `{liste X1, X2, X3}` |
|
| 387 | + * |
|
| 388 | + * @see critere_DATA_liste_dist() |
|
| 389 | + * |
|
| 390 | + **/ |
|
| 391 | + protected function select_liste() { |
|
| 392 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 393 | + if (!isset($this->command['liste'][1])) { |
|
| 394 | + if (!is_array($this->command['liste'][0])) { |
|
| 395 | + $this->command['liste'] = explode(',', $this->command['liste'][0]); |
|
| 396 | + } else { |
|
| 397 | + $this->command['liste'] = $this->command['liste'][0]; |
|
| 398 | + } |
|
| 399 | + } |
|
| 400 | + $this->tableau = $this->command['liste']; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + /** |
|
| 404 | + * Retourne un tableau donne depuis un critere liste |
|
| 405 | + * Critere {enum Xmin, Xmax} |
|
| 406 | + * |
|
| 407 | + **/ |
|
| 408 | + protected function select_enum() { |
|
| 409 | + # s'il n'y a qu'une valeur dans la liste, sans doute une #BALISE |
|
| 410 | + if (!isset($this->command['enum'][1])) { |
|
| 411 | + if (!is_array($this->command['enum'][0])) { |
|
| 412 | + $this->command['enum'] = explode(',', $this->command['enum'][0]); |
|
| 413 | + } else { |
|
| 414 | + $this->command['enum'] = $this->command['enum'][0]; |
|
| 415 | + } |
|
| 416 | + } |
|
| 417 | + if ((is_countable($this->command['enum']) ? count($this->command['enum']) : 0) >= 3) { |
|
| 418 | + $enum = range( |
|
| 419 | + array_shift($this->command['enum']), |
|
| 420 | + array_shift($this->command['enum']), |
|
| 421 | + array_shift($this->command['enum']) |
|
| 422 | + ); |
|
| 423 | + } else { |
|
| 424 | + $enum = range(array_shift($this->command['enum']), array_shift($this->command['enum'])); |
|
| 425 | + } |
|
| 426 | + $this->tableau = $enum; |
|
| 427 | + } |
|
| 428 | + |
|
| 429 | + |
|
| 430 | + /** |
|
| 431 | + * extraire le chemin "query.results" du tableau de donnees |
|
| 432 | + * {datapath query.results} |
|
| 433 | + * |
|
| 434 | + **/ |
|
| 435 | + protected function select_datapath() { |
|
| 436 | + $base = reset($this->command['datapath']); |
|
| 437 | + if (strlen($base = ltrim(trim($base), '/'))) { |
|
| 438 | + $this->tableau = table_valeur($this->tableau, $base); |
|
| 439 | + if (!is_array($this->tableau)) { |
|
| 440 | + $this->tableau = []; |
|
| 441 | + $this->err = true; |
|
| 442 | + spip_log("datapath '$base' absent"); |
|
| 443 | + } |
|
| 444 | + } |
|
| 445 | + } |
|
| 446 | + |
|
| 447 | + /** |
|
| 448 | + * Ordonner les resultats |
|
| 449 | + * {par x} |
|
| 450 | + * |
|
| 451 | + **/ |
|
| 452 | + protected function select_orderby() { |
|
| 453 | + $sortfunc = ''; |
|
| 454 | + $aleas = 0; |
|
| 455 | + foreach ($this->command['orderby'] as $tri) { |
|
| 456 | + // virer le / initial pour les criteres de la forme {par /xx} |
|
| 457 | + if (preg_match(',^\.?([/\w:_-]+)( DESC)?$,iS', ltrim($tri, '/'), $r)) { |
|
| 458 | + $r = array_pad($r, 3, null); |
|
| 459 | + |
|
| 460 | + // tri par cle |
|
| 461 | + if ($r[1] == 'cle') { |
|
| 462 | + if (isset($r[2]) and $r[2]) { |
|
| 463 | + krsort($this->tableau); |
|
| 464 | + } else { |
|
| 465 | + ksort($this->tableau); |
|
| 466 | + } |
|
| 467 | + } # {par hasard} |
|
| 468 | + else { |
|
| 469 | + if ($r[1] == 'hasard') { |
|
| 470 | + $k = array_keys($this->tableau); |
|
| 471 | + shuffle($k); |
|
| 472 | + $v = []; |
|
| 473 | + foreach ($k as $cle) { |
|
| 474 | + $v[$cle] = $this->tableau[$cle]; |
|
| 475 | + } |
|
| 476 | + $this->tableau = $v; |
|
| 477 | + } else { |
|
| 478 | + # {par valeur} |
|
| 479 | + if ($r[1] == 'valeur') { |
|
| 480 | + $tv = '%s'; |
|
| 481 | + } # {par valeur/xx/yy} ?? |
|
| 482 | + else { |
|
| 483 | + $tv = 'table_valeur(%s, ' . var_export($r[1], true) . ')'; |
|
| 484 | + } |
|
| 485 | + $sortfunc .= ' |
|
| 486 | 486 | $a = ' . sprintf($tv, '$aa') . '; |
| 487 | 487 | $b = ' . sprintf($tv, '$bb') . '; |
| 488 | 488 | if ($a <> $b) |
| 489 | 489 | return ($a ' . (!empty($r[2]) ? '>' : '<') . ' $b) ? -1 : 1;'; |
| 490 | - } |
|
| 491 | - } |
|
| 492 | - } |
|
| 493 | - } |
|
| 494 | - |
|
| 495 | - if ($sortfunc) { |
|
| 496 | - $sortfunc .= "\n return 0;"; |
|
| 497 | - uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | - } |
|
| 499 | - } |
|
| 500 | - |
|
| 501 | - |
|
| 502 | - /** |
|
| 503 | - * Grouper les resultats |
|
| 504 | - * {fusion /x/y/z} |
|
| 505 | - * |
|
| 506 | - **/ |
|
| 507 | - protected function select_groupby() { |
|
| 508 | - // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | - if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | - $vu = []; |
|
| 511 | - foreach ($this->tableau as $k => $v) { |
|
| 512 | - $val = table_valeur($v, $fusion); |
|
| 513 | - if (isset($vu[$val])) { |
|
| 514 | - unset($this->tableau[$k]); |
|
| 515 | - } else { |
|
| 516 | - $vu[$val] = true; |
|
| 517 | - } |
|
| 518 | - } |
|
| 519 | - } |
|
| 520 | - } |
|
| 521 | - |
|
| 522 | - |
|
| 523 | - /** |
|
| 524 | - * L'iterateur est-il encore valide ? |
|
| 525 | - * |
|
| 526 | - * @return bool |
|
| 527 | - */ |
|
| 528 | - public function valid(): bool { |
|
| 529 | - return !is_null($this->cle); |
|
| 530 | - } |
|
| 531 | - |
|
| 532 | - /** |
|
| 533 | - * Retourner la valeur |
|
| 534 | - * |
|
| 535 | - * @return mixed |
|
| 536 | - */ |
|
| 537 | - #[\ReturnTypeWillChange] |
|
| 538 | - public function current() { |
|
| 539 | - return $this->valeur; |
|
| 540 | - } |
|
| 541 | - |
|
| 542 | - /** |
|
| 543 | - * Retourner la cle |
|
| 544 | - * |
|
| 545 | - * @return mixed |
|
| 546 | - */ |
|
| 547 | - #[\ReturnTypeWillChange] |
|
| 548 | - public function key() { |
|
| 549 | - return $this->cle; |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - /** |
|
| 553 | - * Passer a la valeur suivante |
|
| 554 | - * |
|
| 555 | - * @return void |
|
| 556 | - */ |
|
| 557 | - public function next(): void { |
|
| 558 | - if ($this->valid()) { |
|
| 559 | - $this->cle = key($this->tableau); |
|
| 560 | - $this->valeur = current($this->tableau); |
|
| 561 | - next($this->tableau); |
|
| 562 | - } |
|
| 563 | - } |
|
| 564 | - |
|
| 565 | - /** |
|
| 566 | - * Compter le nombre total de resultats |
|
| 567 | - * |
|
| 568 | - * @return int |
|
| 569 | - */ |
|
| 570 | - public function count() { |
|
| 571 | - if (is_null($this->total)) { |
|
| 572 | - $this->total = count($this->tableau); |
|
| 573 | - } |
|
| 574 | - |
|
| 575 | - return $this->total; |
|
| 576 | - } |
|
| 490 | + } |
|
| 491 | + } |
|
| 492 | + } |
|
| 493 | + } |
|
| 494 | + |
|
| 495 | + if ($sortfunc) { |
|
| 496 | + $sortfunc .= "\n return 0;"; |
|
| 497 | + uasort($this->tableau, fn($aa, $bb) => eval($sortfunc)); |
|
| 498 | + } |
|
| 499 | + } |
|
| 500 | + |
|
| 501 | + |
|
| 502 | + /** |
|
| 503 | + * Grouper les resultats |
|
| 504 | + * {fusion /x/y/z} |
|
| 505 | + * |
|
| 506 | + **/ |
|
| 507 | + protected function select_groupby() { |
|
| 508 | + // virer le / initial pour les criteres de la forme {fusion /xx} |
|
| 509 | + if (strlen($fusion = ltrim($this->command['groupby'][0], '/'))) { |
|
| 510 | + $vu = []; |
|
| 511 | + foreach ($this->tableau as $k => $v) { |
|
| 512 | + $val = table_valeur($v, $fusion); |
|
| 513 | + if (isset($vu[$val])) { |
|
| 514 | + unset($this->tableau[$k]); |
|
| 515 | + } else { |
|
| 516 | + $vu[$val] = true; |
|
| 517 | + } |
|
| 518 | + } |
|
| 519 | + } |
|
| 520 | + } |
|
| 521 | + |
|
| 522 | + |
|
| 523 | + /** |
|
| 524 | + * L'iterateur est-il encore valide ? |
|
| 525 | + * |
|
| 526 | + * @return bool |
|
| 527 | + */ |
|
| 528 | + public function valid(): bool { |
|
| 529 | + return !is_null($this->cle); |
|
| 530 | + } |
|
| 531 | + |
|
| 532 | + /** |
|
| 533 | + * Retourner la valeur |
|
| 534 | + * |
|
| 535 | + * @return mixed |
|
| 536 | + */ |
|
| 537 | + #[\ReturnTypeWillChange] |
|
| 538 | + public function current() { |
|
| 539 | + return $this->valeur; |
|
| 540 | + } |
|
| 541 | + |
|
| 542 | + /** |
|
| 543 | + * Retourner la cle |
|
| 544 | + * |
|
| 545 | + * @return mixed |
|
| 546 | + */ |
|
| 547 | + #[\ReturnTypeWillChange] |
|
| 548 | + public function key() { |
|
| 549 | + return $this->cle; |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + /** |
|
| 553 | + * Passer a la valeur suivante |
|
| 554 | + * |
|
| 555 | + * @return void |
|
| 556 | + */ |
|
| 557 | + public function next(): void { |
|
| 558 | + if ($this->valid()) { |
|
| 559 | + $this->cle = key($this->tableau); |
|
| 560 | + $this->valeur = current($this->tableau); |
|
| 561 | + next($this->tableau); |
|
| 562 | + } |
|
| 563 | + } |
|
| 564 | + |
|
| 565 | + /** |
|
| 566 | + * Compter le nombre total de resultats |
|
| 567 | + * |
|
| 568 | + * @return int |
|
| 569 | + */ |
|
| 570 | + public function count() { |
|
| 571 | + if (is_null($this->total)) { |
|
| 572 | + $this->total = count($this->tableau); |
|
| 573 | + } |
|
| 574 | + |
|
| 575 | + return $this->total; |
|
| 576 | + } |
|
| 577 | 577 | } |
| 578 | 578 | |
| 579 | 579 | /* |
@@ -587,7 +587,7 @@ discard block |
||
| 587 | 587 | * @return array |
| 588 | 588 | */ |
| 589 | 589 | function inc_file_to_array_dist($data) { |
| 590 | - return preg_split('/\r?\n/', $data); |
|
| 590 | + return preg_split('/\r?\n/', $data); |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -596,9 +596,9 @@ discard block |
||
| 596 | 596 | * @return array |
| 597 | 597 | */ |
| 598 | 598 | function inc_plugins_to_array_dist() { |
| 599 | - include_spip('inc/plugin'); |
|
| 599 | + include_spip('inc/plugin'); |
|
| 600 | 600 | |
| 601 | - return liste_chemin_plugin_actifs(); |
|
| 601 | + return liste_chemin_plugin_actifs(); |
|
| 602 | 602 | } |
| 603 | 603 | |
| 604 | 604 | /** |
@@ -608,7 +608,7 @@ discard block |
||
| 608 | 608 | * @return array |
| 609 | 609 | */ |
| 610 | 610 | function inc_xml_to_array_dist($data) { |
| 611 | - return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 611 | + return @XMLObjectToArray(new SimpleXmlIterator($data)); |
|
| 612 | 612 | } |
| 613 | 613 | |
| 614 | 614 | /** |
@@ -620,14 +620,14 @@ discard block |
||
| 620 | 620 | * |
| 621 | 621 | */ |
| 622 | 622 | function inc_object_to_array($object) { |
| 623 | - if (!is_object($object) && !is_array($object)) { |
|
| 624 | - return $object; |
|
| 625 | - } |
|
| 626 | - if (is_object($object)) { |
|
| 627 | - $object = get_object_vars($object); |
|
| 628 | - } |
|
| 629 | - |
|
| 630 | - return array_map('inc_object_to_array', $object); |
|
| 623 | + if (!is_object($object) && !is_array($object)) { |
|
| 624 | + return $object; |
|
| 625 | + } |
|
| 626 | + if (is_object($object)) { |
|
| 627 | + $object = get_object_vars($object); |
|
| 628 | + } |
|
| 629 | + |
|
| 630 | + return array_map('inc_object_to_array', $object); |
|
| 631 | 631 | } |
| 632 | 632 | |
| 633 | 633 | /** |
@@ -637,20 +637,20 @@ discard block |
||
| 637 | 637 | * @return array|bool |
| 638 | 638 | */ |
| 639 | 639 | function inc_sql_to_array_dist($data) { |
| 640 | - # sortir le connecteur de $data |
|
| 641 | - preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | - $serveur = (string)$v[1]; |
|
| 643 | - $req = trim($v[2]); |
|
| 644 | - if ($s = sql_query($req, $serveur)) { |
|
| 645 | - $r = []; |
|
| 646 | - while ($t = sql_fetch($s)) { |
|
| 647 | - $r[] = $t; |
|
| 648 | - } |
|
| 649 | - |
|
| 650 | - return $r; |
|
| 651 | - } |
|
| 652 | - |
|
| 653 | - return false; |
|
| 640 | + # sortir le connecteur de $data |
|
| 641 | + preg_match(',^(?:(\w+):)?(.*)$,Sm', $data, $v); |
|
| 642 | + $serveur = (string)$v[1]; |
|
| 643 | + $req = trim($v[2]); |
|
| 644 | + if ($s = sql_query($req, $serveur)) { |
|
| 645 | + $r = []; |
|
| 646 | + while ($t = sql_fetch($s)) { |
|
| 647 | + $r[] = $t; |
|
| 648 | + } |
|
| 649 | + |
|
| 650 | + return $r; |
|
| 651 | + } |
|
| 652 | + |
|
| 653 | + return false; |
|
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | /** |
@@ -660,13 +660,13 @@ discard block |
||
| 660 | 660 | * @return array|bool |
| 661 | 661 | */ |
| 662 | 662 | function inc_json_to_array_dist($data) { |
| 663 | - try { |
|
| 664 | - $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | - } catch (JsonException $e) { |
|
| 666 | - $json = null; |
|
| 667 | - spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | - } |
|
| 669 | - return is_array($json) ? (array) $json : []; |
|
| 663 | + try { |
|
| 664 | + $json = json_decode($data, true, 512, JSON_THROW_ON_ERROR); |
|
| 665 | + } catch (JsonException $e) { |
|
| 666 | + $json = null; |
|
| 667 | + spip_log('Failed to parse Json data : ' . $e->getMessage(), _LOG_INFO); |
|
| 668 | + } |
|
| 669 | + return is_array($json) ? (array) $json : []; |
|
| 670 | 670 | } |
| 671 | 671 | |
| 672 | 672 | /** |
@@ -676,30 +676,30 @@ discard block |
||
| 676 | 676 | * @return array|bool |
| 677 | 677 | */ |
| 678 | 678 | function inc_csv_to_array_dist($data) { |
| 679 | - include_spip('inc/csv'); |
|
| 680 | - [$entete, $csv] = analyse_csv($data); |
|
| 681 | - array_unshift($csv, $entete); |
|
| 682 | - |
|
| 683 | - include_spip('inc/charsets'); |
|
| 684 | - $i = 1; |
|
| 685 | - foreach ($entete as $k => $v) { |
|
| 686 | - if (trim($v) == '') { |
|
| 687 | - $v = 'col' . $i; |
|
| 688 | - } // reperer des eventuelles cases vides |
|
| 689 | - if (is_numeric($v) and $v < 0) { |
|
| 690 | - $v = '__' . $v; |
|
| 691 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | - if (is_numeric($v)) { |
|
| 693 | - $v = '_' . $v; |
|
| 694 | - } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | - $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | - foreach ($csv as &$item) { |
|
| 697 | - $item[$v] = &$item[$k]; |
|
| 698 | - } |
|
| 699 | - $i++; |
|
| 700 | - } |
|
| 701 | - |
|
| 702 | - return $csv; |
|
| 679 | + include_spip('inc/csv'); |
|
| 680 | + [$entete, $csv] = analyse_csv($data); |
|
| 681 | + array_unshift($csv, $entete); |
|
| 682 | + |
|
| 683 | + include_spip('inc/charsets'); |
|
| 684 | + $i = 1; |
|
| 685 | + foreach ($entete as $k => $v) { |
|
| 686 | + if (trim($v) == '') { |
|
| 687 | + $v = 'col' . $i; |
|
| 688 | + } // reperer des eventuelles cases vides |
|
| 689 | + if (is_numeric($v) and $v < 0) { |
|
| 690 | + $v = '__' . $v; |
|
| 691 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 692 | + if (is_numeric($v)) { |
|
| 693 | + $v = '_' . $v; |
|
| 694 | + } // ne pas risquer d'ecraser une cle numerique |
|
| 695 | + $v = strtolower(preg_replace(',\W+,', '_', translitteration($v))); |
|
| 696 | + foreach ($csv as &$item) { |
|
| 697 | + $item[$v] = &$item[$k]; |
|
| 698 | + } |
|
| 699 | + $i++; |
|
| 700 | + } |
|
| 701 | + |
|
| 702 | + return $csv; |
|
| 703 | 703 | } |
| 704 | 704 | |
| 705 | 705 | /** |
@@ -709,13 +709,13 @@ discard block |
||
| 709 | 709 | * @return array|bool |
| 710 | 710 | */ |
| 711 | 711 | function inc_rss_to_array_dist($data) { |
| 712 | - $tableau = null; |
|
| 713 | - include_spip('inc/syndic'); |
|
| 714 | - if (is_array($rss = analyser_backend($data))) { |
|
| 715 | - $tableau = $rss; |
|
| 716 | - } |
|
| 712 | + $tableau = null; |
|
| 713 | + include_spip('inc/syndic'); |
|
| 714 | + if (is_array($rss = analyser_backend($data))) { |
|
| 715 | + $tableau = $rss; |
|
| 716 | + } |
|
| 717 | 717 | |
| 718 | - return $tableau; |
|
| 718 | + return $tableau; |
|
| 719 | 719 | } |
| 720 | 720 | |
| 721 | 721 | /** |
@@ -725,9 +725,9 @@ discard block |
||
| 725 | 725 | * @return array|bool |
| 726 | 726 | */ |
| 727 | 727 | function inc_atom_to_array_dist($data) { |
| 728 | - $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 728 | + $rss_to_array = charger_fonction('rss_to_array', 'inc'); |
|
| 729 | 729 | |
| 730 | - return $rss_to_array($data); |
|
| 730 | + return $rss_to_array($data); |
|
| 731 | 731 | } |
| 732 | 732 | |
| 733 | 733 | /** |
@@ -738,12 +738,12 @@ discard block |
||
| 738 | 738 | * @return array|bool |
| 739 | 739 | */ |
| 740 | 740 | function inc_glob_to_array_dist($data) { |
| 741 | - $a = glob( |
|
| 742 | - $data, |
|
| 743 | - GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | - ); |
|
| 741 | + $a = glob( |
|
| 742 | + $data, |
|
| 743 | + GLOB_MARK | GLOB_NOSORT | GLOB_BRACE |
|
| 744 | + ); |
|
| 745 | 745 | |
| 746 | - return $a ?: []; |
|
| 746 | + return $a ?: []; |
|
| 747 | 747 | } |
| 748 | 748 | |
| 749 | 749 | /** |
@@ -754,14 +754,14 @@ discard block |
||
| 754 | 754 | * @throws Exception |
| 755 | 755 | */ |
| 756 | 756 | function inc_yaml_to_array_dist($data) { |
| 757 | - include_spip('inc/yaml-mini'); |
|
| 758 | - if (!function_exists('yaml_decode')) { |
|
| 759 | - throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 757 | + include_spip('inc/yaml-mini'); |
|
| 758 | + if (!function_exists('yaml_decode')) { |
|
| 759 | + throw new Exception('YAML: impossible de trouver la fonction yaml_decode'); |
|
| 760 | 760 | |
| 761 | - return false; |
|
| 762 | - } |
|
| 761 | + return false; |
|
| 762 | + } |
|
| 763 | 763 | |
| 764 | - return yaml_decode($data); |
|
| 764 | + return yaml_decode($data); |
|
| 765 | 765 | } |
| 766 | 766 | |
| 767 | 767 | |
@@ -776,7 +776,7 @@ discard block |
||
| 776 | 776 | * @return array|bool |
| 777 | 777 | */ |
| 778 | 778 | function inc_pregfiles_to_array_dist($dir, $regexp = -1, $limit = 10000) { |
| 779 | - return (array)preg_files($dir, $regexp, $limit); |
|
| 779 | + return (array)preg_files($dir, $regexp, $limit); |
|
| 780 | 780 | } |
| 781 | 781 | |
| 782 | 782 | /** |
@@ -788,23 +788,23 @@ discard block |
||
| 788 | 788 | * @return array|bool |
| 789 | 789 | */ |
| 790 | 790 | function inc_ls_to_array_dist($data) { |
| 791 | - $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | - $a = $glob_to_array($data); |
|
| 793 | - foreach ($a as &$v) { |
|
| 794 | - $b = (array)@stat($v); |
|
| 795 | - foreach ($b as $k => $ignore) { |
|
| 796 | - if (is_numeric($k)) { |
|
| 797 | - unset($b[$k]); |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | - $v = array_merge( |
|
| 802 | - pathinfo($v), |
|
| 803 | - $b |
|
| 804 | - ); |
|
| 805 | - } |
|
| 806 | - |
|
| 807 | - return $a; |
|
| 791 | + $glob_to_array = charger_fonction('glob_to_array', 'inc'); |
|
| 792 | + $a = $glob_to_array($data); |
|
| 793 | + foreach ($a as &$v) { |
|
| 794 | + $b = (array)@stat($v); |
|
| 795 | + foreach ($b as $k => $ignore) { |
|
| 796 | + if (is_numeric($k)) { |
|
| 797 | + unset($b[$k]); |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + $b['file'] = preg_replace('`/$`', '', $v) ; |
|
| 801 | + $v = array_merge( |
|
| 802 | + pathinfo($v), |
|
| 803 | + $b |
|
| 804 | + ); |
|
| 805 | + } |
|
| 806 | + |
|
| 807 | + return $a; |
|
| 808 | 808 | } |
| 809 | 809 | |
| 810 | 810 | /** |
@@ -814,25 +814,25 @@ discard block |
||
| 814 | 814 | * @return array|bool |
| 815 | 815 | */ |
| 816 | 816 | function XMLObjectToArray($object) { |
| 817 | - $xml_array = []; |
|
| 818 | - for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | - if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | - $key .= '-' . uniqid(); |
|
| 821 | - } |
|
| 822 | - $vars = get_object_vars($object->current()); |
|
| 823 | - if (isset($vars['@attributes'])) { |
|
| 824 | - foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | - $xml_array[$key][$k] = $v; |
|
| 826 | - } |
|
| 827 | - } |
|
| 828 | - if ($object->hasChildren()) { |
|
| 829 | - $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | - $object->current() |
|
| 831 | - ); |
|
| 832 | - } else { |
|
| 833 | - $xml_array[$key][] = strval($object->current()); |
|
| 834 | - } |
|
| 835 | - } |
|
| 836 | - |
|
| 837 | - return $xml_array; |
|
| 817 | + $xml_array = []; |
|
| 818 | + for ($object->rewind(); $object->valid(); $object->next()) { |
|
| 819 | + if (array_key_exists($key = $object->key(), $xml_array)) { |
|
| 820 | + $key .= '-' . uniqid(); |
|
| 821 | + } |
|
| 822 | + $vars = get_object_vars($object->current()); |
|
| 823 | + if (isset($vars['@attributes'])) { |
|
| 824 | + foreach ($vars['@attributes'] as $k => $v) { |
|
| 825 | + $xml_array[$key][$k] = $v; |
|
| 826 | + } |
|
| 827 | + } |
|
| 828 | + if ($object->hasChildren()) { |
|
| 829 | + $xml_array[$key][] = XMLObjectToArray( |
|
| 830 | + $object->current() |
|
| 831 | + ); |
|
| 832 | + } else { |
|
| 833 | + $xml_array[$key][] = strval($object->current()); |
|
| 834 | + } |
|
| 835 | + } |
|
| 836 | + |
|
| 837 | + return $xml_array; |
|
| 838 | 838 | } |
@@ -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 | |
@@ -27,215 +27,215 @@ discard block |
||
| 27 | 27 | * Permet d'itérer sur des données en base de données |
| 28 | 28 | */ |
| 29 | 29 | class IterateurSQL implements Iterator { |
| 30 | - /** |
|
| 31 | - * Ressource sql |
|
| 32 | - * |
|
| 33 | - * @var Object|bool |
|
| 34 | - */ |
|
| 35 | - protected $sqlresult = false; |
|
| 36 | - |
|
| 37 | - /** |
|
| 38 | - * row sql courante |
|
| 39 | - * |
|
| 40 | - * @var array|null |
|
| 41 | - */ |
|
| 42 | - protected $row = null; |
|
| 43 | - |
|
| 44 | - protected bool $firstseek = false; |
|
| 45 | - |
|
| 46 | - protected int $pos = -1; |
|
| 47 | - |
|
| 48 | - protected string $type = 'SQL'; |
|
| 49 | - |
|
| 50 | - protected array $command = []; |
|
| 51 | - |
|
| 52 | - protected array $info = []; |
|
| 53 | - |
|
| 54 | - |
|
| 55 | - /** Erreur presente ? **/ |
|
| 56 | - public bool $err = false; |
|
| 57 | - |
|
| 58 | - /** |
|
| 59 | - * Calcul du total des elements |
|
| 60 | - * |
|
| 61 | - * @var int|null |
|
| 62 | - **/ |
|
| 63 | - public $total = null; |
|
| 64 | - |
|
| 65 | - /** |
|
| 66 | - * selectionner les donnees, ie faire la requete SQL |
|
| 67 | - * |
|
| 68 | - * @return void |
|
| 69 | - */ |
|
| 70 | - protected function select() { |
|
| 71 | - $this->row = null; |
|
| 72 | - $v = &$this->command; |
|
| 73 | - $this->sqlresult = calculer_select( |
|
| 74 | - $v['select'], |
|
| 75 | - $v['from'], |
|
| 76 | - $v['type'], |
|
| 77 | - $v['where'], |
|
| 78 | - $v['join'], |
|
| 79 | - $v['groupby'], |
|
| 80 | - $v['orderby'], |
|
| 81 | - $v['limit'], |
|
| 82 | - $v['having'], |
|
| 83 | - $v['table'], |
|
| 84 | - $v['id'], |
|
| 85 | - $v['connect'], |
|
| 86 | - $this->info |
|
| 87 | - ); |
|
| 88 | - $this->err = !$this->sqlresult; |
|
| 89 | - $this->firstseek = false; |
|
| 90 | - $this->pos = -1; |
|
| 91 | - |
|
| 92 | - // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | - //$this->total = $this->count(); |
|
| 94 | - } |
|
| 95 | - |
|
| 96 | - /* |
|
| 30 | + /** |
|
| 31 | + * Ressource sql |
|
| 32 | + * |
|
| 33 | + * @var Object|bool |
|
| 34 | + */ |
|
| 35 | + protected $sqlresult = false; |
|
| 36 | + |
|
| 37 | + /** |
|
| 38 | + * row sql courante |
|
| 39 | + * |
|
| 40 | + * @var array|null |
|
| 41 | + */ |
|
| 42 | + protected $row = null; |
|
| 43 | + |
|
| 44 | + protected bool $firstseek = false; |
|
| 45 | + |
|
| 46 | + protected int $pos = -1; |
|
| 47 | + |
|
| 48 | + protected string $type = 'SQL'; |
|
| 49 | + |
|
| 50 | + protected array $command = []; |
|
| 51 | + |
|
| 52 | + protected array $info = []; |
|
| 53 | + |
|
| 54 | + |
|
| 55 | + /** Erreur presente ? **/ |
|
| 56 | + public bool $err = false; |
|
| 57 | + |
|
| 58 | + /** |
|
| 59 | + * Calcul du total des elements |
|
| 60 | + * |
|
| 61 | + * @var int|null |
|
| 62 | + **/ |
|
| 63 | + public $total = null; |
|
| 64 | + |
|
| 65 | + /** |
|
| 66 | + * selectionner les donnees, ie faire la requete SQL |
|
| 67 | + * |
|
| 68 | + * @return void |
|
| 69 | + */ |
|
| 70 | + protected function select() { |
|
| 71 | + $this->row = null; |
|
| 72 | + $v = &$this->command; |
|
| 73 | + $this->sqlresult = calculer_select( |
|
| 74 | + $v['select'], |
|
| 75 | + $v['from'], |
|
| 76 | + $v['type'], |
|
| 77 | + $v['where'], |
|
| 78 | + $v['join'], |
|
| 79 | + $v['groupby'], |
|
| 80 | + $v['orderby'], |
|
| 81 | + $v['limit'], |
|
| 82 | + $v['having'], |
|
| 83 | + $v['table'], |
|
| 84 | + $v['id'], |
|
| 85 | + $v['connect'], |
|
| 86 | + $this->info |
|
| 87 | + ); |
|
| 88 | + $this->err = !$this->sqlresult; |
|
| 89 | + $this->firstseek = false; |
|
| 90 | + $this->pos = -1; |
|
| 91 | + |
|
| 92 | + // pas d'init a priori, le calcul ne sera fait qu'en cas de besoin (provoque une double requete souvent inutile en sqlite) |
|
| 93 | + //$this->total = $this->count(); |
|
| 94 | + } |
|
| 95 | + |
|
| 96 | + /* |
|
| 97 | 97 | * array command: les commandes d'initialisation |
| 98 | 98 | * array info: les infos sur le squelette |
| 99 | 99 | */ |
| 100 | - public function __construct($command, $info = []) { |
|
| 101 | - $this->type = 'SQL'; |
|
| 102 | - $this->command = $command; |
|
| 103 | - $this->info = $info; |
|
| 104 | - $this->select(); |
|
| 105 | - } |
|
| 106 | - |
|
| 107 | - /** |
|
| 108 | - * Rembobiner |
|
| 109 | - * |
|
| 110 | - * @return bool |
|
| 111 | - */ |
|
| 112 | - public function rewind(): void { |
|
| 113 | - if ($this->pos > 0) { |
|
| 114 | - $this->seek(0); |
|
| 115 | - } |
|
| 116 | - } |
|
| 117 | - |
|
| 118 | - /** |
|
| 119 | - * Verifier l'etat de l'iterateur |
|
| 120 | - * |
|
| 121 | - * @return bool |
|
| 122 | - */ |
|
| 123 | - public function valid(): bool { |
|
| 124 | - if ($this->err) { |
|
| 125 | - return false; |
|
| 126 | - } |
|
| 127 | - if (!$this->firstseek) { |
|
| 128 | - $this->next(); |
|
| 129 | - } |
|
| 130 | - |
|
| 131 | - return is_array($this->row); |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - /** |
|
| 135 | - * Valeurs sur la position courante |
|
| 136 | - * |
|
| 137 | - * @return array |
|
| 138 | - */ |
|
| 139 | - #[\ReturnTypeWillChange] |
|
| 140 | - public function current() { |
|
| 141 | - return $this->row; |
|
| 142 | - } |
|
| 143 | - |
|
| 144 | - #[\ReturnTypeWillChange] |
|
| 145 | - public function key() { |
|
| 146 | - return $this->pos; |
|
| 147 | - } |
|
| 148 | - |
|
| 149 | - /** |
|
| 150 | - * Sauter a une position absolue |
|
| 151 | - * |
|
| 152 | - * @param int $n |
|
| 153 | - * @param null|string $continue |
|
| 154 | - * @return bool |
|
| 155 | - */ |
|
| 156 | - public function seek($n = 0, $continue = null) { |
|
| 157 | - if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | - // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | - // si la position courante est apres la position visee |
|
| 160 | - // il faut relancer la requete |
|
| 161 | - if ($this->pos > $n) { |
|
| 162 | - $this->free(); |
|
| 163 | - $this->select(); |
|
| 164 | - $this->valid(); |
|
| 165 | - } |
|
| 166 | - // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | - // (sera fait en cas d'echec de cette fonction) |
|
| 168 | - return false; |
|
| 169 | - } |
|
| 170 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | - $this->pos = min($n, $this->count()); |
|
| 172 | - |
|
| 173 | - return true; |
|
| 174 | - } |
|
| 175 | - |
|
| 176 | - /** |
|
| 177 | - * Avancer d'un cran |
|
| 178 | - * |
|
| 179 | - * @return void |
|
| 180 | - */ |
|
| 181 | - public function next(): void { |
|
| 182 | - $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | - $this->pos++; |
|
| 184 | - $this->firstseek |= true; |
|
| 185 | - } |
|
| 186 | - |
|
| 187 | - /** |
|
| 188 | - * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | - * |
|
| 190 | - * @return array|bool|null |
|
| 191 | - */ |
|
| 192 | - public function fetch() { |
|
| 193 | - if ($this->valid()) { |
|
| 194 | - $r = $this->current(); |
|
| 195 | - $this->next(); |
|
| 196 | - } else { |
|
| 197 | - $r = false; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $r; |
|
| 201 | - } |
|
| 202 | - |
|
| 203 | - /** |
|
| 204 | - * liberer les ressources |
|
| 205 | - * |
|
| 206 | - * @return bool |
|
| 207 | - */ |
|
| 208 | - public function free() { |
|
| 209 | - if (!$this->sqlresult) { |
|
| 210 | - return true; |
|
| 211 | - } |
|
| 212 | - $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | - $this->sqlresult = null; |
|
| 214 | - |
|
| 215 | - return $a; |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Compter le nombre de resultats |
|
| 220 | - * |
|
| 221 | - * @return int |
|
| 222 | - */ |
|
| 223 | - public function count() { |
|
| 224 | - if (is_null($this->total)) { |
|
| 225 | - if (!$this->sqlresult) { |
|
| 226 | - $this->total = 0; |
|
| 227 | - } else { |
|
| 228 | - # cas count(*) |
|
| 229 | - if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | - $this->valid(); |
|
| 231 | - $s = $this->current(); |
|
| 232 | - $this->total = $s['count(*)']; |
|
| 233 | - } else { |
|
| 234 | - $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | - } |
|
| 236 | - } |
|
| 237 | - } |
|
| 238 | - |
|
| 239 | - return $this->total; |
|
| 240 | - } |
|
| 100 | + public function __construct($command, $info = []) { |
|
| 101 | + $this->type = 'SQL'; |
|
| 102 | + $this->command = $command; |
|
| 103 | + $this->info = $info; |
|
| 104 | + $this->select(); |
|
| 105 | + } |
|
| 106 | + |
|
| 107 | + /** |
|
| 108 | + * Rembobiner |
|
| 109 | + * |
|
| 110 | + * @return bool |
|
| 111 | + */ |
|
| 112 | + public function rewind(): void { |
|
| 113 | + if ($this->pos > 0) { |
|
| 114 | + $this->seek(0); |
|
| 115 | + } |
|
| 116 | + } |
|
| 117 | + |
|
| 118 | + /** |
|
| 119 | + * Verifier l'etat de l'iterateur |
|
| 120 | + * |
|
| 121 | + * @return bool |
|
| 122 | + */ |
|
| 123 | + public function valid(): bool { |
|
| 124 | + if ($this->err) { |
|
| 125 | + return false; |
|
| 126 | + } |
|
| 127 | + if (!$this->firstseek) { |
|
| 128 | + $this->next(); |
|
| 129 | + } |
|
| 130 | + |
|
| 131 | + return is_array($this->row); |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + /** |
|
| 135 | + * Valeurs sur la position courante |
|
| 136 | + * |
|
| 137 | + * @return array |
|
| 138 | + */ |
|
| 139 | + #[\ReturnTypeWillChange] |
|
| 140 | + public function current() { |
|
| 141 | + return $this->row; |
|
| 142 | + } |
|
| 143 | + |
|
| 144 | + #[\ReturnTypeWillChange] |
|
| 145 | + public function key() { |
|
| 146 | + return $this->pos; |
|
| 147 | + } |
|
| 148 | + |
|
| 149 | + /** |
|
| 150 | + * Sauter a une position absolue |
|
| 151 | + * |
|
| 152 | + * @param int $n |
|
| 153 | + * @param null|string $continue |
|
| 154 | + * @return bool |
|
| 155 | + */ |
|
| 156 | + public function seek($n = 0, $continue = null) { |
|
| 157 | + if (!sql_seek($this->sqlresult, $n, $this->command['connect'], $continue)) { |
|
| 158 | + // SQLite ne sait pas seek(), il faut relancer la query |
|
| 159 | + // si la position courante est apres la position visee |
|
| 160 | + // il faut relancer la requete |
|
| 161 | + if ($this->pos > $n) { |
|
| 162 | + $this->free(); |
|
| 163 | + $this->select(); |
|
| 164 | + $this->valid(); |
|
| 165 | + } |
|
| 166 | + // et utiliser la methode par defaut pour se deplacer au bon endroit |
|
| 167 | + // (sera fait en cas d'echec de cette fonction) |
|
| 168 | + return false; |
|
| 169 | + } |
|
| 170 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 171 | + $this->pos = min($n, $this->count()); |
|
| 172 | + |
|
| 173 | + return true; |
|
| 174 | + } |
|
| 175 | + |
|
| 176 | + /** |
|
| 177 | + * Avancer d'un cran |
|
| 178 | + * |
|
| 179 | + * @return void |
|
| 180 | + */ |
|
| 181 | + public function next(): void { |
|
| 182 | + $this->row = sql_fetch($this->sqlresult, $this->command['connect']); |
|
| 183 | + $this->pos++; |
|
| 184 | + $this->firstseek |= true; |
|
| 185 | + } |
|
| 186 | + |
|
| 187 | + /** |
|
| 188 | + * Avancer et retourner les donnees pour le nouvel element |
|
| 189 | + * |
|
| 190 | + * @return array|bool|null |
|
| 191 | + */ |
|
| 192 | + public function fetch() { |
|
| 193 | + if ($this->valid()) { |
|
| 194 | + $r = $this->current(); |
|
| 195 | + $this->next(); |
|
| 196 | + } else { |
|
| 197 | + $r = false; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $r; |
|
| 201 | + } |
|
| 202 | + |
|
| 203 | + /** |
|
| 204 | + * liberer les ressources |
|
| 205 | + * |
|
| 206 | + * @return bool |
|
| 207 | + */ |
|
| 208 | + public function free() { |
|
| 209 | + if (!$this->sqlresult) { |
|
| 210 | + return true; |
|
| 211 | + } |
|
| 212 | + $a = sql_free($this->sqlresult, $this->command['connect']); |
|
| 213 | + $this->sqlresult = null; |
|
| 214 | + |
|
| 215 | + return $a; |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Compter le nombre de resultats |
|
| 220 | + * |
|
| 221 | + * @return int |
|
| 222 | + */ |
|
| 223 | + public function count() { |
|
| 224 | + if (is_null($this->total)) { |
|
| 225 | + if (!$this->sqlresult) { |
|
| 226 | + $this->total = 0; |
|
| 227 | + } else { |
|
| 228 | + # cas count(*) |
|
| 229 | + if (in_array('count(*)', $this->command['select'])) { |
|
| 230 | + $this->valid(); |
|
| 231 | + $s = $this->current(); |
|
| 232 | + $this->total = $s['count(*)']; |
|
| 233 | + } else { |
|
| 234 | + $this->total = sql_count($this->sqlresult, $this->command['connect']); |
|
| 235 | + } |
|
| 236 | + } |
|
| 237 | + } |
|
| 238 | + |
|
| 239 | + return $this->total; |
|
| 240 | + } |
|
| 241 | 241 | } |
@@ -26,7 +26,7 @@ discard block |
||
| 26 | 26 | **/ |
| 27 | 27 | |
| 28 | 28 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 29 | - return; |
|
| 29 | + return; |
|
| 30 | 30 | } |
| 31 | 31 | |
| 32 | 32 | /** |
@@ -48,16 +48,16 @@ discard block |
||
| 48 | 48 | * Code PHP si cet argument est présent, sinon null |
| 49 | 49 | **/ |
| 50 | 50 | function interprete_argument_balise(int $n, Champ $p): ?string { |
| 51 | - if (($p->param) && (!$p->param[0][0]) && ((is_countable($p->param[0]) ? count($p->param[0]) : 0) > $n)) { |
|
| 52 | - return calculer_liste( |
|
| 53 | - $p->param[0][$n], |
|
| 54 | - $p->descr, |
|
| 55 | - $p->boucles, |
|
| 56 | - $p->id_boucle |
|
| 57 | - ); |
|
| 58 | - } else { |
|
| 59 | - return null; |
|
| 60 | - } |
|
| 51 | + if (($p->param) && (!$p->param[0][0]) && ((is_countable($p->param[0]) ? count($p->param[0]) : 0) > $n)) { |
|
| 52 | + return calculer_liste( |
|
| 53 | + $p->param[0][$n], |
|
| 54 | + $p->descr, |
|
| 55 | + $p->boucles, |
|
| 56 | + $p->id_boucle |
|
| 57 | + ); |
|
| 58 | + } else { |
|
| 59 | + return null; |
|
| 60 | + } |
|
| 61 | 61 | } |
| 62 | 62 | |
| 63 | 63 | |
@@ -77,10 +77,10 @@ discard block |
||
| 77 | 77 | * Pile complétée par le code à générer |
| 78 | 78 | **/ |
| 79 | 79 | function balise_NOM_SITE_SPIP_dist($p) { |
| 80 | - $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 80 | + $p->code = "\$GLOBALS['meta']['nom_site']"; |
|
| 81 | 81 | |
| 82 | - #$p->interdire_scripts = true; |
|
| 83 | - return $p; |
|
| 82 | + #$p->interdire_scripts = true; |
|
| 83 | + return $p; |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | /** |
@@ -96,10 +96,10 @@ discard block |
||
| 96 | 96 | * Pile complétée par le code à générer |
| 97 | 97 | **/ |
| 98 | 98 | function balise_EMAIL_WEBMASTER_dist($p) { |
| 99 | - $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 99 | + $p->code = "\$GLOBALS['meta']['email_webmaster']"; |
|
| 100 | 100 | |
| 101 | - #$p->interdire_scripts = true; |
|
| 102 | - return $p; |
|
| 101 | + #$p->interdire_scripts = true; |
|
| 102 | + return $p; |
|
| 103 | 103 | } |
| 104 | 104 | |
| 105 | 105 | /** |
@@ -115,10 +115,10 @@ discard block |
||
| 115 | 115 | * Pile complétée par le code à générer |
| 116 | 116 | **/ |
| 117 | 117 | function balise_DESCRIPTIF_SITE_SPIP_dist($p) { |
| 118 | - $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 118 | + $p->code = "\$GLOBALS['meta']['descriptif_site']"; |
|
| 119 | 119 | |
| 120 | - #$p->interdire_scripts = true; |
|
| 121 | - return $p; |
|
| 120 | + #$p->interdire_scripts = true; |
|
| 121 | + return $p; |
|
| 122 | 122 | } |
| 123 | 123 | |
| 124 | 124 | |
@@ -139,10 +139,10 @@ discard block |
||
| 139 | 139 | * Pile complétée par le code à générer |
| 140 | 140 | **/ |
| 141 | 141 | function balise_CHARSET_dist($p) { |
| 142 | - $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 142 | + $p->code = "\$GLOBALS['meta']['charset']"; |
|
| 143 | 143 | |
| 144 | - #$p->interdire_scripts = true; |
|
| 145 | - return $p; |
|
| 144 | + #$p->interdire_scripts = true; |
|
| 145 | + return $p; |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | /** |
@@ -167,11 +167,11 @@ discard block |
||
| 167 | 167 | * Pile complétée par le code à générer |
| 168 | 168 | **/ |
| 169 | 169 | function balise_LANG_LEFT_dist($p) { |
| 170 | - $_lang = champ_sql('lang', $p); |
|
| 171 | - $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | - $p->interdire_scripts = false; |
|
| 170 | + $_lang = champ_sql('lang', $p); |
|
| 171 | + $p->code = "lang_dir($_lang, 'left','right')"; |
|
| 172 | + $p->interdire_scripts = false; |
|
| 173 | 173 | |
| 174 | - return $p; |
|
| 174 | + return $p; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | /** |
@@ -191,11 +191,11 @@ discard block |
||
| 191 | 191 | * Pile complétée par le code à générer |
| 192 | 192 | **/ |
| 193 | 193 | function balise_LANG_RIGHT_dist($p) { |
| 194 | - $_lang = champ_sql('lang', $p); |
|
| 195 | - $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | - $p->interdire_scripts = false; |
|
| 194 | + $_lang = champ_sql('lang', $p); |
|
| 195 | + $p->code = "lang_dir($_lang, 'right','left')"; |
|
| 196 | + $p->interdire_scripts = false; |
|
| 197 | 197 | |
| 198 | - return $p; |
|
| 198 | + return $p; |
|
| 199 | 199 | } |
| 200 | 200 | |
| 201 | 201 | /** |
@@ -220,11 +220,11 @@ discard block |
||
| 220 | 220 | * Pile complétée par le code à générer |
| 221 | 221 | **/ |
| 222 | 222 | function balise_LANG_DIR_dist($p) { |
| 223 | - $_lang = champ_sql('lang', $p); |
|
| 224 | - $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | - $p->interdire_scripts = false; |
|
| 223 | + $_lang = champ_sql('lang', $p); |
|
| 224 | + $p->code = "lang_dir($_lang, 'ltr','rtl')"; |
|
| 225 | + $p->interdire_scripts = false; |
|
| 226 | 226 | |
| 227 | - return $p; |
|
| 227 | + return $p; |
|
| 228 | 228 | } |
| 229 | 229 | |
| 230 | 230 | |
@@ -241,10 +241,10 @@ discard block |
||
| 241 | 241 | * Pile complétée par le code à générer |
| 242 | 242 | **/ |
| 243 | 243 | function balise_PUCE_dist($p) { |
| 244 | - $p->code = 'definir_puce()'; |
|
| 245 | - $p->interdire_scripts = false; |
|
| 244 | + $p->code = 'definir_puce()'; |
|
| 245 | + $p->interdire_scripts = false; |
|
| 246 | 246 | |
| 247 | - return $p; |
|
| 247 | + return $p; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -268,9 +268,9 @@ discard block |
||
| 268 | 268 | * Pile completée du code PHP d'exécution de la balise |
| 269 | 269 | */ |
| 270 | 270 | function balise_DATE_dist($p) { |
| 271 | - $p->code = champ_sql('date', $p); |
|
| 271 | + $p->code = champ_sql('date', $p); |
|
| 272 | 272 | |
| 273 | - return $p; |
|
| 273 | + return $p; |
|
| 274 | 274 | } |
| 275 | 275 | |
| 276 | 276 | |
@@ -290,10 +290,10 @@ discard block |
||
| 290 | 290 | * Pile completée du code PHP d'exécution de la balise |
| 291 | 291 | */ |
| 292 | 292 | function balise_DATE_REDAC_dist($p) { |
| 293 | - $p->code = champ_sql('date_redac', $p); |
|
| 294 | - $p->interdire_scripts = false; |
|
| 293 | + $p->code = champ_sql('date_redac', $p); |
|
| 294 | + $p->interdire_scripts = false; |
|
| 295 | 295 | |
| 296 | - return $p; |
|
| 296 | + return $p; |
|
| 297 | 297 | } |
| 298 | 298 | |
| 299 | 299 | /** |
@@ -312,10 +312,10 @@ discard block |
||
| 312 | 312 | * Pile completée du code PHP d'exécution de la balise |
| 313 | 313 | */ |
| 314 | 314 | function balise_DATE_MODIF_dist($p) { |
| 315 | - $p->code = champ_sql('date_modif', $p); |
|
| 316 | - $p->interdire_scripts = false; |
|
| 315 | + $p->code = champ_sql('date_modif', $p); |
|
| 316 | + $p->interdire_scripts = false; |
|
| 317 | 317 | |
| 318 | - return $p; |
|
| 318 | + return $p; |
|
| 319 | 319 | } |
| 320 | 320 | |
| 321 | 321 | /** |
@@ -333,13 +333,13 @@ discard block |
||
| 333 | 333 | * Pile completée du code PHP d'exécution de la balise |
| 334 | 334 | */ |
| 335 | 335 | function balise_DATE_NOUVEAUTES_dist($p) { |
| 336 | - $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 336 | + $p->code = "((\$GLOBALS['meta']['quoi_de_neuf'] == 'oui' |
|
| 337 | 337 | AND isset(\$GLOBALS['meta']['dernier_envoi_neuf'])) ? |
| 338 | 338 | \$GLOBALS['meta']['dernier_envoi_neuf'] : |
| 339 | 339 | \"'0000-00-00'\")"; |
| 340 | - $p->interdire_scripts = false; |
|
| 340 | + $p->interdire_scripts = false; |
|
| 341 | 341 | |
| 342 | - return $p; |
|
| 342 | + return $p; |
|
| 343 | 343 | } |
| 344 | 344 | |
| 345 | 345 | |
@@ -357,11 +357,11 @@ discard block |
||
| 357 | 357 | * Pile completée du code PHP d'exécution de la balise |
| 358 | 358 | */ |
| 359 | 359 | function balise_DOSSIER_SQUELETTE_dist($p) { |
| 360 | - $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | - $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | - $p->interdire_scripts = false; |
|
| 360 | + $code = substr(addslashes(dirname($p->descr['sourcefile'])), strlen(_DIR_RACINE)); |
|
| 361 | + $p->code = "_DIR_RACINE . '$code'" . |
|
| 362 | + $p->interdire_scripts = false; |
|
| 363 | 363 | |
| 364 | - return $p; |
|
| 364 | + return $p; |
|
| 365 | 365 | } |
| 366 | 366 | |
| 367 | 367 | /** |
@@ -376,11 +376,11 @@ discard block |
||
| 376 | 376 | * Pile completée du code PHP d'exécution de la balise |
| 377 | 377 | */ |
| 378 | 378 | function balise_SQUELETTE_dist($p) { |
| 379 | - $code = addslashes($p->descr['sourcefile']); |
|
| 380 | - $p->code = "'$code'" . |
|
| 381 | - $p->interdire_scripts = false; |
|
| 379 | + $code = addslashes($p->descr['sourcefile']); |
|
| 380 | + $p->code = "'$code'" . |
|
| 381 | + $p->interdire_scripts = false; |
|
| 382 | 382 | |
| 383 | - return $p; |
|
| 383 | + return $p; |
|
| 384 | 384 | } |
| 385 | 385 | |
| 386 | 386 | /** |
@@ -399,10 +399,10 @@ discard block |
||
| 399 | 399 | * Pile completée du code PHP d'exécution de la balise |
| 400 | 400 | */ |
| 401 | 401 | function balise_SPIP_VERSION_dist($p) { |
| 402 | - $p->code = 'spip_version()'; |
|
| 403 | - $p->interdire_scripts = false; |
|
| 402 | + $p->code = 'spip_version()'; |
|
| 403 | + $p->interdire_scripts = false; |
|
| 404 | 404 | |
| 405 | - return $p; |
|
| 405 | + return $p; |
|
| 406 | 406 | } |
| 407 | 407 | |
| 408 | 408 | |
@@ -428,18 +428,18 @@ discard block |
||
| 428 | 428 | * Pile complétée par le code à générer |
| 429 | 429 | **/ |
| 430 | 430 | function balise_NOM_SITE_dist($p) { |
| 431 | - if (!$p->etoile) { |
|
| 432 | - $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | - champ_sql('url_site', $p) . ',' . |
|
| 434 | - champ_sql('nom_site', $p) . |
|
| 435 | - ", 'titre', \$connect, false))"; |
|
| 436 | - } else { |
|
| 437 | - $p->code = champ_sql('nom_site', $p); |
|
| 438 | - } |
|
| 431 | + if (!$p->etoile) { |
|
| 432 | + $p->code = 'supprimer_numero(calculer_url(' . |
|
| 433 | + champ_sql('url_site', $p) . ',' . |
|
| 434 | + champ_sql('nom_site', $p) . |
|
| 435 | + ", 'titre', \$connect, false))"; |
|
| 436 | + } else { |
|
| 437 | + $p->code = champ_sql('nom_site', $p); |
|
| 438 | + } |
|
| 439 | 439 | |
| 440 | - $p->interdire_scripts = true; |
|
| 440 | + $p->interdire_scripts = true; |
|
| 441 | 441 | |
| 442 | - return $p; |
|
| 442 | + return $p; |
|
| 443 | 443 | } |
| 444 | 444 | |
| 445 | 445 | |
@@ -456,11 +456,11 @@ discard block |
||
| 456 | 456 | * Pile complétée par le code à générer |
| 457 | 457 | **/ |
| 458 | 458 | function balise_NOTES_dist($p) { |
| 459 | - // Recuperer les notes |
|
| 460 | - $p->code = 'calculer_notes()'; |
|
| 459 | + // Recuperer les notes |
|
| 460 | + $p->code = 'calculer_notes()'; |
|
| 461 | 461 | |
| 462 | - #$p->interdire_scripts = true; |
|
| 463 | - return $p; |
|
| 462 | + #$p->interdire_scripts = true; |
|
| 463 | + return $p; |
|
| 464 | 464 | } |
| 465 | 465 | |
| 466 | 466 | |
@@ -482,10 +482,10 @@ discard block |
||
| 482 | 482 | * Pile complétée par le code à générer |
| 483 | 483 | **/ |
| 484 | 484 | function balise_RECHERCHE_dist($p) { |
| 485 | - $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | - $p->interdire_scripts = false; |
|
| 485 | + $p->code = 'entites_html(_request("recherche"))'; |
|
| 486 | + $p->interdire_scripts = false; |
|
| 487 | 487 | |
| 488 | - return $p; |
|
| 488 | + return $p; |
|
| 489 | 489 | } |
| 490 | 490 | |
| 491 | 491 | |
@@ -503,17 +503,17 @@ discard block |
||
| 503 | 503 | * Pile complétée par le code à générer |
| 504 | 504 | **/ |
| 505 | 505 | function balise_COMPTEUR_BOUCLE_dist($p) { |
| 506 | - $b = index_boucle_mere($p); |
|
| 507 | - if ($b === '') { |
|
| 508 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | - erreur_squelette($msg, $p); |
|
| 510 | - } else { |
|
| 511 | - $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | - $p->boucles[$b]->cptrows = true; |
|
| 513 | - $p->interdire_scripts = false; |
|
| 506 | + $b = index_boucle_mere($p); |
|
| 507 | + if ($b === '') { |
|
| 508 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 509 | + erreur_squelette($msg, $p); |
|
| 510 | + } else { |
|
| 511 | + $p->code = "(\$Numrows['$b']['compteur_boucle'] ?? 0)"; |
|
| 512 | + $p->boucles[$b]->cptrows = true; |
|
| 513 | + $p->interdire_scripts = false; |
|
| 514 | 514 | |
| 515 | - return $p; |
|
| 516 | - } |
|
| 515 | + return $p; |
|
| 516 | + } |
|
| 517 | 517 | } |
| 518 | 518 | |
| 519 | 519 | /** |
@@ -531,17 +531,17 @@ discard block |
||
| 531 | 531 | * Pile complétée par le code à générer |
| 532 | 532 | **/ |
| 533 | 533 | function balise_TOTAL_BOUCLE_dist($p) { |
| 534 | - $b = index_boucle_mere($p); |
|
| 535 | - if ($b === '') { |
|
| 536 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | - erreur_squelette($msg, $p); |
|
| 538 | - } else { |
|
| 539 | - $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | - $p->boucles[$b]->numrows = true; |
|
| 541 | - $p->interdire_scripts = false; |
|
| 542 | - } |
|
| 534 | + $b = index_boucle_mere($p); |
|
| 535 | + if ($b === '') { |
|
| 536 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 537 | + erreur_squelette($msg, $p); |
|
| 538 | + } else { |
|
| 539 | + $p->code = "(\$Numrows['$b']['total'] ?? 0)"; |
|
| 540 | + $p->boucles[$b]->numrows = true; |
|
| 541 | + $p->interdire_scripts = false; |
|
| 542 | + } |
|
| 543 | 543 | |
| 544 | - return $p; |
|
| 544 | + return $p; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -561,7 +561,7 @@ discard block |
||
| 561 | 561 | * Pile complétée par le code à générer |
| 562 | 562 | **/ |
| 563 | 563 | function balise_POINTS_dist($p) { |
| 564 | - return rindex_pile($p, 'points', 'recherche'); |
|
| 564 | + return rindex_pile($p, 'points', 'recherche'); |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -582,12 +582,12 @@ discard block |
||
| 582 | 582 | * Pile complétée par le code à générer |
| 583 | 583 | **/ |
| 584 | 584 | function balise_POPULARITE_ABSOLUE_dist($p) { |
| 585 | - $p->code = 'ceil(' . |
|
| 586 | - champ_sql('popularite', $p) . |
|
| 587 | - ')'; |
|
| 588 | - $p->interdire_scripts = false; |
|
| 585 | + $p->code = 'ceil(' . |
|
| 586 | + champ_sql('popularite', $p) . |
|
| 587 | + ')'; |
|
| 588 | + $p->interdire_scripts = false; |
|
| 589 | 589 | |
| 590 | - return $p; |
|
| 590 | + return $p; |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,10 +607,10 @@ discard block |
||
| 607 | 607 | * Pile complétée par le code à générer |
| 608 | 608 | **/ |
| 609 | 609 | function balise_POPULARITE_SITE_dist($p) { |
| 610 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | - $p->interdire_scripts = false; |
|
| 610 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_total\'])'; |
|
| 611 | + $p->interdire_scripts = false; |
|
| 612 | 612 | |
| 613 | - return $p; |
|
| 613 | + return $p; |
|
| 614 | 614 | } |
| 615 | 615 | |
| 616 | 616 | /** |
@@ -631,10 +631,10 @@ discard block |
||
| 631 | 631 | * Pile complétée par le code à générer |
| 632 | 632 | **/ |
| 633 | 633 | function balise_POPULARITE_MAX_dist($p) { |
| 634 | - $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | - $p->interdire_scripts = false; |
|
| 634 | + $p->code = 'ceil($GLOBALS["meta"][\'popularite_max\'])'; |
|
| 635 | + $p->interdire_scripts = false; |
|
| 636 | 636 | |
| 637 | - return $p; |
|
| 637 | + return $p; |
|
| 638 | 638 | } |
| 639 | 639 | |
| 640 | 640 | |
@@ -660,15 +660,15 @@ discard block |
||
| 660 | 660 | * Pile complétée par le code à générer |
| 661 | 661 | **/ |
| 662 | 662 | function balise_VALEUR_dist($p) { |
| 663 | - $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 664 | - $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 663 | + $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 664 | + $p->code = index_pile($p->id_boucle, 'valeur', $p->boucles, $b); |
|
| 665 | 665 | ; |
| 666 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | - $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | - } |
|
| 669 | - $p->interdire_scripts = true; |
|
| 666 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 667 | + $p->code = 'table_valeur(' . $p->code . ', ' . $v . ')'; |
|
| 668 | + } |
|
| 669 | + $p->interdire_scripts = true; |
|
| 670 | 670 | |
| 671 | - return $p; |
|
| 671 | + return $p; |
|
| 672 | 672 | } |
| 673 | 673 | |
| 674 | 674 | /** |
@@ -697,16 +697,16 @@ discard block |
||
| 697 | 697 | * Pile complétée par le code à générer |
| 698 | 698 | **/ |
| 699 | 699 | function balise_EXPOSE_dist($p) { |
| 700 | - $on = "'on'"; |
|
| 701 | - $off = "''"; |
|
| 702 | - if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | - $on = $v; |
|
| 704 | - if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | - $off = $v; |
|
| 706 | - } |
|
| 707 | - } |
|
| 700 | + $on = "'on'"; |
|
| 701 | + $off = "''"; |
|
| 702 | + if (($v = interprete_argument_balise(1, $p)) !== null) { |
|
| 703 | + $on = $v; |
|
| 704 | + if (($v = interprete_argument_balise(2, $p)) !== null) { |
|
| 705 | + $off = $v; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | 708 | |
| 709 | - return calculer_balise_expose($p, $on, $off); |
|
| 709 | + return calculer_balise_expose($p, $on, $off); |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | /** |
@@ -724,35 +724,35 @@ discard block |
||
| 724 | 724 | * Pile complétée par le code à générer |
| 725 | 725 | **/ |
| 726 | 726 | function calculer_balise_expose($p, $on, $off) { |
| 727 | - $b = index_boucle($p); |
|
| 728 | - if (empty($p->boucles[$b]->primary)) { |
|
| 729 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | - erreur_squelette($msg, $p); |
|
| 731 | - } else { |
|
| 732 | - $key = $p->boucles[$b]->primary; |
|
| 733 | - $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | - $desc = $p->boucles[$b]->show; |
|
| 735 | - $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 727 | + $b = index_boucle($p); |
|
| 728 | + if (empty($p->boucles[$b]->primary)) { |
|
| 729 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 730 | + erreur_squelette($msg, $p); |
|
| 731 | + } else { |
|
| 732 | + $key = $p->boucles[$b]->primary; |
|
| 733 | + $type = $p->boucles[$p->id_boucle]->primary; |
|
| 734 | + $desc = $p->boucles[$b]->show; |
|
| 735 | + $connect = sql_quote($p->boucles[$b]->sql_serveur); |
|
| 736 | 736 | |
| 737 | - // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | - $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 737 | + // Ne pas utiliser champ_sql, on jongle avec le nom boucle explicite |
|
| 738 | + $c = index_pile($p->id_boucle, $type, $p->boucles); |
|
| 739 | 739 | |
| 740 | - if (isset($desc['field']['id_parent'])) { |
|
| 741 | - $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | - } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | - $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | - } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | - $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | - } else { |
|
| 747 | - $parent = "''"; |
|
| 748 | - } |
|
| 740 | + if (isset($desc['field']['id_parent'])) { |
|
| 741 | + $parent = 0; // pour if (!$parent) dans calculer_expose |
|
| 742 | + } elseif (isset($desc['field']['id_rubrique'])) { |
|
| 743 | + $parent = index_pile($p->id_boucle, 'id_rubrique', $p->boucles, $b); |
|
| 744 | + } elseif (isset($desc['field']['id_groupe'])) { |
|
| 745 | + $parent = index_pile($p->id_boucle, 'id_groupe', $p->boucles, $b); |
|
| 746 | + } else { |
|
| 747 | + $parent = "''"; |
|
| 748 | + } |
|
| 749 | 749 | |
| 750 | - $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | - } |
|
| 750 | + $p->code = "(calcul_exposer($c, '$type', \$Pile[0], $parent, '$key', $connect) ? $on : $off)"; |
|
| 751 | + } |
|
| 752 | 752 | |
| 753 | - $p->interdire_scripts = false; |
|
| 753 | + $p->interdire_scripts = false; |
|
| 754 | 754 | |
| 755 | - return $p; |
|
| 755 | + return $p; |
|
| 756 | 756 | } |
| 757 | 757 | |
| 758 | 758 | |
@@ -793,46 +793,46 @@ discard block |
||
| 793 | 793 | **/ |
| 794 | 794 | function balise_INTRODUCTION_dist($p) { |
| 795 | 795 | |
| 796 | - $type_objet = $p->type_requete; |
|
| 797 | - $cle_objet = id_table_objet($type_objet); |
|
| 798 | - $_id_objet = champ_sql($cle_objet, $p); |
|
| 799 | - |
|
| 800 | - // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 801 | - // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 802 | - $_introduction_longueur = 'null'; |
|
| 803 | - $_ligne = 'array('; |
|
| 804 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 805 | - if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 806 | - if (isset($desc['field']['descriptif'])) { |
|
| 807 | - $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 808 | - } |
|
| 809 | - if (isset($desc['field']['texte'])) { |
|
| 810 | - $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 811 | - } |
|
| 812 | - if (isset($desc['field']['chapo'])) { |
|
| 813 | - $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 814 | - } |
|
| 815 | - if (isset($desc['introduction_longueur'])) { |
|
| 816 | - $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 817 | - } |
|
| 818 | - } |
|
| 819 | - $_ligne .= ')'; |
|
| 820 | - |
|
| 821 | - // Récupérer la longueur et la suite passés en paramètres |
|
| 822 | - $_longueur_ou_suite = 'null'; |
|
| 823 | - if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 824 | - $_longueur_ou_suite = $v1; |
|
| 825 | - } |
|
| 826 | - $_suite = 'null'; |
|
| 827 | - if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 828 | - $_suite = $v2; |
|
| 829 | - } |
|
| 830 | - |
|
| 831 | - $p->code = "generer_objet_introduction($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 832 | - |
|
| 833 | - #$p->interdire_scripts = true; |
|
| 834 | - $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 835 | - return $p; |
|
| 796 | + $type_objet = $p->type_requete; |
|
| 797 | + $cle_objet = id_table_objet($type_objet); |
|
| 798 | + $_id_objet = champ_sql($cle_objet, $p); |
|
| 799 | + |
|
| 800 | + // Récupérer les valeurs sql nécessaires : descriptif, texte et chapo |
|
| 801 | + // ainsi que le longueur d'introduction donnée dans la description de l'objet. |
|
| 802 | + $_introduction_longueur = 'null'; |
|
| 803 | + $_ligne = 'array('; |
|
| 804 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 805 | + if ($desc = $trouver_table(table_objet_sql($type_objet))) { |
|
| 806 | + if (isset($desc['field']['descriptif'])) { |
|
| 807 | + $_ligne .= "'descriptif' => " . champ_sql('descriptif', $p) . ','; |
|
| 808 | + } |
|
| 809 | + if (isset($desc['field']['texte'])) { |
|
| 810 | + $_ligne .= "'texte' => " . champ_sql('texte', $p) . ','; |
|
| 811 | + } |
|
| 812 | + if (isset($desc['field']['chapo'])) { |
|
| 813 | + $_ligne .= "'chapo' => " . champ_sql('chapo', $p) . ','; |
|
| 814 | + } |
|
| 815 | + if (isset($desc['introduction_longueur'])) { |
|
| 816 | + $_introduction_longueur = "'" . $desc['introduction_longueur'] . "'"; |
|
| 817 | + } |
|
| 818 | + } |
|
| 819 | + $_ligne .= ')'; |
|
| 820 | + |
|
| 821 | + // Récupérer la longueur et la suite passés en paramètres |
|
| 822 | + $_longueur_ou_suite = 'null'; |
|
| 823 | + if (($v1 = interprete_argument_balise(1, $p)) !== null) { |
|
| 824 | + $_longueur_ou_suite = $v1; |
|
| 825 | + } |
|
| 826 | + $_suite = 'null'; |
|
| 827 | + if (($v2 = interprete_argument_balise(2, $p)) !== null) { |
|
| 828 | + $_suite = $v2; |
|
| 829 | + } |
|
| 830 | + |
|
| 831 | + $p->code = "generer_objet_introduction($_id_objet, '$type_objet', $_ligne, $_introduction_longueur, $_longueur_ou_suite, $_suite, \$connect)"; |
|
| 832 | + |
|
| 833 | + #$p->interdire_scripts = true; |
|
| 834 | + $p->etoile = '*'; // propre est deja fait dans le calcul de l'intro |
|
| 835 | + return $p; |
|
| 836 | 836 | } |
| 837 | 837 | |
| 838 | 838 | |
@@ -852,15 +852,15 @@ discard block |
||
| 852 | 852 | * Pile complétée par le code à générer |
| 853 | 853 | **/ |
| 854 | 854 | function balise_LANG_dist($p) { |
| 855 | - $_lang = champ_sql('lang', $p); |
|
| 856 | - if (!$p->etoile) { |
|
| 857 | - $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 858 | - } else { |
|
| 859 | - $p->code = "spip_htmlentities($_lang)"; |
|
| 860 | - } |
|
| 861 | - $p->interdire_scripts = false; |
|
| 855 | + $_lang = champ_sql('lang', $p); |
|
| 856 | + if (!$p->etoile) { |
|
| 857 | + $p->code = "spip_htmlentities($_lang ? $_lang : \$GLOBALS['spip_lang'])"; |
|
| 858 | + } else { |
|
| 859 | + $p->code = "spip_htmlentities($_lang)"; |
|
| 860 | + } |
|
| 861 | + $p->interdire_scripts = false; |
|
| 862 | 862 | |
| 863 | - return $p; |
|
| 863 | + return $p; |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | /** |
@@ -882,45 +882,45 @@ discard block |
||
| 882 | 882 | * Pile complétée par le code à générer |
| 883 | 883 | */ |
| 884 | 884 | function balise_LESAUTEURS_dist($p) { |
| 885 | - // Cherche le champ 'lesauteurs' dans la pile |
|
| 886 | - $_lesauteurs = champ_sql('lesauteurs', $p, ''); |
|
| 887 | - |
|
| 888 | - // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 889 | - // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 890 | - // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 891 | - // (cf extension sites/) |
|
| 892 | - if ($_lesauteurs) { |
|
| 893 | - $p->code = "safehtml($_lesauteurs)"; |
|
| 894 | - // $p->interdire_scripts = true; |
|
| 895 | - } else { |
|
| 896 | - if (!$p->id_boucle) { |
|
| 897 | - $connect = ''; |
|
| 898 | - $objet = 'article'; |
|
| 899 | - $id_table_objet = 'id_article'; |
|
| 900 | - } else { |
|
| 901 | - $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 902 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 903 | - $type_boucle = $p->boucles[$b]->type_requete; |
|
| 904 | - $objet = objet_type($type_boucle); |
|
| 905 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 906 | - } |
|
| 907 | - $c = memoriser_contexte_compil($p); |
|
| 908 | - |
|
| 909 | - $p->code = sprintf( |
|
| 910 | - CODE_RECUPERER_FOND, |
|
| 911 | - "'modeles/lesauteurs'", |
|
| 912 | - "array('objet'=>'" . $objet . |
|
| 913 | - "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 914 | - ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 915 | - ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 916 | - ')', |
|
| 917 | - "'trim'=>true, 'compil'=>array($c)", |
|
| 918 | - _q($connect) |
|
| 919 | - ); |
|
| 920 | - $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 921 | - } |
|
| 922 | - |
|
| 923 | - return $p; |
|
| 885 | + // Cherche le champ 'lesauteurs' dans la pile |
|
| 886 | + $_lesauteurs = champ_sql('lesauteurs', $p, ''); |
|
| 887 | + |
|
| 888 | + // Si le champ n'existe pas (cas de spip_articles), on applique |
|
| 889 | + // le modele lesauteurs.html en passant id_article dans le contexte; |
|
| 890 | + // dans le cas contraire on prend le champ 'lesauteurs' |
|
| 891 | + // (cf extension sites/) |
|
| 892 | + if ($_lesauteurs) { |
|
| 893 | + $p->code = "safehtml($_lesauteurs)"; |
|
| 894 | + // $p->interdire_scripts = true; |
|
| 895 | + } else { |
|
| 896 | + if (!$p->id_boucle) { |
|
| 897 | + $connect = ''; |
|
| 898 | + $objet = 'article'; |
|
| 899 | + $id_table_objet = 'id_article'; |
|
| 900 | + } else { |
|
| 901 | + $b = $p->nom_boucle ?: $p->id_boucle; |
|
| 902 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 903 | + $type_boucle = $p->boucles[$b]->type_requete; |
|
| 904 | + $objet = objet_type($type_boucle); |
|
| 905 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 906 | + } |
|
| 907 | + $c = memoriser_contexte_compil($p); |
|
| 908 | + |
|
| 909 | + $p->code = sprintf( |
|
| 910 | + CODE_RECUPERER_FOND, |
|
| 911 | + "'modeles/lesauteurs'", |
|
| 912 | + "array('objet'=>'" . $objet . |
|
| 913 | + "','id_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 914 | + ",'$id_table_objet' => " . champ_sql($id_table_objet, $p) . |
|
| 915 | + ($objet == 'article' ? '' : ",'id_article' => " . champ_sql('id_article', $p)) . |
|
| 916 | + ')', |
|
| 917 | + "'trim'=>true, 'compil'=>array($c)", |
|
| 918 | + _q($connect) |
|
| 919 | + ); |
|
| 920 | + $p->interdire_scripts = false; // securite apposee par recuperer_fond() |
|
| 921 | + } |
|
| 922 | + |
|
| 923 | + return $p; |
|
| 924 | 924 | } |
| 925 | 925 | |
| 926 | 926 | |
@@ -947,76 +947,76 @@ discard block |
||
| 947 | 947 | * Pile complétée par le code à générer |
| 948 | 948 | */ |
| 949 | 949 | function balise_RANG_dist($p) { |
| 950 | - $b = index_boucle($p); |
|
| 951 | - if ($b === '') { |
|
| 952 | - $msg = [ |
|
| 953 | - 'zbug_champ_hors_boucle', |
|
| 954 | - ['champ' => '#RANG'] |
|
| 955 | - ]; |
|
| 956 | - erreur_squelette($msg, $p); |
|
| 957 | - } else { |
|
| 958 | - // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 959 | - // dans la boucle immediatement englobante uniquement |
|
| 960 | - // sinon on compose le champ calcule |
|
| 961 | - $_rang = champ_sql('rang', $p, '', false); |
|
| 962 | - |
|
| 963 | - // si pas trouve de champ sql rang : |
|
| 964 | - if (!$_rang or $_rang == "''") { |
|
| 965 | - $boucle = &$p->boucles[$b]; |
|
| 966 | - |
|
| 967 | - // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 968 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 969 | - $desc = $trouver_table($boucle->id_table); |
|
| 970 | - $_titre = ''; # où extraire le numero ? |
|
| 971 | - |
|
| 972 | - if (isset($desc['titre'])) { |
|
| 973 | - $t = $desc['titre']; |
|
| 974 | - if ( |
|
| 975 | - // Soit on trouve avec la déclaration de la lang AVANT |
|
| 976 | - preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 977 | - // Soit on prend depuis le début |
|
| 978 | - or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | - ) { |
|
| 980 | - $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 981 | - $m = trim($m); |
|
| 982 | - if ($m != "''") { |
|
| 983 | - if (!preg_match(',\W,', $m)) { |
|
| 984 | - $m = $boucle->id_table . ".$m"; |
|
| 985 | - } |
|
| 986 | - |
|
| 987 | - $m .= ' AS titre_rang'; |
|
| 988 | - |
|
| 989 | - $boucle->select[] = $m; |
|
| 990 | - $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 991 | - } |
|
| 992 | - } |
|
| 993 | - } |
|
| 994 | - |
|
| 995 | - // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 996 | - if (!$_titre) { |
|
| 997 | - $_titre = champ_sql('titre', $p); |
|
| 998 | - } |
|
| 999 | - |
|
| 1000 | - // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1001 | - // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1002 | - $type_boucle = $boucle->type_requete; |
|
| 1003 | - $objet = objet_type($type_boucle); |
|
| 1004 | - $id_table_objet = id_table_objet($type_boucle); |
|
| 1005 | - $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1006 | - $_env = '$Pile[0]'; |
|
| 1007 | - |
|
| 1008 | - if (!$_titre) {$_titre = "''"; |
|
| 1009 | - } |
|
| 1010 | - if (!$_primary) {$_primary = "''"; |
|
| 1011 | - } |
|
| 1012 | - $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1013 | - } |
|
| 1014 | - |
|
| 1015 | - $p->code = $_rang; |
|
| 1016 | - $p->interdire_scripts = false; |
|
| 1017 | - } |
|
| 1018 | - |
|
| 1019 | - return $p; |
|
| 950 | + $b = index_boucle($p); |
|
| 951 | + if ($b === '') { |
|
| 952 | + $msg = [ |
|
| 953 | + 'zbug_champ_hors_boucle', |
|
| 954 | + ['champ' => '#RANG'] |
|
| 955 | + ]; |
|
| 956 | + erreur_squelette($msg, $p); |
|
| 957 | + } else { |
|
| 958 | + // chercher d'abord un champ sql rang (mais pas dans le env : defaut '' si on trouve pas de champ sql) |
|
| 959 | + // dans la boucle immediatement englobante uniquement |
|
| 960 | + // sinon on compose le champ calcule |
|
| 961 | + $_rang = champ_sql('rang', $p, '', false); |
|
| 962 | + |
|
| 963 | + // si pas trouve de champ sql rang : |
|
| 964 | + if (!$_rang or $_rang == "''") { |
|
| 965 | + $boucle = &$p->boucles[$b]; |
|
| 966 | + |
|
| 967 | + // on gere le cas ou #RANG est une extraction du numero dans le titre |
|
| 968 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 969 | + $desc = $trouver_table($boucle->id_table); |
|
| 970 | + $_titre = ''; # où extraire le numero ? |
|
| 971 | + |
|
| 972 | + if (isset($desc['titre'])) { |
|
| 973 | + $t = $desc['titre']; |
|
| 974 | + if ( |
|
| 975 | + // Soit on trouve avec la déclaration de la lang AVANT |
|
| 976 | + preg_match(';(?:lang\s*,)\s*(.*?titre)\s*(,|$);', $t, $m) |
|
| 977 | + // Soit on prend depuis le début |
|
| 978 | + or preg_match(';^(.*?titre)\s*(,|$);', $t, $m) |
|
| 979 | + ) { |
|
| 980 | + $m = preg_replace(',as\s+titre$,i', '', $m[1]); |
|
| 981 | + $m = trim($m); |
|
| 982 | + if ($m != "''") { |
|
| 983 | + if (!preg_match(',\W,', $m)) { |
|
| 984 | + $m = $boucle->id_table . ".$m"; |
|
| 985 | + } |
|
| 986 | + |
|
| 987 | + $m .= ' AS titre_rang'; |
|
| 988 | + |
|
| 989 | + $boucle->select[] = $m; |
|
| 990 | + $_titre = '$Pile[$SP][\'titre_rang\']'; |
|
| 991 | + } |
|
| 992 | + } |
|
| 993 | + } |
|
| 994 | + |
|
| 995 | + // si on n'a rien trouvé, on utilise le champ titre classique |
|
| 996 | + if (!$_titre) { |
|
| 997 | + $_titre = champ_sql('titre', $p); |
|
| 998 | + } |
|
| 999 | + |
|
| 1000 | + // et on recupere aussi les infos de liaison si on est en train d'editer les liens justement |
|
| 1001 | + // cas des formulaires xxx_lies utilises par #FORMULAIRE_EDITER_LIENS |
|
| 1002 | + $type_boucle = $boucle->type_requete; |
|
| 1003 | + $objet = objet_type($type_boucle); |
|
| 1004 | + $id_table_objet = id_table_objet($type_boucle); |
|
| 1005 | + $_primary = champ_sql($id_table_objet, $p, '', false); |
|
| 1006 | + $_env = '$Pile[0]'; |
|
| 1007 | + |
|
| 1008 | + if (!$_titre) {$_titre = "''"; |
|
| 1009 | + } |
|
| 1010 | + if (!$_primary) {$_primary = "''"; |
|
| 1011 | + } |
|
| 1012 | + $_rang = "calculer_rang_smart($_titre, '$objet', $_primary, $_env)"; |
|
| 1013 | + } |
|
| 1014 | + |
|
| 1015 | + $p->code = $_rang; |
|
| 1016 | + $p->interdire_scripts = false; |
|
| 1017 | + } |
|
| 1018 | + |
|
| 1019 | + return $p; |
|
| 1020 | 1020 | } |
| 1021 | 1021 | |
| 1022 | 1022 | |
@@ -1038,12 +1038,12 @@ discard block |
||
| 1038 | 1038 | * Pile complétée par le code à générer |
| 1039 | 1039 | **/ |
| 1040 | 1040 | function balise_POPULARITE_dist($p) { |
| 1041 | - $_popularite = champ_sql('popularite', $p); |
|
| 1042 | - $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1041 | + $_popularite = champ_sql('popularite', $p); |
|
| 1042 | + $p->code = "(ceil(min(100, 100 * $_popularite |
|
| 1043 | 1043 | / max(1 , 0 + \$GLOBALS['meta']['popularite_max']))))"; |
| 1044 | - $p->interdire_scripts = false; |
|
| 1044 | + $p->interdire_scripts = false; |
|
| 1045 | 1045 | |
| 1046 | - return $p; |
|
| 1046 | + return $p; |
|
| 1047 | 1047 | } |
| 1048 | 1048 | |
| 1049 | 1049 | /** |
@@ -1054,8 +1054,8 @@ discard block |
||
| 1054 | 1054 | * l'absence peut-être due à une faute de frappe dans le contexte inclus. |
| 1055 | 1055 | */ |
| 1056 | 1056 | define( |
| 1057 | - 'CODE_PAGINATION', |
|
| 1058 | - '%s($Numrows["%s"]["grand_total"], |
|
| 1057 | + 'CODE_PAGINATION', |
|
| 1058 | + '%s($Numrows["%s"]["grand_total"], |
|
| 1059 | 1059 | %s, |
| 1060 | 1060 | isset($Pile[0][%4$s])?$Pile[0][%4$s]:intval(_request(%4$s)), |
| 1061 | 1061 | %5$s, %6$s, %7$s, %8$s, array(%9$s))' |
@@ -1092,75 +1092,75 @@ discard block |
||
| 1092 | 1092 | * Pile complétée par le code à générer |
| 1093 | 1093 | */ |
| 1094 | 1094 | function balise_PAGINATION_dist($p, $liste = 'true') { |
| 1095 | - $b = index_boucle_mere($p); |
|
| 1096 | - |
|
| 1097 | - // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1098 | - if ($b === '') { |
|
| 1099 | - $msg = [ |
|
| 1100 | - 'zbug_champ_hors_boucle', |
|
| 1101 | - ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1102 | - ]; |
|
| 1103 | - erreur_squelette($msg, $p); |
|
| 1104 | - |
|
| 1105 | - return $p; |
|
| 1106 | - } |
|
| 1107 | - |
|
| 1108 | - // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1109 | - // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1110 | - if (!$p->boucles[$b]->mode_partie) { |
|
| 1111 | - if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1112 | - $msg = [ |
|
| 1113 | - 'zbug_pagination_sans_critere', |
|
| 1114 | - ['champ' => '#PAGINATION'] |
|
| 1115 | - ]; |
|
| 1116 | - erreur_squelette($msg, $p); |
|
| 1117 | - } |
|
| 1118 | - |
|
| 1119 | - return $p; |
|
| 1120 | - } |
|
| 1121 | - |
|
| 1122 | - // a priori true |
|
| 1123 | - // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1124 | - // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1125 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1126 | - if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1127 | - $key = key($_contexte); |
|
| 1128 | - if (is_numeric($key)) { |
|
| 1129 | - array_shift($_contexte); |
|
| 1130 | - $__modele = interprete_argument_balise(1, $p); |
|
| 1131 | - } |
|
| 1132 | - } |
|
| 1133 | - |
|
| 1134 | - if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1135 | - $code_contexte = implode(',', $_contexte); |
|
| 1136 | - } else { |
|
| 1137 | - $code_contexte = ''; |
|
| 1138 | - } |
|
| 1139 | - |
|
| 1140 | - $connect = $p->boucles[$b]->sql_serveur; |
|
| 1141 | - $pas = $p->boucles[$b]->total_parties; |
|
| 1142 | - $f_pagination = chercher_filtre('pagination'); |
|
| 1143 | - $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1144 | - $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1145 | - : ("'debut" . substr($type, 1)); |
|
| 1146 | - |
|
| 1147 | - $p->code = sprintf( |
|
| 1148 | - CODE_PAGINATION, |
|
| 1149 | - $f_pagination, |
|
| 1150 | - $b, |
|
| 1151 | - $type, |
|
| 1152 | - $modif, |
|
| 1153 | - $pas, |
|
| 1154 | - $liste, |
|
| 1155 | - ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1156 | - _q($connect), |
|
| 1157 | - $code_contexte |
|
| 1158 | - ); |
|
| 1159 | - |
|
| 1160 | - $p->boucles[$b]->numrows = true; |
|
| 1161 | - $p->interdire_scripts = false; |
|
| 1162 | - |
|
| 1163 | - return $p; |
|
| 1095 | + $b = index_boucle_mere($p); |
|
| 1096 | + |
|
| 1097 | + // s'il n'y a pas de nom de boucle, on ne peut pas paginer |
|
| 1098 | + if ($b === '') { |
|
| 1099 | + $msg = [ |
|
| 1100 | + 'zbug_champ_hors_boucle', |
|
| 1101 | + ['champ' => $liste ? 'PAGINATION' : 'ANCRE_PAGINATION'] |
|
| 1102 | + ]; |
|
| 1103 | + erreur_squelette($msg, $p); |
|
| 1104 | + |
|
| 1105 | + return $p; |
|
| 1106 | + } |
|
| 1107 | + |
|
| 1108 | + // s'il n'y a pas de mode_partie, c'est qu'on se trouve |
|
| 1109 | + // dans un boucle recursive ou qu'on a oublie le critere {pagination} |
|
| 1110 | + if (!$p->boucles[$b]->mode_partie) { |
|
| 1111 | + if (!$p->boucles[$b]->table_optionnelle) { |
|
| 1112 | + $msg = [ |
|
| 1113 | + 'zbug_pagination_sans_critere', |
|
| 1114 | + ['champ' => '#PAGINATION'] |
|
| 1115 | + ]; |
|
| 1116 | + erreur_squelette($msg, $p); |
|
| 1117 | + } |
|
| 1118 | + |
|
| 1119 | + return $p; |
|
| 1120 | + } |
|
| 1121 | + |
|
| 1122 | + // a priori true |
|
| 1123 | + // si false, le compilo va bloquer sur des syntaxes avec un filtre sans argument qui suit la balise |
|
| 1124 | + // si true, les arguments simples (sans truc=chose) vont degager |
|
| 1125 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false, false); |
|
| 1126 | + if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1127 | + $key = key($_contexte); |
|
| 1128 | + if (is_numeric($key)) { |
|
| 1129 | + array_shift($_contexte); |
|
| 1130 | + $__modele = interprete_argument_balise(1, $p); |
|
| 1131 | + } |
|
| 1132 | + } |
|
| 1133 | + |
|
| 1134 | + if (is_countable($_contexte) ? count($_contexte) : 0) { |
|
| 1135 | + $code_contexte = implode(',', $_contexte); |
|
| 1136 | + } else { |
|
| 1137 | + $code_contexte = ''; |
|
| 1138 | + } |
|
| 1139 | + |
|
| 1140 | + $connect = $p->boucles[$b]->sql_serveur; |
|
| 1141 | + $pas = $p->boucles[$b]->total_parties; |
|
| 1142 | + $f_pagination = chercher_filtre('pagination'); |
|
| 1143 | + $type = $p->boucles[$b]->modificateur['debut_nom']; |
|
| 1144 | + $modif = ($type[0] !== "'") ? "'debut'.$type" |
|
| 1145 | + : ("'debut" . substr($type, 1)); |
|
| 1146 | + |
|
| 1147 | + $p->code = sprintf( |
|
| 1148 | + CODE_PAGINATION, |
|
| 1149 | + $f_pagination, |
|
| 1150 | + $b, |
|
| 1151 | + $type, |
|
| 1152 | + $modif, |
|
| 1153 | + $pas, |
|
| 1154 | + $liste, |
|
| 1155 | + ((isset($__modele) and $__modele) ? $__modele : "''"), |
|
| 1156 | + _q($connect), |
|
| 1157 | + $code_contexte |
|
| 1158 | + ); |
|
| 1159 | + |
|
| 1160 | + $p->boucles[$b]->numrows = true; |
|
| 1161 | + $p->interdire_scripts = false; |
|
| 1162 | + |
|
| 1163 | + return $p; |
|
| 1164 | 1164 | } |
| 1165 | 1165 | |
| 1166 | 1166 | |
@@ -1187,11 +1187,11 @@ discard block |
||
| 1187 | 1187 | * Pile complétée par le code à générer |
| 1188 | 1188 | **/ |
| 1189 | 1189 | function balise_ANCRE_PAGINATION_dist($p) { |
| 1190 | - if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1191 | - return $f($p, $liste = 'false'); |
|
| 1192 | - } else { |
|
| 1193 | - return null; |
|
| 1194 | - } // ou une erreur ? |
|
| 1190 | + if ($f = charger_fonction('PAGINATION', 'balise', true)) { |
|
| 1191 | + return $f($p, $liste = 'false'); |
|
| 1192 | + } else { |
|
| 1193 | + return null; |
|
| 1194 | + } // ou une erreur ? |
|
| 1195 | 1195 | } |
| 1196 | 1196 | |
| 1197 | 1197 | |
@@ -1212,17 +1212,17 @@ discard block |
||
| 1212 | 1212 | * Pile complétée par le code à générer |
| 1213 | 1213 | **/ |
| 1214 | 1214 | function balise_GRAND_TOTAL_dist($p) { |
| 1215 | - $b = index_boucle_mere($p); |
|
| 1216 | - if ($b === '') { |
|
| 1217 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1218 | - erreur_squelette($msg, $p); |
|
| 1219 | - } else { |
|
| 1220 | - $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1221 | - $p->boucles[$b]->numrows = true; |
|
| 1222 | - $p->interdire_scripts = false; |
|
| 1223 | - } |
|
| 1215 | + $b = index_boucle_mere($p); |
|
| 1216 | + if ($b === '') { |
|
| 1217 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 1218 | + erreur_squelette($msg, $p); |
|
| 1219 | + } else { |
|
| 1220 | + $p->code = "(\$Numrows['$b']['grand_total'] ?? \$Numrows['$b']['total'] ?? 0)"; |
|
| 1221 | + $p->boucles[$b]->numrows = true; |
|
| 1222 | + $p->interdire_scripts = false; |
|
| 1223 | + } |
|
| 1224 | 1224 | |
| 1225 | - return $p; |
|
| 1225 | + return $p; |
|
| 1226 | 1226 | } |
| 1227 | 1227 | |
| 1228 | 1228 | |
@@ -1250,10 +1250,10 @@ discard block |
||
| 1250 | 1250 | * Pile complétée par le code à générer |
| 1251 | 1251 | **/ |
| 1252 | 1252 | function balise_SELF_dist($p) { |
| 1253 | - $p->code = 'self()'; |
|
| 1254 | - $p->interdire_scripts = false; |
|
| 1253 | + $p->code = 'self()'; |
|
| 1254 | + $p->interdire_scripts = false; |
|
| 1255 | 1255 | |
| 1256 | - return $p; |
|
| 1256 | + return $p; |
|
| 1257 | 1257 | } |
| 1258 | 1258 | |
| 1259 | 1259 | |
@@ -1280,17 +1280,17 @@ discard block |
||
| 1280 | 1280 | * Pile complétée par le code à générer |
| 1281 | 1281 | **/ |
| 1282 | 1282 | function balise_CHEMIN_dist($p) { |
| 1283 | - $arg = interprete_argument_balise(1, $p); |
|
| 1284 | - if (!$arg) { |
|
| 1285 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1286 | - erreur_squelette($msg, $p); |
|
| 1287 | - } else { |
|
| 1288 | - $p->code = 'find_in_path((string)' . $arg . ')'; |
|
| 1289 | - } |
|
| 1283 | + $arg = interprete_argument_balise(1, $p); |
|
| 1284 | + if (!$arg) { |
|
| 1285 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN']]; |
|
| 1286 | + erreur_squelette($msg, $p); |
|
| 1287 | + } else { |
|
| 1288 | + $p->code = 'find_in_path((string)' . $arg . ')'; |
|
| 1289 | + } |
|
| 1290 | 1290 | |
| 1291 | - $p->interdire_scripts = false; |
|
| 1291 | + $p->interdire_scripts = false; |
|
| 1292 | 1292 | |
| 1293 | - return $p; |
|
| 1293 | + return $p; |
|
| 1294 | 1294 | } |
| 1295 | 1295 | |
| 1296 | 1296 | /** |
@@ -1315,16 +1315,16 @@ discard block |
||
| 1315 | 1315 | * Pile complétée par le code à générer |
| 1316 | 1316 | **/ |
| 1317 | 1317 | function balise_CHEMIN_IMAGE_dist($p) { |
| 1318 | - $arg = interprete_argument_balise(1, $p); |
|
| 1319 | - if (!$arg) { |
|
| 1320 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1321 | - erreur_squelette($msg, $p); |
|
| 1322 | - } else { |
|
| 1323 | - $p->code = 'chemin_image((string)' . $arg . ')'; |
|
| 1324 | - } |
|
| 1318 | + $arg = interprete_argument_balise(1, $p); |
|
| 1319 | + if (!$arg) { |
|
| 1320 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' CHEMIN_IMAGE']]; |
|
| 1321 | + erreur_squelette($msg, $p); |
|
| 1322 | + } else { |
|
| 1323 | + $p->code = 'chemin_image((string)' . $arg . ')'; |
|
| 1324 | + } |
|
| 1325 | 1325 | |
| 1326 | - $p->interdire_scripts = false; |
|
| 1327 | - return $p; |
|
| 1326 | + $p->interdire_scripts = false; |
|
| 1327 | + return $p; |
|
| 1328 | 1328 | } |
| 1329 | 1329 | |
| 1330 | 1330 | |
@@ -1362,36 +1362,36 @@ discard block |
||
| 1362 | 1362 | **/ |
| 1363 | 1363 | function balise_ENV_dist($p, $src = null) { |
| 1364 | 1364 | |
| 1365 | - // cle du tableau desiree |
|
| 1366 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1367 | - // valeur par defaut |
|
| 1368 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1365 | + // cle du tableau desiree |
|
| 1366 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1367 | + // valeur par defaut |
|
| 1368 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1369 | 1369 | |
| 1370 | - // $src est un tableau de donnees sources eventuellement transmis |
|
| 1371 | - // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1370 | + // $src est un tableau de donnees sources eventuellement transmis |
|
| 1371 | + // en absence, on utilise l'environnement du squelette $Pile[0] |
|
| 1372 | 1372 | |
| 1373 | - if (!$_nom) { |
|
| 1374 | - // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1375 | - // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1376 | - if ($src) { |
|
| 1377 | - $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1378 | - } else { |
|
| 1379 | - $p->code = 'serialize($Pile[0]??[])'; |
|
| 1380 | - } |
|
| 1381 | - } else { |
|
| 1382 | - if (!$src) { |
|
| 1383 | - $src = '$Pile[0]??[]'; |
|
| 1384 | - } |
|
| 1385 | - if ($_sinon) { |
|
| 1386 | - $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1387 | - } else { |
|
| 1388 | - $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1389 | - } |
|
| 1390 | - } |
|
| 1373 | + if (!$_nom) { |
|
| 1374 | + // cas de #ENV sans argument : on retourne le serialize() du tableau |
|
| 1375 | + // une belle fonction [(#ENV|affiche_env)] serait pratique |
|
| 1376 | + if ($src) { |
|
| 1377 | + $p->code = '(is_array($a = (' . $src . ')) ? serialize($a) : "")'; |
|
| 1378 | + } else { |
|
| 1379 | + $p->code = 'serialize($Pile[0]??[])'; |
|
| 1380 | + } |
|
| 1381 | + } else { |
|
| 1382 | + if (!$src) { |
|
| 1383 | + $src = '$Pile[0]??[]'; |
|
| 1384 | + } |
|
| 1385 | + if ($_sinon) { |
|
| 1386 | + $p->code = "sinon(table_valeur($src, (string)$_nom, null), $_sinon)"; |
|
| 1387 | + } else { |
|
| 1388 | + $p->code = "table_valeur($src, (string)$_nom, null)"; |
|
| 1389 | + } |
|
| 1390 | + } |
|
| 1391 | 1391 | |
| 1392 | - #$p->interdire_scripts = true; |
|
| 1392 | + #$p->interdire_scripts = true; |
|
| 1393 | 1393 | |
| 1394 | - return $p; |
|
| 1394 | + return $p; |
|
| 1395 | 1395 | } |
| 1396 | 1396 | |
| 1397 | 1397 | /** |
@@ -1421,16 +1421,16 @@ discard block |
||
| 1421 | 1421 | * Pile completée du code PHP d'exécution de la balise |
| 1422 | 1422 | */ |
| 1423 | 1423 | function balise_CONFIG_dist($p) { |
| 1424 | - if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1425 | - $arg = "''"; |
|
| 1426 | - } |
|
| 1427 | - $_sinon = interprete_argument_balise(2, $p); |
|
| 1428 | - $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1424 | + if (!$arg = interprete_argument_balise(1, $p)) { |
|
| 1425 | + $arg = "''"; |
|
| 1426 | + } |
|
| 1427 | + $_sinon = interprete_argument_balise(2, $p); |
|
| 1428 | + $_unserialize = sinon(interprete_argument_balise(3, $p), 'false'); |
|
| 1429 | 1429 | |
| 1430 | - $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1431 | - ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1430 | + $p->code = '(include_spip(\'inc/config\')?lire_config(' . $arg . ',' . |
|
| 1431 | + ($_sinon && $_sinon != "''" ? $_sinon : 'null') . ',' . $_unserialize . "):'')"; |
|
| 1432 | 1432 | |
| 1433 | - return $p; |
|
| 1433 | + return $p; |
|
| 1434 | 1434 | } |
| 1435 | 1435 | |
| 1436 | 1436 | |
@@ -1453,10 +1453,10 @@ discard block |
||
| 1453 | 1453 | * Pile completée du code PHP d'exécution de la balise |
| 1454 | 1454 | */ |
| 1455 | 1455 | function balise_CONNECT_dist($p) { |
| 1456 | - $p->code = '($connect ? $connect : NULL)'; |
|
| 1457 | - $p->interdire_scripts = false; |
|
| 1456 | + $p->code = '($connect ? $connect : NULL)'; |
|
| 1457 | + $p->interdire_scripts = false; |
|
| 1458 | 1458 | |
| 1459 | - return $p; |
|
| 1459 | + return $p; |
|
| 1460 | 1460 | } |
| 1461 | 1461 | |
| 1462 | 1462 | |
@@ -1484,15 +1484,15 @@ discard block |
||
| 1484 | 1484 | * Pile completée du code PHP d'exécution de la balise |
| 1485 | 1485 | **/ |
| 1486 | 1486 | function balise_SESSION_dist($p) { |
| 1487 | - $p->descr['session'] = true; |
|
| 1487 | + $p->descr['session'] = true; |
|
| 1488 | 1488 | |
| 1489 | - $f = function_exists('balise_ENV') |
|
| 1490 | - ? 'balise_ENV' |
|
| 1491 | - : 'balise_ENV_dist'; |
|
| 1489 | + $f = function_exists('balise_ENV') |
|
| 1490 | + ? 'balise_ENV' |
|
| 1491 | + : 'balise_ENV_dist'; |
|
| 1492 | 1492 | |
| 1493 | - $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1493 | + $p = $f($p, '$GLOBALS["visiteur_session"]??[]'); |
|
| 1494 | 1494 | |
| 1495 | - return $p; |
|
| 1495 | + return $p; |
|
| 1496 | 1496 | } |
| 1497 | 1497 | |
| 1498 | 1498 | |
@@ -1515,18 +1515,18 @@ discard block |
||
| 1515 | 1515 | * Pile completée du code PHP d'exécution de la balise |
| 1516 | 1516 | **/ |
| 1517 | 1517 | function balise_SESSION_SET_dist($p) { |
| 1518 | - $_nom = interprete_argument_balise(1, $p); |
|
| 1519 | - $_val = interprete_argument_balise(2, $p); |
|
| 1520 | - if (!$_nom or !$_val) { |
|
| 1521 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1522 | - erreur_squelette($err_b_s_a, $p); |
|
| 1523 | - } else { |
|
| 1524 | - $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1525 | - } |
|
| 1518 | + $_nom = interprete_argument_balise(1, $p); |
|
| 1519 | + $_val = interprete_argument_balise(2, $p); |
|
| 1520 | + if (!$_nom or !$_val) { |
|
| 1521 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SESSION_SET']]; |
|
| 1522 | + erreur_squelette($err_b_s_a, $p); |
|
| 1523 | + } else { |
|
| 1524 | + $p->code = '(include_spip("inc/session") AND session_set(' . $_nom . ',' . $_val . '))'; |
|
| 1525 | + } |
|
| 1526 | 1526 | |
| 1527 | - $p->interdire_scripts = false; |
|
| 1527 | + $p->interdire_scripts = false; |
|
| 1528 | 1528 | |
| 1529 | - return $p; |
|
| 1529 | + return $p; |
|
| 1530 | 1530 | } |
| 1531 | 1531 | |
| 1532 | 1532 | |
@@ -1557,30 +1557,30 @@ discard block |
||
| 1557 | 1557 | * Pile completée du code PHP d'exécution de la balise |
| 1558 | 1558 | **/ |
| 1559 | 1559 | function balise_EVAL_dist($p) { |
| 1560 | - $php = interprete_argument_balise(1, $p); |
|
| 1561 | - if ($php) { |
|
| 1562 | - # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1563 | - # attention au commentaire "// x signes" qui precede |
|
| 1564 | - if ( |
|
| 1565 | - preg_match( |
|
| 1566 | - ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1567 | - $php, |
|
| 1568 | - $r |
|
| 1569 | - ) |
|
| 1570 | - ) { |
|
| 1571 | - $p->code = /* $r[1]. */ |
|
| 1572 | - '(' . $r[2] . ')'; |
|
| 1573 | - } else { |
|
| 1574 | - $p->code = "eval('return '.$php.';')"; |
|
| 1575 | - } |
|
| 1576 | - } else { |
|
| 1577 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1578 | - erreur_squelette($msg, $p); |
|
| 1579 | - } |
|
| 1580 | - |
|
| 1581 | - #$p->interdire_scripts = true; |
|
| 1582 | - |
|
| 1583 | - return $p; |
|
| 1560 | + $php = interprete_argument_balise(1, $p); |
|
| 1561 | + if ($php) { |
|
| 1562 | + # optimisation sur les #EVAL{une expression sans #BALISE} |
|
| 1563 | + # attention au commentaire "// x signes" qui precede |
|
| 1564 | + if ( |
|
| 1565 | + preg_match( |
|
| 1566 | + ",^([[:space:]]*//[^\n]*\n)'([^']+)'$,ms", |
|
| 1567 | + $php, |
|
| 1568 | + $r |
|
| 1569 | + ) |
|
| 1570 | + ) { |
|
| 1571 | + $p->code = /* $r[1]. */ |
|
| 1572 | + '(' . $r[2] . ')'; |
|
| 1573 | + } else { |
|
| 1574 | + $p->code = "eval('return '.$php.';')"; |
|
| 1575 | + } |
|
| 1576 | + } else { |
|
| 1577 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' EVAL']]; |
|
| 1578 | + erreur_squelette($msg, $p); |
|
| 1579 | + } |
|
| 1580 | + |
|
| 1581 | + #$p->interdire_scripts = true; |
|
| 1582 | + |
|
| 1583 | + return $p; |
|
| 1584 | 1584 | } |
| 1585 | 1585 | |
| 1586 | 1586 | |
@@ -1610,19 +1610,19 @@ discard block |
||
| 1610 | 1610 | **/ |
| 1611 | 1611 | function balise_CHAMP_SQL_dist($p) { |
| 1612 | 1612 | |
| 1613 | - if ( |
|
| 1614 | - $p->param |
|
| 1615 | - and isset($p->param[0][1][0]) |
|
| 1616 | - and $champ = ($p->param[0][1][0]->texte) |
|
| 1617 | - ) { |
|
| 1618 | - $p->code = champ_sql($champ, $p); |
|
| 1619 | - } else { |
|
| 1620 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1621 | - erreur_squelette($err_b_s_a, $p); |
|
| 1622 | - } |
|
| 1613 | + if ( |
|
| 1614 | + $p->param |
|
| 1615 | + and isset($p->param[0][1][0]) |
|
| 1616 | + and $champ = ($p->param[0][1][0]->texte) |
|
| 1617 | + ) { |
|
| 1618 | + $p->code = champ_sql($champ, $p); |
|
| 1619 | + } else { |
|
| 1620 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => ' CHAMP_SQL']]; |
|
| 1621 | + erreur_squelette($err_b_s_a, $p); |
|
| 1622 | + } |
|
| 1623 | 1623 | |
| 1624 | - #$p->interdire_scripts = true; |
|
| 1625 | - return $p; |
|
| 1624 | + #$p->interdire_scripts = true; |
|
| 1625 | + return $p; |
|
| 1626 | 1626 | } |
| 1627 | 1627 | |
| 1628 | 1628 | /** |
@@ -1648,13 +1648,13 @@ discard block |
||
| 1648 | 1648 | * Pile complétée par le code à générer |
| 1649 | 1649 | **/ |
| 1650 | 1650 | function balise_VAL_dist($p) { |
| 1651 | - $p->code = interprete_argument_balise(1, $p) ?? ''; |
|
| 1652 | - if (!strlen($p->code)) { |
|
| 1653 | - $p->code = "''"; |
|
| 1654 | - } |
|
| 1655 | - $p->interdire_scripts = false; |
|
| 1651 | + $p->code = interprete_argument_balise(1, $p) ?? ''; |
|
| 1652 | + if (!strlen($p->code)) { |
|
| 1653 | + $p->code = "''"; |
|
| 1654 | + } |
|
| 1655 | + $p->interdire_scripts = false; |
|
| 1656 | 1656 | |
| 1657 | - return $p; |
|
| 1657 | + return $p; |
|
| 1658 | 1658 | } |
| 1659 | 1659 | |
| 1660 | 1660 | /** |
@@ -1683,10 +1683,10 @@ discard block |
||
| 1683 | 1683 | * Pile complétée par le code à générer |
| 1684 | 1684 | **/ |
| 1685 | 1685 | function balise_REM_dist($p) { |
| 1686 | - $p->code = "''"; |
|
| 1687 | - $p->interdire_scripts = false; |
|
| 1686 | + $p->code = "''"; |
|
| 1687 | + $p->interdire_scripts = false; |
|
| 1688 | 1688 | |
| 1689 | - return $p; |
|
| 1689 | + return $p; |
|
| 1690 | 1690 | } |
| 1691 | 1691 | |
| 1692 | 1692 | /** |
@@ -1696,10 +1696,10 @@ discard block |
||
| 1696 | 1696 | * @return mixed |
| 1697 | 1697 | */ |
| 1698 | 1698 | function balise_NULL_dist($p) { |
| 1699 | - $p->code = 'null'; |
|
| 1700 | - $p->interdire_scripts = false; |
|
| 1699 | + $p->code = 'null'; |
|
| 1700 | + $p->interdire_scripts = false; |
|
| 1701 | 1701 | |
| 1702 | - return $p; |
|
| 1702 | + return $p; |
|
| 1703 | 1703 | } |
| 1704 | 1704 | |
| 1705 | 1705 | |
@@ -1723,18 +1723,18 @@ discard block |
||
| 1723 | 1723 | **/ |
| 1724 | 1724 | function balise_HTTP_HEADER_dist($p) { |
| 1725 | 1725 | |
| 1726 | - $header = interprete_argument_balise(1, $p); |
|
| 1727 | - if (!$header) { |
|
| 1728 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1729 | - erreur_squelette($err_b_s_a, $p); |
|
| 1730 | - } else { |
|
| 1731 | - $p->code = "'<'.'?php header(' . _q(" |
|
| 1732 | - . $header |
|
| 1733 | - . ") . '); ?'.'>'"; |
|
| 1734 | - } |
|
| 1735 | - $p->interdire_scripts = false; |
|
| 1726 | + $header = interprete_argument_balise(1, $p); |
|
| 1727 | + if (!$header) { |
|
| 1728 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'HTTP_HEADER']]; |
|
| 1729 | + erreur_squelette($err_b_s_a, $p); |
|
| 1730 | + } else { |
|
| 1731 | + $p->code = "'<'.'?php header(' . _q(" |
|
| 1732 | + . $header |
|
| 1733 | + . ") . '); ?'.'>'"; |
|
| 1734 | + } |
|
| 1735 | + $p->interdire_scripts = false; |
|
| 1736 | 1736 | |
| 1737 | - return $p; |
|
| 1737 | + return $p; |
|
| 1738 | 1738 | } |
| 1739 | 1739 | |
| 1740 | 1740 | |
@@ -1759,20 +1759,20 @@ discard block |
||
| 1759 | 1759 | * Pile complétée par le code à générer |
| 1760 | 1760 | **/ |
| 1761 | 1761 | function balise_FILTRE_dist($p) { |
| 1762 | - if ($p->param) { |
|
| 1763 | - $args = []; |
|
| 1764 | - foreach ($p->param as $i => $ignore) { |
|
| 1765 | - $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1766 | - } |
|
| 1767 | - $p->code = "'<' . '" |
|
| 1768 | - . '?php header("X-Spip-Filtre: \'.' |
|
| 1769 | - . join('.\'|\'.', $args) |
|
| 1770 | - . " . '\"); ?'.'>'"; |
|
| 1762 | + if ($p->param) { |
|
| 1763 | + $args = []; |
|
| 1764 | + foreach ($p->param as $i => $ignore) { |
|
| 1765 | + $args[] = interprete_argument_balise($i + 1, $p); |
|
| 1766 | + } |
|
| 1767 | + $p->code = "'<' . '" |
|
| 1768 | + . '?php header("X-Spip-Filtre: \'.' |
|
| 1769 | + . join('.\'|\'.', $args) |
|
| 1770 | + . " . '\"); ?'.'>'"; |
|
| 1771 | 1771 | |
| 1772 | - $p->interdire_scripts = false; |
|
| 1772 | + $p->interdire_scripts = false; |
|
| 1773 | 1773 | |
| 1774 | - return $p; |
|
| 1775 | - } |
|
| 1774 | + return $p; |
|
| 1775 | + } |
|
| 1776 | 1776 | } |
| 1777 | 1777 | |
| 1778 | 1778 | |
@@ -1808,55 +1808,55 @@ discard block |
||
| 1808 | 1808 | **/ |
| 1809 | 1809 | function balise_CACHE_dist($p) { |
| 1810 | 1810 | |
| 1811 | - if ($p->param) { |
|
| 1812 | - $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1813 | - |
|
| 1814 | - // noter la duree du cache dans un entete proprietaire |
|
| 1815 | - |
|
| 1816 | - $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1817 | - . $duree |
|
| 1818 | - . '"); ?' . "'.'>'"; |
|
| 1819 | - |
|
| 1820 | - // Remplir le header Cache-Control |
|
| 1821 | - // cas #CACHE{0} |
|
| 1822 | - if ($duree == 0) { |
|
| 1823 | - $code .= ".'<'.'" |
|
| 1824 | - . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1825 | - . "'.'><'.'" |
|
| 1826 | - . '?php header("Pragma: no-cache"); ?' |
|
| 1827 | - . "'.'>'"; |
|
| 1828 | - } |
|
| 1829 | - |
|
| 1830 | - // recuperer les parametres suivants |
|
| 1831 | - $i = 1; |
|
| 1832 | - while (isset($p->param[0][++$i])) { |
|
| 1833 | - $pa = ($p->param[0][$i][0]->texte); |
|
| 1834 | - |
|
| 1835 | - if ( |
|
| 1836 | - $pa == 'cache-client' |
|
| 1837 | - and $duree > 0 |
|
| 1838 | - ) { |
|
| 1839 | - $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1840 | - . $duree |
|
| 1841 | - . '"); ?' . "'.'>'"; |
|
| 1842 | - // il semble logique, si on cache-client, de ne pas invalider |
|
| 1843 | - $pa = 'statique'; |
|
| 1844 | - } |
|
| 1845 | - |
|
| 1846 | - if ( |
|
| 1847 | - $pa == 'statique' |
|
| 1848 | - and $duree > 0 |
|
| 1849 | - ) { |
|
| 1850 | - $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1851 | - } |
|
| 1852 | - } |
|
| 1853 | - } else { |
|
| 1854 | - $code = "''"; |
|
| 1855 | - } |
|
| 1856 | - $p->code = $code; |
|
| 1857 | - $p->interdire_scripts = false; |
|
| 1858 | - |
|
| 1859 | - return $p; |
|
| 1811 | + if ($p->param) { |
|
| 1812 | + $duree = valeur_numerique($p->param[0][1][0]->texte); |
|
| 1813 | + |
|
| 1814 | + // noter la duree du cache dans un entete proprietaire |
|
| 1815 | + |
|
| 1816 | + $code = "'<'.'" . '?php header("X-Spip-Cache: ' |
|
| 1817 | + . $duree |
|
| 1818 | + . '"); ?' . "'.'>'"; |
|
| 1819 | + |
|
| 1820 | + // Remplir le header Cache-Control |
|
| 1821 | + // cas #CACHE{0} |
|
| 1822 | + if ($duree == 0) { |
|
| 1823 | + $code .= ".'<'.'" |
|
| 1824 | + . '?php header("Cache-Control: no-cache, must-revalidate"); ?' |
|
| 1825 | + . "'.'><'.'" |
|
| 1826 | + . '?php header("Pragma: no-cache"); ?' |
|
| 1827 | + . "'.'>'"; |
|
| 1828 | + } |
|
| 1829 | + |
|
| 1830 | + // recuperer les parametres suivants |
|
| 1831 | + $i = 1; |
|
| 1832 | + while (isset($p->param[0][++$i])) { |
|
| 1833 | + $pa = ($p->param[0][$i][0]->texte); |
|
| 1834 | + |
|
| 1835 | + if ( |
|
| 1836 | + $pa == 'cache-client' |
|
| 1837 | + and $duree > 0 |
|
| 1838 | + ) { |
|
| 1839 | + $code .= ".'<'.'" . '?php header("Cache-Control: max-age=' |
|
| 1840 | + . $duree |
|
| 1841 | + . '"); ?' . "'.'>'"; |
|
| 1842 | + // il semble logique, si on cache-client, de ne pas invalider |
|
| 1843 | + $pa = 'statique'; |
|
| 1844 | + } |
|
| 1845 | + |
|
| 1846 | + if ( |
|
| 1847 | + $pa == 'statique' |
|
| 1848 | + and $duree > 0 |
|
| 1849 | + ) { |
|
| 1850 | + $code .= ".'<'.'" . '?php header("X-Spip-Statique: oui"); ?' . "'.'>'"; |
|
| 1851 | + } |
|
| 1852 | + } |
|
| 1853 | + } else { |
|
| 1854 | + $code = "''"; |
|
| 1855 | + } |
|
| 1856 | + $p->code = $code; |
|
| 1857 | + $p->interdire_scripts = false; |
|
| 1858 | + |
|
| 1859 | + return $p; |
|
| 1860 | 1860 | } |
| 1861 | 1861 | |
| 1862 | 1862 | |
@@ -1888,13 +1888,13 @@ discard block |
||
| 1888 | 1888 | * Pile complétée par le code à générer |
| 1889 | 1889 | */ |
| 1890 | 1890 | function balise_INSERT_HEAD_dist($p) { |
| 1891 | - $p->code = "'<'.'" |
|
| 1892 | - . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1893 | - . "'.'>'"; |
|
| 1894 | - $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1895 | - $p->interdire_scripts = false; |
|
| 1891 | + $p->code = "'<'.'" |
|
| 1892 | + . '?php header("X-Spip-Filtre: insert_head_css_conditionnel"); ?' |
|
| 1893 | + . "'.'>'"; |
|
| 1894 | + $p->code .= ". pipeline('insert_head','<!-- insert_head -->')"; |
|
| 1895 | + $p->interdire_scripts = false; |
|
| 1896 | 1896 | |
| 1897 | - return $p; |
|
| 1897 | + return $p; |
|
| 1898 | 1898 | } |
| 1899 | 1899 | |
| 1900 | 1900 | /** |
@@ -1912,10 +1912,10 @@ discard block |
||
| 1912 | 1912 | * Pile complétée par le code à générer |
| 1913 | 1913 | */ |
| 1914 | 1914 | function balise_INSERT_HEAD_CSS_dist($p) { |
| 1915 | - $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1916 | - $p->interdire_scripts = false; |
|
| 1915 | + $p->code = "pipeline('insert_head_css','<!-- insert_head_css -->')"; |
|
| 1916 | + $p->interdire_scripts = false; |
|
| 1917 | 1917 | |
| 1918 | - return $p; |
|
| 1918 | + return $p; |
|
| 1919 | 1919 | } |
| 1920 | 1920 | |
| 1921 | 1921 | /** |
@@ -1930,11 +1930,11 @@ discard block |
||
| 1930 | 1930 | * Pile complétée par le code à générer |
| 1931 | 1931 | **/ |
| 1932 | 1932 | function balise_INCLUDE_dist($p) { |
| 1933 | - if (function_exists('balise_INCLURE')) { |
|
| 1934 | - return balise_INCLURE($p); |
|
| 1935 | - } else { |
|
| 1936 | - return balise_INCLURE_dist($p); |
|
| 1937 | - } |
|
| 1933 | + if (function_exists('balise_INCLURE')) { |
|
| 1934 | + return balise_INCLURE($p); |
|
| 1935 | + } else { |
|
| 1936 | + return balise_INCLURE_dist($p); |
|
| 1937 | + } |
|
| 1938 | 1938 | } |
| 1939 | 1939 | |
| 1940 | 1940 | /** |
@@ -1968,66 +1968,66 @@ discard block |
||
| 1968 | 1968 | * Pile complétée par le code à générer |
| 1969 | 1969 | **/ |
| 1970 | 1970 | function balise_INCLURE_dist($p) { |
| 1971 | - $id_boucle = $p->id_boucle; |
|
| 1972 | - // la lang n'est pas passe de facon automatique par argumenter |
|
| 1973 | - // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1974 | - // en option |
|
| 1975 | - |
|
| 1976 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1977 | - |
|
| 1978 | - // erreur de syntaxe = fond absent |
|
| 1979 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1980 | - if (!$_contexte) { |
|
| 1981 | - $contexte = []; |
|
| 1982 | - } |
|
| 1983 | - |
|
| 1984 | - if (isset($_contexte['fond'])) { |
|
| 1985 | - $f = $_contexte['fond']; |
|
| 1986 | - // toujours vrai : |
|
| 1987 | - if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1988 | - $f = $r[1]; |
|
| 1989 | - unset($_contexte['fond']); |
|
| 1990 | - } else { |
|
| 1991 | - spip_log('compilation de #INCLURE a revoir'); |
|
| 1992 | - } |
|
| 1993 | - |
|
| 1994 | - // #INCLURE{doublons} |
|
| 1995 | - if (isset($_contexte['doublons'])) { |
|
| 1996 | - $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1997 | - } |
|
| 1998 | - |
|
| 1999 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2000 | - $flag_env = false; |
|
| 2001 | - if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2002 | - $flag_env = true; |
|
| 2003 | - unset($_contexte['env']); |
|
| 2004 | - } |
|
| 2005 | - |
|
| 2006 | - $_options = []; |
|
| 2007 | - if (isset($_contexte['ajax'])) { |
|
| 2008 | - $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2009 | - unset($_contexte['ajax']); |
|
| 2010 | - } |
|
| 2011 | - if ($p->etoile) { |
|
| 2012 | - $_options[] = "'etoile'=>true"; |
|
| 2013 | - } |
|
| 2014 | - $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2015 | - |
|
| 2016 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2017 | - if ($flag_env) { |
|
| 2018 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2019 | - } |
|
| 2020 | - |
|
| 2021 | - $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2022 | - } elseif (!isset($_contexte[1])) { |
|
| 2023 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2024 | - erreur_squelette($msg, $p); |
|
| 2025 | - } else { |
|
| 2026 | - $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2027 | - } |
|
| 2028 | - |
|
| 2029 | - $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2030 | - return $p; |
|
| 1971 | + $id_boucle = $p->id_boucle; |
|
| 1972 | + // la lang n'est pas passe de facon automatique par argumenter |
|
| 1973 | + // mais le sera pas recuperer_fond, sauf si etoile=>true est passe |
|
| 1974 | + // en option |
|
| 1975 | + |
|
| 1976 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $id_boucle, false, false); |
|
| 1977 | + |
|
| 1978 | + // erreur de syntaxe = fond absent |
|
| 1979 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 1980 | + if (!$_contexte) { |
|
| 1981 | + $contexte = []; |
|
| 1982 | + } |
|
| 1983 | + |
|
| 1984 | + if (isset($_contexte['fond'])) { |
|
| 1985 | + $f = $_contexte['fond']; |
|
| 1986 | + // toujours vrai : |
|
| 1987 | + if (preg_match('/^.fond.\s*=>(.*)$/s', $f, $r)) { |
|
| 1988 | + $f = $r[1]; |
|
| 1989 | + unset($_contexte['fond']); |
|
| 1990 | + } else { |
|
| 1991 | + spip_log('compilation de #INCLURE a revoir'); |
|
| 1992 | + } |
|
| 1993 | + |
|
| 1994 | + // #INCLURE{doublons} |
|
| 1995 | + if (isset($_contexte['doublons'])) { |
|
| 1996 | + $_contexte['doublons'] = "'doublons' => \$doublons"; |
|
| 1997 | + } |
|
| 1998 | + |
|
| 1999 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 2000 | + $flag_env = false; |
|
| 2001 | + if (isset($_contexte['env']) or isset($_contexte['self'])) { |
|
| 2002 | + $flag_env = true; |
|
| 2003 | + unset($_contexte['env']); |
|
| 2004 | + } |
|
| 2005 | + |
|
| 2006 | + $_options = []; |
|
| 2007 | + if (isset($_contexte['ajax'])) { |
|
| 2008 | + $_options[] = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2009 | + unset($_contexte['ajax']); |
|
| 2010 | + } |
|
| 2011 | + if ($p->etoile) { |
|
| 2012 | + $_options[] = "'etoile'=>true"; |
|
| 2013 | + } |
|
| 2014 | + $_options[] = "'compil'=>array(" . memoriser_contexte_compil($p) . ')'; |
|
| 2015 | + |
|
| 2016 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2017 | + if ($flag_env) { |
|
| 2018 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2019 | + } |
|
| 2020 | + |
|
| 2021 | + $p->code = sprintf(CODE_RECUPERER_FOND, $f, $_l, join(',', $_options), "_request('connect') ?? ''"); |
|
| 2022 | + } elseif (!isset($_contexte[1])) { |
|
| 2023 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' INCLURE']]; |
|
| 2024 | + erreur_squelette($msg, $p); |
|
| 2025 | + } else { |
|
| 2026 | + $p->code = 'charge_scripts(' . $_contexte[1] . ',false)'; |
|
| 2027 | + } |
|
| 2028 | + |
|
| 2029 | + $p->interdire_scripts = false; // la securite est assuree par recuperer_fond |
|
| 2030 | + return $p; |
|
| 2031 | 2031 | } |
| 2032 | 2032 | |
| 2033 | 2033 | |
@@ -2055,69 +2055,69 @@ discard block |
||
| 2055 | 2055 | **/ |
| 2056 | 2056 | function balise_MODELE_dist($p) { |
| 2057 | 2057 | |
| 2058 | - $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2059 | - |
|
| 2060 | - // erreur de syntaxe = fond absent |
|
| 2061 | - // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2062 | - if (!$_contexte) { |
|
| 2063 | - $_contexte = []; |
|
| 2064 | - } |
|
| 2065 | - |
|
| 2066 | - if (!isset($_contexte[1])) { |
|
| 2067 | - $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2068 | - erreur_squelette($msg, $p); |
|
| 2069 | - } else { |
|
| 2070 | - $nom = $_contexte[1]; |
|
| 2071 | - unset($_contexte[1]); |
|
| 2072 | - |
|
| 2073 | - if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2074 | - $nom = "'modeles/" . substr($nom, 1); |
|
| 2075 | - } else { |
|
| 2076 | - $nom = "'modeles/' . $nom"; |
|
| 2077 | - } |
|
| 2078 | - |
|
| 2079 | - $flag_env = false; |
|
| 2080 | - if (isset($_contexte['env'])) { |
|
| 2081 | - $flag_env = true; |
|
| 2082 | - unset($_contexte['env']); |
|
| 2083 | - } |
|
| 2084 | - |
|
| 2085 | - // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2086 | - // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2087 | - if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2088 | - $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2089 | - if (!strpos($primary, ',')) { |
|
| 2090 | - $id = champ_sql($primary, $p); |
|
| 2091 | - $_contexte[] = "'$primary'=>" . $id; |
|
| 2092 | - $_contexte[] = "'id'=>" . $id; |
|
| 2093 | - } |
|
| 2094 | - } |
|
| 2095 | - $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2096 | - $connect = ''; |
|
| 2097 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2098 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2099 | - } |
|
| 2100 | - |
|
| 2101 | - $_options = memoriser_contexte_compil($p); |
|
| 2102 | - $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2103 | - if (isset($_contexte['ajax'])) { |
|
| 2104 | - $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2105 | - unset($_contexte['ajax']); |
|
| 2106 | - } |
|
| 2107 | - |
|
| 2108 | - $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2109 | - if ($flag_env) { |
|
| 2110 | - $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2111 | - } |
|
| 2112 | - |
|
| 2113 | - $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2114 | - |
|
| 2115 | - $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2116 | - |
|
| 2117 | - $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2118 | - } |
|
| 2119 | - |
|
| 2120 | - return $p; |
|
| 2058 | + $_contexte = argumenter_inclure($p->param, true, $p, $p->boucles, $p->id_boucle, false); |
|
| 2059 | + |
|
| 2060 | + // erreur de syntaxe = fond absent |
|
| 2061 | + // (2 messages d'erreur SPIP pour le prix d'un, mais pas d'erreur PHP |
|
| 2062 | + if (!$_contexte) { |
|
| 2063 | + $_contexte = []; |
|
| 2064 | + } |
|
| 2065 | + |
|
| 2066 | + if (!isset($_contexte[1])) { |
|
| 2067 | + $msg = ['zbug_balise_sans_argument', ['balise' => ' MODELE']]; |
|
| 2068 | + erreur_squelette($msg, $p); |
|
| 2069 | + } else { |
|
| 2070 | + $nom = $_contexte[1]; |
|
| 2071 | + unset($_contexte[1]); |
|
| 2072 | + |
|
| 2073 | + if (preg_match("/^\s*'[^']*'/s", $nom)) { |
|
| 2074 | + $nom = "'modeles/" . substr($nom, 1); |
|
| 2075 | + } else { |
|
| 2076 | + $nom = "'modeles/' . $nom"; |
|
| 2077 | + } |
|
| 2078 | + |
|
| 2079 | + $flag_env = false; |
|
| 2080 | + if (isset($_contexte['env'])) { |
|
| 2081 | + $flag_env = true; |
|
| 2082 | + unset($_contexte['env']); |
|
| 2083 | + } |
|
| 2084 | + |
|
| 2085 | + // Incoherence dans la syntaxe du contexte. A revoir. |
|
| 2086 | + // Reserver la cle primaire de la boucle courante si elle existe |
|
| 2087 | + if (isset($p->boucles[$p->id_boucle]->primary)) { |
|
| 2088 | + $primary = $p->boucles[$p->id_boucle]->primary; |
|
| 2089 | + if (!strpos($primary, ',')) { |
|
| 2090 | + $id = champ_sql($primary, $p); |
|
| 2091 | + $_contexte[] = "'$primary'=>" . $id; |
|
| 2092 | + $_contexte[] = "'id'=>" . $id; |
|
| 2093 | + } |
|
| 2094 | + } |
|
| 2095 | + $_contexte[] = "'recurs'=>(++\$recurs)"; |
|
| 2096 | + $connect = ''; |
|
| 2097 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2098 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2099 | + } |
|
| 2100 | + |
|
| 2101 | + $_options = memoriser_contexte_compil($p); |
|
| 2102 | + $_options = "'compil'=>array($_options), 'trim'=>true"; |
|
| 2103 | + if (isset($_contexte['ajax'])) { |
|
| 2104 | + $_options .= ', ' . preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 2105 | + unset($_contexte['ajax']); |
|
| 2106 | + } |
|
| 2107 | + |
|
| 2108 | + $_l = 'array(' . join(",\n\t", $_contexte) . ')'; |
|
| 2109 | + if ($flag_env) { |
|
| 2110 | + $_l = "array_merge(\$Pile[0],$_l)"; |
|
| 2111 | + } |
|
| 2112 | + |
|
| 2113 | + $page = sprintf(CODE_RECUPERER_FOND, $nom, $_l, $_options, _q($connect)); |
|
| 2114 | + |
|
| 2115 | + $p->code = "\n\t(((\$recurs=(isset(\$Pile[0]['recurs'])?\$Pile[0]['recurs']:0))>=5)? '' :\n\t$page)\n"; |
|
| 2116 | + |
|
| 2117 | + $p->interdire_scripts = false; // securite assuree par le squelette |
|
| 2118 | + } |
|
| 2119 | + |
|
| 2120 | + return $p; |
|
| 2121 | 2121 | } |
| 2122 | 2122 | |
| 2123 | 2123 | |
@@ -2141,21 +2141,21 @@ discard block |
||
| 2141 | 2141 | * Pile complétée par le code à générer |
| 2142 | 2142 | **/ |
| 2143 | 2143 | function balise_SET_dist($p) { |
| 2144 | - $_nom = interprete_argument_balise(1, $p); |
|
| 2145 | - $_val = interprete_argument_balise(2, $p); |
|
| 2144 | + $_nom = interprete_argument_balise(1, $p); |
|
| 2145 | + $_val = interprete_argument_balise(2, $p); |
|
| 2146 | 2146 | |
| 2147 | - if (!$_nom or !$_val) { |
|
| 2148 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2149 | - erreur_squelette($err_b_s_a, $p); |
|
| 2150 | - } |
|
| 2151 | - // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2152 | - // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2153 | - else { |
|
| 2154 | - $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2155 | - } |
|
| 2147 | + if (!$_nom or !$_val) { |
|
| 2148 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'SET']]; |
|
| 2149 | + erreur_squelette($err_b_s_a, $p); |
|
| 2150 | + } |
|
| 2151 | + // affectation $_zzz inutile, mais permet de contourner un bug OpCode cache sous PHP 5.5.4 |
|
| 2152 | + // cf https://bugs.php.net/bug.php?id=65845 |
|
| 2153 | + else { |
|
| 2154 | + $p->code = "vide(\$Pile['vars'][\$_zzz=(string)$_nom] = $_val)"; |
|
| 2155 | + } |
|
| 2156 | 2156 | |
| 2157 | - $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2158 | - return $p; |
|
| 2157 | + $p->interdire_scripts = false; // la balise ne renvoie rien |
|
| 2158 | + return $p; |
|
| 2159 | 2159 | } |
| 2160 | 2160 | |
| 2161 | 2161 | |
@@ -2185,12 +2185,12 @@ discard block |
||
| 2185 | 2185 | * Pile complétée par le code à générer |
| 2186 | 2186 | **/ |
| 2187 | 2187 | function balise_GET_dist($p) { |
| 2188 | - $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2189 | - if (function_exists('balise_ENV')) { |
|
| 2190 | - return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2191 | - } else { |
|
| 2192 | - return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2193 | - } |
|
| 2188 | + $p->interdire_scripts = false; // le contenu vient de #SET, donc il est de confiance |
|
| 2189 | + if (function_exists('balise_ENV')) { |
|
| 2190 | + return balise_ENV($p, '$Pile["vars"]??[]'); |
|
| 2191 | + } else { |
|
| 2192 | + return balise_ENV_dist($p, '$Pile["vars"]??[]'); |
|
| 2193 | + } |
|
| 2194 | 2194 | } |
| 2195 | 2195 | |
| 2196 | 2196 | |
@@ -2213,22 +2213,22 @@ discard block |
||
| 2213 | 2213 | * Pile complétée par le code à générer |
| 2214 | 2214 | **/ |
| 2215 | 2215 | function balise_DOUBLONS_dist($p) { |
| 2216 | - if ($type = interprete_argument_balise(1, $p)) { |
|
| 2217 | - if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2218 | - $type .= '.' . $famille; |
|
| 2219 | - } |
|
| 2220 | - $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2221 | - if (!$p->etoile) { |
|
| 2222 | - $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2223 | - . $p->code . ')))'; |
|
| 2224 | - } |
|
| 2225 | - } else { |
|
| 2226 | - $p->code = '$doublons'; |
|
| 2227 | - } |
|
| 2216 | + if ($type = interprete_argument_balise(1, $p)) { |
|
| 2217 | + if ($famille = interprete_argument_balise(2, $p)) { |
|
| 2218 | + $type .= '.' . $famille; |
|
| 2219 | + } |
|
| 2220 | + $p->code = '(isset($doublons[' . $type . ']) ? $doublons[' . $type . '] : "")'; |
|
| 2221 | + if (!$p->etoile) { |
|
| 2222 | + $p->code = 'array_filter(array_map("intval",explode(",",' |
|
| 2223 | + . $p->code . ')))'; |
|
| 2224 | + } |
|
| 2225 | + } else { |
|
| 2226 | + $p->code = '$doublons'; |
|
| 2227 | + } |
|
| 2228 | 2228 | |
| 2229 | - $p->interdire_scripts = false; |
|
| 2229 | + $p->interdire_scripts = false; |
|
| 2230 | 2230 | |
| 2231 | - return $p; |
|
| 2231 | + return $p; |
|
| 2232 | 2232 | } |
| 2233 | 2233 | |
| 2234 | 2234 | |
@@ -2251,18 +2251,18 @@ discard block |
||
| 2251 | 2251 | * Pile complétée par le code à générer |
| 2252 | 2252 | **/ |
| 2253 | 2253 | function balise_PIPELINE_dist($p) { |
| 2254 | - $_pipe = interprete_argument_balise(1, $p); |
|
| 2255 | - if (!$_pipe) { |
|
| 2256 | - $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2257 | - erreur_squelette($err_b_s_a, $p); |
|
| 2258 | - } else { |
|
| 2259 | - $_flux = interprete_argument_balise(2, $p); |
|
| 2260 | - $_flux = $_flux ?: "''"; |
|
| 2261 | - $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2262 | - $p->interdire_scripts = false; |
|
| 2263 | - } |
|
| 2254 | + $_pipe = interprete_argument_balise(1, $p); |
|
| 2255 | + if (!$_pipe) { |
|
| 2256 | + $err_b_s_a = ['zbug_balise_sans_argument', ['balise' => 'PIPELINE']]; |
|
| 2257 | + erreur_squelette($err_b_s_a, $p); |
|
| 2258 | + } else { |
|
| 2259 | + $_flux = interprete_argument_balise(2, $p); |
|
| 2260 | + $_flux = $_flux ?: "''"; |
|
| 2261 | + $p->code = "pipeline( $_pipe , $_flux )"; |
|
| 2262 | + $p->interdire_scripts = false; |
|
| 2263 | + } |
|
| 2264 | 2264 | |
| 2265 | - return $p; |
|
| 2265 | + return $p; |
|
| 2266 | 2266 | } |
| 2267 | 2267 | |
| 2268 | 2268 | |
@@ -2287,10 +2287,10 @@ discard block |
||
| 2287 | 2287 | * Pile complétée par le code à générer |
| 2288 | 2288 | **/ |
| 2289 | 2289 | function balise_EDIT_dist($p) { |
| 2290 | - $p->code = "''"; |
|
| 2291 | - $p->interdire_scripts = false; |
|
| 2290 | + $p->code = "''"; |
|
| 2291 | + $p->interdire_scripts = false; |
|
| 2292 | 2292 | |
| 2293 | - return $p; |
|
| 2293 | + return $p; |
|
| 2294 | 2294 | } |
| 2295 | 2295 | |
| 2296 | 2296 | |
@@ -2313,11 +2313,11 @@ discard block |
||
| 2313 | 2313 | * Pile complétée par le code à générer |
| 2314 | 2314 | **/ |
| 2315 | 2315 | function balise_TOTAL_UNIQUE_dist($p) { |
| 2316 | - $_famille = interprete_argument_balise(1, $p); |
|
| 2317 | - $_famille = $_famille ?: "''"; |
|
| 2318 | - $p->code = "unique('', $_famille, true)"; |
|
| 2316 | + $_famille = interprete_argument_balise(1, $p); |
|
| 2317 | + $_famille = $_famille ?: "''"; |
|
| 2318 | + $p->code = "unique('', $_famille, true)"; |
|
| 2319 | 2319 | |
| 2320 | - return $p; |
|
| 2320 | + return $p; |
|
| 2321 | 2321 | } |
| 2322 | 2322 | |
| 2323 | 2323 | /** |
@@ -2340,19 +2340,19 @@ discard block |
||
| 2340 | 2340 | * Pile complétée par le code à générer |
| 2341 | 2341 | **/ |
| 2342 | 2342 | function balise_ARRAY_dist($p) { |
| 2343 | - $_code = []; |
|
| 2344 | - $n = 1; |
|
| 2345 | - do { |
|
| 2346 | - $_key = interprete_argument_balise($n++, $p); |
|
| 2347 | - $_val = interprete_argument_balise($n++, $p); |
|
| 2348 | - if ($_key and $_val) { |
|
| 2349 | - $_code[] = "$_key => $_val"; |
|
| 2350 | - } |
|
| 2351 | - } while ($_key && $_val); |
|
| 2352 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2353 | - $p->interdire_scripts = false; |
|
| 2343 | + $_code = []; |
|
| 2344 | + $n = 1; |
|
| 2345 | + do { |
|
| 2346 | + $_key = interprete_argument_balise($n++, $p); |
|
| 2347 | + $_val = interprete_argument_balise($n++, $p); |
|
| 2348 | + if ($_key and $_val) { |
|
| 2349 | + $_code[] = "$_key => $_val"; |
|
| 2350 | + } |
|
| 2351 | + } while ($_key && $_val); |
|
| 2352 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2353 | + $p->interdire_scripts = false; |
|
| 2354 | 2354 | |
| 2355 | - return $p; |
|
| 2355 | + return $p; |
|
| 2356 | 2356 | } |
| 2357 | 2357 | |
| 2358 | 2358 | /** |
@@ -2371,15 +2371,15 @@ discard block |
||
| 2371 | 2371 | * Pile complétée par le code à générer |
| 2372 | 2372 | */ |
| 2373 | 2373 | function balise_LISTE_dist($p) { |
| 2374 | - $_code = []; |
|
| 2375 | - $n = 1; |
|
| 2376 | - while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2377 | - $_code[] = $_val; |
|
| 2378 | - } |
|
| 2379 | - $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2380 | - $p->interdire_scripts = false; |
|
| 2374 | + $_code = []; |
|
| 2375 | + $n = 1; |
|
| 2376 | + while ($_val = interprete_argument_balise($n++, $p)) { |
|
| 2377 | + $_code[] = $_val; |
|
| 2378 | + } |
|
| 2379 | + $p->code = 'array(' . join(', ', $_code) . ')'; |
|
| 2380 | + $p->interdire_scripts = false; |
|
| 2381 | 2381 | |
| 2382 | - return $p; |
|
| 2382 | + return $p; |
|
| 2383 | 2383 | } |
| 2384 | 2384 | |
| 2385 | 2385 | |
@@ -2413,21 +2413,21 @@ discard block |
||
| 2413 | 2413 | * Pile complétée par le code à générer |
| 2414 | 2414 | **/ |
| 2415 | 2415 | function balise_AUTORISER_dist($p) { |
| 2416 | - $_code = []; |
|
| 2417 | - $p->descr['session'] = true; // faire un cache par session |
|
| 2416 | + $_code = []; |
|
| 2417 | + $p->descr['session'] = true; // faire un cache par session |
|
| 2418 | 2418 | |
| 2419 | - $n = 1; |
|
| 2420 | - while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2421 | - $_code[] = $_v; |
|
| 2422 | - } |
|
| 2419 | + $n = 1; |
|
| 2420 | + while ($_v = interprete_argument_balise($n++, $p)) { |
|
| 2421 | + $_code[] = $_v; |
|
| 2422 | + } |
|
| 2423 | 2423 | |
| 2424 | - $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2425 | - ', ', |
|
| 2426 | - $_code |
|
| 2427 | - ) . ')?" ":"")'; |
|
| 2428 | - $p->interdire_scripts = false; |
|
| 2424 | + $p->code = '((function_exists("autoriser")||include_spip("inc/autoriser"))&&autoriser(' . join( |
|
| 2425 | + ', ', |
|
| 2426 | + $_code |
|
| 2427 | + ) . ')?" ":"")'; |
|
| 2428 | + $p->interdire_scripts = false; |
|
| 2429 | 2429 | |
| 2430 | - return $p; |
|
| 2430 | + return $p; |
|
| 2431 | 2431 | } |
| 2432 | 2432 | |
| 2433 | 2433 | |
@@ -2451,15 +2451,15 @@ discard block |
||
| 2451 | 2451 | * Pile complétée par le code à générer |
| 2452 | 2452 | **/ |
| 2453 | 2453 | function balise_PLUGIN_dist($p) { |
| 2454 | - $plugin = interprete_argument_balise(1, $p); |
|
| 2455 | - $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2456 | - $type_info = interprete_argument_balise(2, $p); |
|
| 2457 | - $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2454 | + $plugin = interprete_argument_balise(1, $p); |
|
| 2455 | + $plugin = isset($plugin) ? str_replace('\'', '"', $plugin) : '""'; |
|
| 2456 | + $type_info = interprete_argument_balise(2, $p); |
|
| 2457 | + $type_info = isset($type_info) ? str_replace('\'', '"', $type_info) : '"est_actif"'; |
|
| 2458 | 2458 | |
| 2459 | - $f = chercher_filtre('info_plugin'); |
|
| 2460 | - $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2459 | + $f = chercher_filtre('info_plugin'); |
|
| 2460 | + $p->code = $f . '(' . $plugin . ', ' . $type_info . ')'; |
|
| 2461 | 2461 | |
| 2462 | - return $p; |
|
| 2462 | + return $p; |
|
| 2463 | 2463 | } |
| 2464 | 2464 | |
| 2465 | 2465 | /** |
@@ -2480,9 +2480,9 @@ discard block |
||
| 2480 | 2480 | * Pile complétée par le code à générer |
| 2481 | 2481 | **/ |
| 2482 | 2482 | function balise_AIDER_dist($p) { |
| 2483 | - $_motif = interprete_argument_balise(1, $p); |
|
| 2484 | - $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2485 | - return $p; |
|
| 2483 | + $_motif = interprete_argument_balise(1, $p); |
|
| 2484 | + $p->code = "((\$aider=charger_fonction('aide','inc',true))?\$aider($_motif):'')"; |
|
| 2485 | + return $p; |
|
| 2486 | 2486 | } |
| 2487 | 2487 | |
| 2488 | 2488 | /** |
@@ -2508,16 +2508,16 @@ discard block |
||
| 2508 | 2508 | * Pile complétée par le code à générer |
| 2509 | 2509 | **/ |
| 2510 | 2510 | function balise_ACTION_FORMULAIRE($p) { |
| 2511 | - if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2512 | - $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2513 | - } |
|
| 2514 | - if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2515 | - $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2516 | - } |
|
| 2517 | - |
|
| 2518 | - // envoyer le nom du formulaire que l'on traite |
|
| 2519 | - // transmettre les eventuels args de la balise formulaire |
|
| 2520 | - $p->code = " '<span class=\"form-hidden\">' . |
|
| 2511 | + if (!$_url = interprete_argument_balise(1, $p)) { |
|
| 2512 | + $_url = "(\$Pile[0]['action'] ?? '')"; |
|
| 2513 | + } |
|
| 2514 | + if (!$_form = interprete_argument_balise(2, $p)) { |
|
| 2515 | + $_form = "(\$Pile[0]['form'] ?? '')"; |
|
| 2516 | + } |
|
| 2517 | + |
|
| 2518 | + // envoyer le nom du formulaire que l'on traite |
|
| 2519 | + // transmettre les eventuels args de la balise formulaire |
|
| 2520 | + $p->code = " '<span class=\"form-hidden\">' . |
|
| 2521 | 2521 | form_hidden($_url) . |
| 2522 | 2522 | '<input name=\'formulaire_action\' type=\'hidden\' |
| 2523 | 2523 | value=\'' . $_form . '\' />' . |
@@ -2528,9 +2528,9 @@ discard block |
||
| 2528 | 2528 | (\$Pile[0]['_hidden'] ?? '') . |
| 2529 | 2529 | '</span>'"; |
| 2530 | 2530 | |
| 2531 | - $p->interdire_scripts = false; |
|
| 2531 | + $p->interdire_scripts = false; |
|
| 2532 | 2532 | |
| 2533 | - return $p; |
|
| 2533 | + return $p; |
|
| 2534 | 2534 | } |
| 2535 | 2535 | |
| 2536 | 2536 | |
@@ -2571,25 +2571,25 @@ discard block |
||
| 2571 | 2571 | */ |
| 2572 | 2572 | function balise_BOUTON_ACTION_dist($p) { |
| 2573 | 2573 | |
| 2574 | - $args = []; |
|
| 2575 | - for ($k = 1; $k <= 6; $k++) { |
|
| 2576 | - $_a = interprete_argument_balise($k, $p); |
|
| 2577 | - if (!$_a) { |
|
| 2578 | - $_a = "''"; |
|
| 2579 | - } |
|
| 2580 | - $args[] = $_a; |
|
| 2581 | - } |
|
| 2582 | - // supprimer les args vides |
|
| 2583 | - while (end($args) == "''" and count($args) > 2) { |
|
| 2584 | - array_pop($args); |
|
| 2585 | - } |
|
| 2586 | - $args = implode(',', $args); |
|
| 2574 | + $args = []; |
|
| 2575 | + for ($k = 1; $k <= 6; $k++) { |
|
| 2576 | + $_a = interprete_argument_balise($k, $p); |
|
| 2577 | + if (!$_a) { |
|
| 2578 | + $_a = "''"; |
|
| 2579 | + } |
|
| 2580 | + $args[] = $_a; |
|
| 2581 | + } |
|
| 2582 | + // supprimer les args vides |
|
| 2583 | + while (end($args) == "''" and count($args) > 2) { |
|
| 2584 | + array_pop($args); |
|
| 2585 | + } |
|
| 2586 | + $args = implode(',', $args); |
|
| 2587 | 2587 | |
| 2588 | - $bouton_action = chercher_filtre('bouton_action'); |
|
| 2589 | - $p->code = "$bouton_action($args)"; |
|
| 2590 | - $p->interdire_scripts = false; |
|
| 2588 | + $bouton_action = chercher_filtre('bouton_action'); |
|
| 2589 | + $p->code = "$bouton_action($args)"; |
|
| 2590 | + $p->interdire_scripts = false; |
|
| 2591 | 2591 | |
| 2592 | - return $p; |
|
| 2592 | + return $p; |
|
| 2593 | 2593 | } |
| 2594 | 2594 | |
| 2595 | 2595 | |
@@ -2608,10 +2608,10 @@ discard block |
||
| 2608 | 2608 | * Pile complétée par le code à générer |
| 2609 | 2609 | */ |
| 2610 | 2610 | function balise_SLOGAN_SITE_SPIP_dist($p) { |
| 2611 | - $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2611 | + $p->code = "\$GLOBALS['meta']['slogan_site']"; |
|
| 2612 | 2612 | |
| 2613 | - #$p->interdire_scripts = true; |
|
| 2614 | - return $p; |
|
| 2613 | + #$p->interdire_scripts = true; |
|
| 2614 | + return $p; |
|
| 2615 | 2615 | } |
| 2616 | 2616 | |
| 2617 | 2617 | |
@@ -2635,10 +2635,10 @@ discard block |
||
| 2635 | 2635 | * Pile complétée par le code à générer |
| 2636 | 2636 | */ |
| 2637 | 2637 | function balise_HTML5_dist($p) { |
| 2638 | - $p->code = html5_permis() ? "' '" : "''"; |
|
| 2639 | - $p->interdire_scripts = false; |
|
| 2638 | + $p->code = html5_permis() ? "' '" : "''"; |
|
| 2639 | + $p->interdire_scripts = false; |
|
| 2640 | 2640 | |
| 2641 | - return $p; |
|
| 2641 | + return $p; |
|
| 2642 | 2642 | } |
| 2643 | 2643 | |
| 2644 | 2644 | |
@@ -2664,58 +2664,58 @@ discard block |
||
| 2664 | 2664 | * Pile complétée par le code à générer |
| 2665 | 2665 | */ |
| 2666 | 2666 | function balise_TRI_dist($p, $liste = 'true') { |
| 2667 | - $b = index_boucle_mere($p); |
|
| 2668 | - // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2669 | - if ($b === '') { |
|
| 2670 | - $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2671 | - erreur_squelette($msg, $p); |
|
| 2672 | - $p->code = "''"; |
|
| 2667 | + $b = index_boucle_mere($p); |
|
| 2668 | + // s'il n'y a pas de nom de boucle, on ne peut pas trier |
|
| 2669 | + if ($b === '') { |
|
| 2670 | + $msg = ['zbug_champ_hors_boucle', ['champ' => zbug_presenter_champ($p)]]; |
|
| 2671 | + erreur_squelette($msg, $p); |
|
| 2672 | + $p->code = "''"; |
|
| 2673 | 2673 | |
| 2674 | - return $p; |
|
| 2675 | - } |
|
| 2676 | - $boucle = $p->boucles[$b]; |
|
| 2674 | + return $p; |
|
| 2675 | + } |
|
| 2676 | + $boucle = $p->boucles[$b]; |
|
| 2677 | 2677 | |
| 2678 | - // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2679 | - // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2680 | - if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2681 | - $msg = ['zbug_champ_hors_critere', [ |
|
| 2682 | - 'champ' => zbug_presenter_champ($p), |
|
| 2683 | - 'critere' => 'tri' |
|
| 2684 | - ]]; |
|
| 2685 | - erreur_squelette($msg, $p); |
|
| 2686 | - $p->code = "''"; |
|
| 2678 | + // s'il n'y a pas de tri_champ, c'est qu'on se trouve |
|
| 2679 | + // dans un boucle recursive ou qu'on a oublie le critere {tri} |
|
| 2680 | + if (!isset($boucle->modificateur['tri_champ'])) { |
|
| 2681 | + $msg = ['zbug_champ_hors_critere', [ |
|
| 2682 | + 'champ' => zbug_presenter_champ($p), |
|
| 2683 | + 'critere' => 'tri' |
|
| 2684 | + ]]; |
|
| 2685 | + erreur_squelette($msg, $p); |
|
| 2686 | + $p->code = "''"; |
|
| 2687 | 2687 | |
| 2688 | - return $p; |
|
| 2689 | - } |
|
| 2688 | + return $p; |
|
| 2689 | + } |
|
| 2690 | 2690 | |
| 2691 | - // Différentes infos relatives au tri présentes dans les modificateurs |
|
| 2692 | - $_tri_nom = $boucle->modificateur['tri_nom'] ; // nom du paramètre définissant le tri |
|
| 2693 | - $_tri_champ = $boucle->modificateur['tri_champ']; // champ actuel utilisé le tri |
|
| 2694 | - $_tri_sens = $boucle->modificateur['tri_sens']; // sens de tri actuel |
|
| 2695 | - $_tri_liste_sens_defaut = $boucle->modificateur['tri_liste_sens_defaut']; // sens par défaut pour chaque champ |
|
| 2691 | + // Différentes infos relatives au tri présentes dans les modificateurs |
|
| 2692 | + $_tri_nom = $boucle->modificateur['tri_nom'] ; // nom du paramètre définissant le tri |
|
| 2693 | + $_tri_champ = $boucle->modificateur['tri_champ']; // champ actuel utilisé le tri |
|
| 2694 | + $_tri_sens = $boucle->modificateur['tri_sens']; // sens de tri actuel |
|
| 2695 | + $_tri_liste_sens_defaut = $boucle->modificateur['tri_liste_sens_defaut']; // sens par défaut pour chaque champ |
|
| 2696 | 2696 | |
| 2697 | - $_champ_ou_sens = interprete_argument_balise(1, $p); |
|
| 2698 | - // si pas de champ, renvoyer le critère de tri actuel |
|
| 2699 | - if (!$_champ_ou_sens) { |
|
| 2700 | - $p->code = $_tri_champ; |
|
| 2697 | + $_champ_ou_sens = interprete_argument_balise(1, $p); |
|
| 2698 | + // si pas de champ, renvoyer le critère de tri actuel |
|
| 2699 | + if (!$_champ_ou_sens) { |
|
| 2700 | + $p->code = $_tri_champ; |
|
| 2701 | 2701 | |
| 2702 | - return $p; |
|
| 2703 | - } |
|
| 2704 | - // forcer la jointure si besoin, et si le champ est statique |
|
| 2705 | - if (preg_match(",^'([\w.]+)'$,i", $_champ_ou_sens, $m)) { |
|
| 2706 | - index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2707 | - } |
|
| 2702 | + return $p; |
|
| 2703 | + } |
|
| 2704 | + // forcer la jointure si besoin, et si le champ est statique |
|
| 2705 | + if (preg_match(",^'([\w.]+)'$,i", $_champ_ou_sens, $m)) { |
|
| 2706 | + index_pile($b, $m[1], $p->boucles, '', null, true, false); |
|
| 2707 | + } |
|
| 2708 | 2708 | |
| 2709 | - $_libelle = interprete_argument_balise(2, $p); |
|
| 2710 | - $_libelle = $_libelle ?: $_champ_ou_sens; |
|
| 2709 | + $_libelle = interprete_argument_balise(2, $p); |
|
| 2710 | + $_libelle = $_libelle ?: $_champ_ou_sens; |
|
| 2711 | 2711 | |
| 2712 | - $_class = interprete_argument_balise(3, $p) ?? "''"; |
|
| 2712 | + $_class = interprete_argument_balise(3, $p) ?? "''"; |
|
| 2713 | 2713 | |
| 2714 | - $p->code = "calculer_balise_tri($_champ_ou_sens, $_libelle, $_class, $_tri_nom, $_tri_champ, $_tri_sens, $_tri_liste_sens_defaut)"; |
|
| 2714 | + $p->code = "calculer_balise_tri($_champ_ou_sens, $_libelle, $_class, $_tri_nom, $_tri_champ, $_tri_sens, $_tri_liste_sens_defaut)"; |
|
| 2715 | 2715 | |
| 2716 | - $p->interdire_scripts = false; |
|
| 2716 | + $p->interdire_scripts = false; |
|
| 2717 | 2717 | |
| 2718 | - return $p; |
|
| 2718 | + return $p; |
|
| 2719 | 2719 | } |
| 2720 | 2720 | |
| 2721 | 2721 | |
@@ -2736,21 +2736,21 @@ discard block |
||
| 2736 | 2736 | * Pile complétée par le code à générer |
| 2737 | 2737 | */ |
| 2738 | 2738 | function balise_SAUTER_dist($p) { |
| 2739 | - $id_boucle = $p->id_boucle; |
|
| 2739 | + $id_boucle = $p->id_boucle; |
|
| 2740 | 2740 | |
| 2741 | - if (empty($p->boucles[$id_boucle])) { |
|
| 2742 | - $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2743 | - erreur_squelette($msg, $p); |
|
| 2744 | - } else { |
|
| 2745 | - $_saut = interprete_argument_balise(1, $p); |
|
| 2746 | - $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2747 | - $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2741 | + if (empty($p->boucles[$id_boucle])) { |
|
| 2742 | + $msg = ['zbug_champ_hors_boucle', ['champ' => '#SAUTER']]; |
|
| 2743 | + erreur_squelette($msg, $p); |
|
| 2744 | + } else { |
|
| 2745 | + $_saut = interprete_argument_balise(1, $p); |
|
| 2746 | + $_compteur = "\$Numrows['$id_boucle']['compteur_boucle']"; |
|
| 2747 | + $_total = "(\$Numrows['$id_boucle']['total'] ?? null)"; |
|
| 2748 | 2748 | |
| 2749 | - $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2750 | - } |
|
| 2751 | - $p->interdire_scripts = false; |
|
| 2749 | + $p->code = "vide($_compteur=\$iter->skip($_saut,$_total))"; |
|
| 2750 | + } |
|
| 2751 | + $p->interdire_scripts = false; |
|
| 2752 | 2752 | |
| 2753 | - return $p; |
|
| 2753 | + return $p; |
|
| 2754 | 2754 | } |
| 2755 | 2755 | |
| 2756 | 2756 | |
@@ -2772,22 +2772,22 @@ discard block |
||
| 2772 | 2772 | * Pile complétée par le code à générer |
| 2773 | 2773 | */ |
| 2774 | 2774 | function balise_PUBLIE_dist($p) { |
| 2775 | - if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2776 | - $_type = _q($p->type_requete); |
|
| 2777 | - $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2778 | - } else { |
|
| 2779 | - $_id = interprete_argument_balise(2, $p); |
|
| 2780 | - } |
|
| 2775 | + if (!$_type = interprete_argument_balise(1, $p)) { |
|
| 2776 | + $_type = _q($p->type_requete); |
|
| 2777 | + $_id = champ_sql($p->boucles[$p->id_boucle]->primary, $p); |
|
| 2778 | + } else { |
|
| 2779 | + $_id = interprete_argument_balise(2, $p); |
|
| 2780 | + } |
|
| 2781 | 2781 | |
| 2782 | - $connect = ''; |
|
| 2783 | - if (isset($p->boucles[$p->id_boucle])) { |
|
| 2784 | - $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2785 | - } |
|
| 2782 | + $connect = ''; |
|
| 2783 | + if (isset($p->boucles[$p->id_boucle])) { |
|
| 2784 | + $connect = $p->boucles[$p->id_boucle]->sql_serveur; |
|
| 2785 | + } |
|
| 2786 | 2786 | |
| 2787 | - $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2788 | - $p->interdire_scripts = false; |
|
| 2787 | + $p->code = '(objet_test_si_publie(' . $_type . ',intval(' . $_id . '),' . _q($connect) . ")?' ':'')"; |
|
| 2788 | + $p->interdire_scripts = false; |
|
| 2789 | 2789 | |
| 2790 | - return $p; |
|
| 2790 | + return $p; |
|
| 2791 | 2791 | } |
| 2792 | 2792 | |
| 2793 | 2793 | /** |
@@ -2816,12 +2816,12 @@ discard block |
||
| 2816 | 2816 | * Pile complétée par le code à générer |
| 2817 | 2817 | */ |
| 2818 | 2818 | function balise_PRODUIRE_dist($p) { |
| 2819 | - $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2820 | - $p = $balise_inclure($p); |
|
| 2819 | + $balise_inclure = charger_fonction('INCLURE', 'balise'); |
|
| 2820 | + $p = $balise_inclure($p); |
|
| 2821 | 2821 | |
| 2822 | - $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2822 | + $p->code = str_replace('recuperer_fond(', 'produire_fond_statique(', $p->code); |
|
| 2823 | 2823 | |
| 2824 | - return $p; |
|
| 2824 | + return $p; |
|
| 2825 | 2825 | } |
| 2826 | 2826 | |
| 2827 | 2827 | /** |
@@ -2840,13 +2840,13 @@ discard block |
||
| 2840 | 2840 | * Pile complétée par le code à générer |
| 2841 | 2841 | */ |
| 2842 | 2842 | function balise_LARGEUR_ECRAN_dist($p) { |
| 2843 | - $_class = interprete_argument_balise(1, $p); |
|
| 2844 | - if (!$_class) { |
|
| 2845 | - $_class = 'null'; |
|
| 2846 | - } |
|
| 2847 | - $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2843 | + $_class = interprete_argument_balise(1, $p); |
|
| 2844 | + if (!$_class) { |
|
| 2845 | + $_class = 'null'; |
|
| 2846 | + } |
|
| 2847 | + $p->code = "(is_string($_class)?vide(\$GLOBALS['largeur_ecran']=$_class):(isset(\$GLOBALS['largeur_ecran'])?\$GLOBALS['largeur_ecran']:''))"; |
|
| 2848 | 2848 | |
| 2849 | - return $p; |
|
| 2849 | + return $p; |
|
| 2850 | 2850 | } |
| 2851 | 2851 | |
| 2852 | 2852 | |
@@ -2862,14 +2862,14 @@ discard block |
||
| 2862 | 2862 | * Pile complétée par le code à générer |
| 2863 | 2863 | **/ |
| 2864 | 2864 | function balise_CONST_dist($p) { |
| 2865 | - $_const = interprete_argument_balise(1, $p); |
|
| 2866 | - if (!strlen($_const ?? '')) { |
|
| 2867 | - $p->code = "''"; |
|
| 2868 | - } |
|
| 2869 | - else { |
|
| 2870 | - $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2871 | - } |
|
| 2872 | - $p->interdire_scripts = false; |
|
| 2873 | - |
|
| 2874 | - return $p; |
|
| 2865 | + $_const = interprete_argument_balise(1, $p); |
|
| 2866 | + if (!strlen($_const ?? '')) { |
|
| 2867 | + $p->code = "''"; |
|
| 2868 | + } |
|
| 2869 | + else { |
|
| 2870 | + $p->code = "(defined($_const)?constant($_const):'')"; |
|
| 2871 | + } |
|
| 2872 | + $p->interdire_scripts = false; |
|
| 2873 | + |
|
| 2874 | + return $p; |
|
| 2875 | 2875 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Compilateur\References |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | /** |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * - '' si une référence explicite incorrecte est envoyée |
| 42 | 42 | */ |
| 43 | 43 | function index_boucle($p) { |
| 44 | - if (strlen($p->nom_boucle)) { |
|
| 45 | - // retourne l’index explicite demandé s’il existe |
|
| 46 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | - return $p->nom_boucle; |
|
| 48 | - } |
|
| 49 | - return ''; |
|
| 50 | - } |
|
| 51 | - return $p->id_boucle; |
|
| 44 | + if (strlen($p->nom_boucle)) { |
|
| 45 | + // retourne l’index explicite demandé s’il existe |
|
| 46 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 47 | + return $p->nom_boucle; |
|
| 48 | + } |
|
| 49 | + return ''; |
|
| 50 | + } |
|
| 51 | + return $p->id_boucle; |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -71,17 +71,17 @@ discard block |
||
| 71 | 71 | * - '' si une référence explicite incorrecte est envoyée |
| 72 | 72 | */ |
| 73 | 73 | function index_boucle_mere($p) { |
| 74 | - if (strlen($p->nom_boucle)) { |
|
| 75 | - // retourne l’index explicite demandé s’il existe |
|
| 76 | - if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | - return $p->nom_boucle; |
|
| 78 | - } |
|
| 79 | - return ''; |
|
| 80 | - } |
|
| 81 | - if (!empty($p->descr['id_mere'])) { |
|
| 82 | - return $p->descr['id_mere']; |
|
| 83 | - } |
|
| 84 | - return ''; |
|
| 74 | + if (strlen($p->nom_boucle)) { |
|
| 75 | + // retourne l’index explicite demandé s’il existe |
|
| 76 | + if (!empty($p->boucles[$p->nom_boucle])) { |
|
| 77 | + return $p->nom_boucle; |
|
| 78 | + } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | + if (!empty($p->descr['id_mere'])) { |
|
| 82 | + return $p->descr['id_mere']; |
|
| 83 | + } |
|
| 84 | + return ''; |
|
| 85 | 85 | } |
| 86 | 86 | |
| 87 | 87 | /** |
@@ -115,74 +115,74 @@ discard block |
||
| 115 | 115 | * Code PHP pour obtenir le champ SQL |
| 116 | 116 | */ |
| 117 | 117 | function index_pile( |
| 118 | - $idb, |
|
| 119 | - $nom_champ, |
|
| 120 | - &$boucles, |
|
| 121 | - $explicite = '', |
|
| 122 | - $defaut = null, |
|
| 123 | - $remonte_pile = true, |
|
| 124 | - $select = true |
|
| 118 | + $idb, |
|
| 119 | + $nom_champ, |
|
| 120 | + &$boucles, |
|
| 121 | + $explicite = '', |
|
| 122 | + $defaut = null, |
|
| 123 | + $remonte_pile = true, |
|
| 124 | + $select = true |
|
| 125 | 125 | ) { |
| 126 | - if (!is_string($defaut)) { |
|
| 127 | - $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | - } |
|
| 129 | - |
|
| 130 | - $idb_origine = $idb; |
|
| 131 | - $nom_champ_origine = $nom_champ; |
|
| 132 | - |
|
| 133 | - $i = 0; |
|
| 134 | - if (strlen($explicite)) { |
|
| 135 | - // Recherche d'un champ dans un etage superieur |
|
| 136 | - while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | - # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | - $i++; |
|
| 139 | - $idb = $boucles[$idb]->id_parent; |
|
| 140 | - } |
|
| 141 | - } |
|
| 142 | - |
|
| 143 | - # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | - $nom_champ = strtolower($nom_champ); |
|
| 145 | - $conditionnel = []; |
|
| 146 | - // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | - // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | - while (isset($boucles[$idb])) { |
|
| 149 | - $joker = true; |
|
| 150 | - // modifie $joker si tous les champs sont autorisés. |
|
| 151 | - // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | - // $c = le nom du champ demandé |
|
| 153 | - [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | - if ($t) { |
|
| 155 | - if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | - $boucles[$idb]->select[] = $t; |
|
| 157 | - } |
|
| 158 | - // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | - $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | - $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | - if (!$joker) { |
|
| 162 | - return index_compose($conditionnel, $champ); |
|
| 163 | - } |
|
| 164 | - |
|
| 165 | - // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | - // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | - // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | - // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | - $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - if ($remonte_pile) { |
|
| 173 | - # spip_log("On remonte vers $i"); |
|
| 174 | - // Sinon on remonte d'un cran |
|
| 175 | - $idb = $boucles[$idb]->id_parent; |
|
| 176 | - $i++; |
|
| 177 | - } else { |
|
| 178 | - $idb = null; |
|
| 179 | - } |
|
| 180 | - } |
|
| 181 | - |
|
| 182 | - # spip_log("Pas vu $nom_champ"); |
|
| 183 | - // esperons qu'il y sera |
|
| 184 | - // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | - return index_compose($conditionnel, $defaut); |
|
| 126 | + if (!is_string($defaut)) { |
|
| 127 | + $defaut = '($Pile[0][\'' . strtolower($nom_champ) . '\'] ?? null)'; |
|
| 128 | + } |
|
| 129 | + |
|
| 130 | + $idb_origine = $idb; |
|
| 131 | + $nom_champ_origine = $nom_champ; |
|
| 132 | + |
|
| 133 | + $i = 0; |
|
| 134 | + if (strlen($explicite)) { |
|
| 135 | + // Recherche d'un champ dans un etage superieur |
|
| 136 | + while (($idb !== $explicite) && ($idb !== '')) { |
|
| 137 | + # spip_log("Cherchexpl: $nom_champ '$explicite' '$idb' '$i'"); |
|
| 138 | + $i++; |
|
| 139 | + $idb = $boucles[$idb]->id_parent; |
|
| 140 | + } |
|
| 141 | + } |
|
| 142 | + |
|
| 143 | + # spip_log("Cherche: $nom_champ a partir de '$idb'"); |
|
| 144 | + $nom_champ = strtolower($nom_champ); |
|
| 145 | + $conditionnel = []; |
|
| 146 | + // attention: entre la boucle nommee 0, "" et le tableau vide, |
|
| 147 | + // il y a incoherences qu'il vaut mieux eviter |
|
| 148 | + while (isset($boucles[$idb])) { |
|
| 149 | + $joker = true; |
|
| 150 | + // modifie $joker si tous les champs sont autorisés. |
|
| 151 | + // $t = le select pour le champ, si on l'a trouvé (ou si joker) |
|
| 152 | + // $c = le nom du champ demandé |
|
| 153 | + [$t, $c] = index_tables_en_pile($idb, $nom_champ, $boucles, $joker); |
|
| 154 | + if ($t) { |
|
| 155 | + if ($select and !in_array($t, $boucles[$idb]->select)) { |
|
| 156 | + $boucles[$idb]->select[] = $t; |
|
| 157 | + } |
|
| 158 | + // renseigner la boucle source de ce champ pour les traitements |
|
| 159 | + $boucles[$idb_origine]->index_champ[$nom_champ_origine] = $idb; |
|
| 160 | + $champ = '$Pile[$SP' . ($i ? "-$i" : '') . '][\'' . $c . '\']'; |
|
| 161 | + if (!$joker) { |
|
| 162 | + return index_compose($conditionnel, $champ); |
|
| 163 | + } |
|
| 164 | + |
|
| 165 | + // tant que l'on trouve des tables avec joker, on continue |
|
| 166 | + // avec la boucle parente et on conditionne à l'exécution |
|
| 167 | + // la présence du champ. Si le champ existe à l'exécution |
|
| 168 | + // dans une boucle, il est pris, sinon on le cherche dans le parent... |
|
| 169 | + $conditionnel[] = "isset($champ)?$champ"; |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + if ($remonte_pile) { |
|
| 173 | + # spip_log("On remonte vers $i"); |
|
| 174 | + // Sinon on remonte d'un cran |
|
| 175 | + $idb = $boucles[$idb]->id_parent; |
|
| 176 | + $i++; |
|
| 177 | + } else { |
|
| 178 | + $idb = null; |
|
| 179 | + } |
|
| 180 | + } |
|
| 181 | + |
|
| 182 | + # spip_log("Pas vu $nom_champ"); |
|
| 183 | + // esperons qu'il y sera |
|
| 184 | + // ou qu'on a fourni une valeur par "defaut" plus pertinent |
|
| 185 | + return index_compose($conditionnel, $defaut); |
|
| 186 | 186 | } |
| 187 | 187 | |
| 188 | 188 | /** |
@@ -196,12 +196,12 @@ discard block |
||
| 196 | 196 | * @return string Code PHP complet de recherche d'un champ |
| 197 | 197 | */ |
| 198 | 198 | function index_compose($conditionnel, $defaut) { |
| 199 | - while ($c = array_pop($conditionnel)) { |
|
| 200 | - // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | - $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | - } |
|
| 199 | + while ($c = array_pop($conditionnel)) { |
|
| 200 | + // si on passe defaut = '', ne pas générer d'erreur de compilation. |
|
| 201 | + $defaut = "($c:(" . ($defaut ?: "''") . '))'; |
|
| 202 | + } |
|
| 203 | 203 | |
| 204 | - return $defaut; |
|
| 204 | + return $defaut; |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | /** |
@@ -237,97 +237,97 @@ discard block |
||
| 237 | 237 | **/ |
| 238 | 238 | function index_tables_en_pile($idb, $nom_champ, &$boucles, &$joker) { |
| 239 | 239 | |
| 240 | - $r = $boucles[$idb]->type_requete; |
|
| 241 | - // boucle recursive, c'est foutu... |
|
| 242 | - if ($r == TYPE_RECURSIF) { |
|
| 243 | - return []; |
|
| 244 | - } |
|
| 245 | - if (!$r) { |
|
| 246 | - $joker = false; // indiquer a l'appelant |
|
| 247 | - # continuer pour chercher l'erreur suivante |
|
| 248 | - return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | - } |
|
| 250 | - |
|
| 251 | - $desc = $boucles[$idb]->show; |
|
| 252 | - // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | - $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | - if ($excep) { |
|
| 255 | - $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | - } |
|
| 257 | - |
|
| 258 | - // il y a un alias connu pour ce champ |
|
| 259 | - if ($excep) { |
|
| 260 | - $joker = false; // indiquer a l'appelant |
|
| 261 | - return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | - } |
|
| 263 | - |
|
| 264 | - // le champ existe dans la table, on le prend. |
|
| 265 | - if (isset($desc['field'][$nom_champ])) { |
|
| 266 | - $t = $boucles[$idb]->id_table ?? ''; |
|
| 267 | - $joker = false; // indiquer a l'appelant |
|
| 268 | - // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 269 | - return ["$t.$nom_champ", $nom_champ]; |
|
| 270 | - } |
|
| 271 | - |
|
| 272 | - // Tous les champs sont-ils acceptés ? |
|
| 273 | - // Si oui, on retourne le champ, et on lève le flag joker |
|
| 274 | - // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 275 | - // et testent la présence du champ à l'exécution et non à la compilation |
|
| 276 | - // car ils ne connaissent pas ici leurs contenus. |
|
| 277 | - if ( |
|
| 278 | - /*$joker AND */ |
|
| 279 | - isset($desc['field']['*']) |
|
| 280 | - ) { |
|
| 281 | - $joker = true; // indiquer a l'appelant |
|
| 282 | - return [$nom_champ, $nom_champ]; |
|
| 283 | - } |
|
| 284 | - |
|
| 285 | - $joker = false; // indiquer a l'appelant |
|
| 286 | - |
|
| 287 | - // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 288 | - if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 289 | - [, $_table, $_nom_champ] = $r; |
|
| 290 | - if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 291 | - $_alias = $cle . '_' . $_nom_champ; |
|
| 292 | - return index_exception( |
|
| 293 | - $boucles[$idb], |
|
| 294 | - $desc, |
|
| 295 | - $_alias, |
|
| 296 | - [$_table, $_nom_champ] |
|
| 297 | - ); |
|
| 298 | - } |
|
| 299 | - return ['', '']; |
|
| 300 | - } |
|
| 301 | - |
|
| 302 | - // pas d'alias, pas de champ, pas de joker... |
|
| 303 | - // tenter via une jointure... |
|
| 304 | - |
|
| 305 | - // regarder si le champ est deja dans une jointure existante |
|
| 306 | - // sinon, si il y a des joitures explicites, la construire |
|
| 307 | - if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 308 | - if ($boucles[$idb]->jointures_explicites) { |
|
| 309 | - // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 310 | - // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 311 | - // mais est-ce ce qu'on veut ? |
|
| 312 | - $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 313 | - if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 314 | - $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 315 | - } |
|
| 316 | - } |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - if ($t) { |
|
| 320 | - // si on a trouvé une jointure possible, on fait comme |
|
| 321 | - // si c'était une exception pour le champ demandé |
|
| 322 | - return index_exception( |
|
| 323 | - $boucles[$idb], |
|
| 324 | - $desc, |
|
| 325 | - $nom_champ, |
|
| 326 | - [$t[1]['id_table'], reset($t[2])] |
|
| 327 | - ); |
|
| 328 | - } |
|
| 329 | - |
|
| 330 | - return ['', '']; |
|
| 240 | + $r = $boucles[$idb]->type_requete; |
|
| 241 | + // boucle recursive, c'est foutu... |
|
| 242 | + if ($r == TYPE_RECURSIF) { |
|
| 243 | + return []; |
|
| 244 | + } |
|
| 245 | + if (!$r) { |
|
| 246 | + $joker = false; // indiquer a l'appelant |
|
| 247 | + # continuer pour chercher l'erreur suivante |
|
| 248 | + return ["'#" . $r . ':' . $nom_champ . "'", '']; |
|
| 249 | + } |
|
| 250 | + |
|
| 251 | + $desc = $boucles[$idb]->show; |
|
| 252 | + // le nom du champ est il une exception de la table ? un alias ? |
|
| 253 | + $excep = $GLOBALS['exceptions_des_tables'][$r] ?? ''; |
|
| 254 | + if ($excep) { |
|
| 255 | + $excep = $excep[$nom_champ] ?? ''; |
|
| 256 | + } |
|
| 257 | + |
|
| 258 | + // il y a un alias connu pour ce champ |
|
| 259 | + if ($excep) { |
|
| 260 | + $joker = false; // indiquer a l'appelant |
|
| 261 | + return index_exception($boucles[$idb], $desc, $nom_champ, $excep); |
|
| 262 | + } |
|
| 263 | + |
|
| 264 | + // le champ existe dans la table, on le prend. |
|
| 265 | + if (isset($desc['field'][$nom_champ])) { |
|
| 266 | + $t = $boucles[$idb]->id_table ?? ''; |
|
| 267 | + $joker = false; // indiquer a l'appelant |
|
| 268 | + // note: dans certains cas ('valeur' d’une boucle DATA, sans id_table), retourne ['.valeur', 'valeur'] … |
|
| 269 | + return ["$t.$nom_champ", $nom_champ]; |
|
| 270 | + } |
|
| 271 | + |
|
| 272 | + // Tous les champs sont-ils acceptés ? |
|
| 273 | + // Si oui, on retourne le champ, et on lève le flag joker |
|
| 274 | + // C'est le cas des itérateurs DATA qui acceptent tout |
|
| 275 | + // et testent la présence du champ à l'exécution et non à la compilation |
|
| 276 | + // car ils ne connaissent pas ici leurs contenus. |
|
| 277 | + if ( |
|
| 278 | + /*$joker AND */ |
|
| 279 | + isset($desc['field']['*']) |
|
| 280 | + ) { |
|
| 281 | + $joker = true; // indiquer a l'appelant |
|
| 282 | + return [$nom_champ, $nom_champ]; |
|
| 283 | + } |
|
| 284 | + |
|
| 285 | + $joker = false; // indiquer a l'appelant |
|
| 286 | + |
|
| 287 | + // la table de jointure est explicitement indiquée (rubrique.titre) |
|
| 288 | + if (preg_match('/^(.*)\.(.*)$/', $nom_champ, $r)) { |
|
| 289 | + [, $_table, $_nom_champ] = $r; |
|
| 290 | + if ($cle = trouver_jointure_champ($_nom_champ, $boucles[$idb], [$_table])) { |
|
| 291 | + $_alias = $cle . '_' . $_nom_champ; |
|
| 292 | + return index_exception( |
|
| 293 | + $boucles[$idb], |
|
| 294 | + $desc, |
|
| 295 | + $_alias, |
|
| 296 | + [$_table, $_nom_champ] |
|
| 297 | + ); |
|
| 298 | + } |
|
| 299 | + return ['', '']; |
|
| 300 | + } |
|
| 301 | + |
|
| 302 | + // pas d'alias, pas de champ, pas de joker... |
|
| 303 | + // tenter via une jointure... |
|
| 304 | + |
|
| 305 | + // regarder si le champ est deja dans une jointure existante |
|
| 306 | + // sinon, si il y a des joitures explicites, la construire |
|
| 307 | + if (!$t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb])) { |
|
| 308 | + if ($boucles[$idb]->jointures_explicites) { |
|
| 309 | + // [todo] Ne pas lancer que lorsque il y a des jointures explicites !!!! |
|
| 310 | + // fonctionnel, il suffit d'utiliser $boucles[$idb]->jointures au lieu de jointures_explicites |
|
| 311 | + // mais est-ce ce qu'on veut ? |
|
| 312 | + $jointures = preg_split('/\s+/', $boucles[$idb]->jointures_explicites); |
|
| 313 | + if ($cle = trouver_jointure_champ($nom_champ, $boucles[$idb], $jointures)) { |
|
| 314 | + $t = trouver_champ_exterieur($nom_champ, $boucles[$idb]->from, $boucles[$idb]); |
|
| 315 | + } |
|
| 316 | + } |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + if ($t) { |
|
| 320 | + // si on a trouvé une jointure possible, on fait comme |
|
| 321 | + // si c'était une exception pour le champ demandé |
|
| 322 | + return index_exception( |
|
| 323 | + $boucles[$idb], |
|
| 324 | + $desc, |
|
| 325 | + $nom_champ, |
|
| 326 | + [$t[1]['id_table'], reset($t[2])] |
|
| 327 | + ); |
|
| 328 | + } |
|
| 329 | + |
|
| 330 | + return ['', '']; |
|
| 331 | 331 | } |
| 332 | 332 | |
| 333 | 333 | |
@@ -355,52 +355,52 @@ discard block |
||
| 355 | 355 | * est une expression pour le SELECT de la boucle du style "mots.titre AS titre_mot" |
| 356 | 356 | **/ |
| 357 | 357 | function index_exception(&$boucle, $desc, $nom_champ, $excep) { |
| 358 | - static $trouver_table; |
|
| 359 | - if (!$trouver_table) { |
|
| 360 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 361 | - } |
|
| 362 | - |
|
| 363 | - if (is_array($excep)) { |
|
| 364 | - // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 365 | - $t = null; |
|
| 366 | - if (count($excep) == 3) { |
|
| 367 | - $index_exception_derogatoire = array_pop($excep); |
|
| 368 | - $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 369 | - } |
|
| 370 | - if ($t == null) { |
|
| 371 | - [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 372 | - $excep = $x; #PHP5 de droite a gauche ! |
|
| 373 | - $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 374 | - if (!$j) { |
|
| 375 | - return ['', '']; |
|
| 376 | - } |
|
| 377 | - $e = $j['table']; |
|
| 378 | - if (!$t = array_search($e, $boucle->from)) { |
|
| 379 | - $k = $j['key']['PRIMARY KEY']; |
|
| 380 | - if (strpos($k, ',')) { |
|
| 381 | - $l = (preg_split('/\s*,\s*/', $k)); |
|
| 382 | - $k = $desc['key']['PRIMARY KEY']; |
|
| 383 | - if (!in_array($k, $l)) { |
|
| 384 | - spip_log("jointure impossible $e " . join(',', $l)); |
|
| 385 | - |
|
| 386 | - return ['', '']; |
|
| 387 | - } |
|
| 388 | - } |
|
| 389 | - $k = [$boucle->id_table, [$e], $k]; |
|
| 390 | - fabrique_jointures($boucle, [$k]); |
|
| 391 | - $t = array_search($e, $boucle->from); |
|
| 392 | - } |
|
| 393 | - } |
|
| 394 | - } else { |
|
| 395 | - $t = $boucle->id_table; |
|
| 396 | - } |
|
| 397 | - // demander a SQL de gerer le synonyme |
|
| 398 | - // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 399 | - if ($excep != $nom_champ) { |
|
| 400 | - $excep .= ' AS ' . $nom_champ; |
|
| 401 | - } |
|
| 402 | - |
|
| 403 | - return ["$t.$excep", $nom_champ]; |
|
| 358 | + static $trouver_table; |
|
| 359 | + if (!$trouver_table) { |
|
| 360 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 361 | + } |
|
| 362 | + |
|
| 363 | + if (is_array($excep)) { |
|
| 364 | + // permettre aux plugins de gerer eux meme des jointures derogatoire ingerables |
|
| 365 | + $t = null; |
|
| 366 | + if (count($excep) == 3) { |
|
| 367 | + $index_exception_derogatoire = array_pop($excep); |
|
| 368 | + $t = $index_exception_derogatoire($boucle, $desc, $nom_champ, $excep); |
|
| 369 | + } |
|
| 370 | + if ($t == null) { |
|
| 371 | + [$e, $x] = $excep; #PHP4 affecte de gauche a droite |
|
| 372 | + $excep = $x; #PHP5 de droite a gauche ! |
|
| 373 | + $j = $trouver_table($e, $boucle->sql_serveur); |
|
| 374 | + if (!$j) { |
|
| 375 | + return ['', '']; |
|
| 376 | + } |
|
| 377 | + $e = $j['table']; |
|
| 378 | + if (!$t = array_search($e, $boucle->from)) { |
|
| 379 | + $k = $j['key']['PRIMARY KEY']; |
|
| 380 | + if (strpos($k, ',')) { |
|
| 381 | + $l = (preg_split('/\s*,\s*/', $k)); |
|
| 382 | + $k = $desc['key']['PRIMARY KEY']; |
|
| 383 | + if (!in_array($k, $l)) { |
|
| 384 | + spip_log("jointure impossible $e " . join(',', $l)); |
|
| 385 | + |
|
| 386 | + return ['', '']; |
|
| 387 | + } |
|
| 388 | + } |
|
| 389 | + $k = [$boucle->id_table, [$e], $k]; |
|
| 390 | + fabrique_jointures($boucle, [$k]); |
|
| 391 | + $t = array_search($e, $boucle->from); |
|
| 392 | + } |
|
| 393 | + } |
|
| 394 | + } else { |
|
| 395 | + $t = $boucle->id_table; |
|
| 396 | + } |
|
| 397 | + // demander a SQL de gerer le synonyme |
|
| 398 | + // ca permet que excep soit dynamique (Cedric, 2/3/06) |
|
| 399 | + if ($excep != $nom_champ) { |
|
| 400 | + $excep .= ' AS ' . $nom_champ; |
|
| 401 | + } |
|
| 402 | + |
|
| 403 | + return ["$t.$excep", $nom_champ]; |
|
| 404 | 404 | } |
| 405 | 405 | |
| 406 | 406 | /** |
@@ -425,7 +425,7 @@ discard block |
||
| 425 | 425 | * Code PHP pour retrouver le champ |
| 426 | 426 | */ |
| 427 | 427 | function champ_sql($champ, $p, $defaut = null, $remonte_pile = true) { |
| 428 | - return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 428 | + return index_pile($p->id_boucle, $champ, $p->boucles, $p->nom_boucle, $defaut, $remonte_pile); |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | |
@@ -445,9 +445,9 @@ discard block |
||
| 445 | 445 | * Code PHP pour d'exécution de la balise et de ses filtres |
| 446 | 446 | **/ |
| 447 | 447 | function calculer_champ($p) { |
| 448 | - $p = calculer_balise($p->nom_champ, $p); |
|
| 448 | + $p = calculer_balise($p->nom_champ, $p); |
|
| 449 | 449 | |
| 450 | - return applique_filtres($p); |
|
| 450 | + return applique_filtres($p); |
|
| 451 | 451 | } |
| 452 | 452 | |
| 453 | 453 | |
@@ -484,26 +484,26 @@ discard block |
||
| 484 | 484 | **/ |
| 485 | 485 | function calculer_balise(string $nom, \Champ $p): \Champ { |
| 486 | 486 | |
| 487 | - // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 488 | - if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 489 | - $p->balise_calculee = true; |
|
| 490 | - $res = $f($p); |
|
| 491 | - if ($res !== null and is_object($res)) { |
|
| 492 | - return $res; |
|
| 493 | - } |
|
| 494 | - } |
|
| 495 | - |
|
| 496 | - // Certaines des balises comportant un _ sont generiques |
|
| 497 | - if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 498 | - $res = $balise_generique['fonction_generique']($p); |
|
| 499 | - if ($res !== null and is_object($res)) { |
|
| 500 | - return $res; |
|
| 501 | - } |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 505 | - |
|
| 506 | - return $f($nom, $p); |
|
| 487 | + // S'agit-t-il d'une balise_XXXX[_dist]() ? |
|
| 488 | + if ($f = charger_fonction($nom, 'balise', true)) { |
|
| 489 | + $p->balise_calculee = true; |
|
| 490 | + $res = $f($p); |
|
| 491 | + if ($res !== null and is_object($res)) { |
|
| 492 | + return $res; |
|
| 493 | + } |
|
| 494 | + } |
|
| 495 | + |
|
| 496 | + // Certaines des balises comportant un _ sont generiques |
|
| 497 | + if ($balise_generique = chercher_balise_generique($nom)) { |
|
| 498 | + $res = $balise_generique['fonction_generique']($p); |
|
| 499 | + if ($res !== null and is_object($res)) { |
|
| 500 | + return $res; |
|
| 501 | + } |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $f = charger_fonction('DEFAUT', 'calculer_balise'); |
|
| 505 | + |
|
| 506 | + return $f($nom, $p); |
|
| 507 | 507 | } |
| 508 | 508 | |
| 509 | 509 | |
@@ -531,37 +531,37 @@ discard block |
||
| 531 | 531 | **/ |
| 532 | 532 | function calculer_balise_DEFAUT_dist($nom, $p) { |
| 533 | 533 | |
| 534 | - // ca pourrait etre un champ SQL homonyme, |
|
| 535 | - $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 536 | - |
|
| 537 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 538 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 539 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 540 | - $code = addslashes($p->fonctions[0][1]); |
|
| 541 | - $p->code .= " . '$code'"; |
|
| 542 | - } |
|
| 543 | - |
|
| 544 | - // ne pas passer le filtre securite sur les id_xxx |
|
| 545 | - if (strpos($nom, 'ID_') === 0) { |
|
| 546 | - $p->interdire_scripts = false; |
|
| 547 | - } |
|
| 548 | - |
|
| 549 | - // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 550 | - // SI le champ SQL n'est pas trouve |
|
| 551 | - // ET si la balise a une forme de couleur |
|
| 552 | - // ET s'il n'y a ni filtre ni etoile |
|
| 553 | - // ALORS retourner la couleur. |
|
| 554 | - // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 555 | - if ( |
|
| 556 | - preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 557 | - and !$p->etoile |
|
| 558 | - and !$p->fonctions |
|
| 559 | - ) { |
|
| 560 | - $p->code = "'#$nom'"; |
|
| 561 | - $p->interdire_scripts = false; |
|
| 562 | - } |
|
| 563 | - |
|
| 564 | - return $p; |
|
| 534 | + // ca pourrait etre un champ SQL homonyme, |
|
| 535 | + $p->code = index_pile($p->id_boucle, $nom, $p->boucles, $p->nom_boucle); |
|
| 536 | + |
|
| 537 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 538 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 539 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 540 | + $code = addslashes($p->fonctions[0][1]); |
|
| 541 | + $p->code .= " . '$code'"; |
|
| 542 | + } |
|
| 543 | + |
|
| 544 | + // ne pas passer le filtre securite sur les id_xxx |
|
| 545 | + if (strpos($nom, 'ID_') === 0) { |
|
| 546 | + $p->interdire_scripts = false; |
|
| 547 | + } |
|
| 548 | + |
|
| 549 | + // Compatibilite ascendante avec les couleurs html (#FEFEFE) : |
|
| 550 | + // SI le champ SQL n'est pas trouve |
|
| 551 | + // ET si la balise a une forme de couleur |
|
| 552 | + // ET s'il n'y a ni filtre ni etoile |
|
| 553 | + // ALORS retourner la couleur. |
|
| 554 | + // Ca permet si l'on veut vraiment de recuperer [(#ACCEDE*)] |
|
| 555 | + if ( |
|
| 556 | + preg_match('/^[A-F]{1,6}$/i', $nom) |
|
| 557 | + and !$p->etoile |
|
| 558 | + and !$p->fonctions |
|
| 559 | + ) { |
|
| 560 | + $p->code = "'#$nom'"; |
|
| 561 | + $p->interdire_scripts = false; |
|
| 562 | + } |
|
| 563 | + |
|
| 564 | + return $p; |
|
| 565 | 565 | } |
| 566 | 566 | |
| 567 | 567 | |
@@ -604,39 +604,39 @@ discard block |
||
| 604 | 604 | **/ |
| 605 | 605 | function calculer_balise_dynamique($p, $nom, $l, $supp = []) { |
| 606 | 606 | |
| 607 | - if (!balise_distante_interdite($p)) { |
|
| 608 | - $p->code = "''"; |
|
| 609 | - |
|
| 610 | - return $p; |
|
| 611 | - } |
|
| 612 | - // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 613 | - // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 614 | - if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 615 | - $p->fonctions = []; |
|
| 616 | - } |
|
| 617 | - |
|
| 618 | - if ($p->param and ($c = $p->param[0])) { |
|
| 619 | - // liste d'arguments commence toujours par la chaine vide |
|
| 620 | - array_shift($c); |
|
| 621 | - // construire la liste d'arguments comme pour un filtre |
|
| 622 | - $param = compose_filtres_args($p, $c, ','); |
|
| 623 | - } else { |
|
| 624 | - $param = ''; |
|
| 625 | - } |
|
| 626 | - $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 627 | - |
|
| 628 | - $p->code = sprintf( |
|
| 629 | - CODE_EXECUTER_BALISE, |
|
| 630 | - $nom, |
|
| 631 | - join(',', $collecte), |
|
| 632 | - ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 633 | - memoriser_contexte_compil($p), |
|
| 634 | - (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 635 | - ); |
|
| 636 | - |
|
| 637 | - $p->interdire_scripts = false; |
|
| 638 | - |
|
| 639 | - return $p; |
|
| 607 | + if (!balise_distante_interdite($p)) { |
|
| 608 | + $p->code = "''"; |
|
| 609 | + |
|
| 610 | + return $p; |
|
| 611 | + } |
|
| 612 | + // compatibilite: depuis qu'on accepte #BALISE{ses_args} sans [(...)] autour |
|
| 613 | + // il faut recracher {...} quand ce n'est finalement pas des args |
|
| 614 | + if ($p->fonctions and (!$p->fonctions[0][0]) and $p->fonctions[0][1]) { |
|
| 615 | + $p->fonctions = []; |
|
| 616 | + } |
|
| 617 | + |
|
| 618 | + if ($p->param and ($c = $p->param[0])) { |
|
| 619 | + // liste d'arguments commence toujours par la chaine vide |
|
| 620 | + array_shift($c); |
|
| 621 | + // construire la liste d'arguments comme pour un filtre |
|
| 622 | + $param = compose_filtres_args($p, $c, ','); |
|
| 623 | + } else { |
|
| 624 | + $param = ''; |
|
| 625 | + } |
|
| 626 | + $collecte = collecter_balise_dynamique($l, $p, $nom); |
|
| 627 | + |
|
| 628 | + $p->code = sprintf( |
|
| 629 | + CODE_EXECUTER_BALISE, |
|
| 630 | + $nom, |
|
| 631 | + join(',', $collecte), |
|
| 632 | + ($collecte ? $param : substr($param, 1)), # virer la virgule |
|
| 633 | + memoriser_contexte_compil($p), |
|
| 634 | + (!$supp ? '' : (', ' . join(',', $supp))) |
|
| 635 | + ); |
|
| 636 | + |
|
| 637 | + $p->interdire_scripts = false; |
|
| 638 | + |
|
| 639 | + return $p; |
|
| 640 | 640 | } |
| 641 | 641 | |
| 642 | 642 | |
@@ -666,17 +666,17 @@ discard block |
||
| 666 | 666 | * Liste des codes PHP d'éxecution des balises collectées |
| 667 | 667 | **/ |
| 668 | 668 | function collecter_balise_dynamique(array $l, \Champ &$p, string $nom): array { |
| 669 | - $args = []; |
|
| 670 | - foreach ($l as $c) { |
|
| 671 | - if ($c === null) { |
|
| 672 | - $args[] = 'null'; |
|
| 673 | - } else { |
|
| 674 | - $x = calculer_balise($c, $p); |
|
| 675 | - $args[] = $x->code; |
|
| 676 | - } |
|
| 677 | - } |
|
| 678 | - |
|
| 679 | - return $args; |
|
| 669 | + $args = []; |
|
| 670 | + foreach ($l as $c) { |
|
| 671 | + if ($c === null) { |
|
| 672 | + $args[] = 'null'; |
|
| 673 | + } else { |
|
| 674 | + $x = calculer_balise($c, $p); |
|
| 675 | + $args[] = $x->code; |
|
| 676 | + } |
|
| 677 | + } |
|
| 678 | + |
|
| 679 | + return $args; |
|
| 680 | 680 | } |
| 681 | 681 | |
| 682 | 682 | |
@@ -691,22 +691,22 @@ discard block |
||
| 691 | 691 | * Nom de la connexion |
| 692 | 692 | **/ |
| 693 | 693 | function trouver_nom_serveur_distant($p) { |
| 694 | - $nom = $p->id_boucle; |
|
| 695 | - if ( |
|
| 696 | - $nom |
|
| 697 | - and isset($p->boucles[$nom]) |
|
| 698 | - ) { |
|
| 699 | - $s = $p->boucles[$nom]->sql_serveur; |
|
| 700 | - if ( |
|
| 701 | - strlen($s) |
|
| 702 | - and strlen($serveur = strtolower($s)) |
|
| 703 | - and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 704 | - ) { |
|
| 705 | - return $serveur; |
|
| 706 | - } |
|
| 707 | - } |
|
| 708 | - |
|
| 709 | - return ''; |
|
| 694 | + $nom = $p->id_boucle; |
|
| 695 | + if ( |
|
| 696 | + $nom |
|
| 697 | + and isset($p->boucles[$nom]) |
|
| 698 | + ) { |
|
| 699 | + $s = $p->boucles[$nom]->sql_serveur; |
|
| 700 | + if ( |
|
| 701 | + strlen($s) |
|
| 702 | + and strlen($serveur = strtolower($s)) |
|
| 703 | + and !in_array($serveur, $GLOBALS['exception_des_connect']) |
|
| 704 | + ) { |
|
| 705 | + return $serveur; |
|
| 706 | + } |
|
| 707 | + } |
|
| 708 | + |
|
| 709 | + return ''; |
|
| 710 | 710 | } |
| 711 | 711 | |
| 712 | 712 | |
@@ -730,15 +730,15 @@ discard block |
||
| 730 | 730 | * - false : La balise est interdite car le serveur est distant |
| 731 | 731 | **/ |
| 732 | 732 | function balise_distante_interdite($p) { |
| 733 | - $nom = $p->id_boucle; |
|
| 733 | + $nom = $p->id_boucle; |
|
| 734 | 734 | |
| 735 | - if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 736 | - spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 735 | + if ($nom and trouver_nom_serveur_distant($p)) { |
|
| 736 | + spip_log($nom . ':' . $p->nom_champ . ' ' . _T('zbug_distant_interdit')); |
|
| 737 | 737 | |
| 738 | - return false; |
|
| 739 | - } |
|
| 738 | + return false; |
|
| 739 | + } |
|
| 740 | 740 | |
| 741 | - return true; |
|
| 741 | + return true; |
|
| 742 | 742 | } |
| 743 | 743 | |
| 744 | 744 | |
@@ -748,84 +748,84 @@ discard block |
||
| 748 | 748 | // |
| 749 | 749 | function champs_traitements($p) { |
| 750 | 750 | |
| 751 | - if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 752 | - $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 753 | - } else { |
|
| 754 | - // quand on utilise un traitement catch-all * |
|
| 755 | - // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 756 | - // leur propre securite |
|
| 757 | - if (!$p->balise_calculee) { |
|
| 758 | - $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 759 | - } else { |
|
| 760 | - $ps = false; |
|
| 761 | - } |
|
| 762 | - } |
|
| 763 | - |
|
| 764 | - if (is_array($ps)) { |
|
| 765 | - // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 766 | - $idb = index_boucle($p); |
|
| 767 | - // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 768 | - if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 769 | - $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 770 | - } |
|
| 771 | - |
|
| 772 | - // mais on peut aussi etre hors boucle. Se mefier. |
|
| 773 | - $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 774 | - $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 775 | - |
|
| 776 | - // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 777 | - if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 778 | - $type_alias = $type_requete; |
|
| 779 | - $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 780 | - } else { |
|
| 781 | - $type_alias = false; |
|
| 782 | - } |
|
| 783 | - |
|
| 784 | - // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 785 | - if ($table_sql and isset($ps[$table_sql])) { |
|
| 786 | - $ps = $ps[$table_sql]; |
|
| 787 | - } // ou pour une boucle en particulier "DATA","articles" |
|
| 788 | - elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 789 | - $ps = $ps[$type_requete]; |
|
| 790 | - } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 791 | - elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 792 | - $ps = $ps[$type_alias]; |
|
| 793 | - } // ou pour indifféremment quelle que soit la boucle |
|
| 794 | - elseif (isset($ps[0])) { |
|
| 795 | - $ps = $ps[0]; |
|
| 796 | - } else { |
|
| 797 | - $ps = false; |
|
| 798 | - } |
|
| 799 | - } |
|
| 800 | - |
|
| 801 | - if (!$ps) { |
|
| 802 | - return $p->code; |
|
| 803 | - } |
|
| 804 | - |
|
| 805 | - // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 806 | - // ou si in INCLURE contient {doublons} |
|
| 807 | - // on insere une fonction de remplissage du tableau des doublons |
|
| 808 | - // dans les filtres propre() ou typo() |
|
| 809 | - // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 810 | - |
|
| 811 | - if ( |
|
| 812 | - isset($p->descr['documents']) |
|
| 813 | - and |
|
| 814 | - $p->descr['documents'] |
|
| 815 | - and ( |
|
| 816 | - (strpos($ps, 'propre') !== false) |
|
| 817 | - or |
|
| 818 | - (strpos($ps, 'typo') !== false) |
|
| 819 | - ) |
|
| 820 | - ) { |
|
| 821 | - $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 822 | - } |
|
| 823 | - |
|
| 824 | - // La protection des champs par |safehtml est assuree par les extensions |
|
| 825 | - // dans la declaration des traitements des champs sensibles |
|
| 826 | - |
|
| 827 | - // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 828 | - return str_replace('%s', $p->code, $ps); |
|
| 751 | + if (isset($GLOBALS['table_des_traitements'][$p->nom_champ])) { |
|
| 752 | + $ps = $GLOBALS['table_des_traitements'][$p->nom_champ]; |
|
| 753 | + } else { |
|
| 754 | + // quand on utilise un traitement catch-all * |
|
| 755 | + // celui-ci ne s'applique pas sur les balises calculees qui peuvent gerer |
|
| 756 | + // leur propre securite |
|
| 757 | + if (!$p->balise_calculee) { |
|
| 758 | + $ps = $GLOBALS['table_des_traitements']['*']; |
|
| 759 | + } else { |
|
| 760 | + $ps = false; |
|
| 761 | + } |
|
| 762 | + } |
|
| 763 | + |
|
| 764 | + if (is_array($ps)) { |
|
| 765 | + // Recuperer le type de boucle (articles, DATA) et la table SQL sur laquelle elle porte |
|
| 766 | + $idb = index_boucle($p); |
|
| 767 | + // si le champ a ete trouve dans une boucle parente sa source est renseignee ici |
|
| 768 | + if (!empty($p->boucles[$idb]->index_champ[$p->nom_champ])) { |
|
| 769 | + $idb = $p->boucles[$idb]->index_champ[$p->nom_champ]; |
|
| 770 | + } |
|
| 771 | + |
|
| 772 | + // mais on peut aussi etre hors boucle. Se mefier. |
|
| 773 | + $type_requete = $p->boucles[$idb]->type_requete ?? false; |
|
| 774 | + $table_sql = $p->boucles[$idb]->show['table_sql'] ?? false; |
|
| 775 | + |
|
| 776 | + // bien prendre en compte les alias de boucles (hierarchie => rubrique, syndication => syncdic, etc.) |
|
| 777 | + if ($type_requete and isset($GLOBALS['table_des_tables'][$type_requete])) { |
|
| 778 | + $type_alias = $type_requete; |
|
| 779 | + $type_requete = $GLOBALS['table_des_tables'][$type_requete]; |
|
| 780 | + } else { |
|
| 781 | + $type_alias = false; |
|
| 782 | + } |
|
| 783 | + |
|
| 784 | + // le traitement peut n'etre defini que pour une table en particulier "spip_articles" |
|
| 785 | + if ($table_sql and isset($ps[$table_sql])) { |
|
| 786 | + $ps = $ps[$table_sql]; |
|
| 787 | + } // ou pour une boucle en particulier "DATA","articles" |
|
| 788 | + elseif ($type_requete and isset($ps[$type_requete])) { |
|
| 789 | + $ps = $ps[$type_requete]; |
|
| 790 | + } // ou pour une boucle utilisant un alias ("hierarchie") |
|
| 791 | + elseif ($type_alias and isset($ps[$type_alias])) { |
|
| 792 | + $ps = $ps[$type_alias]; |
|
| 793 | + } // ou pour indifféremment quelle que soit la boucle |
|
| 794 | + elseif (isset($ps[0])) { |
|
| 795 | + $ps = $ps[0]; |
|
| 796 | + } else { |
|
| 797 | + $ps = false; |
|
| 798 | + } |
|
| 799 | + } |
|
| 800 | + |
|
| 801 | + if (!$ps) { |
|
| 802 | + return $p->code; |
|
| 803 | + } |
|
| 804 | + |
|
| 805 | + // Si une boucle DOCUMENTS{doublons} est presente dans le squelette, |
|
| 806 | + // ou si in INCLURE contient {doublons} |
|
| 807 | + // on insere une fonction de remplissage du tableau des doublons |
|
| 808 | + // dans les filtres propre() ou typo() |
|
| 809 | + // (qui traitent les raccourcis <docXX> referencant les docs) |
|
| 810 | + |
|
| 811 | + if ( |
|
| 812 | + isset($p->descr['documents']) |
|
| 813 | + and |
|
| 814 | + $p->descr['documents'] |
|
| 815 | + and ( |
|
| 816 | + (strpos($ps, 'propre') !== false) |
|
| 817 | + or |
|
| 818 | + (strpos($ps, 'typo') !== false) |
|
| 819 | + ) |
|
| 820 | + ) { |
|
| 821 | + $ps = 'traiter_doublons_documents($doublons, ' . $ps . ')'; |
|
| 822 | + } |
|
| 823 | + |
|
| 824 | + // La protection des champs par |safehtml est assuree par les extensions |
|
| 825 | + // dans la declaration des traitements des champs sensibles |
|
| 826 | + |
|
| 827 | + // Remplacer enfin le placeholder %s par le vrai code de la balise |
|
| 828 | + return str_replace('%s', $p->code, $ps); |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | |
@@ -837,110 +837,110 @@ discard block |
||
| 837 | 837 | // |
| 838 | 838 | function applique_filtres($p) { |
| 839 | 839 | |
| 840 | - // Traitements standards (cf. supra) |
|
| 841 | - if ($p->etoile == '') { |
|
| 842 | - $code = champs_traitements($p); |
|
| 843 | - } else { |
|
| 844 | - $code = $p->code; |
|
| 845 | - } |
|
| 840 | + // Traitements standards (cf. supra) |
|
| 841 | + if ($p->etoile == '') { |
|
| 842 | + $code = champs_traitements($p); |
|
| 843 | + } else { |
|
| 844 | + $code = $p->code; |
|
| 845 | + } |
|
| 846 | 846 | |
| 847 | - // Appliquer les filtres perso |
|
| 848 | - if ($p->param) { |
|
| 849 | - $code = compose_filtres($p, $code); |
|
| 850 | - } |
|
| 847 | + // Appliquer les filtres perso |
|
| 848 | + if ($p->param) { |
|
| 849 | + $code = compose_filtres($p, $code); |
|
| 850 | + } |
|
| 851 | 851 | |
| 852 | - // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 853 | - // un drapeau dans la structure d'invalidation $Cache |
|
| 854 | - if (isset($p->descr['session'])) { |
|
| 855 | - $code = "invalideur_session(\$Cache, $code)"; |
|
| 856 | - } |
|
| 852 | + // S'il y a un lien avec la session, ajouter un code qui levera |
|
| 853 | + // un drapeau dans la structure d'invalidation $Cache |
|
| 854 | + if (isset($p->descr['session'])) { |
|
| 855 | + $code = "invalideur_session(\$Cache, $code)"; |
|
| 856 | + } |
|
| 857 | 857 | |
| 858 | - $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 858 | + $code = sandbox_composer_interdire_scripts($code, $p); |
|
| 859 | 859 | |
| 860 | - return $code; |
|
| 860 | + return $code; |
|
| 861 | 861 | } |
| 862 | 862 | |
| 863 | 863 | // Cf. function pipeline dans ecrire/inc_utils.php |
| 864 | 864 | function compose_filtres(&$p, $code) { |
| 865 | 865 | |
| 866 | - $image_miette = false; |
|
| 867 | - foreach ($p->param as $filtre) { |
|
| 868 | - $fonc = array_shift($filtre); |
|
| 869 | - if (!$fonc) { |
|
| 870 | - continue; |
|
| 871 | - } // normalement qu'au premier tour. |
|
| 872 | - $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 873 | - if ($image_miette and !$is_filtre_image) { |
|
| 874 | - // il faut graver maintenant car apres le filtre en cours |
|
| 875 | - // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 876 | - $code = "filtrer('image_graver', $code)"; |
|
| 877 | - $image_miette = false; |
|
| 878 | - } |
|
| 879 | - |
|
| 880 | - // recuperer les arguments du filtre, |
|
| 881 | - // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 882 | - $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 883 | - if ($fonc !== '?') { |
|
| 884 | - $sep = ','; |
|
| 885 | - } else { |
|
| 886 | - $sep = ':'; |
|
| 887 | - // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 888 | - if ($countfiltre != 2) { |
|
| 889 | - $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 890 | - $countfiltre = 2; |
|
| 891 | - } |
|
| 892 | - } |
|
| 893 | - $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 894 | - $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 895 | - if ($logique) { |
|
| 896 | - $code = $logique; |
|
| 897 | - } else { |
|
| 898 | - $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 899 | - if ($is_filtre_image) { |
|
| 900 | - $image_miette = true; |
|
| 901 | - } |
|
| 902 | - } |
|
| 903 | - } |
|
| 904 | - // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 905 | - if ($image_miette) { |
|
| 906 | - $code = "filtrer('image_graver',$code)"; |
|
| 907 | - } |
|
| 908 | - |
|
| 909 | - return $code; |
|
| 866 | + $image_miette = false; |
|
| 867 | + foreach ($p->param as $filtre) { |
|
| 868 | + $fonc = array_shift($filtre); |
|
| 869 | + if (!$fonc) { |
|
| 870 | + continue; |
|
| 871 | + } // normalement qu'au premier tour. |
|
| 872 | + $is_filtre_image = ((substr($fonc, 0, 6) == 'image_') and $fonc != 'image_graver'); |
|
| 873 | + if ($image_miette and !$is_filtre_image) { |
|
| 874 | + // il faut graver maintenant car apres le filtre en cours |
|
| 875 | + // on est pas sur d'avoir encore le nom du fichier dans le pipe |
|
| 876 | + $code = "filtrer('image_graver', $code)"; |
|
| 877 | + $image_miette = false; |
|
| 878 | + } |
|
| 879 | + |
|
| 880 | + // recuperer les arguments du filtre, |
|
| 881 | + // a separer par "," ou ":" dans le cas du filtre "?{a,b}" |
|
| 882 | + $countfiltre = is_countable($filtre) ? count($filtre) : 0; |
|
| 883 | + if ($fonc !== '?') { |
|
| 884 | + $sep = ','; |
|
| 885 | + } else { |
|
| 886 | + $sep = ':'; |
|
| 887 | + // |?{a,b} *doit* avoir exactement 2 arguments ; on les force |
|
| 888 | + if ($countfiltre != 2) { |
|
| 889 | + $filtre = [$filtre[0] ?? '', $filtre[1] ?? '']; |
|
| 890 | + $countfiltre = 2; |
|
| 891 | + } |
|
| 892 | + } |
|
| 893 | + $arglist = compose_filtres_args($p, $filtre, $sep); |
|
| 894 | + $logique = filtre_logique($fonc, $code, substr($arglist, 1)); |
|
| 895 | + if ($logique) { |
|
| 896 | + $code = $logique; |
|
| 897 | + } else { |
|
| 898 | + $code = sandbox_composer_filtre($fonc, $code, $arglist, $p, $countfiltre); |
|
| 899 | + if ($is_filtre_image) { |
|
| 900 | + $image_miette = true; |
|
| 901 | + } |
|
| 902 | + } |
|
| 903 | + } |
|
| 904 | + // ramasser les images intermediaires inutiles et graver l'image finale |
|
| 905 | + if ($image_miette) { |
|
| 906 | + $code = "filtrer('image_graver',$code)"; |
|
| 907 | + } |
|
| 908 | + |
|
| 909 | + return $code; |
|
| 910 | 910 | } |
| 911 | 911 | |
| 912 | 912 | // Filtres et,ou,oui,non,sinon,xou,xor,and,or,not,yes |
| 913 | 913 | // et comparateurs |
| 914 | 914 | function filtre_logique($fonc, $code, $arg) { |
| 915 | 915 | |
| 916 | - switch (true) { |
|
| 917 | - case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 918 | - return "($code $fonc $arg)"; |
|
| 919 | - case ($fonc == 'and') or ($fonc == 'et'): |
|
| 920 | - return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 921 | - case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 922 | - return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 923 | - case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 924 | - return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 925 | - case ($fonc == 'sinon'): |
|
| 926 | - return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 927 | - case ($fonc == 'not') or ($fonc == 'non'): |
|
| 928 | - return "(($code) ?'' :' ')"; |
|
| 929 | - case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 930 | - return "(($code) ?' ' :'')"; |
|
| 931 | - } |
|
| 932 | - |
|
| 933 | - return ''; |
|
| 916 | + switch (true) { |
|
| 917 | + case in_array($fonc, $GLOBALS['table_criteres_infixes']): |
|
| 918 | + return "($code $fonc $arg)"; |
|
| 919 | + case ($fonc == 'and') or ($fonc == 'et'): |
|
| 920 | + return "((($code) AND ($arg)) ?' ' :'')"; |
|
| 921 | + case ($fonc == 'or') or ($fonc == 'ou'): |
|
| 922 | + return "((($code) OR ($arg)) ?' ' :'')"; |
|
| 923 | + case ($fonc == 'xor') or ($fonc == 'xou'): |
|
| 924 | + return "((($code) XOR ($arg)) ?' ' :'')"; |
|
| 925 | + case ($fonc == 'sinon'): |
|
| 926 | + return "(((\$a = $code) OR (is_string(\$a) AND strlen(\$a))) ? \$a : $arg)"; |
|
| 927 | + case ($fonc == 'not') or ($fonc == 'non'): |
|
| 928 | + return "(($code) ?'' :' ')"; |
|
| 929 | + case ($fonc == 'yes') or ($fonc == 'oui'): |
|
| 930 | + return "(($code) ?' ' :'')"; |
|
| 931 | + } |
|
| 932 | + |
|
| 933 | + return ''; |
|
| 934 | 934 | } |
| 935 | 935 | |
| 936 | 936 | function compose_filtres_args($p, $args, $sep) { |
| 937 | - $arglist = ''; |
|
| 938 | - foreach ($args as $arg) { |
|
| 939 | - $arglist .= $sep . |
|
| 940 | - calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 941 | - } |
|
| 937 | + $arglist = ''; |
|
| 938 | + foreach ($args as $arg) { |
|
| 939 | + $arglist .= $sep . |
|
| 940 | + calculer_liste($arg, $p->descr, $p->boucles, $p->id_boucle); |
|
| 941 | + } |
|
| 942 | 942 | |
| 943 | - return $arglist; |
|
| 943 | + return $arglist; |
|
| 944 | 944 | } |
| 945 | 945 | |
| 946 | 946 | |
@@ -958,15 +958,15 @@ discard block |
||
| 958 | 958 | **/ |
| 959 | 959 | function calculer_argument_precedent($idb, $nom_champ, &$boucles, $defaut = null) { |
| 960 | 960 | |
| 961 | - // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 962 | - if ($boucles[$idb]->externe) { |
|
| 963 | - index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 964 | - // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 965 | - // on ignore le defaut fourni dans ce cas |
|
| 966 | - $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 967 | - } |
|
| 961 | + // si recursif, forcer l'extraction du champ SQL mais ignorer le code |
|
| 962 | + if ($boucles[$idb]->externe) { |
|
| 963 | + index_pile($idb, $nom_champ, $boucles, '', $defaut); |
|
| 964 | + // retourner $Pile[$SP] et pas $Pile[0] si recursion en 1ere boucle |
|
| 965 | + // on ignore le defaut fourni dans ce cas |
|
| 966 | + $defaut = "(\$Pile[\$SP]['$nom_champ'] ?? null)"; |
|
| 967 | + } |
|
| 968 | 968 | |
| 969 | - return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 969 | + return index_pile($boucles[$idb]->id_parent, $nom_champ, $boucles, '', $defaut); |
|
| 970 | 970 | } |
| 971 | 971 | |
| 972 | 972 | // |
@@ -980,30 +980,30 @@ discard block |
||
| 980 | 980 | // |
| 981 | 981 | |
| 982 | 982 | function rindex_pile($p, $champ, $motif) { |
| 983 | - $n = 0; |
|
| 984 | - $b = $p->id_boucle; |
|
| 985 | - $p->code = ''; |
|
| 986 | - while ($b != '') { |
|
| 987 | - foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 988 | - if ($critere->op == $motif) { |
|
| 989 | - $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 990 | - "]['$champ']"; |
|
| 991 | - $b = ''; |
|
| 992 | - break 2; |
|
| 993 | - } |
|
| 994 | - } |
|
| 995 | - $n++; |
|
| 996 | - $b = $p->boucles[$b]->id_parent; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1000 | - if (!$p->code) { |
|
| 1001 | - $p->code = "''"; |
|
| 1002 | - } |
|
| 1003 | - |
|
| 1004 | - $p->interdire_scripts = false; |
|
| 1005 | - |
|
| 1006 | - return $p; |
|
| 983 | + $n = 0; |
|
| 984 | + $b = $p->id_boucle; |
|
| 985 | + $p->code = ''; |
|
| 986 | + while ($b != '') { |
|
| 987 | + foreach ($p->boucles[$b]->criteres as $critere) { |
|
| 988 | + if ($critere->op == $motif) { |
|
| 989 | + $p->code = '$Pile[$SP' . (($n == 0) ? '' : "-$n") . |
|
| 990 | + "]['$champ']"; |
|
| 991 | + $b = ''; |
|
| 992 | + break 2; |
|
| 993 | + } |
|
| 994 | + } |
|
| 995 | + $n++; |
|
| 996 | + $b = $p->boucles[$b]->id_parent; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + // si on est hors d'une boucle de {recherche}, cette balise est vide |
|
| 1000 | + if (!$p->code) { |
|
| 1001 | + $p->code = "''"; |
|
| 1002 | + } |
|
| 1003 | + |
|
| 1004 | + $p->interdire_scripts = false; |
|
| 1005 | + |
|
| 1006 | + return $p; |
|
| 1007 | 1007 | } |
| 1008 | 1008 | |
| 1009 | 1009 | /** |
@@ -1013,7 +1013,7 @@ discard block |
||
| 1013 | 1013 | * @return string Nom de la balise, avec indication de boucle explicite si présent. |
| 1014 | 1014 | */ |
| 1015 | 1015 | function zbug_presenter_champ($p, $champ = '') { |
| 1016 | - $balise = $champ ?: $p->nom_champ; |
|
| 1017 | - $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1018 | - return "#{$explicite}{$balise}"; |
|
| 1016 | + $balise = $champ ?: $p->nom_champ; |
|
| 1017 | + $explicite = $p->nom_boucle ? $p->nom_boucle . ':' : ''; |
|
| 1018 | + return "#{$explicite}{$balise}"; |
|
| 1019 | 1019 | } |
@@ -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 | |
@@ -34,35 +34,35 @@ discard block |
||
| 34 | 34 | * @package SPIP\Core\Compilateur\AST |
| 35 | 35 | */ |
| 36 | 36 | class Contexte { |
| 37 | - /** |
|
| 38 | - * Description du squelette |
|
| 39 | - * |
|
| 40 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | - * |
|
| 42 | - * Peut contenir les index : |
|
| 43 | - * |
|
| 44 | - * - nom : Nom du fichier de cache |
|
| 45 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | - * - sourcefile : Chemin du squelette |
|
| 47 | - * - squelette : Code du squelette |
|
| 48 | - * - id_mere : Identifiant de la boucle parente |
|
| 49 | - * - documents : Pour embed et img dans les textes |
|
| 50 | - * - session : Pour un cache sessionné par auteur |
|
| 51 | - * - niv : Niveau de tabulation |
|
| 52 | - */ |
|
| 53 | - public array $descr = []; |
|
| 54 | - |
|
| 55 | - /** Identifiant de la boucle */ |
|
| 56 | - public string $id_boucle = ''; |
|
| 57 | - |
|
| 58 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 59 | - public int $ligne = 0; |
|
| 60 | - |
|
| 61 | - /** Langue d'exécution */ |
|
| 62 | - public string $lang = ''; |
|
| 63 | - |
|
| 64 | - /** Résultat de la compilation: toujours une expression PHP */ |
|
| 65 | - public string $code = ''; |
|
| 37 | + /** |
|
| 38 | + * Description du squelette |
|
| 39 | + * |
|
| 40 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 41 | + * |
|
| 42 | + * Peut contenir les index : |
|
| 43 | + * |
|
| 44 | + * - nom : Nom du fichier de cache |
|
| 45 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 46 | + * - sourcefile : Chemin du squelette |
|
| 47 | + * - squelette : Code du squelette |
|
| 48 | + * - id_mere : Identifiant de la boucle parente |
|
| 49 | + * - documents : Pour embed et img dans les textes |
|
| 50 | + * - session : Pour un cache sessionné par auteur |
|
| 51 | + * - niv : Niveau de tabulation |
|
| 52 | + */ |
|
| 53 | + public array $descr = []; |
|
| 54 | + |
|
| 55 | + /** Identifiant de la boucle */ |
|
| 56 | + public string $id_boucle = ''; |
|
| 57 | + |
|
| 58 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 59 | + public int $ligne = 0; |
|
| 60 | + |
|
| 61 | + /** Langue d'exécution */ |
|
| 62 | + public string $lang = ''; |
|
| 63 | + |
|
| 64 | + /** Résultat de la compilation: toujours une expression PHP */ |
|
| 65 | + public string $code = ''; |
|
| 66 | 66 | } |
| 67 | 67 | |
| 68 | 68 | |
@@ -72,32 +72,32 @@ discard block |
||
| 72 | 72 | * @package SPIP\Core\Compilateur\AST |
| 73 | 73 | **/ |
| 74 | 74 | class Texte { |
| 75 | - /** Type de noeud */ |
|
| 76 | - public string $type = 'texte'; |
|
| 77 | - |
|
| 78 | - /** Le texte */ |
|
| 79 | - public string $texte; |
|
| 80 | - |
|
| 81 | - /** |
|
| 82 | - * Contenu avant le texte. |
|
| 83 | - * |
|
| 84 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 85 | - * |
|
| 86 | - * @var string|array |
|
| 87 | - */ |
|
| 88 | - public $avant = ''; |
|
| 89 | - |
|
| 90 | - /** |
|
| 91 | - * Contenu après le texte. |
|
| 92 | - * |
|
| 93 | - * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 94 | - * |
|
| 95 | - * @var string|array |
|
| 96 | - */ |
|
| 97 | - public $apres = ''; |
|
| 98 | - |
|
| 99 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 100 | - public int $ligne = 0; |
|
| 75 | + /** Type de noeud */ |
|
| 76 | + public string $type = 'texte'; |
|
| 77 | + |
|
| 78 | + /** Le texte */ |
|
| 79 | + public string $texte; |
|
| 80 | + |
|
| 81 | + /** |
|
| 82 | + * Contenu avant le texte. |
|
| 83 | + * |
|
| 84 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 85 | + * |
|
| 86 | + * @var string|array |
|
| 87 | + */ |
|
| 88 | + public $avant = ''; |
|
| 89 | + |
|
| 90 | + /** |
|
| 91 | + * Contenu après le texte. |
|
| 92 | + * |
|
| 93 | + * Vide ou apostrophe simple ou double si le texte en était entouré |
|
| 94 | + * |
|
| 95 | + * @var string|array |
|
| 96 | + */ |
|
| 97 | + public $apres = ''; |
|
| 98 | + |
|
| 99 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 100 | + public int $ligne = 0; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | /** |
@@ -106,59 +106,59 @@ discard block |
||
| 106 | 106 | * @package SPIP\Core\Compilateur\AST |
| 107 | 107 | **/ |
| 108 | 108 | class Inclure { |
| 109 | - /** Type de noeud */ |
|
| 110 | - public string $type = 'include'; |
|
| 111 | - |
|
| 112 | - /** |
|
| 113 | - * Nom d'un fichier inclu |
|
| 114 | - * |
|
| 115 | - * - Objet Texte si inclusion d'un autre squelette |
|
| 116 | - * - chaîne si inclusion d'un fichier PHP directement |
|
| 117 | - * |
|
| 118 | - * @var string|Texte |
|
| 119 | - */ |
|
| 120 | - public $texte; |
|
| 121 | - |
|
| 122 | - /** |
|
| 123 | - * Inutilisé, propriété générique de l'AST |
|
| 124 | - * |
|
| 125 | - * @var string|array |
|
| 126 | - */ |
|
| 127 | - public $avant = ''; |
|
| 128 | - |
|
| 129 | - /** |
|
| 130 | - * Inutilisé, propriété générique de l'AST |
|
| 131 | - * |
|
| 132 | - * @var string|array |
|
| 133 | - */ |
|
| 134 | - public $apres = ''; |
|
| 135 | - |
|
| 136 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 137 | - public int $ligne = 0; |
|
| 138 | - |
|
| 139 | - /** Valeurs des paramètres */ |
|
| 140 | - public array $param = []; |
|
| 141 | - |
|
| 142 | - /** Source des filtres (compatibilité) (?) */ |
|
| 143 | - public array $fonctions = []; |
|
| 144 | - |
|
| 145 | - /** |
|
| 146 | - * Description du squelette |
|
| 147 | - * |
|
| 148 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 149 | - * |
|
| 150 | - * Peut contenir les index : |
|
| 151 | - * |
|
| 152 | - * - nom : Nom du fichier de cache |
|
| 153 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 154 | - * - sourcefile : Chemin du squelette |
|
| 155 | - * - squelette : Code du squelette |
|
| 156 | - * - id_mere : Identifiant de la boucle parente |
|
| 157 | - * - documents : Pour embed et img dans les textes |
|
| 158 | - * - session : Pour un cache sessionné par auteur |
|
| 159 | - * - niv : Niveau de tabulation |
|
| 160 | - */ |
|
| 161 | - public array $descr = []; |
|
| 109 | + /** Type de noeud */ |
|
| 110 | + public string $type = 'include'; |
|
| 111 | + |
|
| 112 | + /** |
|
| 113 | + * Nom d'un fichier inclu |
|
| 114 | + * |
|
| 115 | + * - Objet Texte si inclusion d'un autre squelette |
|
| 116 | + * - chaîne si inclusion d'un fichier PHP directement |
|
| 117 | + * |
|
| 118 | + * @var string|Texte |
|
| 119 | + */ |
|
| 120 | + public $texte; |
|
| 121 | + |
|
| 122 | + /** |
|
| 123 | + * Inutilisé, propriété générique de l'AST |
|
| 124 | + * |
|
| 125 | + * @var string|array |
|
| 126 | + */ |
|
| 127 | + public $avant = ''; |
|
| 128 | + |
|
| 129 | + /** |
|
| 130 | + * Inutilisé, propriété générique de l'AST |
|
| 131 | + * |
|
| 132 | + * @var string|array |
|
| 133 | + */ |
|
| 134 | + public $apres = ''; |
|
| 135 | + |
|
| 136 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 137 | + public int $ligne = 0; |
|
| 138 | + |
|
| 139 | + /** Valeurs des paramètres */ |
|
| 140 | + public array $param = []; |
|
| 141 | + |
|
| 142 | + /** Source des filtres (compatibilité) (?) */ |
|
| 143 | + public array $fonctions = []; |
|
| 144 | + |
|
| 145 | + /** |
|
| 146 | + * Description du squelette |
|
| 147 | + * |
|
| 148 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 149 | + * |
|
| 150 | + * Peut contenir les index : |
|
| 151 | + * |
|
| 152 | + * - nom : Nom du fichier de cache |
|
| 153 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 154 | + * - sourcefile : Chemin du squelette |
|
| 155 | + * - squelette : Code du squelette |
|
| 156 | + * - id_mere : Identifiant de la boucle parente |
|
| 157 | + * - documents : Pour embed et img dans les textes |
|
| 158 | + * - session : Pour un cache sessionné par auteur |
|
| 159 | + * - niv : Niveau de tabulation |
|
| 160 | + */ |
|
| 161 | + public array $descr = []; |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | |
@@ -168,362 +168,362 @@ discard block |
||
| 168 | 168 | * @package SPIP\Core\Compilateur\AST |
| 169 | 169 | **/ |
| 170 | 170 | class Boucle { |
| 171 | - /** Type de noeud */ |
|
| 172 | - public string $type = 'boucle'; |
|
| 173 | - |
|
| 174 | - /** Identifiant de la boucle */ |
|
| 175 | - public string $id_boucle; |
|
| 176 | - |
|
| 177 | - /** Identifiant de la boucle parente */ |
|
| 178 | - public string $id_parent = ''; |
|
| 179 | - |
|
| 180 | - /** Un nom explicite qui peut être affecté manuellement à certaines boucles générées */ |
|
| 181 | - public string $nom = ''; |
|
| 182 | - |
|
| 183 | - /** |
|
| 184 | - * Partie avant toujours affichee |
|
| 185 | - * |
|
| 186 | - * @var string|array |
|
| 187 | - */ |
|
| 188 | - public $preaff = ''; |
|
| 189 | - |
|
| 190 | - /** |
|
| 191 | - * Partie optionnelle avant |
|
| 192 | - * |
|
| 193 | - * @var string|array |
|
| 194 | - */ |
|
| 195 | - public $avant = ''; |
|
| 196 | - |
|
| 197 | - /** |
|
| 198 | - * Pour chaque élément |
|
| 199 | - * |
|
| 200 | - * @var string|array |
|
| 201 | - */ |
|
| 202 | - public $milieu = ''; |
|
| 203 | - |
|
| 204 | - /** |
|
| 205 | - * Partie optionnelle après |
|
| 206 | - * |
|
| 207 | - * @var string|array |
|
| 208 | - */ |
|
| 209 | - public $apres = ''; |
|
| 210 | - |
|
| 211 | - /** |
|
| 212 | - * Partie alternative, si pas de résultat dans la boucle |
|
| 213 | - * |
|
| 214 | - * @var string|array |
|
| 215 | - */ |
|
| 216 | - public $altern = ''; |
|
| 217 | - |
|
| 218 | - /** |
|
| 219 | - * Partie apres toujours affichee |
|
| 220 | - * |
|
| 221 | - * @var string|array |
|
| 222 | - */ |
|
| 223 | - public $postaff = ''; |
|
| 224 | - |
|
| 225 | - |
|
| 226 | - /** |
|
| 227 | - * La boucle doit-elle sélectionner la langue ? |
|
| 228 | - * |
|
| 229 | - * Valeurs : '', 'oui', 'non' |
|
| 230 | - */ |
|
| 231 | - public string $lang_select = ''; |
|
| 232 | - |
|
| 233 | - /** |
|
| 234 | - * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 235 | - * |
|
| 236 | - * FIXME: un seul typage (string ?) |
|
| 237 | - * |
|
| 238 | - * @var string|false|null |
|
| 239 | - */ |
|
| 240 | - public $type_requete = null; |
|
| 241 | - |
|
| 242 | - /** |
|
| 243 | - * La table est elle optionnelle ? |
|
| 244 | - * |
|
| 245 | - * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 246 | - */ |
|
| 247 | - public bool $table_optionnelle = false; |
|
| 248 | - |
|
| 249 | - /** |
|
| 250 | - * Nom du fichier de connexion |
|
| 251 | - */ |
|
| 252 | - public string $sql_serveur = ''; |
|
| 253 | - |
|
| 254 | - /** |
|
| 255 | - * Paramètres de la boucle |
|
| 256 | - * |
|
| 257 | - * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 258 | - * au calcul des critères |
|
| 259 | - */ |
|
| 260 | - public array $param = []; |
|
| 261 | - |
|
| 262 | - /** |
|
| 263 | - * Critères de la boucle |
|
| 264 | - * |
|
| 265 | - * FIXME: type array unique. |
|
| 266 | - * |
|
| 267 | - * @var string|Critere[] |
|
| 268 | - * - string: phrasage (code brut). Il reste si erreur de critère |
|
| 269 | - * - array: analyse correcte des critères... |
|
| 270 | - */ |
|
| 271 | - public $criteres = []; |
|
| 272 | - |
|
| 273 | - /** |
|
| 274 | - * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 275 | - * |
|
| 276 | - * @var string[] |
|
| 277 | - */ |
|
| 278 | - public array $separateur = []; |
|
| 279 | - |
|
| 280 | - /** |
|
| 281 | - * Liste des jointures possibles avec cette table |
|
| 282 | - * |
|
| 283 | - * Les jointures par défaut de la table sont complétées en priorité |
|
| 284 | - * des jointures déclarées explicitement sur la boucle |
|
| 285 | - * |
|
| 286 | - * @see base_trouver_table_dist() |
|
| 287 | - */ |
|
| 288 | - public array $jointures = []; |
|
| 289 | - |
|
| 290 | - /** |
|
| 291 | - * Jointures explicites avec cette table |
|
| 292 | - * |
|
| 293 | - * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 294 | - * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 295 | - * à la boucle. |
|
| 296 | - * |
|
| 297 | - * @var string|bool |
|
| 298 | - */ |
|
| 299 | - public $jointures_explicites = false; |
|
| 300 | - |
|
| 301 | - /** |
|
| 302 | - * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 303 | - */ |
|
| 304 | - public string $doublons = ''; |
|
| 305 | - |
|
| 306 | - /** |
|
| 307 | - * Code PHP ajouté au début de chaque itération de boucle. |
|
| 308 | - * |
|
| 309 | - * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 310 | - */ |
|
| 311 | - public string $partie = ''; |
|
| 312 | - |
|
| 313 | - /** |
|
| 314 | - * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 315 | - * ou de soustractions d'éléments à faire |
|
| 316 | - * |
|
| 317 | - * Dans les critères limitant le nombre d'éléments affichés |
|
| 318 | - * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 319 | - */ |
|
| 320 | - public string $total_parties = ''; |
|
| 321 | - |
|
| 322 | - /** |
|
| 323 | - * Code PHP ajouté avant l'itération de boucle. |
|
| 324 | - * |
|
| 325 | - * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 326 | - * pour initialiser les variables de début et de fin d'itération. |
|
| 327 | - */ |
|
| 328 | - public string $mode_partie = ''; |
|
| 329 | - |
|
| 330 | - /** |
|
| 331 | - * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 332 | - * |
|
| 333 | - * Si une boucle est appelée de manière récursive quelque part par |
|
| 334 | - * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 335 | - * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 336 | - * de l'appelant (rec) |
|
| 337 | - */ |
|
| 338 | - public string $externe = ''; |
|
| 339 | - |
|
| 340 | - // champs pour la construction de la requete SQL |
|
| 341 | - |
|
| 342 | - /** |
|
| 343 | - * Liste des champs à récupérer par la boucle |
|
| 344 | - * |
|
| 345 | - * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 346 | - * |
|
| 347 | - * @var string[] |
|
| 348 | - */ |
|
| 349 | - public array $select = []; |
|
| 350 | - |
|
| 351 | - /** |
|
| 352 | - * Liste des alias / tables SQL utilisées dans la boucle |
|
| 353 | - * |
|
| 354 | - * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 355 | - * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 356 | - * |
|
| 357 | - * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 358 | - * |
|
| 359 | - * @var string[] |
|
| 360 | - */ |
|
| 361 | - public array $from = []; |
|
| 362 | - |
|
| 363 | - /** |
|
| 364 | - * Liste des alias / type de jointures utilisées dans la boucle |
|
| 365 | - * |
|
| 366 | - * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 367 | - * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 368 | - * |
|
| 369 | - * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 370 | - * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 371 | - * |
|
| 372 | - * @var string[] |
|
| 373 | - */ |
|
| 374 | - public array $from_type = []; |
|
| 375 | - |
|
| 376 | - /** |
|
| 377 | - * Liste des conditions WHERE de la boucle |
|
| 378 | - * |
|
| 379 | - * Permet de restreindre les éléments retournés par une boucle |
|
| 380 | - * en fonctions des conditions transmises dans ce tableau. |
|
| 381 | - * |
|
| 382 | - * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 383 | - * |
|
| 384 | - * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 385 | - * chaque élément ajouté directement au where par |
|
| 386 | - * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 387 | - * est une condition AND en plus. |
|
| 388 | - * |
|
| 389 | - * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 390 | - * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 391 | - * $expr = array(operateur, val1, val2) |
|
| 392 | - * |
|
| 393 | - * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 394 | - * à réaliser tel que : |
|
| 395 | - * |
|
| 396 | - * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 397 | - * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 398 | - * suivant cet ordre : "val1 operateur val2". |
|
| 399 | - * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 400 | - * - "'AND'", "'OR'", "'NOT'" : |
|
| 401 | - * dans ce cas val1 et val2 sont également des expressions |
|
| 402 | - * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 403 | - * Exemples : |
|
| 404 | - * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 405 | - * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 406 | - * |
|
| 407 | - * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 408 | - * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 409 | - * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 410 | - */ |
|
| 411 | - public array $where = []; |
|
| 412 | - |
|
| 413 | - public array $join = []; |
|
| 414 | - public array $having = []; |
|
| 415 | - public $limit = ''; |
|
| 416 | - public array $group = []; |
|
| 417 | - public array $order = []; |
|
| 418 | - public array $default_order = []; |
|
| 419 | - public string $date = 'date'; |
|
| 420 | - public string $hash = ''; |
|
| 421 | - public $in = ''; |
|
| 422 | - public bool $sous_requete = false; |
|
| 423 | - |
|
| 424 | - /** |
|
| 425 | - * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 426 | - * |
|
| 427 | - * Il sert à insérer le code calculant une hierarchie |
|
| 428 | - */ |
|
| 429 | - public string $hierarchie = ''; |
|
| 430 | - |
|
| 431 | - // champs pour la construction du corps PHP |
|
| 432 | - |
|
| 433 | - /** |
|
| 434 | - * Description des sources de données de la boucle |
|
| 435 | - * |
|
| 436 | - * Description des données de la boucle issu de trouver_table |
|
| 437 | - * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 438 | - * |
|
| 439 | - * @see base_trouver_table_dist() |
|
| 440 | - */ |
|
| 441 | - public array $show = []; |
|
| 442 | - |
|
| 443 | - /** |
|
| 444 | - * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 445 | - */ |
|
| 446 | - public string $id_table = ''; |
|
| 447 | - |
|
| 448 | - /** |
|
| 449 | - * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 450 | - */ |
|
| 451 | - public string $primary = ''; |
|
| 452 | - |
|
| 453 | - /** |
|
| 454 | - * Code PHP compilé de la boucle |
|
| 455 | - * |
|
| 456 | - * FIXME: un seul type (string ?) |
|
| 457 | - * |
|
| 458 | - * - false: boucle fautive ? |
|
| 459 | - * |
|
| 460 | - * @var string|false |
|
| 461 | - */ |
|
| 462 | - public $return = ''; |
|
| 463 | - |
|
| 464 | - public $numrows = false; |
|
| 465 | - public $cptrows = false; |
|
| 466 | - |
|
| 467 | - /** |
|
| 468 | - * Description du squelette |
|
| 469 | - * |
|
| 470 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 471 | - * |
|
| 472 | - * Peut contenir les index : |
|
| 473 | - * |
|
| 474 | - * - nom : Nom du fichier de cache |
|
| 475 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 476 | - * - sourcefile : Chemin du squelette |
|
| 477 | - * - squelette : Code du squelette |
|
| 478 | - * - id_mere : Identifiant de la boucle parente |
|
| 479 | - * - documents : Pour embed et img dans les textes |
|
| 480 | - * - session : Pour un cache sessionné par auteur |
|
| 481 | - * - niv : Niveau de tabulation |
|
| 482 | - */ |
|
| 483 | - public array $descr = []; |
|
| 484 | - |
|
| 485 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 486 | - public int $ligne = 0; |
|
| 487 | - |
|
| 488 | - |
|
| 489 | - /** |
|
| 490 | - * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 491 | - * utilisable par les plugins egalement |
|
| 492 | - * |
|
| 493 | - * @var array<string, mixed> |
|
| 494 | - */ |
|
| 495 | - public array $modificateur = []; |
|
| 496 | - |
|
| 497 | - /** |
|
| 498 | - * Type d'itérateur utilisé pour cette boucle |
|
| 499 | - * |
|
| 500 | - * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 501 | - * - 'DATA' pour l'itérateur DATA, ... |
|
| 502 | - * |
|
| 503 | - * @var string |
|
| 504 | - */ |
|
| 505 | - public string $iterateur = ''; // type d'iterateur |
|
| 506 | - |
|
| 507 | - /** |
|
| 508 | - * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 509 | - */ |
|
| 510 | - public array $debug = []; |
|
| 511 | - |
|
| 512 | - /** |
|
| 513 | - * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 514 | - * notamment si le champ a été trouve dans une boucle parente |
|
| 515 | - * |
|
| 516 | - * Tableau nom du champ => index de boucle |
|
| 517 | - */ |
|
| 518 | - public array $index_champ = []; |
|
| 519 | - |
|
| 520 | - /** Source des filtres (compatibilité) (?) */ |
|
| 521 | - public array $fonctions = []; |
|
| 522 | - |
|
| 523 | - // obsoletes, conserves provisoirement pour compatibilite |
|
| 524 | - public $tout = false; |
|
| 525 | - public $plat = false; |
|
| 526 | - public $lien = false; |
|
| 171 | + /** Type de noeud */ |
|
| 172 | + public string $type = 'boucle'; |
|
| 173 | + |
|
| 174 | + /** Identifiant de la boucle */ |
|
| 175 | + public string $id_boucle; |
|
| 176 | + |
|
| 177 | + /** Identifiant de la boucle parente */ |
|
| 178 | + public string $id_parent = ''; |
|
| 179 | + |
|
| 180 | + /** Un nom explicite qui peut être affecté manuellement à certaines boucles générées */ |
|
| 181 | + public string $nom = ''; |
|
| 182 | + |
|
| 183 | + /** |
|
| 184 | + * Partie avant toujours affichee |
|
| 185 | + * |
|
| 186 | + * @var string|array |
|
| 187 | + */ |
|
| 188 | + public $preaff = ''; |
|
| 189 | + |
|
| 190 | + /** |
|
| 191 | + * Partie optionnelle avant |
|
| 192 | + * |
|
| 193 | + * @var string|array |
|
| 194 | + */ |
|
| 195 | + public $avant = ''; |
|
| 196 | + |
|
| 197 | + /** |
|
| 198 | + * Pour chaque élément |
|
| 199 | + * |
|
| 200 | + * @var string|array |
|
| 201 | + */ |
|
| 202 | + public $milieu = ''; |
|
| 203 | + |
|
| 204 | + /** |
|
| 205 | + * Partie optionnelle après |
|
| 206 | + * |
|
| 207 | + * @var string|array |
|
| 208 | + */ |
|
| 209 | + public $apres = ''; |
|
| 210 | + |
|
| 211 | + /** |
|
| 212 | + * Partie alternative, si pas de résultat dans la boucle |
|
| 213 | + * |
|
| 214 | + * @var string|array |
|
| 215 | + */ |
|
| 216 | + public $altern = ''; |
|
| 217 | + |
|
| 218 | + /** |
|
| 219 | + * Partie apres toujours affichee |
|
| 220 | + * |
|
| 221 | + * @var string|array |
|
| 222 | + */ |
|
| 223 | + public $postaff = ''; |
|
| 224 | + |
|
| 225 | + |
|
| 226 | + /** |
|
| 227 | + * La boucle doit-elle sélectionner la langue ? |
|
| 228 | + * |
|
| 229 | + * Valeurs : '', 'oui', 'non' |
|
| 230 | + */ |
|
| 231 | + public string $lang_select = ''; |
|
| 232 | + |
|
| 233 | + /** |
|
| 234 | + * Alias de table d'application de la requête ou nom complet de la table SQL |
|
| 235 | + * |
|
| 236 | + * FIXME: un seul typage (string ?) |
|
| 237 | + * |
|
| 238 | + * @var string|false|null |
|
| 239 | + */ |
|
| 240 | + public $type_requete = null; |
|
| 241 | + |
|
| 242 | + /** |
|
| 243 | + * La table est elle optionnelle ? |
|
| 244 | + * |
|
| 245 | + * Si oui, aucune erreur ne sera générée si la table demandée n'est pas présente |
|
| 246 | + */ |
|
| 247 | + public bool $table_optionnelle = false; |
|
| 248 | + |
|
| 249 | + /** |
|
| 250 | + * Nom du fichier de connexion |
|
| 251 | + */ |
|
| 252 | + public string $sql_serveur = ''; |
|
| 253 | + |
|
| 254 | + /** |
|
| 255 | + * Paramètres de la boucle |
|
| 256 | + * |
|
| 257 | + * Description des paramètres passés à la boucle, qui servent ensuite |
|
| 258 | + * au calcul des critères |
|
| 259 | + */ |
|
| 260 | + public array $param = []; |
|
| 261 | + |
|
| 262 | + /** |
|
| 263 | + * Critères de la boucle |
|
| 264 | + * |
|
| 265 | + * FIXME: type array unique. |
|
| 266 | + * |
|
| 267 | + * @var string|Critere[] |
|
| 268 | + * - string: phrasage (code brut). Il reste si erreur de critère |
|
| 269 | + * - array: analyse correcte des critères... |
|
| 270 | + */ |
|
| 271 | + public $criteres = []; |
|
| 272 | + |
|
| 273 | + /** |
|
| 274 | + * Textes insérés entre 2 éléments de boucle (critère inter) |
|
| 275 | + * |
|
| 276 | + * @var string[] |
|
| 277 | + */ |
|
| 278 | + public array $separateur = []; |
|
| 279 | + |
|
| 280 | + /** |
|
| 281 | + * Liste des jointures possibles avec cette table |
|
| 282 | + * |
|
| 283 | + * Les jointures par défaut de la table sont complétées en priorité |
|
| 284 | + * des jointures déclarées explicitement sur la boucle |
|
| 285 | + * |
|
| 286 | + * @see base_trouver_table_dist() |
|
| 287 | + */ |
|
| 288 | + public array $jointures = []; |
|
| 289 | + |
|
| 290 | + /** |
|
| 291 | + * Jointures explicites avec cette table |
|
| 292 | + * |
|
| 293 | + * Ces jointures sont utilisées en priorité par rapport aux jointures |
|
| 294 | + * normales possibles pour retrouver les colonnes demandées extérieures |
|
| 295 | + * à la boucle. |
|
| 296 | + * |
|
| 297 | + * @var string|bool |
|
| 298 | + */ |
|
| 299 | + public $jointures_explicites = false; |
|
| 300 | + |
|
| 301 | + /** |
|
| 302 | + * Nom de la variable PHP stockant le noms de doublons utilisés "$doublons_index" |
|
| 303 | + */ |
|
| 304 | + public string $doublons = ''; |
|
| 305 | + |
|
| 306 | + /** |
|
| 307 | + * Code PHP ajouté au début de chaque itération de boucle. |
|
| 308 | + * |
|
| 309 | + * Utilisé entre autre par les critères {pagination}, {n-a,b}, {a/b}... |
|
| 310 | + */ |
|
| 311 | + public string $partie = ''; |
|
| 312 | + |
|
| 313 | + /** |
|
| 314 | + * Nombre de divisions de la boucle, d'éléments à afficher, |
|
| 315 | + * ou de soustractions d'éléments à faire |
|
| 316 | + * |
|
| 317 | + * Dans les critères limitant le nombre d'éléments affichés |
|
| 318 | + * {a,b}, {a,n-b}, {a/b}, {pagination b}, b est affecté à total_parties. |
|
| 319 | + */ |
|
| 320 | + public string $total_parties = ''; |
|
| 321 | + |
|
| 322 | + /** |
|
| 323 | + * Code PHP ajouté avant l'itération de boucle. |
|
| 324 | + * |
|
| 325 | + * Utilisé entre autre par les critères {pagination}, {a,b}, {a/b} |
|
| 326 | + * pour initialiser les variables de début et de fin d'itération. |
|
| 327 | + */ |
|
| 328 | + public string $mode_partie = ''; |
|
| 329 | + |
|
| 330 | + /** |
|
| 331 | + * Identifiant d'une boucle qui appelle celle-ci de manière récursive |
|
| 332 | + * |
|
| 333 | + * Si une boucle est appelée de manière récursive quelque part par |
|
| 334 | + * une autre boucle comme <BOUCLE_rec(boucle_identifiant) />, cette |
|
| 335 | + * boucle (identifiant) reçoit dans cette propriété l'identifiant |
|
| 336 | + * de l'appelant (rec) |
|
| 337 | + */ |
|
| 338 | + public string $externe = ''; |
|
| 339 | + |
|
| 340 | + // champs pour la construction de la requete SQL |
|
| 341 | + |
|
| 342 | + /** |
|
| 343 | + * Liste des champs à récupérer par la boucle |
|
| 344 | + * |
|
| 345 | + * Expression 'table.nom_champ' ou calculée 'nom_champ AS x' |
|
| 346 | + * |
|
| 347 | + * @var string[] |
|
| 348 | + */ |
|
| 349 | + public array $select = []; |
|
| 350 | + |
|
| 351 | + /** |
|
| 352 | + * Liste des alias / tables SQL utilisées dans la boucle |
|
| 353 | + * |
|
| 354 | + * L'index est un identifiant (xx dans spip_xx assez souvent) qui servira |
|
| 355 | + * d'alias au nom de la table ; la valeur est le nom de la table SQL désirée. |
|
| 356 | + * |
|
| 357 | + * L'index 0 peut définir le type de sources de données de l'itérateur DATA |
|
| 358 | + * |
|
| 359 | + * @var string[] |
|
| 360 | + */ |
|
| 361 | + public array $from = []; |
|
| 362 | + |
|
| 363 | + /** |
|
| 364 | + * Liste des alias / type de jointures utilisées dans la boucle |
|
| 365 | + * |
|
| 366 | + * L'index est le nom d'alias (comme pour la propriété $from), et la valeur |
|
| 367 | + * un type de jointure parmi 'INNER', 'LEFT', 'RIGHT', 'OUTER'. |
|
| 368 | + * |
|
| 369 | + * Lorsque le type n'est pas déclaré pour un alias, c'est 'INNER' |
|
| 370 | + * qui sera utilisé par défaut (créant donc un INNER JOIN). |
|
| 371 | + * |
|
| 372 | + * @var string[] |
|
| 373 | + */ |
|
| 374 | + public array $from_type = []; |
|
| 375 | + |
|
| 376 | + /** |
|
| 377 | + * Liste des conditions WHERE de la boucle |
|
| 378 | + * |
|
| 379 | + * Permet de restreindre les éléments retournés par une boucle |
|
| 380 | + * en fonctions des conditions transmises dans ce tableau. |
|
| 381 | + * |
|
| 382 | + * Ce tableau peut avoir plusieurs niveaux de profondeur. |
|
| 383 | + * |
|
| 384 | + * Les éléments du premier niveau sont reliés par des AND, donc |
|
| 385 | + * chaque élément ajouté directement au where par |
|
| 386 | + * $boucle->where[] = array(...) ou $boucle->where[] = "'expression'" |
|
| 387 | + * est une condition AND en plus. |
|
| 388 | + * |
|
| 389 | + * Par contre, lorsqu'on indique un tableau, il peut décrire des relations |
|
| 390 | + * internes différentes. Soit $expr un tableau d'expressions quelconques de 3 valeurs : |
|
| 391 | + * $expr = array(operateur, val1, val2) |
|
| 392 | + * |
|
| 393 | + * Ces 3 valeurs sont des expressions PHP. L'index 0 désigne l'opérateur |
|
| 394 | + * à réaliser tel que : |
|
| 395 | + * |
|
| 396 | + * - "'='" , "'>='", "'<'", "'IN'", "'REGEXP'", "'LIKE'", ... : |
|
| 397 | + * val1 et val2 sont des champs et valeurs à utiliser dans la comparaison |
|
| 398 | + * suivant cet ordre : "val1 operateur val2". |
|
| 399 | + * Exemple : $boucle->where[] = array("'='", "'articles.statut'", "'\"publie\"'"); |
|
| 400 | + * - "'AND'", "'OR'", "'NOT'" : |
|
| 401 | + * dans ce cas val1 et val2 sont également des expressions |
|
| 402 | + * de comparaison complètes, et peuvent être eux-même des tableaux comme $expr |
|
| 403 | + * Exemples : |
|
| 404 | + * $boucle->where[] = array("'OR'", $expr1, $expr2); |
|
| 405 | + * $boucle->where[] = array("'NOT'", $expr); // val2 n'existe pas avec NOT |
|
| 406 | + * |
|
| 407 | + * D'autres noms sont possibles pour l'opérateur (le nombre de valeurs diffère) : |
|
| 408 | + * - "'SELF'", "'SUBSELECT'" : indiquent des sous requêtes |
|
| 409 | + * - "'?'" : indique une condition à faire évaluer (val1 ? val2 : val3) |
|
| 410 | + */ |
|
| 411 | + public array $where = []; |
|
| 412 | + |
|
| 413 | + public array $join = []; |
|
| 414 | + public array $having = []; |
|
| 415 | + public $limit = ''; |
|
| 416 | + public array $group = []; |
|
| 417 | + public array $order = []; |
|
| 418 | + public array $default_order = []; |
|
| 419 | + public string $date = 'date'; |
|
| 420 | + public string $hash = ''; |
|
| 421 | + public $in = ''; |
|
| 422 | + public bool $sous_requete = false; |
|
| 423 | + |
|
| 424 | + /** |
|
| 425 | + * Code PHP qui sera ajouté en tout début de la fonction de boucle |
|
| 426 | + * |
|
| 427 | + * Il sert à insérer le code calculant une hierarchie |
|
| 428 | + */ |
|
| 429 | + public string $hierarchie = ''; |
|
| 430 | + |
|
| 431 | + // champs pour la construction du corps PHP |
|
| 432 | + |
|
| 433 | + /** |
|
| 434 | + * Description des sources de données de la boucle |
|
| 435 | + * |
|
| 436 | + * Description des données de la boucle issu de trouver_table |
|
| 437 | + * dans le cadre de l'itérateur SQL et contenant au moins l'index 'field'. |
|
| 438 | + * |
|
| 439 | + * @see base_trouver_table_dist() |
|
| 440 | + */ |
|
| 441 | + public array $show = []; |
|
| 442 | + |
|
| 443 | + /** |
|
| 444 | + * Nom de la table SQL principale de la boucle, sans son préfixe |
|
| 445 | + */ |
|
| 446 | + public string $id_table = ''; |
|
| 447 | + |
|
| 448 | + /** |
|
| 449 | + * Nom de la clé primaire de la table SQL principale de la boucle |
|
| 450 | + */ |
|
| 451 | + public string $primary = ''; |
|
| 452 | + |
|
| 453 | + /** |
|
| 454 | + * Code PHP compilé de la boucle |
|
| 455 | + * |
|
| 456 | + * FIXME: un seul type (string ?) |
|
| 457 | + * |
|
| 458 | + * - false: boucle fautive ? |
|
| 459 | + * |
|
| 460 | + * @var string|false |
|
| 461 | + */ |
|
| 462 | + public $return = ''; |
|
| 463 | + |
|
| 464 | + public $numrows = false; |
|
| 465 | + public $cptrows = false; |
|
| 466 | + |
|
| 467 | + /** |
|
| 468 | + * Description du squelette |
|
| 469 | + * |
|
| 470 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 471 | + * |
|
| 472 | + * Peut contenir les index : |
|
| 473 | + * |
|
| 474 | + * - nom : Nom du fichier de cache |
|
| 475 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 476 | + * - sourcefile : Chemin du squelette |
|
| 477 | + * - squelette : Code du squelette |
|
| 478 | + * - id_mere : Identifiant de la boucle parente |
|
| 479 | + * - documents : Pour embed et img dans les textes |
|
| 480 | + * - session : Pour un cache sessionné par auteur |
|
| 481 | + * - niv : Niveau de tabulation |
|
| 482 | + */ |
|
| 483 | + public array $descr = []; |
|
| 484 | + |
|
| 485 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 486 | + public int $ligne = 0; |
|
| 487 | + |
|
| 488 | + |
|
| 489 | + /** |
|
| 490 | + * table pour stocker les modificateurs de boucle tels que tout, plat ..., |
|
| 491 | + * utilisable par les plugins egalement |
|
| 492 | + * |
|
| 493 | + * @var array<string, mixed> |
|
| 494 | + */ |
|
| 495 | + public array $modificateur = []; |
|
| 496 | + |
|
| 497 | + /** |
|
| 498 | + * Type d'itérateur utilisé pour cette boucle |
|
| 499 | + * |
|
| 500 | + * - 'SQL' dans le cadre d'une boucle sur une table SQL |
|
| 501 | + * - 'DATA' pour l'itérateur DATA, ... |
|
| 502 | + * |
|
| 503 | + * @var string |
|
| 504 | + */ |
|
| 505 | + public string $iterateur = ''; // type d'iterateur |
|
| 506 | + |
|
| 507 | + /** |
|
| 508 | + * @var array $debug Textes qui seront insérés dans l’entête de boucle du mode debug |
|
| 509 | + */ |
|
| 510 | + public array $debug = []; |
|
| 511 | + |
|
| 512 | + /** |
|
| 513 | + * Index de la boucle dont le champ présent dans cette boucle est originaire, |
|
| 514 | + * notamment si le champ a été trouve dans une boucle parente |
|
| 515 | + * |
|
| 516 | + * Tableau nom du champ => index de boucle |
|
| 517 | + */ |
|
| 518 | + public array $index_champ = []; |
|
| 519 | + |
|
| 520 | + /** Source des filtres (compatibilité) (?) */ |
|
| 521 | + public array $fonctions = []; |
|
| 522 | + |
|
| 523 | + // obsoletes, conserves provisoirement pour compatibilite |
|
| 524 | + public $tout = false; |
|
| 525 | + public $plat = false; |
|
| 526 | + public $lien = false; |
|
| 527 | 527 | } |
| 528 | 528 | |
| 529 | 529 | /** |
@@ -534,30 +534,30 @@ discard block |
||
| 534 | 534 | * @package SPIP\Core\Compilateur\AST |
| 535 | 535 | **/ |
| 536 | 536 | class Critere { |
| 537 | - /** Type de noeud */ |
|
| 538 | - public string $type = 'critere'; |
|
| 537 | + /** Type de noeud */ |
|
| 538 | + public string $type = 'critere'; |
|
| 539 | 539 | |
| 540 | - /** Opérateur (>, <, >=, IN, ...) */ |
|
| 541 | - public ?string $op; |
|
| 540 | + /** Opérateur (>, <, >=, IN, ...) */ |
|
| 541 | + public ?string $op; |
|
| 542 | 542 | |
| 543 | - /** Présence d'une négation (truc !op valeur) */ |
|
| 544 | - public bool $not = false; |
|
| 543 | + /** Présence d'une négation (truc !op valeur) */ |
|
| 544 | + public bool $not = false; |
|
| 545 | 545 | |
| 546 | - /** Présence d'une exclusion (!truc op valeur) */ |
|
| 547 | - public string $exclus = ''; |
|
| 546 | + /** Présence d'une exclusion (!truc op valeur) */ |
|
| 547 | + public string $exclus = ''; |
|
| 548 | 548 | |
| 549 | - /** Présence d'une condition dans le critère (truc ?) */ |
|
| 550 | - public bool $cond = false; |
|
| 549 | + /** Présence d'une condition dans le critère (truc ?) */ |
|
| 550 | + public bool $cond = false; |
|
| 551 | 551 | |
| 552 | - /** |
|
| 553 | - * Paramètres du critère |
|
| 554 | - * - $param[0] : élément avant l'opérateur |
|
| 555 | - * - $param[1..n] : éléments après l'opérateur |
|
| 556 | - */ |
|
| 557 | - public array $param = []; |
|
| 552 | + /** |
|
| 553 | + * Paramètres du critère |
|
| 554 | + * - $param[0] : élément avant l'opérateur |
|
| 555 | + * - $param[1..n] : éléments après l'opérateur |
|
| 556 | + */ |
|
| 557 | + public array $param = []; |
|
| 558 | 558 | |
| 559 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 560 | - public int $ligne = 0; |
|
| 559 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 560 | + public int $ligne = 0; |
|
| 561 | 561 | } |
| 562 | 562 | |
| 563 | 563 | /** |
@@ -566,100 +566,100 @@ discard block |
||
| 566 | 566 | * @package SPIP\Core\Compilateur\AST |
| 567 | 567 | **/ |
| 568 | 568 | class Champ { |
| 569 | - /** Type de noeud */ |
|
| 570 | - public string $type = 'champ'; |
|
| 571 | - |
|
| 572 | - /** Nom du champ demandé. Exemple 'ID_ARTICLE' */ |
|
| 573 | - public ?string $nom_champ; |
|
| 574 | - |
|
| 575 | - /** Identifiant de la boucle parente si explicité */ |
|
| 576 | - public ?string $nom_boucle = ''; |
|
| 577 | - |
|
| 578 | - /** |
|
| 579 | - * Partie optionnelle avant |
|
| 580 | - * |
|
| 581 | - * @var null|string|array |
|
| 582 | - */ |
|
| 583 | - public $avant; |
|
| 584 | - |
|
| 585 | - /** |
|
| 586 | - * Partie optionnelle après |
|
| 587 | - * |
|
| 588 | - * @var null|string|array |
|
| 589 | - */ |
|
| 590 | - public $apres; |
|
| 591 | - |
|
| 592 | - /** |
|
| 593 | - * Étoiles : annuler des automatismes |
|
| 594 | - * |
|
| 595 | - * - '*' annule les filtres automatiques |
|
| 596 | - * - '**' annule en plus les protections de scripts |
|
| 597 | - */ |
|
| 598 | - public ?string $etoile; |
|
| 599 | - |
|
| 600 | - /** |
|
| 601 | - * Arguments et filtres explicites sur la balise |
|
| 602 | - * |
|
| 603 | - * - $param[0] contient les arguments de la balise |
|
| 604 | - * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 605 | - */ |
|
| 606 | - public array $param = []; |
|
| 607 | - |
|
| 608 | - /** Source des filtres (compatibilité) (?) */ |
|
| 609 | - public array $fonctions = []; |
|
| 610 | - |
|
| 611 | - /** |
|
| 612 | - * Identifiant de la boucle |
|
| 613 | - * |
|
| 614 | - * @var string |
|
| 615 | - */ |
|
| 616 | - public $id_boucle = ''; |
|
| 617 | - |
|
| 618 | - /** |
|
| 619 | - * AST du squelette, liste de toutes les boucles |
|
| 620 | - * |
|
| 621 | - * @var Boucle[] |
|
| 622 | - */ |
|
| 623 | - public array $boucles; |
|
| 624 | - |
|
| 625 | - /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 626 | - public ?string $type_requete; |
|
| 627 | - |
|
| 628 | - /** Résultat de la compilation: toujours une expression PHP */ |
|
| 629 | - public string $code = ''; |
|
| 630 | - |
|
| 631 | - /** |
|
| 632 | - * Interdire les scripts |
|
| 633 | - * |
|
| 634 | - * false si on est sûr de cette balise |
|
| 635 | - * |
|
| 636 | - * @see interdire_scripts() |
|
| 637 | - */ |
|
| 638 | - public bool $interdire_scripts = true; |
|
| 639 | - |
|
| 640 | - /** |
|
| 641 | - * Description du squelette |
|
| 642 | - * |
|
| 643 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 644 | - * |
|
| 645 | - * Peut contenir les index : |
|
| 646 | - * |
|
| 647 | - * - nom : Nom du fichier de cache |
|
| 648 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 649 | - * - sourcefile : Chemin du squelette |
|
| 650 | - * - squelette : Code du squelette |
|
| 651 | - * - id_mere : Identifiant de la boucle parente |
|
| 652 | - * - documents : Pour embed et img dans les textes |
|
| 653 | - * - session : Pour un cache sessionné par auteur |
|
| 654 | - * - niv : Niveau de tabulation |
|
| 655 | - */ |
|
| 656 | - public array $descr = []; |
|
| 657 | - |
|
| 658 | - /** Numéro de ligne dans le code source du squelette*/ |
|
| 659 | - public int $ligne = 0; |
|
| 660 | - |
|
| 661 | - /** Drapeau pour reperer les balises calculées par une fonction explicite */ |
|
| 662 | - public bool $balise_calculee = false; |
|
| 569 | + /** Type de noeud */ |
|
| 570 | + public string $type = 'champ'; |
|
| 571 | + |
|
| 572 | + /** Nom du champ demandé. Exemple 'ID_ARTICLE' */ |
|
| 573 | + public ?string $nom_champ; |
|
| 574 | + |
|
| 575 | + /** Identifiant de la boucle parente si explicité */ |
|
| 576 | + public ?string $nom_boucle = ''; |
|
| 577 | + |
|
| 578 | + /** |
|
| 579 | + * Partie optionnelle avant |
|
| 580 | + * |
|
| 581 | + * @var null|string|array |
|
| 582 | + */ |
|
| 583 | + public $avant; |
|
| 584 | + |
|
| 585 | + /** |
|
| 586 | + * Partie optionnelle après |
|
| 587 | + * |
|
| 588 | + * @var null|string|array |
|
| 589 | + */ |
|
| 590 | + public $apres; |
|
| 591 | + |
|
| 592 | + /** |
|
| 593 | + * Étoiles : annuler des automatismes |
|
| 594 | + * |
|
| 595 | + * - '*' annule les filtres automatiques |
|
| 596 | + * - '**' annule en plus les protections de scripts |
|
| 597 | + */ |
|
| 598 | + public ?string $etoile; |
|
| 599 | + |
|
| 600 | + /** |
|
| 601 | + * Arguments et filtres explicites sur la balise |
|
| 602 | + * |
|
| 603 | + * - $param[0] contient les arguments de la balise |
|
| 604 | + * - $param[1..n] contient les filtres à appliquer à la balise |
|
| 605 | + */ |
|
| 606 | + public array $param = []; |
|
| 607 | + |
|
| 608 | + /** Source des filtres (compatibilité) (?) */ |
|
| 609 | + public array $fonctions = []; |
|
| 610 | + |
|
| 611 | + /** |
|
| 612 | + * Identifiant de la boucle |
|
| 613 | + * |
|
| 614 | + * @var string |
|
| 615 | + */ |
|
| 616 | + public $id_boucle = ''; |
|
| 617 | + |
|
| 618 | + /** |
|
| 619 | + * AST du squelette, liste de toutes les boucles |
|
| 620 | + * |
|
| 621 | + * @var Boucle[] |
|
| 622 | + */ |
|
| 623 | + public array $boucles; |
|
| 624 | + |
|
| 625 | + /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 626 | + public ?string $type_requete; |
|
| 627 | + |
|
| 628 | + /** Résultat de la compilation: toujours une expression PHP */ |
|
| 629 | + public string $code = ''; |
|
| 630 | + |
|
| 631 | + /** |
|
| 632 | + * Interdire les scripts |
|
| 633 | + * |
|
| 634 | + * false si on est sûr de cette balise |
|
| 635 | + * |
|
| 636 | + * @see interdire_scripts() |
|
| 637 | + */ |
|
| 638 | + public bool $interdire_scripts = true; |
|
| 639 | + |
|
| 640 | + /** |
|
| 641 | + * Description du squelette |
|
| 642 | + * |
|
| 643 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 644 | + * |
|
| 645 | + * Peut contenir les index : |
|
| 646 | + * |
|
| 647 | + * - nom : Nom du fichier de cache |
|
| 648 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 649 | + * - sourcefile : Chemin du squelette |
|
| 650 | + * - squelette : Code du squelette |
|
| 651 | + * - id_mere : Identifiant de la boucle parente |
|
| 652 | + * - documents : Pour embed et img dans les textes |
|
| 653 | + * - session : Pour un cache sessionné par auteur |
|
| 654 | + * - niv : Niveau de tabulation |
|
| 655 | + */ |
|
| 656 | + public array $descr = []; |
|
| 657 | + |
|
| 658 | + /** Numéro de ligne dans le code source du squelette*/ |
|
| 659 | + public int $ligne = 0; |
|
| 660 | + |
|
| 661 | + /** Drapeau pour reperer les balises calculées par une fonction explicite */ |
|
| 662 | + public bool $balise_calculee = false; |
|
| 663 | 663 | } |
| 664 | 664 | |
| 665 | 665 | |
@@ -667,80 +667,80 @@ discard block |
||
| 667 | 667 | * Description d'une chaîne de langue |
| 668 | 668 | **/ |
| 669 | 669 | class Idiome { |
| 670 | - /** Type de noeud */ |
|
| 671 | - public string $type = 'idiome'; |
|
| 672 | - |
|
| 673 | - /** Clé de traduction demandée. Exemple 'item_oui' */ |
|
| 674 | - public string $nom_champ = ''; |
|
| 675 | - |
|
| 676 | - /** Module de langue où chercher la clé de traduction. Exemple 'medias' */ |
|
| 677 | - public string $module = ''; |
|
| 678 | - |
|
| 679 | - /** Arguments à passer à la chaîne */ |
|
| 680 | - public array $arg = []; |
|
| 681 | - |
|
| 682 | - /** Filtres à appliquer au résultat */ |
|
| 683 | - public array $param = []; |
|
| 684 | - |
|
| 685 | - /** Source des filtres (compatibilité) (?) */ |
|
| 686 | - public array $fonctions = []; |
|
| 687 | - |
|
| 688 | - /** |
|
| 689 | - * Inutilisé, propriété générique de l'AST |
|
| 690 | - * |
|
| 691 | - * @var string|array |
|
| 692 | - */ |
|
| 693 | - public $avant = ''; |
|
| 694 | - |
|
| 695 | - /** |
|
| 696 | - * Inutilisé, propriété générique de l'AST |
|
| 697 | - * |
|
| 698 | - * @var string|array |
|
| 699 | - */ |
|
| 700 | - public $apres = ''; |
|
| 701 | - |
|
| 702 | - /** Identifiant de la boucle */ |
|
| 703 | - public string $id_boucle = ''; |
|
| 704 | - |
|
| 705 | - /** |
|
| 706 | - * AST du squelette, liste de toutes les boucles |
|
| 707 | - * |
|
| 708 | - * @var Boucle[] |
|
| 709 | - */ |
|
| 710 | - public array $boucles; |
|
| 711 | - |
|
| 712 | - /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 713 | - public ?string $type_requete; |
|
| 714 | - |
|
| 715 | - /** Résultat de la compilation: toujours une expression PHP */ |
|
| 716 | - public string $code = ''; |
|
| 717 | - |
|
| 718 | - /** |
|
| 719 | - * Interdire les scripts |
|
| 720 | - * |
|
| 721 | - * @see interdire_scripts() |
|
| 722 | - */ |
|
| 723 | - public bool $interdire_scripts = false; |
|
| 724 | - |
|
| 725 | - /** |
|
| 726 | - * Description du squelette |
|
| 727 | - * |
|
| 728 | - * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 729 | - * |
|
| 730 | - * Peut contenir les index : |
|
| 731 | - * - nom : Nom du fichier de cache |
|
| 732 | - * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 733 | - * - sourcefile : Chemin du squelette |
|
| 734 | - * - squelette : Code du squelette |
|
| 735 | - * - id_mere : Identifiant de la boucle parente |
|
| 736 | - * - documents : Pour embed et img dans les textes |
|
| 737 | - * - session : Pour un cache sessionné par auteur |
|
| 738 | - * - niv : Niveau de tabulation |
|
| 739 | - */ |
|
| 740 | - public array $descr = []; |
|
| 741 | - |
|
| 742 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 743 | - public int $ligne = 0; |
|
| 670 | + /** Type de noeud */ |
|
| 671 | + public string $type = 'idiome'; |
|
| 672 | + |
|
| 673 | + /** Clé de traduction demandée. Exemple 'item_oui' */ |
|
| 674 | + public string $nom_champ = ''; |
|
| 675 | + |
|
| 676 | + /** Module de langue où chercher la clé de traduction. Exemple 'medias' */ |
|
| 677 | + public string $module = ''; |
|
| 678 | + |
|
| 679 | + /** Arguments à passer à la chaîne */ |
|
| 680 | + public array $arg = []; |
|
| 681 | + |
|
| 682 | + /** Filtres à appliquer au résultat */ |
|
| 683 | + public array $param = []; |
|
| 684 | + |
|
| 685 | + /** Source des filtres (compatibilité) (?) */ |
|
| 686 | + public array $fonctions = []; |
|
| 687 | + |
|
| 688 | + /** |
|
| 689 | + * Inutilisé, propriété générique de l'AST |
|
| 690 | + * |
|
| 691 | + * @var string|array |
|
| 692 | + */ |
|
| 693 | + public $avant = ''; |
|
| 694 | + |
|
| 695 | + /** |
|
| 696 | + * Inutilisé, propriété générique de l'AST |
|
| 697 | + * |
|
| 698 | + * @var string|array |
|
| 699 | + */ |
|
| 700 | + public $apres = ''; |
|
| 701 | + |
|
| 702 | + /** Identifiant de la boucle */ |
|
| 703 | + public string $id_boucle = ''; |
|
| 704 | + |
|
| 705 | + /** |
|
| 706 | + * AST du squelette, liste de toutes les boucles |
|
| 707 | + * |
|
| 708 | + * @var Boucle[] |
|
| 709 | + */ |
|
| 710 | + public array $boucles; |
|
| 711 | + |
|
| 712 | + /** Alias de table d'application de la requête ou nom complet de la table SQL */ |
|
| 713 | + public ?string $type_requete; |
|
| 714 | + |
|
| 715 | + /** Résultat de la compilation: toujours une expression PHP */ |
|
| 716 | + public string $code = ''; |
|
| 717 | + |
|
| 718 | + /** |
|
| 719 | + * Interdire les scripts |
|
| 720 | + * |
|
| 721 | + * @see interdire_scripts() |
|
| 722 | + */ |
|
| 723 | + public bool $interdire_scripts = false; |
|
| 724 | + |
|
| 725 | + /** |
|
| 726 | + * Description du squelette |
|
| 727 | + * |
|
| 728 | + * Sert pour la gestion d'erreur et la production de code dependant du contexte |
|
| 729 | + * |
|
| 730 | + * Peut contenir les index : |
|
| 731 | + * - nom : Nom du fichier de cache |
|
| 732 | + * - gram : Nom de la grammaire du squelette (détermine le phraseur à utiliser) |
|
| 733 | + * - sourcefile : Chemin du squelette |
|
| 734 | + * - squelette : Code du squelette |
|
| 735 | + * - id_mere : Identifiant de la boucle parente |
|
| 736 | + * - documents : Pour embed et img dans les textes |
|
| 737 | + * - session : Pour un cache sessionné par auteur |
|
| 738 | + * - niv : Niveau de tabulation |
|
| 739 | + */ |
|
| 740 | + public array $descr = []; |
|
| 741 | + |
|
| 742 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 743 | + public int $ligne = 0; |
|
| 744 | 744 | } |
| 745 | 745 | |
| 746 | 746 | /** |
@@ -749,18 +749,18 @@ discard block |
||
| 749 | 749 | * @package SPIP\Core\Compilateur\AST |
| 750 | 750 | **/ |
| 751 | 751 | class Polyglotte { |
| 752 | - /** Type de noeud */ |
|
| 753 | - public string $type = 'polyglotte'; |
|
| 754 | - |
|
| 755 | - /** |
|
| 756 | - * Tableau des traductions possibles classées par langue |
|
| 757 | - * |
|
| 758 | - * Tableau code de langue => texte |
|
| 759 | - */ |
|
| 760 | - public array $traductions = []; |
|
| 761 | - |
|
| 762 | - /** Numéro de ligne dans le code source du squelette */ |
|
| 763 | - public int $ligne = 0; |
|
| 752 | + /** Type de noeud */ |
|
| 753 | + public string $type = 'polyglotte'; |
|
| 754 | + |
|
| 755 | + /** |
|
| 756 | + * Tableau des traductions possibles classées par langue |
|
| 757 | + * |
|
| 758 | + * Tableau code de langue => texte |
|
| 759 | + */ |
|
| 760 | + public array $traductions = []; |
|
| 761 | + |
|
| 762 | + /** Numéro de ligne dans le code source du squelette */ |
|
| 763 | + public int $ligne = 0; |
|
| 764 | 764 | } |
| 765 | 765 | |
| 766 | 766 | |
@@ -783,90 +783,90 @@ discard block |
||
| 783 | 783 | */ |
| 784 | 784 | function declarer_interfaces() { |
| 785 | 785 | |
| 786 | - $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 787 | - $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 788 | - $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 789 | - $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 790 | - |
|
| 791 | - // definition des statuts de publication |
|
| 792 | - $GLOBALS['table_statut'] = []; |
|
| 793 | - |
|
| 794 | - // |
|
| 795 | - // tableau des tables de jointures |
|
| 796 | - // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 797 | - $GLOBALS['tables_jointures'] = []; |
|
| 798 | - $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 799 | - |
|
| 800 | - // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 801 | - $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 802 | - |
|
| 803 | - |
|
| 804 | - if (!defined('_TRAITEMENT_TYPO')) { |
|
| 805 | - define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 806 | - } |
|
| 807 | - if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 808 | - define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 809 | - } |
|
| 810 | - if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 811 | - define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 812 | - } |
|
| 813 | - $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 814 | - $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 815 | - $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 816 | - $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 817 | - $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 818 | - $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 819 | - $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 820 | - $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 821 | - $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 822 | - $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 823 | - $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 824 | - $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 825 | - $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 826 | - $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 827 | - $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 828 | - $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 829 | - $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 830 | - $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 831 | - $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 832 | - $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 833 | - $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 834 | - $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 835 | - $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 836 | - $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 837 | - |
|
| 838 | - // valeur par defaut pour les balises non listees ci-dessus |
|
| 839 | - $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 840 | - // toujours securiser les DATA |
|
| 841 | - $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 842 | - // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 843 | - $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 844 | - |
|
| 845 | - |
|
| 846 | - // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 847 | - $interfaces = pipeline( |
|
| 848 | - 'declarer_tables_interfaces', |
|
| 849 | - [ |
|
| 850 | - 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 851 | - 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 852 | - 'table_date' => $GLOBALS['table_date'], |
|
| 853 | - 'table_titre' => $GLOBALS['table_titre'], |
|
| 854 | - 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 855 | - 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 856 | - 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 857 | - 'table_statut' => $GLOBALS['table_statut'], |
|
| 858 | - ] |
|
| 859 | - ); |
|
| 860 | - if ($interfaces) { |
|
| 861 | - $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 862 | - $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 863 | - $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 864 | - $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 865 | - $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 866 | - $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 867 | - $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 868 | - $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 869 | - } |
|
| 786 | + $GLOBALS['table_des_tables']['articles'] = 'articles'; |
|
| 787 | + $GLOBALS['table_des_tables']['auteurs'] = 'auteurs'; |
|
| 788 | + $GLOBALS['table_des_tables']['rubriques'] = 'rubriques'; |
|
| 789 | + $GLOBALS['table_des_tables']['hierarchie'] = 'rubriques'; |
|
| 790 | + |
|
| 791 | + // definition des statuts de publication |
|
| 792 | + $GLOBALS['table_statut'] = []; |
|
| 793 | + |
|
| 794 | + // |
|
| 795 | + // tableau des tables de jointures |
|
| 796 | + // Ex: gestion du critere {id_mot} dans la boucle(ARTICLES) |
|
| 797 | + $GLOBALS['tables_jointures'] = []; |
|
| 798 | + $GLOBALS['tables_jointures']['spip_jobs'][] = 'jobs_liens'; |
|
| 799 | + |
|
| 800 | + // $GLOBALS['exceptions_des_jointures']['titre_mot'] = array('spip_mots', 'titre'); // pour exemple |
|
| 801 | + $GLOBALS['exceptions_des_jointures']['profondeur'] = ['spip_rubriques', 'profondeur']; |
|
| 802 | + |
|
| 803 | + |
|
| 804 | + if (!defined('_TRAITEMENT_TYPO')) { |
|
| 805 | + define('_TRAITEMENT_TYPO', 'typo(%s, "TYPO", $connect, $Pile[0])'); |
|
| 806 | + } |
|
| 807 | + if (!defined('_TRAITEMENT_RACCOURCIS')) { |
|
| 808 | + define('_TRAITEMENT_RACCOURCIS', 'propre(%s, $connect, $Pile[0])'); |
|
| 809 | + } |
|
| 810 | + if (!defined('_TRAITEMENT_TYPO_SANS_NUMERO')) { |
|
| 811 | + define('_TRAITEMENT_TYPO_SANS_NUMERO', 'supprimer_numero(typo(%s, "TYPO", $connect, $Pile[0]))'); |
|
| 812 | + } |
|
| 813 | + $GLOBALS['table_des_traitements']['BIO'][] = 'safehtml(' . _TRAITEMENT_RACCOURCIS . ')'; |
|
| 814 | + $GLOBALS['table_des_traitements']['NOM_SITE']['spip_auteurs'] = 'entites_html(%s)'; |
|
| 815 | + $GLOBALS['table_des_traitements']['NOM']['spip_auteurs'] = 'safehtml(' . _TRAITEMENT_TYPO_SANS_NUMERO . ')'; |
|
| 816 | + $GLOBALS['table_des_traitements']['CHAPO'][] = _TRAITEMENT_RACCOURCIS; |
|
| 817 | + $GLOBALS['table_des_traitements']['DATE'][] = 'normaliser_date(%s)'; |
|
| 818 | + $GLOBALS['table_des_traitements']['DATE_REDAC'][] = 'normaliser_date(%s)'; |
|
| 819 | + $GLOBALS['table_des_traitements']['DATE_MODIF'][] = 'normaliser_date(%s)'; |
|
| 820 | + $GLOBALS['table_des_traitements']['DATE_NOUVEAUTES'][] = 'normaliser_date(%s)'; |
|
| 821 | + $GLOBALS['table_des_traitements']['DESCRIPTIF'][] = _TRAITEMENT_RACCOURCIS; |
|
| 822 | + $GLOBALS['table_des_traitements']['INTRODUCTION'][] = _TRAITEMENT_RACCOURCIS; |
|
| 823 | + $GLOBALS['table_des_traitements']['NOM_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 824 | + $GLOBALS['table_des_traitements']['NOM'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 825 | + $GLOBALS['table_des_traitements']['AUTEUR'][] = _TRAITEMENT_TYPO; |
|
| 826 | + $GLOBALS['table_des_traitements']['PS'][] = _TRAITEMENT_RACCOURCIS; |
|
| 827 | + $GLOBALS['table_des_traitements']['SOURCE'][] = _TRAITEMENT_TYPO; |
|
| 828 | + $GLOBALS['table_des_traitements']['SOUSTITRE'][] = _TRAITEMENT_TYPO; |
|
| 829 | + $GLOBALS['table_des_traitements']['SURTITRE'][] = _TRAITEMENT_TYPO; |
|
| 830 | + $GLOBALS['table_des_traitements']['TAGS'][] = '%s'; |
|
| 831 | + $GLOBALS['table_des_traitements']['TEXTE'][] = _TRAITEMENT_RACCOURCIS; |
|
| 832 | + $GLOBALS['table_des_traitements']['TITRE'][] = _TRAITEMENT_TYPO_SANS_NUMERO; |
|
| 833 | + $GLOBALS['table_des_traitements']['TYPE'][] = _TRAITEMENT_TYPO; |
|
| 834 | + $GLOBALS['table_des_traitements']['DESCRIPTIF_SITE_SPIP'][] = _TRAITEMENT_RACCOURCIS; |
|
| 835 | + $GLOBALS['table_des_traitements']['SLOGAN_SITE_SPIP'][] = _TRAITEMENT_TYPO; |
|
| 836 | + $GLOBALS['table_des_traitements']['ENV'][] = 'entites_html(%s,true)'; |
|
| 837 | + |
|
| 838 | + // valeur par defaut pour les balises non listees ci-dessus |
|
| 839 | + $GLOBALS['table_des_traitements']['*'][] = false; // pas de traitement, mais permet au compilo de trouver la declaration suivante |
|
| 840 | + // toujours securiser les DATA |
|
| 841 | + $GLOBALS['table_des_traitements']['*']['DATA'] = 'safehtml(%s)'; |
|
| 842 | + // expliciter pour VALEUR qui est un champ calcule et ne sera pas protege par le catch-all * |
|
| 843 | + $GLOBALS['table_des_traitements']['VALEUR']['DATA'] = 'safehtml(%s)'; |
|
| 844 | + |
|
| 845 | + |
|
| 846 | + // gerer l'affectation en 2 temps car si le pipe n'est pas encore declare, on ecrase les globales |
|
| 847 | + $interfaces = pipeline( |
|
| 848 | + 'declarer_tables_interfaces', |
|
| 849 | + [ |
|
| 850 | + 'table_des_tables' => $GLOBALS['table_des_tables'], |
|
| 851 | + 'exceptions_des_tables' => $GLOBALS['exceptions_des_tables'], |
|
| 852 | + 'table_date' => $GLOBALS['table_date'], |
|
| 853 | + 'table_titre' => $GLOBALS['table_titre'], |
|
| 854 | + 'tables_jointures' => $GLOBALS['tables_jointures'], |
|
| 855 | + 'exceptions_des_jointures' => $GLOBALS['exceptions_des_jointures'], |
|
| 856 | + 'table_des_traitements' => $GLOBALS['table_des_traitements'], |
|
| 857 | + 'table_statut' => $GLOBALS['table_statut'], |
|
| 858 | + ] |
|
| 859 | + ); |
|
| 860 | + if ($interfaces) { |
|
| 861 | + $GLOBALS['table_des_tables'] = $interfaces['table_des_tables']; |
|
| 862 | + $GLOBALS['exceptions_des_tables'] = $interfaces['exceptions_des_tables']; |
|
| 863 | + $GLOBALS['table_date'] = $interfaces['table_date']; |
|
| 864 | + $GLOBALS['table_titre'] = $interfaces['table_titre']; |
|
| 865 | + $GLOBALS['tables_jointures'] = $interfaces['tables_jointures']; |
|
| 866 | + $GLOBALS['exceptions_des_jointures'] = $interfaces['exceptions_des_jointures']; |
|
| 867 | + $GLOBALS['table_des_traitements'] = $interfaces['table_des_traitements']; |
|
| 868 | + $GLOBALS['table_statut'] = $interfaces['table_statut']; |
|
| 869 | + } |
|
| 870 | 870 | } |
| 871 | 871 | |
| 872 | 872 | declarer_interfaces(); |
@@ -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 | /** Repérer un code ne calculant rien, meme avec commentaire */ |
@@ -58,92 +58,92 @@ discard block |
||
| 58 | 58 | |
| 59 | 59 | |
| 60 | 60 | function argumenter_inclure( |
| 61 | - $params, |
|
| 62 | - $rejet_filtres, |
|
| 63 | - $p, |
|
| 64 | - &$boucles, |
|
| 65 | - $id_boucle, |
|
| 66 | - $echap = true, |
|
| 67 | - $lang = '', |
|
| 68 | - $fond1 = false |
|
| 61 | + $params, |
|
| 62 | + $rejet_filtres, |
|
| 63 | + $p, |
|
| 64 | + &$boucles, |
|
| 65 | + $id_boucle, |
|
| 66 | + $echap = true, |
|
| 67 | + $lang = '', |
|
| 68 | + $fond1 = false |
|
| 69 | 69 | ) { |
| 70 | - $l = []; |
|
| 71 | - $erreur_p_i_i = ''; |
|
| 72 | - if (!is_array($params)) { |
|
| 73 | - return $l; |
|
| 74 | - } |
|
| 75 | - foreach ($params as $k => $couple) { |
|
| 76 | - // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | - $filtre = array_shift($couple); |
|
| 78 | - if ($filtre) { |
|
| 79 | - break; |
|
| 80 | - } |
|
| 81 | - foreach ($couple as $n => $val) { |
|
| 82 | - $var = $val[0]; |
|
| 83 | - if ($var->type != 'texte') { |
|
| 84 | - if ($n or $k or $fond1) { |
|
| 85 | - $erreur_p_i_i = [ |
|
| 86 | - 'zbug_parametres_inclus_incorrects', |
|
| 87 | - ['param' => $var->nom_champ] |
|
| 88 | - ]; |
|
| 89 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | - break; |
|
| 91 | - } else { |
|
| 92 | - $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | - } |
|
| 94 | - } else { |
|
| 95 | - preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | - $m = array_pad($m, 3, null); |
|
| 97 | - $var = $m[1]; |
|
| 98 | - $auto = false; |
|
| 70 | + $l = []; |
|
| 71 | + $erreur_p_i_i = ''; |
|
| 72 | + if (!is_array($params)) { |
|
| 73 | + return $l; |
|
| 74 | + } |
|
| 75 | + foreach ($params as $k => $couple) { |
|
| 76 | + // la liste d'arguments d'inclusion peut se terminer par un filtre |
|
| 77 | + $filtre = array_shift($couple); |
|
| 78 | + if ($filtre) { |
|
| 79 | + break; |
|
| 80 | + } |
|
| 81 | + foreach ($couple as $n => $val) { |
|
| 82 | + $var = $val[0]; |
|
| 83 | + if ($var->type != 'texte') { |
|
| 84 | + if ($n or $k or $fond1) { |
|
| 85 | + $erreur_p_i_i = [ |
|
| 86 | + 'zbug_parametres_inclus_incorrects', |
|
| 87 | + ['param' => $var->nom_champ] |
|
| 88 | + ]; |
|
| 89 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 90 | + break; |
|
| 91 | + } else { |
|
| 92 | + $l[1] = calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 93 | + } |
|
| 94 | + } else { |
|
| 95 | + preg_match(',^([^=]*)(=?)(.*)$,m', $var->texte, $m); |
|
| 96 | + $m = array_pad($m, 3, null); |
|
| 97 | + $var = $m[1]; |
|
| 98 | + $auto = false; |
|
| 99 | 99 | ; |
| 100 | - if ($m[2]) { |
|
| 101 | - $v = $m[3]; |
|
| 102 | - if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | - $v = $m[1]; |
|
| 104 | - } |
|
| 105 | - $val[0] = new Texte(); |
|
| 106 | - $val[0]->texte = $v; |
|
| 107 | - } elseif ($k or $n or $fond1) { |
|
| 108 | - $auto = true; |
|
| 109 | - } else { |
|
| 110 | - $var = 1; |
|
| 111 | - } |
|
| 112 | - |
|
| 113 | - if ($var == 'lang') { |
|
| 114 | - $lang = !$auto |
|
| 115 | - ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | - : '$GLOBALS["spip_lang"]'; |
|
| 117 | - } else { |
|
| 118 | - $val = $auto |
|
| 119 | - ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | - : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | - if ($var !== 1) { |
|
| 122 | - $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | - . $val . ($echap ? ") . '" : ' '); |
|
| 124 | - } else { |
|
| 125 | - $val = $echap ? "'.$val.'" : $val; |
|
| 126 | - } |
|
| 127 | - $l[$var] = $val; |
|
| 128 | - } |
|
| 129 | - } |
|
| 130 | - } |
|
| 131 | - } |
|
| 132 | - if ($erreur_p_i_i) { |
|
| 133 | - return false; |
|
| 134 | - } |
|
| 135 | - // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | - // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | - // sauf si on n'en veut pas |
|
| 138 | - if ($lang === false) { |
|
| 139 | - return $l; |
|
| 140 | - } |
|
| 141 | - if (!$lang) { |
|
| 142 | - $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | - } |
|
| 144 | - $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | - |
|
| 146 | - return $l; |
|
| 100 | + if ($m[2]) { |
|
| 101 | + $v = $m[3]; |
|
| 102 | + if (preg_match(',^[\'"](.*)[\'"]$,', $v, $m)) { |
|
| 103 | + $v = $m[1]; |
|
| 104 | + } |
|
| 105 | + $val[0] = new Texte(); |
|
| 106 | + $val[0]->texte = $v; |
|
| 107 | + } elseif ($k or $n or $fond1) { |
|
| 108 | + $auto = true; |
|
| 109 | + } else { |
|
| 110 | + $var = 1; |
|
| 111 | + } |
|
| 112 | + |
|
| 113 | + if ($var == 'lang') { |
|
| 114 | + $lang = !$auto |
|
| 115 | + ? calculer_liste($val, $p->descr, $boucles, $id_boucle) |
|
| 116 | + : '$GLOBALS["spip_lang"]'; |
|
| 117 | + } else { |
|
| 118 | + $val = $auto |
|
| 119 | + ? index_pile($id_boucle, $var, $boucles) |
|
| 120 | + : calculer_liste($val, $p->descr, $boucles, $id_boucle); |
|
| 121 | + if ($var !== 1) { |
|
| 122 | + $val = ($echap ? "\'$var\' => ' . argumenter_squelette(" : "'$var' => ") |
|
| 123 | + . $val . ($echap ? ") . '" : ' '); |
|
| 124 | + } else { |
|
| 125 | + $val = $echap ? "'.$val.'" : $val; |
|
| 126 | + } |
|
| 127 | + $l[$var] = $val; |
|
| 128 | + } |
|
| 129 | + } |
|
| 130 | + } |
|
| 131 | + } |
|
| 132 | + if ($erreur_p_i_i) { |
|
| 133 | + return false; |
|
| 134 | + } |
|
| 135 | + // Cas particulier de la langue : si {lang=xx} est definie, on |
|
| 136 | + // la passe, sinon on passe la langue courante au moment du calcul |
|
| 137 | + // sauf si on n'en veut pas |
|
| 138 | + if ($lang === false) { |
|
| 139 | + return $l; |
|
| 140 | + } |
|
| 141 | + if (!$lang) { |
|
| 142 | + $lang = '$GLOBALS["spip_lang"]'; |
|
| 143 | + } |
|
| 144 | + $l['lang'] = ($echap ? "\'lang\' => ' . argumenter_squelette(" : "'lang' => ") . $lang . ($echap ? ") . '" : ' '); |
|
| 145 | + |
|
| 146 | + return $l; |
|
| 147 | 147 | } |
| 148 | 148 | |
| 149 | 149 | /** |
@@ -167,84 +167,84 @@ discard block |
||
| 167 | 167 | **/ |
| 168 | 168 | function calculer_inclure($p, &$boucles, $id_boucle) { |
| 169 | 169 | |
| 170 | - $_options = []; |
|
| 171 | - $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | - if (is_string($p->texte)) { |
|
| 173 | - $fichier = $p->texte; |
|
| 174 | - $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | - } else { |
|
| 176 | - $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | - if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | - $fichier = $r[1]; |
|
| 179 | - } else { |
|
| 180 | - $fichier = ''; |
|
| 181 | - } |
|
| 182 | - } |
|
| 183 | - if (!$code or $code === '""' or $code === "''") { |
|
| 184 | - $trace = $p->fonctions; |
|
| 185 | - while ( |
|
| 186 | - is_array($trace) |
|
| 187 | - and $trace = array_filter($trace) |
|
| 188 | - and count($trace) == 1 |
|
| 189 | - ) { |
|
| 190 | - $trace = reset($trace); |
|
| 191 | - } |
|
| 192 | - $erreur_p_i_i = [ |
|
| 193 | - 'zbug_parametres_inclus_incorrects', |
|
| 194 | - ['param' => print_r($trace, true)] |
|
| 195 | - ]; |
|
| 196 | - erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | - |
|
| 198 | - return "''"; |
|
| 199 | - } |
|
| 200 | - $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | - |
|
| 202 | - if (is_array($_contexte)) { |
|
| 203 | - // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | - if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | - unset($_contexte['env']); |
|
| 206 | - } |
|
| 207 | - |
|
| 208 | - // noter les doublons dans l'appel a public.php |
|
| 209 | - if (isset($_contexte['doublons'])) { |
|
| 210 | - $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | - } |
|
| 212 | - |
|
| 213 | - if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | - $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | - unset($_contexte['ajax']); |
|
| 216 | - } |
|
| 217 | - |
|
| 218 | - $_contexte = join(",\n\t", $_contexte); |
|
| 219 | - } else { |
|
| 220 | - return false; |
|
| 221 | - } // j'aurais voulu toucher le fond ... |
|
| 222 | - |
|
| 223 | - $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | - |
|
| 225 | - if ($env) { |
|
| 226 | - $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | - } |
|
| 228 | - |
|
| 229 | - // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | - if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | - $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | - } else { |
|
| 233 | - $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | - if ($ajax) { |
|
| 235 | - $_options[] = $ajax; |
|
| 236 | - } |
|
| 237 | - $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | - $code = 'echo ' . sprintf( |
|
| 239 | - CODE_RECUPERER_FOND, |
|
| 240 | - $code, |
|
| 241 | - $contexte, |
|
| 242 | - implode(',', $_options), |
|
| 243 | - "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | - ) . ';'; |
|
| 245 | - } |
|
| 246 | - |
|
| 247 | - return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 170 | + $_options = []; |
|
| 171 | + $_contexte = argumenter_inclure($p->param, false, $p, $boucles, $id_boucle, true, '', true); |
|
| 172 | + if (is_string($p->texte)) { |
|
| 173 | + $fichier = $p->texte; |
|
| 174 | + $code = '"' . str_replace('"', '\"', $fichier) . '"'; |
|
| 175 | + } else { |
|
| 176 | + $code = calculer_liste($p->texte, $p->descr, $boucles, $id_boucle); |
|
| 177 | + if ($code and preg_match("/^'([^']*)'/s", $code, $r)) { |
|
| 178 | + $fichier = $r[1]; |
|
| 179 | + } else { |
|
| 180 | + $fichier = ''; |
|
| 181 | + } |
|
| 182 | + } |
|
| 183 | + if (!$code or $code === '""' or $code === "''") { |
|
| 184 | + $trace = $p->fonctions; |
|
| 185 | + while ( |
|
| 186 | + is_array($trace) |
|
| 187 | + and $trace = array_filter($trace) |
|
| 188 | + and count($trace) == 1 |
|
| 189 | + ) { |
|
| 190 | + $trace = reset($trace); |
|
| 191 | + } |
|
| 192 | + $erreur_p_i_i = [ |
|
| 193 | + 'zbug_parametres_inclus_incorrects', |
|
| 194 | + ['param' => print_r($trace, true)] |
|
| 195 | + ]; |
|
| 196 | + erreur_squelette($erreur_p_i_i, $p); |
|
| 197 | + |
|
| 198 | + return "''"; |
|
| 199 | + } |
|
| 200 | + $compil = texte_script(memoriser_contexte_compil($p)); |
|
| 201 | + |
|
| 202 | + if (is_array($_contexte)) { |
|
| 203 | + // Critere d'inclusion {env} (et {self} pour compatibilite ascendante) |
|
| 204 | + if ($env = (isset($_contexte['env']) || isset($_contexte['self']))) { |
|
| 205 | + unset($_contexte['env']); |
|
| 206 | + } |
|
| 207 | + |
|
| 208 | + // noter les doublons dans l'appel a public.php |
|
| 209 | + if (isset($_contexte['doublons'])) { |
|
| 210 | + $_contexte['doublons'] = "\\'doublons\\' => '.var_export(\$doublons,true).'"; |
|
| 211 | + } |
|
| 212 | + |
|
| 213 | + if ($ajax = isset($_contexte['ajax'])) { |
|
| 214 | + $ajax = preg_replace(',=>(.*)$,ims', '=> ($v=(\\1))?$v:true', $_contexte['ajax']); |
|
| 215 | + unset($_contexte['ajax']); |
|
| 216 | + } |
|
| 217 | + |
|
| 218 | + $_contexte = join(",\n\t", $_contexte); |
|
| 219 | + } else { |
|
| 220 | + return false; |
|
| 221 | + } // j'aurais voulu toucher le fond ... |
|
| 222 | + |
|
| 223 | + $contexte = 'array(' . $_contexte . ')'; |
|
| 224 | + |
|
| 225 | + if ($env) { |
|
| 226 | + $contexte = "array_merge('.var_export(\$Pile[0],1).',$contexte)"; |
|
| 227 | + } |
|
| 228 | + |
|
| 229 | + // s'il y a une extension .php, ce n'est pas un squelette |
|
| 230 | + if ($fichier and preg_match('/^.+[.]php$/s', $fichier)) { |
|
| 231 | + $code = sandbox_composer_inclure_php($fichier, $p, $contexte); |
|
| 232 | + } else { |
|
| 233 | + $_options[] = "\"compil\"=>array($compil)"; |
|
| 234 | + if ($ajax) { |
|
| 235 | + $_options[] = $ajax; |
|
| 236 | + } |
|
| 237 | + $code = " ' . argumenter_squelette($code) . '"; |
|
| 238 | + $code = 'echo ' . sprintf( |
|
| 239 | + CODE_RECUPERER_FOND, |
|
| 240 | + $code, |
|
| 241 | + $contexte, |
|
| 242 | + implode(',', $_options), |
|
| 243 | + "_request(\\'connect\\') ?? \\'\\'" |
|
| 244 | + ) . ';'; |
|
| 245 | + } |
|
| 246 | + |
|
| 247 | + return "\n'<'.'" . '?php ' . $code . "\n?'." . "'>'"; |
|
| 248 | 248 | } |
| 249 | 249 | |
| 250 | 250 | |
@@ -262,7 +262,7 @@ discard block |
||
| 262 | 262 | * true pour ne tester que le cas publie et ignorer l'eventuel var_mode=preview de la page |
| 263 | 263 | */ |
| 264 | 264 | function instituer_boucle(&$boucle, $echapper = true, $ignore_previsu = false) { |
| 265 | - /* |
|
| 265 | + /* |
|
| 266 | 266 | $show['statut'][] = array( |
| 267 | 267 | 'champ'=>'statut', // champ de la table sur lequel porte le filtrage par le statut |
| 268 | 268 | 'publie'=>'publie', // valeur ou liste de valeurs, qui definissent l'objet comme publie. |
@@ -286,74 +286,74 @@ discard block |
||
| 286 | 286 | champstatut est alors le champ statut sur la tablen |
| 287 | 287 | dans les jointures, clen peut etre un tableau pour une jointure complexe : array('id_objet','id_article','objet','article') |
| 288 | 288 | */ |
| 289 | - $id_table = $boucle->id_table; |
|
| 290 | - $show = $boucle->show; |
|
| 291 | - if (isset($show['statut']) and $show['statut']) { |
|
| 292 | - foreach ($show['statut'] as $k => $s) { |
|
| 293 | - // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | - $filtrer = true; |
|
| 295 | - if (isset($s['exception'])) { |
|
| 296 | - foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | - if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | - $filtrer = false; |
|
| 299 | - break; |
|
| 300 | - } |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - |
|
| 304 | - if ($filtrer) { |
|
| 305 | - if (is_array($s['champ'])) { |
|
| 306 | - $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | - $jointures = []; |
|
| 308 | - // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | - // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | - foreach ($s['champ'] as $j) { |
|
| 312 | - $id = reset($j); |
|
| 313 | - $def = $trouver_table($id); |
|
| 314 | - $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | - } |
|
| 316 | - $jointures[0][0] = $id_table; |
|
| 317 | - if (!array_search($id, $boucle->from)) { |
|
| 318 | - include_spip('public/jointures'); |
|
| 319 | - fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | - } |
|
| 321 | - // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | - $id = array_search($id, $boucle->from); |
|
| 323 | - } else { |
|
| 324 | - $id = $id_table; |
|
| 325 | - $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | - } |
|
| 327 | - $mstatut = $id . '.' . $statut; |
|
| 328 | - |
|
| 329 | - $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | - include_spip('public/quete'); |
|
| 331 | - if ( |
|
| 332 | - isset($s['post_date']) and $s['post_date'] |
|
| 333 | - and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | - ) { |
|
| 335 | - $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | - array_unshift( |
|
| 337 | - $boucle->where, |
|
| 338 | - $echapper ? |
|
| 339 | - "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | - : |
|
| 341 | - quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | - ); |
|
| 343 | - } |
|
| 344 | - array_unshift( |
|
| 345 | - $boucle->where, |
|
| 346 | - $echapper ? |
|
| 347 | - "\nquete_condition_statut('$mstatut'," |
|
| 348 | - . _q($s['previsu']) . ',' |
|
| 349 | - . _q($s['publie']) . ',' |
|
| 350 | - . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | - : |
|
| 352 | - quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | - ); |
|
| 354 | - } |
|
| 355 | - } |
|
| 356 | - } |
|
| 289 | + $id_table = $boucle->id_table; |
|
| 290 | + $show = $boucle->show; |
|
| 291 | + if (isset($show['statut']) and $show['statut']) { |
|
| 292 | + foreach ($show['statut'] as $k => $s) { |
|
| 293 | + // Restreindre aux elements publies si pas de {statut} ou autre dans les criteres |
|
| 294 | + $filtrer = true; |
|
| 295 | + if (isset($s['exception'])) { |
|
| 296 | + foreach (is_array($s['exception']) ? $s['exception'] : [$s['exception']] as $m) { |
|
| 297 | + if (isset($boucle->modificateur[$m]) or isset($boucle->modificateur['criteres'][$m])) { |
|
| 298 | + $filtrer = false; |
|
| 299 | + break; |
|
| 300 | + } |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + |
|
| 304 | + if ($filtrer) { |
|
| 305 | + if (is_array($s['champ'])) { |
|
| 306 | + $statut = preg_replace(',\W,', '', array_pop($s['champ'])); // securite |
|
| 307 | + $jointures = []; |
|
| 308 | + // indiquer la description de chaque table dans le tableau de jointures, |
|
| 309 | + // ce qui permet d'eviter certains GROUP BY inutiles. |
|
| 310 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 311 | + foreach ($s['champ'] as $j) { |
|
| 312 | + $id = reset($j); |
|
| 313 | + $def = $trouver_table($id); |
|
| 314 | + $jointures[] = ['', [$id, $def], end($j)]; |
|
| 315 | + } |
|
| 316 | + $jointures[0][0] = $id_table; |
|
| 317 | + if (!array_search($id, $boucle->from)) { |
|
| 318 | + include_spip('public/jointures'); |
|
| 319 | + fabrique_jointures($boucle, $jointures, true, $boucle->show, $id_table, '', $echapper); |
|
| 320 | + } |
|
| 321 | + // trouver l'alias de la table d'arrivee qui porte le statut |
|
| 322 | + $id = array_search($id, $boucle->from); |
|
| 323 | + } else { |
|
| 324 | + $id = $id_table; |
|
| 325 | + $statut = preg_replace(',\W,', '', $s['champ']); // securite |
|
| 326 | + } |
|
| 327 | + $mstatut = $id . '.' . $statut; |
|
| 328 | + |
|
| 329 | + $arg_ignore_previsu = ($ignore_previsu ? ',true' : ''); |
|
| 330 | + include_spip('public/quete'); |
|
| 331 | + if ( |
|
| 332 | + isset($s['post_date']) and $s['post_date'] |
|
| 333 | + and $GLOBALS['meta']['post_dates'] == 'non' |
|
| 334 | + ) { |
|
| 335 | + $date = $id . '.' . preg_replace(',\W,', '', $s['post_date']); // securite |
|
| 336 | + array_unshift( |
|
| 337 | + $boucle->where, |
|
| 338 | + $echapper ? |
|
| 339 | + "\nquete_condition_postdates('$date'," . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 340 | + : |
|
| 341 | + quete_condition_postdates($date, $boucle->sql_serveur, $ignore_previsu) |
|
| 342 | + ); |
|
| 343 | + } |
|
| 344 | + array_unshift( |
|
| 345 | + $boucle->where, |
|
| 346 | + $echapper ? |
|
| 347 | + "\nquete_condition_statut('$mstatut'," |
|
| 348 | + . _q($s['previsu']) . ',' |
|
| 349 | + . _q($s['publie']) . ',' |
|
| 350 | + . _q($boucle->sql_serveur) . "$arg_ignore_previsu)" |
|
| 351 | + : |
|
| 352 | + quete_condition_statut($mstatut, $s['previsu'], $s['publie'], $boucle->sql_serveur, $ignore_previsu) |
|
| 353 | + ); |
|
| 354 | + } |
|
| 355 | + } |
|
| 356 | + } |
|
| 357 | 357 | } |
| 358 | 358 | |
| 359 | 359 | /** |
@@ -372,29 +372,29 @@ discard block |
||
| 372 | 372 | */ |
| 373 | 373 | function calculer_boucle($id_boucle, &$boucles) { |
| 374 | 374 | |
| 375 | - $boucle = &$boucles[$id_boucle]; |
|
| 376 | - instituer_boucle($boucle); |
|
| 377 | - $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | - |
|
| 379 | - // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | - // mais pas tous, sinon ca pete. |
|
| 381 | - if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | - $trace = ''; |
|
| 383 | - } else { |
|
| 384 | - $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | - $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | - $trace = " |
|
| 375 | + $boucle = &$boucles[$id_boucle]; |
|
| 376 | + instituer_boucle($boucle); |
|
| 377 | + $boucles[$id_boucle] = pipeline('post_boucle', $boucles[$id_boucle]); |
|
| 378 | + |
|
| 379 | + // en mode debug memoriser les premiers passages dans la boucle, |
|
| 380 | + // mais pas tous, sinon ca pete. |
|
| 381 | + if (_request('var_mode_affiche') != 'resultat') { |
|
| 382 | + $trace = ''; |
|
| 383 | + } else { |
|
| 384 | + $_trace = $boucles[$id_boucle]->descr['nom'] . $id_boucle; |
|
| 385 | + $_trace = "\$GLOBALS['debug_objets']['resultat']['$_trace']"; |
|
| 386 | + $trace = " |
|
| 387 | 387 | if (empty($_trace)) { |
| 388 | 388 | $_trace = []; |
| 389 | 389 | } |
| 390 | 390 | if (count($_trace) < 3) { |
| 391 | 391 | $_trace" . '[] = $t0; |
| 392 | 392 | }'; |
| 393 | - } |
|
| 393 | + } |
|
| 394 | 394 | |
| 395 | - return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | - ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | - : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 395 | + return ($boucles[$id_boucle]->type_requete == TYPE_RECURSIF) |
|
| 396 | + ? calculer_boucle_rec($id_boucle, $boucles, $trace) |
|
| 397 | + : calculer_boucle_nonrec($id_boucle, $boucles, $trace); |
|
| 398 | 398 | } |
| 399 | 399 | |
| 400 | 400 | |
@@ -417,15 +417,15 @@ discard block |
||
| 417 | 417 | * Code PHP compilé de la boucle récursive |
| 418 | 418 | **/ |
| 419 | 419 | function calculer_boucle_rec($id_boucle, &$boucles, $trace) { |
| 420 | - $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | - |
|
| 422 | - return |
|
| 423 | - // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | - "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | - . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | - . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | - . $trace |
|
| 428 | - . "\n\treturn \$t0;"; |
|
| 420 | + $nom = $boucles[$id_boucle]->param[0]; |
|
| 421 | + |
|
| 422 | + return |
|
| 423 | + // Numrows[$nom] peut ne pas être encore defini |
|
| 424 | + "\n\t\$save_numrows = (isset(\$Numrows['$nom']) ? \$Numrows['$nom'] : array());" |
|
| 425 | + . "\n\t\$t0 = " . $boucles[$id_boucle]->return . ';' |
|
| 426 | + . "\n\t\$Numrows['$nom'] = (\$save_numrows);" |
|
| 427 | + . $trace |
|
| 428 | + . "\n\treturn \$t0;"; |
|
| 429 | 429 | } |
| 430 | 430 | |
| 431 | 431 | /** |
@@ -478,174 +478,174 @@ discard block |
||
| 478 | 478 | **/ |
| 479 | 479 | function calculer_boucle_nonrec($id_boucle, &$boucles, $trace) { |
| 480 | 480 | |
| 481 | - $code_sep = null; |
|
| 482 | - $boucle = &$boucles[$id_boucle]; |
|
| 483 | - $return = $boucle->return; |
|
| 484 | - $type_boucle = $boucle->type_requete; |
|
| 485 | - $primary = $boucle->primary; |
|
| 486 | - $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | - $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | - $corps = ''; |
|
| 489 | - |
|
| 490 | - // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | - // et puis faire un [] plutot qu'un "','." |
|
| 492 | - if ($boucle->doublons) { |
|
| 493 | - $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | - index_pile($id_boucle, $primary, $boucles) |
|
| 495 | - . "; // doublons\n"; |
|
| 496 | - } |
|
| 497 | - |
|
| 498 | - // La boucle doit-elle selectionner la langue ? |
|
| 499 | - // - par defaut, les boucles suivantes le font |
|
| 500 | - // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | - // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | - if ( |
|
| 503 | - !$constant && $boucle->lang_select != 'non' && |
|
| 504 | - (($boucle->lang_select == 'oui') || |
|
| 505 | - in_array($type_boucle, [ |
|
| 506 | - 'articles', |
|
| 507 | - 'rubriques', |
|
| 508 | - 'hierarchie', |
|
| 509 | - 'breves' |
|
| 510 | - ])) |
|
| 511 | - ) { |
|
| 512 | - // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | - // afin que le corps de boucle affecte la globale directement |
|
| 514 | - $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | - $fin_lang = "lang_select();\n\t"; |
|
| 516 | - $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | - |
|
| 518 | - $corps .= |
|
| 519 | - "\n\t\tlang_select_public(" |
|
| 520 | - . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | - . ", '" . $boucle->lang_select . "'" |
|
| 522 | - . (in_array($type_boucle, [ |
|
| 523 | - 'articles', |
|
| 524 | - 'rubriques', |
|
| 525 | - 'hierarchie', |
|
| 526 | - 'breves' |
|
| 527 | - ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | - . ');'; |
|
| 529 | - } else { |
|
| 530 | - $init_lang = ''; |
|
| 531 | - $fin_lang = ''; |
|
| 532 | - $fin_lang_select_public = ''; |
|
| 533 | - // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | - if ( |
|
| 535 | - strpos($return, '?php') === false |
|
| 536 | - and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | - ) { |
|
| 538 | - $i = 1; |
|
| 539 | - foreach ($r[1] as $t) { |
|
| 540 | - $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | - $return = str_replace($t, "\$l$i", $return); |
|
| 542 | - $i++; |
|
| 543 | - } |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - |
|
| 547 | - // gestion optimale des separateurs et des boucles constantes |
|
| 548 | - if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | - $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - $corps .= |
|
| 553 | - ((!$boucle->separateur) ? |
|
| 554 | - (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | - (($return === "''") ? '' : |
|
| 556 | - ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | - ("\n\t\t\$t1 " . |
|
| 558 | - ((strpos($return, '$t1.') === 0) ? |
|
| 559 | - ('.=' . substr($return, 4)) : |
|
| 560 | - ('= ' . $return)) . |
|
| 561 | - ";\n\t\t" . |
|
| 562 | - '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | - |
|
| 564 | - // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | - // souhaite invalider ces elements |
|
| 566 | - if (!$constant and $primary) { |
|
| 567 | - include_spip('inc/invalideur'); |
|
| 568 | - $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | - } |
|
| 570 | - |
|
| 571 | - // gerer le compteur de boucle |
|
| 572 | - // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | - |
|
| 574 | - if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | - $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | - . $boucle->partie |
|
| 577 | - . $corps; |
|
| 578 | - } |
|
| 579 | - |
|
| 580 | - // depiler la lang de la boucle si besoin |
|
| 581 | - $corps .= $fin_lang_select_public; |
|
| 582 | - |
|
| 583 | - // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | - |
|
| 585 | - if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | - if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | - if (!$boucle->numrows) { |
|
| 588 | - return "\n\t\$t0 = '';"; |
|
| 589 | - } else { |
|
| 590 | - $corps = ''; |
|
| 591 | - } |
|
| 592 | - } else { |
|
| 593 | - $boucle->numrows = true; |
|
| 594 | - $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | - } |
|
| 596 | - } else { |
|
| 597 | - $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | - } |
|
| 599 | - |
|
| 600 | - $count = ''; |
|
| 601 | - if (!$boucle->select) { |
|
| 602 | - if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | - $count = '1'; |
|
| 604 | - } else { |
|
| 605 | - $count = 'count(*)'; |
|
| 606 | - } |
|
| 607 | - $boucles[$id_boucle]->select[] = $count; |
|
| 608 | - } |
|
| 609 | - |
|
| 610 | - if ($flag_cpt) { |
|
| 611 | - $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | - . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | - } else { |
|
| 614 | - $nums = ''; |
|
| 615 | - } |
|
| 616 | - |
|
| 617 | - if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | - $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | - . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | - . $boucle->mode_partie |
|
| 621 | - . "\n\t"; |
|
| 622 | - } |
|
| 623 | - |
|
| 624 | - // Ne calculer la requete que maintenant |
|
| 625 | - // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | - |
|
| 627 | - $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | - ? ("\n\t$init = array();") : '') |
|
| 629 | - . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | - |
|
| 631 | - $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | - |
|
| 633 | - $a = sprintf( |
|
| 634 | - CODE_CORPS_BOUCLE, |
|
| 635 | - $init, |
|
| 636 | - $boucle->iterateur, |
|
| 637 | - '$command', |
|
| 638 | - $contexte, |
|
| 639 | - $nums, |
|
| 640 | - $init_lang, |
|
| 641 | - $corps, |
|
| 642 | - $fin_lang, |
|
| 643 | - $trace, |
|
| 644 | - 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | - ); |
|
| 481 | + $code_sep = null; |
|
| 482 | + $boucle = &$boucles[$id_boucle]; |
|
| 483 | + $return = $boucle->return; |
|
| 484 | + $type_boucle = $boucle->type_requete; |
|
| 485 | + $primary = $boucle->primary; |
|
| 486 | + $constant = preg_match(CODE_MONOTONE, str_replace("\\'", '', $return)); |
|
| 487 | + $flag_cpt = $boucle->mode_partie || $boucle->cptrows; |
|
| 488 | + $corps = ''; |
|
| 489 | + |
|
| 490 | + // faudrait expanser le foreach a la compil, car y en a souvent qu'un |
|
| 491 | + // et puis faire un [] plutot qu'un "','." |
|
| 492 | + if ($boucle->doublons) { |
|
| 493 | + $corps .= "\n\t\t\tforeach(" . $boucle->doublons . ' as $k) $doublons[$k] .= "," . ' . |
|
| 494 | + index_pile($id_boucle, $primary, $boucles) |
|
| 495 | + . "; // doublons\n"; |
|
| 496 | + } |
|
| 497 | + |
|
| 498 | + // La boucle doit-elle selectionner la langue ? |
|
| 499 | + // - par defaut, les boucles suivantes le font |
|
| 500 | + // (sauf si forcer_lang==true ou si le titre contient <multi>). |
|
| 501 | + // - a moins d'une demande explicite via {!lang_select} |
|
| 502 | + if ( |
|
| 503 | + !$constant && $boucle->lang_select != 'non' && |
|
| 504 | + (($boucle->lang_select == 'oui') || |
|
| 505 | + in_array($type_boucle, [ |
|
| 506 | + 'articles', |
|
| 507 | + 'rubriques', |
|
| 508 | + 'hierarchie', |
|
| 509 | + 'breves' |
|
| 510 | + ])) |
|
| 511 | + ) { |
|
| 512 | + // Memoriser la langue avant la boucle et la restituer apres |
|
| 513 | + // afin que le corps de boucle affecte la globale directement |
|
| 514 | + $init_lang = "lang_select(\$GLOBALS['spip_lang']);\n\t"; |
|
| 515 | + $fin_lang = "lang_select();\n\t"; |
|
| 516 | + $fin_lang_select_public = "\n\t\tlang_select();"; |
|
| 517 | + |
|
| 518 | + $corps .= |
|
| 519 | + "\n\t\tlang_select_public(" |
|
| 520 | + . index_pile($id_boucle, 'lang', $boucles) |
|
| 521 | + . ", '" . $boucle->lang_select . "'" |
|
| 522 | + . (in_array($type_boucle, [ |
|
| 523 | + 'articles', |
|
| 524 | + 'rubriques', |
|
| 525 | + 'hierarchie', |
|
| 526 | + 'breves' |
|
| 527 | + ]) ? ', ' . index_pile($id_boucle, 'titre', $boucles) : '') |
|
| 528 | + . ');'; |
|
| 529 | + } else { |
|
| 530 | + $init_lang = ''; |
|
| 531 | + $fin_lang = ''; |
|
| 532 | + $fin_lang_select_public = ''; |
|
| 533 | + // sortir les appels au traducteur (invariants de boucle) |
|
| 534 | + if ( |
|
| 535 | + strpos($return, '?php') === false |
|
| 536 | + and preg_match_all("/\W(_T[(]'[^']*'[)])/", $return, $r) |
|
| 537 | + ) { |
|
| 538 | + $i = 1; |
|
| 539 | + foreach ($r[1] as $t) { |
|
| 540 | + $init_lang .= "\n\t\$l$i = $t;"; |
|
| 541 | + $return = str_replace($t, "\$l$i", $return); |
|
| 542 | + $i++; |
|
| 543 | + } |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + |
|
| 547 | + // gestion optimale des separateurs et des boucles constantes |
|
| 548 | + if (is_countable($boucle->separateur) ? count($boucle->separateur) : 0) { |
|
| 549 | + $code_sep = ("'" . str_replace("'", "\'", join('', $boucle->separateur)) . "'"); |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + $corps .= |
|
| 553 | + ((!$boucle->separateur) ? |
|
| 554 | + (($constant && !$corps && !$flag_cpt) ? $return : |
|
| 555 | + (($return === "''") ? '' : |
|
| 556 | + ("\n\t\t" . '$t0 .= ' . $return . ';'))) : |
|
| 557 | + ("\n\t\t\$t1 " . |
|
| 558 | + ((strpos($return, '$t1.') === 0) ? |
|
| 559 | + ('.=' . substr($return, 4)) : |
|
| 560 | + ('= ' . $return)) . |
|
| 561 | + ";\n\t\t" . |
|
| 562 | + '$t0 .= ((strlen($t1) && strlen($t0)) ? ' . $code_sep . " : '') . \$t1;")); |
|
| 563 | + |
|
| 564 | + // Calculer les invalideurs si c'est une boucle non constante et si on |
|
| 565 | + // souhaite invalider ces elements |
|
| 566 | + if (!$constant and $primary) { |
|
| 567 | + include_spip('inc/invalideur'); |
|
| 568 | + $corps = calcul_invalideurs($corps, $primary, $boucles, $id_boucle); |
|
| 569 | + } |
|
| 570 | + |
|
| 571 | + // gerer le compteur de boucle |
|
| 572 | + // avec ou sans son utilisation par les criteres {1/3} {1,4} {n-2,1}... |
|
| 573 | + |
|
| 574 | + if ($boucle->partie or $boucle->cptrows) { |
|
| 575 | + $corps = "\n\t\t\$Numrows['$id_boucle']['compteur_boucle']++;" |
|
| 576 | + . $boucle->partie |
|
| 577 | + . $corps; |
|
| 578 | + } |
|
| 579 | + |
|
| 580 | + // depiler la lang de la boucle si besoin |
|
| 581 | + $corps .= $fin_lang_select_public; |
|
| 582 | + |
|
| 583 | + // si le corps est une constante, ne pas appeler le serveur N fois! |
|
| 584 | + |
|
| 585 | + if (preg_match(CODE_MONOTONE, str_replace("\\'", '', $corps), $r)) { |
|
| 586 | + if (!isset($r[2]) or (!$r[2])) { |
|
| 587 | + if (!$boucle->numrows) { |
|
| 588 | + return "\n\t\$t0 = '';"; |
|
| 589 | + } else { |
|
| 590 | + $corps = ''; |
|
| 591 | + } |
|
| 592 | + } else { |
|
| 593 | + $boucle->numrows = true; |
|
| 594 | + $corps = "\n\t\$t0 = str_repeat($corps, \$Numrows['$id_boucle']['total']);"; |
|
| 595 | + } |
|
| 596 | + } else { |
|
| 597 | + $corps = "while (\$Pile[\$SP]=\$iter->fetch()) {\n$corps\n }"; |
|
| 598 | + } |
|
| 599 | + |
|
| 600 | + $count = ''; |
|
| 601 | + if (!$boucle->select) { |
|
| 602 | + if (!$boucle->numrows or $boucle->limit or $boucle->mode_partie or $boucle->group) { |
|
| 603 | + $count = '1'; |
|
| 604 | + } else { |
|
| 605 | + $count = 'count(*)'; |
|
| 606 | + } |
|
| 607 | + $boucles[$id_boucle]->select[] = $count; |
|
| 608 | + } |
|
| 609 | + |
|
| 610 | + if ($flag_cpt) { |
|
| 611 | + $nums = "\n\t// COMPTEUR\n\t" |
|
| 612 | + . "\$Numrows['$id_boucle']['compteur_boucle'] = 0;\n\t"; |
|
| 613 | + } else { |
|
| 614 | + $nums = ''; |
|
| 615 | + } |
|
| 616 | + |
|
| 617 | + if ($boucle->numrows or $boucle->mode_partie) { |
|
| 618 | + $nums .= "\$Numrows['$id_boucle']['command'] = \$command;\n\t" |
|
| 619 | + . "\$Numrows['$id_boucle']['total'] = @intval(\$iter->count());" |
|
| 620 | + . $boucle->mode_partie |
|
| 621 | + . "\n\t"; |
|
| 622 | + } |
|
| 623 | + |
|
| 624 | + // Ne calculer la requete que maintenant |
|
| 625 | + // car ce qui precede appelle index_pile qui influe dessus |
|
| 626 | + |
|
| 627 | + $init = (($init = $boucles[$id_boucle]->doublons) |
|
| 628 | + ? ("\n\t$init = array();") : '') |
|
| 629 | + . calculer_requete_sql($boucles[$id_boucle]); |
|
| 630 | + |
|
| 631 | + $contexte = memoriser_contexte_compil($boucle); |
|
| 632 | + |
|
| 633 | + $a = sprintf( |
|
| 634 | + CODE_CORPS_BOUCLE, |
|
| 635 | + $init, |
|
| 636 | + $boucle->iterateur, |
|
| 637 | + '$command', |
|
| 638 | + $contexte, |
|
| 639 | + $nums, |
|
| 640 | + $init_lang, |
|
| 641 | + $corps, |
|
| 642 | + $fin_lang, |
|
| 643 | + $trace, |
|
| 644 | + 'BOUCLE' . $id_boucle . ' @ ' . ($boucle->descr['sourcefile']) |
|
| 645 | + ); |
|
| 646 | 646 | |
| 647 | 647 | # var_dump($a);exit; |
| 648 | - return $a; |
|
| 648 | + return $a; |
|
| 649 | 649 | } |
| 650 | 650 | |
| 651 | 651 | |
@@ -661,48 +661,48 @@ discard block |
||
| 661 | 661 | * Code PHP compilé définissant les informations de requête |
| 662 | 662 | **/ |
| 663 | 663 | function calculer_requete_sql($boucle) { |
| 664 | - $init = []; |
|
| 665 | - $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | - $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | - # En absence de champ c'est un decompte : |
|
| 668 | - $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | - $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | - $init[] = calculer_dec( |
|
| 671 | - 'groupby', |
|
| 672 | - 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | - ); |
|
| 674 | - $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | - $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | - $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | - $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | - $init[] = calculer_dec( |
|
| 679 | - 'limit', |
|
| 680 | - ( |
|
| 681 | - strpos($boucle->limit, 'intval') === false ? |
|
| 682 | - "'" . ($boucle->limit) . "'" : |
|
| 683 | - $boucle->limit |
|
| 684 | - ) |
|
| 685 | - ); |
|
| 686 | - $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | - $s = $d = ''; |
|
| 688 | - // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | - // ou recalculée à chaque passage (vide) |
|
| 690 | - foreach ($init as $i) { |
|
| 691 | - if (reset($i)) { |
|
| 692 | - $s .= "\n\t\t" . end($i); |
|
| 693 | - } # statique |
|
| 694 | - else { |
|
| 695 | - $d .= "\n\t" . end($i); |
|
| 696 | - } # dynamique |
|
| 697 | - } |
|
| 698 | - |
|
| 699 | - return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | - . $boucle->in |
|
| 701 | - . $boucle->hash |
|
| 702 | - . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | - . $s |
|
| 704 | - . "\n\t}" |
|
| 705 | - . $d; |
|
| 664 | + $init = []; |
|
| 665 | + $init[] = calculer_dec('table', "'" . $boucle->id_table . "'"); |
|
| 666 | + $init[] = calculer_dec('id', "'" . $boucle->id_boucle . "'"); |
|
| 667 | + # En absence de champ c'est un decompte : |
|
| 668 | + $init[] = calculer_dec('from', calculer_from($boucle)); |
|
| 669 | + $init[] = calculer_dec('type', calculer_from_type($boucle)); |
|
| 670 | + $init[] = calculer_dec( |
|
| 671 | + 'groupby', |
|
| 672 | + 'array(' . (($g = join("\",\n\t\t\"", $boucle->group)) ? '"' . $g . '"' : '') . ')' |
|
| 673 | + ); |
|
| 674 | + $init[] = calculer_dec('select', 'array("' . join("\",\n\t\t\"", $boucle->select) . '")'); |
|
| 675 | + $init[] = calculer_dec('orderby', 'array(' . calculer_order($boucle) . ')'); |
|
| 676 | + $init[] = calculer_dec('where', calculer_dump_array($boucle->where)); |
|
| 677 | + $init[] = calculer_dec('join', calculer_dump_join($boucle->join)); |
|
| 678 | + $init[] = calculer_dec( |
|
| 679 | + 'limit', |
|
| 680 | + ( |
|
| 681 | + strpos($boucle->limit, 'intval') === false ? |
|
| 682 | + "'" . ($boucle->limit) . "'" : |
|
| 683 | + $boucle->limit |
|
| 684 | + ) |
|
| 685 | + ); |
|
| 686 | + $init[] = calculer_dec('having', calculer_dump_array($boucle->having)); |
|
| 687 | + $s = $d = ''; |
|
| 688 | + // l'index 0 de $i indique si l'affectation est statique (contenu) |
|
| 689 | + // ou recalculée à chaque passage (vide) |
|
| 690 | + foreach ($init as $i) { |
|
| 691 | + if (reset($i)) { |
|
| 692 | + $s .= "\n\t\t" . end($i); |
|
| 693 | + } # statique |
|
| 694 | + else { |
|
| 695 | + $d .= "\n\t" . end($i); |
|
| 696 | + } # dynamique |
|
| 697 | + } |
|
| 698 | + |
|
| 699 | + return ($boucle->hierarchie ? "\n\t$boucle->hierarchie" : '') |
|
| 700 | + . $boucle->in |
|
| 701 | + . $boucle->hash |
|
| 702 | + . "\n\t" . 'if (!isset($command[\'table\'])) {' |
|
| 703 | + . $s |
|
| 704 | + . "\n\t}" |
|
| 705 | + . $d; |
|
| 706 | 706 | } |
| 707 | 707 | |
| 708 | 708 | /** |
@@ -720,13 +720,13 @@ discard block |
||
| 720 | 720 | * qui peut être utilisé pour la production d'un tableau array() |
| 721 | 721 | **/ |
| 722 | 722 | function memoriser_contexte_compil($p) { |
| 723 | - return join(',', [ |
|
| 724 | - _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | - _q($p->descr['nom'] ?? ''), |
|
| 726 | - _q($p->id_boucle ?? ''), |
|
| 727 | - intval($p->ligne), |
|
| 728 | - '$GLOBALS[\'spip_lang\']' |
|
| 729 | - ]); |
|
| 723 | + return join(',', [ |
|
| 724 | + _q($p->descr['sourcefile'] ?? ''), |
|
| 725 | + _q($p->descr['nom'] ?? ''), |
|
| 726 | + _q($p->id_boucle ?? ''), |
|
| 727 | + intval($p->ligne), |
|
| 728 | + '$GLOBALS[\'spip_lang\']' |
|
| 729 | + ]); |
|
| 730 | 730 | } |
| 731 | 731 | |
| 732 | 732 | /** |
@@ -744,20 +744,20 @@ discard block |
||
| 744 | 744 | * Objet Contexte |
| 745 | 745 | **/ |
| 746 | 746 | function reconstruire_contexte_compil($context_compil) { |
| 747 | - if (!is_array($context_compil)) { |
|
| 748 | - return $context_compil; |
|
| 749 | - } |
|
| 750 | - $p = new Contexte(); |
|
| 751 | - $p->descr = [ |
|
| 752 | - 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | - 'nom' => $context_compil[1] ?? '', |
|
| 754 | - ]; |
|
| 755 | - |
|
| 756 | - $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | - $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | - $p->lang = $context_compil[4] ?? ''; |
|
| 759 | - |
|
| 760 | - return $p; |
|
| 747 | + if (!is_array($context_compil)) { |
|
| 748 | + return $context_compil; |
|
| 749 | + } |
|
| 750 | + $p = new Contexte(); |
|
| 751 | + $p->descr = [ |
|
| 752 | + 'sourcefile' => $context_compil[0] ?? '', |
|
| 753 | + 'nom' => $context_compil[1] ?? '', |
|
| 754 | + ]; |
|
| 755 | + |
|
| 756 | + $p->id_boucle = $context_compil[2] ?? ''; |
|
| 757 | + $p->ligne = (int)($context_compil[3] ?? 0); |
|
| 758 | + $p->lang = $context_compil[4] ?? ''; |
|
| 759 | + |
|
| 760 | + return $p; |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -783,12 +783,12 @@ discard block |
||
| 783 | 783 | * - index 1 : Code de l'affectation |
| 784 | 784 | **/ |
| 785 | 785 | function calculer_dec($nom, $val) { |
| 786 | - $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | - // si une variable apparait dans le calcul de la clause |
|
| 788 | - // il faut la re-evaluer a chaque passage |
|
| 789 | - if ( |
|
| 790 | - strpos($val, '$') !== false |
|
| 791 | - /* |
|
| 786 | + $static = 'if (!isset($command[\'' . $nom . '\'])) '; |
|
| 787 | + // si une variable apparait dans le calcul de la clause |
|
| 788 | + // il faut la re-evaluer a chaque passage |
|
| 789 | + if ( |
|
| 790 | + strpos($val, '$') !== false |
|
| 791 | + /* |
|
| 792 | 792 | OR strpos($val, 'sql_') !== false |
| 793 | 793 | OR ( |
| 794 | 794 | $test = str_replace(array("array(",'\"',"\'"),array("","",""),$val) // supprimer les array( et les echappements de guillemets |
@@ -796,11 +796,11 @@ discard block |
||
| 796 | 796 | AND $test = preg_replace(",'[^']*',UimsS","",$test) // supprimer les chaines qui peuvent contenir des fonctions SQL qui ne genent pas |
| 797 | 797 | AND preg_match(",\w+\s*\(,UimsS",$test,$regs) // tester la presence de fonctions restantes |
| 798 | 798 | )*/ |
| 799 | - ) { |
|
| 800 | - $static = ''; |
|
| 801 | - } |
|
| 799 | + ) { |
|
| 800 | + $static = ''; |
|
| 801 | + } |
|
| 802 | 802 | |
| 803 | - return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 803 | + return [$static, '$command[\'' . $nom . '\'] = ' . $val . ';']; |
|
| 804 | 804 | } |
| 805 | 805 | |
| 806 | 806 | /** |
@@ -820,32 +820,32 @@ discard block |
||
| 820 | 820 | * Expression PHP décrivant un texte ou un tableau |
| 821 | 821 | **/ |
| 822 | 822 | function calculer_dump_array($a) { |
| 823 | - if (!is_array($a)) { |
|
| 824 | - return $a; |
|
| 825 | - } |
|
| 826 | - $res = ''; |
|
| 827 | - if ($a and $a[0] == "'?'") { |
|
| 828 | - return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | - ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | - ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | - ')'); |
|
| 832 | - } else { |
|
| 833 | - foreach ($a as $k => $v) { |
|
| 834 | - $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | - $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | - } |
|
| 837 | - |
|
| 838 | - return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | - } |
|
| 823 | + if (!is_array($a)) { |
|
| 824 | + return $a; |
|
| 825 | + } |
|
| 826 | + $res = ''; |
|
| 827 | + if ($a and $a[0] == "'?'") { |
|
| 828 | + return ('(' . calculer_dump_array($a[1]) . |
|
| 829 | + ' ? ' . calculer_dump_array($a[2]) . |
|
| 830 | + ' : ' . calculer_dump_array($a[3]) . |
|
| 831 | + ')'); |
|
| 832 | + } else { |
|
| 833 | + foreach ($a as $k => $v) { |
|
| 834 | + $showk = (is_numeric($k) ? '' : sql_quote($k) . ' => '); |
|
| 835 | + $res .= ', ' . $showk . calculer_dump_array($v); |
|
| 836 | + } |
|
| 837 | + |
|
| 838 | + return "\n\t\t\tarray(" . substr($res, 2) . ')'; |
|
| 839 | + } |
|
| 840 | 840 | } |
| 841 | 841 | |
| 842 | 842 | function calculer_dump_join($a) { |
| 843 | - $res = ''; |
|
| 844 | - foreach ($a as $k => $v) { |
|
| 845 | - $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | - } |
|
| 843 | + $res = ''; |
|
| 844 | + foreach ($a as $k => $v) { |
|
| 845 | + $res .= ", '$k' => array(" . implode(',', $v) . ')'; |
|
| 846 | + } |
|
| 847 | 847 | |
| 848 | - return 'array(' . substr($res, 2) . ')'; |
|
| 848 | + return 'array(' . substr($res, 2) . ')'; |
|
| 849 | 849 | } |
| 850 | 850 | |
| 851 | 851 | /** |
@@ -857,12 +857,12 @@ discard block |
||
| 857 | 857 | * Code PHP construisant un tableau des alias et noms des tables du FROM |
| 858 | 858 | **/ |
| 859 | 859 | function calculer_from(&$boucle) { |
| 860 | - $res = ''; |
|
| 861 | - foreach ($boucle->from as $k => $v) { |
|
| 862 | - $res .= ",'$k' => '$v'"; |
|
| 863 | - } |
|
| 860 | + $res = ''; |
|
| 861 | + foreach ($boucle->from as $k => $v) { |
|
| 862 | + $res .= ",'$k' => '$v'"; |
|
| 863 | + } |
|
| 864 | 864 | |
| 865 | - return 'array(' . substr($res, 1) . ')'; |
|
| 865 | + return 'array(' . substr($res, 1) . ')'; |
|
| 866 | 866 | } |
| 867 | 867 | |
| 868 | 868 | /** |
@@ -875,30 +875,30 @@ discard block |
||
| 875 | 875 | * Code PHP construisant un tableau des alias et type de jointure du FROM |
| 876 | 876 | **/ |
| 877 | 877 | function calculer_from_type(&$boucle) { |
| 878 | - $res = ''; |
|
| 879 | - foreach ($boucle->from_type as $k => $v) { |
|
| 880 | - $res .= ",'$k' => '$v'"; |
|
| 881 | - } |
|
| 878 | + $res = ''; |
|
| 879 | + foreach ($boucle->from_type as $k => $v) { |
|
| 880 | + $res .= ",'$k' => '$v'"; |
|
| 881 | + } |
|
| 882 | 882 | |
| 883 | - return 'array(' . substr($res, 1) . ')'; |
|
| 883 | + return 'array(' . substr($res, 1) . ')'; |
|
| 884 | 884 | } |
| 885 | 885 | |
| 886 | 886 | function calculer_order(&$boucle) { |
| 887 | - if ( |
|
| 888 | - !$order = $boucle->order |
|
| 889 | - and !$order = $boucle->default_order |
|
| 890 | - ) { |
|
| 891 | - $order = []; |
|
| 892 | - } |
|
| 893 | - |
|
| 894 | - /*if (isset($boucle->modificateur['collate'])){ |
|
| 887 | + if ( |
|
| 888 | + !$order = $boucle->order |
|
| 889 | + and !$order = $boucle->default_order |
|
| 890 | + ) { |
|
| 891 | + $order = []; |
|
| 892 | + } |
|
| 893 | + |
|
| 894 | + /*if (isset($boucle->modificateur['collate'])){ |
|
| 895 | 895 | $col = "." . $boucle->modificateur['collate']; |
| 896 | 896 | foreach($order as $k=>$o) |
| 897 | 897 | if (strpos($order[$k],'COLLATE')===false) |
| 898 | 898 | $order[$k].= $col; |
| 899 | 899 | }*/ |
| 900 | 900 | |
| 901 | - return join(', ', $order); |
|
| 901 | + return join(', ', $order); |
|
| 902 | 902 | } |
| 903 | 903 | |
| 904 | 904 | // Production du code PHP a partir de la sequence livree par le phraseur |
@@ -907,62 +907,62 @@ discard block |
||
| 907 | 907 | // (qui sera argument d'un Return ou la partie droite d'une affectation). |
| 908 | 908 | |
| 909 | 909 | function calculer_liste($tableau, $descr, &$boucles, $id_boucle = '') { |
| 910 | - if (!$tableau) { |
|
| 911 | - return "''"; |
|
| 912 | - } |
|
| 913 | - if (is_string($descr)) { |
|
| 914 | - if (isset($boucles[$descr])) { |
|
| 915 | - $idb = $descr; |
|
| 916 | - $descr = []; |
|
| 917 | - if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | - $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | - } |
|
| 920 | - if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | - $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | - } |
|
| 923 | - } |
|
| 924 | - else { |
|
| 925 | - $descr = []; |
|
| 926 | - } |
|
| 927 | - } |
|
| 928 | - if (!isset($descr['niv'])) { |
|
| 929 | - $descr['niv'] = 0; |
|
| 930 | - } |
|
| 931 | - $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | - if ($codes === false) { |
|
| 933 | - return false; |
|
| 934 | - } |
|
| 935 | - $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | - if (!$n) { |
|
| 937 | - return "''"; |
|
| 938 | - } |
|
| 939 | - $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | - if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | - if ($n == 1) { |
|
| 942 | - return $codes[0]; |
|
| 943 | - } else { |
|
| 944 | - $res = ''; |
|
| 945 | - foreach ($codes as $code) { |
|
| 946 | - if ( |
|
| 947 | - !preg_match("/^'[^']*'$/", $code) |
|
| 948 | - or substr($res, -1, 1) !== "'" |
|
| 949 | - ) { |
|
| 950 | - $res .= " .\n$tab$code"; |
|
| 951 | - } else { |
|
| 952 | - $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | - } |
|
| 954 | - } |
|
| 955 | - |
|
| 956 | - return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | - } |
|
| 958 | - } else { |
|
| 959 | - $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | - |
|
| 961 | - return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | - " ,\n$tab", |
|
| 963 | - $codes |
|
| 964 | - ) . ')))'; |
|
| 965 | - } |
|
| 910 | + if (!$tableau) { |
|
| 911 | + return "''"; |
|
| 912 | + } |
|
| 913 | + if (is_string($descr)) { |
|
| 914 | + if (isset($boucles[$descr])) { |
|
| 915 | + $idb = $descr; |
|
| 916 | + $descr = []; |
|
| 917 | + if (isset($boucles[$idb]->descr['id_mere_contexte'])) { |
|
| 918 | + $descr['id_mere'] = $boucles[$idb]->descr['id_mere_contexte']; |
|
| 919 | + } |
|
| 920 | + if (isset($boucles[$idb]->descr['sourcefile'])) { |
|
| 921 | + $descr['sourcefile'] = $boucles[$idb]->descr['sourcefile']; |
|
| 922 | + } |
|
| 923 | + } |
|
| 924 | + else { |
|
| 925 | + $descr = []; |
|
| 926 | + } |
|
| 927 | + } |
|
| 928 | + if (!isset($descr['niv'])) { |
|
| 929 | + $descr['niv'] = 0; |
|
| 930 | + } |
|
| 931 | + $codes = compile_cas($tableau, $descr, $boucles, $id_boucle); |
|
| 932 | + if ($codes === false) { |
|
| 933 | + return false; |
|
| 934 | + } |
|
| 935 | + $n = is_countable($codes) ? count($codes) : 0; |
|
| 936 | + if (!$n) { |
|
| 937 | + return "''"; |
|
| 938 | + } |
|
| 939 | + $tab = str_repeat("\t", $descr['niv']); |
|
| 940 | + if (_request('var_mode_affiche') != 'validation') { |
|
| 941 | + if ($n == 1) { |
|
| 942 | + return $codes[0]; |
|
| 943 | + } else { |
|
| 944 | + $res = ''; |
|
| 945 | + foreach ($codes as $code) { |
|
| 946 | + if ( |
|
| 947 | + !preg_match("/^'[^']*'$/", $code) |
|
| 948 | + or substr($res, -1, 1) !== "'" |
|
| 949 | + ) { |
|
| 950 | + $res .= " .\n$tab$code"; |
|
| 951 | + } else { |
|
| 952 | + $res = substr($res, 0, -1) . substr($code, 1); |
|
| 953 | + } |
|
| 954 | + } |
|
| 955 | + |
|
| 956 | + return '(' . substr($res, 2 + $descr['niv']) . ')'; |
|
| 957 | + } |
|
| 958 | + } else { |
|
| 959 | + $nom = $descr['nom'] . $id_boucle . ($descr['niv'] ?: ''); |
|
| 960 | + |
|
| 961 | + return "join('', array_map('array_shift', \$GLOBALS['debug_objets']['sequence']['$nom'] = array(" . join( |
|
| 962 | + " ,\n$tab", |
|
| 963 | + $codes |
|
| 964 | + ) . ')))'; |
|
| 965 | + } |
|
| 966 | 966 | } |
| 967 | 967 | |
| 968 | 968 | |
@@ -972,213 +972,213 @@ discard block |
||
| 972 | 972 | |
| 973 | 973 | function compile_cas($tableau, $descr, &$boucles, $id_boucle) { |
| 974 | 974 | |
| 975 | - $codes = []; |
|
| 976 | - // cas de la boucle recursive |
|
| 977 | - if (is_array($id_boucle)) { |
|
| 978 | - $id_boucle = $id_boucle[0]; |
|
| 979 | - } |
|
| 980 | - $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 981 | - $tab = str_repeat("\t", ++$descr['niv']); |
|
| 982 | - $mode = _request('var_mode_affiche'); |
|
| 983 | - $err_e_c = ''; |
|
| 984 | - // chaque commentaire introduit dans le code doit commencer |
|
| 985 | - // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 986 | - foreach ($tableau as $p) { |
|
| 987 | - switch ($p->type) { |
|
| 988 | - // texte seul |
|
| 989 | - case 'texte': |
|
| 990 | - $code = sandbox_composer_texte($p->texte, $p); |
|
| 991 | - $commentaire = strlen($p->texte) . ' signes'; |
|
| 992 | - $avant = ''; |
|
| 993 | - $apres = ''; |
|
| 994 | - $altern = "''"; |
|
| 995 | - break; |
|
| 996 | - |
|
| 997 | - case 'polyglotte': |
|
| 998 | - $code = ''; |
|
| 999 | - foreach ($p->traductions as $k => $v) { |
|
| 1000 | - $code .= ",'" . |
|
| 1001 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1002 | - "' => '" . |
|
| 1003 | - str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1004 | - "'"; |
|
| 1005 | - } |
|
| 1006 | - $code = 'choisir_traduction(array(' . |
|
| 1007 | - substr($code, 1) . |
|
| 1008 | - '))'; |
|
| 1009 | - $commentaire = '&'; |
|
| 1010 | - $avant = ''; |
|
| 1011 | - $apres = ''; |
|
| 1012 | - $altern = "''"; |
|
| 1013 | - break; |
|
| 1014 | - |
|
| 1015 | - // inclure |
|
| 1016 | - case 'include': |
|
| 1017 | - $p->descr = $descr; |
|
| 1018 | - $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1019 | - if ($code === false) { |
|
| 1020 | - $err_e_c = true; |
|
| 1021 | - $code = "''"; |
|
| 1022 | - } else { |
|
| 1023 | - $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1024 | - $avant = ''; |
|
| 1025 | - $apres = ''; |
|
| 1026 | - $altern = "''"; |
|
| 1027 | - } |
|
| 1028 | - break; |
|
| 1029 | - |
|
| 1030 | - // boucle |
|
| 1031 | - case TYPE_RECURSIF: |
|
| 1032 | - $nom = $p->id_boucle; |
|
| 1033 | - $newdescr = $descr; |
|
| 1034 | - $newdescr['id_mere'] = $nom; |
|
| 1035 | - $newdescr['niv']++; |
|
| 1036 | - $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1037 | - $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1038 | - $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1039 | - $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1040 | - $newdescr['niv']--; |
|
| 1041 | - $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1042 | - if ( |
|
| 1043 | - $preaff === false |
|
| 1044 | - or $avant === false |
|
| 1045 | - or $apres === false |
|
| 1046 | - or $altern === false |
|
| 1047 | - or $postaff === false |
|
| 1048 | - ) { |
|
| 1049 | - $err_e_c = true; |
|
| 1050 | - $code = "''"; |
|
| 1051 | - } else { |
|
| 1052 | - $code = 'BOUCLE' . |
|
| 1053 | - str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1054 | - '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1055 | - $commentaire = "?$nom"; |
|
| 1056 | - if ( |
|
| 1057 | - !$boucles[$nom]->milieu |
|
| 1058 | - and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1059 | - ) { |
|
| 1060 | - if ($preaff != "''") { |
|
| 1061 | - $code .= "\n. $preaff"; |
|
| 1062 | - } |
|
| 1063 | - if ($altern != "''") { |
|
| 1064 | - $code .= "\n. $altern"; |
|
| 1065 | - } |
|
| 1066 | - if ($postaff != "''") { |
|
| 1067 | - $code .= "\n. $postaff"; |
|
| 1068 | - } |
|
| 1069 | - if ($avant <> "''" or $apres <> "''") { |
|
| 1070 | - spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1071 | - } |
|
| 1072 | - $avant = $apres = $altern = "''"; |
|
| 1073 | - } else { |
|
| 1074 | - if ($preaff != "''") { |
|
| 1075 | - $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1076 | - $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1077 | - } |
|
| 1078 | - if ($postaff != "''") { |
|
| 1079 | - $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1080 | - $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1081 | - } |
|
| 1082 | - if ($altern != "''") { |
|
| 1083 | - $altern = "($altern)"; |
|
| 1084 | - } |
|
| 1085 | - } |
|
| 1086 | - } |
|
| 1087 | - break; |
|
| 1088 | - |
|
| 1089 | - case 'idiome': |
|
| 1090 | - $l = []; |
|
| 1091 | - $code = ''; |
|
| 1092 | - foreach ($p->arg as $k => $v) { |
|
| 1093 | - $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1094 | - if ($k) { |
|
| 1095 | - $l[] = _q($k) . ' => ' . $_v; |
|
| 1096 | - } else { |
|
| 1097 | - $code = $_v; |
|
| 1098 | - } |
|
| 1099 | - } |
|
| 1100 | - // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1101 | - if ($p->module) { |
|
| 1102 | - $m = $p->module . ':' . $p->nom_champ; |
|
| 1103 | - } elseif ($p->nom_champ) { |
|
| 1104 | - $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1105 | - } else { |
|
| 1106 | - $m = ''; |
|
| 1107 | - } |
|
| 1108 | - |
|
| 1109 | - $code = (!$code ? "'$m'" : |
|
| 1110 | - ($m ? "'$m' . $code" : |
|
| 1111 | - ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1112 | - . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1113 | - $code = "_T($code)"; |
|
| 1114 | - if ($p->param) { |
|
| 1115 | - $p->id_boucle = $id_boucle; |
|
| 1116 | - $p->boucles = &$boucles; |
|
| 1117 | - $code = compose_filtres($p, $code); |
|
| 1118 | - } |
|
| 1119 | - $commentaire = ':'; |
|
| 1120 | - $avant = ''; |
|
| 1121 | - $apres = ''; |
|
| 1122 | - $altern = "''"; |
|
| 1123 | - break; |
|
| 1124 | - |
|
| 1125 | - case 'champ': |
|
| 1126 | - // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1127 | - $p->id_boucle = $id_boucle; |
|
| 1128 | - $p->boucles = &$boucles; |
|
| 1129 | - $p->descr = $descr; |
|
| 1130 | - #$p->interdire_scripts = true; |
|
| 1131 | - $p->type_requete = $type; |
|
| 1132 | - |
|
| 1133 | - $code = calculer_champ($p); |
|
| 1134 | - $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1135 | - $avant = calculer_liste( |
|
| 1136 | - $p->avant, |
|
| 1137 | - $descr, |
|
| 1138 | - $boucles, |
|
| 1139 | - $id_boucle |
|
| 1140 | - ); |
|
| 1141 | - $apres = calculer_liste( |
|
| 1142 | - $p->apres, |
|
| 1143 | - $descr, |
|
| 1144 | - $boucles, |
|
| 1145 | - $id_boucle |
|
| 1146 | - ); |
|
| 1147 | - $altern = "''"; |
|
| 1148 | - // Si la valeur est destinee a une comparaison a '' |
|
| 1149 | - // forcer la conversion en une chaine par strval |
|
| 1150 | - // si ca peut etre autre chose qu'une chaine |
|
| 1151 | - if ( |
|
| 1152 | - ($avant != "''" or $apres != "''") |
|
| 1153 | - and $code[0] != "'" |
|
| 975 | + $codes = []; |
|
| 976 | + // cas de la boucle recursive |
|
| 977 | + if (is_array($id_boucle)) { |
|
| 978 | + $id_boucle = $id_boucle[0]; |
|
| 979 | + } |
|
| 980 | + $type = !$id_boucle ? '' : $boucles[$id_boucle]->type_requete; |
|
| 981 | + $tab = str_repeat("\t", ++$descr['niv']); |
|
| 982 | + $mode = _request('var_mode_affiche'); |
|
| 983 | + $err_e_c = ''; |
|
| 984 | + // chaque commentaire introduit dans le code doit commencer |
|
| 985 | + // par un caractere distinguant le cas, pour exploitation par debug. |
|
| 986 | + foreach ($tableau as $p) { |
|
| 987 | + switch ($p->type) { |
|
| 988 | + // texte seul |
|
| 989 | + case 'texte': |
|
| 990 | + $code = sandbox_composer_texte($p->texte, $p); |
|
| 991 | + $commentaire = strlen($p->texte) . ' signes'; |
|
| 992 | + $avant = ''; |
|
| 993 | + $apres = ''; |
|
| 994 | + $altern = "''"; |
|
| 995 | + break; |
|
| 996 | + |
|
| 997 | + case 'polyglotte': |
|
| 998 | + $code = ''; |
|
| 999 | + foreach ($p->traductions as $k => $v) { |
|
| 1000 | + $code .= ",'" . |
|
| 1001 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $k) . |
|
| 1002 | + "' => '" . |
|
| 1003 | + str_replace(['\\', "'"], ['\\\\', "\\'"], $v) . |
|
| 1004 | + "'"; |
|
| 1005 | + } |
|
| 1006 | + $code = 'choisir_traduction(array(' . |
|
| 1007 | + substr($code, 1) . |
|
| 1008 | + '))'; |
|
| 1009 | + $commentaire = '&'; |
|
| 1010 | + $avant = ''; |
|
| 1011 | + $apres = ''; |
|
| 1012 | + $altern = "''"; |
|
| 1013 | + break; |
|
| 1014 | + |
|
| 1015 | + // inclure |
|
| 1016 | + case 'include': |
|
| 1017 | + $p->descr = $descr; |
|
| 1018 | + $code = calculer_inclure($p, $boucles, $id_boucle); |
|
| 1019 | + if ($code === false) { |
|
| 1020 | + $err_e_c = true; |
|
| 1021 | + $code = "''"; |
|
| 1022 | + } else { |
|
| 1023 | + $commentaire = '<INCLURE ' . addslashes(str_replace("\n", ' ', $code)) . '>'; |
|
| 1024 | + $avant = ''; |
|
| 1025 | + $apres = ''; |
|
| 1026 | + $altern = "''"; |
|
| 1027 | + } |
|
| 1028 | + break; |
|
| 1029 | + |
|
| 1030 | + // boucle |
|
| 1031 | + case TYPE_RECURSIF: |
|
| 1032 | + $nom = $p->id_boucle; |
|
| 1033 | + $newdescr = $descr; |
|
| 1034 | + $newdescr['id_mere'] = $nom; |
|
| 1035 | + $newdescr['niv']++; |
|
| 1036 | + $preaff = calculer_liste($p->preaff, $newdescr, $boucles, $id_boucle); |
|
| 1037 | + $avant = calculer_liste($p->avant, $newdescr, $boucles, $id_boucle); |
|
| 1038 | + $apres = calculer_liste($p->apres, $newdescr, $boucles, $id_boucle); |
|
| 1039 | + $postaff = calculer_liste($p->postaff, $newdescr, $boucles, $id_boucle); |
|
| 1040 | + $newdescr['niv']--; |
|
| 1041 | + $altern = calculer_liste($p->altern, $newdescr, $boucles, $id_boucle); |
|
| 1042 | + if ( |
|
| 1043 | + $preaff === false |
|
| 1044 | + or $avant === false |
|
| 1045 | + or $apres === false |
|
| 1046 | + or $altern === false |
|
| 1047 | + or $postaff === false |
|
| 1048 | + ) { |
|
| 1049 | + $err_e_c = true; |
|
| 1050 | + $code = "''"; |
|
| 1051 | + } else { |
|
| 1052 | + $code = 'BOUCLE' . |
|
| 1053 | + str_replace('-', '_', $nom) . $descr['nom'] . |
|
| 1054 | + '($Cache, $Pile, $doublons, $Numrows, $SP)'; |
|
| 1055 | + $commentaire = "?$nom"; |
|
| 1056 | + if ( |
|
| 1057 | + !$boucles[$nom]->milieu |
|
| 1058 | + and $boucles[$nom]->type_requete <> TYPE_RECURSIF |
|
| 1059 | + ) { |
|
| 1060 | + if ($preaff != "''") { |
|
| 1061 | + $code .= "\n. $preaff"; |
|
| 1062 | + } |
|
| 1063 | + if ($altern != "''") { |
|
| 1064 | + $code .= "\n. $altern"; |
|
| 1065 | + } |
|
| 1066 | + if ($postaff != "''") { |
|
| 1067 | + $code .= "\n. $postaff"; |
|
| 1068 | + } |
|
| 1069 | + if ($avant <> "''" or $apres <> "''") { |
|
| 1070 | + spip_log("boucle $nom toujours vide, code superflu dans $descr[sourcefile]"); |
|
| 1071 | + } |
|
| 1072 | + $avant = $apres = $altern = "''"; |
|
| 1073 | + } else { |
|
| 1074 | + if ($preaff != "''") { |
|
| 1075 | + $avant = compile_concatene_parties_codes($preaff, $avant); |
|
| 1076 | + $altern = compile_concatene_parties_codes($preaff, $altern); |
|
| 1077 | + } |
|
| 1078 | + if ($postaff != "''") { |
|
| 1079 | + $apres = compile_concatene_parties_codes($apres, $postaff); |
|
| 1080 | + $altern = compile_concatene_parties_codes($altern, $postaff); |
|
| 1081 | + } |
|
| 1082 | + if ($altern != "''") { |
|
| 1083 | + $altern = "($altern)"; |
|
| 1084 | + } |
|
| 1085 | + } |
|
| 1086 | + } |
|
| 1087 | + break; |
|
| 1088 | + |
|
| 1089 | + case 'idiome': |
|
| 1090 | + $l = []; |
|
| 1091 | + $code = ''; |
|
| 1092 | + foreach ($p->arg as $k => $v) { |
|
| 1093 | + $_v = calculer_liste($v, $descr, $boucles, $id_boucle); |
|
| 1094 | + if ($k) { |
|
| 1095 | + $l[] = _q($k) . ' => ' . $_v; |
|
| 1096 | + } else { |
|
| 1097 | + $code = $_v; |
|
| 1098 | + } |
|
| 1099 | + } |
|
| 1100 | + // Si le module n'est pas fourni, l'expliciter sauf si calculé |
|
| 1101 | + if ($p->module) { |
|
| 1102 | + $m = $p->module . ':' . $p->nom_champ; |
|
| 1103 | + } elseif ($p->nom_champ) { |
|
| 1104 | + $m = MODULES_IDIOMES . ':' . $p->nom_champ; |
|
| 1105 | + } else { |
|
| 1106 | + $m = ''; |
|
| 1107 | + } |
|
| 1108 | + |
|
| 1109 | + $code = (!$code ? "'$m'" : |
|
| 1110 | + ($m ? "'$m' . $code" : |
|
| 1111 | + ("(strpos(\$x=$code, ':') ? \$x : ('" . MODULES_IDIOMES . ":' . \$x))"))) |
|
| 1112 | + . (!$l ? '' : (', array(' . implode(",\n", $l) . ')')); |
|
| 1113 | + $code = "_T($code)"; |
|
| 1114 | + if ($p->param) { |
|
| 1115 | + $p->id_boucle = $id_boucle; |
|
| 1116 | + $p->boucles = &$boucles; |
|
| 1117 | + $code = compose_filtres($p, $code); |
|
| 1118 | + } |
|
| 1119 | + $commentaire = ':'; |
|
| 1120 | + $avant = ''; |
|
| 1121 | + $apres = ''; |
|
| 1122 | + $altern = "''"; |
|
| 1123 | + break; |
|
| 1124 | + |
|
| 1125 | + case 'champ': |
|
| 1126 | + // cette structure pourrait etre completee des le phrase' (a faire) |
|
| 1127 | + $p->id_boucle = $id_boucle; |
|
| 1128 | + $p->boucles = &$boucles; |
|
| 1129 | + $p->descr = $descr; |
|
| 1130 | + #$p->interdire_scripts = true; |
|
| 1131 | + $p->type_requete = $type; |
|
| 1132 | + |
|
| 1133 | + $code = calculer_champ($p); |
|
| 1134 | + $commentaire = '#' . $p->nom_champ . $p->etoile; |
|
| 1135 | + $avant = calculer_liste( |
|
| 1136 | + $p->avant, |
|
| 1137 | + $descr, |
|
| 1138 | + $boucles, |
|
| 1139 | + $id_boucle |
|
| 1140 | + ); |
|
| 1141 | + $apres = calculer_liste( |
|
| 1142 | + $p->apres, |
|
| 1143 | + $descr, |
|
| 1144 | + $boucles, |
|
| 1145 | + $id_boucle |
|
| 1146 | + ); |
|
| 1147 | + $altern = "''"; |
|
| 1148 | + // Si la valeur est destinee a une comparaison a '' |
|
| 1149 | + // forcer la conversion en une chaine par strval |
|
| 1150 | + // si ca peut etre autre chose qu'une chaine |
|
| 1151 | + if ( |
|
| 1152 | + ($avant != "''" or $apres != "''") |
|
| 1153 | + and $code[0] != "'" |
|
| 1154 | 1154 | # AND (strpos($code,'interdire_scripts') !== 0) |
| 1155 | - and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1156 | - and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1157 | - and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1158 | - ) { |
|
| 1159 | - $code = "strval($code)"; |
|
| 1160 | - } |
|
| 1161 | - break; |
|
| 1162 | - |
|
| 1163 | - default: |
|
| 1164 | - // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1165 | - $code = "''"; |
|
| 1166 | - $p->descr = $descr; |
|
| 1167 | - $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1168 | - erreur_squelette($err_e_c, $p); |
|
| 1169 | - } // switch |
|
| 1170 | - |
|
| 1171 | - if ($code != "''") { |
|
| 1172 | - $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1173 | - $codes[] = (($mode == 'validation') ? |
|
| 1174 | - "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1175 | - : (($mode == 'code') ? |
|
| 1176 | - "\n// $commentaire\n$code" : |
|
| 1177 | - $code)); |
|
| 1178 | - } |
|
| 1179 | - } // foreach |
|
| 1180 | - |
|
| 1181 | - return $err_e_c ? false : $codes; |
|
| 1155 | + and !preg_match(_REGEXP_COND_VIDE_NONVIDE, $code) |
|
| 1156 | + and !preg_match(_REGEXP_COND_NONVIDE_VIDE, $code) |
|
| 1157 | + and !preg_match(_REGEXP_CONCAT_NON_VIDE, $code) |
|
| 1158 | + ) { |
|
| 1159 | + $code = "strval($code)"; |
|
| 1160 | + } |
|
| 1161 | + break; |
|
| 1162 | + |
|
| 1163 | + default: |
|
| 1164 | + // Erreur de construction de l'arbre de syntaxe abstraite |
|
| 1165 | + $code = "''"; |
|
| 1166 | + $p->descr = $descr; |
|
| 1167 | + $err_e_c = _T('zbug_erreur_compilation'); |
|
| 1168 | + erreur_squelette($err_e_c, $p); |
|
| 1169 | + } // switch |
|
| 1170 | + |
|
| 1171 | + if ($code != "''") { |
|
| 1172 | + $code = compile_retour($code, $avant, $apres, $altern, $tab, $descr['niv']); |
|
| 1173 | + $codes[] = (($mode == 'validation') ? |
|
| 1174 | + "array($code, '$commentaire', " . $p->ligne . ')' |
|
| 1175 | + : (($mode == 'code') ? |
|
| 1176 | + "\n// $commentaire\n$code" : |
|
| 1177 | + $code)); |
|
| 1178 | + } |
|
| 1179 | + } // foreach |
|
| 1180 | + |
|
| 1181 | + return $err_e_c ? false : $codes; |
|
| 1182 | 1182 | } |
| 1183 | 1183 | |
| 1184 | 1184 | /** |
@@ -1188,13 +1188,13 @@ discard block |
||
| 1188 | 1188 | * @return string |
| 1189 | 1189 | */ |
| 1190 | 1190 | function compile_concatene_parties_codes($partie1, $partie2) { |
| 1191 | - if ($partie1 === "''") { |
|
| 1192 | - return $partie2; |
|
| 1193 | - } |
|
| 1194 | - if ($partie2 === "''") { |
|
| 1195 | - return $partie1; |
|
| 1196 | - } |
|
| 1197 | - return "$partie1\n. $partie2"; |
|
| 1191 | + if ($partie1 === "''") { |
|
| 1192 | + return $partie2; |
|
| 1193 | + } |
|
| 1194 | + if ($partie2 === "''") { |
|
| 1195 | + return $partie1; |
|
| 1196 | + } |
|
| 1197 | + return "$partie1\n. $partie2"; |
|
| 1198 | 1198 | } |
| 1199 | 1199 | |
| 1200 | 1200 | |
@@ -1218,56 +1218,56 @@ discard block |
||
| 1218 | 1218 | * @return mixed|string |
| 1219 | 1219 | */ |
| 1220 | 1220 | function compile_retour($code, $avant, $apres, $altern, $tab, $n) { |
| 1221 | - if ($avant === "''") { |
|
| 1222 | - $avant = ''; |
|
| 1223 | - } |
|
| 1224 | - if ($apres === "''") { |
|
| 1225 | - $apres = ''; |
|
| 1226 | - } |
|
| 1227 | - if ($avant or $apres or ($altern !== "''")) { |
|
| 1228 | - if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1229 | - $t = $code; |
|
| 1230 | - $cond = ''; |
|
| 1231 | - } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1232 | - $t = $r[2]; |
|
| 1233 | - $cond = '!' . $r[1]; |
|
| 1234 | - } else { |
|
| 1235 | - if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1236 | - $t = $r[2]; |
|
| 1237 | - $cond = $r[1]; |
|
| 1238 | - } else { |
|
| 1239 | - $t = '$t' . $n; |
|
| 1240 | - $cond = "($t = $code)!==''"; |
|
| 1241 | - } |
|
| 1242 | - } |
|
| 1243 | - |
|
| 1244 | - $res = (!$avant ? '' : "$avant . ") . |
|
| 1245 | - $t . |
|
| 1246 | - (!$apres ? '' : " . $apres"); |
|
| 1247 | - |
|
| 1248 | - if ($res !== $t) { |
|
| 1249 | - $res = "($res)"; |
|
| 1250 | - } |
|
| 1251 | - |
|
| 1252 | - $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1253 | - } |
|
| 1254 | - |
|
| 1255 | - return $code; |
|
| 1221 | + if ($avant === "''") { |
|
| 1222 | + $avant = ''; |
|
| 1223 | + } |
|
| 1224 | + if ($apres === "''") { |
|
| 1225 | + $apres = ''; |
|
| 1226 | + } |
|
| 1227 | + if ($avant or $apres or ($altern !== "''")) { |
|
| 1228 | + if (preg_match(_REGEXP_CONCAT_NON_VIDE, $code)) { |
|
| 1229 | + $t = $code; |
|
| 1230 | + $cond = ''; |
|
| 1231 | + } elseif (preg_match(_REGEXP_COND_VIDE_NONVIDE, $code, $r)) { |
|
| 1232 | + $t = $r[2]; |
|
| 1233 | + $cond = '!' . $r[1]; |
|
| 1234 | + } else { |
|
| 1235 | + if (preg_match(_REGEXP_COND_NONVIDE_VIDE, $code, $r)) { |
|
| 1236 | + $t = $r[2]; |
|
| 1237 | + $cond = $r[1]; |
|
| 1238 | + } else { |
|
| 1239 | + $t = '$t' . $n; |
|
| 1240 | + $cond = "($t = $code)!==''"; |
|
| 1241 | + } |
|
| 1242 | + } |
|
| 1243 | + |
|
| 1244 | + $res = (!$avant ? '' : "$avant . ") . |
|
| 1245 | + $t . |
|
| 1246 | + (!$apres ? '' : " . $apres"); |
|
| 1247 | + |
|
| 1248 | + if ($res !== $t) { |
|
| 1249 | + $res = "($res)"; |
|
| 1250 | + } |
|
| 1251 | + |
|
| 1252 | + $code = (!$cond ? $res : "($cond ?\n\t$tab$res :\n\t$tab$altern)"); |
|
| 1253 | + } |
|
| 1254 | + |
|
| 1255 | + return $code; |
|
| 1256 | 1256 | } |
| 1257 | 1257 | |
| 1258 | 1258 | |
| 1259 | 1259 | function compile_inclure_doublons($lexemes) { |
| 1260 | - foreach ($lexemes as $v) { |
|
| 1261 | - if ($v->type === 'include' and $v->param) { |
|
| 1262 | - foreach ($v->param as $r) { |
|
| 1263 | - if (trim($r[0]) === 'doublons') { |
|
| 1264 | - return true; |
|
| 1265 | - } |
|
| 1266 | - } |
|
| 1267 | - } |
|
| 1268 | - } |
|
| 1269 | - |
|
| 1270 | - return false; |
|
| 1260 | + foreach ($lexemes as $v) { |
|
| 1261 | + if ($v->type === 'include' and $v->param) { |
|
| 1262 | + foreach ($v->param as $r) { |
|
| 1263 | + if (trim($r[0]) === 'doublons') { |
|
| 1264 | + return true; |
|
| 1265 | + } |
|
| 1266 | + } |
|
| 1267 | + } |
|
| 1268 | + } |
|
| 1269 | + |
|
| 1270 | + return false; |
|
| 1271 | 1271 | } |
| 1272 | 1272 | |
| 1273 | 1273 | // Prend en argument le texte d'un squelette, le nom de son fichier d'origine, |
@@ -1286,354 +1286,354 @@ discard block |
||
| 1286 | 1286 | // En cas d'erreur, elle retournera un tableau des 2 premiers elements seulement |
| 1287 | 1287 | |
| 1288 | 1288 | function public_compiler_dist($squelette, $nom, $gram, $sourcefile, string $connect = '') { |
| 1289 | - // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1290 | - // Bonus : supprime le BOM |
|
| 1291 | - include_spip('inc/charsets'); |
|
| 1292 | - $squelette = transcoder_page($squelette); |
|
| 1293 | - |
|
| 1294 | - // rendre inertes les echappements de #[](){}<> |
|
| 1295 | - $i = 0; |
|
| 1296 | - while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1297 | - $i++; |
|
| 1298 | - } |
|
| 1299 | - $squelette = preg_replace_callback( |
|
| 1300 | - ',\\\\([#[()\]{}<>]),', |
|
| 1301 | - fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1302 | - $squelette, |
|
| 1303 | - -1, |
|
| 1304 | - $esc |
|
| 1305 | - ); |
|
| 1306 | - |
|
| 1307 | - $descr = [ |
|
| 1308 | - 'nom' => $nom, |
|
| 1309 | - 'gram' => $gram, |
|
| 1310 | - 'sourcefile' => $sourcefile, |
|
| 1311 | - 'squelette' => $squelette |
|
| 1312 | - ]; |
|
| 1313 | - |
|
| 1314 | - // Phraser le squelette, selon sa grammaire |
|
| 1315 | - |
|
| 1316 | - $boucles = []; |
|
| 1317 | - $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1318 | - |
|
| 1319 | - $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1320 | - |
|
| 1321 | - $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1322 | - |
|
| 1323 | - // restituer les echappements |
|
| 1324 | - if ($esc) { |
|
| 1325 | - foreach ($boucles as $i => $boucle) { |
|
| 1326 | - $boucles[$i]->return = preg_replace_callback( |
|
| 1327 | - ",$inerte-(\d+)-,", |
|
| 1328 | - fn($a) => chr($a[1]), |
|
| 1329 | - $boucle->return |
|
| 1330 | - ); |
|
| 1331 | - $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1332 | - ",$inerte-(\d+)-,", |
|
| 1333 | - fn($a) => '\\\\' . chr($a[1]), |
|
| 1334 | - $boucle->descr['squelette'] |
|
| 1335 | - ); |
|
| 1336 | - } |
|
| 1337 | - } |
|
| 1338 | - |
|
| 1339 | - $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1340 | - if ($debug) { |
|
| 1341 | - include_spip('public/decompiler'); |
|
| 1342 | - foreach ($boucles as $id => $boucle) { |
|
| 1343 | - if ($id) { |
|
| 1344 | - $decomp = "\n/* BOUCLE " . |
|
| 1345 | - $boucle->type_requete . |
|
| 1346 | - ' ' . |
|
| 1347 | - str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1348 | - ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1349 | - " */\n"; |
|
| 1350 | - } else { |
|
| 1351 | - $decomp = ("\n/*\n" . |
|
| 1352 | - str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1353 | - . "\n*/"); |
|
| 1354 | - } |
|
| 1355 | - $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1356 | - $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | - } |
|
| 1358 | - } |
|
| 1359 | - |
|
| 1360 | - return $boucles; |
|
| 1289 | + // Pre-traitement : reperer le charset du squelette, et le convertir |
|
| 1290 | + // Bonus : supprime le BOM |
|
| 1291 | + include_spip('inc/charsets'); |
|
| 1292 | + $squelette = transcoder_page($squelette); |
|
| 1293 | + |
|
| 1294 | + // rendre inertes les echappements de #[](){}<> |
|
| 1295 | + $i = 0; |
|
| 1296 | + while (false !== strpos($squelette, $inerte = '-INERTE' . $i)) { |
|
| 1297 | + $i++; |
|
| 1298 | + } |
|
| 1299 | + $squelette = preg_replace_callback( |
|
| 1300 | + ',\\\\([#[()\]{}<>]),', |
|
| 1301 | + fn($a) => "$inerte-" . ord($a[1]) . '-', |
|
| 1302 | + $squelette, |
|
| 1303 | + -1, |
|
| 1304 | + $esc |
|
| 1305 | + ); |
|
| 1306 | + |
|
| 1307 | + $descr = [ |
|
| 1308 | + 'nom' => $nom, |
|
| 1309 | + 'gram' => $gram, |
|
| 1310 | + 'sourcefile' => $sourcefile, |
|
| 1311 | + 'squelette' => $squelette |
|
| 1312 | + ]; |
|
| 1313 | + |
|
| 1314 | + // Phraser le squelette, selon sa grammaire |
|
| 1315 | + |
|
| 1316 | + $boucles = []; |
|
| 1317 | + $f = charger_fonction('phraser_' . $gram, 'public'); |
|
| 1318 | + |
|
| 1319 | + $squelette = $f($squelette, '', $boucles, $descr); |
|
| 1320 | + |
|
| 1321 | + $boucles = compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, $connect); |
|
| 1322 | + |
|
| 1323 | + // restituer les echappements |
|
| 1324 | + if ($esc) { |
|
| 1325 | + foreach ($boucles as $i => $boucle) { |
|
| 1326 | + $boucles[$i]->return = preg_replace_callback( |
|
| 1327 | + ",$inerte-(\d+)-,", |
|
| 1328 | + fn($a) => chr($a[1]), |
|
| 1329 | + $boucle->return |
|
| 1330 | + ); |
|
| 1331 | + $boucles[$i]->descr['squelette'] = preg_replace_callback( |
|
| 1332 | + ",$inerte-(\d+)-,", |
|
| 1333 | + fn($a) => '\\\\' . chr($a[1]), |
|
| 1334 | + $boucle->descr['squelette'] |
|
| 1335 | + ); |
|
| 1336 | + } |
|
| 1337 | + } |
|
| 1338 | + |
|
| 1339 | + $debug = ($boucles and defined('_VAR_MODE') and _VAR_MODE == 'debug'); |
|
| 1340 | + if ($debug) { |
|
| 1341 | + include_spip('public/decompiler'); |
|
| 1342 | + foreach ($boucles as $id => $boucle) { |
|
| 1343 | + if ($id) { |
|
| 1344 | + $decomp = "\n/* BOUCLE " . |
|
| 1345 | + $boucle->type_requete . |
|
| 1346 | + ' ' . |
|
| 1347 | + str_replace('*/', '* /', public_decompiler($boucle, $gram, 0, 'criteres')) . |
|
| 1348 | + ($boucle->debug ? "\n *\n * " . implode("\n * ", $boucle->debug) . "\n" : '') . |
|
| 1349 | + " */\n"; |
|
| 1350 | + } else { |
|
| 1351 | + $decomp = ("\n/*\n" . |
|
| 1352 | + str_replace('*/', '* /', public_decompiler($squelette, $gram)) |
|
| 1353 | + . "\n*/"); |
|
| 1354 | + } |
|
| 1355 | + $boucles[$id]->return = $decomp . $boucle->return; |
|
| 1356 | + $GLOBALS['debug_objets']['code'][$nom . $id] = $boucle->return; |
|
| 1357 | + } |
|
| 1358 | + } |
|
| 1359 | + |
|
| 1360 | + return $boucles; |
|
| 1361 | 1361 | } |
| 1362 | 1362 | |
| 1363 | 1363 | // Point d'entree pour arbre de syntaxe abstraite fourni en premier argument |
| 1364 | 1364 | // Autres specifications comme ci-dessus |
| 1365 | 1365 | |
| 1366 | 1366 | function compiler_squelette($squelette, $boucles, $nom, $descr, $sourcefile, string $connect = '') { |
| 1367 | - static $trouver_table; |
|
| 1368 | - spip_timer('calcul_skel'); |
|
| 1369 | - |
|
| 1370 | - if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1371 | - $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1372 | - $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1373 | - |
|
| 1374 | - if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1375 | - $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1376 | - } |
|
| 1377 | - } |
|
| 1378 | - foreach ($boucles as $id => $boucle) { |
|
| 1379 | - $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1380 | - } |
|
| 1381 | - $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1382 | - |
|
| 1383 | - // Demander la description des tables une fois pour toutes |
|
| 1384 | - if (!$trouver_table) { |
|
| 1385 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1386 | - } |
|
| 1387 | - |
|
| 1388 | - // reperer si les doublons sont demandes |
|
| 1389 | - // pour un inclure ou une boucle document |
|
| 1390 | - // c'est utile a la fonction champs_traitements |
|
| 1391 | - foreach ($boucles as $id => $boucle) { |
|
| 1392 | - if (!($type = $boucle->type_requete)) { |
|
| 1393 | - continue; |
|
| 1394 | - } |
|
| 1395 | - if ( |
|
| 1396 | - !$descr['documents'] and ( |
|
| 1397 | - (($type == 'documents') and $boucle->doublons) or |
|
| 1398 | - compile_inclure_doublons($boucle->avant) or |
|
| 1399 | - compile_inclure_doublons($boucle->apres) or |
|
| 1400 | - compile_inclure_doublons($boucle->milieu) or |
|
| 1401 | - compile_inclure_doublons($boucle->altern)) |
|
| 1402 | - ) { |
|
| 1403 | - $descr['documents'] = true; |
|
| 1404 | - } |
|
| 1405 | - if ($type != TYPE_RECURSIF) { |
|
| 1406 | - if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1407 | - $boucles[$id]->sql_serveur = $connect; |
|
| 1408 | - } |
|
| 1409 | - |
|
| 1410 | - // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1411 | - if ( |
|
| 1412 | - $g = charger_fonction( |
|
| 1413 | - preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1414 | - 'iterateur', |
|
| 1415 | - true |
|
| 1416 | - ) |
|
| 1417 | - ) { |
|
| 1418 | - $boucles[$id] = $g($boucle); |
|
| 1419 | - |
|
| 1420 | - // sinon, en cas de requeteur d'un type predefini, |
|
| 1421 | - // utiliser les informations donnees par le requeteur |
|
| 1422 | - // cas "php:xx" et "data:xx". |
|
| 1423 | - } else { |
|
| 1424 | - if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1425 | - $requeteur($boucles, $boucle, $id); |
|
| 1426 | - |
|
| 1427 | - // utiliser la description des champs transmis |
|
| 1428 | - } else { |
|
| 1429 | - $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1430 | - // si la table n'existe pas avec le connecteur par defaut, |
|
| 1431 | - // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1432 | - // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1433 | - if ( |
|
| 1434 | - !$show |
|
| 1435 | - and $show = $trouver_table($type, strtolower($type)) |
|
| 1436 | - ) { |
|
| 1437 | - $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1438 | - } |
|
| 1439 | - if ($show) { |
|
| 1440 | - $boucles[$id]->show = $show; |
|
| 1441 | - // recopie les infos les plus importantes |
|
| 1442 | - $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1443 | - $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1444 | - $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1445 | - $boucles[$id]->iterateur = 'SQL'; |
|
| 1446 | - |
|
| 1447 | - if (empty($boucles[$id]->descr)) { |
|
| 1448 | - $boucles[$id]->descr = &$descr; |
|
| 1449 | - } |
|
| 1450 | - if ( |
|
| 1451 | - (!$boucles[$id]->jointures) |
|
| 1452 | - and is_array($show['tables_jointures']) |
|
| 1453 | - and count($x = $show['tables_jointures']) |
|
| 1454 | - ) { |
|
| 1455 | - $boucles[$id]->jointures = $x; |
|
| 1456 | - } |
|
| 1457 | - if ($boucles[$id]->jointures_explicites) { |
|
| 1458 | - $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1459 | - while ($j = array_pop($jointures)) { |
|
| 1460 | - array_unshift($boucles[$id]->jointures, $j); |
|
| 1461 | - } |
|
| 1462 | - } |
|
| 1463 | - } else { |
|
| 1464 | - // Pas une erreur si la table est optionnelle |
|
| 1465 | - if ($boucles[$id]->table_optionnelle) { |
|
| 1466 | - $boucles[$id]->type_requete = ''; |
|
| 1467 | - } else { |
|
| 1468 | - $boucles[$id]->type_requete = false; |
|
| 1469 | - $boucle = $boucles[$id]; |
|
| 1470 | - $x = (!$boucle->sql_serveur ? '' : |
|
| 1471 | - ($boucle->sql_serveur . ':')) . |
|
| 1472 | - $type; |
|
| 1473 | - $msg = [ |
|
| 1474 | - 'zbug_table_inconnue', |
|
| 1475 | - ['table' => $x] |
|
| 1476 | - ]; |
|
| 1477 | - erreur_squelette($msg, $boucle); |
|
| 1478 | - } |
|
| 1479 | - } |
|
| 1480 | - } |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - } |
|
| 1484 | - |
|
| 1485 | - // Commencer par reperer les boucles appelees explicitement |
|
| 1486 | - // car elles indexent les arguments de maniere derogatoire |
|
| 1487 | - foreach ($boucles as $id => $boucle) { |
|
| 1488 | - if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1489 | - $boucles[$id]->descr = &$descr; |
|
| 1490 | - $rec = &$boucles[$boucle->param[0]]; |
|
| 1491 | - if (!$rec) { |
|
| 1492 | - $msg = [ |
|
| 1493 | - 'zbug_boucle_recursive_undef', |
|
| 1494 | - ['nom' => $boucle->param[0]] |
|
| 1495 | - ]; |
|
| 1496 | - erreur_squelette($msg, $boucle); |
|
| 1497 | - $boucles[$id]->type_requete = false; |
|
| 1498 | - } else { |
|
| 1499 | - $rec->externe = $id; |
|
| 1500 | - $descr['id_mere'] = $id; |
|
| 1501 | - $boucles[$id]->return = |
|
| 1502 | - calculer_liste( |
|
| 1503 | - [$rec], |
|
| 1504 | - $descr, |
|
| 1505 | - $boucles, |
|
| 1506 | - $boucle->param |
|
| 1507 | - ); |
|
| 1508 | - } |
|
| 1509 | - } |
|
| 1510 | - } |
|
| 1511 | - foreach ($boucles as $id => $boucle) { |
|
| 1512 | - $id = strval($id); // attention au type dans index_pile |
|
| 1513 | - $type = $boucle->type_requete; |
|
| 1514 | - if ($type and $type != TYPE_RECURSIF) { |
|
| 1515 | - $res = ''; |
|
| 1516 | - if ($boucle->param) { |
|
| 1517 | - // retourne un tableau en cas d'erreur |
|
| 1518 | - $res = calculer_criteres($id, $boucles); |
|
| 1519 | - } |
|
| 1520 | - $descr['id_mere'] = $id; |
|
| 1521 | - $boucles[$id]->return = |
|
| 1522 | - calculer_liste( |
|
| 1523 | - $boucle->milieu, |
|
| 1524 | - $descr, |
|
| 1525 | - $boucles, |
|
| 1526 | - $id |
|
| 1527 | - ); |
|
| 1528 | - // Si les criteres se sont mal compiles |
|
| 1529 | - // ne pas tenter d'assembler le code final |
|
| 1530 | - // (mais compiler le corps pour detection d'erreurs) |
|
| 1531 | - if (is_array($res)) { |
|
| 1532 | - $boucles[$id]->type_requete = false; |
|
| 1533 | - } |
|
| 1534 | - } |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - // idem pour la racine |
|
| 1538 | - $descr['id_mere'] = ''; |
|
| 1539 | - $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1540 | - |
|
| 1541 | - |
|
| 1542 | - // Calcul du corps de toutes les fonctions PHP, |
|
| 1543 | - // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1544 | - // de'terminables seulement maintenant |
|
| 1545 | - |
|
| 1546 | - foreach ($boucles as $id => $boucle) { |
|
| 1547 | - $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1548 | - if ($boucle->return === false) { |
|
| 1549 | - $corps = false; |
|
| 1550 | - continue; |
|
| 1551 | - } |
|
| 1552 | - // appeler la fonction de definition de la boucle |
|
| 1553 | - |
|
| 1554 | - if ($req = $boucle->type_requete) { |
|
| 1555 | - // boucle personnalisée ? |
|
| 1556 | - $table = strtoupper($boucle->type_requete); |
|
| 1557 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1558 | - if ( |
|
| 1559 | - // fonction de boucle avec serveur & table |
|
| 1560 | - (!$serveur or |
|
| 1561 | - ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1562 | - and (!function_exists($f = $f . '_dist')) |
|
| 1563 | - ) |
|
| 1564 | - ) |
|
| 1565 | - // fonction de boucle avec table |
|
| 1566 | - and (!function_exists($f = 'boucle_' . $table)) |
|
| 1567 | - and (!function_exists($f = $f . '_dist')) |
|
| 1568 | - ) { |
|
| 1569 | - // fonction de boucle standard |
|
| 1570 | - if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1571 | - $f = 'boucle_DEFAUT_dist'; |
|
| 1572 | - } |
|
| 1573 | - } |
|
| 1574 | - |
|
| 1575 | - $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1576 | - "static \$connect;\n\t" . |
|
| 1577 | - "\$command['connect'] = \$connect = " . |
|
| 1578 | - _q($boucle->sql_serveur) . |
|
| 1579 | - ';' . |
|
| 1580 | - $f($id, $boucles); |
|
| 1581 | - } else { |
|
| 1582 | - $req = ("\n\treturn '';"); |
|
| 1583 | - } |
|
| 1584 | - |
|
| 1585 | - $boucles[$id]->return = |
|
| 1586 | - "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1587 | - '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1588 | - $req . |
|
| 1589 | - "\n}\n"; |
|
| 1590 | - } |
|
| 1591 | - |
|
| 1592 | - // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1593 | - // retourner False, sinon inserer leur decompilation |
|
| 1594 | - if (is_bool($corps)) { |
|
| 1595 | - return false; |
|
| 1596 | - } |
|
| 1597 | - |
|
| 1598 | - $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1367 | + static $trouver_table; |
|
| 1368 | + spip_timer('calcul_skel'); |
|
| 1369 | + |
|
| 1370 | + if (defined('_VAR_MODE') and _VAR_MODE == 'debug') { |
|
| 1371 | + $GLOBALS['debug_objets']['squelette'][$nom] = $descr['squelette']; |
|
| 1372 | + $GLOBALS['debug_objets']['sourcefile'][$nom] = $sourcefile; |
|
| 1373 | + |
|
| 1374 | + if (!isset($GLOBALS['debug_objets']['principal'])) { |
|
| 1375 | + $GLOBALS['debug_objets']['principal'] = $nom; |
|
| 1376 | + } |
|
| 1377 | + } |
|
| 1378 | + foreach ($boucles as $id => $boucle) { |
|
| 1379 | + $GLOBALS['debug_objets']['boucle'][$nom . $id] = $boucle; |
|
| 1380 | + } |
|
| 1381 | + $descr['documents'] = compile_inclure_doublons($squelette); |
|
| 1382 | + |
|
| 1383 | + // Demander la description des tables une fois pour toutes |
|
| 1384 | + if (!$trouver_table) { |
|
| 1385 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 1386 | + } |
|
| 1387 | + |
|
| 1388 | + // reperer si les doublons sont demandes |
|
| 1389 | + // pour un inclure ou une boucle document |
|
| 1390 | + // c'est utile a la fonction champs_traitements |
|
| 1391 | + foreach ($boucles as $id => $boucle) { |
|
| 1392 | + if (!($type = $boucle->type_requete)) { |
|
| 1393 | + continue; |
|
| 1394 | + } |
|
| 1395 | + if ( |
|
| 1396 | + !$descr['documents'] and ( |
|
| 1397 | + (($type == 'documents') and $boucle->doublons) or |
|
| 1398 | + compile_inclure_doublons($boucle->avant) or |
|
| 1399 | + compile_inclure_doublons($boucle->apres) or |
|
| 1400 | + compile_inclure_doublons($boucle->milieu) or |
|
| 1401 | + compile_inclure_doublons($boucle->altern)) |
|
| 1402 | + ) { |
|
| 1403 | + $descr['documents'] = true; |
|
| 1404 | + } |
|
| 1405 | + if ($type != TYPE_RECURSIF) { |
|
| 1406 | + if (!$boucles[$id]->sql_serveur and $connect) { |
|
| 1407 | + $boucles[$id]->sql_serveur = $connect; |
|
| 1408 | + } |
|
| 1409 | + |
|
| 1410 | + // chercher dans les iterateurs du repertoire iterateur/ |
|
| 1411 | + if ( |
|
| 1412 | + $g = charger_fonction( |
|
| 1413 | + preg_replace('/\W/', '_', $boucle->type_requete), |
|
| 1414 | + 'iterateur', |
|
| 1415 | + true |
|
| 1416 | + ) |
|
| 1417 | + ) { |
|
| 1418 | + $boucles[$id] = $g($boucle); |
|
| 1419 | + |
|
| 1420 | + // sinon, en cas de requeteur d'un type predefini, |
|
| 1421 | + // utiliser les informations donnees par le requeteur |
|
| 1422 | + // cas "php:xx" et "data:xx". |
|
| 1423 | + } else { |
|
| 1424 | + if ($boucle->sql_serveur and $requeteur = charger_fonction($boucle->sql_serveur, 'requeteur', true)) { |
|
| 1425 | + $requeteur($boucles, $boucle, $id); |
|
| 1426 | + |
|
| 1427 | + // utiliser la description des champs transmis |
|
| 1428 | + } else { |
|
| 1429 | + $show = $trouver_table($type, $boucles[$id]->sql_serveur); |
|
| 1430 | + // si la table n'existe pas avec le connecteur par defaut, |
|
| 1431 | + // c'est peut etre une table qui necessite son connecteur dedie fourni |
|
| 1432 | + // permet une ecriture allegee (GEO) -> (geo:GEO) |
|
| 1433 | + if ( |
|
| 1434 | + !$show |
|
| 1435 | + and $show = $trouver_table($type, strtolower($type)) |
|
| 1436 | + ) { |
|
| 1437 | + $boucles[$id]->sql_serveur = strtolower($type); |
|
| 1438 | + } |
|
| 1439 | + if ($show) { |
|
| 1440 | + $boucles[$id]->show = $show; |
|
| 1441 | + // recopie les infos les plus importantes |
|
| 1442 | + $boucles[$id]->primary = $show['key']['PRIMARY KEY'] ?? ''; |
|
| 1443 | + $boucles[$id]->id_table = $x = preg_replace(',^spip_,', '', $show['id_table']); |
|
| 1444 | + $boucles[$id]->from[$x] = $nom_table = $show['table']; |
|
| 1445 | + $boucles[$id]->iterateur = 'SQL'; |
|
| 1446 | + |
|
| 1447 | + if (empty($boucles[$id]->descr)) { |
|
| 1448 | + $boucles[$id]->descr = &$descr; |
|
| 1449 | + } |
|
| 1450 | + if ( |
|
| 1451 | + (!$boucles[$id]->jointures) |
|
| 1452 | + and is_array($show['tables_jointures']) |
|
| 1453 | + and count($x = $show['tables_jointures']) |
|
| 1454 | + ) { |
|
| 1455 | + $boucles[$id]->jointures = $x; |
|
| 1456 | + } |
|
| 1457 | + if ($boucles[$id]->jointures_explicites) { |
|
| 1458 | + $jointures = preg_split('/\s+/', $boucles[$id]->jointures_explicites); |
|
| 1459 | + while ($j = array_pop($jointures)) { |
|
| 1460 | + array_unshift($boucles[$id]->jointures, $j); |
|
| 1461 | + } |
|
| 1462 | + } |
|
| 1463 | + } else { |
|
| 1464 | + // Pas une erreur si la table est optionnelle |
|
| 1465 | + if ($boucles[$id]->table_optionnelle) { |
|
| 1466 | + $boucles[$id]->type_requete = ''; |
|
| 1467 | + } else { |
|
| 1468 | + $boucles[$id]->type_requete = false; |
|
| 1469 | + $boucle = $boucles[$id]; |
|
| 1470 | + $x = (!$boucle->sql_serveur ? '' : |
|
| 1471 | + ($boucle->sql_serveur . ':')) . |
|
| 1472 | + $type; |
|
| 1473 | + $msg = [ |
|
| 1474 | + 'zbug_table_inconnue', |
|
| 1475 | + ['table' => $x] |
|
| 1476 | + ]; |
|
| 1477 | + erreur_squelette($msg, $boucle); |
|
| 1478 | + } |
|
| 1479 | + } |
|
| 1480 | + } |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + } |
|
| 1484 | + |
|
| 1485 | + // Commencer par reperer les boucles appelees explicitement |
|
| 1486 | + // car elles indexent les arguments de maniere derogatoire |
|
| 1487 | + foreach ($boucles as $id => $boucle) { |
|
| 1488 | + if ($boucle->type_requete == TYPE_RECURSIF and $boucle->param) { |
|
| 1489 | + $boucles[$id]->descr = &$descr; |
|
| 1490 | + $rec = &$boucles[$boucle->param[0]]; |
|
| 1491 | + if (!$rec) { |
|
| 1492 | + $msg = [ |
|
| 1493 | + 'zbug_boucle_recursive_undef', |
|
| 1494 | + ['nom' => $boucle->param[0]] |
|
| 1495 | + ]; |
|
| 1496 | + erreur_squelette($msg, $boucle); |
|
| 1497 | + $boucles[$id]->type_requete = false; |
|
| 1498 | + } else { |
|
| 1499 | + $rec->externe = $id; |
|
| 1500 | + $descr['id_mere'] = $id; |
|
| 1501 | + $boucles[$id]->return = |
|
| 1502 | + calculer_liste( |
|
| 1503 | + [$rec], |
|
| 1504 | + $descr, |
|
| 1505 | + $boucles, |
|
| 1506 | + $boucle->param |
|
| 1507 | + ); |
|
| 1508 | + } |
|
| 1509 | + } |
|
| 1510 | + } |
|
| 1511 | + foreach ($boucles as $id => $boucle) { |
|
| 1512 | + $id = strval($id); // attention au type dans index_pile |
|
| 1513 | + $type = $boucle->type_requete; |
|
| 1514 | + if ($type and $type != TYPE_RECURSIF) { |
|
| 1515 | + $res = ''; |
|
| 1516 | + if ($boucle->param) { |
|
| 1517 | + // retourne un tableau en cas d'erreur |
|
| 1518 | + $res = calculer_criteres($id, $boucles); |
|
| 1519 | + } |
|
| 1520 | + $descr['id_mere'] = $id; |
|
| 1521 | + $boucles[$id]->return = |
|
| 1522 | + calculer_liste( |
|
| 1523 | + $boucle->milieu, |
|
| 1524 | + $descr, |
|
| 1525 | + $boucles, |
|
| 1526 | + $id |
|
| 1527 | + ); |
|
| 1528 | + // Si les criteres se sont mal compiles |
|
| 1529 | + // ne pas tenter d'assembler le code final |
|
| 1530 | + // (mais compiler le corps pour detection d'erreurs) |
|
| 1531 | + if (is_array($res)) { |
|
| 1532 | + $boucles[$id]->type_requete = false; |
|
| 1533 | + } |
|
| 1534 | + } |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + // idem pour la racine |
|
| 1538 | + $descr['id_mere'] = ''; |
|
| 1539 | + $corps = calculer_liste($squelette, $descr, $boucles); |
|
| 1540 | + |
|
| 1541 | + |
|
| 1542 | + // Calcul du corps de toutes les fonctions PHP, |
|
| 1543 | + // en particulier les requetes SQL et TOTAL_BOUCLE |
|
| 1544 | + // de'terminables seulement maintenant |
|
| 1545 | + |
|
| 1546 | + foreach ($boucles as $id => $boucle) { |
|
| 1547 | + $boucle = $boucles[$id] = pipeline('pre_boucle', $boucle); |
|
| 1548 | + if ($boucle->return === false) { |
|
| 1549 | + $corps = false; |
|
| 1550 | + continue; |
|
| 1551 | + } |
|
| 1552 | + // appeler la fonction de definition de la boucle |
|
| 1553 | + |
|
| 1554 | + if ($req = $boucle->type_requete) { |
|
| 1555 | + // boucle personnalisée ? |
|
| 1556 | + $table = strtoupper($boucle->type_requete); |
|
| 1557 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1558 | + if ( |
|
| 1559 | + // fonction de boucle avec serveur & table |
|
| 1560 | + (!$serveur or |
|
| 1561 | + ((!function_exists($f = 'boucle_' . $serveur . '_' . $table)) |
|
| 1562 | + and (!function_exists($f = $f . '_dist')) |
|
| 1563 | + ) |
|
| 1564 | + ) |
|
| 1565 | + // fonction de boucle avec table |
|
| 1566 | + and (!function_exists($f = 'boucle_' . $table)) |
|
| 1567 | + and (!function_exists($f = $f . '_dist')) |
|
| 1568 | + ) { |
|
| 1569 | + // fonction de boucle standard |
|
| 1570 | + if (!function_exists($f = 'boucle_DEFAUT')) { |
|
| 1571 | + $f = 'boucle_DEFAUT_dist'; |
|
| 1572 | + } |
|
| 1573 | + } |
|
| 1574 | + |
|
| 1575 | + $req = "\n\n\tstatic \$command = array();\n\t" . |
|
| 1576 | + "static \$connect;\n\t" . |
|
| 1577 | + "\$command['connect'] = \$connect = " . |
|
| 1578 | + _q($boucle->sql_serveur) . |
|
| 1579 | + ';' . |
|
| 1580 | + $f($id, $boucles); |
|
| 1581 | + } else { |
|
| 1582 | + $req = ("\n\treturn '';"); |
|
| 1583 | + } |
|
| 1584 | + |
|
| 1585 | + $boucles[$id]->return = |
|
| 1586 | + "\n\nfunction BOUCLE" . strtr($id, '-', '_') . $nom . |
|
| 1587 | + '(&$Cache, &$Pile, &$doublons, &$Numrows, $SP) {' . |
|
| 1588 | + $req . |
|
| 1589 | + "\n}\n"; |
|
| 1590 | + } |
|
| 1591 | + |
|
| 1592 | + // Au final, si le corps ou un critere au moins s'est mal compile |
|
| 1593 | + // retourner False, sinon inserer leur decompilation |
|
| 1594 | + if (is_bool($corps)) { |
|
| 1595 | + return false; |
|
| 1596 | + } |
|
| 1597 | + |
|
| 1598 | + $principal = "\nfunction " . $nom . '($Cache, $Pile, $doublons = array(), $Numrows = array(), $SP = 0) { |
|
| 1599 | 1599 | ' |
| 1600 | - // reporter de maniere securisee les doublons inclus |
|
| 1601 | - . ' |
|
| 1600 | + // reporter de maniere securisee les doublons inclus |
|
| 1601 | + . ' |
|
| 1602 | 1602 | if (isset($Pile[0]["doublons"]) AND is_array($Pile[0]["doublons"])) |
| 1603 | 1603 | $doublons = nettoyer_env_doublons($Pile[0]["doublons"]); |
| 1604 | 1604 | |
| 1605 | 1605 | $connect = ' . |
| 1606 | - _q($connect) . '; |
|
| 1606 | + _q($connect) . '; |
|
| 1607 | 1607 | $page = ' . |
| 1608 | - // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1609 | - // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1610 | - // avant de referencer $Cache |
|
| 1611 | - $corps . '; |
|
| 1608 | + // ATTENTION, le calcul de l'expression $corps affectera $Cache |
|
| 1609 | + // c'est pourquoi on l'affecte a la variable auxiliaire $page. |
|
| 1610 | + // avant de referencer $Cache |
|
| 1611 | + $corps . '; |
|
| 1612 | 1612 | |
| 1613 | 1613 | return analyse_resultat_skel(' . var_export($nom, true) |
| 1614 | - . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1614 | + . ', $Cache, $page, ' . var_export($sourcefile, true) . '); |
|
| 1615 | 1615 | }'; |
| 1616 | 1616 | |
| 1617 | - $secondes = spip_timer('calcul_skel'); |
|
| 1618 | - spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1619 | - // $connect n'est pas sûr : on nettoie |
|
| 1620 | - $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1617 | + $secondes = spip_timer('calcul_skel'); |
|
| 1618 | + spip_log("COMPIL ($secondes) [$sourcefile] $nom.php"); |
|
| 1619 | + // $connect n'est pas sûr : on nettoie |
|
| 1620 | + $connect = preg_replace(',[^\w],', '', $connect); |
|
| 1621 | 1621 | |
| 1622 | - // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1623 | - $code = new Boucle(); |
|
| 1624 | - $code->descr = $descr; |
|
| 1625 | - $code->return = ' |
|
| 1622 | + // Assimiler la fct principale a une boucle anonyme, pour retourner un resultat simple |
|
| 1623 | + $code = new Boucle(); |
|
| 1624 | + $code->descr = $descr; |
|
| 1625 | + $code->return = ' |
|
| 1626 | 1626 | // |
| 1627 | 1627 | // Fonction principale du squelette ' . |
| 1628 | - $sourcefile . |
|
| 1629 | - ($connect ? " pour $connect" : '') . |
|
| 1630 | - (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1631 | - "\n//\n" . |
|
| 1632 | - $principal; |
|
| 1628 | + $sourcefile . |
|
| 1629 | + ($connect ? " pour $connect" : '') . |
|
| 1630 | + (!CODE_COMMENTE ? '' : "\n// Temps de compilation total: $secondes") . |
|
| 1631 | + "\n//\n" . |
|
| 1632 | + $principal; |
|
| 1633 | 1633 | |
| 1634 | - $boucles[''] = $code; |
|
| 1634 | + $boucles[''] = $code; |
|
| 1635 | 1635 | |
| 1636 | - return $boucles; |
|
| 1636 | + return $boucles; |
|
| 1637 | 1637 | } |
| 1638 | 1638 | |
| 1639 | 1639 | |
@@ -1650,18 +1650,18 @@ discard block |
||
| 1650 | 1650 | * |
| 1651 | 1651 | **/ |
| 1652 | 1652 | function requeteur_php_dist(&$boucles, &$boucle, &$id) { |
| 1653 | - if (class_exists($boucle->type_requete)) { |
|
| 1654 | - $g = charger_fonction('php', 'iterateur'); |
|
| 1655 | - $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1656 | - } else { |
|
| 1657 | - $x = $boucle->type_requete; |
|
| 1658 | - $boucle->type_requete = false; |
|
| 1659 | - $msg = [ |
|
| 1660 | - 'zbug_iterateur_inconnu', |
|
| 1661 | - ['iterateur' => $x] |
|
| 1662 | - ]; |
|
| 1663 | - erreur_squelette($msg, $boucle); |
|
| 1664 | - } |
|
| 1653 | + if (class_exists($boucle->type_requete)) { |
|
| 1654 | + $g = charger_fonction('php', 'iterateur'); |
|
| 1655 | + $boucles[$id] = $g($boucle, $boucle->type_requete); |
|
| 1656 | + } else { |
|
| 1657 | + $x = $boucle->type_requete; |
|
| 1658 | + $boucle->type_requete = false; |
|
| 1659 | + $msg = [ |
|
| 1660 | + 'zbug_iterateur_inconnu', |
|
| 1661 | + ['iterateur' => $x] |
|
| 1662 | + ]; |
|
| 1663 | + erreur_squelette($msg, $boucle); |
|
| 1664 | + } |
|
| 1665 | 1665 | } |
| 1666 | 1666 | |
| 1667 | 1667 | |
@@ -1679,22 +1679,22 @@ discard block |
||
| 1679 | 1679 | * |
| 1680 | 1680 | **/ |
| 1681 | 1681 | function requeteur_data_dist(&$boucles, &$boucle, &$id) { |
| 1682 | - include_spip('iterateur/data'); |
|
| 1683 | - if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | - $g = charger_fonction('data', 'iterateur'); |
|
| 1685 | - $boucles[$id] = $g($boucle); |
|
| 1686 | - // from[0] stocke le type de data (rss, yql, ...) |
|
| 1687 | - $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1688 | - } else { |
|
| 1689 | - $x = $boucle->type_requete; |
|
| 1690 | - $boucle->type_requete = false; |
|
| 1691 | - $msg = [ |
|
| 1692 | - 'zbug_requeteur_inconnu', |
|
| 1693 | - [ |
|
| 1694 | - 'requeteur' => 'data', |
|
| 1695 | - 'type' => $x |
|
| 1696 | - ] |
|
| 1697 | - ]; |
|
| 1698 | - erreur_squelette($msg, $boucle); |
|
| 1699 | - } |
|
| 1682 | + include_spip('iterateur/data'); |
|
| 1683 | + if ($h = charger_fonction($boucle->type_requete . '_to_array', 'inc', true)) { |
|
| 1684 | + $g = charger_fonction('data', 'iterateur'); |
|
| 1685 | + $boucles[$id] = $g($boucle); |
|
| 1686 | + // from[0] stocke le type de data (rss, yql, ...) |
|
| 1687 | + $boucles[$id]->from[] = $boucle->type_requete; |
|
| 1688 | + } else { |
|
| 1689 | + $x = $boucle->type_requete; |
|
| 1690 | + $boucle->type_requete = false; |
|
| 1691 | + $msg = [ |
|
| 1692 | + 'zbug_requeteur_inconnu', |
|
| 1693 | + [ |
|
| 1694 | + 'requeteur' => 'data', |
|
| 1695 | + 'type' => $x |
|
| 1696 | + ] |
|
| 1697 | + ]; |
|
| 1698 | + erreur_squelette($msg, $boucle); |
|
| 1699 | + } |
|
| 1700 | 1700 | } |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | /** |
@@ -43,12 +43,12 @@ discard block |
||
| 43 | 43 | **/ |
| 44 | 44 | function critere_racine_dist($idb, &$boucles, $crit) { |
| 45 | 45 | |
| 46 | - $not = $crit->not; |
|
| 47 | - $boucle = &$boucles[$idb]; |
|
| 48 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 46 | + $not = $crit->not; |
|
| 47 | + $boucle = &$boucles[$idb]; |
|
| 48 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 49 | 49 | |
| 50 | - $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 50 | + $c = ["'='", "'$boucle->id_table." . "$id_parent'", 0]; |
|
| 51 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 52 | 52 | } |
| 53 | 53 | |
| 54 | 54 | |
@@ -65,15 +65,15 @@ discard block |
||
| 65 | 65 | * @return void|array |
| 66 | 66 | **/ |
| 67 | 67 | function critere_exclus_dist($idb, &$boucles, $crit) { |
| 68 | - $not = $crit->not; |
|
| 69 | - $boucle = &$boucles[$idb]; |
|
| 70 | - $id = $boucle->primary; |
|
| 71 | - |
|
| 72 | - if ($not or !$id) { |
|
| 73 | - return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | - } |
|
| 75 | - $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | - $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 68 | + $not = $crit->not; |
|
| 69 | + $boucle = &$boucles[$idb]; |
|
| 70 | + $id = $boucle->primary; |
|
| 71 | + |
|
| 72 | + if ($not or !$id) { |
|
| 73 | + return ['zbug_critere_inconnu', ['critere' => $not . $crit->op]]; |
|
| 74 | + } |
|
| 75 | + $arg = kwote(calculer_argument_precedent($idb, $id, $boucles)); |
|
| 76 | + $boucle->where[] = ["'!='", "'$boucle->id_table." . "$id'", $arg]; |
|
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | |
@@ -93,73 +93,73 @@ discard block |
||
| 93 | 93 | * @return void|array |
| 94 | 94 | **/ |
| 95 | 95 | function critere_doublons_dist($idb, &$boucles, $crit) { |
| 96 | - $boucle = &$boucles[$idb]; |
|
| 97 | - $primary = $boucle->primary; |
|
| 98 | - |
|
| 99 | - // la table nécessite une clé primaire, non composée |
|
| 100 | - if (!$primary or strpos($primary, ',')) { |
|
| 101 | - return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | - } |
|
| 103 | - |
|
| 104 | - $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | - |
|
| 106 | - // le doublon s'applique sur un type de boucle (article) |
|
| 107 | - $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | - |
|
| 109 | - // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | - // on obtient $nom = "'article' . 'nom'" |
|
| 111 | - if (isset($crit->param[0])) { |
|
| 112 | - $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | - } |
|
| 114 | - |
|
| 115 | - // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | - $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | - $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | - |
|
| 119 | - // on crée un sql_in avec la clé primaire de la table |
|
| 120 | - // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | - // $doublons et son index, ici $nom |
|
| 122 | - |
|
| 123 | - // debut du code "sql_in('articles.id_article', " |
|
| 124 | - $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | - // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | - // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | - $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | - |
|
| 129 | - // le debut complet du code des doublons |
|
| 130 | - $debut_doub = $debut_in . $debut_doub; |
|
| 131 | - |
|
| 132 | - // nom du doublon "('article' . 'nom')]" |
|
| 133 | - $fin_doub = "($nom)]"; |
|
| 134 | - |
|
| 135 | - // si on trouve un autre critère doublon, |
|
| 136 | - // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | - foreach ($boucle->where as $k => $w) { |
|
| 138 | - if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | - // fusionner le sql_in (du where) |
|
| 140 | - $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | - // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | - $x = strpos($boucle->hash, $init_comment); |
|
| 143 | - $len = strlen($init_comment); |
|
| 144 | - $boucle->hash = |
|
| 145 | - substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | - |
|
| 147 | - return; |
|
| 148 | - } |
|
| 149 | - } |
|
| 150 | - |
|
| 151 | - // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | - $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | - |
|
| 154 | - // déclarer le doublon s'il n'existe pas encore |
|
| 155 | - $boucle->hash .= $init_comment . $init_code; |
|
| 156 | - |
|
| 157 | - |
|
| 158 | - # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | - # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | - # {!doublons A}{doublons B} |
|
| 161 | - # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | - # if ($crit->not) $boucle->doublons = ""; |
|
| 96 | + $boucle = &$boucles[$idb]; |
|
| 97 | + $primary = $boucle->primary; |
|
| 98 | + |
|
| 99 | + // la table nécessite une clé primaire, non composée |
|
| 100 | + if (!$primary or strpos($primary, ',')) { |
|
| 101 | + return ['zbug_doublon_sur_table_sans_cle_primaire']; |
|
| 102 | + } |
|
| 103 | + |
|
| 104 | + $not = ($crit->not ? '' : 'NOT'); |
|
| 105 | + |
|
| 106 | + // le doublon s'applique sur un type de boucle (article) |
|
| 107 | + $nom = "'" . $boucle->type_requete . "'"; |
|
| 108 | + |
|
| 109 | + // compléter le nom avec un nom précisé {doublons nom} |
|
| 110 | + // on obtient $nom = "'article' . 'nom'" |
|
| 111 | + if (isset($crit->param[0])) { |
|
| 112 | + $nom .= '.' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 113 | + } |
|
| 114 | + |
|
| 115 | + // code qui déclarera l'index du stockage de nos doublons (pour éviter une notice PHP) |
|
| 116 | + $init_comment = "\n\n\t// Initialise le(s) critère(s) doublons\n"; |
|
| 117 | + $init_code = "\tif (!isset(\$doublons[\$d = $nom])) { \$doublons[\$d] = ''; }\n"; |
|
| 118 | + |
|
| 119 | + // on crée un sql_in avec la clé primaire de la table |
|
| 120 | + // et la collection des doublons déjà emmagasinés dans le tableau |
|
| 121 | + // $doublons et son index, ici $nom |
|
| 122 | + |
|
| 123 | + // debut du code "sql_in('articles.id_article', " |
|
| 124 | + $debut_in = "sql_in('" . $boucle->id_table . '.' . $primary . "', "; |
|
| 125 | + // lecture des données du doublon "$doublons[$doublon_index[] = " |
|
| 126 | + // Attention : boucle->doublons désigne une variable qu'on affecte |
|
| 127 | + $debut_doub = '$doublons[' . (!$not ? '' : ($boucle->doublons . '[]= ')); |
|
| 128 | + |
|
| 129 | + // le debut complet du code des doublons |
|
| 130 | + $debut_doub = $debut_in . $debut_doub; |
|
| 131 | + |
|
| 132 | + // nom du doublon "('article' . 'nom')]" |
|
| 133 | + $fin_doub = "($nom)]"; |
|
| 134 | + |
|
| 135 | + // si on trouve un autre critère doublon, |
|
| 136 | + // on fusionne pour avoir un seul IN, et on s'en va ! |
|
| 137 | + foreach ($boucle->where as $k => $w) { |
|
| 138 | + if (strpos($w[0], $debut_doub) === 0) { |
|
| 139 | + // fusionner le sql_in (du where) |
|
| 140 | + $boucle->where[$k][0] = $debut_doub . $fin_doub . ' . ' . substr($w[0], strlen($debut_in)); |
|
| 141 | + // fusionner l'initialisation (du hash) pour faire plus joli |
|
| 142 | + $x = strpos($boucle->hash, $init_comment); |
|
| 143 | + $len = strlen($init_comment); |
|
| 144 | + $boucle->hash = |
|
| 145 | + substr($boucle->hash, 0, $x + $len) . $init_code . substr($boucle->hash, $x + $len); |
|
| 146 | + |
|
| 147 | + return; |
|
| 148 | + } |
|
| 149 | + } |
|
| 150 | + |
|
| 151 | + // mettre l'ensemble dans un tableau pour que ce ne soit pas vu comme une constante |
|
| 152 | + $boucle->where[] = [$debut_doub . $fin_doub . ", '" . $not . "')"]; |
|
| 153 | + |
|
| 154 | + // déclarer le doublon s'il n'existe pas encore |
|
| 155 | + $boucle->hash .= $init_comment . $init_code; |
|
| 156 | + |
|
| 157 | + |
|
| 158 | + # la ligne suivante avait l'intention d'eviter une collecte deja faite |
|
| 159 | + # mais elle fait planter une boucle a 2 critere doublons: |
|
| 160 | + # {!doublons A}{doublons B} |
|
| 161 | + # (de http://article.gmane.org/gmane.comp.web.spip.devel/31034) |
|
| 162 | + # if ($crit->not) $boucle->doublons = ""; |
|
| 163 | 163 | } |
| 164 | 164 | |
| 165 | 165 | |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @return void |
| 181 | 181 | **/ |
| 182 | 182 | function critere_lang_select_dist($idb, &$boucles, $crit) { |
| 183 | - if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | - $param = 'oui'; |
|
| 185 | - } |
|
| 186 | - if ($crit->not) { |
|
| 187 | - $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | - } |
|
| 189 | - $boucle = &$boucles[$idb]; |
|
| 190 | - $boucle->lang_select = $param; |
|
| 183 | + if (!isset($crit->param[1][0]) or !($param = $crit->param[1][0]->texte)) { |
|
| 184 | + $param = 'oui'; |
|
| 185 | + } |
|
| 186 | + if ($crit->not) { |
|
| 187 | + $param = ($param == 'oui') ? 'non' : 'oui'; |
|
| 188 | + } |
|
| 189 | + $boucle = &$boucles[$idb]; |
|
| 190 | + $boucle->lang_select = $param; |
|
| 191 | 191 | } |
| 192 | 192 | |
| 193 | 193 | |
@@ -209,15 +209,15 @@ discard block |
||
| 209 | 209 | * @return void |
| 210 | 210 | **/ |
| 211 | 211 | function critere_debut_dist($idb, &$boucles, $crit) { |
| 212 | - [$un, $deux] = $crit->param; |
|
| 213 | - $un = $un[0]->texte; |
|
| 214 | - $deux = $deux[0]->texte; |
|
| 215 | - if ($deux) { |
|
| 216 | - $boucles[$idb]->limit = |
|
| 217 | - 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | - } else { |
|
| 219 | - calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | - } |
|
| 212 | + [$un, $deux] = $crit->param; |
|
| 213 | + $un = $un[0]->texte; |
|
| 214 | + $deux = $deux[0]->texte; |
|
| 215 | + if ($deux) { |
|
| 216 | + $boucles[$idb]->limit = |
|
| 217 | + 'intval($Pile[0]["debut' . $un . '"]) . ",' . $deux . '"'; |
|
| 218 | + } else { |
|
| 219 | + calculer_critere_DEFAUT_dist($idb, $boucles, $crit); |
|
| 220 | + } |
|
| 221 | 221 | } |
| 222 | 222 | |
| 223 | 223 | |
@@ -251,58 +251,58 @@ discard block |
||
| 251 | 251 | **/ |
| 252 | 252 | function critere_pagination_dist($idb, &$boucles, $crit) { |
| 253 | 253 | |
| 254 | - $boucle = &$boucles[$idb]; |
|
| 255 | - // definition de la taille de la page |
|
| 256 | - $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | - |
|
| 259 | - if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | - $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | - } else { |
|
| 262 | - $r = intval($r[2]); |
|
| 263 | - $pas = strval($r ?: 10); |
|
| 264 | - } |
|
| 265 | - |
|
| 266 | - // Calcul du nommage de la pagination si il existe. |
|
| 267 | - // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | - // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | - $type = "'$idb'"; |
|
| 270 | - // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | - // Syntaxe {pagination 20, nom} |
|
| 272 | - if (isset($crit->param[0][1])) { |
|
| 273 | - $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | - } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | - elseif (isset($crit->param[1][0])) { |
|
| 276 | - $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | - } |
|
| 278 | - |
|
| 279 | - $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | - $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | - $partie = |
|
| 282 | - // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | - 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | - . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | - . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | - . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | - . "\t}\n" |
|
| 288 | - . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | - |
|
| 290 | - $boucle->hash .= ' |
|
| 254 | + $boucle = &$boucles[$idb]; |
|
| 255 | + // definition de la taille de la page |
|
| 256 | + $pas = !isset($crit->param[0][0]) ? "''" |
|
| 257 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 258 | + |
|
| 259 | + if (!preg_match(_CODE_QUOTE, $pas, $r)) { |
|
| 260 | + $pas = "((\$a = intval($pas)) ? \$a : 10)"; |
|
| 261 | + } else { |
|
| 262 | + $r = intval($r[2]); |
|
| 263 | + $pas = strval($r ?: 10); |
|
| 264 | + } |
|
| 265 | + |
|
| 266 | + // Calcul du nommage de la pagination si il existe. |
|
| 267 | + // La nouvelle syntaxe {pagination 20, nom} est prise en compte et privilégiée mais on reste |
|
| 268 | + // compatible avec l'ancienne car certains cas fonctionnent correctement |
|
| 269 | + $type = "'$idb'"; |
|
| 270 | + // Calcul d'un nommage spécifique de la pagination si précisé. |
|
| 271 | + // Syntaxe {pagination 20, nom} |
|
| 272 | + if (isset($crit->param[0][1])) { |
|
| 273 | + $type = calculer_liste([$crit->param[0][1]], $idb, $boucles, $boucle->id_parent); |
|
| 274 | + } // Ancienne syntaxe {pagination 20 nom} pour compatibilité |
|
| 275 | + elseif (isset($crit->param[1][0])) { |
|
| 276 | + $type = calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 277 | + } |
|
| 278 | + |
|
| 279 | + $debut = ($type[0] !== "'") ? "'debut'.$type" : ("'debut" . substr($type, 1)); |
|
| 280 | + $boucle->modificateur['debut_nom'] = $type; |
|
| 281 | + $partie = |
|
| 282 | + // tester si le numero de page demande est de la forme '@yyy' |
|
| 283 | + 'isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : _request(' . $debut . ");\n" |
|
| 284 | + . "\tif (\$debut_boucle && \$debut_boucle[0] === '@') {\n" |
|
| 285 | + . "\t\t" . '$debut_boucle = $Pile[0][' . $debut . '] = quete_debut_pagination(\'' . $boucle->primary . '\',$Pile[0][\'@' . $boucle->primary . '\'] = substr($debut_boucle,1),' . $pas . ',$iter);' . "\n" |
|
| 286 | + . "\t\t" . '$iter->seek(0);' . "\n" |
|
| 287 | + . "\t}\n" |
|
| 288 | + . "\t" . '$debut_boucle = intval($debut_boucle)'; |
|
| 289 | + |
|
| 290 | + $boucle->hash .= ' |
|
| 291 | 291 | $command[\'pagination\'] = array((isset($Pile[0][' . $debut . ']) ? $Pile[0][' . $debut . '] : null), ' . $pas . ');'; |
| 292 | 292 | |
| 293 | - $boucle->total_parties = $pas; |
|
| 294 | - calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | - // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | - // sauf si pas de primaire, ou si primaire composee |
|
| 297 | - // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | - if ( |
|
| 300 | - $boucle->primary |
|
| 301 | - and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | - and !in_array($t, $boucle->select) |
|
| 303 | - ) { |
|
| 304 | - $boucle->select[] = $t; |
|
| 305 | - } |
|
| 293 | + $boucle->total_parties = $pas; |
|
| 294 | + calculer_parties($boucles, $idb, $partie, 'p+'); |
|
| 295 | + // ajouter la cle primaire dans le select pour pouvoir gerer la pagination referencee par @id |
|
| 296 | + // sauf si pas de primaire, ou si primaire composee |
|
| 297 | + // dans ce cas, on ne sait pas gerer une pagination indirecte |
|
| 298 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 299 | + if ( |
|
| 300 | + $boucle->primary |
|
| 301 | + and !preg_match('/[,\s]/', $boucle->primary) |
|
| 302 | + and !in_array($t, $boucle->select) |
|
| 303 | + ) { |
|
| 304 | + $boucle->select[] = $t; |
|
| 305 | + } |
|
| 306 | 306 | } |
| 307 | 307 | |
| 308 | 308 | |
@@ -324,24 +324,24 @@ discard block |
||
| 324 | 324 | **/ |
| 325 | 325 | function critere_recherche_dist($idb, &$boucles, $crit) { |
| 326 | 326 | |
| 327 | - $boucle = &$boucles[$idb]; |
|
| 327 | + $boucle = &$boucles[$idb]; |
|
| 328 | 328 | |
| 329 | - if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | - erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 329 | + if (!$boucle->primary or strpos($boucle->primary, ',')) { |
|
| 330 | + erreur_squelette(_T('zbug_critere_sur_table_sans_cle_primaire', ['critere' => 'recherche']), $boucle); |
|
| 331 | 331 | |
| 332 | - return; |
|
| 333 | - } |
|
| 332 | + return; |
|
| 333 | + } |
|
| 334 | 334 | |
| 335 | - if (isset($crit->param[0])) { |
|
| 336 | - $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | - } else { |
|
| 338 | - $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | - } |
|
| 335 | + if (isset($crit->param[0])) { |
|
| 336 | + $quoi = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 337 | + } else { |
|
| 338 | + $quoi = '(isset($Pile[0]["recherche"])?$Pile[0]["recherche"]:(isset($GLOBALS["recherche"])?$GLOBALS["recherche"]:""))'; |
|
| 339 | + } |
|
| 340 | 340 | |
| 341 | - $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | - $boucle->hash .= ' |
|
| 341 | + $_modificateur = var_export($boucle->modificateur, true); |
|
| 342 | + $boucle->hash .= ' |
|
| 343 | 343 | // RECHERCHE' |
| 344 | - . ($crit->cond ? ' |
|
| 344 | + . ($crit->cond ? ' |
|
| 345 | 345 | if (!strlen(' . $quoi . ')){ |
| 346 | 346 | list($rech_select, $rech_where) = array("0 as points",""); |
| 347 | 347 | } else' : '') . ' |
@@ -352,21 +352,21 @@ discard block |
||
| 352 | 352 | '; |
| 353 | 353 | |
| 354 | 354 | |
| 355 | - $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | - $boucle->select[] = $t; |
|
| 358 | - } # pour postgres, neuneu ici |
|
| 359 | - // jointure uniquement sur le serveur principal |
|
| 360 | - // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | - if (!$boucle->sql_serveur) { |
|
| 362 | - $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | - $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | - } |
|
| 365 | - $boucle->select[] = '$rech_select'; |
|
| 366 | - //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | - |
|
| 368 | - // et la recherche trouve |
|
| 369 | - $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 355 | + $t = $boucle->id_table . '.' . $boucle->primary; |
|
| 356 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 357 | + $boucle->select[] = $t; |
|
| 358 | + } # pour postgres, neuneu ici |
|
| 359 | + // jointure uniquement sur le serveur principal |
|
| 360 | + // (on ne peut joindre une table d'un serveur distant avec la table des resultats du serveur principal) |
|
| 361 | + if (!$boucle->sql_serveur) { |
|
| 362 | + $boucle->join['resultats'] = ["'" . $boucle->id_table . "'", "'id'", "'" . $boucle->primary . "'"]; |
|
| 363 | + $boucle->from['resultats'] = 'spip_resultats'; |
|
| 364 | + } |
|
| 365 | + $boucle->select[] = '$rech_select'; |
|
| 366 | + //$boucle->where[]= "\$rech_where?'resultats.id=".$boucle->id_table.".".$boucle->primary."':''"; |
|
| 367 | + |
|
| 368 | + // et la recherche trouve |
|
| 369 | + $boucle->where[] = '$rech_where?$rech_where:\'\''; |
|
| 370 | 370 | } |
| 371 | 371 | |
| 372 | 372 | /** |
@@ -383,25 +383,25 @@ discard block |
||
| 383 | 383 | * @return void |
| 384 | 384 | **/ |
| 385 | 385 | function critere_traduction_dist($idb, &$boucles, $crit) { |
| 386 | - $boucle = &$boucles[$idb]; |
|
| 387 | - $prim = $boucle->primary; |
|
| 388 | - $table = $boucle->id_table; |
|
| 389 | - $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | - $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | - $boucle->where[] = |
|
| 392 | - [ |
|
| 393 | - "'OR'", |
|
| 394 | - [ |
|
| 395 | - "'AND'", |
|
| 396 | - ["'='", "'$table.id_trad'", 0], |
|
| 397 | - ["'='", "'$table.$prim'", $dprim] |
|
| 398 | - ], |
|
| 399 | - [ |
|
| 400 | - "'AND'", |
|
| 401 | - ["'>'", "'$table.id_trad'", 0], |
|
| 402 | - ["'='", "'$table.id_trad'", $arg] |
|
| 403 | - ] |
|
| 404 | - ]; |
|
| 386 | + $boucle = &$boucles[$idb]; |
|
| 387 | + $prim = $boucle->primary; |
|
| 388 | + $table = $boucle->id_table; |
|
| 389 | + $arg = kwote(calculer_argument_precedent($idb, 'id_trad', $boucles)); |
|
| 390 | + $dprim = kwote(calculer_argument_precedent($idb, $prim, $boucles)); |
|
| 391 | + $boucle->where[] = |
|
| 392 | + [ |
|
| 393 | + "'OR'", |
|
| 394 | + [ |
|
| 395 | + "'AND'", |
|
| 396 | + ["'='", "'$table.id_trad'", 0], |
|
| 397 | + ["'='", "'$table.$prim'", $dprim] |
|
| 398 | + ], |
|
| 399 | + [ |
|
| 400 | + "'AND'", |
|
| 401 | + ["'>'", "'$table.id_trad'", 0], |
|
| 402 | + ["'='", "'$table.id_trad'", $arg] |
|
| 403 | + ] |
|
| 404 | + ]; |
|
| 405 | 405 | } |
| 406 | 406 | |
| 407 | 407 | |
@@ -419,17 +419,17 @@ discard block |
||
| 419 | 419 | * @return void |
| 420 | 420 | **/ |
| 421 | 421 | function critere_origine_traduction_dist($idb, &$boucles, $crit) { |
| 422 | - $boucle = &$boucles[$idb]; |
|
| 423 | - $prim = $boucle->primary; |
|
| 424 | - $table = $boucle->id_table; |
|
| 425 | - |
|
| 426 | - $c = |
|
| 427 | - [ |
|
| 428 | - "'OR'", |
|
| 429 | - ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | - ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | - ]; |
|
| 432 | - $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 422 | + $boucle = &$boucles[$idb]; |
|
| 423 | + $prim = $boucle->primary; |
|
| 424 | + $table = $boucle->id_table; |
|
| 425 | + |
|
| 426 | + $c = |
|
| 427 | + [ |
|
| 428 | + "'OR'", |
|
| 429 | + ["'='", "'$table." . "id_trad'", "'$table.$prim'"], |
|
| 430 | + ["'='", "'$table.id_trad'", "'0'"] |
|
| 431 | + ]; |
|
| 432 | + $boucle->where[] = ($crit->not ? ["'NOT'", $c] : $c); |
|
| 433 | 433 | } |
| 434 | 434 | |
| 435 | 435 | |
@@ -446,17 +446,17 @@ discard block |
||
| 446 | 446 | **/ |
| 447 | 447 | function critere_meme_parent_dist($idb, &$boucles, $crit) { |
| 448 | 448 | |
| 449 | - $boucle = &$boucles[$idb]; |
|
| 450 | - $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | - $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | - |
|
| 454 | - if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | - $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | - } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | - else { |
|
| 458 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | - } |
|
| 449 | + $boucle = &$boucles[$idb]; |
|
| 450 | + $arg = kwote(calculer_argument_precedent($idb, 'id_parent', $boucles)); |
|
| 451 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 452 | + $mparent = $boucle->id_table . '.' . $id_parent; |
|
| 453 | + |
|
| 454 | + if ($boucle->type_requete == 'rubriques' or isset($GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'])) { |
|
| 455 | + $boucle->where[] = ["'='", "'$mparent'", $arg]; |
|
| 456 | + } // le cas FORUMS est gere dans le plugin forum, dans la fonction critere_FORUMS_meme_parent_dist() |
|
| 457 | + else { |
|
| 458 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $boucle->type_requete]]; |
|
| 459 | + } |
|
| 460 | 460 | } |
| 461 | 461 | |
| 462 | 462 | |
@@ -487,37 +487,37 @@ discard block |
||
| 487 | 487 | **/ |
| 488 | 488 | function critere_branche_dist($idb, &$boucles, $crit) { |
| 489 | 489 | |
| 490 | - $not = $crit->not; |
|
| 491 | - $boucle = &$boucles[$idb]; |
|
| 492 | - // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | - if (isset($crit->param[0])) { |
|
| 494 | - $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | - // sinon on le prend chez une boucle parente |
|
| 496 | - } else { |
|
| 497 | - $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | - } |
|
| 499 | - |
|
| 500 | - //Trouver une jointure |
|
| 501 | - $champ = 'id_rubrique'; |
|
| 502 | - $desc = $boucle->show; |
|
| 503 | - //Seulement si necessaire |
|
| 504 | - if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | - $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | - $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | - if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | - $decompose = decompose_champ_id_objet($champ); |
|
| 510 | - $champ = array_shift($decompose); |
|
| 511 | - $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | - } |
|
| 513 | - } else { |
|
| 514 | - $cle = $boucle->id_table; |
|
| 515 | - } |
|
| 516 | - |
|
| 517 | - $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | - . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | - $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | - ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 490 | + $not = $crit->not; |
|
| 491 | + $boucle = &$boucles[$idb]; |
|
| 492 | + // prendre en priorite un identifiant en parametre {branche XX} |
|
| 493 | + if (isset($crit->param[0])) { |
|
| 494 | + $arg = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 495 | + // sinon on le prend chez une boucle parente |
|
| 496 | + } else { |
|
| 497 | + $arg = kwote(calculer_argument_precedent($idb, 'id_rubrique', $boucles), $boucle->sql_serveur, 'int NOT NULL'); |
|
| 498 | + } |
|
| 499 | + |
|
| 500 | + //Trouver une jointure |
|
| 501 | + $champ = 'id_rubrique'; |
|
| 502 | + $desc = $boucle->show; |
|
| 503 | + //Seulement si necessaire |
|
| 504 | + if (!array_key_exists($champ, $desc['field'])) { |
|
| 505 | + $cle = trouver_jointure_champ($champ, $boucle); |
|
| 506 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 507 | + $desc = $trouver_table($boucle->from[$cle]); |
|
| 508 | + if (count(trouver_champs_decomposes($champ, $desc)) > 1) { |
|
| 509 | + $decompose = decompose_champ_id_objet($champ); |
|
| 510 | + $champ = array_shift($decompose); |
|
| 511 | + $boucle->where[] = ["'='", _q($cle . '.' . reset($decompose)), '"' . sql_quote(end($decompose)) . '"']; |
|
| 512 | + } |
|
| 513 | + } else { |
|
| 514 | + $cle = $boucle->id_table; |
|
| 515 | + } |
|
| 516 | + |
|
| 517 | + $c = "sql_in('$cle" . ".$champ', calcul_branche_in($arg)" |
|
| 518 | + . ($not ? ", 'NOT'" : '') . ')'; |
|
| 519 | + $boucle->where[] = !$crit->cond ? $c : |
|
| 520 | + ("($arg ? $c : " . ($not ? "'0=1'" : "'1=1'") . ')'); |
|
| 521 | 521 | } |
| 522 | 522 | |
| 523 | 523 | /** |
@@ -533,15 +533,15 @@ discard block |
||
| 533 | 533 | **/ |
| 534 | 534 | function critere_logo_dist($idb, &$boucles, $crit) { |
| 535 | 535 | |
| 536 | - $boucle = &$boucles[$idb]; |
|
| 537 | - $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | - $serveur = $boucle->sql_serveur; |
|
| 536 | + $boucle = &$boucles[$idb]; |
|
| 537 | + $not = ($crit->not ? 'NOT' : ''); |
|
| 538 | + $serveur = $boucle->sql_serveur; |
|
| 539 | 539 | |
| 540 | - $c = "sql_in('" . |
|
| 541 | - $boucle->id_table . '.' . $boucle->primary |
|
| 542 | - . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 540 | + $c = "sql_in('" . |
|
| 541 | + $boucle->id_table . '.' . $boucle->primary |
|
| 542 | + . "', lister_objets_avec_logos('" . $boucle->primary . "'), '$not', '$serveur')"; |
|
| 543 | 543 | |
| 544 | - $boucle->where[] = $c; |
|
| 544 | + $boucle->where[] = $c; |
|
| 545 | 545 | } |
| 546 | 546 | |
| 547 | 547 | |
@@ -563,31 +563,31 @@ discard block |
||
| 563 | 563 | * @return void|array |
| 564 | 564 | **/ |
| 565 | 565 | function critere_fusion_dist($idb, &$boucles, $crit) { |
| 566 | - if ($t = isset($crit->param[0])) { |
|
| 567 | - $t = $crit->param[0]; |
|
| 568 | - if ($t[0]->type == 'texte') { |
|
| 569 | - $t = $t[0]->texte; |
|
| 570 | - if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | - $t = table_objet_sql($r[1]); |
|
| 572 | - $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | - if ($t) { |
|
| 574 | - $t .= '.' . $r[2]; |
|
| 575 | - } |
|
| 576 | - } |
|
| 577 | - } else { |
|
| 578 | - $t = '".' |
|
| 579 | - . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | - . '."'; |
|
| 581 | - } |
|
| 582 | - } |
|
| 583 | - if ($t) { |
|
| 584 | - $boucles[$idb]->group[] = $t; |
|
| 585 | - if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | - $boucles[$idb]->select[] = $t; |
|
| 587 | - } |
|
| 588 | - } else { |
|
| 589 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | - } |
|
| 566 | + if ($t = isset($crit->param[0])) { |
|
| 567 | + $t = $crit->param[0]; |
|
| 568 | + if ($t[0]->type == 'texte') { |
|
| 569 | + $t = $t[0]->texte; |
|
| 570 | + if (preg_match('/^(.*)\.(.*)$/', $t, $r)) { |
|
| 571 | + $t = table_objet_sql($r[1]); |
|
| 572 | + $t = array_search($t, $boucles[$idb]->from); |
|
| 573 | + if ($t) { |
|
| 574 | + $t .= '.' . $r[2]; |
|
| 575 | + } |
|
| 576 | + } |
|
| 577 | + } else { |
|
| 578 | + $t = '".' |
|
| 579 | + . calculer_critere_arg_dynamique($idb, $boucles, $t) |
|
| 580 | + . '."'; |
|
| 581 | + } |
|
| 582 | + } |
|
| 583 | + if ($t) { |
|
| 584 | + $boucles[$idb]->group[] = $t; |
|
| 585 | + if (!in_array($t, $boucles[$idb]->select)) { |
|
| 586 | + $boucles[$idb]->select[] = $t; |
|
| 587 | + } |
|
| 588 | + } else { |
|
| 589 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 590 | + } |
|
| 591 | 591 | } |
| 592 | 592 | |
| 593 | 593 | /** |
@@ -607,7 +607,7 @@ discard block |
||
| 607 | 607 | * @return void |
| 608 | 608 | **/ |
| 609 | 609 | function critere_fusion_supprimer_dist($idb, &$boucles, $crit) { |
| 610 | - $boucles[$idb]->group = []; |
|
| 610 | + $boucles[$idb]->group = []; |
|
| 611 | 611 | } |
| 612 | 612 | |
| 613 | 613 | /** |
@@ -644,44 +644,44 @@ discard block |
||
| 644 | 644 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 645 | 645 | */ |
| 646 | 646 | function critere_collecte_dist($idb, &$boucles, $crit) { |
| 647 | - if (isset($crit->param[0])) { |
|
| 648 | - $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | - $boucle = $boucles[$idb]; |
|
| 650 | - $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | - if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | - // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | - // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | - if ( |
|
| 656 | - (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | - or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | - ) { |
|
| 659 | - $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | - } else { |
|
| 661 | - $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | - } |
|
| 663 | - } |
|
| 664 | - } else { |
|
| 665 | - return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | - } |
|
| 647 | + if (isset($crit->param[0])) { |
|
| 648 | + $_coll = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 649 | + $boucle = $boucles[$idb]; |
|
| 650 | + $boucle->modificateur['collate'] = "($_coll ?' COLLATE '.$_coll:'')"; |
|
| 651 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 652 | + if ($n && (strpos($boucle->order[$n - 1], 'COLLATE') === false)) { |
|
| 653 | + // l'instruction COLLATE doit être placée avant ASC ou DESC |
|
| 654 | + // notamment lors de l'utilisation `{!par xxx}{collate yyy}` |
|
| 655 | + if ( |
|
| 656 | + (false !== $i = strpos($boucle->order[$n - 1], 'ASC')) |
|
| 657 | + or (false !== $i = strpos($boucle->order[$n - 1], 'DESC')) |
|
| 658 | + ) { |
|
| 659 | + $boucle->order[$n - 1] = substr_replace($boucle->order[$n - 1], "' . " . $boucle->modificateur['collate'] . " . ' ", $i, 0); |
|
| 660 | + } else { |
|
| 661 | + $boucle->order[$n - 1] .= ' . ' . $boucle->modificateur['collate']; |
|
| 662 | + } |
|
| 663 | + } |
|
| 664 | + } else { |
|
| 665 | + return (['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . (is_countable($boucles[$idb]->order) ? count($boucles[$idb]->order) : 0)]]); |
|
| 666 | + } |
|
| 667 | 667 | } |
| 668 | 668 | |
| 669 | 669 | function calculer_critere_arg_dynamique($idb, &$boucles, $crit, $suffix = '') { |
| 670 | - $boucle = $boucles[$idb]; |
|
| 671 | - $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | - $var = '$champs_' . $idb; |
|
| 673 | - $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | - if (!$desc) { |
|
| 675 | - $desc = $boucle->show['field']; |
|
| 676 | - $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | - $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | - } |
|
| 679 | - if ($desc) { |
|
| 680 | - $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | - } |
|
| 682 | - $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | - |
|
| 684 | - return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 670 | + $boucle = $boucles[$idb]; |
|
| 671 | + $alt = "('" . $boucle->id_table . '.\' . $x' . $suffix . ')'; |
|
| 672 | + $var = '$champs_' . $idb; |
|
| 673 | + $desc = (strpos($boucle->in, (string) "static $var =") !== false); |
|
| 674 | + if (!$desc) { |
|
| 675 | + $desc = $boucle->show['field']; |
|
| 676 | + $desc = implode(',', array_map('_q', array_keys($desc))); |
|
| 677 | + $boucles[$idb]->in .= "\n\tstatic $var = array(" . $desc . ');'; |
|
| 678 | + } |
|
| 679 | + if ($desc) { |
|
| 680 | + $alt = "(in_array(\$x, $var) ? $alt :(\$x$suffix))"; |
|
| 681 | + } |
|
| 682 | + $arg = calculer_liste($crit, $idb, $boucles, $boucle->id_parent); |
|
| 683 | + |
|
| 684 | + return "((\$x = preg_replace(\"/\\W/\",'', $arg)) ? $alt : '')"; |
|
| 685 | 685 | } |
| 686 | 686 | |
| 687 | 687 | /** |
@@ -720,7 +720,7 @@ discard block |
||
| 720 | 720 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 721 | 721 | */ |
| 722 | 722 | function critere_par_dist($idb, &$boucles, $crit) { |
| 723 | - return critere_parinverse($idb, $boucles, $crit); |
|
| 723 | + return critere_parinverse($idb, $boucles, $crit); |
|
| 724 | 724 | } |
| 725 | 725 | |
| 726 | 726 | /** |
@@ -742,93 +742,93 @@ discard block |
||
| 742 | 742 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 743 | 743 | */ |
| 744 | 744 | function critere_parinverse($idb, &$boucles, $crit) { |
| 745 | - $boucle = &$boucles[$idb]; |
|
| 746 | - |
|
| 747 | - $sens = $collecte = ''; |
|
| 748 | - if ($crit->not) { |
|
| 749 | - $sens = " . ' DESC'"; |
|
| 750 | - } |
|
| 751 | - if (isset($boucle->modificateur['collate'])) { |
|
| 752 | - $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | - } |
|
| 754 | - |
|
| 755 | - // Pour chaque paramètre du critère |
|
| 756 | - foreach ($crit->param as $tri) { |
|
| 757 | - $order = $fct = ''; |
|
| 758 | - // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | - if ($tri[0]->type != 'texte') { |
|
| 760 | - // calculer le order dynamique qui verifie les champs |
|
| 761 | - $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | - // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | - calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | - } |
|
| 765 | - // tris textuels {par titre} |
|
| 766 | - else { |
|
| 767 | - $par = array_shift($tri); |
|
| 768 | - $par = $par->texte; |
|
| 769 | - |
|
| 770 | - // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | - if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | - $expression = trim($m[1]); |
|
| 773 | - $champ = trim($m[2]); |
|
| 774 | - if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | - $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | - } else { |
|
| 777 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | - } |
|
| 779 | - |
|
| 780 | - // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | - } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | - // {par FONCTION(champ)} |
|
| 783 | - if (isset($match) and count($match) > 2) { |
|
| 784 | - $par = substr($match[2], 1, -1); |
|
| 785 | - $fct = $match[1]; |
|
| 786 | - } |
|
| 787 | - // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | - if ($par == 'hasard') { |
|
| 789 | - $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | - } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | - $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | - } else { |
|
| 793 | - // cas général {par champ}, {par table.champ}, ... |
|
| 794 | - $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | - } |
|
| 796 | - } |
|
| 797 | - |
|
| 798 | - // on ne sait pas traiter… |
|
| 799 | - else { |
|
| 800 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | - } |
|
| 802 | - |
|
| 803 | - // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | - if (is_array($order)) { |
|
| 805 | - return $order; |
|
| 806 | - } |
|
| 807 | - } |
|
| 808 | - |
|
| 809 | - if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | - $t = $m[1]; |
|
| 811 | - if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | - $boucle->select[] = $t; |
|
| 813 | - } |
|
| 814 | - } else { |
|
| 815 | - $sens = ''; |
|
| 816 | - } |
|
| 817 | - |
|
| 818 | - if ($fct) { |
|
| 819 | - if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | - $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | - } else { |
|
| 822 | - $order = "'$fct(' . $order . ')'"; |
|
| 823 | - } |
|
| 824 | - } |
|
| 825 | - $t = $order . $collecte . $sens; |
|
| 826 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | - $t = $r[1] . $r[2]; |
|
| 828 | - } |
|
| 829 | - |
|
| 830 | - $boucle->order[] = $t; |
|
| 831 | - } |
|
| 745 | + $boucle = &$boucles[$idb]; |
|
| 746 | + |
|
| 747 | + $sens = $collecte = ''; |
|
| 748 | + if ($crit->not) { |
|
| 749 | + $sens = " . ' DESC'"; |
|
| 750 | + } |
|
| 751 | + if (isset($boucle->modificateur['collate'])) { |
|
| 752 | + $collecte = ' . ' . $boucle->modificateur['collate']; |
|
| 753 | + } |
|
| 754 | + |
|
| 755 | + // Pour chaque paramètre du critère |
|
| 756 | + foreach ($crit->param as $tri) { |
|
| 757 | + $order = $fct = ''; |
|
| 758 | + // tris specifiés dynamiquement {par #ENV{tri}} |
|
| 759 | + if ($tri[0]->type != 'texte') { |
|
| 760 | + // calculer le order dynamique qui verifie les champs |
|
| 761 | + $order = calculer_critere_arg_dynamique($idb, $boucles, $tri, $sens); |
|
| 762 | + // ajouter 'hasard' comme possibilité de tri dynamique |
|
| 763 | + calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 764 | + } |
|
| 765 | + // tris textuels {par titre} |
|
| 766 | + else { |
|
| 767 | + $par = array_shift($tri); |
|
| 768 | + $par = $par->texte; |
|
| 769 | + |
|
| 770 | + // tris de la forme {par expression champ} tel que {par num titre} ou {par multi titre} |
|
| 771 | + if (preg_match(',^(\w+)[\s]+(.*)$,', $par, $m)) { |
|
| 772 | + $expression = trim($m[1]); |
|
| 773 | + $champ = trim($m[2]); |
|
| 774 | + if (function_exists($f = 'calculer_critere_par_expression_' . $expression)) { |
|
| 775 | + $order = $f($idb, $boucles, $crit, $tri, $champ); |
|
| 776 | + } else { |
|
| 777 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 778 | + } |
|
| 779 | + |
|
| 780 | + // tris de la forme {par champ} ou {par FONCTION(champ)} |
|
| 781 | + } elseif ($boucle->type_requete == 'DATA' or preg_match(',^' . CHAMP_SQL_PLUS_FONC . '$,is', $par, $match)) { |
|
| 782 | + // {par FONCTION(champ)} |
|
| 783 | + if (isset($match) and count($match) > 2) { |
|
| 784 | + $par = substr($match[2], 1, -1); |
|
| 785 | + $fct = $match[1]; |
|
| 786 | + } |
|
| 787 | + // quelques cas spécifiques {par hasard}, {par date} |
|
| 788 | + if ($par == 'hasard') { |
|
| 789 | + $order = calculer_critere_par_hasard($idb, $boucles, $crit); |
|
| 790 | + } elseif ($par == 'date' and !empty($boucle->show['date'])) { |
|
| 791 | + $order = "'" . $boucle->id_table . '.' . $boucle->show['date'] . "'"; |
|
| 792 | + } else { |
|
| 793 | + // cas général {par champ}, {par table.champ}, ... |
|
| 794 | + $order = calculer_critere_par_champ($idb, $boucles, $crit, $par); |
|
| 795 | + } |
|
| 796 | + } |
|
| 797 | + |
|
| 798 | + // on ne sait pas traiter… |
|
| 799 | + else { |
|
| 800 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 801 | + } |
|
| 802 | + |
|
| 803 | + // En cas d'erreur de squelette retournée par une fonction |
|
| 804 | + if (is_array($order)) { |
|
| 805 | + return $order; |
|
| 806 | + } |
|
| 807 | + } |
|
| 808 | + |
|
| 809 | + if (preg_match('/^\'([^"]*)\'$/', $order, $m)) { |
|
| 810 | + $t = $m[1]; |
|
| 811 | + if (strpos($t, '.') and !in_array($t, $boucle->select)) { |
|
| 812 | + $boucle->select[] = $t; |
|
| 813 | + } |
|
| 814 | + } else { |
|
| 815 | + $sens = ''; |
|
| 816 | + } |
|
| 817 | + |
|
| 818 | + if ($fct) { |
|
| 819 | + if (preg_match("/^\s*'(.*)'\s*$/", $order, $r)) { |
|
| 820 | + $order = "'$fct(" . $r[1] . ")'"; |
|
| 821 | + } else { |
|
| 822 | + $order = "'$fct(' . $order . ')'"; |
|
| 823 | + } |
|
| 824 | + } |
|
| 825 | + $t = $order . $collecte . $sens; |
|
| 826 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 827 | + $t = $r[1] . $r[2]; |
|
| 828 | + } |
|
| 829 | + |
|
| 830 | + $boucle->order[] = $t; |
|
| 831 | + } |
|
| 832 | 832 | } |
| 833 | 833 | |
| 834 | 834 | /** |
@@ -842,13 +842,13 @@ discard block |
||
| 842 | 842 | * @return string Clause pour le Order by |
| 843 | 843 | */ |
| 844 | 844 | function calculer_critere_par_hasard($idb, &$boucles, $crit) { |
| 845 | - $boucle = &$boucles[$idb]; |
|
| 846 | - // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | - $parha = 'rand() AS hasard'; |
|
| 848 | - if (!in_array($parha, $boucle->select)) { |
|
| 849 | - $boucle->select[] = $parha; |
|
| 850 | - } |
|
| 851 | - return "'hasard'"; |
|
| 845 | + $boucle = &$boucles[$idb]; |
|
| 846 | + // Si ce n'est fait, ajouter un champ 'hasard' dans le select |
|
| 847 | + $parha = 'rand() AS hasard'; |
|
| 848 | + if (!in_array($parha, $boucle->select)) { |
|
| 849 | + $boucle->select[] = $parha; |
|
| 850 | + } |
|
| 851 | + return "'hasard'"; |
|
| 852 | 852 | } |
| 853 | 853 | |
| 854 | 854 | /** |
@@ -872,24 +872,24 @@ discard block |
||
| 872 | 872 | * @return string|array Clause pour le Order by (array si erreur) |
| 873 | 873 | */ |
| 874 | 874 | function calculer_critere_par_expression_num($idb, &$boucles, $crit, $tri, $champ) { |
| 875 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | - if (is_array($_champ)) { |
|
| 877 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | - } |
|
| 879 | - $boucle = &$boucles[$idb]; |
|
| 880 | - $texte = '0+' . $_champ; |
|
| 881 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | - if ($suite !== "''") { |
|
| 883 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | - } |
|
| 885 | - $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | - $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | - |
|
| 888 | - $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | - $orderassinum = trim($orderassinum, "'"); |
|
| 890 | - |
|
| 891 | - $order = "'$orderassinum, $asnum'"; |
|
| 892 | - return $order; |
|
| 875 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 876 | + if (is_array($_champ)) { |
|
| 877 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " num $champ"]]; |
|
| 878 | + } |
|
| 879 | + $boucle = &$boucles[$idb]; |
|
| 880 | + $texte = '0+' . $_champ; |
|
| 881 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 882 | + if ($suite !== "''") { |
|
| 883 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 884 | + } |
|
| 885 | + $asnum = 'num' . ($boucle->order ? count($boucle->order) : ''); |
|
| 886 | + $boucle->select[] = $texte . " AS $asnum"; |
|
| 887 | + |
|
| 888 | + $orderassinum = calculer_critere_par_expression_sinum($idb, $boucles, $crit, $tri, $champ); |
|
| 889 | + $orderassinum = trim($orderassinum, "'"); |
|
| 890 | + |
|
| 891 | + $order = "'$orderassinum, $asnum'"; |
|
| 892 | + return $order; |
|
| 893 | 893 | } |
| 894 | 894 | |
| 895 | 895 | /** |
@@ -910,35 +910,35 @@ discard block |
||
| 910 | 910 | * @return string|array Clause pour le Order by (array si erreur) |
| 911 | 911 | */ |
| 912 | 912 | function calculer_critere_par_expression_sinum($idb, &$boucles, $crit, $tri, $champ) { |
| 913 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | - if (is_array($_champ)) { |
|
| 915 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | - } |
|
| 917 | - $boucle = &$boucles[$idb]; |
|
| 918 | - $texte = '0+' . $_champ; |
|
| 919 | - $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | - if ($suite !== "''") { |
|
| 921 | - $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | - } |
|
| 923 | - |
|
| 924 | - $as = false; |
|
| 925 | - $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | - foreach ($boucle->select as $s) { |
|
| 927 | - if (strpos($s, $select) === 0) { |
|
| 928 | - $as = trim(substr($s, strlen($select))); |
|
| 929 | - if (!preg_match(',\W,', $as)) { |
|
| 930 | - break; |
|
| 931 | - } |
|
| 932 | - $as = false; |
|
| 933 | - } |
|
| 934 | - } |
|
| 935 | - |
|
| 936 | - if (!$as) { |
|
| 937 | - $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | - $boucle->select[] = $select . $as; |
|
| 939 | - } |
|
| 940 | - $order = "'$as'"; |
|
| 941 | - return $order; |
|
| 913 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 914 | + if (is_array($_champ)) { |
|
| 915 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " sinum $champ"]]; |
|
| 916 | + } |
|
| 917 | + $boucle = &$boucles[$idb]; |
|
| 918 | + $texte = '0+' . $_champ; |
|
| 919 | + $suite = calculer_liste($tri, $idb, $boucles, $boucle->id_parent); |
|
| 920 | + if ($suite !== "''") { |
|
| 921 | + $texte = "\" . ((\$x = $suite) ? ('$texte' . \$x) : '0')" . ' . "'; |
|
| 922 | + } |
|
| 923 | + |
|
| 924 | + $as = false; |
|
| 925 | + $select = "CASE ( $texte ) WHEN 0 THEN 1 ELSE 0 END AS "; |
|
| 926 | + foreach ($boucle->select as $s) { |
|
| 927 | + if (strpos($s, $select) === 0) { |
|
| 928 | + $as = trim(substr($s, strlen($select))); |
|
| 929 | + if (!preg_match(',\W,', $as)) { |
|
| 930 | + break; |
|
| 931 | + } |
|
| 932 | + $as = false; |
|
| 933 | + } |
|
| 934 | + } |
|
| 935 | + |
|
| 936 | + if (!$as) { |
|
| 937 | + $as = 'sinum' . ($boucle->order ? count($boucle->order) : ''); |
|
| 938 | + $boucle->select[] = $select . $as; |
|
| 939 | + } |
|
| 940 | + $order = "'$as'"; |
|
| 941 | + return $order; |
|
| 942 | 942 | } |
| 943 | 943 | |
| 944 | 944 | |
@@ -958,14 +958,14 @@ discard block |
||
| 958 | 958 | * @return string|array Clause pour le Order by (array si erreur) |
| 959 | 959 | */ |
| 960 | 960 | function calculer_critere_par_expression_multi($idb, &$boucles, $crit, $tri, $champ) { |
| 961 | - $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | - if (is_array($_champ)) { |
|
| 963 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | - } |
|
| 965 | - $boucle = &$boucles[$idb]; |
|
| 966 | - $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | - $order = "'multi'"; |
|
| 968 | - return $order; |
|
| 961 | + $_champ = calculer_critere_par_champ($idb, $boucles, $crit, $champ, true); |
|
| 962 | + if (is_array($_champ)) { |
|
| 963 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " multi $champ"]]; |
|
| 964 | + } |
|
| 965 | + $boucle = &$boucles[$idb]; |
|
| 966 | + $boucle->select[] = "\".sql_multi('" . $_champ . "', \$GLOBALS['spip_lang']).\""; |
|
| 967 | + $order = "'multi'"; |
|
| 968 | + return $order; |
|
| 969 | 969 | } |
| 970 | 970 | |
| 971 | 971 | /** |
@@ -984,56 +984,56 @@ discard block |
||
| 984 | 984 | * @return array|string |
| 985 | 985 | */ |
| 986 | 986 | function calculer_critere_par_champ($idb, &$boucles, $crit, $par, $raw = false) { |
| 987 | - $boucle = &$boucles[$idb]; |
|
| 988 | - $desc = $boucle->show; |
|
| 989 | - |
|
| 990 | - // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | - if (isset($desc['field'][$par])) { |
|
| 992 | - $par = $boucle->id_table . '.' . $par; |
|
| 993 | - } |
|
| 994 | - // le champ est peut être une jointure |
|
| 995 | - else { |
|
| 996 | - $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | - $champ = $par; |
|
| 998 | - |
|
| 999 | - // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | - if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | - [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | - } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | - elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | - [, $table, $champ] = $r; |
|
| 1005 | - $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | - $table = table_objet_sql($table); |
|
| 1007 | - } |
|
| 1008 | - |
|
| 1009 | - // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | - // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | - // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | - if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | - } elseif ( |
|
| 1015 | - $boucle->jointures_explicites |
|
| 1016 | - and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | - ) { |
|
| 1018 | - $par = $alias . '.' . $champ; |
|
| 1019 | - } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | - $par = $alias . '.' . $champ; |
|
| 1021 | - // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | - } elseif ( |
|
| 1023 | - $table_alias |
|
| 1024 | - and isset($boucle->from[$table_alias]) |
|
| 1025 | - and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | - ) { |
|
| 1027 | - $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | - } elseif ($table) { |
|
| 1029 | - // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | - } else { |
|
| 1032 | - // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | - } |
|
| 1034 | - } |
|
| 1035 | - |
|
| 1036 | - return $raw ? $par : "'$par'"; |
|
| 987 | + $boucle = &$boucles[$idb]; |
|
| 988 | + $desc = $boucle->show; |
|
| 989 | + |
|
| 990 | + // le champ existe dans la table, pas de souci (le plus commun) |
|
| 991 | + if (isset($desc['field'][$par])) { |
|
| 992 | + $par = $boucle->id_table . '.' . $par; |
|
| 993 | + } |
|
| 994 | + // le champ est peut être une jointure |
|
| 995 | + else { |
|
| 996 | + $table = $table_alias = false; // toutes les tables de jointure possibles |
|
| 997 | + $champ = $par; |
|
| 998 | + |
|
| 999 | + // le champ demandé est une exception de jointure {par titre_mot} |
|
| 1000 | + if (isset($GLOBALS['exceptions_des_jointures'][$par])) { |
|
| 1001 | + [$table, $champ] = $GLOBALS['exceptions_des_jointures'][$par]; |
|
| 1002 | + } // la table de jointure est explicitement indiquée {par truc.muche} |
|
| 1003 | + elseif (preg_match('/^([^,]*)\.(.*)$/', $par, $r)) { |
|
| 1004 | + [, $table, $champ] = $r; |
|
| 1005 | + $table_alias = $table; // c'est peut-être un alias de table {par L1.titre} |
|
| 1006 | + $table = table_objet_sql($table); |
|
| 1007 | + } |
|
| 1008 | + |
|
| 1009 | + // Si on connait la table d'arrivée, on la demande donc explicitement |
|
| 1010 | + // Sinon on cherche le champ dans les tables possibles de jointures |
|
| 1011 | + // Si la table est déjà dans le from, on la réutilise. |
|
| 1012 | + if ($infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $table)) { |
|
| 1013 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1014 | + } elseif ( |
|
| 1015 | + $boucle->jointures_explicites |
|
| 1016 | + and $alias = trouver_jointure_champ($champ, $boucle, explode(' ', $boucle->jointures_explicites), false, $table) |
|
| 1017 | + ) { |
|
| 1018 | + $par = $alias . '.' . $champ; |
|
| 1019 | + } elseif ($alias = trouver_jointure_champ($champ, $boucle, $boucle->jointures, false, $table)) { |
|
| 1020 | + $par = $alias . '.' . $champ; |
|
| 1021 | + // en spécifiant directement l'alias {par L2.titre} (situation hasardeuse tout de même) |
|
| 1022 | + } elseif ( |
|
| 1023 | + $table_alias |
|
| 1024 | + and isset($boucle->from[$table_alias]) |
|
| 1025 | + and $infos = chercher_champ_dans_tables($champ, $boucle->from, $boucle->sql_serveur, $boucle->from[$table_alias]) |
|
| 1026 | + ) { |
|
| 1027 | + $par = $infos['alias'] . '.' . $champ; |
|
| 1028 | + } elseif ($table) { |
|
| 1029 | + // On avait table + champ, mais on ne les a pas trouvés |
|
| 1030 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . " $par"]]; |
|
| 1031 | + } else { |
|
| 1032 | + // Sinon tant pis, ca doit etre un champ synthetise (cf points) |
|
| 1033 | + } |
|
| 1034 | + } |
|
| 1035 | + |
|
| 1036 | + return $raw ? $par : "'$par'"; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | |
| 1039 | 1039 | /** |
@@ -1047,11 +1047,11 @@ discard block |
||
| 1047 | 1047 | * @return string Champ pour le compilateur si trouvé, tel que "'alias.champ'", sinon vide. |
| 1048 | 1048 | */ |
| 1049 | 1049 | function critere_par_joint($table, $champ, &$boucle) { |
| 1050 | - $t = array_search($table, $boucle->from); |
|
| 1051 | - if (!$t) { |
|
| 1052 | - $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | - } |
|
| 1054 | - return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1050 | + $t = array_search($table, $boucle->from); |
|
| 1051 | + if (!$t) { |
|
| 1052 | + $t = trouver_jointure_champ($champ, $boucle); |
|
| 1053 | + } |
|
| 1054 | + return !$t ? '' : ("'" . $t . '.' . $champ . "'"); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | |
| 1057 | 1057 | /** |
@@ -1076,33 +1076,33 @@ discard block |
||
| 1076 | 1076 | */ |
| 1077 | 1077 | function critere_inverse_dist($idb, &$boucles, $crit) { |
| 1078 | 1078 | |
| 1079 | - $boucle = &$boucles[$idb]; |
|
| 1080 | - // Classement par ordre inverse |
|
| 1081 | - if ($crit->not) { |
|
| 1082 | - critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | - } else { |
|
| 1084 | - $order = "' DESC'"; |
|
| 1085 | - // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | - if (isset($crit->param[0])) { |
|
| 1087 | - $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | - $order = "(($critere)?' DESC':'')"; |
|
| 1089 | - } |
|
| 1090 | - |
|
| 1091 | - $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | - if (!$n) { |
|
| 1093 | - if (isset($boucle->default_order[0])) { |
|
| 1094 | - $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | - } else { |
|
| 1096 | - $boucle->default_order[] = ' DESC'; |
|
| 1097 | - } |
|
| 1098 | - } else { |
|
| 1099 | - $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | - if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | - $t = $r[1] . $r[2]; |
|
| 1102 | - } |
|
| 1103 | - $boucle->order[$n - 1] = $t; |
|
| 1104 | - } |
|
| 1105 | - } |
|
| 1079 | + $boucle = &$boucles[$idb]; |
|
| 1080 | + // Classement par ordre inverse |
|
| 1081 | + if ($crit->not) { |
|
| 1082 | + critere_parinverse($idb, $boucles, $crit); |
|
| 1083 | + } else { |
|
| 1084 | + $order = "' DESC'"; |
|
| 1085 | + // Classement par ordre inverse fonction eventuelle de #ENV{...} |
|
| 1086 | + if (isset($crit->param[0])) { |
|
| 1087 | + $critere = calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1088 | + $order = "(($critere)?' DESC':'')"; |
|
| 1089 | + } |
|
| 1090 | + |
|
| 1091 | + $n = is_countable($boucle->order) ? count($boucle->order) : 0; |
|
| 1092 | + if (!$n) { |
|
| 1093 | + if (isset($boucle->default_order[0])) { |
|
| 1094 | + $boucle->default_order[0] .= ' . " DESC"'; |
|
| 1095 | + } else { |
|
| 1096 | + $boucle->default_order[] = ' DESC'; |
|
| 1097 | + } |
|
| 1098 | + } else { |
|
| 1099 | + $t = $boucle->order[$n - 1] . " . $order"; |
|
| 1100 | + if (preg_match("/^(.*)'\s*\.\s*'([^']*')$/", $t, $r)) { |
|
| 1101 | + $t = $r[1] . $r[2]; |
|
| 1102 | + } |
|
| 1103 | + $boucle->order[$n - 1] = $t; |
|
| 1104 | + } |
|
| 1105 | + } |
|
| 1106 | 1106 | } |
| 1107 | 1107 | |
| 1108 | 1108 | /** |
@@ -1113,137 +1113,137 @@ discard block |
||
| 1113 | 1113 | * @return void|array |
| 1114 | 1114 | */ |
| 1115 | 1115 | function critere_par_ordre_liste_dist($idb, &$boucles, $crit) { |
| 1116 | - $boucle = &$boucles[$idb]; |
|
| 1116 | + $boucle = &$boucles[$idb]; |
|
| 1117 | 1117 | |
| 1118 | - $sens = $collecte = ''; |
|
| 1119 | - if ($crit->not) { |
|
| 1120 | - $sens = " . ' DESC'"; |
|
| 1121 | - } |
|
| 1118 | + $sens = $collecte = ''; |
|
| 1119 | + if ($crit->not) { |
|
| 1120 | + $sens = " . ' DESC'"; |
|
| 1121 | + } |
|
| 1122 | 1122 | |
| 1123 | - $crit2 = clone $crit; |
|
| 1124 | - $crit2->not = false; |
|
| 1125 | - $crit2->param = [reset($crit->param)]; |
|
| 1126 | - $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1123 | + $crit2 = clone $crit; |
|
| 1124 | + $crit2->not = false; |
|
| 1125 | + $crit2->param = [reset($crit->param)]; |
|
| 1126 | + $res = critere_parinverse($idb, $boucles, $crit2); |
|
| 1127 | 1127 | |
| 1128 | - // erreur ? |
|
| 1129 | - if (is_array($res)) { |
|
| 1130 | - return $res; |
|
| 1131 | - } |
|
| 1128 | + // erreur ? |
|
| 1129 | + if (is_array($res)) { |
|
| 1130 | + return $res; |
|
| 1131 | + } |
|
| 1132 | 1132 | |
| 1133 | - $_order = array_pop($boucle->order); |
|
| 1133 | + $_order = array_pop($boucle->order); |
|
| 1134 | 1134 | |
| 1135 | - $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | - $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1135 | + $_liste = calculer_liste($crit->param[1], [], $boucles, $boucles[$idb]->id_parent); |
|
| 1136 | + $boucle->order[] = "'FIELD(' . $_order . ',' . ((\$zl=formate_liste_critere_par_ordre_liste($_liste,'" . $boucle->sql_serveur . "')) ? \$zl : '0').')'$sens"; |
|
| 1137 | 1137 | } |
| 1138 | 1138 | |
| 1139 | 1139 | |
| 1140 | 1140 | function critere_agenda_dist($idb, &$boucles, $crit) { |
| 1141 | - $params = $crit->param; |
|
| 1142 | - |
|
| 1143 | - if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | - } |
|
| 1146 | - |
|
| 1147 | - $boucle = &$boucles[$idb]; |
|
| 1148 | - $parent = $boucle->id_parent; |
|
| 1149 | - $fields = $boucle->show['field']; |
|
| 1150 | - |
|
| 1151 | - $date = array_shift($params); |
|
| 1152 | - $type = array_shift($params); |
|
| 1153 | - |
|
| 1154 | - // la valeur $type doit etre connue a la compilation |
|
| 1155 | - // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | - $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | - |
|
| 1158 | - // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | - // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | - // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | - // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | - if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | - $date = $date[0]->texte; |
|
| 1164 | - if (!isset($fields[$date])) { |
|
| 1165 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | - } |
|
| 1167 | - } else { |
|
| 1168 | - $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | - $noms = array_keys($fields); |
|
| 1170 | - $defaut = $noms[0]; |
|
| 1171 | - $noms = join(' ', $noms); |
|
| 1172 | - # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | - $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | - $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | - } |
|
| 1176 | - $annee = $params ? array_shift($params) : ''; |
|
| 1177 | - $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | - calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | - ') ? $x : date("Y"))'; |
|
| 1180 | - |
|
| 1181 | - $mois = $params ? array_shift($params) : ''; |
|
| 1182 | - $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | - calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | - ') ? $x : date("m"))'; |
|
| 1185 | - |
|
| 1186 | - $jour = $params ? array_shift($params) : ''; |
|
| 1187 | - $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | - calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | - ') ? $x : date("d"))'; |
|
| 1190 | - |
|
| 1191 | - $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | - $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | - calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | - ') ? $x : date("Y"))'; |
|
| 1195 | - |
|
| 1196 | - $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | - $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | - calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | - ') ? $x : date("m"))'; |
|
| 1200 | - |
|
| 1201 | - $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | - $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | - calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | - ') ? $x : date("d"))'; |
|
| 1205 | - |
|
| 1206 | - $date = $boucle->id_table . ".$date"; |
|
| 1207 | - |
|
| 1208 | - $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | - if ($type == 'jour') { |
|
| 1210 | - $boucle->where[] = [ |
|
| 1211 | - "'='", |
|
| 1212 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | - ]; |
|
| 1215 | - } elseif ($type == 'mois') { |
|
| 1216 | - $boucle->where[] = [ |
|
| 1217 | - "'='", |
|
| 1218 | - "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | - ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | - ]; |
|
| 1221 | - } elseif ($type == 'semaine') { |
|
| 1222 | - $boucle->where[] = [ |
|
| 1223 | - "'AND'", |
|
| 1224 | - [ |
|
| 1225 | - "'>='", |
|
| 1226 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | - ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | - ], |
|
| 1229 | - [ |
|
| 1230 | - "'<='", |
|
| 1231 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | - ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | - ] |
|
| 1234 | - ]; |
|
| 1235 | - } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | - $boucle->where[] = [ |
|
| 1237 | - "'AND'", |
|
| 1238 | - [ |
|
| 1239 | - "'>='", |
|
| 1240 | - "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | - ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | - ], |
|
| 1243 | - ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | - ]; |
|
| 1245 | - } |
|
| 1246 | - // sinon on prend tout |
|
| 1141 | + $params = $crit->param; |
|
| 1142 | + |
|
| 1143 | + if ((is_countable($params) ? count($params) : 0) < 1) { |
|
| 1144 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1145 | + } |
|
| 1146 | + |
|
| 1147 | + $boucle = &$boucles[$idb]; |
|
| 1148 | + $parent = $boucle->id_parent; |
|
| 1149 | + $fields = $boucle->show['field']; |
|
| 1150 | + |
|
| 1151 | + $date = array_shift($params); |
|
| 1152 | + $type = array_shift($params); |
|
| 1153 | + |
|
| 1154 | + // la valeur $type doit etre connue a la compilation |
|
| 1155 | + // donc etre forcement reduite a un litteral unique dans le source |
|
| 1156 | + $type = is_object($type[0]) ? $type[0]->texte : null; |
|
| 1157 | + |
|
| 1158 | + // La valeur date doit designer un champ de la table SQL. |
|
| 1159 | + // Si c'est un litteral unique dans le source, verifier a la compil, |
|
| 1160 | + // sinon synthetiser le test de verif pour execution ulterieure |
|
| 1161 | + // On prendra arbitrairement le premier champ si test negatif. |
|
| 1162 | + if (((is_countable($date) ? count($date) : 0) == 1) and ($date[0]->type == 'texte')) { |
|
| 1163 | + $date = $date[0]->texte; |
|
| 1164 | + if (!isset($fields[$date])) { |
|
| 1165 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ' . $date]]; |
|
| 1166 | + } |
|
| 1167 | + } else { |
|
| 1168 | + $a = calculer_liste($date, $idb, $boucles, $parent); |
|
| 1169 | + $noms = array_keys($fields); |
|
| 1170 | + $defaut = $noms[0]; |
|
| 1171 | + $noms = join(' ', $noms); |
|
| 1172 | + # bien laisser 2 espaces avant $nom pour que strpos<>0 |
|
| 1173 | + $cond = "(\$a=strval($a))AND\nstrpos(\" $noms \",\" \$a \")"; |
|
| 1174 | + $date = "'.(($cond)\n?\$a:\"$defaut\").'"; |
|
| 1175 | + } |
|
| 1176 | + $annee = $params ? array_shift($params) : ''; |
|
| 1177 | + $annee = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1178 | + calculer_liste($annee, $idb, $boucles, $parent) . |
|
| 1179 | + ') ? $x : date("Y"))'; |
|
| 1180 | + |
|
| 1181 | + $mois = $params ? array_shift($params) : ''; |
|
| 1182 | + $mois = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1183 | + calculer_liste($mois, $idb, $boucles, $parent) . |
|
| 1184 | + ') ? $x : date("m"))'; |
|
| 1185 | + |
|
| 1186 | + $jour = $params ? array_shift($params) : ''; |
|
| 1187 | + $jour = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1188 | + calculer_liste($jour, $idb, $boucles, $parent) . |
|
| 1189 | + ') ? $x : date("d"))'; |
|
| 1190 | + |
|
| 1191 | + $annee2 = $params ? array_shift($params) : ''; |
|
| 1192 | + $annee2 = "\n" . 'sprintf("%04d", ($x = ' . |
|
| 1193 | + calculer_liste($annee2, $idb, $boucles, $parent) . |
|
| 1194 | + ') ? $x : date("Y"))'; |
|
| 1195 | + |
|
| 1196 | + $mois2 = $params ? array_shift($params) : ''; |
|
| 1197 | + $mois2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1198 | + calculer_liste($mois2, $idb, $boucles, $parent) . |
|
| 1199 | + ') ? $x : date("m"))'; |
|
| 1200 | + |
|
| 1201 | + $jour2 = $params ? array_shift($params) : ''; |
|
| 1202 | + $jour2 = "\n" . 'sprintf("%02d", ($x = ' . |
|
| 1203 | + calculer_liste($jour2, $idb, $boucles, $parent) . |
|
| 1204 | + ') ? $x : date("d"))'; |
|
| 1205 | + |
|
| 1206 | + $date = $boucle->id_table . ".$date"; |
|
| 1207 | + |
|
| 1208 | + $quote_end = ",'" . $boucle->sql_serveur . "','text'"; |
|
| 1209 | + if ($type == 'jour') { |
|
| 1210 | + $boucle->where[] = [ |
|
| 1211 | + "'='", |
|
| 1212 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1213 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1214 | + ]; |
|
| 1215 | + } elseif ($type == 'mois') { |
|
| 1216 | + $boucle->where[] = [ |
|
| 1217 | + "'='", |
|
| 1218 | + "'DATE_FORMAT($date, \'%Y%m\')'", |
|
| 1219 | + ("sql_quote($annee . $mois$quote_end)") |
|
| 1220 | + ]; |
|
| 1221 | + } elseif ($type == 'semaine') { |
|
| 1222 | + $boucle->where[] = [ |
|
| 1223 | + "'AND'", |
|
| 1224 | + [ |
|
| 1225 | + "'>='", |
|
| 1226 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1227 | + ("date_debut_semaine($annee, $mois, $jour)") |
|
| 1228 | + ], |
|
| 1229 | + [ |
|
| 1230 | + "'<='", |
|
| 1231 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1232 | + ("date_fin_semaine($annee, $mois, $jour)") |
|
| 1233 | + ] |
|
| 1234 | + ]; |
|
| 1235 | + } elseif ((is_countable($crit->param) ? count($crit->param) : 0) > 2) { |
|
| 1236 | + $boucle->where[] = [ |
|
| 1237 | + "'AND'", |
|
| 1238 | + [ |
|
| 1239 | + "'>='", |
|
| 1240 | + "'DATE_FORMAT($date, \'%Y%m%d\')'", |
|
| 1241 | + ("sql_quote($annee . $mois . $jour$quote_end)") |
|
| 1242 | + ], |
|
| 1243 | + ["'<='", "'DATE_FORMAT($date, \'%Y%m%d\')'", ("sql_quote($annee2 . $mois2 . $jour2$quote_end)")] |
|
| 1244 | + ]; |
|
| 1245 | + } |
|
| 1246 | + // sinon on prend tout |
|
| 1247 | 1247 | } |
| 1248 | 1248 | |
| 1249 | 1249 | |
@@ -1268,33 +1268,33 @@ discard block |
||
| 1268 | 1268 | * @return void |
| 1269 | 1269 | **/ |
| 1270 | 1270 | function calculer_critere_parties($idb, &$boucles, $crit) { |
| 1271 | - $boucle = &$boucles[$idb]; |
|
| 1272 | - $a1 = $crit->param[0]; |
|
| 1273 | - $a2 = $crit->param[1]; |
|
| 1274 | - $op = $crit->op; |
|
| 1275 | - |
|
| 1276 | - [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | - [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | - |
|
| 1279 | - if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | - $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | - } else { |
|
| 1282 | - // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | - $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | - // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | - $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | - $mode = (($op == '/') ? '/' : |
|
| 1287 | - (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | - // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | - if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | - $boucle->limit = |
|
| 1291 | - (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | - . ".','." |
|
| 1293 | - . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | - } else { |
|
| 1295 | - calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | - } |
|
| 1297 | - } |
|
| 1271 | + $boucle = &$boucles[$idb]; |
|
| 1272 | + $a1 = $crit->param[0]; |
|
| 1273 | + $a2 = $crit->param[1]; |
|
| 1274 | + $op = $crit->op; |
|
| 1275 | + |
|
| 1276 | + [$a11, $a12] = calculer_critere_parties_aux($idb, $boucles, $a1); |
|
| 1277 | + [$a21, $a22] = calculer_critere_parties_aux($idb, $boucles, $a2); |
|
| 1278 | + |
|
| 1279 | + if (($op == ',') && (is_numeric($a11) && (is_numeric($a21)))) { |
|
| 1280 | + $boucle->limit = $a11 . ',' . $a21; |
|
| 1281 | + } else { |
|
| 1282 | + // 3 dans {1/3}, {2,3} ou {1,n-3} |
|
| 1283 | + $boucle->total_parties = ($a21 != 'n') ? $a21 : $a22; |
|
| 1284 | + // 2 dans {2/3}, {2,5}, {n-2,1} |
|
| 1285 | + $partie = ($a11 != 'n') ? $a11 : $a12; |
|
| 1286 | + $mode = (($op == '/') ? '/' : |
|
| 1287 | + (($a11 == 'n') ? '-' : '+') . (($a21 == 'n') ? '-' : '+')); |
|
| 1288 | + // cas simple {0,#ENV{truc}} compilons le en LIMIT : |
|
| 1289 | + if ($a11 !== 'n' and $a21 !== 'n' and $mode == '++' and $op == ',') { |
|
| 1290 | + $boucle->limit = |
|
| 1291 | + (is_numeric($a11) ? "'$a11'" : $a11) |
|
| 1292 | + . ".','." |
|
| 1293 | + . (is_numeric($a21) ? "'$a21'" : $a21); |
|
| 1294 | + } else { |
|
| 1295 | + calculer_parties($boucles, $idb, $partie, $mode); |
|
| 1296 | + } |
|
| 1297 | + } |
|
| 1298 | 1298 | } |
| 1299 | 1299 | |
| 1300 | 1300 | /** |
@@ -1322,63 +1322,63 @@ discard block |
||
| 1322 | 1322 | * @return void |
| 1323 | 1323 | **/ |
| 1324 | 1324 | function calculer_parties(&$boucles, $id_boucle, $debut, $mode) { |
| 1325 | - $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | - |
|
| 1327 | - preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | - [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | - $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | - // {1/3} |
|
| 1331 | - if ($op1 == '/') { |
|
| 1332 | - $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | - $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | - "($total_parties ? $total_parties : 1)"; |
|
| 1335 | - $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | - $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | - } else { |
|
| 1338 | - // cas {n-1,x} |
|
| 1339 | - if ($op1 == '-') { |
|
| 1340 | - $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | - } |
|
| 1342 | - |
|
| 1343 | - // cas {x,n-1} |
|
| 1344 | - if ($op2 == '-') { |
|
| 1345 | - $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | - . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | - ($total_parties . ' - 1')); |
|
| 1348 | - } else { |
|
| 1349 | - // {x,1} ou {pagination} |
|
| 1350 | - $fin = '$debut_boucle' |
|
| 1351 | - . (is_numeric($total_parties) ? |
|
| 1352 | - (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | - ('+' . $total_parties . ' - 1')); |
|
| 1354 | - } |
|
| 1355 | - |
|
| 1356 | - // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | - if ($op1 == 'p') { |
|
| 1358 | - $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | - $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | - $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | - } |
|
| 1362 | - } |
|
| 1363 | - |
|
| 1364 | - // Notes : |
|
| 1365 | - // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | - // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | - // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | - // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | - |
|
| 1370 | - $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | - . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | - . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | - . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | - . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | - . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | - . "\n\tif (\$debut_boucle>0" |
|
| 1377 | - . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | - . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | - . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | - |
|
| 1381 | - $boucles[$id_boucle]->partie = " |
|
| 1325 | + $total_parties = $boucles[$id_boucle]->total_parties; |
|
| 1326 | + |
|
| 1327 | + preg_match(',([+-/p])([+-/])?,', $mode, $regs); |
|
| 1328 | + [, $op1, $op2] = array_pad($regs, 3, null); |
|
| 1329 | + $nombre_boucle = "\$Numrows['$id_boucle']['total']"; |
|
| 1330 | + // {1/3} |
|
| 1331 | + if ($op1 == '/') { |
|
| 1332 | + $pmoins1 = is_numeric($debut) ? ($debut - 1) : "($debut-1)"; |
|
| 1333 | + $totpos = is_numeric($total_parties) ? ($total_parties) : |
|
| 1334 | + "($total_parties ? $total_parties : 1)"; |
|
| 1335 | + $fin = "ceil(($nombre_boucle * $debut )/$totpos) - 1"; |
|
| 1336 | + $debut = !$pmoins1 ? 0 : "ceil(($nombre_boucle * $pmoins1)/$totpos);"; |
|
| 1337 | + } else { |
|
| 1338 | + // cas {n-1,x} |
|
| 1339 | + if ($op1 == '-') { |
|
| 1340 | + $debut = "$nombre_boucle - $debut;"; |
|
| 1341 | + } |
|
| 1342 | + |
|
| 1343 | + // cas {x,n-1} |
|
| 1344 | + if ($op2 == '-') { |
|
| 1345 | + $fin = '$debut_boucle + ' . $nombre_boucle . ' - ' |
|
| 1346 | + . (is_numeric($total_parties) ? ($total_parties + 1) : |
|
| 1347 | + ($total_parties . ' - 1')); |
|
| 1348 | + } else { |
|
| 1349 | + // {x,1} ou {pagination} |
|
| 1350 | + $fin = '$debut_boucle' |
|
| 1351 | + . (is_numeric($total_parties) ? |
|
| 1352 | + (($total_parties == 1) ? '' : (' + ' . ($total_parties - 1))) : |
|
| 1353 | + ('+' . $total_parties . ' - 1')); |
|
| 1354 | + } |
|
| 1355 | + |
|
| 1356 | + // {pagination}, gerer le debut_xx=-1 pour tout voir |
|
| 1357 | + if ($op1 == 'p') { |
|
| 1358 | + $debut .= ";\n \$debut_boucle = ((\$tout=(\$debut_boucle == -1))?0:(\$debut_boucle))"; |
|
| 1359 | + $debut .= ";\n \$debut_boucle = max(0,min(\$debut_boucle,floor(($nombre_boucle-1)/($total_parties))*($total_parties)))"; |
|
| 1360 | + $fin = "(\$tout ? $nombre_boucle : $fin)"; |
|
| 1361 | + } |
|
| 1362 | + } |
|
| 1363 | + |
|
| 1364 | + // Notes : |
|
| 1365 | + // $debut_boucle et $fin_boucle sont les indices SQL du premier |
|
| 1366 | + // et du dernier demandes dans la boucle : 0 pour le premier, |
|
| 1367 | + // n-1 pour le dernier ; donc total_boucle = 1 + debut - fin |
|
| 1368 | + // Utiliser min pour rabattre $fin_boucle sur total_boucle. |
|
| 1369 | + |
|
| 1370 | + $boucles[$id_boucle]->mode_partie = "\n\t" |
|
| 1371 | + . '$debut_boucle = ' . $debut . ";\n " |
|
| 1372 | + . "\$debut_boucle = intval(\$debut_boucle);\n " |
|
| 1373 | + . '$fin_boucle = min(' . $fin . ", \$Numrows['$id_boucle']['total'] - 1);\n " |
|
| 1374 | + . '$Numrows[\'' . $id_boucle . "']['grand_total'] = \$Numrows['$id_boucle']['total'];\n " |
|
| 1375 | + . '$Numrows[\'' . $id_boucle . '\']["total"] = max(0,$fin_boucle - $debut_boucle + 1);' |
|
| 1376 | + . "\n\tif (\$debut_boucle>0" |
|
| 1377 | + . " AND \$debut_boucle < \$Numrows['$id_boucle']['grand_total']" |
|
| 1378 | + . " AND \$iter->seek(\$debut_boucle,'continue'))" |
|
| 1379 | + . "\n\t\t\$Numrows['$id_boucle']['compteur_boucle'] = \$debut_boucle;\n\t"; |
|
| 1380 | + |
|
| 1381 | + $boucles[$id_boucle]->partie = " |
|
| 1382 | 1382 | if (\$Numrows['$id_boucle']['compteur_boucle'] <= \$debut_boucle) continue; |
| 1383 | 1383 | if (\$Numrows['$id_boucle']['compteur_boucle']-1 > \$fin_boucle) break;"; |
| 1384 | 1384 | } |
@@ -1395,26 +1395,26 @@ discard block |
||
| 1395 | 1395 | * @return array Valeur de l'élément (peut être une expression PHP), Nombre soustrait |
| 1396 | 1396 | **/ |
| 1397 | 1397 | function calculer_critere_parties_aux($idb, &$boucles, $param) { |
| 1398 | - if ($param[0]->type != 'texte') { |
|
| 1399 | - $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | - if (isset($param[1]->texte)) { |
|
| 1401 | - preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | - |
|
| 1403 | - return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | - } else { |
|
| 1405 | - return ["intval($a1)", 0]; |
|
| 1406 | - } |
|
| 1407 | - } else { |
|
| 1408 | - preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | - $a1 = $m[1]; |
|
| 1410 | - if (empty($m[3])) { |
|
| 1411 | - return [$a1, 0]; |
|
| 1412 | - } elseif (!empty($m[4])) { |
|
| 1413 | - return [$a1, $m[4]]; |
|
| 1414 | - } else { |
|
| 1415 | - return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | - } |
|
| 1417 | - } |
|
| 1398 | + if ($param[0]->type != 'texte') { |
|
| 1399 | + $a1 = calculer_liste([$param[0]], $idb, $boucles, $boucles[$idb]->id_parent); |
|
| 1400 | + if (isset($param[1]->texte)) { |
|
| 1401 | + preg_match(',^\s*(-([0-9]+))?\s*$,', $param[1]->texte, $m); |
|
| 1402 | + |
|
| 1403 | + return ["intval($a1)", ((isset($m[2]) and $m[2]) ? $m[2] : 0)]; |
|
| 1404 | + } else { |
|
| 1405 | + return ["intval($a1)", 0]; |
|
| 1406 | + } |
|
| 1407 | + } else { |
|
| 1408 | + preg_match(',^\s*(([0-9]+)|n)\s*(-\s*([0-9]+)?\s*)?$,', $param[0]->texte, $m); |
|
| 1409 | + $a1 = $m[1]; |
|
| 1410 | + if (empty($m[3])) { |
|
| 1411 | + return [$a1, 0]; |
|
| 1412 | + } elseif (!empty($m[4])) { |
|
| 1413 | + return [$a1, $m[4]]; |
|
| 1414 | + } else { |
|
| 1415 | + return [$a1, calculer_liste([$param[1]], $idb, $boucles, $boucles[$idb]->id_parent)]; |
|
| 1416 | + } |
|
| 1417 | + } |
|
| 1418 | 1418 | } |
| 1419 | 1419 | |
| 1420 | 1420 | |
@@ -1441,47 +1441,47 @@ discard block |
||
| 1441 | 1441 | * array : Erreur sur un des critères |
| 1442 | 1442 | **/ |
| 1443 | 1443 | function calculer_criteres($idb, &$boucles) { |
| 1444 | - $msg = ''; |
|
| 1445 | - $boucle = $boucles[$idb]; |
|
| 1446 | - $table = strtoupper($boucle->type_requete); |
|
| 1447 | - $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | - |
|
| 1449 | - $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | - // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | - if (!is_array($boucle->criteres)) { |
|
| 1452 | - return []; |
|
| 1453 | - } |
|
| 1454 | - |
|
| 1455 | - foreach ($boucle->criteres as $crit) { |
|
| 1456 | - $critere = $crit->op; |
|
| 1457 | - // critere personnalise ? |
|
| 1458 | - if ( |
|
| 1459 | - (!$serveur or |
|
| 1460 | - ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | - and (!function_exists($f = $f . '_dist')) |
|
| 1462 | - and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | - and (!function_exists($f = $f . '_dist')) |
|
| 1464 | - ) |
|
| 1465 | - ) |
|
| 1466 | - and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | - and (!function_exists($f = $f . '_dist')) |
|
| 1468 | - and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | - and (!function_exists($f = $f . '_dist')) |
|
| 1470 | - ) { |
|
| 1471 | - // fonction critere standard |
|
| 1472 | - $f = $defaut; |
|
| 1473 | - } |
|
| 1474 | - // compile le critere |
|
| 1475 | - $res = $f($idb, $boucles, $crit); |
|
| 1476 | - |
|
| 1477 | - // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | - if (is_array($res)) { |
|
| 1479 | - $msg = $res; |
|
| 1480 | - erreur_squelette($msg, $boucle); |
|
| 1481 | - } |
|
| 1482 | - } |
|
| 1483 | - |
|
| 1484 | - return $msg; |
|
| 1444 | + $msg = ''; |
|
| 1445 | + $boucle = $boucles[$idb]; |
|
| 1446 | + $table = strtoupper($boucle->type_requete); |
|
| 1447 | + $serveur = strtolower($boucle->sql_serveur); |
|
| 1448 | + |
|
| 1449 | + $defaut = charger_fonction('DEFAUT', 'calculer_critere'); |
|
| 1450 | + // s'il y avait une erreur de syntaxe, propager cette info |
|
| 1451 | + if (!is_array($boucle->criteres)) { |
|
| 1452 | + return []; |
|
| 1453 | + } |
|
| 1454 | + |
|
| 1455 | + foreach ($boucle->criteres as $crit) { |
|
| 1456 | + $critere = $crit->op; |
|
| 1457 | + // critere personnalise ? |
|
| 1458 | + if ( |
|
| 1459 | + (!$serveur or |
|
| 1460 | + ((!function_exists($f = 'critere_' . $serveur . '_' . $table . '_' . $critere)) |
|
| 1461 | + and (!function_exists($f = $f . '_dist')) |
|
| 1462 | + and (!function_exists($f = 'critere_' . $serveur . '_' . $critere)) |
|
| 1463 | + and (!function_exists($f = $f . '_dist')) |
|
| 1464 | + ) |
|
| 1465 | + ) |
|
| 1466 | + and (!function_exists($f = 'critere_' . $table . '_' . $critere)) |
|
| 1467 | + and (!function_exists($f = $f . '_dist')) |
|
| 1468 | + and (!function_exists($f = 'critere_' . $critere)) |
|
| 1469 | + and (!function_exists($f = $f . '_dist')) |
|
| 1470 | + ) { |
|
| 1471 | + // fonction critere standard |
|
| 1472 | + $f = $defaut; |
|
| 1473 | + } |
|
| 1474 | + // compile le critere |
|
| 1475 | + $res = $f($idb, $boucles, $crit); |
|
| 1476 | + |
|
| 1477 | + // Gestion centralisee des erreurs pour pouvoir propager |
|
| 1478 | + if (is_array($res)) { |
|
| 1479 | + $msg = $res; |
|
| 1480 | + erreur_squelette($msg, $boucle); |
|
| 1481 | + } |
|
| 1482 | + } |
|
| 1483 | + |
|
| 1484 | + return $msg; |
|
| 1485 | 1485 | } |
| 1486 | 1486 | |
| 1487 | 1487 | /** |
@@ -1496,11 +1496,11 @@ discard block |
||
| 1496 | 1496 | * @return string Code compilé rééchappé |
| 1497 | 1497 | */ |
| 1498 | 1498 | function kwote($lisp, $serveur = '', $type = '') { |
| 1499 | - if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | - return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | - } else { |
|
| 1502 | - return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | - } |
|
| 1499 | + if (preg_match(_CODE_QUOTE, $lisp, $r)) { |
|
| 1500 | + return $r[1] . '"' . sql_quote(str_replace(["\\'", '\\\\'], ["'", '\\'], $r[2]), $serveur, $type) . '"'; |
|
| 1501 | + } else { |
|
| 1502 | + return "sql_quote($lisp, '$serveur', '" . str_replace("'", "\\'", $type) . "')"; |
|
| 1503 | + } |
|
| 1504 | 1504 | } |
| 1505 | 1505 | |
| 1506 | 1506 | |
@@ -1519,81 +1519,81 @@ discard block |
||
| 1519 | 1519 | * @return void|array |
| 1520 | 1520 | **/ |
| 1521 | 1521 | function critere_IN_dist($idb, &$boucles, $crit) { |
| 1522 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | - if (!$r) { |
|
| 1524 | - return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1525 | - } |
|
| 1526 | - [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | - |
|
| 1528 | - $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | - |
|
| 1530 | - // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | - $where = $in; |
|
| 1532 | - if ($crit->cond) { |
|
| 1533 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | - $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | - $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | - } |
|
| 1538 | - } |
|
| 1539 | - if ($crit->exclus) { |
|
| 1540 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | - $where = ["'NOT'", $where]; |
|
| 1542 | - } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | - { |
|
| 1545 | - $where = [ |
|
| 1546 | - "'NOT'", |
|
| 1547 | - [ |
|
| 1548 | - "'IN'", |
|
| 1549 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | - ] |
|
| 1552 | - ]; |
|
| 1553 | - } |
|
| 1554 | - } |
|
| 1555 | - |
|
| 1556 | - $boucles[$idb]->where[] = $where; |
|
| 1557 | - if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | - } |
|
| 1522 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1523 | + if (!$r) { |
|
| 1524 | + return ['zbug_critere_inconnu', ['critere' => $crit->op . ' ?']]; |
|
| 1525 | + } |
|
| 1526 | + [$arg, $op, $val, $col, $where_complement] = $r; |
|
| 1527 | + |
|
| 1528 | + $in = critere_IN_cas($idb, $boucles, $crit->not ? 'NOT' : ($crit->exclus ? 'exclus' : ''), $arg, $op, $val, $col); |
|
| 1529 | + |
|
| 1530 | + // inserer la condition; exemple: {id_mot ?IN (66, 62, 64)} |
|
| 1531 | + $where = $in; |
|
| 1532 | + if ($crit->cond) { |
|
| 1533 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1534 | + $where = ["'?'", $pred, $where, "''"]; |
|
| 1535 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1536 | + $where_complement = ["'?'", $pred, $where_complement, "''"]; |
|
| 1537 | + } |
|
| 1538 | + } |
|
| 1539 | + if ($crit->exclus) { |
|
| 1540 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1541 | + $where = ["'NOT'", $where]; |
|
| 1542 | + } else // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1543 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1544 | + { |
|
| 1545 | + $where = [ |
|
| 1546 | + "'NOT'", |
|
| 1547 | + [ |
|
| 1548 | + "'IN'", |
|
| 1549 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1550 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1551 | + ] |
|
| 1552 | + ]; |
|
| 1553 | + } |
|
| 1554 | + } |
|
| 1555 | + |
|
| 1556 | + $boucles[$idb]->where[] = $where; |
|
| 1557 | + if ($where_complement) { // condition annexe du type "AND (objet='article')" |
|
| 1558 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1559 | + } |
|
| 1560 | 1560 | } |
| 1561 | 1561 | |
| 1562 | 1562 | function critere_IN_cas($idb, &$boucles, $crit2, $arg, $op, $val, $col) { |
| 1563 | - static $num = []; |
|
| 1564 | - $descr = $boucles[$idb]->descr; |
|
| 1565 | - $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | - |
|
| 1567 | - $var = '$in' . $cpt++; |
|
| 1568 | - $x = "\n\t$var = array();"; |
|
| 1569 | - foreach ($val as $k => $v) { |
|
| 1570 | - if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | - // optimiser le traitement des constantes |
|
| 1572 | - if (is_numeric($r[2])) { |
|
| 1573 | - $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | - } else { |
|
| 1575 | - $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | - } |
|
| 1577 | - } else { |
|
| 1578 | - // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | - // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | - // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | - // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | - $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | - } |
|
| 1584 | - } |
|
| 1585 | - |
|
| 1586 | - $boucles[$idb]->in .= $x; |
|
| 1587 | - |
|
| 1588 | - // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | - // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | - // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | - // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | - if (!$crit2) { |
|
| 1593 | - $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | - } |
|
| 1595 | - |
|
| 1596 | - return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1563 | + static $num = []; |
|
| 1564 | + $descr = $boucles[$idb]->descr; |
|
| 1565 | + $cpt = &$num[$descr['nom']][$descr['gram']][$idb]; |
|
| 1566 | + |
|
| 1567 | + $var = '$in' . $cpt++; |
|
| 1568 | + $x = "\n\t$var = array();"; |
|
| 1569 | + foreach ($val as $k => $v) { |
|
| 1570 | + if (preg_match(",^(\n//.*\n)?'(.*)'$,", $v, $r)) { |
|
| 1571 | + // optimiser le traitement des constantes |
|
| 1572 | + if (is_numeric($r[2])) { |
|
| 1573 | + $x .= "\n\t$var" . "[]= $r[2];"; |
|
| 1574 | + } else { |
|
| 1575 | + $x .= "\n\t$var" . '[]= ' . sql_quote($r[2]) . ';'; |
|
| 1576 | + } |
|
| 1577 | + } else { |
|
| 1578 | + // Pour permettre de passer des tableaux de valeurs |
|
| 1579 | + // on repere l'utilisation brute de #ENV**{X}, |
|
| 1580 | + // c'est-a-dire sa traduction en ($PILE[0][X]). |
|
| 1581 | + // et on deballe mais en rajoutant l'anti XSS |
|
| 1582 | + $x .= "\n\tif (!(is_array(\$a = ($v))))\n\t\t$var" . "[]= \$a;\n\telse $var = array_merge($var, \$a);"; |
|
| 1583 | + } |
|
| 1584 | + } |
|
| 1585 | + |
|
| 1586 | + $boucles[$idb]->in .= $x; |
|
| 1587 | + |
|
| 1588 | + // inserer le tri par defaut selon les ordres du IN ... |
|
| 1589 | + // avec une ecriture de type FIELD qui degrade les performances (du meme ordre qu'un regexp) |
|
| 1590 | + // et que l'on limite donc strictement aux cas necessaires : |
|
| 1591 | + // si ce n'est pas un !IN, et si il n'y a pas d'autre order dans la boucle |
|
| 1592 | + if (!$crit2) { |
|
| 1593 | + $boucles[$idb]->default_order[] = "((!\$zqv=sql_quote($var) OR \$zqv===\"''\") ? 0 : ('FIELD($arg,' . \$zqv . ')'))"; |
|
| 1594 | + } |
|
| 1595 | + |
|
| 1596 | + return "sql_in('$arg', $var" . ($crit2 == 'NOT' ? ",'NOT'" : '') . ')'; |
|
| 1597 | 1597 | } |
| 1598 | 1598 | |
| 1599 | 1599 | /** |
@@ -1609,22 +1609,22 @@ discard block |
||
| 1609 | 1609 | * @return void |
| 1610 | 1610 | */ |
| 1611 | 1611 | function critere_where_dist($idb, &$boucles, $crit) { |
| 1612 | - $boucle = &$boucles[$idb]; |
|
| 1613 | - if (isset($crit->param[0])) { |
|
| 1614 | - $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | - } else { |
|
| 1616 | - $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | - } |
|
| 1618 | - |
|
| 1619 | - if ($crit->cond) { |
|
| 1620 | - $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | - } |
|
| 1622 | - |
|
| 1623 | - if ($crit->not) { |
|
| 1624 | - $_where = "array('NOT',$_where)"; |
|
| 1625 | - } |
|
| 1626 | - |
|
| 1627 | - $boucle->where[] = $_where; |
|
| 1612 | + $boucle = &$boucles[$idb]; |
|
| 1613 | + if (isset($crit->param[0])) { |
|
| 1614 | + $_where = calculer_liste($crit->param[0], $idb, $boucles, $boucle->id_parent); |
|
| 1615 | + } else { |
|
| 1616 | + $_where = 'spip_sanitize_from_request(@$Pile[0]["where"],"where","vide")'; |
|
| 1617 | + } |
|
| 1618 | + |
|
| 1619 | + if ($crit->cond) { |
|
| 1620 | + $_where = "((\$zzw = $_where) ? \$zzw : '')"; |
|
| 1621 | + } |
|
| 1622 | + |
|
| 1623 | + if ($crit->not) { |
|
| 1624 | + $_where = "array('NOT',$_where)"; |
|
| 1625 | + } |
|
| 1626 | + |
|
| 1627 | + $boucle->where[] = $_where; |
|
| 1628 | 1628 | } |
| 1629 | 1629 | |
| 1630 | 1630 | /** |
@@ -1652,31 +1652,31 @@ discard block |
||
| 1652 | 1652 | * @return void |
| 1653 | 1653 | */ |
| 1654 | 1654 | function critere_id__dist($idb, &$boucles, $crit) { |
| 1655 | - /** @var Boucle $boucle */ |
|
| 1656 | - $boucle = $boucles[$idb]; |
|
| 1657 | - |
|
| 1658 | - $champs = lister_champs_id_conditionnel( |
|
| 1659 | - $boucle->show['table'], |
|
| 1660 | - $boucle->show, |
|
| 1661 | - $boucle->sql_serveur |
|
| 1662 | - ); |
|
| 1663 | - |
|
| 1664 | - // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | - if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | - $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | - } |
|
| 1668 | - // nous aider en mode debug. |
|
| 1669 | - $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | - $boucle->modificateur['id_'] = $champs; |
|
| 1671 | - |
|
| 1672 | - // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | - foreach ($champs as $champ) { |
|
| 1674 | - $critere_id_table = new Critere(); |
|
| 1675 | - $critere_id_table->op = $champ; |
|
| 1676 | - $critere_id_table->cond = '?'; |
|
| 1677 | - $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | - calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | - } |
|
| 1655 | + /** @var Boucle $boucle */ |
|
| 1656 | + $boucle = $boucles[$idb]; |
|
| 1657 | + |
|
| 1658 | + $champs = lister_champs_id_conditionnel( |
|
| 1659 | + $boucle->show['table'], |
|
| 1660 | + $boucle->show, |
|
| 1661 | + $boucle->sql_serveur |
|
| 1662 | + ); |
|
| 1663 | + |
|
| 1664 | + // ne pas tenir compte des critères identiques déjà présents. |
|
| 1665 | + if (!empty($boucle->modificateur['criteres'])) { |
|
| 1666 | + $champs = array_diff($champs, array_keys($boucle->modificateur['criteres'])); |
|
| 1667 | + } |
|
| 1668 | + // nous aider en mode debug. |
|
| 1669 | + $boucle->debug[] = 'id_ : ' . implode(', ', $champs); |
|
| 1670 | + $boucle->modificateur['id_'] = $champs; |
|
| 1671 | + |
|
| 1672 | + // créer un critère {id_xxx?} de chaque champ retenu |
|
| 1673 | + foreach ($champs as $champ) { |
|
| 1674 | + $critere_id_table = new Critere(); |
|
| 1675 | + $critere_id_table->op = $champ; |
|
| 1676 | + $critere_id_table->cond = '?'; |
|
| 1677 | + $critere_id_table->ligne = $crit->ligne; |
|
| 1678 | + calculer_critere_DEFAUT_dist($idb, $boucles, $critere_id_table); |
|
| 1679 | + } |
|
| 1680 | 1680 | } |
| 1681 | 1681 | |
| 1682 | 1682 | /** |
@@ -1696,75 +1696,75 @@ discard block |
||
| 1696 | 1696 | * @return array Liste de nom de champs (tel que id_article, id_mot, id_parent ...) |
| 1697 | 1697 | */ |
| 1698 | 1698 | function lister_champs_id_conditionnel($table, $desc = null, $serveur = '') { |
| 1699 | - // calculer la description de la table |
|
| 1700 | - if (!is_array($desc)) { |
|
| 1701 | - $desc = description_table($table, $serveur); |
|
| 1702 | - } |
|
| 1703 | - if (!$desc) { |
|
| 1704 | - return []; |
|
| 1705 | - } |
|
| 1706 | - |
|
| 1707 | - // Les champs id_xx de la table demandée |
|
| 1708 | - $champs = array_filter( |
|
| 1709 | - array_keys($desc['field']), |
|
| 1710 | - fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | - ); |
|
| 1712 | - |
|
| 1713 | - // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | - if ( |
|
| 1715 | - in_array('id_rubrique', $champs) |
|
| 1716 | - and !in_array('id_secteur', $champs) |
|
| 1717 | - ) { |
|
| 1718 | - $champs[] = 'id_secteur'; |
|
| 1719 | - } |
|
| 1720 | - |
|
| 1721 | - // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | - if ($serveur) { |
|
| 1723 | - return $champs; |
|
| 1724 | - } |
|
| 1725 | - |
|
| 1726 | - $primary = false; |
|
| 1727 | - $associable = false; |
|
| 1728 | - include_spip('action/editer_liens'); |
|
| 1729 | - |
|
| 1730 | - if (isset($desc['type'])) { |
|
| 1731 | - $primary = id_table_objet($desc['type']); |
|
| 1732 | - $associable = objet_associable($desc['type']); |
|
| 1733 | - } |
|
| 1734 | - if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | - $associable = true; |
|
| 1736 | - } |
|
| 1737 | - |
|
| 1738 | - // liste de toutes les tables principales, sauf la notre |
|
| 1739 | - $tables = lister_tables_objets_sql(); |
|
| 1740 | - unset($tables[$table]); |
|
| 1741 | - |
|
| 1742 | - foreach ($tables as $_table => $_desc) { |
|
| 1743 | - if ( |
|
| 1744 | - $associable |
|
| 1745 | - or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | - or objet_associable($_desc['type']) |
|
| 1747 | - ) { |
|
| 1748 | - $champs[] = id_table_objet($_table); |
|
| 1749 | - } |
|
| 1750 | - } |
|
| 1751 | - $champs = array_values(array_unique($champs)); |
|
| 1752 | - |
|
| 1753 | - // Exclusions de certains id |
|
| 1754 | - $exclusions = pipeline( |
|
| 1755 | - 'exclure_id_conditionnel', |
|
| 1756 | - [ |
|
| 1757 | - 'args' => [ |
|
| 1758 | - 'table' => $table, |
|
| 1759 | - 'id_table_objet' => $primary, |
|
| 1760 | - 'associable' => $associable, |
|
| 1761 | - ], |
|
| 1762 | - 'data' => [], |
|
| 1763 | - ] |
|
| 1764 | - ); |
|
| 1765 | - $champs = array_diff($champs, $exclusions); |
|
| 1766 | - |
|
| 1767 | - return $champs; |
|
| 1699 | + // calculer la description de la table |
|
| 1700 | + if (!is_array($desc)) { |
|
| 1701 | + $desc = description_table($table, $serveur); |
|
| 1702 | + } |
|
| 1703 | + if (!$desc) { |
|
| 1704 | + return []; |
|
| 1705 | + } |
|
| 1706 | + |
|
| 1707 | + // Les champs id_xx de la table demandée |
|
| 1708 | + $champs = array_filter( |
|
| 1709 | + array_keys($desc['field']), |
|
| 1710 | + fn($champ) => strpos($champ, 'id_') === 0 or (in_array($champ, ['objet'])) |
|
| 1711 | + ); |
|
| 1712 | + |
|
| 1713 | + // Si le champ id_rubrique appartient à la liste et si id_secteur n'est pas inclus on le rajoute. |
|
| 1714 | + if ( |
|
| 1715 | + in_array('id_rubrique', $champs) |
|
| 1716 | + and !in_array('id_secteur', $champs) |
|
| 1717 | + ) { |
|
| 1718 | + $champs[] = 'id_secteur'; |
|
| 1719 | + } |
|
| 1720 | + |
|
| 1721 | + // On ne fera pas mieux pour les tables d’un autre serveur |
|
| 1722 | + if ($serveur) { |
|
| 1723 | + return $champs; |
|
| 1724 | + } |
|
| 1725 | + |
|
| 1726 | + $primary = false; |
|
| 1727 | + $associable = false; |
|
| 1728 | + include_spip('action/editer_liens'); |
|
| 1729 | + |
|
| 1730 | + if (isset($desc['type'])) { |
|
| 1731 | + $primary = id_table_objet($desc['type']); |
|
| 1732 | + $associable = objet_associable($desc['type']); |
|
| 1733 | + } |
|
| 1734 | + if (isset($desc['field']['id_objet']) and isset($desc['field']['objet'])) { |
|
| 1735 | + $associable = true; |
|
| 1736 | + } |
|
| 1737 | + |
|
| 1738 | + // liste de toutes les tables principales, sauf la notre |
|
| 1739 | + $tables = lister_tables_objets_sql(); |
|
| 1740 | + unset($tables[$table]); |
|
| 1741 | + |
|
| 1742 | + foreach ($tables as $_table => $_desc) { |
|
| 1743 | + if ( |
|
| 1744 | + $associable |
|
| 1745 | + or ($primary and in_array($primary, array_keys($_desc['field']))) |
|
| 1746 | + or objet_associable($_desc['type']) |
|
| 1747 | + ) { |
|
| 1748 | + $champs[] = id_table_objet($_table); |
|
| 1749 | + } |
|
| 1750 | + } |
|
| 1751 | + $champs = array_values(array_unique($champs)); |
|
| 1752 | + |
|
| 1753 | + // Exclusions de certains id |
|
| 1754 | + $exclusions = pipeline( |
|
| 1755 | + 'exclure_id_conditionnel', |
|
| 1756 | + [ |
|
| 1757 | + 'args' => [ |
|
| 1758 | + 'table' => $table, |
|
| 1759 | + 'id_table_objet' => $primary, |
|
| 1760 | + 'associable' => $associable, |
|
| 1761 | + ], |
|
| 1762 | + 'data' => [], |
|
| 1763 | + ] |
|
| 1764 | + ); |
|
| 1765 | + $champs = array_diff($champs, $exclusions); |
|
| 1766 | + |
|
| 1767 | + return $champs; |
|
| 1768 | 1768 | } |
| 1769 | 1769 | |
| 1770 | 1770 | /** |
@@ -1819,28 +1819,28 @@ discard block |
||
| 1819 | 1819 | * @return void |
| 1820 | 1820 | */ |
| 1821 | 1821 | function critere_tri_dist($idb, &$boucles, $crit) { |
| 1822 | - $boucle = &$boucles[$idb]; |
|
| 1823 | - |
|
| 1824 | - // definition du champ par defaut |
|
| 1825 | - $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | - : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | - $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | - : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | - $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | - : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | - |
|
| 1832 | - $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | - |
|
| 1834 | - $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | - $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | - |
|
| 1837 | - $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | - $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | - $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1840 | - $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1841 | - // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1842 | - // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1843 | - $boucle->hash .= " |
|
| 1822 | + $boucle = &$boucles[$idb]; |
|
| 1823 | + |
|
| 1824 | + // definition du champ par defaut |
|
| 1825 | + $_champ_defaut = !isset($crit->param[0][0]) ? "''" |
|
| 1826 | + : calculer_liste([$crit->param[0][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1827 | + $_liste_sens_defaut = !isset($crit->param[1][0]) ? '1' |
|
| 1828 | + : calculer_liste([$crit->param[1][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1829 | + $_variable = !isset($crit->param[2][0]) ? "'$idb'" |
|
| 1830 | + : calculer_liste([$crit->param[2][0]], $idb, $boucles, $boucle->id_parent); |
|
| 1831 | + |
|
| 1832 | + $_tri = "((\$t=(isset(\$Pile[0]['tri'.$_variable]))?\$Pile[0]['tri'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('tri'.$_variable))?session_get('tri'.$_variable):$_champ_defaut))?tri_protege_champ(\$t):'')"; |
|
| 1833 | + |
|
| 1834 | + $_sens_defaut = "(is_array(\$s=$_liste_sens_defaut)?(isset(\$s[\$st=$_tri])?\$s[\$st]:reset(\$s)):\$s)"; |
|
| 1835 | + $_sens = "((intval(\$t=(isset(\$Pile[0]['sens'.$_variable]))?\$Pile[0]['sens'.$_variable]:((strncmp($_variable,'session',7)==0 AND session_get('sens'.$_variable))?session_get('sens'.$_variable):$_sens_defaut))==-1 OR \$t=='inverse')?-1:1)"; |
|
| 1836 | + |
|
| 1837 | + $boucle->modificateur['tri_champ'] = $_tri; |
|
| 1838 | + $boucle->modificateur['tri_sens'] = $_sens; |
|
| 1839 | + $boucle->modificateur['tri_liste_sens_defaut'] = $_liste_sens_defaut; |
|
| 1840 | + $boucle->modificateur['tri_nom'] = $_variable; |
|
| 1841 | + // faut il inserer un test sur l'existence de $tri parmi les champs de la table ? |
|
| 1842 | + // evite des erreurs sql, mais peut empecher des tri sur jointure ... |
|
| 1843 | + $boucle->hash .= " |
|
| 1844 | 1844 | \$senstri = ''; |
| 1845 | 1845 | \$tri = $_tri; |
| 1846 | 1846 | if (\$tri){ |
@@ -1848,8 +1848,8 @@ discard block |
||
| 1848 | 1848 | \$senstri = (\$senstri<0)?' DESC':''; |
| 1849 | 1849 | }; |
| 1850 | 1850 | "; |
| 1851 | - $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1852 | - $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1851 | + $boucle->select[] = '".tri_champ_select($tri)."'; |
|
| 1852 | + $boucle->order[] = "tri_champ_order(\$tri,\$command['from'],\$senstri)"; |
|
| 1853 | 1853 | } |
| 1854 | 1854 | |
| 1855 | 1855 | # Criteres de comparaison |
@@ -1866,20 +1866,20 @@ discard block |
||
| 1866 | 1866 | * @return void|array |
| 1867 | 1867 | **/ |
| 1868 | 1868 | function calculer_critere_DEFAUT_dist($idb, &$boucles, $crit) { |
| 1869 | - // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1870 | - if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1871 | - return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1872 | - } |
|
| 1873 | - |
|
| 1874 | - $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1875 | - if (!$r) { |
|
| 1876 | - # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1877 | - # if (!$crit->cond) { |
|
| 1878 | - return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1879 | - # } |
|
| 1880 | - } else { |
|
| 1881 | - calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1882 | - } |
|
| 1869 | + // double cas particulier {0,1} et {1/2} repere a l'analyse lexicale |
|
| 1870 | + if (($crit->op == ',') or ($crit->op == '/')) { |
|
| 1871 | + return calculer_critere_parties($idb, $boucles, $crit); |
|
| 1872 | + } |
|
| 1873 | + |
|
| 1874 | + $r = calculer_critere_infixe($idb, $boucles, $crit); |
|
| 1875 | + if (!$r) { |
|
| 1876 | + # // on produit une erreur seulement si le critere n'a pas de '?' |
|
| 1877 | + # if (!$crit->cond) { |
|
| 1878 | + return ['zbug_critere_inconnu', ['critere' => $crit->op]]; |
|
| 1879 | + # } |
|
| 1880 | + } else { |
|
| 1881 | + calculer_critere_DEFAUT_args($idb, $boucles, $crit, $r); |
|
| 1882 | + } |
|
| 1883 | 1883 | } |
| 1884 | 1884 | |
| 1885 | 1885 | |
@@ -1899,62 +1899,62 @@ discard block |
||
| 1899 | 1899 | * @return void |
| 1900 | 1900 | **/ |
| 1901 | 1901 | function calculer_critere_DEFAUT_args($idb, &$boucles, $crit, $args) { |
| 1902 | - [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1903 | - |
|
| 1904 | - $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1905 | - |
|
| 1906 | - // inserer la negation (cf !...) |
|
| 1907 | - |
|
| 1908 | - if ($crit->not) { |
|
| 1909 | - $where = ["'NOT'", $where]; |
|
| 1910 | - } |
|
| 1911 | - if ($crit->exclus) { |
|
| 1912 | - if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1913 | - $where = ["'NOT'", $where]; |
|
| 1914 | - } else { |
|
| 1915 | - // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1916 | - // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1917 | - $where = [ |
|
| 1918 | - "'NOT'", |
|
| 1919 | - [ |
|
| 1920 | - "'IN'", |
|
| 1921 | - "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1922 | - ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1923 | - ] |
|
| 1924 | - ]; |
|
| 1925 | - } |
|
| 1926 | - } |
|
| 1927 | - |
|
| 1928 | - // inserer la condition (cf {lang?}) |
|
| 1929 | - // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1930 | - if ($crit->cond) { |
|
| 1931 | - $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1932 | - if ($col === 'date' or $col === 'date_redac') { |
|
| 1933 | - if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1934 | - $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - if ($op === '=' and !$crit->not) { |
|
| 1939 | - $where = [ |
|
| 1940 | - "'?'", |
|
| 1941 | - "(is_array($pred))", |
|
| 1942 | - critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1943 | - $where |
|
| 1944 | - ]; |
|
| 1945 | - } |
|
| 1946 | - $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1947 | - if ($where_complement) { |
|
| 1948 | - // condition annexe du type "AND (objet='article')" |
|
| 1949 | - $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1950 | - } |
|
| 1951 | - } |
|
| 1952 | - |
|
| 1953 | - $boucles[$idb]->where[] = $where; |
|
| 1954 | - if ($where_complement) { |
|
| 1955 | - // condition annexe du type "AND (objet='article')" |
|
| 1956 | - $boucles[$idb]->where[] = $where_complement; |
|
| 1957 | - } |
|
| 1902 | + [$arg, $op, $val, $col, $where_complement] = $args; |
|
| 1903 | + |
|
| 1904 | + $where = ["'$op'", "'$arg'", $val[0]]; |
|
| 1905 | + |
|
| 1906 | + // inserer la negation (cf !...) |
|
| 1907 | + |
|
| 1908 | + if ($crit->not) { |
|
| 1909 | + $where = ["'NOT'", $where]; |
|
| 1910 | + } |
|
| 1911 | + if ($crit->exclus) { |
|
| 1912 | + if (!preg_match(',^L[0-9]+[.],', $arg)) { |
|
| 1913 | + $where = ["'NOT'", $where]; |
|
| 1914 | + } else { |
|
| 1915 | + // un not sur un critere de jointure se traduit comme un NOT IN avec une sous requete |
|
| 1916 | + // c'est une sous requete identique a la requete principale sous la forme (SELF,$select,$where) avec $select et $where qui surchargent |
|
| 1917 | + $where = [ |
|
| 1918 | + "'NOT'", |
|
| 1919 | + [ |
|
| 1920 | + "'IN'", |
|
| 1921 | + "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", |
|
| 1922 | + ["'SELF'", "'" . $boucles[$idb]->id_table . '.' . $boucles[$idb]->primary . "'", $where] |
|
| 1923 | + ] |
|
| 1924 | + ]; |
|
| 1925 | + } |
|
| 1926 | + } |
|
| 1927 | + |
|
| 1928 | + // inserer la condition (cf {lang?}) |
|
| 1929 | + // traiter a part la date, elle est mise d'office par SPIP, |
|
| 1930 | + if ($crit->cond) { |
|
| 1931 | + $pred = calculer_argument_precedent($idb, $col, $boucles); |
|
| 1932 | + if ($col === 'date' or $col === 'date_redac') { |
|
| 1933 | + if ($pred === "\$Pile[0]['" . $col . "']") { |
|
| 1934 | + $pred = "(\$Pile[0]['{$col}_default']?'':$pred)"; |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + if ($op === '=' and !$crit->not) { |
|
| 1939 | + $where = [ |
|
| 1940 | + "'?'", |
|
| 1941 | + "(is_array($pred))", |
|
| 1942 | + critere_IN_cas($idb, $boucles, 'COND', $arg, $op, [$pred], $col), |
|
| 1943 | + $where |
|
| 1944 | + ]; |
|
| 1945 | + } |
|
| 1946 | + $where = ["'?'", "!is_whereable($pred)", "''", $where]; |
|
| 1947 | + if ($where_complement) { |
|
| 1948 | + // condition annexe du type "AND (objet='article')" |
|
| 1949 | + $where_complement = ["'?'", "!is_whereable($pred)", "''", $where_complement]; |
|
| 1950 | + } |
|
| 1951 | + } |
|
| 1952 | + |
|
| 1953 | + $boucles[$idb]->where[] = $where; |
|
| 1954 | + if ($where_complement) { |
|
| 1955 | + // condition annexe du type "AND (objet='article')" |
|
| 1956 | + $boucles[$idb]->where[] = $where_complement; |
|
| 1957 | + } |
|
| 1958 | 1958 | } |
| 1959 | 1959 | |
| 1960 | 1960 | |
@@ -1995,165 +1995,165 @@ discard block |
||
| 1995 | 1995 | **/ |
| 1996 | 1996 | function calculer_critere_infixe($idb, &$boucles, $crit) { |
| 1997 | 1997 | |
| 1998 | - $boucle = &$boucles[$idb]; |
|
| 1999 | - $type = $boucle->type_requete; |
|
| 2000 | - $table = $boucle->id_table; |
|
| 2001 | - $desc = $boucle->show; |
|
| 2002 | - $col_vraie = null; |
|
| 2003 | - |
|
| 2004 | - [$fct, $col, $op, $val, $args_sql] = |
|
| 2005 | - calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2006 | - |
|
| 2007 | - $col_alias = $col; |
|
| 2008 | - $where_complement = false; |
|
| 2009 | - |
|
| 2010 | - // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2011 | - if ($col == 'id_enfant') { |
|
| 2012 | - $col = $boucle->primary; |
|
| 2013 | - } |
|
| 2014 | - |
|
| 2015 | - // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2016 | - if ( |
|
| 2017 | - (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | - or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2019 | - ) { |
|
| 2020 | - $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2021 | - } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2022 | - else { |
|
| 2023 | - if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2024 | - $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2025 | - } |
|
| 2026 | - |
|
| 2027 | - // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2028 | - // sauf si exception declaree : sauter cette etape |
|
| 2029 | - else { |
|
| 2030 | - if ( |
|
| 2031 | - !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2032 | - and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2033 | - and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2034 | - ) { |
|
| 2035 | - $e = decompose_champ_id_objet($col); |
|
| 2036 | - $col = array_shift($e); |
|
| 2037 | - $where_complement = primary_doublee($e, $table); |
|
| 2038 | - } // Cas particulier : expressions de date |
|
| 2039 | - else { |
|
| 2040 | - if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2041 | - [$col, $col_vraie] = $c; |
|
| 2042 | - $table = ''; |
|
| 2043 | - } // table explicitée {mots.titre} |
|
| 2044 | - else { |
|
| 2045 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2046 | - [, $table, $col] = $r; |
|
| 2047 | - $col_alias = $col; |
|
| 2048 | - |
|
| 2049 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2050 | - if ( |
|
| 2051 | - $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2052 | - and isset($desc['field'][$col]) |
|
| 2053 | - and $cle = array_search($desc['table'], $boucle->from) |
|
| 2054 | - ) { |
|
| 2055 | - $table = $cle; |
|
| 2056 | - } else { |
|
| 2057 | - $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2058 | - } |
|
| 2059 | - #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2060 | - if (!$table) { |
|
| 2061 | - return ''; |
|
| 2062 | - } |
|
| 2063 | - } |
|
| 2064 | - // si le champ n'est pas trouvé dans la table, |
|
| 2065 | - // on cherche si une jointure peut l'obtenir |
|
| 2066 | - elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2067 | - // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2068 | - if (@array_key_exists('*', $desc['field'])) { |
|
| 2069 | - $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2070 | - } |
|
| 2071 | - else { |
|
| 2072 | - $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2073 | - if (!$r) { |
|
| 2074 | - return ''; |
|
| 2075 | - } |
|
| 2076 | - [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2077 | - } |
|
| 2078 | - } |
|
| 2079 | - } |
|
| 2080 | - } |
|
| 2081 | - } |
|
| 2082 | - } |
|
| 2083 | - |
|
| 2084 | - $col_vraie = ($col_vraie ?: $col); |
|
| 2085 | - // Dans tous les cas, |
|
| 2086 | - // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2087 | - // et passer dans sql_quote avec le type si connu |
|
| 2088 | - // et int sinon si la valeur est numerique |
|
| 2089 | - // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2090 | - // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2091 | - if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2092 | - $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2093 | - // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2094 | - // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2095 | - if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2096 | - $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2097 | - } |
|
| 2098 | - // sinon expliciter les |
|
| 2099 | - // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2100 | - // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2101 | - // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2102 | - // sans toucher aux |
|
| 2103 | - // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2104 | - // sql_quote(truc,'','varchar') |
|
| 2105 | - elseif ( |
|
| 2106 | - preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2107 | - // si pas deja un type |
|
| 2108 | - and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2109 | - ) { |
|
| 2110 | - $r = $r[1] |
|
| 2111 | - . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2112 | - . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2113 | - $val[0] = "sql_quote($r)"; |
|
| 2114 | - } |
|
| 2115 | - elseif ( |
|
| 2116 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2117 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2118 | - ) { |
|
| 2119 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2120 | - } |
|
| 2121 | - } |
|
| 2122 | - |
|
| 2123 | - if ( |
|
| 2124 | - strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | - and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | - ) { |
|
| 2127 | - $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2128 | - } |
|
| 2129 | - |
|
| 2130 | - // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2131 | - // leurs requetes par defaut, notamment le champ statut |
|
| 2132 | - // Ne pas confondre champs de la table principale et des jointures |
|
| 2133 | - if ($table === $boucle->id_table) { |
|
| 2134 | - $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2135 | - if ($col_alias != $col_vraie) { |
|
| 2136 | - $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2137 | - } |
|
| 2138 | - } |
|
| 2139 | - |
|
| 2140 | - // inserer le nom de la table SQL devant le nom du champ |
|
| 2141 | - if ($table) { |
|
| 2142 | - if ($col[0] == '`') { |
|
| 2143 | - $arg = "$table." . substr($col, 1, -1); |
|
| 2144 | - } else { |
|
| 2145 | - $arg = "$table.$col"; |
|
| 2146 | - } |
|
| 2147 | - } else { |
|
| 2148 | - $arg = $col; |
|
| 2149 | - } |
|
| 2150 | - |
|
| 2151 | - // inserer la fonction SQL |
|
| 2152 | - if ($fct) { |
|
| 2153 | - $arg = "$fct($arg$args_sql)"; |
|
| 2154 | - } |
|
| 2155 | - |
|
| 2156 | - return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 1998 | + $boucle = &$boucles[$idb]; |
|
| 1999 | + $type = $boucle->type_requete; |
|
| 2000 | + $table = $boucle->id_table; |
|
| 2001 | + $desc = $boucle->show; |
|
| 2002 | + $col_vraie = null; |
|
| 2003 | + |
|
| 2004 | + [$fct, $col, $op, $val, $args_sql] = |
|
| 2005 | + calculer_critere_infixe_ops($idb, $boucles, $crit); |
|
| 2006 | + |
|
| 2007 | + $col_alias = $col; |
|
| 2008 | + $where_complement = false; |
|
| 2009 | + |
|
| 2010 | + // Cas particulier : id_enfant => utiliser la colonne id_objet |
|
| 2011 | + if ($col == 'id_enfant') { |
|
| 2012 | + $col = $boucle->primary; |
|
| 2013 | + } |
|
| 2014 | + |
|
| 2015 | + // Cas particulier : id_parent => verifier les exceptions de tables |
|
| 2016 | + if ( |
|
| 2017 | + (in_array($col, ['id_parent', 'id_secteur']) and isset($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2018 | + or (isset($GLOBALS['exceptions_des_tables'][$table][$col]) and is_string($GLOBALS['exceptions_des_tables'][$table][$col])) |
|
| 2019 | + ) { |
|
| 2020 | + $col = $GLOBALS['exceptions_des_tables'][$table][$col]; |
|
| 2021 | + } // et possibilite de gerer un critere secteur sur des tables de plugins (ie forums) |
|
| 2022 | + else { |
|
| 2023 | + if (($col == 'id_secteur') and ($critere_secteur = charger_fonction("critere_secteur_$type", 'public', true))) { |
|
| 2024 | + $table = $critere_secteur($idb, $boucles, $val, $crit); |
|
| 2025 | + } |
|
| 2026 | + |
|
| 2027 | + // cas id_article=xx qui se mappe en id_objet=xx AND objet=article |
|
| 2028 | + // sauf si exception declaree : sauter cette etape |
|
| 2029 | + else { |
|
| 2030 | + if ( |
|
| 2031 | + !isset($GLOBALS['exceptions_des_jointures'][table_objet_sql($table)][$col]) |
|
| 2032 | + and !isset($GLOBALS['exceptions_des_jointures'][$col]) |
|
| 2033 | + and count(trouver_champs_decomposes($col, $desc)) > 1 |
|
| 2034 | + ) { |
|
| 2035 | + $e = decompose_champ_id_objet($col); |
|
| 2036 | + $col = array_shift($e); |
|
| 2037 | + $where_complement = primary_doublee($e, $table); |
|
| 2038 | + } // Cas particulier : expressions de date |
|
| 2039 | + else { |
|
| 2040 | + if ($c = calculer_critere_infixe_date($idb, $boucles, $col)) { |
|
| 2041 | + [$col, $col_vraie] = $c; |
|
| 2042 | + $table = ''; |
|
| 2043 | + } // table explicitée {mots.titre} |
|
| 2044 | + else { |
|
| 2045 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2046 | + [, $table, $col] = $r; |
|
| 2047 | + $col_alias = $col; |
|
| 2048 | + |
|
| 2049 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 2050 | + if ( |
|
| 2051 | + $desc = $trouver_table($table, $boucle->sql_serveur) |
|
| 2052 | + and isset($desc['field'][$col]) |
|
| 2053 | + and $cle = array_search($desc['table'], $boucle->from) |
|
| 2054 | + ) { |
|
| 2055 | + $table = $cle; |
|
| 2056 | + } else { |
|
| 2057 | + $table = trouver_jointure_champ($col, $boucle, [$table], ($crit->cond or $op != '=')); |
|
| 2058 | + } |
|
| 2059 | + #$table = calculer_critere_externe_init($boucle, array($table), $col, $desc, ($crit->cond OR $op!='='), true); |
|
| 2060 | + if (!$table) { |
|
| 2061 | + return ''; |
|
| 2062 | + } |
|
| 2063 | + } |
|
| 2064 | + // si le champ n'est pas trouvé dans la table, |
|
| 2065 | + // on cherche si une jointure peut l'obtenir |
|
| 2066 | + elseif (@!array_key_exists($col, $desc['field'])) { |
|
| 2067 | + // Champ joker * des iterateurs DATA qui accepte tout |
|
| 2068 | + if (@array_key_exists('*', $desc['field'])) { |
|
| 2069 | + $desc['field'][$col_vraie ?: $col] = ''; // on veut pas de cast INT par defaut car le type peut etre n'importe quoi dans les boucles DATA |
|
| 2070 | + } |
|
| 2071 | + else { |
|
| 2072 | + $r = calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table); |
|
| 2073 | + if (!$r) { |
|
| 2074 | + return ''; |
|
| 2075 | + } |
|
| 2076 | + [$col, $col_alias, $table, $where_complement, $desc] = $r; |
|
| 2077 | + } |
|
| 2078 | + } |
|
| 2079 | + } |
|
| 2080 | + } |
|
| 2081 | + } |
|
| 2082 | + } |
|
| 2083 | + |
|
| 2084 | + $col_vraie = ($col_vraie ?: $col); |
|
| 2085 | + // Dans tous les cas, |
|
| 2086 | + // virer les guillemets eventuels autour d'un int (qui sont refuses par certains SQL) |
|
| 2087 | + // et passer dans sql_quote avec le type si connu |
|
| 2088 | + // et int sinon si la valeur est numerique |
|
| 2089 | + // sinon introduire le vrai type du champ si connu dans le sql_quote (ou int NOT NULL sinon) |
|
| 2090 | + // Ne pas utiliser intval, PHP tronquant les Bigint de SQL |
|
| 2091 | + if ($op == '=' or in_array($op, $GLOBALS['table_criteres_infixes'])) { |
|
| 2092 | + $type_cast_quote = ($desc['field'][$col_vraie] ?? 'int NOT NULL'); |
|
| 2093 | + // defaire le quote des int et les passer dans sql_quote avec le bon type de champ si on le connait, int sinon |
|
| 2094 | + // prendre en compte le debug ou la valeur arrive avec un commentaire PHP en debut |
|
| 2095 | + if (preg_match(",^\\A(\s*//.*?$\s*)?\"'(-?\d+)'\"\\z,ms", $val[0], $r)) { |
|
| 2096 | + $val[0] = $r[1] . '"' . sql_quote($r[2], $boucle->sql_serveur, $type_cast_quote) . '"'; |
|
| 2097 | + } |
|
| 2098 | + // sinon expliciter les |
|
| 2099 | + // sql_quote(truc) en sql_quote(truc,'',type) |
|
| 2100 | + // sql_quote(truc,serveur) en sql_quote(truc,serveur,type) |
|
| 2101 | + // sql_quote(truc,serveur,'') en sql_quote(truc,serveur,type) |
|
| 2102 | + // sans toucher aux |
|
| 2103 | + // sql_quote(truc,'','varchar(10) DEFAULT \'oui\' COLLATE NOCASE') |
|
| 2104 | + // sql_quote(truc,'','varchar') |
|
| 2105 | + elseif ( |
|
| 2106 | + preg_match('/\Asql_quote[(](.*?)(,[^)]*?)?(,[^)]*(?:\(\d+\)[^)]*)?)?[)]\s*\z/ms', $val[0], $r) |
|
| 2107 | + // si pas deja un type |
|
| 2108 | + and (!isset($r[3]) or !$r[3] or !trim($r[3], ", '")) |
|
| 2109 | + ) { |
|
| 2110 | + $r = $r[1] |
|
| 2111 | + . ((isset($r[2]) and $r[2]) ? $r[2] : ",''") |
|
| 2112 | + . ",'" . addslashes($type_cast_quote) . "'"; |
|
| 2113 | + $val[0] = "sql_quote($r)"; |
|
| 2114 | + } |
|
| 2115 | + elseif ( |
|
| 2116 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2117 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2118 | + ) { |
|
| 2119 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'" . addslashes($type_cast_quote) . "')"; |
|
| 2120 | + } |
|
| 2121 | + } |
|
| 2122 | + |
|
| 2123 | + if ( |
|
| 2124 | + strpos($val[0], '@@defaultcast@@') !== false |
|
| 2125 | + and preg_match("/'@@defaultcast@@'\s*\)\s*\z/ms", $val[0], $r) |
|
| 2126 | + ) { |
|
| 2127 | + $val[0] = substr($val[0], 0, -strlen($r[0])) . "'char')"; |
|
| 2128 | + } |
|
| 2129 | + |
|
| 2130 | + // Indicateur pour permettre aux fonctionx boucle_X de modifier |
|
| 2131 | + // leurs requetes par defaut, notamment le champ statut |
|
| 2132 | + // Ne pas confondre champs de la table principale et des jointures |
|
| 2133 | + if ($table === $boucle->id_table) { |
|
| 2134 | + $boucles[$idb]->modificateur['criteres'][$col_vraie] = true; |
|
| 2135 | + if ($col_alias != $col_vraie) { |
|
| 2136 | + $boucles[$idb]->modificateur['criteres'][$col_alias] = true; |
|
| 2137 | + } |
|
| 2138 | + } |
|
| 2139 | + |
|
| 2140 | + // inserer le nom de la table SQL devant le nom du champ |
|
| 2141 | + if ($table) { |
|
| 2142 | + if ($col[0] == '`') { |
|
| 2143 | + $arg = "$table." . substr($col, 1, -1); |
|
| 2144 | + } else { |
|
| 2145 | + $arg = "$table.$col"; |
|
| 2146 | + } |
|
| 2147 | + } else { |
|
| 2148 | + $arg = $col; |
|
| 2149 | + } |
|
| 2150 | + |
|
| 2151 | + // inserer la fonction SQL |
|
| 2152 | + if ($fct) { |
|
| 2153 | + $arg = "$fct($arg$args_sql)"; |
|
| 2154 | + } |
|
| 2155 | + |
|
| 2156 | + return [$arg, $op, $val, $col_alias, $where_complement]; |
|
| 2157 | 2157 | } |
| 2158 | 2158 | |
| 2159 | 2159 | |
@@ -2182,77 +2182,77 @@ discard block |
||
| 2182 | 2182 | **/ |
| 2183 | 2183 | function calculer_critere_infixe_externe($boucle, $crit, $op, $desc, $col, $col_alias, $table) { |
| 2184 | 2184 | |
| 2185 | - $where = ''; |
|
| 2186 | - |
|
| 2187 | - $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2188 | - // gestion par les plugins des jointures tordues |
|
| 2189 | - // pas automatiques mais necessaires |
|
| 2190 | - $table_sql = table_objet_sql($table); |
|
| 2191 | - if ( |
|
| 2192 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | - and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2194 | - and |
|
| 2195 | - ( |
|
| 2196 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2197 | - or |
|
| 2198 | - isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2199 | - ) |
|
| 2200 | - ) { |
|
| 2201 | - $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2202 | - $index = $t[$col] ?? $t[''] ?? []; |
|
| 2203 | - |
|
| 2204 | - if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2205 | - [$t, $col, $calculer_critere_externe] = $index; |
|
| 2206 | - } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2207 | - [$t, $col] = $t[$col]; |
|
| 2208 | - } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2209 | - [$calculer_critere_externe] = $index; |
|
| 2210 | - $t = $table; |
|
| 2211 | - } else { |
|
| 2212 | - $t = ''; |
|
| 2213 | - } // jointure non declaree. La trouver. |
|
| 2214 | - } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2215 | - [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2216 | - } else { |
|
| 2217 | - $t = ''; |
|
| 2218 | - } // jointure non declaree. La trouver. |
|
| 2219 | - |
|
| 2220 | - // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2221 | - |
|
| 2222 | - // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2223 | - // permet de forcer une table de lien quand il y a ambiguite |
|
| 2224 | - // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2225 | - // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2226 | - $table = ''; |
|
| 2227 | - if ($boucle->jointures_explicites) { |
|
| 2228 | - $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2229 | - $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2230 | - } |
|
| 2231 | - |
|
| 2232 | - // et sinon on cherche parmi toutes les jointures declarees |
|
| 2233 | - if (!$table) { |
|
| 2234 | - $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2235 | - } |
|
| 2236 | - |
|
| 2237 | - if (!$table) { |
|
| 2238 | - return ''; |
|
| 2239 | - } |
|
| 2240 | - |
|
| 2241 | - // il ne reste plus qu'a trouver le champ dans les from |
|
| 2242 | - [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2243 | - |
|
| 2244 | - if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2245 | - $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2246 | - if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2247 | - $e = decompose_champ_id_objet($col); |
|
| 2248 | - $col = array_shift($e); |
|
| 2249 | - $where = primary_doublee($e, $table); |
|
| 2250 | - } else { |
|
| 2251 | - $col = reset($cle); |
|
| 2252 | - } |
|
| 2253 | - } |
|
| 2254 | - |
|
| 2255 | - return [$col, $col_alias, $table, $where, $desc]; |
|
| 2185 | + $where = ''; |
|
| 2186 | + |
|
| 2187 | + $calculer_critere_externe = 'calculer_critere_externe_init'; |
|
| 2188 | + // gestion par les plugins des jointures tordues |
|
| 2189 | + // pas automatiques mais necessaires |
|
| 2190 | + $table_sql = table_objet_sql($table); |
|
| 2191 | + if ( |
|
| 2192 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2193 | + and is_array($GLOBALS['exceptions_des_jointures'][$table_sql]) |
|
| 2194 | + and |
|
| 2195 | + ( |
|
| 2196 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql][$col]) |
|
| 2197 | + or |
|
| 2198 | + isset($GLOBALS['exceptions_des_jointures'][$table_sql]['']) |
|
| 2199 | + ) |
|
| 2200 | + ) { |
|
| 2201 | + $t = $GLOBALS['exceptions_des_jointures'][$table_sql]; |
|
| 2202 | + $index = $t[$col] ?? $t[''] ?? []; |
|
| 2203 | + |
|
| 2204 | + if ((is_countable($index) ? count($index) : 0) == 3) { |
|
| 2205 | + [$t, $col, $calculer_critere_externe] = $index; |
|
| 2206 | + } elseif ((is_countable($index) ? count($index) : 0) == 2) { |
|
| 2207 | + [$t, $col] = $t[$col]; |
|
| 2208 | + } elseif ((is_countable($index) ? count($index) : 0) == 1) { |
|
| 2209 | + [$calculer_critere_externe] = $index; |
|
| 2210 | + $t = $table; |
|
| 2211 | + } else { |
|
| 2212 | + $t = ''; |
|
| 2213 | + } // jointure non declaree. La trouver. |
|
| 2214 | + } elseif (isset($GLOBALS['exceptions_des_jointures'][$col])) { |
|
| 2215 | + [$t, $col] = $GLOBALS['exceptions_des_jointures'][$col]; |
|
| 2216 | + } else { |
|
| 2217 | + $t = ''; |
|
| 2218 | + } // jointure non declaree. La trouver. |
|
| 2219 | + |
|
| 2220 | + // ici on construit le from pour fournir $col en piochant dans les jointures |
|
| 2221 | + |
|
| 2222 | + // si des jointures explicites sont fournies, on cherche d'abord dans celles ci |
|
| 2223 | + // permet de forcer une table de lien quand il y a ambiguite |
|
| 2224 | + // <BOUCLE_(DOCUMENTS documents_liens){id_mot}> |
|
| 2225 | + // alors que <BOUCLE_(DOCUMENTS){id_mot}> produit la meme chose que <BOUCLE_(DOCUMENTS mots_liens){id_mot}> |
|
| 2226 | + $table = ''; |
|
| 2227 | + if ($boucle->jointures_explicites) { |
|
| 2228 | + $jointures_explicites = explode(' ', $boucle->jointures_explicites); |
|
| 2229 | + $table = $calculer_critere_externe($boucle, $jointures_explicites, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2230 | + } |
|
| 2231 | + |
|
| 2232 | + // et sinon on cherche parmi toutes les jointures declarees |
|
| 2233 | + if (!$table) { |
|
| 2234 | + $table = $calculer_critere_externe($boucle, $boucle->jointures, $col, $desc, ($crit->cond or $op != '='), $t); |
|
| 2235 | + } |
|
| 2236 | + |
|
| 2237 | + if (!$table) { |
|
| 2238 | + return ''; |
|
| 2239 | + } |
|
| 2240 | + |
|
| 2241 | + // il ne reste plus qu'a trouver le champ dans les from |
|
| 2242 | + [$nom, $desc, $cle] = trouver_champ_exterieur($col, $boucle->from, $boucle); |
|
| 2243 | + |
|
| 2244 | + if ((is_countable($cle) ? count($cle) : 0) > 1 or reset($cle) !== $col) { |
|
| 2245 | + $col_alias = $col; // id_article devient juste le nom d'origine |
|
| 2246 | + if ((is_countable($cle) ? count($cle) : 0) > 1 and reset($cle) == 'id_objet') { |
|
| 2247 | + $e = decompose_champ_id_objet($col); |
|
| 2248 | + $col = array_shift($e); |
|
| 2249 | + $where = primary_doublee($e, $table); |
|
| 2250 | + } else { |
|
| 2251 | + $col = reset($cle); |
|
| 2252 | + } |
|
| 2253 | + } |
|
| 2254 | + |
|
| 2255 | + return [$col, $col_alias, $table, $where, $desc]; |
|
| 2256 | 2256 | } |
| 2257 | 2257 | |
| 2258 | 2258 | |
@@ -2273,10 +2273,10 @@ discard block |
||
| 2273 | 2273 | * - valeur |
| 2274 | 2274 | **/ |
| 2275 | 2275 | function primary_doublee($decompose, $table) { |
| 2276 | - $e1 = reset($decompose); |
|
| 2277 | - $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2276 | + $e1 = reset($decompose); |
|
| 2277 | + $e2 = "sql_quote('" . end($decompose) . "')"; |
|
| 2278 | 2278 | |
| 2279 | - return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2279 | + return ["'='", "'$table." . $e1 . "'", $e2]; |
|
| 2280 | 2280 | } |
| 2281 | 2281 | |
| 2282 | 2282 | /** |
@@ -2307,57 +2307,57 @@ discard block |
||
| 2307 | 2307 | * Vide sinon. |
| 2308 | 2308 | */ |
| 2309 | 2309 | function calculer_critere_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2310 | - // si on demande un truc du genre spip_mots |
|
| 2311 | - // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2312 | - // et qu'on est la |
|
| 2313 | - // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2314 | - if ( |
|
| 2315 | - $checkarrivee |
|
| 2316 | - and is_string($checkarrivee) |
|
| 2317 | - and $a = table_objet($checkarrivee) |
|
| 2318 | - and in_array($a . '_liens', $joints) |
|
| 2319 | - ) { |
|
| 2320 | - if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2321 | - return $res; |
|
| 2322 | - } |
|
| 2323 | - } |
|
| 2324 | - foreach ($joints as $joint) { |
|
| 2325 | - if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2326 | - // alias de table dans le from |
|
| 2327 | - $t = array_search($arrivee[0], $boucle->from); |
|
| 2328 | - // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2329 | - $cols = $arrivee[2]; |
|
| 2330 | - // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2331 | - if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2332 | - array_pop($cols); |
|
| 2333 | - } |
|
| 2334 | - if ($t) { |
|
| 2335 | - // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2336 | - $joindre = false; |
|
| 2337 | - foreach ($cols as $col) { |
|
| 2338 | - $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2339 | - if (trouver_champ($c, $boucle->where)) { |
|
| 2340 | - $joindre = true; |
|
| 2341 | - } else { |
|
| 2342 | - // mais ca peut etre dans le FIELD pour le Having |
|
| 2343 | - $c = "/FIELD.$t" . ".$col,/"; |
|
| 2344 | - if (trouver_champ($c, $boucle->select)) { |
|
| 2345 | - $joindre = true; |
|
| 2346 | - } |
|
| 2347 | - } |
|
| 2348 | - } |
|
| 2349 | - if (!$joindre) { |
|
| 2350 | - return $t; |
|
| 2351 | - } |
|
| 2352 | - } |
|
| 2353 | - array_pop($arrivee); |
|
| 2354 | - if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2355 | - return $res; |
|
| 2356 | - } |
|
| 2357 | - } |
|
| 2358 | - } |
|
| 2359 | - |
|
| 2360 | - return ''; |
|
| 2310 | + // si on demande un truc du genre spip_mots |
|
| 2311 | + // avec aussi spip_mots_liens dans les jointures dispo |
|
| 2312 | + // et qu'on est la |
|
| 2313 | + // il faut privilegier la jointure directe en 2 etapes spip_mots_liens, spip_mots |
|
| 2314 | + if ( |
|
| 2315 | + $checkarrivee |
|
| 2316 | + and is_string($checkarrivee) |
|
| 2317 | + and $a = table_objet($checkarrivee) |
|
| 2318 | + and in_array($a . '_liens', $joints) |
|
| 2319 | + ) { |
|
| 2320 | + if ($res = calculer_lien_externe_init($boucle, $joints, $col, $desc, $cond, $checkarrivee)) { |
|
| 2321 | + return $res; |
|
| 2322 | + } |
|
| 2323 | + } |
|
| 2324 | + foreach ($joints as $joint) { |
|
| 2325 | + if ($arrivee = trouver_champ_exterieur($col, [$joint], $boucle, $checkarrivee)) { |
|
| 2326 | + // alias de table dans le from |
|
| 2327 | + $t = array_search($arrivee[0], $boucle->from); |
|
| 2328 | + // recuperer la cle id_xx eventuellement decomposee en (id_objet,objet) |
|
| 2329 | + $cols = $arrivee[2]; |
|
| 2330 | + // mais on ignore la 3eme cle si presente qui correspond alors au point de depart |
|
| 2331 | + if ((is_countable($cols) ? count($cols) : 0) > 2) { |
|
| 2332 | + array_pop($cols); |
|
| 2333 | + } |
|
| 2334 | + if ($t) { |
|
| 2335 | + // la table est déjà dans le FROM, on vérifie si le champ est utilisé. |
|
| 2336 | + $joindre = false; |
|
| 2337 | + foreach ($cols as $col) { |
|
| 2338 | + $c = '/\b' . $t . ".$col" . '\b/'; |
|
| 2339 | + if (trouver_champ($c, $boucle->where)) { |
|
| 2340 | + $joindre = true; |
|
| 2341 | + } else { |
|
| 2342 | + // mais ca peut etre dans le FIELD pour le Having |
|
| 2343 | + $c = "/FIELD.$t" . ".$col,/"; |
|
| 2344 | + if (trouver_champ($c, $boucle->select)) { |
|
| 2345 | + $joindre = true; |
|
| 2346 | + } |
|
| 2347 | + } |
|
| 2348 | + } |
|
| 2349 | + if (!$joindre) { |
|
| 2350 | + return $t; |
|
| 2351 | + } |
|
| 2352 | + } |
|
| 2353 | + array_pop($arrivee); |
|
| 2354 | + if ($res = calculer_jointure($boucle, [$boucle->id_table, $desc], $arrivee, $cols, $cond, 1)) { |
|
| 2355 | + return $res; |
|
| 2356 | + } |
|
| 2357 | + } |
|
| 2358 | + } |
|
| 2359 | + |
|
| 2360 | + return ''; |
|
| 2361 | 2361 | } |
| 2362 | 2362 | |
| 2363 | 2363 | /** |
@@ -2383,35 +2383,35 @@ discard block |
||
| 2383 | 2383 | * Alias de la table de jointure (Lx) |
| 2384 | 2384 | */ |
| 2385 | 2385 | function calculer_lien_externe_init(&$boucle, $joints, $col, $desc, $cond, $checkarrivee = false) { |
| 2386 | - $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2387 | - |
|
| 2388 | - // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2389 | - $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2390 | - $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2391 | - |
|
| 2392 | - if (!$intermediaire or !$arrivee) { |
|
| 2393 | - return ''; |
|
| 2394 | - } |
|
| 2395 | - array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2396 | - array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2397 | - |
|
| 2398 | - $res = fabrique_jointures( |
|
| 2399 | - $boucle, |
|
| 2400 | - [ |
|
| 2401 | - [ |
|
| 2402 | - $boucle->id_table, |
|
| 2403 | - $intermediaire, |
|
| 2404 | - [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2405 | - ], |
|
| 2406 | - [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2407 | - ], |
|
| 2408 | - $cond, |
|
| 2409 | - $desc, |
|
| 2410 | - $boucle->id_table, |
|
| 2411 | - [$col] |
|
| 2412 | - ); |
|
| 2413 | - |
|
| 2414 | - return $res; |
|
| 2386 | + $primary_arrivee = id_table_objet($checkarrivee); |
|
| 2387 | + |
|
| 2388 | + // [FIXME] $checkarrivee peut-il arriver avec false ???? |
|
| 2389 | + $intermediaire = trouver_champ_exterieur($primary_arrivee, $joints, $boucle, $checkarrivee . '_liens'); |
|
| 2390 | + $arrivee = trouver_champ_exterieur($col, $joints, $boucle, $checkarrivee); |
|
| 2391 | + |
|
| 2392 | + if (!$intermediaire or !$arrivee) { |
|
| 2393 | + return ''; |
|
| 2394 | + } |
|
| 2395 | + array_pop($intermediaire); // enlever la cle en 3eme argument |
|
| 2396 | + array_pop($arrivee); // enlever la cle en 3eme argument |
|
| 2397 | + |
|
| 2398 | + $res = fabrique_jointures( |
|
| 2399 | + $boucle, |
|
| 2400 | + [ |
|
| 2401 | + [ |
|
| 2402 | + $boucle->id_table, |
|
| 2403 | + $intermediaire, |
|
| 2404 | + [id_table_objet($desc['table_objet']), 'id_objet', 'objet', $desc['type']] |
|
| 2405 | + ], |
|
| 2406 | + [reset($intermediaire), $arrivee, $primary_arrivee] |
|
| 2407 | + ], |
|
| 2408 | + $cond, |
|
| 2409 | + $desc, |
|
| 2410 | + $boucle->id_table, |
|
| 2411 | + [$col] |
|
| 2412 | + ); |
|
| 2413 | + |
|
| 2414 | + return $res; |
|
| 2415 | 2415 | } |
| 2416 | 2416 | |
| 2417 | 2417 | |
@@ -2428,17 +2428,17 @@ discard block |
||
| 2428 | 2428 | * false sinon. |
| 2429 | 2429 | **/ |
| 2430 | 2430 | function trouver_champ($champ, $where) { |
| 2431 | - if (!is_array($where)) { |
|
| 2432 | - return preg_match($champ, $where); |
|
| 2433 | - } else { |
|
| 2434 | - foreach ($where as $clause) { |
|
| 2435 | - if (trouver_champ($champ, $clause)) { |
|
| 2436 | - return true; |
|
| 2437 | - } |
|
| 2438 | - } |
|
| 2439 | - |
|
| 2440 | - return false; |
|
| 2441 | - } |
|
| 2431 | + if (!is_array($where)) { |
|
| 2432 | + return preg_match($champ, $where); |
|
| 2433 | + } else { |
|
| 2434 | + foreach ($where as $clause) { |
|
| 2435 | + if (trouver_champ($champ, $clause)) { |
|
| 2436 | + return true; |
|
| 2437 | + } |
|
| 2438 | + } |
|
| 2439 | + |
|
| 2440 | + return false; |
|
| 2441 | + } |
|
| 2442 | 2442 | } |
| 2443 | 2443 | |
| 2444 | 2444 | |
@@ -2464,129 +2464,129 @@ discard block |
||
| 2464 | 2464 | * - string $args_sql Suite des arguments du critère. ? |
| 2465 | 2465 | **/ |
| 2466 | 2466 | function calculer_critere_infixe_ops($idb, &$boucles, $crit) { |
| 2467 | - // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2468 | - if (count($crit->param) == 0) { |
|
| 2469 | - $op = '='; |
|
| 2470 | - $col = $val = $crit->op; |
|
| 2471 | - if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2472 | - $val = $r[2]; |
|
| 2473 | - } |
|
| 2474 | - // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2475 | - if ($val == 'lang') { |
|
| 2476 | - $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2477 | - } else { |
|
| 2478 | - $defaut = null; |
|
| 2479 | - if ($val == 'id_parent') { |
|
| 2480 | - // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2481 | - // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2482 | - // pour eviter l'erreur SQL |
|
| 2483 | - $val = $boucles[$idb]->primary; |
|
| 2484 | - // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2485 | - $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2486 | - } elseif ($val == 'id_enfant') { |
|
| 2487 | - // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2488 | - // de la boucle superieure |
|
| 2489 | - $val = 'id_parent'; |
|
| 2490 | - } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2491 | - // un critere conditionnel sur date est traite a part |
|
| 2492 | - // car la date est mise d'office par SPIP, |
|
| 2493 | - $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2494 | - } |
|
| 2495 | - |
|
| 2496 | - $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2497 | - $val = [kwote($val)]; |
|
| 2498 | - } |
|
| 2499 | - } else { |
|
| 2500 | - // comparaison explicite |
|
| 2501 | - // le phraseur impose que le premier param soit du texte |
|
| 2502 | - $params = $crit->param; |
|
| 2503 | - $op = $crit->op; |
|
| 2504 | - if ($op == '==') { |
|
| 2505 | - $op = 'REGEXP'; |
|
| 2506 | - } |
|
| 2507 | - $col = array_shift($params); |
|
| 2508 | - $col = $col[0]->texte; |
|
| 2509 | - |
|
| 2510 | - $val = []; |
|
| 2511 | - $parent = $boucles[$idb]->id_parent; |
|
| 2512 | - |
|
| 2513 | - // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2514 | - // celui ne sachant pas ce qu'est un critere infixe |
|
| 2515 | - // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2516 | - if ( |
|
| 2517 | - count($params) == 1 |
|
| 2518 | - and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2519 | - and $params[0][0]->type == 'texte' |
|
| 2520 | - and $params[0][2]->type == 'texte' |
|
| 2521 | - and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2522 | - and (($p == "'") or ($p == '"')) |
|
| 2523 | - and $params[0][1]->type == 'champ' |
|
| 2524 | - ) { |
|
| 2525 | - $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2526 | - } else { |
|
| 2527 | - foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2528 | - $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2529 | - if (strcasecmp($op, 'IN') == 0) { |
|
| 2530 | - $val[] = $a; |
|
| 2531 | - } else { |
|
| 2532 | - $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2533 | - } // toujours quoter en char ici |
|
| 2534 | - } |
|
| 2535 | - } |
|
| 2536 | - } |
|
| 2537 | - |
|
| 2538 | - $fct = $args_sql = ''; |
|
| 2539 | - // fonction SQL ? |
|
| 2540 | - // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2541 | - if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2542 | - $fct = $m[1]; |
|
| 2543 | - preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2544 | - $col = $a[1]; |
|
| 2545 | - if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2546 | - $col = $m[1]; |
|
| 2547 | - $args_sql = $m[2]; |
|
| 2548 | - } |
|
| 2549 | - $args_sql .= $a[2]; |
|
| 2550 | - } |
|
| 2551 | - |
|
| 2552 | - return [$fct, $col, $op, $val, $args_sql]; |
|
| 2467 | + // cas d'une valeur comparee a elle-meme ou son referent |
|
| 2468 | + if (count($crit->param) == 0) { |
|
| 2469 | + $op = '='; |
|
| 2470 | + $col = $val = $crit->op; |
|
| 2471 | + if (preg_match('/^(.*)\.(.*)$/', $col, $r)) { |
|
| 2472 | + $val = $r[2]; |
|
| 2473 | + } |
|
| 2474 | + // Cas special {lang} : aller chercher $GLOBALS['spip_lang'] |
|
| 2475 | + if ($val == 'lang') { |
|
| 2476 | + $val = [kwote('$GLOBALS[\'spip_lang\']')]; |
|
| 2477 | + } else { |
|
| 2478 | + $defaut = null; |
|
| 2479 | + if ($val == 'id_parent') { |
|
| 2480 | + // Si id_parent, comparer l'id_parent avec l'id_objet |
|
| 2481 | + // de la boucle superieure.... faudrait verifier qu'il existe |
|
| 2482 | + // pour eviter l'erreur SQL |
|
| 2483 | + $val = $boucles[$idb]->primary; |
|
| 2484 | + // mais si pas de boucle superieure, prendre id_parent dans l'env |
|
| 2485 | + $defaut = "(\$Pile[0]['id_parent'] ?? null)"; |
|
| 2486 | + } elseif ($val == 'id_enfant') { |
|
| 2487 | + // Si id_enfant, comparer l'id_objet avec l'id_parent |
|
| 2488 | + // de la boucle superieure |
|
| 2489 | + $val = 'id_parent'; |
|
| 2490 | + } elseif ($crit->cond and ($col == 'date' or $col == 'date_redac')) { |
|
| 2491 | + // un critere conditionnel sur date est traite a part |
|
| 2492 | + // car la date est mise d'office par SPIP, |
|
| 2493 | + $defaut = "(\$Pile[0]['{$col}_default']?'':\$Pile[0]['" . $col . "'])"; |
|
| 2494 | + } |
|
| 2495 | + |
|
| 2496 | + $val = calculer_argument_precedent($idb, $val, $boucles, $defaut); |
|
| 2497 | + $val = [kwote($val)]; |
|
| 2498 | + } |
|
| 2499 | + } else { |
|
| 2500 | + // comparaison explicite |
|
| 2501 | + // le phraseur impose que le premier param soit du texte |
|
| 2502 | + $params = $crit->param; |
|
| 2503 | + $op = $crit->op; |
|
| 2504 | + if ($op == '==') { |
|
| 2505 | + $op = 'REGEXP'; |
|
| 2506 | + } |
|
| 2507 | + $col = array_shift($params); |
|
| 2508 | + $col = $col[0]->texte; |
|
| 2509 | + |
|
| 2510 | + $val = []; |
|
| 2511 | + $parent = $boucles[$idb]->id_parent; |
|
| 2512 | + |
|
| 2513 | + // Dans le cas {x=='#DATE'} etc, defaire le travail du phraseur, |
|
| 2514 | + // celui ne sachant pas ce qu'est un critere infixe |
|
| 2515 | + // et a fortiori son 2e operande qu'entoure " ou ' |
|
| 2516 | + if ( |
|
| 2517 | + count($params) == 1 |
|
| 2518 | + and (is_countable($params[0]) ? count($params[0]) : 0) == 3 |
|
| 2519 | + and $params[0][0]->type == 'texte' |
|
| 2520 | + and $params[0][2]->type == 'texte' |
|
| 2521 | + and ($p = $params[0][0]->texte) == $params[0][2]->texte |
|
| 2522 | + and (($p == "'") or ($p == '"')) |
|
| 2523 | + and $params[0][1]->type == 'champ' |
|
| 2524 | + ) { |
|
| 2525 | + $val[] = "$p\\$p#" . $params[0][1]->nom_champ . "\\$p$p"; |
|
| 2526 | + } else { |
|
| 2527 | + foreach ((($op != 'IN') ? $params : calculer_vieux_in($params)) as $p) { |
|
| 2528 | + $a = calculer_liste($p, $idb, $boucles, $parent); |
|
| 2529 | + if (strcasecmp($op, 'IN') == 0) { |
|
| 2530 | + $val[] = $a; |
|
| 2531 | + } else { |
|
| 2532 | + $val[] = kwote($a, $boucles[$idb]->sql_serveur, '@@defaultcast@@'); |
|
| 2533 | + } // toujours quoter en char ici |
|
| 2534 | + } |
|
| 2535 | + } |
|
| 2536 | + } |
|
| 2537 | + |
|
| 2538 | + $fct = $args_sql = ''; |
|
| 2539 | + // fonction SQL ? |
|
| 2540 | + // chercher FONCTION(champ) tel que CONCAT(titre,descriptif) |
|
| 2541 | + if (preg_match('/^(.*)' . SQL_ARGS . '$/', $col, $m)) { |
|
| 2542 | + $fct = $m[1]; |
|
| 2543 | + preg_match('/^\(([^,]*)(.*)\)$/', $m[2], $a); |
|
| 2544 | + $col = $a[1]; |
|
| 2545 | + if (preg_match('/^(\S*)(\s+AS\s+.*)$/i', $col, $m)) { |
|
| 2546 | + $col = $m[1]; |
|
| 2547 | + $args_sql = $m[2]; |
|
| 2548 | + } |
|
| 2549 | + $args_sql .= $a[2]; |
|
| 2550 | + } |
|
| 2551 | + |
|
| 2552 | + return [$fct, $col, $op, $val, $args_sql]; |
|
| 2553 | 2553 | } |
| 2554 | 2554 | |
| 2555 | 2555 | // compatibilite ancienne version |
| 2556 | 2556 | |
| 2557 | 2557 | function calculer_vieux_in($params) { |
| 2558 | - $deb = $params[0][0]; |
|
| 2559 | - $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2560 | - $last = $params[$k]; |
|
| 2561 | - $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2562 | - $last = $last[$j]; |
|
| 2563 | - $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2564 | - |
|
| 2565 | - if ( |
|
| 2566 | - !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2567 | - && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2568 | - ) { |
|
| 2569 | - return $params; |
|
| 2570 | - } |
|
| 2571 | - $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2572 | - // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2573 | - $last = $params[$k][$j]; |
|
| 2574 | - $n = strlen($last->texte); |
|
| 2575 | - $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2576 | - $newp = []; |
|
| 2577 | - foreach ($params as $v) { |
|
| 2578 | - if ($v[0]->type != 'texte') { |
|
| 2579 | - $newp[] = $v; |
|
| 2580 | - } else { |
|
| 2581 | - foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2582 | - $t = new Texte(); |
|
| 2583 | - $t->texte = $x; |
|
| 2584 | - $newp[] = [$t]; |
|
| 2585 | - } |
|
| 2586 | - } |
|
| 2587 | - } |
|
| 2588 | - |
|
| 2589 | - return $newp; |
|
| 2558 | + $deb = $params[0][0]; |
|
| 2559 | + $k = (is_countable($params) ? count($params) : 0) - 1; |
|
| 2560 | + $last = $params[$k]; |
|
| 2561 | + $j = (is_countable($last) ? count($last) : 0) - 1; |
|
| 2562 | + $last = $last[$j]; |
|
| 2563 | + $n = isset($last->texte) ? strlen($last->texte) : 0; |
|
| 2564 | + |
|
| 2565 | + if ( |
|
| 2566 | + !((isset($deb->texte[0]) and $deb->texte[0] == '(') |
|
| 2567 | + && (isset($last->texte[$n - 1]) and $last->texte[$n - 1] == ')')) |
|
| 2568 | + ) { |
|
| 2569 | + return $params; |
|
| 2570 | + } |
|
| 2571 | + $params[0][0]->texte = substr($deb->texte, 1); |
|
| 2572 | + // attention, on peut avoir k=0,j=0 ==> recalculer |
|
| 2573 | + $last = $params[$k][$j]; |
|
| 2574 | + $n = strlen($last->texte); |
|
| 2575 | + $params[$k][$j]->texte = substr($last->texte, 0, $n - 1); |
|
| 2576 | + $newp = []; |
|
| 2577 | + foreach ($params as $v) { |
|
| 2578 | + if ($v[0]->type != 'texte') { |
|
| 2579 | + $newp[] = $v; |
|
| 2580 | + } else { |
|
| 2581 | + foreach (explode(',', $v[0]->texte) as $x) { |
|
| 2582 | + $t = new Texte(); |
|
| 2583 | + $t->texte = $x; |
|
| 2584 | + $newp[] = [$t]; |
|
| 2585 | + } |
|
| 2586 | + } |
|
| 2587 | + } |
|
| 2588 | + |
|
| 2589 | + return $newp; |
|
| 2590 | 2590 | } |
| 2591 | 2591 | |
| 2592 | 2592 | /** |
@@ -2605,95 +2605,95 @@ discard block |
||
| 2605 | 2605 | * - nom de la colonne de date (si le calcul n'est pas relatif) |
| 2606 | 2606 | **/ |
| 2607 | 2607 | function calculer_critere_infixe_date($idb, &$boucles, $col) { |
| 2608 | - if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2609 | - return ''; |
|
| 2610 | - } |
|
| 2611 | - |
|
| 2612 | - $boucle = $boucles[$idb]; |
|
| 2613 | - $table = $boucle->show; |
|
| 2614 | - |
|
| 2615 | - // si c'est une colonne de la table, ne rien faire |
|
| 2616 | - if (isset($table['field'][$col])) { |
|
| 2617 | - return ''; |
|
| 2618 | - } |
|
| 2619 | - |
|
| 2620 | - // Le type de critère à prendre en compte |
|
| 2621 | - $col = $regs[1]; |
|
| 2622 | - |
|
| 2623 | - // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2624 | - if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2625 | - # Recherche de l'existence du champ date_xxxx, |
|
| 2626 | - # si oui choisir ce champ, sinon choisir xxxx |
|
| 2627 | - if (isset($table['field']["date$suite"])) { |
|
| 2628 | - $date_orig = 'date' . $suite; |
|
| 2629 | - } else { |
|
| 2630 | - $date_orig = substr($suite, 1); |
|
| 2631 | - } |
|
| 2632 | - |
|
| 2633 | - $pred = $date_orig; |
|
| 2634 | - } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2635 | - // Si aucune déclaration trouvée, on quitte |
|
| 2636 | - if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2637 | - return ''; |
|
| 2638 | - } |
|
| 2639 | - // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2640 | - $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2641 | - |
|
| 2642 | - // Si c'est pour du relatif |
|
| 2643 | - if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2644 | - $pred = 'date'; |
|
| 2645 | - } |
|
| 2646 | - } |
|
| 2647 | - |
|
| 2648 | - $date_compare = "\"' . normaliser_date(" . |
|
| 2649 | - calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2650 | - ") . '\""; |
|
| 2651 | - |
|
| 2652 | - $col_vraie = $date_orig; |
|
| 2653 | - $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2654 | - |
|
| 2655 | - switch ($col) { |
|
| 2656 | - case 'date': |
|
| 2657 | - $col = $date_orig; |
|
| 2658 | - break; |
|
| 2659 | - case 'jour': |
|
| 2660 | - $col = "DAYOFMONTH($date_orig)"; |
|
| 2661 | - break; |
|
| 2662 | - case 'mois': |
|
| 2663 | - $col = "MONTH($date_orig)"; |
|
| 2664 | - break; |
|
| 2665 | - case 'annee': |
|
| 2666 | - $col = "YEAR($date_orig)"; |
|
| 2667 | - break; |
|
| 2668 | - case 'heure': |
|
| 2669 | - $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2670 | - break; |
|
| 2671 | - case 'age': |
|
| 2672 | - $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2673 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2674 | - break; |
|
| 2675 | - case 'age_relatif': |
|
| 2676 | - $col = calculer_param_date($date_compare, $date_orig); |
|
| 2677 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | - break; |
|
| 2679 | - case 'jour_relatif': |
|
| 2680 | - $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2681 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | - break; |
|
| 2683 | - case 'mois_relatif': |
|
| 2684 | - $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2685 | - $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2686 | - ')-YEAR(' . $date_orig . '))'; |
|
| 2687 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2688 | - break; |
|
| 2689 | - case 'annee_relatif': |
|
| 2690 | - $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2691 | - $date_orig . ')'; |
|
| 2692 | - $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | - break; |
|
| 2694 | - } |
|
| 2695 | - |
|
| 2696 | - return [$col, $col_vraie]; |
|
| 2608 | + if (!preg_match(',^((age|jour|mois|annee)_relatif|date|mois|annee|jour|heure|age)(_[a-z_]+)?$,', $col, $regs)) { |
|
| 2609 | + return ''; |
|
| 2610 | + } |
|
| 2611 | + |
|
| 2612 | + $boucle = $boucles[$idb]; |
|
| 2613 | + $table = $boucle->show; |
|
| 2614 | + |
|
| 2615 | + // si c'est une colonne de la table, ne rien faire |
|
| 2616 | + if (isset($table['field'][$col])) { |
|
| 2617 | + return ''; |
|
| 2618 | + } |
|
| 2619 | + |
|
| 2620 | + // Le type de critère à prendre en compte |
|
| 2621 | + $col = $regs[1]; |
|
| 2622 | + |
|
| 2623 | + // Si on trouve un nom de champ date précis, on l'utilise, pas besoin de déclaration dans l'API objet |
|
| 2624 | + if (isset($regs[3]) and $suite = $regs[3]) { |
|
| 2625 | + # Recherche de l'existence du champ date_xxxx, |
|
| 2626 | + # si oui choisir ce champ, sinon choisir xxxx |
|
| 2627 | + if (isset($table['field']["date$suite"])) { |
|
| 2628 | + $date_orig = 'date' . $suite; |
|
| 2629 | + } else { |
|
| 2630 | + $date_orig = substr($suite, 1); |
|
| 2631 | + } |
|
| 2632 | + |
|
| 2633 | + $pred = $date_orig; |
|
| 2634 | + } else { // Sinon il FAUT avoir déclaré le champ date officiel dans l'API objet |
|
| 2635 | + // Si aucune déclaration trouvée, on quitte |
|
| 2636 | + if (!$table['date'] && !isset($GLOBALS['table_date'][$table['id_table']])) { |
|
| 2637 | + return ''; |
|
| 2638 | + } |
|
| 2639 | + // Par défaut, on prend le champ date déclaré dans l'API |
|
| 2640 | + $pred = $date_orig = $GLOBALS['table_date'][$table['id_table']] ?? $table['date']; |
|
| 2641 | + |
|
| 2642 | + // Si c'est pour du relatif |
|
| 2643 | + if (isset($regs[2]) and $rel = $regs[2]) { |
|
| 2644 | + $pred = 'date'; |
|
| 2645 | + } |
|
| 2646 | + } |
|
| 2647 | + |
|
| 2648 | + $date_compare = "\"' . normaliser_date(" . |
|
| 2649 | + calculer_argument_precedent($idb, $pred, $boucles) . |
|
| 2650 | + ") . '\""; |
|
| 2651 | + |
|
| 2652 | + $col_vraie = $date_orig; |
|
| 2653 | + $date_orig = $boucle->id_table . '.' . $date_orig; |
|
| 2654 | + |
|
| 2655 | + switch ($col) { |
|
| 2656 | + case 'date': |
|
| 2657 | + $col = $date_orig; |
|
| 2658 | + break; |
|
| 2659 | + case 'jour': |
|
| 2660 | + $col = "DAYOFMONTH($date_orig)"; |
|
| 2661 | + break; |
|
| 2662 | + case 'mois': |
|
| 2663 | + $col = "MONTH($date_orig)"; |
|
| 2664 | + break; |
|
| 2665 | + case 'annee': |
|
| 2666 | + $col = "YEAR($date_orig)"; |
|
| 2667 | + break; |
|
| 2668 | + case 'heure': |
|
| 2669 | + $col = "DATE_FORMAT($date_orig, \\'%H:%i\\')"; |
|
| 2670 | + break; |
|
| 2671 | + case 'age': |
|
| 2672 | + $col = calculer_param_date("\'' . date('Y-m-d H:i:00') . '\'", $date_orig); |
|
| 2673 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2674 | + break; |
|
| 2675 | + case 'age_relatif': |
|
| 2676 | + $col = calculer_param_date($date_compare, $date_orig); |
|
| 2677 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2678 | + break; |
|
| 2679 | + case 'jour_relatif': |
|
| 2680 | + $col = '(TO_DAYS(' . $date_compare . ')-TO_DAYS(' . $date_orig . '))'; |
|
| 2681 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2682 | + break; |
|
| 2683 | + case 'mois_relatif': |
|
| 2684 | + $col = 'MONTH(' . $date_compare . ')-MONTH(' . |
|
| 2685 | + $date_orig . ')+12*(YEAR(' . $date_compare . |
|
| 2686 | + ')-YEAR(' . $date_orig . '))'; |
|
| 2687 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2688 | + break; |
|
| 2689 | + case 'annee_relatif': |
|
| 2690 | + $col = 'YEAR(' . $date_compare . ')-YEAR(' . |
|
| 2691 | + $date_orig . ')'; |
|
| 2692 | + $col_vraie = '';// comparer a un int (par defaut) |
|
| 2693 | + break; |
|
| 2694 | + } |
|
| 2695 | + |
|
| 2696 | + return [$col, $col_vraie]; |
|
| 2697 | 2697 | } |
| 2698 | 2698 | |
| 2699 | 2699 | /** |
@@ -2712,16 +2712,16 @@ discard block |
||
| 2712 | 2712 | * de colonne SQL et une date. |
| 2713 | 2713 | **/ |
| 2714 | 2714 | function calculer_param_date($date_compare, $date_orig) { |
| 2715 | - if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2716 | - $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2717 | - $date_compare = '\'$x\''; |
|
| 2718 | - } else { |
|
| 2719 | - $init = $date_compare; |
|
| 2720 | - } |
|
| 2721 | - |
|
| 2722 | - return |
|
| 2723 | - // optimisation : mais prevoir le support SQLite avant |
|
| 2724 | - "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2715 | + if (preg_match(",'\" *\.(.*)\. *\"',", $date_compare, $r)) { |
|
| 2716 | + $init = "'\" . (\$x = $r[1]) . \"'"; |
|
| 2717 | + $date_compare = '\'$x\''; |
|
| 2718 | + } else { |
|
| 2719 | + $init = $date_compare; |
|
| 2720 | + } |
|
| 2721 | + |
|
| 2722 | + return |
|
| 2723 | + // optimisation : mais prevoir le support SQLite avant |
|
| 2724 | + "TIMESTAMPDIFF(HOUR,$date_orig,$init)/24"; |
|
| 2725 | 2725 | } |
| 2726 | 2726 | |
| 2727 | 2727 | /** |
@@ -2739,20 +2739,20 @@ discard block |
||
| 2739 | 2739 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2740 | 2740 | */ |
| 2741 | 2741 | function critere_DATA_source_dist($idb, &$boucles, $crit) { |
| 2742 | - $boucle = &$boucles[$idb]; |
|
| 2743 | - |
|
| 2744 | - $args = []; |
|
| 2745 | - foreach ($crit->param as &$param) { |
|
| 2746 | - array_push( |
|
| 2747 | - $args, |
|
| 2748 | - calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2749 | - ); |
|
| 2750 | - } |
|
| 2742 | + $boucle = &$boucles[$idb]; |
|
| 2751 | 2743 | |
| 2752 | - $boucle->hash .= ' |
|
| 2744 | + $args = []; |
|
| 2745 | + foreach ($crit->param as &$param) { |
|
| 2746 | + array_push( |
|
| 2747 | + $args, |
|
| 2748 | + calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) |
|
| 2749 | + ); |
|
| 2750 | + } |
|
| 2751 | + |
|
| 2752 | + $boucle->hash .= ' |
|
| 2753 | 2753 | $command[\'sourcemode\'] = ' . array_shift($args) . ";\n"; |
| 2754 | 2754 | |
| 2755 | - $boucle->hash .= ' |
|
| 2755 | + $boucle->hash .= ' |
|
| 2756 | 2756 | $command[\'source\'] = array(' . join(', ', $args) . ");\n"; |
| 2757 | 2757 | } |
| 2758 | 2758 | |
@@ -2770,8 +2770,8 @@ discard block |
||
| 2770 | 2770 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2771 | 2771 | */ |
| 2772 | 2772 | function critere_DATA_datacache_dist($idb, &$boucles, $crit) { |
| 2773 | - $boucle = &$boucles[$idb]; |
|
| 2774 | - $boucle->hash .= ' |
|
| 2773 | + $boucle = &$boucles[$idb]; |
|
| 2774 | + $boucle->hash .= ' |
|
| 2775 | 2775 | $command[\'datacache\'] = ' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2776 | 2776 | } |
| 2777 | 2777 | |
@@ -2787,12 +2787,12 @@ discard block |
||
| 2787 | 2787 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2788 | 2788 | */ |
| 2789 | 2789 | function critere_php_args_dist($idb, &$boucles, $crit) { |
| 2790 | - $boucle = &$boucles[$idb]; |
|
| 2791 | - $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2792 | - foreach ($crit->param as $param) { |
|
| 2793 | - $boucle->hash .= ' |
|
| 2790 | + $boucle = &$boucles[$idb]; |
|
| 2791 | + $boucle->hash .= '$command[\'args\']=array();'; |
|
| 2792 | + foreach ($crit->param as $param) { |
|
| 2793 | + $boucle->hash .= ' |
|
| 2794 | 2794 | $command[\'args\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2795 | - } |
|
| 2795 | + } |
|
| 2796 | 2796 | } |
| 2797 | 2797 | |
| 2798 | 2798 | /** |
@@ -2809,16 +2809,16 @@ discard block |
||
| 2809 | 2809 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2810 | 2810 | */ |
| 2811 | 2811 | function critere_DATA_liste_dist($idb, &$boucles, $crit) { |
| 2812 | - $boucle = &$boucles[$idb]; |
|
| 2813 | - $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2814 | - foreach ($crit->param as $param) { |
|
| 2815 | - $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2816 | - $param, |
|
| 2817 | - $idb, |
|
| 2818 | - $boucles, |
|
| 2819 | - $boucles[$idb]->id_parent |
|
| 2820 | - ) . ";\n"; |
|
| 2821 | - } |
|
| 2812 | + $boucle = &$boucles[$idb]; |
|
| 2813 | + $boucle->hash .= "\n\t" . '$command[\'liste\'] = array();' . "\n"; |
|
| 2814 | + foreach ($crit->param as $param) { |
|
| 2815 | + $boucle->hash .= "\t" . '$command[\'liste\'][] = ' . calculer_liste( |
|
| 2816 | + $param, |
|
| 2817 | + $idb, |
|
| 2818 | + $boucles, |
|
| 2819 | + $boucles[$idb]->id_parent |
|
| 2820 | + ) . ";\n"; |
|
| 2821 | + } |
|
| 2822 | 2822 | } |
| 2823 | 2823 | |
| 2824 | 2824 | /** |
@@ -2843,16 +2843,16 @@ discard block |
||
| 2843 | 2843 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2844 | 2844 | */ |
| 2845 | 2845 | function critere_DATA_enum_dist($idb, &$boucles, $crit) { |
| 2846 | - $boucle = &$boucles[$idb]; |
|
| 2847 | - $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2848 | - foreach ($crit->param as $param) { |
|
| 2849 | - $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2850 | - $param, |
|
| 2851 | - $idb, |
|
| 2852 | - $boucles, |
|
| 2853 | - $boucles[$idb]->id_parent |
|
| 2854 | - ) . ";\n"; |
|
| 2855 | - } |
|
| 2846 | + $boucle = &$boucles[$idb]; |
|
| 2847 | + $boucle->hash .= "\n\t" . '$command[\'enum\'] = array();' . "\n"; |
|
| 2848 | + foreach ($crit->param as $param) { |
|
| 2849 | + $boucle->hash .= "\t" . '$command[\'enum\'][] = ' . calculer_liste( |
|
| 2850 | + $param, |
|
| 2851 | + $idb, |
|
| 2852 | + $boucles, |
|
| 2853 | + $boucles[$idb]->id_parent |
|
| 2854 | + ) . ";\n"; |
|
| 2855 | + } |
|
| 2856 | 2856 | } |
| 2857 | 2857 | |
| 2858 | 2858 | /** |
@@ -2867,11 +2867,11 @@ discard block |
||
| 2867 | 2867 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2868 | 2868 | */ |
| 2869 | 2869 | function critere_DATA_datapath_dist($idb, &$boucles, $crit) { |
| 2870 | - $boucle = &$boucles[$idb]; |
|
| 2871 | - foreach ($crit->param as $param) { |
|
| 2872 | - $boucle->hash .= ' |
|
| 2870 | + $boucle = &$boucles[$idb]; |
|
| 2871 | + foreach ($crit->param as $param) { |
|
| 2872 | + $boucle->hash .= ' |
|
| 2873 | 2873 | $command[\'datapath\'][] = ' . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ';'; |
| 2874 | - } |
|
| 2874 | + } |
|
| 2875 | 2875 | } |
| 2876 | 2876 | |
| 2877 | 2877 | |
@@ -2903,20 +2903,20 @@ discard block |
||
| 2903 | 2903 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2904 | 2904 | */ |
| 2905 | 2905 | function critere_si_dist($idb, &$boucles, $crit) { |
| 2906 | - $boucle = &$boucles[$idb]; |
|
| 2907 | - // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2908 | - // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2909 | - // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2910 | - $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2911 | - if ($crit->param) { |
|
| 2912 | - foreach ($crit->param as $param) { |
|
| 2913 | - $boucle->hash .= "\t\$command['si'][] = " |
|
| 2914 | - . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2915 | - } |
|
| 2916 | - // interdire {si 0} aussi ! |
|
| 2917 | - } else { |
|
| 2918 | - $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2919 | - } |
|
| 2906 | + $boucle = &$boucles[$idb]; |
|
| 2907 | + // il faut initialiser 1 fois le tableau a chaque appel de la boucle |
|
| 2908 | + // (par exemple lorsque notre boucle est appelee dans une autre boucle) |
|
| 2909 | + // mais ne pas l'initialiser n fois si il y a n criteres {si } dans la boucle ! |
|
| 2910 | + $boucle->hash .= "\n\tif (!isset(\$si_init)) { \$command['si'] = array(); \$si_init = true; }\n"; |
|
| 2911 | + if ($crit->param) { |
|
| 2912 | + foreach ($crit->param as $param) { |
|
| 2913 | + $boucle->hash .= "\t\$command['si'][] = " |
|
| 2914 | + . calculer_liste($param, $idb, $boucles, $boucles[$idb]->id_parent) . ";\n"; |
|
| 2915 | + } |
|
| 2916 | + // interdire {si 0} aussi ! |
|
| 2917 | + } else { |
|
| 2918 | + $boucle->hash .= '$command[\'si\'][] = 0;'; |
|
| 2919 | + } |
|
| 2920 | 2920 | } |
| 2921 | 2921 | |
| 2922 | 2922 | /** |
@@ -2933,8 +2933,8 @@ discard block |
||
| 2933 | 2933 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2934 | 2934 | */ |
| 2935 | 2935 | function critere_POUR_tableau_dist($idb, &$boucles, $crit) { |
| 2936 | - $boucle = &$boucles[$idb]; |
|
| 2937 | - $boucle->hash .= ' |
|
| 2936 | + $boucle = &$boucles[$idb]; |
|
| 2937 | + $boucle->hash .= ' |
|
| 2938 | 2938 | $command[\'source\'] = array(' . calculer_liste($crit->param[0], $idb, $boucles, $boucles[$idb]->id_parent) . '); |
| 2939 | 2939 | $command[\'sourcemode\'] = \'table\';'; |
| 2940 | 2940 | } |
@@ -2955,27 +2955,27 @@ discard block |
||
| 2955 | 2955 | */ |
| 2956 | 2956 | function critere_noeud_dist($idb, &$boucles, $crit) { |
| 2957 | 2957 | |
| 2958 | - $not = $crit->not; |
|
| 2959 | - $boucle = &$boucles[$idb]; |
|
| 2960 | - $primary = $boucle->primary; |
|
| 2958 | + $not = $crit->not; |
|
| 2959 | + $boucle = &$boucles[$idb]; |
|
| 2960 | + $primary = $boucle->primary; |
|
| 2961 | 2961 | |
| 2962 | - if (!$primary or strpos($primary, ',')) { |
|
| 2963 | - erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2962 | + if (!$primary or strpos($primary, ',')) { |
|
| 2963 | + erreur_squelette(_T('zbug_doublon_sur_table_sans_cle_primaire'), $boucle); |
|
| 2964 | 2964 | |
| 2965 | - return; |
|
| 2966 | - } |
|
| 2967 | - $table = $boucle->type_requete; |
|
| 2968 | - $table_sql = table_objet_sql(objet_type($table)); |
|
| 2965 | + return; |
|
| 2966 | + } |
|
| 2967 | + $table = $boucle->type_requete; |
|
| 2968 | + $table_sql = table_objet_sql(objet_type($table)); |
|
| 2969 | 2969 | |
| 2970 | - $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2970 | + $id_parent = $GLOBALS['exceptions_des_tables'][$boucle->id_table]['id_parent'] ?? 'id_parent'; |
|
| 2971 | 2971 | |
| 2972 | - $in = 'IN'; |
|
| 2973 | - $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2974 | - if ($not) { |
|
| 2975 | - $where = ["'NOT'", $where]; |
|
| 2976 | - } |
|
| 2972 | + $in = 'IN'; |
|
| 2973 | + $where = ["'IN'", "'$boucle->id_table." . "$primary'", "'('.sql_get_select('$id_parent', '$table_sql').')'"]; |
|
| 2974 | + if ($not) { |
|
| 2975 | + $where = ["'NOT'", $where]; |
|
| 2976 | + } |
|
| 2977 | 2977 | |
| 2978 | - $boucle->where[] = $where; |
|
| 2978 | + $boucle->where[] = $where; |
|
| 2979 | 2979 | } |
| 2980 | 2980 | |
| 2981 | 2981 | /** |
@@ -2991,8 +2991,8 @@ discard block |
||
| 2991 | 2991 | * @param Critere $crit Paramètres du critère dans cette boucle |
| 2992 | 2992 | */ |
| 2993 | 2993 | function critere_feuille_dist($idb, &$boucles, $crit) { |
| 2994 | - $not = $crit->not; |
|
| 2995 | - $crit->not = $not ? false : true; |
|
| 2996 | - critere_noeud_dist($idb, $boucles, $crit); |
|
| 2997 | - $crit->not = $not; |
|
| 2994 | + $not = $crit->not; |
|
| 2995 | + $crit->not = $not ? false : true; |
|
| 2996 | + critere_noeud_dist($idb, $boucles, $crit); |
|
| 2997 | + $crit->not = $not; |
|
| 2998 | 2998 | } |