@@ -524,8 +524,7 @@ discard block |
||
| 524 | 524 | process_image_svg_identite($ret); |
| 525 | 525 | $ret['creer'] = false; |
| 526 | 526 | } |
| 527 | - } |
|
| 528 | - else { |
|
| 527 | + } else { |
|
| 529 | 528 | if (!function_exists($ret['fonction_imagecreatefrom'])) { |
| 530 | 529 | return false; |
| 531 | 530 | } |
@@ -628,8 +627,7 @@ discard block |
||
| 628 | 627 | |
| 629 | 628 | if (isset($info['mime'])) { |
| 630 | 629 | $mime = $info['mime']; |
| 631 | - } |
|
| 632 | - else { |
|
| 630 | + } else { |
|
| 633 | 631 | $mime = image_type_to_mime_type($info[2]); |
| 634 | 632 | } |
| 635 | 633 | |
@@ -1408,9 +1406,7 @@ discard block |
||
| 1408 | 1406 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1409 | 1407 | $vignette = $destination . '.' . $format; |
| 1410 | 1408 | @copy($image, $vignette); |
| 1411 | - } |
|
| 1412 | - |
|
| 1413 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1409 | + } elseif ($valeurs['format_source'] === 'svg') { |
|
| 1414 | 1410 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1415 | 1411 | $format_sortie = 'svg'; |
| 1416 | 1412 | $vignette = $destination . '.' . $format_sortie; |
@@ -1846,8 +1842,7 @@ discard block |
||
| 1846 | 1842 | $date = test_espace_prive() ? ('?' . $date) : ''; |
| 1847 | 1843 | |
| 1848 | 1844 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1849 | - } |
|
| 1850 | - else { |
|
| 1845 | + } else { |
|
| 1851 | 1846 | # BMP, tiff ... les redacteurs osent tout! |
| 1852 | 1847 | return $img; |
| 1853 | 1848 | } |
@@ -43,13 +43,13 @@ discard block |
||
| 43 | 43 | $blue = dechex($blue); |
| 44 | 44 | |
| 45 | 45 | if (strlen($red) == 1) { |
| 46 | - $red = '0' . $red; |
|
| 46 | + $red = '0'.$red; |
|
| 47 | 47 | } |
| 48 | 48 | if (strlen($green) == 1) { |
| 49 | - $green = '0' . $green; |
|
| 49 | + $green = '0'.$green; |
|
| 50 | 50 | } |
| 51 | 51 | if (strlen($blue) == 1) { |
| 52 | - $blue = '0' . $blue; |
|
| 52 | + $blue = '0'.$blue; |
|
| 53 | 53 | } |
| 54 | 54 | |
| 55 | 55 | return "$red$green$blue"; |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $couleur = couleur_html_to_hex($couleur); |
| 68 | 68 | $couleur = ltrim($couleur, '#'); |
| 69 | 69 | if (strlen($couleur) === 3) { |
| 70 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 70 | + $couleur = $couleur[0].$couleur[0].$couleur[1].$couleur[1].$couleur[2].$couleur[2]; |
|
| 71 | 71 | } |
| 72 | 72 | $retour = []; |
| 73 | 73 | $retour['red'] = hexdec(substr($couleur, 0, 2)); |
@@ -125,9 +125,9 @@ discard block |
||
| 125 | 125 | $var_G = ($G / 255); |
| 126 | 126 | $var_B = ($B / 255); |
| 127 | 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 |
|
| 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 | 131 | |
| 132 | 132 | $L = ($var_Max + $var_Min) / 2; |
| 133 | 133 | |
@@ -189,7 +189,7 @@ discard block |
||
| 189 | 189 | */ |
| 190 | 190 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 191 | 191 | // helper |
| 192 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 192 | + $hue_2_rgb = function($v1, $v2, $vH) { |
|
| 193 | 193 | if ($vH < 0) { |
| 194 | 194 | $vH += 1; |
| 195 | 195 | } |
@@ -321,11 +321,11 @@ discard block |
||
| 321 | 321 | $img = "<img src='$source' />"; |
| 322 | 322 | } elseif ( |
| 323 | 323 | preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
| 324 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 324 | + and $extension = _image_trouver_extension_depuis_mime('image/'.$regs[1]) |
|
| 325 | 325 | and in_array($extension, _image_extensions_acceptees_en_entree()) |
| 326 | 326 | ) { |
| 327 | 327 | # gerer img src="data:....base64" |
| 328 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 328 | + $local = sous_repertoire(_DIR_VAR, 'image-data').md5($regs[2]).'.'._image_extension_normalisee($extension); |
|
| 329 | 329 | if (!file_exists($local)) { |
| 330 | 330 | ecrire_fichier($local, base64_decode($regs[2])); |
| 331 | 331 | } |
@@ -342,7 +342,7 @@ discard block |
||
| 342 | 342 | // les protocoles web prennent au moins 3 lettres |
| 343 | 343 | if (tester_url_absolue($source)) { |
| 344 | 344 | include_spip('inc/distant'); |
| 345 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 345 | + $fichier = _DIR_RACINE.copie_locale($source); |
|
| 346 | 346 | if (!$fichier) { |
| 347 | 347 | return ''; |
| 348 | 348 | } |
@@ -440,9 +440,9 @@ discard block |
||
| 440 | 440 | // on garde la terminaison initiale car image simplement copiee |
| 441 | 441 | // et on postfixe son nom avec un md5 du path |
| 442 | 442 | $terminaison_dest = $terminaison; |
| 443 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 443 | + $fichier_dest .= '-'.substr(md5("$identifiant"), 0, 5); |
|
| 444 | 444 | } else { |
| 445 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 445 | + $fichier_dest .= '-'.substr(md5("$identifiant-$effet"), 0, 5); |
|
| 446 | 446 | } |
| 447 | 447 | $cache = sous_repertoire(_DIR_VAR, $cache); |
| 448 | 448 | $cache = sous_repertoire($cache, $effet); |
@@ -453,7 +453,7 @@ discard block |
||
| 453 | 453 | $fichier_dest = substr($fichier_dest, 2); |
| 454 | 454 | } |
| 455 | 455 | |
| 456 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 456 | + $fichier_dest = $cache.$fichier_dest.'.'.$terminaison_dest; |
|
| 457 | 457 | |
| 458 | 458 | $GLOBALS['images_calculees'][] = $fichier_dest; |
| 459 | 459 | |
@@ -491,15 +491,15 @@ discard block |
||
| 491 | 491 | |
| 492 | 492 | if ($creer) { |
| 493 | 493 | spip_log( |
| 494 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 495 | - 'images' . _LOG_DEBUG |
|
| 494 | + 'filtre image '.($fonction_creation ? reset($fonction_creation) : '')."[$effet] sur $fichier", |
|
| 495 | + 'images'._LOG_DEBUG |
|
| 496 | 496 | ); |
| 497 | 497 | } |
| 498 | 498 | |
| 499 | 499 | $term_fonction = _image_trouver_extension_pertinente($fichier); |
| 500 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 500 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom'.$term_fonction; |
|
| 501 | 501 | $ret['fichier'] = $fichier; |
| 502 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 502 | + $ret['fonction_image'] = '_image_image'.$terminaison_dest; |
|
| 503 | 503 | $ret['fichier_dest'] = $fichier_dest; |
| 504 | 504 | $ret['format_source'] = _image_extension_normalisee($terminaison); |
| 505 | 505 | $ret['format_dest'] = $terminaison_dest; |
@@ -649,7 +649,7 @@ discard block |
||
| 649 | 649 | |
| 650 | 650 | $_terminaison = _image_trouver_extension_depuis_mime($mime); |
| 651 | 651 | if ($_terminaison and $_terminaison !== $terminaison) { |
| 652 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 652 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.'._LOG_INFO_IMPORTANTE); |
|
| 653 | 653 | $terminaison = $_terminaison; |
| 654 | 654 | } |
| 655 | 655 | return $terminaison; |
@@ -806,7 +806,7 @@ discard block |
||
| 806 | 806 | if (!function_exists('imagepng')) { |
| 807 | 807 | return false; |
| 808 | 808 | } |
| 809 | - $tmp = $fichier . '.tmp'; |
|
| 809 | + $tmp = $fichier.'.tmp'; |
|
| 810 | 810 | $ret = imagepng($img, $tmp); |
| 811 | 811 | if (file_exists($tmp)) { |
| 812 | 812 | $taille_test = getimagesize($tmp); |
@@ -841,7 +841,7 @@ discard block |
||
| 841 | 841 | if (!function_exists('imagegif')) { |
| 842 | 842 | return false; |
| 843 | 843 | } |
| 844 | - $tmp = $fichier . '.tmp'; |
|
| 844 | + $tmp = $fichier.'.tmp'; |
|
| 845 | 845 | $ret = imagegif($img, $tmp); |
| 846 | 846 | if (file_exists($tmp)) { |
| 847 | 847 | $taille_test = getimagesize($tmp); |
@@ -881,7 +881,7 @@ discard block |
||
| 881 | 881 | if (!function_exists('imagejpeg')) { |
| 882 | 882 | return false; |
| 883 | 883 | } |
| 884 | - $tmp = $fichier . '.tmp'; |
|
| 884 | + $tmp = $fichier.'.tmp'; |
|
| 885 | 885 | |
| 886 | 886 | // Enable interlancing |
| 887 | 887 | imageinterlace($img, true); |
@@ -942,7 +942,7 @@ discard block |
||
| 942 | 942 | if (!function_exists('imagewebp')) { |
| 943 | 943 | return false; |
| 944 | 944 | } |
| 945 | - $tmp = $fichier . '.tmp'; |
|
| 945 | + $tmp = $fichier.'.tmp'; |
|
| 946 | 946 | $ret = imagewebp($img, $tmp, $qualite); |
| 947 | 947 | if (file_exists($tmp)) { |
| 948 | 948 | $taille_test = getimagesize($tmp); |
@@ -976,7 +976,7 @@ discard block |
||
| 976 | 976 | */ |
| 977 | 977 | function _image_imagesvg($img, $fichier) { |
| 978 | 978 | |
| 979 | - $tmp = $fichier . '.tmp'; |
|
| 979 | + $tmp = $fichier.'.tmp'; |
|
| 980 | 980 | if (strpos($img, '<') === false) { |
| 981 | 981 | $img = supprimer_timestamp($img); |
| 982 | 982 | if (!file_exists($img)) { |
@@ -1033,13 +1033,13 @@ discard block |
||
| 1033 | 1033 | */ |
| 1034 | 1034 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1035 | 1035 | if (is_null($fonction)) { |
| 1036 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1036 | + $fonction = '_image_image'.$valeurs['format_dest']; |
|
| 1037 | 1037 | } |
| 1038 | 1038 | $ret = false; |
| 1039 | 1039 | #un flag pour reperer les images gravees |
| 1040 | 1040 | $lock = ( |
| 1041 | 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')) |
|
| 1042 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'].'.src')) |
|
| 1043 | 1043 | ); |
| 1044 | 1044 | if ( |
| 1045 | 1045 | function_exists($fonction) |
@@ -1051,7 +1051,7 @@ discard block |
||
| 1051 | 1051 | // dans tous les cas mettre a jour la taille de l'image finale |
| 1052 | 1052 | [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
| 1053 | 1053 | $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
| 1054 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1054 | + ecrire_fichier($valeurs['fichier_dest'].'.src', serialize($valeurs), true); |
|
| 1055 | 1055 | } |
| 1056 | 1056 | } |
| 1057 | 1057 | |
@@ -1226,7 +1226,7 @@ discard block |
||
| 1226 | 1226 | |
| 1227 | 1227 | // attributs deprecies. Transformer en CSS |
| 1228 | 1228 | if ($espace = extraire_attribut($tag, 'hspace')) { |
| 1229 | - $style = "margin:{$espace}px;" . $style; |
|
| 1229 | + $style = "margin:{$espace}px;".$style; |
|
| 1230 | 1230 | $tag = inserer_attribut($tag, 'hspace', ''); |
| 1231 | 1231 | } |
| 1232 | 1232 | |
@@ -1353,7 +1353,7 @@ discard block |
||
| 1353 | 1353 | $image = $valeurs['fichier']; |
| 1354 | 1354 | $format = $valeurs['format_source']; |
| 1355 | 1355 | $destdir = dirname($valeurs['fichier_dest']); |
| 1356 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1356 | + $destfile = basename($valeurs['fichier_dest'], '.'.$valeurs['format_dest']); |
|
| 1357 | 1357 | |
| 1358 | 1358 | $format_sortie = $valeurs['format_dest']; |
| 1359 | 1359 | |
@@ -1385,14 +1385,14 @@ discard block |
||
| 1385 | 1385 | |
| 1386 | 1386 | // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
| 1387 | 1387 | if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
| 1388 | - $vignette = $destination . '.' . $format; |
|
| 1388 | + $vignette = $destination.'.'.$format; |
|
| 1389 | 1389 | @copy($image, $vignette); |
| 1390 | 1390 | } |
| 1391 | 1391 | |
| 1392 | 1392 | elseif ($valeurs['format_source'] === 'svg') { |
| 1393 | 1393 | if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
| 1394 | 1394 | $format_sortie = 'svg'; |
| 1395 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1395 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1396 | 1396 | $valeurs['fichier_dest'] = $vignette; |
| 1397 | 1397 | _image_gd_output($svg, $valeurs); |
| 1398 | 1398 | } |
@@ -1404,9 +1404,9 @@ discard block |
||
| 1404 | 1404 | define('_CONVERT_COMMAND', 'convert'); |
| 1405 | 1405 | } // Securite : mes_options.php peut preciser le chemin absolu |
| 1406 | 1406 | if (!defined('_RESIZE_COMMAND')) { |
| 1407 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1407 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND.' -quality '._IMG_CONVERT_QUALITE.' -resize %xx%y! %src %dest'); |
|
| 1408 | 1408 | } |
| 1409 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1409 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1410 | 1410 | $commande = str_replace( |
| 1411 | 1411 | ['%x', '%y', '%src', '%dest'], |
| 1412 | 1412 | [ |
@@ -1422,7 +1422,7 @@ discard block |
||
| 1422 | 1422 | if (!@file_exists($vignette)) { |
| 1423 | 1423 | spip_log("echec convert sur $vignette"); |
| 1424 | 1424 | |
| 1425 | - return; // echec commande |
|
| 1425 | + return; // echec commande |
|
| 1426 | 1426 | } |
| 1427 | 1427 | } |
| 1428 | 1428 | |
@@ -1439,7 +1439,7 @@ discard block |
||
| 1439 | 1439 | if (!$output) { |
| 1440 | 1440 | return; |
| 1441 | 1441 | } |
| 1442 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1442 | + $vignette = $output.DIRECTORY_SEPARATOR.basename($destination).'.'.$format_sortie; |
|
| 1443 | 1443 | |
| 1444 | 1444 | $imagick = new Imagick(); |
| 1445 | 1445 | $imagick->readImage(realpath($image)); |
@@ -1448,7 +1448,7 @@ discard block |
||
| 1448 | 1448 | $destHeight, |
| 1449 | 1449 | Imagick::FILTER_LANCZOS, |
| 1450 | 1450 | 1 |
| 1451 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1451 | + ); //, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1452 | 1452 | $imagick->writeImage($vignette); |
| 1453 | 1453 | |
| 1454 | 1454 | if (!@file_exists($vignette)) { |
@@ -1457,7 +1457,7 @@ discard block |
||
| 1457 | 1457 | return; |
| 1458 | 1458 | } |
| 1459 | 1459 | // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
| 1460 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1460 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1461 | 1461 | } |
| 1462 | 1462 | |
| 1463 | 1463 | // netpbm |
@@ -1468,11 +1468,11 @@ discard block |
||
| 1468 | 1468 | if (_PNMSCALE_COMMAND == '') { |
| 1469 | 1469 | return; |
| 1470 | 1470 | } |
| 1471 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1471 | + $vignette = $destination.'.'.$format_sortie; |
|
| 1472 | 1472 | $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
| 1473 | 1473 | if ($format == 'jpg') { |
| 1474 | 1474 | $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
| 1475 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1475 | + exec("$jpegtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1476 | 1476 | if (!($s = @filesize($vignette))) { |
| 1477 | 1477 | spip_unlink($vignette); |
| 1478 | 1478 | } |
@@ -1484,7 +1484,7 @@ discard block |
||
| 1484 | 1484 | } else { |
| 1485 | 1485 | if ($format == 'gif') { |
| 1486 | 1486 | $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
| 1487 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1487 | + exec("$giftopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1488 | 1488 | if (!($s = @filesize($vignette))) { |
| 1489 | 1489 | spip_unlink($vignette); |
| 1490 | 1490 | } |
@@ -1496,7 +1496,7 @@ discard block |
||
| 1496 | 1496 | } else { |
| 1497 | 1497 | if ($format == 'png') { |
| 1498 | 1498 | $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
| 1499 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1499 | + exec("$pngtopnm_command $image | "._PNMSCALE_COMMAND." -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1500 | 1500 | if (!($s = @filesize($vignette))) { |
| 1501 | 1501 | spip_unlink($vignette); |
| 1502 | 1502 | } |
@@ -1518,7 +1518,7 @@ discard block |
||
| 1518 | 1518 | return; |
| 1519 | 1519 | } |
| 1520 | 1520 | if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
| 1521 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1521 | + spip_log('vignette gd1/gd2 impossible : '.$srcWidth * $srcHeight.'pixels'); |
|
| 1522 | 1522 | |
| 1523 | 1523 | return; |
| 1524 | 1524 | } |
@@ -1828,7 +1828,7 @@ discard block |
||
| 1828 | 1828 | // de l'image, de facon a tromper le cache du navigateur |
| 1829 | 1829 | // quand on fait supprimer/reuploader un logo |
| 1830 | 1830 | // (pas de filemtime si SAFE MODE) |
| 1831 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1831 | + $date = test_espace_prive() ? ('?'.$date) : ''; |
|
| 1832 | 1832 | |
| 1833 | 1833 | return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
| 1834 | 1834 | } |
@@ -1874,7 +1874,7 @@ discard block |
||
| 1874 | 1874 | public static function LittleEndian2String($number, $minbytes = 1) { |
| 1875 | 1875 | $intstring = ''; |
| 1876 | 1876 | while ($number > 0) { |
| 1877 | - $intstring = $intstring . chr($number & 255); |
|
| 1877 | + $intstring = $intstring.chr($number & 255); |
|
| 1878 | 1878 | $number >>= 8; |
| 1879 | 1879 | } |
| 1880 | 1880 | |
@@ -1906,9 +1906,9 @@ discard block |
||
| 1906 | 1906 | $b = $argb['blue']; |
| 1907 | 1907 | |
| 1908 | 1908 | if ($bpp[$key] == 32) { |
| 1909 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1909 | + $icXOR[$key] .= chr($b).chr($g).chr($r).chr($a); |
|
| 1910 | 1910 | } elseif ($bpp[$key] == 24) { |
| 1911 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1911 | + $icXOR[$key] .= chr($b).chr($g).chr($r); |
|
| 1912 | 1912 | } |
| 1913 | 1913 | |
| 1914 | 1914 | if ($a < 128) { |
@@ -1935,48 +1935,48 @@ discard block |
||
| 1935 | 1935 | |
| 1936 | 1936 | // BITMAPINFOHEADER - 40 bytes |
| 1937 | 1937 | $BitmapInfoHeader[$key] = ''; |
| 1938 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1938 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1939 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1940 | 1940 | // The biHeight member specifies the combined |
| 1941 | 1941 | // height of the XOR and AND masks. |
| 1942 | 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; |
|
| 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 | 1951 | } |
| 1952 | 1952 | |
| 1953 | 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? |
|
| 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 | 1957 | |
| 1958 | 1958 | $dwImageOffset = 6 + (count($gd_image_array) * 16); |
| 1959 | 1959 | foreach ($gd_image_array as $key => $gd_image) { |
| 1960 | 1960 | // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
| 1961 | 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) |
|
| 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 | 1966 | |
| 1967 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1967 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1968 | + $icondata .= chr($bpp[$key])."\x00"; // wBitCount; // Bits per pixel |
|
| 1969 | 1969 | |
| 1970 | 1970 | $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
| 1971 | 1971 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1972 | 1972 | $dwBytesInRes, |
| 1973 | 1973 | 4 |
| 1974 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1974 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1975 | 1975 | |
| 1976 | 1976 | $icondata .= phpthumb_functions::LittleEndian2String( |
| 1977 | 1977 | $dwImageOffset, |
| 1978 | 1978 | 4 |
| 1979 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1979 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1980 | 1980 | $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
| 1981 | 1981 | $dwImageOffset += strlen($icXOR[$key]); |
| 1982 | 1982 | $dwImageOffset += strlen($icAND[$key]); |
@@ -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,18 +64,18 @@ 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 ??= ''; |
|
| 68 | - $couleur = couleur_html_to_hex($couleur); |
|
| 69 | - $couleur = ltrim($couleur, '#'); |
|
| 70 | - if (strlen($couleur) === 3) { |
|
| 71 | - $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | - } |
|
| 73 | - $retour = []; |
|
| 74 | - $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 75 | - $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 76 | - $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 77 | - |
|
| 78 | - return $retour; |
|
| 67 | + $couleur ??= ''; |
|
| 68 | + $couleur = couleur_html_to_hex($couleur); |
|
| 69 | + $couleur = ltrim($couleur, '#'); |
|
| 70 | + if (strlen($couleur) === 3) { |
|
| 71 | + $couleur = $couleur[0] . $couleur[0] . $couleur[1] . $couleur[1] . $couleur[2] . $couleur[2]; |
|
| 72 | + } |
|
| 73 | + $retour = []; |
|
| 74 | + $retour['red'] = hexdec(substr($couleur, 0, 2)); |
|
| 75 | + $retour['green'] = hexdec(substr($couleur, 2, 2)); |
|
| 76 | + $retour['blue'] = hexdec(substr($couleur, 4, 2)); |
|
| 77 | + |
|
| 78 | + return $retour; |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | |
@@ -92,8 +92,8 @@ discard block |
||
| 92 | 92 | * Le code de la couleur en hexadécimal. |
| 93 | 93 | */ |
| 94 | 94 | function _couleur_hsl_to_hex($hue, $saturation, $lightness) { |
| 95 | - $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 96 | - return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 95 | + $rgb = _couleur_hsl_to_rgb($hue, $saturation, $lightness); |
|
| 96 | + return _couleur_dec_to_hex($rgb['r'], $rgb['g'], $rgb['b']); |
|
| 97 | 97 | } |
| 98 | 98 | |
| 99 | 99 | /** |
@@ -105,8 +105,8 @@ discard block |
||
| 105 | 105 | * Un tableau des 3 éléments : teinte, saturation, luminosité. |
| 106 | 106 | */ |
| 107 | 107 | function _couleur_hex_to_hsl($couleur) { |
| 108 | - $rgb = _couleur_hex_to_dec($couleur); |
|
| 109 | - return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 108 | + $rgb = _couleur_hex_to_dec($couleur); |
|
| 109 | + return _couleur_rgb_to_hsl($rgb['red'], $rgb['green'], $rgb['blue']); |
|
| 110 | 110 | } |
| 111 | 111 | |
| 112 | 112 | /** |
@@ -121,59 +121,59 @@ discard block |
||
| 121 | 121 | * @return array |
| 122 | 122 | */ |
| 123 | 123 | function _couleur_rgb_to_hsl($R, $G, $B) { |
| 124 | - $H = null; |
|
| 125 | - $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 126 | - $var_G = ($G / 255); |
|
| 127 | - $var_B = ($B / 255); |
|
| 128 | - |
|
| 129 | - $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 130 | - $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 131 | - $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 132 | - |
|
| 133 | - $L = ($var_Max + $var_Min) / 2; |
|
| 134 | - |
|
| 135 | - if ($del_Max == 0) { |
|
| 136 | - //This is a gray, no chroma... |
|
| 137 | - $H = 0; //HSL results = 0 ÷ 1 |
|
| 138 | - $S = 0; |
|
| 139 | - } else { |
|
| 140 | - // Chromatic data... |
|
| 141 | - if ($L < 0.5) { |
|
| 142 | - $S = $del_Max / ($var_Max + $var_Min); |
|
| 143 | - } else { |
|
| 144 | - $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 145 | - } |
|
| 146 | - |
|
| 147 | - $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | - $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | - $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 150 | - |
|
| 151 | - if ($var_R == $var_Max) { |
|
| 152 | - $H = $del_B - $del_G; |
|
| 153 | - } else { |
|
| 154 | - if ($var_G == $var_Max) { |
|
| 155 | - $H = (1 / 3) + $del_R - $del_B; |
|
| 156 | - } else { |
|
| 157 | - if ($var_B == $var_Max) { |
|
| 158 | - $H = (2 / 3) + $del_G - $del_R; |
|
| 159 | - } |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if ($H < 0) { |
|
| 164 | - $H += 1; |
|
| 165 | - } |
|
| 166 | - if ($H > 1) { |
|
| 167 | - $H -= 1; |
|
| 168 | - } |
|
| 169 | - } |
|
| 170 | - |
|
| 171 | - $ret = []; |
|
| 172 | - $ret['h'] = $H; |
|
| 173 | - $ret['s'] = $S; |
|
| 174 | - $ret['l'] = $L; |
|
| 175 | - |
|
| 176 | - return $ret; |
|
| 124 | + $H = null; |
|
| 125 | + $var_R = ($R / 255); // Where RGB values = 0 ÷ 255 |
|
| 126 | + $var_G = ($G / 255); |
|
| 127 | + $var_B = ($B / 255); |
|
| 128 | + |
|
| 129 | + $var_Min = min($var_R, $var_G, $var_B); //Min. value of RGB |
|
| 130 | + $var_Max = max($var_R, $var_G, $var_B); //Max. value of RGB |
|
| 131 | + $del_Max = $var_Max - $var_Min; //Delta RGB value |
|
| 132 | + |
|
| 133 | + $L = ($var_Max + $var_Min) / 2; |
|
| 134 | + |
|
| 135 | + if ($del_Max == 0) { |
|
| 136 | + //This is a gray, no chroma... |
|
| 137 | + $H = 0; //HSL results = 0 ÷ 1 |
|
| 138 | + $S = 0; |
|
| 139 | + } else { |
|
| 140 | + // Chromatic data... |
|
| 141 | + if ($L < 0.5) { |
|
| 142 | + $S = $del_Max / ($var_Max + $var_Min); |
|
| 143 | + } else { |
|
| 144 | + $S = $del_Max / (2 - $var_Max - $var_Min); |
|
| 145 | + } |
|
| 146 | + |
|
| 147 | + $del_R = ((($var_Max - $var_R) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 148 | + $del_G = ((($var_Max - $var_G) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 149 | + $del_B = ((($var_Max - $var_B) / 6) + ($del_Max / 2)) / $del_Max; |
|
| 150 | + |
|
| 151 | + if ($var_R == $var_Max) { |
|
| 152 | + $H = $del_B - $del_G; |
|
| 153 | + } else { |
|
| 154 | + if ($var_G == $var_Max) { |
|
| 155 | + $H = (1 / 3) + $del_R - $del_B; |
|
| 156 | + } else { |
|
| 157 | + if ($var_B == $var_Max) { |
|
| 158 | + $H = (2 / 3) + $del_G - $del_R; |
|
| 159 | + } |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if ($H < 0) { |
|
| 164 | + $H += 1; |
|
| 165 | + } |
|
| 166 | + if ($H > 1) { |
|
| 167 | + $H -= 1; |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | + |
|
| 171 | + $ret = []; |
|
| 172 | + $ret['h'] = $H; |
|
| 173 | + $ret['s'] = $S; |
|
| 174 | + $ret['l'] = $L; |
|
| 175 | + |
|
| 176 | + return $ret; |
|
| 177 | 177 | } |
| 178 | 178 | |
| 179 | 179 | |
@@ -189,52 +189,52 @@ discard block |
||
| 189 | 189 | * @return array |
| 190 | 190 | */ |
| 191 | 191 | function _couleur_hsl_to_rgb($H, $S, $L) { |
| 192 | - // helper |
|
| 193 | - $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 194 | - if ($vH < 0) { |
|
| 195 | - $vH += 1; |
|
| 196 | - } |
|
| 197 | - if ($vH > 1) { |
|
| 198 | - $vH -= 1; |
|
| 199 | - } |
|
| 200 | - if ((6 * $vH) < 1) { |
|
| 201 | - return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 202 | - } |
|
| 203 | - if ((2 * $vH) < 1) { |
|
| 204 | - return ($v2); |
|
| 205 | - } |
|
| 206 | - if ((3 * $vH) < 2) { |
|
| 207 | - return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 208 | - } |
|
| 209 | - |
|
| 210 | - return ($v1); |
|
| 211 | - }; |
|
| 212 | - |
|
| 213 | - if ($S == 0) { |
|
| 214 | - // HSV values = 0 -> 1 |
|
| 215 | - $R = $L * 255; |
|
| 216 | - $G = $L * 255; |
|
| 217 | - $B = $L * 255; |
|
| 218 | - } else { |
|
| 219 | - if ($L < 0.5) { |
|
| 220 | - $var_2 = $L * (1 + $S); |
|
| 221 | - } else { |
|
| 222 | - $var_2 = ($L + $S) - ($S * $L); |
|
| 223 | - } |
|
| 224 | - |
|
| 225 | - $var_1 = 2 * $L - $var_2; |
|
| 226 | - |
|
| 227 | - $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 228 | - $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 229 | - $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 230 | - } |
|
| 231 | - |
|
| 232 | - $ret = []; |
|
| 233 | - $ret['r'] = floor($R); |
|
| 234 | - $ret['g'] = floor($G); |
|
| 235 | - $ret['b'] = floor($B); |
|
| 236 | - |
|
| 237 | - return $ret; |
|
| 192 | + // helper |
|
| 193 | + $hue_2_rgb = function ($v1, $v2, $vH) { |
|
| 194 | + if ($vH < 0) { |
|
| 195 | + $vH += 1; |
|
| 196 | + } |
|
| 197 | + if ($vH > 1) { |
|
| 198 | + $vH -= 1; |
|
| 199 | + } |
|
| 200 | + if ((6 * $vH) < 1) { |
|
| 201 | + return ($v1 + ($v2 - $v1) * 6 * $vH); |
|
| 202 | + } |
|
| 203 | + if ((2 * $vH) < 1) { |
|
| 204 | + return ($v2); |
|
| 205 | + } |
|
| 206 | + if ((3 * $vH) < 2) { |
|
| 207 | + return ($v1 + ($v2 - $v1) * ((2 / 3) - $vH) * 6); |
|
| 208 | + } |
|
| 209 | + |
|
| 210 | + return ($v1); |
|
| 211 | + }; |
|
| 212 | + |
|
| 213 | + if ($S == 0) { |
|
| 214 | + // HSV values = 0 -> 1 |
|
| 215 | + $R = $L * 255; |
|
| 216 | + $G = $L * 255; |
|
| 217 | + $B = $L * 255; |
|
| 218 | + } else { |
|
| 219 | + if ($L < 0.5) { |
|
| 220 | + $var_2 = $L * (1 + $S); |
|
| 221 | + } else { |
|
| 222 | + $var_2 = ($L + $S) - ($S * $L); |
|
| 223 | + } |
|
| 224 | + |
|
| 225 | + $var_1 = 2 * $L - $var_2; |
|
| 226 | + |
|
| 227 | + $R = 255 * $hue_2_rgb($var_1, $var_2, $H + (1 / 3)); |
|
| 228 | + $G = 255 * $hue_2_rgb($var_1, $var_2, $H); |
|
| 229 | + $B = 255 * $hue_2_rgb($var_1, $var_2, $H - (1 / 3)); |
|
| 230 | + } |
|
| 231 | + |
|
| 232 | + $ret = []; |
|
| 233 | + $ret['r'] = floor($R); |
|
| 234 | + $ret['g'] = floor($G); |
|
| 235 | + $ret['b'] = floor($B); |
|
| 236 | + |
|
| 237 | + return $ret; |
|
| 238 | 238 | } |
| 239 | 239 | |
| 240 | 240 | /** |
@@ -252,11 +252,11 @@ discard block |
||
| 252 | 252 | * true si il faut supprimer le fichier temporaire ; false sinon. |
| 253 | 253 | */ |
| 254 | 254 | function statut_effacer_images_temporaires($stat) { |
| 255 | - static $statut = false; // par defaut on grave toute les images |
|
| 256 | - if ($stat === 'get') { |
|
| 257 | - return $statut; |
|
| 258 | - } |
|
| 259 | - $statut = $stat ? true : false; |
|
| 255 | + static $statut = false; // par defaut on grave toute les images |
|
| 256 | + if ($stat === 'get') { |
|
| 257 | + return $statut; |
|
| 258 | + } |
|
| 259 | + $statut = $stat ? true : false; |
|
| 260 | 260 | } |
| 261 | 261 | |
| 262 | 262 | |
@@ -309,247 +309,247 @@ discard block |
||
| 309 | 309 | * - array : tableau décrivant de l'image |
| 310 | 310 | */ |
| 311 | 311 | function _image_valeurs_trans($img, $effet, $forcer_format = false, $fonction_creation = null, $find_in_path = false, $support_svg = false) { |
| 312 | - $ret = []; |
|
| 313 | - $f = null; |
|
| 314 | - static $images_recalcul = []; |
|
| 315 | - if (strlen($img) == 0) { |
|
| 316 | - return false; |
|
| 317 | - } |
|
| 318 | - |
|
| 319 | - $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 320 | - if (strlen($source) < 1) { |
|
| 321 | - $source = $img; |
|
| 322 | - $img = "<img src='$source' />"; |
|
| 323 | - } elseif ( |
|
| 324 | - preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 325 | - and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 326 | - and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 327 | - ) { |
|
| 328 | - # gerer img src="data:....base64" |
|
| 329 | - $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 330 | - if (!file_exists($local)) { |
|
| 331 | - ecrire_fichier($local, base64_decode($regs[2])); |
|
| 332 | - } |
|
| 333 | - if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 334 | - $sanitizer($local); |
|
| 335 | - } |
|
| 336 | - $source = $local; |
|
| 337 | - $img = inserer_attribut($img, 'src', $source); |
|
| 338 | - # eviter les mauvaises surprises lors de conversions de format |
|
| 339 | - $img = inserer_attribut($img, 'width', ''); |
|
| 340 | - $img = inserer_attribut($img, 'height', ''); |
|
| 341 | - } |
|
| 342 | - |
|
| 343 | - // les protocoles web prennent au moins 3 lettres |
|
| 344 | - if (tester_url_absolue($source)) { |
|
| 345 | - include_spip('inc/distant'); |
|
| 346 | - $fichier = _DIR_RACINE . copie_locale($source); |
|
| 347 | - if (!$fichier) { |
|
| 348 | - return ''; |
|
| 349 | - } |
|
| 350 | - if ( |
|
| 351 | - $extension = _image_trouver_extension($fichier) |
|
| 352 | - and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 353 | - ) { |
|
| 354 | - $sanitizer($fichier); |
|
| 355 | - } |
|
| 356 | - } else { |
|
| 357 | - // enlever le timestamp eventuel |
|
| 358 | - if (strpos($source, '?') !== false) { |
|
| 359 | - $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 360 | - } |
|
| 361 | - if ( |
|
| 362 | - strpos($source, '?') !== false |
|
| 363 | - and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 364 | - and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 365 | - ) { |
|
| 366 | - $source = $f; |
|
| 367 | - } |
|
| 368 | - $fichier = $source; |
|
| 369 | - } |
|
| 370 | - |
|
| 371 | - $terminaison_dest = ''; |
|
| 372 | - if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 373 | - $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 374 | - } |
|
| 375 | - |
|
| 376 | - if ( |
|
| 377 | - $forcer_format !== false |
|
| 378 | - // 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 |
|
| 379 | - and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 380 | - ) { |
|
| 381 | - $terminaison_dest = $forcer_format; |
|
| 382 | - } |
|
| 383 | - |
|
| 384 | - if (!$terminaison_dest) { |
|
| 385 | - return false; |
|
| 386 | - } |
|
| 387 | - |
|
| 388 | - $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 389 | - $fichier_dest = $nom_fichier; |
|
| 390 | - if ( |
|
| 391 | - ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 392 | - or @file_exists($f = $fichier) |
|
| 393 | - ) { |
|
| 394 | - // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 395 | - // au lieu de faire un acces disque sur le fichier |
|
| 396 | - [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 397 | - $date_src = @filemtime($f); |
|
| 398 | - } elseif ( |
|
| 399 | - @file_exists($f = "$fichier.src") |
|
| 400 | - and lire_fichier($f, $valeurs) |
|
| 401 | - and $valeurs = unserialize($valeurs) |
|
| 402 | - and isset($valeurs['hauteur_dest']) |
|
| 403 | - and isset($valeurs['largeur_dest']) |
|
| 404 | - ) { |
|
| 405 | - $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 406 | - $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 407 | - $date_src = $valeurs['date']; |
|
| 408 | - } // pas de fichier source par la |
|
| 409 | - else { |
|
| 410 | - return false; |
|
| 411 | - } |
|
| 412 | - |
|
| 413 | - // pas de taille mesurable ? |
|
| 414 | - if (!$ret['hauteur'] |
|
| 415 | - or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 416 | - or !$ret['largeur'] |
|
| 417 | - or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 418 | - ) { |
|
| 419 | - return false; |
|
| 420 | - } |
|
| 421 | - |
|
| 422 | - // les images calculees dependent du chemin du fichier source |
|
| 423 | - // 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 |
|
| 424 | - // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 425 | - // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 426 | - // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 427 | - // alors que ca concerne peu de site au final |
|
| 428 | - // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 429 | - $identifiant = $fichier; |
|
| 430 | - |
|
| 431 | - // cas general : |
|
| 432 | - // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 433 | - // cas particulier de reduire : |
|
| 434 | - // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 435 | - $cache = 'cache-gd2'; |
|
| 436 | - if (substr($effet, 0, 7) == 'reduire') { |
|
| 437 | - [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 438 | - [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 439 | - $ret['largeur_dest'] = $destWidth; |
|
| 440 | - $ret['hauteur_dest'] = $destHeight; |
|
| 441 | - $effet = "L{$destWidth}xH$destHeight"; |
|
| 442 | - $cache = 'cache-vignettes'; |
|
| 443 | - $fichier_dest = basename($fichier_dest); |
|
| 444 | - if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 445 | - // on garde la terminaison initiale car image simplement copiee |
|
| 446 | - // et on postfixe son nom avec un md5 du path |
|
| 447 | - $terminaison_dest = $terminaison; |
|
| 448 | - $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 449 | - } else { |
|
| 450 | - $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 451 | - } |
|
| 452 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 453 | - $cache = sous_repertoire($cache, $effet); |
|
| 454 | - } else { |
|
| 455 | - $fichier_dest = md5("$identifiant-$effet"); |
|
| 456 | - $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 457 | - $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 458 | - $fichier_dest = substr($fichier_dest, 2); |
|
| 459 | - } |
|
| 460 | - |
|
| 461 | - $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 462 | - |
|
| 463 | - $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 464 | - |
|
| 465 | - $creer = true; |
|
| 466 | - // si recalcul des images demande, recalculer chaque image une fois |
|
| 467 | - if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 468 | - $images_recalcul[$fichier_dest] = true; |
|
| 469 | - } else { |
|
| 470 | - if (@file_exists($f = $fichier_dest)) { |
|
| 471 | - if (filemtime($f) >= $date_src) { |
|
| 472 | - $creer = false; |
|
| 473 | - } |
|
| 474 | - } else { |
|
| 475 | - if ( |
|
| 476 | - @file_exists($f = "$fichier_dest.src") |
|
| 477 | - and lire_fichier($f, $valeurs) |
|
| 478 | - and $valeurs = unserialize($valeurs) |
|
| 479 | - and $valeurs['date'] >= $date_src |
|
| 480 | - ) { |
|
| 481 | - $creer = false; |
|
| 482 | - } |
|
| 483 | - } |
|
| 484 | - } |
|
| 485 | - if ($creer) { |
|
| 486 | - if (!@file_exists($fichier)) { |
|
| 487 | - if (!@file_exists("$fichier.src")) { |
|
| 488 | - spip_log("Image absente : $fichier"); |
|
| 489 | - |
|
| 490 | - return false; |
|
| 491 | - } |
|
| 492 | - # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 493 | - reconstruire_image_intermediaire($fichier); |
|
| 494 | - } |
|
| 495 | - } |
|
| 496 | - |
|
| 497 | - if ($creer) { |
|
| 498 | - spip_log( |
|
| 499 | - 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 500 | - 'images' . _LOG_DEBUG |
|
| 501 | - ); |
|
| 502 | - } |
|
| 503 | - |
|
| 504 | - $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 505 | - $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 506 | - $ret['fichier'] = $fichier; |
|
| 507 | - $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 508 | - $ret['fichier_dest'] = $fichier_dest; |
|
| 509 | - $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 510 | - $ret['format_dest'] = $terminaison_dest; |
|
| 511 | - $ret['date_src'] = $date_src; |
|
| 512 | - $ret['creer'] = $creer; |
|
| 513 | - $ret['class'] = extraire_attribut($img, 'class'); |
|
| 514 | - $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 515 | - $ret['style'] = extraire_attribut($img, 'style'); |
|
| 516 | - $ret['tag'] = $img; |
|
| 517 | - if ($fonction_creation) { |
|
| 518 | - $ret['reconstruction'] = $fonction_creation; |
|
| 519 | - # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 520 | - # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 521 | - # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 522 | - #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 523 | - } |
|
| 524 | - |
|
| 525 | - $ret = pipeline('image_preparer_filtre', [ |
|
| 526 | - 'args' => [ |
|
| 527 | - 'img' => $img, |
|
| 528 | - 'effet' => $effet, |
|
| 529 | - 'forcer_format' => $forcer_format, |
|
| 530 | - 'fonction_creation' => $fonction_creation, |
|
| 531 | - 'find_in_path' => $find_in_path, |
|
| 532 | - ], |
|
| 533 | - 'data' => $ret |
|
| 534 | - ]); |
|
| 535 | - |
|
| 536 | - // une globale pour le debug en cas de crash memoire |
|
| 537 | - $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 538 | - |
|
| 539 | - // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 540 | - if ($term_fonction === 'svg') { |
|
| 541 | - if ($creer and !$support_svg) { |
|
| 542 | - process_image_svg_identite($ret); |
|
| 543 | - $ret['creer'] = false; |
|
| 544 | - } |
|
| 545 | - } |
|
| 546 | - else { |
|
| 547 | - if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 548 | - return false; |
|
| 549 | - } |
|
| 550 | - } |
|
| 551 | - |
|
| 552 | - return $ret; |
|
| 312 | + $ret = []; |
|
| 313 | + $f = null; |
|
| 314 | + static $images_recalcul = []; |
|
| 315 | + if (strlen($img) == 0) { |
|
| 316 | + return false; |
|
| 317 | + } |
|
| 318 | + |
|
| 319 | + $source = trim(extraire_attribut($img, 'src') ?? ''); |
|
| 320 | + if (strlen($source) < 1) { |
|
| 321 | + $source = $img; |
|
| 322 | + $img = "<img src='$source' />"; |
|
| 323 | + } elseif ( |
|
| 324 | + preg_match('@^data:image/([^;]*);base64,(.*)$@isS', $source, $regs) |
|
| 325 | + and $extension = _image_trouver_extension_depuis_mime('image/' . $regs[1]) |
|
| 326 | + and in_array($extension, _image_extensions_acceptees_en_entree()) |
|
| 327 | + ) { |
|
| 328 | + # gerer img src="data:....base64" |
|
| 329 | + $local = sous_repertoire(_DIR_VAR, 'image-data') . md5($regs[2]) . '.' . _image_extension_normalisee($extension); |
|
| 330 | + if (!file_exists($local)) { |
|
| 331 | + ecrire_fichier($local, base64_decode($regs[2])); |
|
| 332 | + } |
|
| 333 | + if ($sanitizer = charger_fonction($extension, 'sanitizer', true)) { |
|
| 334 | + $sanitizer($local); |
|
| 335 | + } |
|
| 336 | + $source = $local; |
|
| 337 | + $img = inserer_attribut($img, 'src', $source); |
|
| 338 | + # eviter les mauvaises surprises lors de conversions de format |
|
| 339 | + $img = inserer_attribut($img, 'width', ''); |
|
| 340 | + $img = inserer_attribut($img, 'height', ''); |
|
| 341 | + } |
|
| 342 | + |
|
| 343 | + // les protocoles web prennent au moins 3 lettres |
|
| 344 | + if (tester_url_absolue($source)) { |
|
| 345 | + include_spip('inc/distant'); |
|
| 346 | + $fichier = _DIR_RACINE . copie_locale($source); |
|
| 347 | + if (!$fichier) { |
|
| 348 | + return ''; |
|
| 349 | + } |
|
| 350 | + if ( |
|
| 351 | + $extension = _image_trouver_extension($fichier) |
|
| 352 | + and $sanitizer = charger_fonction($extension, 'sanitizer', true) |
|
| 353 | + ) { |
|
| 354 | + $sanitizer($fichier); |
|
| 355 | + } |
|
| 356 | + } else { |
|
| 357 | + // enlever le timestamp eventuel |
|
| 358 | + if (strpos($source, '?') !== false) { |
|
| 359 | + $source = preg_replace(',[?][0-9]+$,', '', $source); |
|
| 360 | + } |
|
| 361 | + if ( |
|
| 362 | + strpos($source, '?') !== false |
|
| 363 | + and strncmp($source, _DIR_IMG, strlen(_DIR_IMG)) == 0 |
|
| 364 | + and file_exists($f = preg_replace(',[?].*$,', '', $source)) |
|
| 365 | + ) { |
|
| 366 | + $source = $f; |
|
| 367 | + } |
|
| 368 | + $fichier = $source; |
|
| 369 | + } |
|
| 370 | + |
|
| 371 | + $terminaison_dest = ''; |
|
| 372 | + if ($terminaison = _image_trouver_extension($fichier)) { |
|
| 373 | + $terminaison_dest = ($terminaison == 'gif') ? 'png' : $terminaison; |
|
| 374 | + } |
|
| 375 | + |
|
| 376 | + if ( |
|
| 377 | + $forcer_format !== false |
|
| 378 | + // 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 |
|
| 379 | + and ($terminaison_dest !== 'svg' or $support_svg or !in_array($forcer_format, _image_extensions_acceptees_en_sortie())) |
|
| 380 | + ) { |
|
| 381 | + $terminaison_dest = $forcer_format; |
|
| 382 | + } |
|
| 383 | + |
|
| 384 | + if (!$terminaison_dest) { |
|
| 385 | + return false; |
|
| 386 | + } |
|
| 387 | + |
|
| 388 | + $nom_fichier = substr($fichier, 0, strlen($fichier) - (strlen($terminaison) + 1)); |
|
| 389 | + $fichier_dest = $nom_fichier; |
|
| 390 | + if ( |
|
| 391 | + ($find_in_path and $f = find_in_path($fichier) and $fichier = $f) |
|
| 392 | + or @file_exists($f = $fichier) |
|
| 393 | + ) { |
|
| 394 | + // on passe la balise img a taille image qui exraira les attributs si possible |
|
| 395 | + // au lieu de faire un acces disque sur le fichier |
|
| 396 | + [$ret['hauteur'], $ret['largeur']] = taille_image($find_in_path ? $f : $img); |
|
| 397 | + $date_src = @filemtime($f); |
|
| 398 | + } elseif ( |
|
| 399 | + @file_exists($f = "$fichier.src") |
|
| 400 | + and lire_fichier($f, $valeurs) |
|
| 401 | + and $valeurs = unserialize($valeurs) |
|
| 402 | + and isset($valeurs['hauteur_dest']) |
|
| 403 | + and isset($valeurs['largeur_dest']) |
|
| 404 | + ) { |
|
| 405 | + $ret['hauteur'] = $valeurs['hauteur_dest']; |
|
| 406 | + $ret['largeur'] = $valeurs['largeur_dest']; |
|
| 407 | + $date_src = $valeurs['date']; |
|
| 408 | + } // pas de fichier source par la |
|
| 409 | + else { |
|
| 410 | + return false; |
|
| 411 | + } |
|
| 412 | + |
|
| 413 | + // pas de taille mesurable ? |
|
| 414 | + if (!$ret['hauteur'] |
|
| 415 | + or !($ret['hauteur'] = intval(round($ret['hauteur']))) |
|
| 416 | + or !$ret['largeur'] |
|
| 417 | + or !($ret['largeur'] = intval(round($ret['largeur']))) |
|
| 418 | + ) { |
|
| 419 | + return false; |
|
| 420 | + } |
|
| 421 | + |
|
| 422 | + // les images calculees dependent du chemin du fichier source |
|
| 423 | + // 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 |
|
| 424 | + // ce n'est pas totalement optimal en terme de stockage, mais chaque image est associee a un fichier .src |
|
| 425 | + // qui contient la methode de reconstrucion (le filtre + les arguments d'appel) et les arguments different entre prive et public |
|
| 426 | + // la mise en commun du fichier image cree donc un bug et des problemes qui necessiteraient beaucoup de complexite de code |
|
| 427 | + // alors que ca concerne peu de site au final |
|
| 428 | + // la release de r23632+r23633+r23634 a provoque peu de remontee de bug attestant du peu de sites impactes |
|
| 429 | + $identifiant = $fichier; |
|
| 430 | + |
|
| 431 | + // cas general : |
|
| 432 | + // on a un dossier cache commun et un nom de fichier qui varie avec l'effet |
|
| 433 | + // cas particulier de reduire : |
|
| 434 | + // un cache par dimension, et le nom de fichier est conserve, suffixe par la dimension aussi |
|
| 435 | + $cache = 'cache-gd2'; |
|
| 436 | + if (substr($effet, 0, 7) == 'reduire') { |
|
| 437 | + [, $maxWidth, $maxHeight] = explode('-', $effet); |
|
| 438 | + [$destWidth, $destHeight] = _image_ratio($ret['largeur'], $ret['hauteur'], $maxWidth, $maxHeight); |
|
| 439 | + $ret['largeur_dest'] = $destWidth; |
|
| 440 | + $ret['hauteur_dest'] = $destHeight; |
|
| 441 | + $effet = "L{$destWidth}xH$destHeight"; |
|
| 442 | + $cache = 'cache-vignettes'; |
|
| 443 | + $fichier_dest = basename($fichier_dest); |
|
| 444 | + if (($ret['largeur'] <= $maxWidth) && ($ret['hauteur'] <= $maxHeight)) { |
|
| 445 | + // on garde la terminaison initiale car image simplement copiee |
|
| 446 | + // et on postfixe son nom avec un md5 du path |
|
| 447 | + $terminaison_dest = $terminaison; |
|
| 448 | + $fichier_dest .= '-' . substr(md5("$identifiant"), 0, 5); |
|
| 449 | + } else { |
|
| 450 | + $fichier_dest .= '-' . substr(md5("$identifiant-$effet"), 0, 5); |
|
| 451 | + } |
|
| 452 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 453 | + $cache = sous_repertoire($cache, $effet); |
|
| 454 | + } else { |
|
| 455 | + $fichier_dest = md5("$identifiant-$effet"); |
|
| 456 | + $cache = sous_repertoire(_DIR_VAR, $cache); |
|
| 457 | + $cache = sous_repertoire($cache, substr($fichier_dest, 0, 2)); |
|
| 458 | + $fichier_dest = substr($fichier_dest, 2); |
|
| 459 | + } |
|
| 460 | + |
|
| 461 | + $fichier_dest = $cache . $fichier_dest . '.' . $terminaison_dest; |
|
| 462 | + |
|
| 463 | + $GLOBALS['images_calculees'][] = $fichier_dest; |
|
| 464 | + |
|
| 465 | + $creer = true; |
|
| 466 | + // si recalcul des images demande, recalculer chaque image une fois |
|
| 467 | + if (defined('_VAR_IMAGES') and _VAR_IMAGES and !isset($images_recalcul[$fichier_dest])) { |
|
| 468 | + $images_recalcul[$fichier_dest] = true; |
|
| 469 | + } else { |
|
| 470 | + if (@file_exists($f = $fichier_dest)) { |
|
| 471 | + if (filemtime($f) >= $date_src) { |
|
| 472 | + $creer = false; |
|
| 473 | + } |
|
| 474 | + } else { |
|
| 475 | + if ( |
|
| 476 | + @file_exists($f = "$fichier_dest.src") |
|
| 477 | + and lire_fichier($f, $valeurs) |
|
| 478 | + and $valeurs = unserialize($valeurs) |
|
| 479 | + and $valeurs['date'] >= $date_src |
|
| 480 | + ) { |
|
| 481 | + $creer = false; |
|
| 482 | + } |
|
| 483 | + } |
|
| 484 | + } |
|
| 485 | + if ($creer) { |
|
| 486 | + if (!@file_exists($fichier)) { |
|
| 487 | + if (!@file_exists("$fichier.src")) { |
|
| 488 | + spip_log("Image absente : $fichier"); |
|
| 489 | + |
|
| 490 | + return false; |
|
| 491 | + } |
|
| 492 | + # on reconstruit l'image source absente a partir de la chaine des .src |
|
| 493 | + reconstruire_image_intermediaire($fichier); |
|
| 494 | + } |
|
| 495 | + } |
|
| 496 | + |
|
| 497 | + if ($creer) { |
|
| 498 | + spip_log( |
|
| 499 | + 'filtre image ' . ($fonction_creation ? reset($fonction_creation) : '') . "[$effet] sur $fichier", |
|
| 500 | + 'images' . _LOG_DEBUG |
|
| 501 | + ); |
|
| 502 | + } |
|
| 503 | + |
|
| 504 | + $term_fonction = _image_trouver_extension_pertinente($fichier); |
|
| 505 | + $ret['fonction_imagecreatefrom'] = '_imagecreatefrom' . $term_fonction; |
|
| 506 | + $ret['fichier'] = $fichier; |
|
| 507 | + $ret['fonction_image'] = '_image_image' . $terminaison_dest; |
|
| 508 | + $ret['fichier_dest'] = $fichier_dest; |
|
| 509 | + $ret['format_source'] = _image_extension_normalisee($terminaison); |
|
| 510 | + $ret['format_dest'] = $terminaison_dest; |
|
| 511 | + $ret['date_src'] = $date_src; |
|
| 512 | + $ret['creer'] = $creer; |
|
| 513 | + $ret['class'] = extraire_attribut($img, 'class'); |
|
| 514 | + $ret['alt'] = extraire_attribut($img, 'alt'); |
|
| 515 | + $ret['style'] = extraire_attribut($img, 'style'); |
|
| 516 | + $ret['tag'] = $img; |
|
| 517 | + if ($fonction_creation) { |
|
| 518 | + $ret['reconstruction'] = $fonction_creation; |
|
| 519 | + # ecrire ici comment creer le fichier, car il est pas sur qu'on l'ecrira reelement |
|
| 520 | + # cas de image_reduire qui finalement ne reduit pas l'image source |
|
| 521 | + # ca evite d'essayer de le creer au prochain hit si il n'est pas la |
|
| 522 | + #ecrire_fichier($ret['fichier_dest'].'.src',serialize($ret),true); |
|
| 523 | + } |
|
| 524 | + |
|
| 525 | + $ret = pipeline('image_preparer_filtre', [ |
|
| 526 | + 'args' => [ |
|
| 527 | + 'img' => $img, |
|
| 528 | + 'effet' => $effet, |
|
| 529 | + 'forcer_format' => $forcer_format, |
|
| 530 | + 'fonction_creation' => $fonction_creation, |
|
| 531 | + 'find_in_path' => $find_in_path, |
|
| 532 | + ], |
|
| 533 | + 'data' => $ret |
|
| 534 | + ]); |
|
| 535 | + |
|
| 536 | + // une globale pour le debug en cas de crash memoire |
|
| 537 | + $GLOBALS['derniere_image_calculee'] = $ret; |
|
| 538 | + |
|
| 539 | + // traiter le cas particulier des SVG : si le filtre n'a pas annonce explicitement qu'il savait faire, on delegue |
|
| 540 | + if ($term_fonction === 'svg') { |
|
| 541 | + if ($creer and !$support_svg) { |
|
| 542 | + process_image_svg_identite($ret); |
|
| 543 | + $ret['creer'] = false; |
|
| 544 | + } |
|
| 545 | + } |
|
| 546 | + else { |
|
| 547 | + if (!function_exists($ret['fonction_imagecreatefrom'])) { |
|
| 548 | + return false; |
|
| 549 | + } |
|
| 550 | + } |
|
| 551 | + |
|
| 552 | + return $ret; |
|
| 553 | 553 | } |
| 554 | 554 | |
| 555 | 555 | |
@@ -558,54 +558,54 @@ discard block |
||
| 558 | 558 | * @return array |
| 559 | 559 | */ |
| 560 | 560 | function _image_extensions_acceptees_en_entree() { |
| 561 | - static $extensions = null; |
|
| 562 | - if (empty($extensions)) { |
|
| 563 | - $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 564 | - if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 565 | - // action=tester renseigne gd_formats et detecte le support de webp |
|
| 566 | - $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 567 | - $extensions = array_map('trim', $extensions); |
|
| 568 | - $extensions = array_filter($extensions); |
|
| 569 | - if (in_array('jpg', $extensions)) { |
|
| 570 | - $extensions[] = 'jpeg'; |
|
| 571 | - } |
|
| 572 | - $extensions = array_unique($extensions); |
|
| 573 | - } |
|
| 574 | - $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 575 | - } |
|
| 576 | - |
|
| 577 | - return $extensions; |
|
| 561 | + static $extensions = null; |
|
| 562 | + if (empty($extensions)) { |
|
| 563 | + $extensions = ['png', 'gif', 'jpg', 'jpeg']; |
|
| 564 | + if (!empty($GLOBALS['meta']['gd_formats'])) { |
|
| 565 | + // action=tester renseigne gd_formats et detecte le support de webp |
|
| 566 | + $extensions = array_merge(explode(',', $GLOBALS['meta']['gd_formats'])); |
|
| 567 | + $extensions = array_map('trim', $extensions); |
|
| 568 | + $extensions = array_filter($extensions); |
|
| 569 | + if (in_array('jpg', $extensions)) { |
|
| 570 | + $extensions[] = 'jpeg'; |
|
| 571 | + } |
|
| 572 | + $extensions = array_unique($extensions); |
|
| 573 | + } |
|
| 574 | + $extensions[] = 'svg'; // on le supporte toujours avec des fonctions specifiques |
|
| 575 | + } |
|
| 576 | + |
|
| 577 | + return $extensions; |
|
| 578 | 578 | } |
| 579 | 579 | |
| 580 | 580 | /** |
| 581 | 581 | * @return array|string[]|null |
| 582 | 582 | */ |
| 583 | 583 | function _image_extensions_acceptees_en_sortie() { |
| 584 | - static $extensions = null; |
|
| 585 | - if (empty($extensions)) { |
|
| 586 | - $extensions = _image_extensions_acceptees_en_entree(); |
|
| 587 | - $extensions = array_diff($extensions, ['jpeg']); |
|
| 588 | - if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 589 | - $extensions = array_diff($extensions, ['gif']); |
|
| 590 | - } |
|
| 591 | - if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 592 | - $extensions = array_diff($extensions, ['webp']); |
|
| 593 | - } |
|
| 594 | - } |
|
| 595 | - |
|
| 596 | - return $extensions; |
|
| 584 | + static $extensions = null; |
|
| 585 | + if (empty($extensions)) { |
|
| 586 | + $extensions = _image_extensions_acceptees_en_entree(); |
|
| 587 | + $extensions = array_diff($extensions, ['jpeg']); |
|
| 588 | + if (in_array('gif', $extensions) and !function_exists('imagegif')) { |
|
| 589 | + $extensions = array_diff($extensions, ['gif']); |
|
| 590 | + } |
|
| 591 | + if (in_array('webp', $extensions) and !function_exists('imagewebp')) { |
|
| 592 | + $extensions = array_diff($extensions, ['webp']); |
|
| 593 | + } |
|
| 594 | + } |
|
| 595 | + |
|
| 596 | + return $extensions; |
|
| 597 | 597 | } |
| 598 | 598 | |
| 599 | 599 | function _image_extension_normalisee($extension) { |
| 600 | - $extension = strtolower($extension); |
|
| 601 | - if ($extension === 'jpeg') { |
|
| 602 | - $extension = 'jpg'; |
|
| 603 | - } |
|
| 604 | - return $extension; |
|
| 600 | + $extension = strtolower($extension); |
|
| 601 | + if ($extension === 'jpeg') { |
|
| 602 | + $extension = 'jpg'; |
|
| 603 | + } |
|
| 604 | + return $extension; |
|
| 605 | 605 | } |
| 606 | 606 | |
| 607 | 607 | function _image_extensions_conservent_transparence() { |
| 608 | - return ['png', 'webp']; |
|
| 608 | + return ['png', 'webp']; |
|
| 609 | 609 | } |
| 610 | 610 | |
| 611 | 611 | |
@@ -615,12 +615,12 @@ discard block |
||
| 615 | 615 | * @return string |
| 616 | 616 | */ |
| 617 | 617 | function _image_trouver_extension($path) { |
| 618 | - $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 619 | - if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 620 | - $terminaison = strtolower($regs[1]); |
|
| 621 | - return $terminaison; |
|
| 622 | - } |
|
| 623 | - return ''; |
|
| 618 | + $preg_extensions = implode('|', _image_extensions_acceptees_en_entree()); |
|
| 619 | + if (preg_match(",\.($preg_extensions)($|[?]),i", $path, $regs)) { |
|
| 620 | + $terminaison = strtolower($regs[1]); |
|
| 621 | + return $terminaison; |
|
| 622 | + } |
|
| 623 | + return ''; |
|
| 624 | 624 | } |
| 625 | 625 | |
| 626 | 626 | /** |
@@ -631,33 +631,33 @@ discard block |
||
| 631 | 631 | * @return string Extension, dans le format attendu par les fonctions 'gd' ('jpeg' pour les .jpg par exemple) |
| 632 | 632 | */ |
| 633 | 633 | function _image_trouver_extension_pertinente($path) { |
| 634 | - $path = supprimer_timestamp($path); |
|
| 635 | - $terminaison = _image_trouver_extension($path); |
|
| 636 | - if ($terminaison == 'jpg') { |
|
| 637 | - $terminaison = 'jpeg'; |
|
| 638 | - } |
|
| 639 | - |
|
| 640 | - if (!file_exists($path)) { |
|
| 641 | - return $terminaison; |
|
| 642 | - } |
|
| 643 | - |
|
| 644 | - if (!$info = @spip_getimagesize($path)) { |
|
| 645 | - return $terminaison; |
|
| 646 | - } |
|
| 647 | - |
|
| 648 | - if (isset($info['mime'])) { |
|
| 649 | - $mime = $info['mime']; |
|
| 650 | - } |
|
| 651 | - else { |
|
| 652 | - $mime = image_type_to_mime_type($info[2]); |
|
| 653 | - } |
|
| 654 | - |
|
| 655 | - $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 656 | - if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 657 | - spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 658 | - $terminaison = $_terminaison; |
|
| 659 | - } |
|
| 660 | - return $terminaison; |
|
| 634 | + $path = supprimer_timestamp($path); |
|
| 635 | + $terminaison = _image_trouver_extension($path); |
|
| 636 | + if ($terminaison == 'jpg') { |
|
| 637 | + $terminaison = 'jpeg'; |
|
| 638 | + } |
|
| 639 | + |
|
| 640 | + if (!file_exists($path)) { |
|
| 641 | + return $terminaison; |
|
| 642 | + } |
|
| 643 | + |
|
| 644 | + if (!$info = @spip_getimagesize($path)) { |
|
| 645 | + return $terminaison; |
|
| 646 | + } |
|
| 647 | + |
|
| 648 | + if (isset($info['mime'])) { |
|
| 649 | + $mime = $info['mime']; |
|
| 650 | + } |
|
| 651 | + else { |
|
| 652 | + $mime = image_type_to_mime_type($info[2]); |
|
| 653 | + } |
|
| 654 | + |
|
| 655 | + $_terminaison = _image_trouver_extension_depuis_mime($mime); |
|
| 656 | + if ($_terminaison and $_terminaison !== $terminaison) { |
|
| 657 | + spip_log("Mauvaise extension du fichier : $path . Son type mime est : $mime", 'images.' . _LOG_INFO_IMPORTANTE); |
|
| 658 | + $terminaison = $_terminaison; |
|
| 659 | + } |
|
| 660 | + return $terminaison; |
|
| 661 | 661 | } |
| 662 | 662 | |
| 663 | 663 | /** |
@@ -665,36 +665,36 @@ discard block |
||
| 665 | 665 | * @return string |
| 666 | 666 | */ |
| 667 | 667 | function _image_trouver_extension_depuis_mime($mime) { |
| 668 | - switch (strtolower($mime)) { |
|
| 669 | - case 'image/png': |
|
| 670 | - case 'image/x-png': |
|
| 671 | - $terminaison = 'png'; |
|
| 672 | - break; |
|
| 673 | - |
|
| 674 | - case 'image/jpg': |
|
| 675 | - case 'image/jpeg': |
|
| 676 | - case 'image/pjpeg': |
|
| 677 | - $terminaison = 'jpeg'; |
|
| 678 | - break; |
|
| 679 | - |
|
| 680 | - case 'image/gif': |
|
| 681 | - $terminaison = 'gif'; |
|
| 682 | - break; |
|
| 683 | - |
|
| 684 | - case 'image/webp': |
|
| 685 | - case 'image/x-webp': |
|
| 686 | - $terminaison = 'webp'; |
|
| 687 | - break; |
|
| 688 | - |
|
| 689 | - case 'image/svg+xml': |
|
| 690 | - $terminaison = 'svg'; |
|
| 691 | - break; |
|
| 692 | - |
|
| 693 | - default: |
|
| 694 | - $terminaison = ''; |
|
| 695 | - } |
|
| 696 | - |
|
| 697 | - return $terminaison; |
|
| 668 | + switch (strtolower($mime)) { |
|
| 669 | + case 'image/png': |
|
| 670 | + case 'image/x-png': |
|
| 671 | + $terminaison = 'png'; |
|
| 672 | + break; |
|
| 673 | + |
|
| 674 | + case 'image/jpg': |
|
| 675 | + case 'image/jpeg': |
|
| 676 | + case 'image/pjpeg': |
|
| 677 | + $terminaison = 'jpeg'; |
|
| 678 | + break; |
|
| 679 | + |
|
| 680 | + case 'image/gif': |
|
| 681 | + $terminaison = 'gif'; |
|
| 682 | + break; |
|
| 683 | + |
|
| 684 | + case 'image/webp': |
|
| 685 | + case 'image/x-webp': |
|
| 686 | + $terminaison = 'webp'; |
|
| 687 | + break; |
|
| 688 | + |
|
| 689 | + case 'image/svg+xml': |
|
| 690 | + $terminaison = 'svg'; |
|
| 691 | + break; |
|
| 692 | + |
|
| 693 | + default: |
|
| 694 | + $terminaison = ''; |
|
| 695 | + } |
|
| 696 | + |
|
| 697 | + return $terminaison; |
|
| 698 | 698 | } |
| 699 | 699 | |
| 700 | 700 | |
@@ -714,18 +714,18 @@ discard block |
||
| 714 | 714 | * Une ressource de type Image GD. |
| 715 | 715 | */ |
| 716 | 716 | function _imagecreatefrom_func(string $func, string $filename) { |
| 717 | - if (!function_exists($func)) { |
|
| 718 | - spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 719 | - erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 720 | - return null; |
|
| 721 | - } |
|
| 722 | - $img = @$func($filename); |
|
| 723 | - if (!$img) { |
|
| 724 | - spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 725 | - erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 726 | - $img = imagecreate(10, 10); |
|
| 727 | - } |
|
| 728 | - return $img; |
|
| 717 | + if (!function_exists($func)) { |
|
| 718 | + spip_log("GD indisponible : $func inexistante. Traitement $filename impossible.", _LOG_CRITIQUE); |
|
| 719 | + erreur_squelette("GD indisponible : $func inexistante. Traitement $filename impossible."); |
|
| 720 | + return null; |
|
| 721 | + } |
|
| 722 | + $img = @$func($filename); |
|
| 723 | + if (!$img) { |
|
| 724 | + spip_log("Erreur lecture imagecreatefromjpeg $filename", _LOG_CRITIQUE); |
|
| 725 | + erreur_squelette("Erreur lecture imagecreatefromjpeg $filename"); |
|
| 726 | + $img = imagecreate(10, 10); |
|
| 727 | + } |
|
| 728 | + return $img; |
|
| 729 | 729 | } |
| 730 | 730 | |
| 731 | 731 | /** |
@@ -741,7 +741,7 @@ discard block |
||
| 741 | 741 | * Une ressource de type Image GD. |
| 742 | 742 | */ |
| 743 | 743 | function _imagecreatefromjpeg($filename) { |
| 744 | - return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 744 | + return _imagecreatefrom_func('imagecreatefromjpeg', $filename); |
|
| 745 | 745 | } |
| 746 | 746 | |
| 747 | 747 | /** |
@@ -757,7 +757,7 @@ discard block |
||
| 757 | 757 | * Une ressource de type Image GD. |
| 758 | 758 | */ |
| 759 | 759 | function _imagecreatefrompng($filename) { |
| 760 | - return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 760 | + return _imagecreatefrom_func('imagecreatefrompng', $filename); |
|
| 761 | 761 | } |
| 762 | 762 | |
| 763 | 763 | /** |
@@ -773,7 +773,7 @@ discard block |
||
| 773 | 773 | * Une ressource de type Image GD. |
| 774 | 774 | */ |
| 775 | 775 | function _imagecreatefromgif($filename) { |
| 776 | - return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 776 | + return _imagecreatefrom_func('imagecreatefromgif', $filename); |
|
| 777 | 777 | } |
| 778 | 778 | |
| 779 | 779 | |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | * Une ressource de type Image GD. |
| 791 | 791 | */ |
| 792 | 792 | function _imagecreatefromwebp($filename) { |
| 793 | - return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 793 | + return _imagecreatefrom_func('imagecreatefromwebp', $filename); |
|
| 794 | 794 | } |
| 795 | 795 | |
| 796 | 796 | /** |
@@ -808,24 +808,24 @@ discard block |
||
| 808 | 808 | * - true si une image est bien retournée. |
| 809 | 809 | */ |
| 810 | 810 | function _image_imagepng($img, $fichier) { |
| 811 | - if (!function_exists('imagepng')) { |
|
| 812 | - return false; |
|
| 813 | - } |
|
| 814 | - $tmp = $fichier . '.tmp'; |
|
| 815 | - $ret = imagepng($img, $tmp); |
|
| 816 | - if (file_exists($tmp)) { |
|
| 817 | - $taille_test = getimagesize($tmp); |
|
| 818 | - if ($taille_test[0] < 1) { |
|
| 819 | - return false; |
|
| 820 | - } |
|
| 821 | - |
|
| 822 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 823 | - @rename($tmp, $fichier); |
|
| 824 | - |
|
| 825 | - return $ret; |
|
| 826 | - } |
|
| 827 | - |
|
| 828 | - return false; |
|
| 811 | + if (!function_exists('imagepng')) { |
|
| 812 | + return false; |
|
| 813 | + } |
|
| 814 | + $tmp = $fichier . '.tmp'; |
|
| 815 | + $ret = imagepng($img, $tmp); |
|
| 816 | + if (file_exists($tmp)) { |
|
| 817 | + $taille_test = getimagesize($tmp); |
|
| 818 | + if ($taille_test[0] < 1) { |
|
| 819 | + return false; |
|
| 820 | + } |
|
| 821 | + |
|
| 822 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 823 | + @rename($tmp, $fichier); |
|
| 824 | + |
|
| 825 | + return $ret; |
|
| 826 | + } |
|
| 827 | + |
|
| 828 | + return false; |
|
| 829 | 829 | } |
| 830 | 830 | |
| 831 | 831 | /** |
@@ -843,24 +843,24 @@ discard block |
||
| 843 | 843 | * - true si une image est bien retournée. |
| 844 | 844 | */ |
| 845 | 845 | function _image_imagegif($img, $fichier) { |
| 846 | - if (!function_exists('imagegif')) { |
|
| 847 | - return false; |
|
| 848 | - } |
|
| 849 | - $tmp = $fichier . '.tmp'; |
|
| 850 | - $ret = imagegif($img, $tmp); |
|
| 851 | - if (file_exists($tmp)) { |
|
| 852 | - $taille_test = getimagesize($tmp); |
|
| 853 | - if ($taille_test[0] < 1) { |
|
| 854 | - return false; |
|
| 855 | - } |
|
| 856 | - |
|
| 857 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 858 | - @rename($tmp, $fichier); |
|
| 859 | - |
|
| 860 | - return $ret; |
|
| 861 | - } |
|
| 862 | - |
|
| 863 | - return false; |
|
| 846 | + if (!function_exists('imagegif')) { |
|
| 847 | + return false; |
|
| 848 | + } |
|
| 849 | + $tmp = $fichier . '.tmp'; |
|
| 850 | + $ret = imagegif($img, $tmp); |
|
| 851 | + if (file_exists($tmp)) { |
|
| 852 | + $taille_test = getimagesize($tmp); |
|
| 853 | + if ($taille_test[0] < 1) { |
|
| 854 | + return false; |
|
| 855 | + } |
|
| 856 | + |
|
| 857 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 858 | + @rename($tmp, $fichier); |
|
| 859 | + |
|
| 860 | + return $ret; |
|
| 861 | + } |
|
| 862 | + |
|
| 863 | + return false; |
|
| 864 | 864 | } |
| 865 | 865 | |
| 866 | 866 | /** |
@@ -883,29 +883,29 @@ discard block |
||
| 883 | 883 | * - true si une image est bien retournée. |
| 884 | 884 | */ |
| 885 | 885 | function _image_imagejpg($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 886 | - if (!function_exists('imagejpeg')) { |
|
| 887 | - return false; |
|
| 888 | - } |
|
| 889 | - $tmp = $fichier . '.tmp'; |
|
| 886 | + if (!function_exists('imagejpeg')) { |
|
| 887 | + return false; |
|
| 888 | + } |
|
| 889 | + $tmp = $fichier . '.tmp'; |
|
| 890 | 890 | |
| 891 | - // Enable interlancing |
|
| 892 | - imageinterlace($img, true); |
|
| 891 | + // Enable interlancing |
|
| 892 | + imageinterlace($img, true); |
|
| 893 | 893 | |
| 894 | - $ret = imagejpeg($img, $tmp, $qualite); |
|
| 894 | + $ret = imagejpeg($img, $tmp, $qualite); |
|
| 895 | 895 | |
| 896 | - if (file_exists($tmp)) { |
|
| 897 | - $taille_test = getimagesize($tmp); |
|
| 898 | - if ($taille_test[0] < 1) { |
|
| 899 | - return false; |
|
| 900 | - } |
|
| 896 | + if (file_exists($tmp)) { |
|
| 897 | + $taille_test = getimagesize($tmp); |
|
| 898 | + if ($taille_test[0] < 1) { |
|
| 899 | + return false; |
|
| 900 | + } |
|
| 901 | 901 | |
| 902 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 903 | - @rename($tmp, $fichier); |
|
| 902 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 903 | + @rename($tmp, $fichier); |
|
| 904 | 904 | |
| 905 | - return $ret; |
|
| 906 | - } |
|
| 905 | + return $ret; |
|
| 906 | + } |
|
| 907 | 907 | |
| 908 | - return false; |
|
| 908 | + return false; |
|
| 909 | 909 | } |
| 910 | 910 | |
| 911 | 911 | /** |
@@ -923,9 +923,9 @@ discard block |
||
| 923 | 923 | * true si le fichier a bien été créé ; false sinon. |
| 924 | 924 | */ |
| 925 | 925 | function _image_imageico($img, $fichier) { |
| 926 | - $gd_image_array = [$img]; |
|
| 926 | + $gd_image_array = [$img]; |
|
| 927 | 927 | |
| 928 | - return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 928 | + return ecrire_fichier($fichier, phpthumb_functions::GD2ICOstring($gd_image_array)); |
|
| 929 | 929 | } |
| 930 | 930 | |
| 931 | 931 | |
@@ -944,24 +944,24 @@ discard block |
||
| 944 | 944 | * - true si une image est bien retournée. |
| 945 | 945 | */ |
| 946 | 946 | function _image_imagewebp($img, $fichier, $qualite = _IMG_GD_QUALITE) { |
| 947 | - if (!function_exists('imagewebp')) { |
|
| 948 | - return false; |
|
| 949 | - } |
|
| 950 | - $tmp = $fichier . '.tmp'; |
|
| 951 | - $ret = imagewebp($img, $tmp, $qualite); |
|
| 952 | - if (file_exists($tmp)) { |
|
| 953 | - $taille_test = getimagesize($tmp); |
|
| 954 | - if ($taille_test[0] < 1) { |
|
| 955 | - return false; |
|
| 956 | - } |
|
| 957 | - |
|
| 958 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 959 | - @rename($tmp, $fichier); |
|
| 960 | - |
|
| 961 | - return $ret; |
|
| 962 | - } |
|
| 963 | - |
|
| 964 | - return false; |
|
| 947 | + if (!function_exists('imagewebp')) { |
|
| 948 | + return false; |
|
| 949 | + } |
|
| 950 | + $tmp = $fichier . '.tmp'; |
|
| 951 | + $ret = imagewebp($img, $tmp, $qualite); |
|
| 952 | + if (file_exists($tmp)) { |
|
| 953 | + $taille_test = getimagesize($tmp); |
|
| 954 | + if ($taille_test[0] < 1) { |
|
| 955 | + return false; |
|
| 956 | + } |
|
| 957 | + |
|
| 958 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 959 | + @rename($tmp, $fichier); |
|
| 960 | + |
|
| 961 | + return $ret; |
|
| 962 | + } |
|
| 963 | + |
|
| 964 | + return false; |
|
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | /** |
@@ -981,35 +981,35 @@ discard block |
||
| 981 | 981 | */ |
| 982 | 982 | function _image_imagesvg($img, $fichier) { |
| 983 | 983 | |
| 984 | - $tmp = $fichier . '.tmp'; |
|
| 985 | - if (strpos($img, '<') === false) { |
|
| 986 | - $img = supprimer_timestamp($img); |
|
| 987 | - if (!file_exists($img)) { |
|
| 988 | - return false; |
|
| 989 | - } |
|
| 990 | - @copy($img, $tmp); |
|
| 991 | - if (filesize($tmp) == filesize($img)) { |
|
| 992 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 993 | - @rename($tmp, $fichier); |
|
| 994 | - return true; |
|
| 995 | - } |
|
| 996 | - return false; |
|
| 997 | - } |
|
| 998 | - |
|
| 999 | - file_put_contents($tmp, $img); |
|
| 1000 | - if (file_exists($tmp)) { |
|
| 1001 | - $taille_test = spip_getimagesize($tmp); |
|
| 1002 | - if ($taille_test[0] < 1) { |
|
| 1003 | - return false; |
|
| 1004 | - } |
|
| 1005 | - |
|
| 1006 | - spip_unlink($fichier); // le fichier peut deja exister |
|
| 1007 | - @rename($tmp, $fichier); |
|
| 1008 | - |
|
| 1009 | - return true; |
|
| 1010 | - } |
|
| 1011 | - |
|
| 1012 | - return false; |
|
| 984 | + $tmp = $fichier . '.tmp'; |
|
| 985 | + if (strpos($img, '<') === false) { |
|
| 986 | + $img = supprimer_timestamp($img); |
|
| 987 | + if (!file_exists($img)) { |
|
| 988 | + return false; |
|
| 989 | + } |
|
| 990 | + @copy($img, $tmp); |
|
| 991 | + if (filesize($tmp) == filesize($img)) { |
|
| 992 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 993 | + @rename($tmp, $fichier); |
|
| 994 | + return true; |
|
| 995 | + } |
|
| 996 | + return false; |
|
| 997 | + } |
|
| 998 | + |
|
| 999 | + file_put_contents($tmp, $img); |
|
| 1000 | + if (file_exists($tmp)) { |
|
| 1001 | + $taille_test = spip_getimagesize($tmp); |
|
| 1002 | + if ($taille_test[0] < 1) { |
|
| 1003 | + return false; |
|
| 1004 | + } |
|
| 1005 | + |
|
| 1006 | + spip_unlink($fichier); // le fichier peut deja exister |
|
| 1007 | + @rename($tmp, $fichier); |
|
| 1008 | + |
|
| 1009 | + return true; |
|
| 1010 | + } |
|
| 1011 | + |
|
| 1012 | + return false; |
|
| 1013 | 1013 | } |
| 1014 | 1014 | |
| 1015 | 1015 | |
@@ -1037,30 +1037,30 @@ discard block |
||
| 1037 | 1037 | * - false sinon. |
| 1038 | 1038 | */ |
| 1039 | 1039 | function _image_gd_output($img, $valeurs, $qualite = _IMG_GD_QUALITE, $fonction = null) { |
| 1040 | - if (is_null($fonction)) { |
|
| 1041 | - $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1042 | - } |
|
| 1043 | - $ret = false; |
|
| 1044 | - #un flag pour reperer les images gravees |
|
| 1045 | - $lock = ( |
|
| 1046 | - !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1047 | - or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1048 | - ); |
|
| 1049 | - if ( |
|
| 1050 | - function_exists($fonction) |
|
| 1051 | - && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1052 | - && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1053 | - && !$lock |
|
| 1054 | - ) { |
|
| 1055 | - if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1056 | - // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1057 | - [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1058 | - $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1059 | - ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1060 | - } |
|
| 1061 | - } |
|
| 1062 | - |
|
| 1063 | - return $ret; |
|
| 1040 | + if (is_null($fonction)) { |
|
| 1041 | + $fonction = '_image_image' . $valeurs['format_dest']; |
|
| 1042 | + } |
|
| 1043 | + $ret = false; |
|
| 1044 | + #un flag pour reperer les images gravees |
|
| 1045 | + $lock = ( |
|
| 1046 | + !statut_effacer_images_temporaires('get') // si la fonction n'a pas ete activee, on grave tout |
|
| 1047 | + or (@file_exists($valeurs['fichier_dest']) and !@file_exists($valeurs['fichier_dest'] . '.src')) |
|
| 1048 | + ); |
|
| 1049 | + if ( |
|
| 1050 | + function_exists($fonction) |
|
| 1051 | + && ($ret = $fonction($img, $valeurs['fichier_dest'], $qualite)) # on a reussi a creer l'image |
|
| 1052 | + && isset($valeurs['reconstruction']) # et on sait comment la resonctruire le cas echeant |
|
| 1053 | + && !$lock |
|
| 1054 | + ) { |
|
| 1055 | + if (@file_exists($valeurs['fichier_dest'])) { |
|
| 1056 | + // dans tous les cas mettre a jour la taille de l'image finale |
|
| 1057 | + [$valeurs['hauteur_dest'], $valeurs['largeur_dest']] = taille_image($valeurs['fichier_dest']); |
|
| 1058 | + $valeurs['date'] = @filemtime($valeurs['fichier_dest']); // pour la retrouver apres disparition |
|
| 1059 | + ecrire_fichier($valeurs['fichier_dest'] . '.src', serialize($valeurs), true); |
|
| 1060 | + } |
|
| 1061 | + } |
|
| 1062 | + |
|
| 1063 | + return $ret; |
|
| 1064 | 1064 | } |
| 1065 | 1065 | |
| 1066 | 1066 | /** |
@@ -1073,27 +1073,27 @@ discard block |
||
| 1073 | 1073 | * Chemin vers le fichier manquant |
| 1074 | 1074 | **/ |
| 1075 | 1075 | function reconstruire_image_intermediaire($fichier_manquant) { |
| 1076 | - $reconstruire = []; |
|
| 1077 | - $fichier = $fichier_manquant; |
|
| 1078 | - while ( |
|
| 1079 | - strpos($fichier, '://') === false |
|
| 1080 | - and !@file_exists($fichier) |
|
| 1081 | - and lire_fichier($src = "$fichier.src", $source) |
|
| 1082 | - and $valeurs = unserialize($source) |
|
| 1083 | - and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1084 | - ) { |
|
| 1085 | - spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1086 | - $reconstruire[] = $valeurs['reconstruction']; |
|
| 1087 | - } |
|
| 1088 | - while (count($reconstruire)) { |
|
| 1089 | - $r = array_pop($reconstruire); |
|
| 1090 | - $fonction = $r[0]; |
|
| 1091 | - $args = $r[1]; |
|
| 1092 | - $fonction(...$args); |
|
| 1093 | - } |
|
| 1094 | - // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1095 | - // mais l'on peut nettoyer les miettes de sa creation |
|
| 1096 | - ramasse_miettes($fichier_manquant); |
|
| 1076 | + $reconstruire = []; |
|
| 1077 | + $fichier = $fichier_manquant; |
|
| 1078 | + while ( |
|
| 1079 | + strpos($fichier, '://') === false |
|
| 1080 | + and !@file_exists($fichier) |
|
| 1081 | + and lire_fichier($src = "$fichier.src", $source) |
|
| 1082 | + and $valeurs = unserialize($source) |
|
| 1083 | + and ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1084 | + ) { |
|
| 1085 | + spip_unlink($src); // si jamais on a un timeout pendant la reconstruction, elle se fera naturellement au hit suivant |
|
| 1086 | + $reconstruire[] = $valeurs['reconstruction']; |
|
| 1087 | + } |
|
| 1088 | + while (count($reconstruire)) { |
|
| 1089 | + $r = array_pop($reconstruire); |
|
| 1090 | + $fonction = $r[0]; |
|
| 1091 | + $args = $r[1]; |
|
| 1092 | + $fonction(...$args); |
|
| 1093 | + } |
|
| 1094 | + // cette image intermediaire est commune a plusieurs series de filtre, il faut la conserver |
|
| 1095 | + // mais l'on peut nettoyer les miettes de sa creation |
|
| 1096 | + ramasse_miettes($fichier_manquant); |
|
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | 1099 | /** |
@@ -1113,28 +1113,28 @@ discard block |
||
| 1113 | 1113 | * Chemin du fichier d'image calculé |
| 1114 | 1114 | **/ |
| 1115 | 1115 | function ramasse_miettes($fichier) { |
| 1116 | - if ( |
|
| 1117 | - strpos($fichier, '://') !== false |
|
| 1118 | - or !lire_fichier($src = "$fichier.src", $source) |
|
| 1119 | - or !$valeurs = unserialize($source) |
|
| 1120 | - ) { |
|
| 1121 | - return; |
|
| 1122 | - } |
|
| 1123 | - spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1124 | - while ( |
|
| 1125 | - ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1126 | - and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1127 | - and (lire_fichier( |
|
| 1128 | - $src = "$fichier.src", |
|
| 1129 | - $source |
|
| 1130 | - )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1131 | - and ($valeurs = unserialize($source)) # et valide |
|
| 1132 | - ) { |
|
| 1133 | - # on efface le fichier |
|
| 1134 | - spip_unlink($fichier); |
|
| 1135 | - # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1136 | - #spip_unlink($src); |
|
| 1137 | - } |
|
| 1116 | + if ( |
|
| 1117 | + strpos($fichier, '://') !== false |
|
| 1118 | + or !lire_fichier($src = "$fichier.src", $source) |
|
| 1119 | + or !$valeurs = unserialize($source) |
|
| 1120 | + ) { |
|
| 1121 | + return; |
|
| 1122 | + } |
|
| 1123 | + spip_unlink($src); # on supprime la reference a sa source pour marquer cette image comme non intermediaire |
|
| 1124 | + while ( |
|
| 1125 | + ($fichier = $valeurs['fichier']) # l'origine est connue (on ne verifie pas son existence, qu'importe ...) |
|
| 1126 | + and (substr($fichier, 0, strlen(_DIR_VAR)) == _DIR_VAR) # et est dans local |
|
| 1127 | + and (lire_fichier( |
|
| 1128 | + $src = "$fichier.src", |
|
| 1129 | + $source |
|
| 1130 | + )) # le fichier a une source connue (c'est donc une image calculee intermediaire) |
|
| 1131 | + and ($valeurs = unserialize($source)) # et valide |
|
| 1132 | + ) { |
|
| 1133 | + # on efface le fichier |
|
| 1134 | + spip_unlink($fichier); |
|
| 1135 | + # mais laisse le .src qui permet de savoir comment reconstruire l'image si besoin |
|
| 1136 | + #spip_unlink($src); |
|
| 1137 | + } |
|
| 1138 | 1138 | } |
| 1139 | 1139 | |
| 1140 | 1140 | |
@@ -1159,31 +1159,31 @@ discard block |
||
| 1159 | 1159 | * Code HTML de l'image |
| 1160 | 1160 | **/ |
| 1161 | 1161 | function image_graver($img) { |
| 1162 | - // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1163 | - // des traitements auto a la fin d'une serie de filtres |
|
| 1164 | - $img = pipeline('post_image_filtrer', $img); |
|
| 1165 | - |
|
| 1166 | - $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1167 | - if (($p = strpos($fichier, '?')) !== false) { |
|
| 1168 | - $fichier = substr($fichier, 0, $p); |
|
| 1169 | - } |
|
| 1170 | - if (strlen($fichier) < 1) { |
|
| 1171 | - $fichier = $img; |
|
| 1172 | - } |
|
| 1173 | - # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1174 | - # et qu'il ne s'agit pas d'une URL |
|
| 1175 | - if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1176 | - reconstruire_image_intermediaire($fichier); |
|
| 1177 | - } |
|
| 1178 | - ramasse_miettes($fichier); |
|
| 1179 | - |
|
| 1180 | - // ajouter le timestamp si besoin |
|
| 1181 | - if (strpos($fichier_ori, '?') === false) { |
|
| 1182 | - // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1183 | - $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1184 | - } |
|
| 1185 | - |
|
| 1186 | - return $img; |
|
| 1162 | + // appeler le filtre post_image_filtrer qui permet de faire |
|
| 1163 | + // des traitements auto a la fin d'une serie de filtres |
|
| 1164 | + $img = pipeline('post_image_filtrer', $img); |
|
| 1165 | + |
|
| 1166 | + $fichier_ori = $fichier = extraire_attribut($img, 'src'); |
|
| 1167 | + if (($p = strpos($fichier, '?')) !== false) { |
|
| 1168 | + $fichier = substr($fichier, 0, $p); |
|
| 1169 | + } |
|
| 1170 | + if (strlen($fichier) < 1) { |
|
| 1171 | + $fichier = $img; |
|
| 1172 | + } |
|
| 1173 | + # si jamais le fichier final n'a pas ete calcule car suppose temporaire |
|
| 1174 | + # et qu'il ne s'agit pas d'une URL |
|
| 1175 | + if (strpos($fichier, '://') === false and !@file_exists($fichier)) { |
|
| 1176 | + reconstruire_image_intermediaire($fichier); |
|
| 1177 | + } |
|
| 1178 | + ramasse_miettes($fichier); |
|
| 1179 | + |
|
| 1180 | + // ajouter le timestamp si besoin |
|
| 1181 | + if (strpos($fichier_ori, '?') === false) { |
|
| 1182 | + // on utilise str_replace pour attraper le onmouseover des logo si besoin |
|
| 1183 | + $img = str_replace($fichier_ori, timestamp($fichier_ori), $img); |
|
| 1184 | + } |
|
| 1185 | + |
|
| 1186 | + return $img; |
|
| 1187 | 1187 | } |
| 1188 | 1188 | |
| 1189 | 1189 | /** |
@@ -1210,34 +1210,34 @@ discard block |
||
| 1210 | 1210 | * Code html modifié de la balise. |
| 1211 | 1211 | **/ |
| 1212 | 1212 | function _image_tag_changer_taille($tag, $width, $height, $style = false) { |
| 1213 | - if ($style === false) { |
|
| 1214 | - $style = extraire_attribut($tag, 'style'); |
|
| 1215 | - } |
|
| 1216 | - |
|
| 1217 | - // enlever le width et height du style |
|
| 1218 | - if ($style) { |
|
| 1219 | - $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1220 | - } |
|
| 1221 | - if ($style and $style[0] === ';') { |
|
| 1222 | - $style = substr($style, 1); |
|
| 1223 | - } |
|
| 1224 | - |
|
| 1225 | - // mettre des attributs de width et height sur les images, |
|
| 1226 | - // ca accelere le rendu du navigateur |
|
| 1227 | - // ca permet aux navigateurs de reserver la bonne taille |
|
| 1228 | - // quand on a desactive l'affichage des images. |
|
| 1229 | - $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1230 | - $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1231 | - |
|
| 1232 | - // attributs deprecies. Transformer en CSS |
|
| 1233 | - if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1234 | - $style = "margin:{$espace}px;" . $style; |
|
| 1235 | - $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1236 | - } |
|
| 1237 | - |
|
| 1238 | - $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1239 | - |
|
| 1240 | - return $tag; |
|
| 1213 | + if ($style === false) { |
|
| 1214 | + $style = extraire_attribut($tag, 'style'); |
|
| 1215 | + } |
|
| 1216 | + |
|
| 1217 | + // enlever le width et height du style |
|
| 1218 | + if ($style) { |
|
| 1219 | + $style = preg_replace(',(^|;)\s*(width|height)\s*:\s*[^;]+,ims', '', $style); |
|
| 1220 | + } |
|
| 1221 | + if ($style and $style[0] === ';') { |
|
| 1222 | + $style = substr($style, 1); |
|
| 1223 | + } |
|
| 1224 | + |
|
| 1225 | + // mettre des attributs de width et height sur les images, |
|
| 1226 | + // ca accelere le rendu du navigateur |
|
| 1227 | + // ca permet aux navigateurs de reserver la bonne taille |
|
| 1228 | + // quand on a desactive l'affichage des images. |
|
| 1229 | + $tag = inserer_attribut($tag, 'width', round($width)); |
|
| 1230 | + $tag = inserer_attribut($tag, 'height', round($height)); |
|
| 1231 | + |
|
| 1232 | + // attributs deprecies. Transformer en CSS |
|
| 1233 | + if ($espace = extraire_attribut($tag, 'hspace')) { |
|
| 1234 | + $style = "margin:{$espace}px;" . $style; |
|
| 1235 | + $tag = inserer_attribut($tag, 'hspace', ''); |
|
| 1236 | + } |
|
| 1237 | + |
|
| 1238 | + $tag = inserer_attribut($tag, 'style', (string) $style, true, $style ? false : true); |
|
| 1239 | + |
|
| 1240 | + return $tag; |
|
| 1241 | 1241 | } |
| 1242 | 1242 | |
| 1243 | 1243 | |
@@ -1263,72 +1263,72 @@ discard block |
||
| 1263 | 1263 | * Retourne le code HTML de l'image |
| 1264 | 1264 | **/ |
| 1265 | 1265 | function _image_ecrire_tag($valeurs, $surcharge = []) { |
| 1266 | - $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1267 | - |
|
| 1268 | - // fermer les tags img pas bien fermes; |
|
| 1269 | - $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1270 | - |
|
| 1271 | - // le style |
|
| 1272 | - $style = $valeurs['style']; |
|
| 1273 | - if (isset($surcharge['style'])) { |
|
| 1274 | - $style = $surcharge['style']; |
|
| 1275 | - unset($surcharge['style']); |
|
| 1276 | - } |
|
| 1277 | - |
|
| 1278 | - // traiter specifiquement la largeur et la hauteur |
|
| 1279 | - $width = $valeurs['largeur']; |
|
| 1280 | - if (isset($surcharge['width'])) { |
|
| 1281 | - $width = $surcharge['width']; |
|
| 1282 | - unset($surcharge['width']); |
|
| 1283 | - } |
|
| 1284 | - $height = $valeurs['hauteur']; |
|
| 1285 | - if (isset($surcharge['height'])) { |
|
| 1286 | - $height = $surcharge['height']; |
|
| 1287 | - unset($surcharge['height']); |
|
| 1288 | - } |
|
| 1289 | - |
|
| 1290 | - $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1291 | - // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1292 | - // on remplace toute les ref a src dans le tag |
|
| 1293 | - $src = extraire_attribut($tag, 'src'); |
|
| 1294 | - if (isset($surcharge['src'])) { |
|
| 1295 | - $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1296 | - // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1297 | - // pas garanti comme methode, mais mieux que rien |
|
| 1298 | - if (strpos($src, '&') !== false) { |
|
| 1299 | - $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1300 | - } |
|
| 1301 | - $src = $surcharge['src']; |
|
| 1302 | - unset($surcharge['src']); |
|
| 1303 | - } |
|
| 1304 | - |
|
| 1305 | - $class = $valeurs['class']; |
|
| 1306 | - if (isset($surcharge['class'])) { |
|
| 1307 | - $class = $surcharge['class']; |
|
| 1308 | - unset($surcharge['class']); |
|
| 1309 | - } |
|
| 1310 | - if (is_scalar($class) && strlen($class)) { |
|
| 1311 | - $tag = inserer_attribut($tag, 'class', $class); |
|
| 1312 | - } |
|
| 1313 | - |
|
| 1314 | - if (count($surcharge)) { |
|
| 1315 | - foreach ($surcharge as $attribut => $valeur) { |
|
| 1316 | - $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1317 | - } |
|
| 1318 | - } |
|
| 1319 | - |
|
| 1320 | - $tag = pipeline( |
|
| 1321 | - 'image_ecrire_tag_finir', |
|
| 1322 | - [ |
|
| 1323 | - 'args' => [ |
|
| 1324 | - 'valeurs' => $valeurs, |
|
| 1325 | - 'surcharge' => $surcharge, |
|
| 1326 | - ], |
|
| 1327 | - 'data' => $tag |
|
| 1328 | - ] |
|
| 1329 | - ); |
|
| 1330 | - |
|
| 1331 | - return $tag; |
|
| 1266 | + $valeurs = pipeline('image_ecrire_tag_preparer', $valeurs); |
|
| 1267 | + |
|
| 1268 | + // fermer les tags img pas bien fermes; |
|
| 1269 | + $tag = str_replace('>', '/>', str_replace('/>', '>', $valeurs['tag'])); |
|
| 1270 | + |
|
| 1271 | + // le style |
|
| 1272 | + $style = $valeurs['style']; |
|
| 1273 | + if (isset($surcharge['style'])) { |
|
| 1274 | + $style = $surcharge['style']; |
|
| 1275 | + unset($surcharge['style']); |
|
| 1276 | + } |
|
| 1277 | + |
|
| 1278 | + // traiter specifiquement la largeur et la hauteur |
|
| 1279 | + $width = $valeurs['largeur']; |
|
| 1280 | + if (isset($surcharge['width'])) { |
|
| 1281 | + $width = $surcharge['width']; |
|
| 1282 | + unset($surcharge['width']); |
|
| 1283 | + } |
|
| 1284 | + $height = $valeurs['hauteur']; |
|
| 1285 | + if (isset($surcharge['height'])) { |
|
| 1286 | + $height = $surcharge['height']; |
|
| 1287 | + unset($surcharge['height']); |
|
| 1288 | + } |
|
| 1289 | + |
|
| 1290 | + $tag = _image_tag_changer_taille($tag, $width, $height, $style); |
|
| 1291 | + // traiter specifiquement le src qui peut etre repris dans un onmouseout |
|
| 1292 | + // on remplace toute les ref a src dans le tag |
|
| 1293 | + $src = extraire_attribut($tag, 'src'); |
|
| 1294 | + if (isset($surcharge['src'])) { |
|
| 1295 | + $tag = str_replace($src, $surcharge['src'], $tag); |
|
| 1296 | + // si il y a des & dans src, alors ils peuvent provenir d'un & |
|
| 1297 | + // pas garanti comme methode, mais mieux que rien |
|
| 1298 | + if (strpos($src, '&') !== false) { |
|
| 1299 | + $tag = str_replace(str_replace('&', '&', $src), $surcharge['src'], $tag); |
|
| 1300 | + } |
|
| 1301 | + $src = $surcharge['src']; |
|
| 1302 | + unset($surcharge['src']); |
|
| 1303 | + } |
|
| 1304 | + |
|
| 1305 | + $class = $valeurs['class']; |
|
| 1306 | + if (isset($surcharge['class'])) { |
|
| 1307 | + $class = $surcharge['class']; |
|
| 1308 | + unset($surcharge['class']); |
|
| 1309 | + } |
|
| 1310 | + if (is_scalar($class) && strlen($class)) { |
|
| 1311 | + $tag = inserer_attribut($tag, 'class', $class); |
|
| 1312 | + } |
|
| 1313 | + |
|
| 1314 | + if (count($surcharge)) { |
|
| 1315 | + foreach ($surcharge as $attribut => $valeur) { |
|
| 1316 | + $tag = inserer_attribut($tag, $attribut, $valeur); |
|
| 1317 | + } |
|
| 1318 | + } |
|
| 1319 | + |
|
| 1320 | + $tag = pipeline( |
|
| 1321 | + 'image_ecrire_tag_finir', |
|
| 1322 | + [ |
|
| 1323 | + 'args' => [ |
|
| 1324 | + 'valeurs' => $valeurs, |
|
| 1325 | + 'surcharge' => $surcharge, |
|
| 1326 | + ], |
|
| 1327 | + 'data' => $tag |
|
| 1328 | + ] |
|
| 1329 | + ); |
|
| 1330 | + |
|
| 1331 | + return $tag; |
|
| 1332 | 1332 | } |
| 1333 | 1333 | |
| 1334 | 1334 | /** |
@@ -1351,267 +1351,267 @@ discard block |
||
| 1351 | 1351 | * Description de l'image, sinon null. |
| 1352 | 1352 | **/ |
| 1353 | 1353 | function _image_creer_vignette($valeurs, $maxWidth, $maxHeight, $process = 'AUTO', $force = false) { |
| 1354 | - $srcHeight = null; |
|
| 1355 | - $retour = []; |
|
| 1356 | - // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1357 | - // le premier format disponible, selon la methode demandee, est utilise |
|
| 1358 | - $image = $valeurs['fichier']; |
|
| 1359 | - $format = $valeurs['format_source']; |
|
| 1360 | - $destdir = dirname($valeurs['fichier_dest']); |
|
| 1361 | - $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1362 | - |
|
| 1363 | - $format_sortie = $valeurs['format_dest']; |
|
| 1364 | - |
|
| 1365 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1366 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1367 | - } |
|
| 1368 | - |
|
| 1369 | - // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1370 | - if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1371 | - return; |
|
| 1372 | - } |
|
| 1373 | - $destination = "$destdir/$destfile"; |
|
| 1374 | - |
|
| 1375 | - // calculer la taille |
|
| 1376 | - if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1377 | - if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1378 | - [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1379 | - } |
|
| 1380 | - } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1381 | - $destWidth = $maxWidth; |
|
| 1382 | - $destHeight = $maxHeight; |
|
| 1383 | - } else { |
|
| 1384 | - spip_log("echec $process sur $image"); |
|
| 1385 | - |
|
| 1386 | - return; |
|
| 1387 | - } |
|
| 1388 | - |
|
| 1389 | - $vignette = ''; |
|
| 1390 | - |
|
| 1391 | - // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1392 | - if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1393 | - $vignette = $destination . '.' . $format; |
|
| 1394 | - @copy($image, $vignette); |
|
| 1395 | - } |
|
| 1396 | - |
|
| 1397 | - elseif ($valeurs['format_source'] === 'svg') { |
|
| 1398 | - if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1399 | - $format_sortie = 'svg'; |
|
| 1400 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1401 | - $valeurs['fichier_dest'] = $vignette; |
|
| 1402 | - _image_gd_output($svg, $valeurs); |
|
| 1403 | - } |
|
| 1404 | - } |
|
| 1405 | - |
|
| 1406 | - // imagemagick en ligne de commande |
|
| 1407 | - elseif ($process == 'convert') { |
|
| 1408 | - if (!defined('_CONVERT_COMMAND')) { |
|
| 1409 | - define('_CONVERT_COMMAND', 'convert'); |
|
| 1410 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1411 | - if (!defined('_RESIZE_COMMAND')) { |
|
| 1412 | - define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1413 | - } |
|
| 1414 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1415 | - $commande = str_replace( |
|
| 1416 | - ['%x', '%y', '%src', '%dest'], |
|
| 1417 | - [ |
|
| 1418 | - $destWidth, |
|
| 1419 | - $destHeight, |
|
| 1420 | - escapeshellcmd($image), |
|
| 1421 | - escapeshellcmd($vignette) |
|
| 1422 | - ], |
|
| 1423 | - _RESIZE_COMMAND |
|
| 1424 | - ); |
|
| 1425 | - spip_log($commande); |
|
| 1426 | - exec($commande); |
|
| 1427 | - if (!@file_exists($vignette)) { |
|
| 1428 | - spip_log("echec convert sur $vignette"); |
|
| 1429 | - |
|
| 1430 | - return; // echec commande |
|
| 1431 | - } |
|
| 1432 | - } |
|
| 1433 | - |
|
| 1434 | - // php5 imagemagick |
|
| 1435 | - elseif ($process == 'imagick') { |
|
| 1436 | - if (!class_exists(\Imagick::class)) { |
|
| 1437 | - spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1438 | - |
|
| 1439 | - return; |
|
| 1440 | - } |
|
| 1441 | - |
|
| 1442 | - // chemin compatible Windows |
|
| 1443 | - $output = realpath(dirname($destination)); |
|
| 1444 | - if (!$output) { |
|
| 1445 | - return; |
|
| 1446 | - } |
|
| 1447 | - $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1448 | - |
|
| 1449 | - $imagick = new Imagick(); |
|
| 1450 | - $imagick->readImage(realpath($image)); |
|
| 1451 | - $imagick->resizeImage( |
|
| 1452 | - $destWidth, |
|
| 1453 | - $destHeight, |
|
| 1454 | - Imagick::FILTER_LANCZOS, |
|
| 1455 | - 1 |
|
| 1456 | - );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1457 | - $imagick->writeImage($vignette); |
|
| 1458 | - |
|
| 1459 | - if (!@file_exists($vignette)) { |
|
| 1460 | - spip_log("echec imagick sur $vignette"); |
|
| 1461 | - |
|
| 1462 | - return; |
|
| 1463 | - } |
|
| 1464 | - // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1465 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1466 | - } |
|
| 1467 | - |
|
| 1468 | - // netpbm |
|
| 1469 | - elseif ($process == 'netpbm') { |
|
| 1470 | - if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1471 | - define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1472 | - } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1473 | - if (_PNMSCALE_COMMAND == '') { |
|
| 1474 | - return; |
|
| 1475 | - } |
|
| 1476 | - $vignette = $destination . '.' . $format_sortie; |
|
| 1477 | - $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1478 | - if ($format == 'jpg') { |
|
| 1479 | - $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1480 | - exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1481 | - if (!($s = @filesize($vignette))) { |
|
| 1482 | - spip_unlink($vignette); |
|
| 1483 | - } |
|
| 1484 | - if (!@file_exists($vignette)) { |
|
| 1485 | - spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1486 | - |
|
| 1487 | - return; |
|
| 1488 | - } |
|
| 1489 | - } else { |
|
| 1490 | - if ($format == 'gif') { |
|
| 1491 | - $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1492 | - exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1493 | - if (!($s = @filesize($vignette))) { |
|
| 1494 | - spip_unlink($vignette); |
|
| 1495 | - } |
|
| 1496 | - if (!@file_exists($vignette)) { |
|
| 1497 | - spip_log("echec netpbm-gif sur $vignette"); |
|
| 1498 | - |
|
| 1499 | - return; |
|
| 1500 | - } |
|
| 1501 | - } else { |
|
| 1502 | - if ($format == 'png') { |
|
| 1503 | - $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | - exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | - if (!($s = @filesize($vignette))) { |
|
| 1506 | - spip_unlink($vignette); |
|
| 1507 | - } |
|
| 1508 | - if (!@file_exists($vignette)) { |
|
| 1509 | - spip_log("echec netpbm-png sur $vignette"); |
|
| 1510 | - |
|
| 1511 | - return; |
|
| 1512 | - } |
|
| 1513 | - } |
|
| 1514 | - } |
|
| 1515 | - } |
|
| 1516 | - } |
|
| 1517 | - |
|
| 1518 | - // gd ou gd2 |
|
| 1519 | - elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1520 | - if (!function_exists('gd_info')) { |
|
| 1521 | - spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1522 | - |
|
| 1523 | - return; |
|
| 1524 | - } |
|
| 1525 | - if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1526 | - spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1527 | - |
|
| 1528 | - return; |
|
| 1529 | - } |
|
| 1530 | - $destFormat = $format_sortie; |
|
| 1531 | - if (!$destFormat) { |
|
| 1532 | - spip_log("pas de format pour $image"); |
|
| 1533 | - |
|
| 1534 | - return; |
|
| 1535 | - } |
|
| 1536 | - |
|
| 1537 | - $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1538 | - if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1539 | - return; |
|
| 1540 | - } |
|
| 1541 | - $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1542 | - if (!$srcImage) { |
|
| 1543 | - spip_log('echec gd1/gd2'); |
|
| 1544 | - |
|
| 1545 | - return; |
|
| 1546 | - } |
|
| 1547 | - |
|
| 1548 | - // Initialisation de l'image destination |
|
| 1549 | - $destImage = null; |
|
| 1550 | - if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1551 | - $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1552 | - } |
|
| 1553 | - if (!$destImage) { |
|
| 1554 | - $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1555 | - } |
|
| 1556 | - |
|
| 1557 | - // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1558 | - $ok = false; |
|
| 1559 | - if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1560 | - if ($format == 'gif') { |
|
| 1561 | - // Si un GIF est transparent, |
|
| 1562 | - // fabriquer un PNG transparent |
|
| 1563 | - $transp = imagecolortransparent($srcImage); |
|
| 1564 | - if ($transp > 0) { |
|
| 1565 | - $destFormat = 'png'; |
|
| 1566 | - } |
|
| 1567 | - } |
|
| 1568 | - if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1569 | - // Conserver la transparence |
|
| 1570 | - if (function_exists('imageAntiAlias')) { |
|
| 1571 | - imageAntiAlias($destImage, true); |
|
| 1572 | - } |
|
| 1573 | - @imagealphablending($destImage, false); |
|
| 1574 | - @imagesavealpha($destImage, true); |
|
| 1575 | - } |
|
| 1576 | - $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | - } |
|
| 1578 | - if (!$ok) { |
|
| 1579 | - $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1580 | - } |
|
| 1581 | - |
|
| 1582 | - // Sauvegarde de l'image destination |
|
| 1583 | - $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1584 | - $valeurs['format_dest'] = $format = $destFormat; |
|
| 1585 | - _image_gd_output($destImage, $valeurs); |
|
| 1586 | - |
|
| 1587 | - if ($srcImage) { |
|
| 1588 | - ImageDestroy($srcImage); |
|
| 1589 | - } |
|
| 1590 | - ImageDestroy($destImage); |
|
| 1591 | - } |
|
| 1592 | - |
|
| 1593 | - if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1594 | - $size = [$destWidth, $destHeight]; |
|
| 1595 | - } |
|
| 1596 | - |
|
| 1597 | - // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1598 | - // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1599 | - if ($size[0] < 1) { |
|
| 1600 | - $size[0] = $destWidth; |
|
| 1601 | - } |
|
| 1602 | - if ($size[1] < 1) { |
|
| 1603 | - $size[1] = $destHeight; |
|
| 1604 | - } |
|
| 1605 | - |
|
| 1606 | - $retour['width'] = $largeur = $size[0]; |
|
| 1607 | - $retour['height'] = $hauteur = $size[1]; |
|
| 1608 | - |
|
| 1609 | - $retour['fichier'] = $vignette; |
|
| 1610 | - $retour['format'] = $format; |
|
| 1611 | - $retour['date'] = @filemtime($vignette); |
|
| 1612 | - |
|
| 1613 | - // renvoyer l'image |
|
| 1614 | - return $retour; |
|
| 1354 | + $srcHeight = null; |
|
| 1355 | + $retour = []; |
|
| 1356 | + // ordre de preference des formats graphiques pour creer les vignettes |
|
| 1357 | + // le premier format disponible, selon la methode demandee, est utilise |
|
| 1358 | + $image = $valeurs['fichier']; |
|
| 1359 | + $format = $valeurs['format_source']; |
|
| 1360 | + $destdir = dirname($valeurs['fichier_dest']); |
|
| 1361 | + $destfile = basename($valeurs['fichier_dest'], '.' . $valeurs['format_dest']); |
|
| 1362 | + |
|
| 1363 | + $format_sortie = $valeurs['format_dest']; |
|
| 1364 | + |
|
| 1365 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1366 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1367 | + } |
|
| 1368 | + |
|
| 1369 | + // si le doc n'est pas une image dans un format accetpable, refuser |
|
| 1370 | + if (!$force and !in_array($format, formats_image_acceptables(in_array($process, ['gd1', 'gd2'])))) { |
|
| 1371 | + return; |
|
| 1372 | + } |
|
| 1373 | + $destination = "$destdir/$destfile"; |
|
| 1374 | + |
|
| 1375 | + // calculer la taille |
|
| 1376 | + if (($srcWidth = $valeurs['largeur']) && ($srcHeight = $valeurs['hauteur'])) { |
|
| 1377 | + if (!($destWidth = $valeurs['largeur_dest']) || !($destHeight = $valeurs['hauteur_dest'])) { |
|
| 1378 | + [$destWidth, $destHeight] = _image_ratio($srcWidth, $srcHeight, $maxWidth, $maxHeight); |
|
| 1379 | + } |
|
| 1380 | + } elseif ($process == 'convert' or $process == 'imagick') { |
|
| 1381 | + $destWidth = $maxWidth; |
|
| 1382 | + $destHeight = $maxHeight; |
|
| 1383 | + } else { |
|
| 1384 | + spip_log("echec $process sur $image"); |
|
| 1385 | + |
|
| 1386 | + return; |
|
| 1387 | + } |
|
| 1388 | + |
|
| 1389 | + $vignette = ''; |
|
| 1390 | + |
|
| 1391 | + // Si l'image est de la taille demandee (ou plus petite), simplement la retourner |
|
| 1392 | + if ($srcWidth and $srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1393 | + $vignette = $destination . '.' . $format; |
|
| 1394 | + @copy($image, $vignette); |
|
| 1395 | + } |
|
| 1396 | + |
|
| 1397 | + elseif ($valeurs['format_source'] === 'svg') { |
|
| 1398 | + if ($svg = svg_redimensionner($valeurs['fichier'], $destWidth, $destHeight)) { |
|
| 1399 | + $format_sortie = 'svg'; |
|
| 1400 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1401 | + $valeurs['fichier_dest'] = $vignette; |
|
| 1402 | + _image_gd_output($svg, $valeurs); |
|
| 1403 | + } |
|
| 1404 | + } |
|
| 1405 | + |
|
| 1406 | + // imagemagick en ligne de commande |
|
| 1407 | + elseif ($process == 'convert') { |
|
| 1408 | + if (!defined('_CONVERT_COMMAND')) { |
|
| 1409 | + define('_CONVERT_COMMAND', 'convert'); |
|
| 1410 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1411 | + if (!defined('_RESIZE_COMMAND')) { |
|
| 1412 | + define('_RESIZE_COMMAND', _CONVERT_COMMAND . ' -quality ' . _IMG_CONVERT_QUALITE . ' -resize %xx%y! %src %dest'); |
|
| 1413 | + } |
|
| 1414 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1415 | + $commande = str_replace( |
|
| 1416 | + ['%x', '%y', '%src', '%dest'], |
|
| 1417 | + [ |
|
| 1418 | + $destWidth, |
|
| 1419 | + $destHeight, |
|
| 1420 | + escapeshellcmd($image), |
|
| 1421 | + escapeshellcmd($vignette) |
|
| 1422 | + ], |
|
| 1423 | + _RESIZE_COMMAND |
|
| 1424 | + ); |
|
| 1425 | + spip_log($commande); |
|
| 1426 | + exec($commande); |
|
| 1427 | + if (!@file_exists($vignette)) { |
|
| 1428 | + spip_log("echec convert sur $vignette"); |
|
| 1429 | + |
|
| 1430 | + return; // echec commande |
|
| 1431 | + } |
|
| 1432 | + } |
|
| 1433 | + |
|
| 1434 | + // php5 imagemagick |
|
| 1435 | + elseif ($process == 'imagick') { |
|
| 1436 | + if (!class_exists(\Imagick::class)) { |
|
| 1437 | + spip_log('Classe Imagick absente !', _LOG_ERREUR); |
|
| 1438 | + |
|
| 1439 | + return; |
|
| 1440 | + } |
|
| 1441 | + |
|
| 1442 | + // chemin compatible Windows |
|
| 1443 | + $output = realpath(dirname($destination)); |
|
| 1444 | + if (!$output) { |
|
| 1445 | + return; |
|
| 1446 | + } |
|
| 1447 | + $vignette = $output . DIRECTORY_SEPARATOR . basename($destination) . '.' . $format_sortie; |
|
| 1448 | + |
|
| 1449 | + $imagick = new Imagick(); |
|
| 1450 | + $imagick->readImage(realpath($image)); |
|
| 1451 | + $imagick->resizeImage( |
|
| 1452 | + $destWidth, |
|
| 1453 | + $destHeight, |
|
| 1454 | + Imagick::FILTER_LANCZOS, |
|
| 1455 | + 1 |
|
| 1456 | + );//, IMAGICK_FILTER_LANCZOS, _IMG_IMAGICK_QUALITE / 100); |
|
| 1457 | + $imagick->writeImage($vignette); |
|
| 1458 | + |
|
| 1459 | + if (!@file_exists($vignette)) { |
|
| 1460 | + spip_log("echec imagick sur $vignette"); |
|
| 1461 | + |
|
| 1462 | + return; |
|
| 1463 | + } |
|
| 1464 | + // remettre le chemin relatif car c'est ce qu'attend SPIP pour la suite (en particlier action/tester) |
|
| 1465 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1466 | + } |
|
| 1467 | + |
|
| 1468 | + // netpbm |
|
| 1469 | + elseif ($process == 'netpbm') { |
|
| 1470 | + if (!defined('_PNMSCALE_COMMAND')) { |
|
| 1471 | + define('_PNMSCALE_COMMAND', 'pnmscale'); |
|
| 1472 | + } // Securite : mes_options.php peut preciser le chemin absolu |
|
| 1473 | + if (_PNMSCALE_COMMAND == '') { |
|
| 1474 | + return; |
|
| 1475 | + } |
|
| 1476 | + $vignette = $destination . '.' . $format_sortie; |
|
| 1477 | + $pnmtojpeg_command = str_replace('pnmscale', 'pnmtojpeg', _PNMSCALE_COMMAND); |
|
| 1478 | + if ($format == 'jpg') { |
|
| 1479 | + $jpegtopnm_command = str_replace('pnmscale', 'jpegtopnm', _PNMSCALE_COMMAND); |
|
| 1480 | + exec("$jpegtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1481 | + if (!($s = @filesize($vignette))) { |
|
| 1482 | + spip_unlink($vignette); |
|
| 1483 | + } |
|
| 1484 | + if (!@file_exists($vignette)) { |
|
| 1485 | + spip_log("echec netpbm-jpg sur $vignette"); |
|
| 1486 | + |
|
| 1487 | + return; |
|
| 1488 | + } |
|
| 1489 | + } else { |
|
| 1490 | + if ($format == 'gif') { |
|
| 1491 | + $giftopnm_command = str_replace('pnmscale', 'giftopnm', _PNMSCALE_COMMAND); |
|
| 1492 | + exec("$giftopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1493 | + if (!($s = @filesize($vignette))) { |
|
| 1494 | + spip_unlink($vignette); |
|
| 1495 | + } |
|
| 1496 | + if (!@file_exists($vignette)) { |
|
| 1497 | + spip_log("echec netpbm-gif sur $vignette"); |
|
| 1498 | + |
|
| 1499 | + return; |
|
| 1500 | + } |
|
| 1501 | + } else { |
|
| 1502 | + if ($format == 'png') { |
|
| 1503 | + $pngtopnm_command = str_replace('pnmscale', 'pngtopnm', _PNMSCALE_COMMAND); |
|
| 1504 | + exec("$pngtopnm_command $image | " . _PNMSCALE_COMMAND . " -width $destWidth | $pnmtojpeg_command > $vignette"); |
|
| 1505 | + if (!($s = @filesize($vignette))) { |
|
| 1506 | + spip_unlink($vignette); |
|
| 1507 | + } |
|
| 1508 | + if (!@file_exists($vignette)) { |
|
| 1509 | + spip_log("echec netpbm-png sur $vignette"); |
|
| 1510 | + |
|
| 1511 | + return; |
|
| 1512 | + } |
|
| 1513 | + } |
|
| 1514 | + } |
|
| 1515 | + } |
|
| 1516 | + } |
|
| 1517 | + |
|
| 1518 | + // gd ou gd2 |
|
| 1519 | + elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1520 | + if (!function_exists('gd_info')) { |
|
| 1521 | + spip_log('Librairie GD absente !', _LOG_ERREUR); |
|
| 1522 | + |
|
| 1523 | + return; |
|
| 1524 | + } |
|
| 1525 | + if (_IMG_GD_MAX_PIXELS && $srcWidth * $srcHeight > _IMG_GD_MAX_PIXELS) { |
|
| 1526 | + spip_log('vignette gd1/gd2 impossible : ' . $srcWidth * $srcHeight . 'pixels'); |
|
| 1527 | + |
|
| 1528 | + return; |
|
| 1529 | + } |
|
| 1530 | + $destFormat = $format_sortie; |
|
| 1531 | + if (!$destFormat) { |
|
| 1532 | + spip_log("pas de format pour $image"); |
|
| 1533 | + |
|
| 1534 | + return; |
|
| 1535 | + } |
|
| 1536 | + |
|
| 1537 | + $fonction_imagecreatefrom = $valeurs['fonction_imagecreatefrom']; |
|
| 1538 | + if (!function_exists($fonction_imagecreatefrom)) { |
|
| 1539 | + return; |
|
| 1540 | + } |
|
| 1541 | + $srcImage = @$fonction_imagecreatefrom($image); |
|
| 1542 | + if (!$srcImage) { |
|
| 1543 | + spip_log('echec gd1/gd2'); |
|
| 1544 | + |
|
| 1545 | + return; |
|
| 1546 | + } |
|
| 1547 | + |
|
| 1548 | + // Initialisation de l'image destination |
|
| 1549 | + $destImage = null; |
|
| 1550 | + if ($process == 'gd2' and $destFormat != 'gif') { |
|
| 1551 | + $destImage = ImageCreateTrueColor($destWidth, $destHeight); |
|
| 1552 | + } |
|
| 1553 | + if (!$destImage) { |
|
| 1554 | + $destImage = ImageCreate($destWidth, $destHeight); |
|
| 1555 | + } |
|
| 1556 | + |
|
| 1557 | + // Recopie de l'image d'origine avec adaptation de la taille |
|
| 1558 | + $ok = false; |
|
| 1559 | + if (($process == 'gd2') and function_exists('ImageCopyResampled')) { |
|
| 1560 | + if ($format == 'gif') { |
|
| 1561 | + // Si un GIF est transparent, |
|
| 1562 | + // fabriquer un PNG transparent |
|
| 1563 | + $transp = imagecolortransparent($srcImage); |
|
| 1564 | + if ($transp > 0) { |
|
| 1565 | + $destFormat = 'png'; |
|
| 1566 | + } |
|
| 1567 | + } |
|
| 1568 | + if (in_array($destFormat, _image_extensions_conservent_transparence())) { |
|
| 1569 | + // Conserver la transparence |
|
| 1570 | + if (function_exists('imageAntiAlias')) { |
|
| 1571 | + imageAntiAlias($destImage, true); |
|
| 1572 | + } |
|
| 1573 | + @imagealphablending($destImage, false); |
|
| 1574 | + @imagesavealpha($destImage, true); |
|
| 1575 | + } |
|
| 1576 | + $ok = @ImageCopyResampled($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1577 | + } |
|
| 1578 | + if (!$ok) { |
|
| 1579 | + $ok = ImageCopyResized($destImage, $srcImage, 0, 0, 0, 0, $destWidth, $destHeight, $srcWidth, $srcHeight); |
|
| 1580 | + } |
|
| 1581 | + |
|
| 1582 | + // Sauvegarde de l'image destination |
|
| 1583 | + $valeurs['fichier_dest'] = $vignette = "$destination.$destFormat"; |
|
| 1584 | + $valeurs['format_dest'] = $format = $destFormat; |
|
| 1585 | + _image_gd_output($destImage, $valeurs); |
|
| 1586 | + |
|
| 1587 | + if ($srcImage) { |
|
| 1588 | + ImageDestroy($srcImage); |
|
| 1589 | + } |
|
| 1590 | + ImageDestroy($destImage); |
|
| 1591 | + } |
|
| 1592 | + |
|
| 1593 | + if (!$vignette or !$size = @spip_getimagesize($vignette)) { |
|
| 1594 | + $size = [$destWidth, $destHeight]; |
|
| 1595 | + } |
|
| 1596 | + |
|
| 1597 | + // Gaffe: en safe mode, pas d'acces a la vignette, |
|
| 1598 | + // donc risque de balancer "width='0'", ce qui masque l'image sous MSIE |
|
| 1599 | + if ($size[0] < 1) { |
|
| 1600 | + $size[0] = $destWidth; |
|
| 1601 | + } |
|
| 1602 | + if ($size[1] < 1) { |
|
| 1603 | + $size[1] = $destHeight; |
|
| 1604 | + } |
|
| 1605 | + |
|
| 1606 | + $retour['width'] = $largeur = $size[0]; |
|
| 1607 | + $retour['height'] = $hauteur = $size[1]; |
|
| 1608 | + |
|
| 1609 | + $retour['fichier'] = $vignette; |
|
| 1610 | + $retour['format'] = $format; |
|
| 1611 | + $retour['date'] = @filemtime($vignette); |
|
| 1612 | + |
|
| 1613 | + // renvoyer l'image |
|
| 1614 | + return $retour; |
|
| 1615 | 1615 | } |
| 1616 | 1616 | |
| 1617 | 1617 | /** |
@@ -1631,25 +1631,25 @@ discard block |
||
| 1631 | 1631 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1632 | 1632 | **/ |
| 1633 | 1633 | function _image_ratio(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1634 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1635 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1636 | - |
|
| 1637 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1638 | - $destWidth = $srcWidth; |
|
| 1639 | - $destHeight = $srcHeight; |
|
| 1640 | - } elseif ($ratioWidth < $ratioHeight) { |
|
| 1641 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1642 | - $destHeight = $maxHeight; |
|
| 1643 | - } else { |
|
| 1644 | - $destWidth = $maxWidth; |
|
| 1645 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1646 | - } |
|
| 1647 | - |
|
| 1648 | - return [ |
|
| 1649 | - intval(round($destWidth)), |
|
| 1650 | - intval(round($destHeight)), |
|
| 1651 | - max($ratioWidth, $ratioHeight) |
|
| 1652 | - ]; |
|
| 1634 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1635 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1636 | + |
|
| 1637 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1638 | + $destWidth = $srcWidth; |
|
| 1639 | + $destHeight = $srcHeight; |
|
| 1640 | + } elseif ($ratioWidth < $ratioHeight) { |
|
| 1641 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1642 | + $destHeight = $maxHeight; |
|
| 1643 | + } else { |
|
| 1644 | + $destWidth = $maxWidth; |
|
| 1645 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1646 | + } |
|
| 1647 | + |
|
| 1648 | + return [ |
|
| 1649 | + intval(round($destWidth)), |
|
| 1650 | + intval(round($destHeight)), |
|
| 1651 | + max($ratioWidth, $ratioHeight) |
|
| 1652 | + ]; |
|
| 1653 | 1653 | } |
| 1654 | 1654 | |
| 1655 | 1655 | /** |
@@ -1669,25 +1669,25 @@ discard block |
||
| 1669 | 1669 | * @return array Liste [ largeur, hauteur, ratio de réduction ] |
| 1670 | 1670 | **/ |
| 1671 | 1671 | function ratio_passe_partout(int $srcWidth, int $srcHeight, int $maxWidth, int $maxHeight): array { |
| 1672 | - $ratioWidth = $srcWidth / $maxWidth; |
|
| 1673 | - $ratioHeight = $srcHeight / $maxHeight; |
|
| 1674 | - |
|
| 1675 | - if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1676 | - $destWidth = $srcWidth; |
|
| 1677 | - $destHeight = $srcHeight; |
|
| 1678 | - } elseif ($ratioWidth > $ratioHeight) { |
|
| 1679 | - $destWidth = $srcWidth / $ratioHeight; |
|
| 1680 | - $destHeight = $maxHeight; |
|
| 1681 | - } else { |
|
| 1682 | - $destWidth = $maxWidth; |
|
| 1683 | - $destHeight = $srcHeight / $ratioWidth; |
|
| 1684 | - } |
|
| 1685 | - |
|
| 1686 | - return [ |
|
| 1687 | - intval(round($destWidth)), |
|
| 1688 | - intval(round($destHeight)), |
|
| 1689 | - min($ratioWidth, $ratioHeight) |
|
| 1690 | - ]; |
|
| 1672 | + $ratioWidth = $srcWidth / $maxWidth; |
|
| 1673 | + $ratioHeight = $srcHeight / $maxHeight; |
|
| 1674 | + |
|
| 1675 | + if ($srcWidth <= $maxWidth and $srcHeight <= $maxHeight) { |
|
| 1676 | + $destWidth = $srcWidth; |
|
| 1677 | + $destHeight = $srcHeight; |
|
| 1678 | + } elseif ($ratioWidth > $ratioHeight) { |
|
| 1679 | + $destWidth = $srcWidth / $ratioHeight; |
|
| 1680 | + $destHeight = $maxHeight; |
|
| 1681 | + } else { |
|
| 1682 | + $destWidth = $maxWidth; |
|
| 1683 | + $destHeight = $srcHeight / $ratioWidth; |
|
| 1684 | + } |
|
| 1685 | + |
|
| 1686 | + return [ |
|
| 1687 | + intval(round($destWidth)), |
|
| 1688 | + intval(round($destHeight)), |
|
| 1689 | + min($ratioWidth, $ratioHeight) |
|
| 1690 | + ]; |
|
| 1691 | 1691 | } |
| 1692 | 1692 | |
| 1693 | 1693 | |
@@ -1700,12 +1700,12 @@ discard block |
||
| 1700 | 1700 | * @return string |
| 1701 | 1701 | */ |
| 1702 | 1702 | function process_image_svg_identite($image) { |
| 1703 | - if ($image['creer']) { |
|
| 1704 | - $source = $image['fichier']; |
|
| 1705 | - _image_gd_output($source, $image); |
|
| 1706 | - } |
|
| 1703 | + if ($image['creer']) { |
|
| 1704 | + $source = $image['fichier']; |
|
| 1705 | + _image_gd_output($source, $image); |
|
| 1706 | + } |
|
| 1707 | 1707 | |
| 1708 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1708 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1709 | 1709 | } |
| 1710 | 1710 | |
| 1711 | 1711 | |
@@ -1738,109 +1738,109 @@ discard block |
||
| 1738 | 1738 | * Code HTML de la balise img produite |
| 1739 | 1739 | **/ |
| 1740 | 1740 | function process_image_reduire($fonction, $img, $taille, $taille_y, $force, $process = 'AUTO') { |
| 1741 | - $image = false; |
|
| 1742 | - if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1743 | - $process = $GLOBALS['meta']['image_process']; |
|
| 1744 | - } |
|
| 1745 | - # determiner le format de sortie |
|
| 1746 | - $format_sortie = false; // le choix par defaut sera bon |
|
| 1747 | - if ($process == 'netpbm') { |
|
| 1748 | - $format_sortie = 'jpg'; |
|
| 1749 | - } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1750 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1751 | - // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1752 | - $gd_formats = formats_image_acceptables(true); |
|
| 1753 | - if ( |
|
| 1754 | - is_array($image) |
|
| 1755 | - and (!in_array($image['format_dest'], $gd_formats) |
|
| 1756 | - or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1757 | - ) |
|
| 1758 | - ) { |
|
| 1759 | - if ($image['format_source'] == 'jpg') { |
|
| 1760 | - $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1761 | - } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1762 | - { |
|
| 1763 | - $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1764 | - } |
|
| 1765 | - // Choisir le format destination |
|
| 1766 | - // - on sauve de preference en JPEG (meilleure compression) |
|
| 1767 | - // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1768 | - # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1769 | - # pas *ecrire* |
|
| 1770 | - $format_sortie = ''; |
|
| 1771 | - foreach ($formats_sortie as $fmt) { |
|
| 1772 | - if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1773 | - $format_sortie = $fmt; |
|
| 1774 | - break; |
|
| 1775 | - } |
|
| 1776 | - } |
|
| 1777 | - $image = false; |
|
| 1778 | - } |
|
| 1779 | - } |
|
| 1780 | - |
|
| 1781 | - if (!is_array($image)) { |
|
| 1782 | - $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1783 | - } |
|
| 1784 | - |
|
| 1785 | - if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1786 | - spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1787 | - // on peut resizer en mode html si on dispose des elements |
|
| 1788 | - [$srcw, $srch] = taille_image($img); |
|
| 1789 | - if ($srcw and $srch) { |
|
| 1790 | - [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1791 | - |
|
| 1792 | - return _image_tag_changer_taille($img, $w, $h); |
|
| 1793 | - } |
|
| 1794 | - // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1795 | - // sous la forme style='max-width: NNpx;' |
|
| 1796 | - return inserer_attribut( |
|
| 1797 | - $img, |
|
| 1798 | - 'style', |
|
| 1799 | - "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1800 | - ); |
|
| 1801 | - } |
|
| 1802 | - |
|
| 1803 | - // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1804 | - if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1805 | - if ($image['creer']) { |
|
| 1806 | - @copy($image['fichier'], $image['fichier_dest']); |
|
| 1807 | - } |
|
| 1808 | - |
|
| 1809 | - return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1810 | - } |
|
| 1811 | - |
|
| 1812 | - if ($image['creer'] == false && !$force) { |
|
| 1813 | - return _image_ecrire_tag( |
|
| 1814 | - $image, |
|
| 1815 | - ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1816 | - ); |
|
| 1817 | - } |
|
| 1818 | - |
|
| 1819 | - if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1820 | - $destWidth = $image['largeur_dest']; |
|
| 1821 | - $destHeight = $image['hauteur_dest']; |
|
| 1822 | - $logo = $image['fichier']; |
|
| 1823 | - $date = $image['date_src']; |
|
| 1824 | - $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1825 | - |
|
| 1826 | - if ($preview && $preview['fichier']) { |
|
| 1827 | - $logo = $preview['fichier']; |
|
| 1828 | - $destWidth = $preview['width']; |
|
| 1829 | - $destHeight = $preview['height']; |
|
| 1830 | - $date = $preview['date']; |
|
| 1831 | - } |
|
| 1832 | - // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1833 | - // de l'image, de facon a tromper le cache du navigateur |
|
| 1834 | - // quand on fait supprimer/reuploader un logo |
|
| 1835 | - // (pas de filemtime si SAFE MODE) |
|
| 1836 | - $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1837 | - |
|
| 1838 | - return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1839 | - } |
|
| 1840 | - else { |
|
| 1841 | - # BMP, tiff ... les redacteurs osent tout! |
|
| 1842 | - return $img; |
|
| 1843 | - } |
|
| 1741 | + $image = false; |
|
| 1742 | + if (($process == 'AUTO') and isset($GLOBALS['meta']['image_process'])) { |
|
| 1743 | + $process = $GLOBALS['meta']['image_process']; |
|
| 1744 | + } |
|
| 1745 | + # determiner le format de sortie |
|
| 1746 | + $format_sortie = false; // le choix par defaut sera bon |
|
| 1747 | + if ($process == 'netpbm') { |
|
| 1748 | + $format_sortie = 'jpg'; |
|
| 1749 | + } elseif ($process == 'gd1' or $process == 'gd2') { |
|
| 1750 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1751 | + // on verifie que l'extension choisie est bonne (en principe oui) |
|
| 1752 | + $gd_formats = formats_image_acceptables(true); |
|
| 1753 | + if ( |
|
| 1754 | + is_array($image) |
|
| 1755 | + and (!in_array($image['format_dest'], $gd_formats) |
|
| 1756 | + or (!in_array($image['format_dest'], _image_extensions_acceptees_en_sortie())) |
|
| 1757 | + ) |
|
| 1758 | + ) { |
|
| 1759 | + if ($image['format_source'] == 'jpg') { |
|
| 1760 | + $formats_sortie = ['jpg', 'png', 'gif']; |
|
| 1761 | + } else // les gif sont passes en png preferentiellement pour etre homogene aux autres filtres images |
|
| 1762 | + { |
|
| 1763 | + $formats_sortie = ['png', 'jpg', 'gif']; |
|
| 1764 | + } |
|
| 1765 | + // Choisir le format destination |
|
| 1766 | + // - on sauve de preference en JPEG (meilleure compression) |
|
| 1767 | + // - pour le GIF : les GD recentes peuvent le lire mais pas l'ecrire |
|
| 1768 | + # bug : gd_formats contient la liste des fichiers qu'on sait *lire*, |
|
| 1769 | + # pas *ecrire* |
|
| 1770 | + $format_sortie = ''; |
|
| 1771 | + foreach ($formats_sortie as $fmt) { |
|
| 1772 | + if (in_array($fmt, $gd_formats) and in_array($fmt, _image_extensions_acceptees_en_sortie())) { |
|
| 1773 | + $format_sortie = $fmt; |
|
| 1774 | + break; |
|
| 1775 | + } |
|
| 1776 | + } |
|
| 1777 | + $image = false; |
|
| 1778 | + } |
|
| 1779 | + } |
|
| 1780 | + |
|
| 1781 | + if (!is_array($image)) { |
|
| 1782 | + $image = _image_valeurs_trans($img, "reduire-{$taille}-{$taille_y}", $format_sortie, $fonction, false, _SVG_SUPPORTED); |
|
| 1783 | + } |
|
| 1784 | + |
|
| 1785 | + if (!is_array($image) or !$image['largeur'] or !$image['hauteur']) { |
|
| 1786 | + spip_log("image_reduire_src:pas de version locale de $img ou extension non prise en charge"); |
|
| 1787 | + // on peut resizer en mode html si on dispose des elements |
|
| 1788 | + [$srcw, $srch] = taille_image($img); |
|
| 1789 | + if ($srcw and $srch) { |
|
| 1790 | + [$w, $h] = _image_ratio($srcw, $srch, $taille, $taille_y); |
|
| 1791 | + |
|
| 1792 | + return _image_tag_changer_taille($img, $w, $h); |
|
| 1793 | + } |
|
| 1794 | + // la on n'a pas d'infos sur l'image source... on refile le truc a css |
|
| 1795 | + // sous la forme style='max-width: NNpx;' |
|
| 1796 | + return inserer_attribut( |
|
| 1797 | + $img, |
|
| 1798 | + 'style', |
|
| 1799 | + "max-width: {$taille}px;max-width: min(100%,{$taille}px); max-height: {$taille_y}px" |
|
| 1800 | + ); |
|
| 1801 | + } |
|
| 1802 | + |
|
| 1803 | + // si l'image est plus petite que la cible retourner une copie cachee de l'image |
|
| 1804 | + if (($image['largeur'] <= $taille) && ($image['hauteur'] <= $taille_y)) { |
|
| 1805 | + if ($image['creer']) { |
|
| 1806 | + @copy($image['fichier'], $image['fichier_dest']); |
|
| 1807 | + } |
|
| 1808 | + |
|
| 1809 | + return _image_ecrire_tag($image, ['src' => $image['fichier_dest']]); |
|
| 1810 | + } |
|
| 1811 | + |
|
| 1812 | + if ($image['creer'] == false && !$force) { |
|
| 1813 | + return _image_ecrire_tag( |
|
| 1814 | + $image, |
|
| 1815 | + ['src' => $image['fichier_dest'], 'width' => $image['largeur_dest'], 'height' => $image['hauteur_dest']] |
|
| 1816 | + ); |
|
| 1817 | + } |
|
| 1818 | + |
|
| 1819 | + if (in_array($image['format_source'], _image_extensions_acceptees_en_entree())) { |
|
| 1820 | + $destWidth = $image['largeur_dest']; |
|
| 1821 | + $destHeight = $image['hauteur_dest']; |
|
| 1822 | + $logo = $image['fichier']; |
|
| 1823 | + $date = $image['date_src']; |
|
| 1824 | + $preview = _image_creer_vignette($image, $taille, $taille_y, $process, $force); |
|
| 1825 | + |
|
| 1826 | + if ($preview && $preview['fichier']) { |
|
| 1827 | + $logo = $preview['fichier']; |
|
| 1828 | + $destWidth = $preview['width']; |
|
| 1829 | + $destHeight = $preview['height']; |
|
| 1830 | + $date = $preview['date']; |
|
| 1831 | + } |
|
| 1832 | + // dans l'espace prive mettre un timestamp sur l'adresse |
|
| 1833 | + // de l'image, de facon a tromper le cache du navigateur |
|
| 1834 | + // quand on fait supprimer/reuploader un logo |
|
| 1835 | + // (pas de filemtime si SAFE MODE) |
|
| 1836 | + $date = test_espace_prive() ? ('?' . $date) : ''; |
|
| 1837 | + |
|
| 1838 | + return _image_ecrire_tag($image, ['src' => "$logo$date", 'width' => $destWidth, 'height' => $destHeight]); |
|
| 1839 | + } |
|
| 1840 | + else { |
|
| 1841 | + # BMP, tiff ... les redacteurs osent tout! |
|
| 1842 | + return $img; |
|
| 1843 | + } |
|
| 1844 | 1844 | } |
| 1845 | 1845 | |
| 1846 | 1846 | /** |
@@ -1854,145 +1854,145 @@ discard block |
||
| 1854 | 1854 | * Class phpthumb_functions |
| 1855 | 1855 | */ |
| 1856 | 1856 | class phpthumb_functions { |
| 1857 | - /** |
|
| 1858 | - * Retourne la couleur d'un pixel dans une image |
|
| 1859 | - * |
|
| 1860 | - * @param resource|GdImage $img |
|
| 1861 | - * @param int $x |
|
| 1862 | - * @param int $y |
|
| 1863 | - * @return array|bool |
|
| 1864 | - */ |
|
| 1865 | - public static function GetPixelColor(&$img, $x, $y) { |
|
| 1866 | - if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1867 | - return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1868 | - } |
|
| 1869 | - return false; |
|
| 1870 | - } |
|
| 1871 | - |
|
| 1872 | - /** |
|
| 1873 | - * Retourne un nombre dans une représentation en Little Endian |
|
| 1874 | - * |
|
| 1875 | - * @param int $number |
|
| 1876 | - * @param int $minbytes |
|
| 1877 | - * @return string |
|
| 1878 | - */ |
|
| 1879 | - public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1880 | - $intstring = ''; |
|
| 1881 | - while ($number > 0) { |
|
| 1882 | - $intstring = $intstring . chr($number & 255); |
|
| 1883 | - $number >>= 8; |
|
| 1884 | - } |
|
| 1885 | - |
|
| 1886 | - return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1887 | - } |
|
| 1888 | - |
|
| 1889 | - /** |
|
| 1890 | - * Transforme une ressource GD en image au format ICO |
|
| 1891 | - * |
|
| 1892 | - * @param array $gd_image_array |
|
| 1893 | - * Tableau de ressources d'images GD |
|
| 1894 | - * @return string |
|
| 1895 | - * Image au format ICO |
|
| 1896 | - */ |
|
| 1897 | - public static function GD2ICOstring(&$gd_image_array) { |
|
| 1898 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1899 | - $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1900 | - $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1901 | - $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1902 | - $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1903 | - |
|
| 1904 | - $icXOR[$key] = ''; |
|
| 1905 | - for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1906 | - for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1907 | - $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1908 | - $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1909 | - $r = $argb['red']; |
|
| 1910 | - $g = $argb['green']; |
|
| 1911 | - $b = $argb['blue']; |
|
| 1912 | - |
|
| 1913 | - if ($bpp[$key] == 32) { |
|
| 1914 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1915 | - } elseif ($bpp[$key] == 24) { |
|
| 1916 | - $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1917 | - } |
|
| 1918 | - |
|
| 1919 | - if ($a < 128) { |
|
| 1920 | - @$icANDmask[$key][$y] .= '1'; |
|
| 1921 | - } else { |
|
| 1922 | - @$icANDmask[$key][$y] .= '0'; |
|
| 1923 | - } |
|
| 1924 | - } |
|
| 1925 | - // mask bits are 32-bit aligned per scanline |
|
| 1926 | - while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1927 | - $icANDmask[$key][$y] .= '0'; |
|
| 1928 | - } |
|
| 1929 | - } |
|
| 1930 | - $icAND[$key] = ''; |
|
| 1931 | - foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1932 | - for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1933 | - $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1934 | - } |
|
| 1935 | - } |
|
| 1936 | - } |
|
| 1937 | - |
|
| 1938 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1939 | - $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1940 | - |
|
| 1941 | - // BITMAPINFOHEADER - 40 bytes |
|
| 1942 | - $BitmapInfoHeader[$key] = ''; |
|
| 1943 | - $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1944 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1945 | - // The biHeight member specifies the combined |
|
| 1946 | - // height of the XOR and AND masks. |
|
| 1947 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1948 | - $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1949 | - $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1950 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1951 | - $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1952 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1953 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1954 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1955 | - $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1956 | - } |
|
| 1957 | - |
|
| 1958 | - |
|
| 1959 | - $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1960 | - $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1961 | - $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1962 | - |
|
| 1963 | - $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1964 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | - // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1966 | - |
|
| 1967 | - $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1968 | - $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1969 | - $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1970 | - $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1971 | - |
|
| 1972 | - $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1973 | - $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1974 | - |
|
| 1975 | - $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1976 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | - $dwBytesInRes, |
|
| 1978 | - 4 |
|
| 1979 | - ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1980 | - |
|
| 1981 | - $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1982 | - $dwImageOffset, |
|
| 1983 | - 4 |
|
| 1984 | - ); // dwImageOffset; // Where in the file is this image? |
|
| 1985 | - $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1986 | - $dwImageOffset += strlen($icXOR[$key]); |
|
| 1987 | - $dwImageOffset += strlen($icAND[$key]); |
|
| 1988 | - } |
|
| 1989 | - |
|
| 1990 | - foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | - $icondata .= $BitmapInfoHeader[$key]; |
|
| 1992 | - $icondata .= $icXOR[$key]; |
|
| 1993 | - $icondata .= $icAND[$key]; |
|
| 1994 | - } |
|
| 1995 | - |
|
| 1996 | - return $icondata; |
|
| 1997 | - } |
|
| 1857 | + /** |
|
| 1858 | + * Retourne la couleur d'un pixel dans une image |
|
| 1859 | + * |
|
| 1860 | + * @param resource|GdImage $img |
|
| 1861 | + * @param int $x |
|
| 1862 | + * @param int $y |
|
| 1863 | + * @return array|bool |
|
| 1864 | + */ |
|
| 1865 | + public static function GetPixelColor(&$img, $x, $y) { |
|
| 1866 | + if (is_resource($img) || (is_object($img) && $img instanceof \GdImage)) { |
|
| 1867 | + return @ImageColorsForIndex($img, @ImageColorAt($img, $x, $y)); |
|
| 1868 | + } |
|
| 1869 | + return false; |
|
| 1870 | + } |
|
| 1871 | + |
|
| 1872 | + /** |
|
| 1873 | + * Retourne un nombre dans une représentation en Little Endian |
|
| 1874 | + * |
|
| 1875 | + * @param int $number |
|
| 1876 | + * @param int $minbytes |
|
| 1877 | + * @return string |
|
| 1878 | + */ |
|
| 1879 | + public static function LittleEndian2String($number, $minbytes = 1) { |
|
| 1880 | + $intstring = ''; |
|
| 1881 | + while ($number > 0) { |
|
| 1882 | + $intstring = $intstring . chr($number & 255); |
|
| 1883 | + $number >>= 8; |
|
| 1884 | + } |
|
| 1885 | + |
|
| 1886 | + return str_pad($intstring, $minbytes, "\x00", STR_PAD_RIGHT); |
|
| 1887 | + } |
|
| 1888 | + |
|
| 1889 | + /** |
|
| 1890 | + * Transforme une ressource GD en image au format ICO |
|
| 1891 | + * |
|
| 1892 | + * @param array $gd_image_array |
|
| 1893 | + * Tableau de ressources d'images GD |
|
| 1894 | + * @return string |
|
| 1895 | + * Image au format ICO |
|
| 1896 | + */ |
|
| 1897 | + public static function GD2ICOstring(&$gd_image_array) { |
|
| 1898 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1899 | + $ImageWidths[$key] = ImageSX($gd_image); |
|
| 1900 | + $ImageHeights[$key] = ImageSY($gd_image); |
|
| 1901 | + $bpp[$key] = ImageIsTrueColor($gd_image) ? 32 : 24; |
|
| 1902 | + $totalcolors[$key] = ImageColorsTotal($gd_image); |
|
| 1903 | + |
|
| 1904 | + $icXOR[$key] = ''; |
|
| 1905 | + for ($y = $ImageHeights[$key] - 1; $y >= 0; $y--) { |
|
| 1906 | + for ($x = 0; $x < $ImageWidths[$key]; $x++) { |
|
| 1907 | + $argb = phpthumb_functions::GetPixelColor($gd_image, $x, $y); |
|
| 1908 | + $a = round(255 * ((127 - $argb['alpha']) / 127)); |
|
| 1909 | + $r = $argb['red']; |
|
| 1910 | + $g = $argb['green']; |
|
| 1911 | + $b = $argb['blue']; |
|
| 1912 | + |
|
| 1913 | + if ($bpp[$key] == 32) { |
|
| 1914 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r) . chr($a); |
|
| 1915 | + } elseif ($bpp[$key] == 24) { |
|
| 1916 | + $icXOR[$key] .= chr($b) . chr($g) . chr($r); |
|
| 1917 | + } |
|
| 1918 | + |
|
| 1919 | + if ($a < 128) { |
|
| 1920 | + @$icANDmask[$key][$y] .= '1'; |
|
| 1921 | + } else { |
|
| 1922 | + @$icANDmask[$key][$y] .= '0'; |
|
| 1923 | + } |
|
| 1924 | + } |
|
| 1925 | + // mask bits are 32-bit aligned per scanline |
|
| 1926 | + while (strlen($icANDmask[$key][$y]) % 32) { |
|
| 1927 | + $icANDmask[$key][$y] .= '0'; |
|
| 1928 | + } |
|
| 1929 | + } |
|
| 1930 | + $icAND[$key] = ''; |
|
| 1931 | + foreach ($icANDmask[$key] as $y => $scanlinemaskbits) { |
|
| 1932 | + for ($i = 0; $i < strlen($scanlinemaskbits); $i += 8) { |
|
| 1933 | + $icAND[$key] .= chr(bindec(str_pad(substr($scanlinemaskbits, $i, 8), 8, '0', STR_PAD_LEFT))); |
|
| 1934 | + } |
|
| 1935 | + } |
|
| 1936 | + } |
|
| 1937 | + |
|
| 1938 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1939 | + $biSizeImage = $ImageWidths[$key] * $ImageHeights[$key] * ($bpp[$key] / 8); |
|
| 1940 | + |
|
| 1941 | + // BITMAPINFOHEADER - 40 bytes |
|
| 1942 | + $BitmapInfoHeader[$key] = ''; |
|
| 1943 | + $BitmapInfoHeader[$key] .= "\x28\x00\x00\x00"; // DWORD biSize; |
|
| 1944 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageWidths[$key], 4); // LONG biWidth; |
|
| 1945 | + // The biHeight member specifies the combined |
|
| 1946 | + // height of the XOR and AND masks. |
|
| 1947 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($ImageHeights[$key] * 2, 4); // LONG biHeight; |
|
| 1948 | + $BitmapInfoHeader[$key] .= "\x01\x00"; // WORD biPlanes; |
|
| 1949 | + $BitmapInfoHeader[$key] .= chr($bpp[$key]) . "\x00"; // wBitCount; |
|
| 1950 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biCompression; |
|
| 1951 | + $BitmapInfoHeader[$key] .= phpthumb_functions::LittleEndian2String($biSizeImage, 4); // DWORD biSizeImage; |
|
| 1952 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biXPelsPerMeter; |
|
| 1953 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // LONG biYPelsPerMeter; |
|
| 1954 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrUsed; |
|
| 1955 | + $BitmapInfoHeader[$key] .= "\x00\x00\x00\x00"; // DWORD biClrImportant; |
|
| 1956 | + } |
|
| 1957 | + |
|
| 1958 | + |
|
| 1959 | + $icondata = "\x00\x00"; // idReserved; // Reserved (must be 0) |
|
| 1960 | + $icondata .= "\x01\x00"; // idType; // Resource Type (1 for icons) |
|
| 1961 | + $icondata .= phpthumb_functions::LittleEndian2String(count($gd_image_array), 2); // idCount; // How many images? |
|
| 1962 | + |
|
| 1963 | + $dwImageOffset = 6 + (count($gd_image_array) * 16); |
|
| 1964 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1965 | + // ICONDIRENTRY idEntries[1]; // An entry for each image (idCount of 'em) |
|
| 1966 | + |
|
| 1967 | + $icondata .= chr($ImageWidths[$key]); // bWidth; // Width, in pixels, of the image |
|
| 1968 | + $icondata .= chr($ImageHeights[$key]); // bHeight; // Height, in pixels, of the image |
|
| 1969 | + $icondata .= chr($totalcolors[$key]); // bColorCount; // Number of colors in image (0 if >=8bpp) |
|
| 1970 | + $icondata .= "\x00"; // bReserved; // Reserved ( must be 0) |
|
| 1971 | + |
|
| 1972 | + $icondata .= "\x01\x00"; // wPlanes; // Color Planes |
|
| 1973 | + $icondata .= chr($bpp[$key]) . "\x00"; // wBitCount; // Bits per pixel |
|
| 1974 | + |
|
| 1975 | + $dwBytesInRes = 40 + strlen($icXOR[$key]) + strlen($icAND[$key]); |
|
| 1976 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1977 | + $dwBytesInRes, |
|
| 1978 | + 4 |
|
| 1979 | + ); // dwBytesInRes; // How many bytes in this resource? |
|
| 1980 | + |
|
| 1981 | + $icondata .= phpthumb_functions::LittleEndian2String( |
|
| 1982 | + $dwImageOffset, |
|
| 1983 | + 4 |
|
| 1984 | + ); // dwImageOffset; // Where in the file is this image? |
|
| 1985 | + $dwImageOffset += strlen($BitmapInfoHeader[$key]); |
|
| 1986 | + $dwImageOffset += strlen($icXOR[$key]); |
|
| 1987 | + $dwImageOffset += strlen($icAND[$key]); |
|
| 1988 | + } |
|
| 1989 | + |
|
| 1990 | + foreach ($gd_image_array as $key => $gd_image) { |
|
| 1991 | + $icondata .= $BitmapInfoHeader[$key]; |
|
| 1992 | + $icondata .= $icXOR[$key]; |
|
| 1993 | + $icondata .= $icAND[$key]; |
|
| 1994 | + } |
|
| 1995 | + |
|
| 1996 | + return $icondata; |
|
| 1997 | + } |
|
| 1998 | 1998 | } |
@@ -193,11 +193,9 @@ |
||
| 193 | 193 | |
| 194 | 194 | if ($statut and test_espace_prive()) { |
| 195 | 195 | $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 196 | + } elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | 197 | $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
| 199 | - } |
|
| 200 | - else { |
|
| 198 | + } else { |
|
| 201 | 199 | $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
| 202 | 200 | } |
| 203 | 201 | $corps = "<div class='boutons'>$corps</div>"; |
@@ -74,7 +74,7 @@ discard block |
||
| 74 | 74 | lire_fichier($file, $c); |
| 75 | 75 | $css .= $c; |
| 76 | 76 | } |
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 77 | + $css = "<style type='text/css'>".$css.'</style>'; |
|
| 78 | 78 | } else { |
| 79 | 79 | foreach ($files as $name) { |
| 80 | 80 | $file = direction_css(find_in_theme($name)); |
@@ -87,19 +87,19 @@ discard block |
||
| 87 | 87 | define('_DOCTYPE_ECRIRE', ''); |
| 88 | 88 | } |
| 89 | 89 | |
| 90 | - return _DOCTYPE_ECRIRE . |
|
| 91 | - html_lang_attributes() . |
|
| 92 | - "<head>\n" . |
|
| 93 | - '<title>' . |
|
| 94 | - textebrut($titre) . |
|
| 95 | - "</title>\n" . |
|
| 96 | - "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | - $css . |
|
| 90 | + return _DOCTYPE_ECRIRE. |
|
| 91 | + html_lang_attributes(). |
|
| 92 | + "<head>\n". |
|
| 93 | + '<title>'. |
|
| 94 | + textebrut($titre). |
|
| 95 | + "</title>\n". |
|
| 96 | + "<meta name='viewport' content='width=device-width' />\n". |
|
| 97 | + $css. |
|
| 98 | 98 | '</head> |
| 99 | -<body' . $onLoad . " class='minipres'> |
|
| 99 | +<body' . $onLoad." class='minipres'> |
|
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 102 | + $titre. |
|
| 103 | 103 | "</h1> |
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
@@ -182,7 +182,7 @@ discard block |
||
| 182 | 182 | |
| 183 | 183 | $titre = ($titre == 'install') |
| 184 | 184 | ? _T('avis_espace_interdit') |
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 185 | + : $titre.' : '._T('info_acces_interdit'); |
|
| 186 | 186 | |
| 187 | 187 | $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
| 188 | 188 | $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
| 202 | 202 | } |
| 203 | 203 | $corps = "<div class='boutons'>$corps</div>"; |
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 204 | + spip_log($nom." $titre ".$_SERVER['REQUEST_URI']); |
|
| 205 | 205 | } |
| 206 | 206 | |
| 207 | 207 | if (!_AJAX) { |
@@ -219,6 +219,6 @@ discard block |
||
| 219 | 219 | foreach ($_POST as $v => $c) { |
| 220 | 220 | $url = parametre_url($url, $v, $c, '&'); |
| 221 | 221 | } |
| 222 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 222 | + ajax_retour('<div>'.$titre.redirige_formulaire($url).'</div>', false); |
|
| 223 | 223 | } |
| 224 | 224 | } |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Minipres |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | include_spip('inc/headers'); |
@@ -46,61 +46,61 @@ discard block |
||
| 46 | 46 | */ |
| 47 | 47 | function install_debut_html($titre = 'AUTO', $onLoad = '', $all_inline = false) { |
| 48 | 48 | |
| 49 | - utiliser_langue_visiteur(); |
|
| 50 | - |
|
| 51 | - http_no_cache(); |
|
| 52 | - |
|
| 53 | - if ($titre == 'AUTO') { |
|
| 54 | - $titre = _T('info_installation_systeme_publication'); |
|
| 55 | - } |
|
| 56 | - |
|
| 57 | - # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | - # lors de l'installation |
|
| 59 | - if (!headers_sent()) { |
|
| 60 | - header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | - } |
|
| 62 | - |
|
| 63 | - $css = ''; |
|
| 64 | - $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | - if ($all_inline) { |
|
| 66 | - // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | - foreach ($files as $name) { |
|
| 68 | - $file = direction_css(find_in_theme($name)); |
|
| 69 | - if (function_exists('minifier')) { |
|
| 70 | - $file = minifier($file); |
|
| 71 | - } else { |
|
| 72 | - $file = url_absolue_css($file); // precaution |
|
| 73 | - } |
|
| 74 | - lire_fichier($file, $c); |
|
| 75 | - $css .= $c; |
|
| 76 | - } |
|
| 77 | - $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | - } else { |
|
| 79 | - foreach ($files as $name) { |
|
| 80 | - $file = direction_css(find_in_theme($name)); |
|
| 81 | - $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - |
|
| 85 | - // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | - if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | - define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | - } |
|
| 89 | - |
|
| 90 | - return _DOCTYPE_ECRIRE . |
|
| 91 | - html_lang_attributes() . |
|
| 92 | - "<head>\n" . |
|
| 93 | - '<title>' . |
|
| 94 | - textebrut($titre) . |
|
| 95 | - "</title>\n" . |
|
| 96 | - "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | - $css . |
|
| 98 | - '</head> |
|
| 49 | + utiliser_langue_visiteur(); |
|
| 50 | + |
|
| 51 | + http_no_cache(); |
|
| 52 | + |
|
| 53 | + if ($titre == 'AUTO') { |
|
| 54 | + $titre = _T('info_installation_systeme_publication'); |
|
| 55 | + } |
|
| 56 | + |
|
| 57 | + # le charset est en utf-8, pour recuperer le nom comme il faut |
|
| 58 | + # lors de l'installation |
|
| 59 | + if (!headers_sent()) { |
|
| 60 | + header('Content-Type: text/html; charset=utf-8'); |
|
| 61 | + } |
|
| 62 | + |
|
| 63 | + $css = ''; |
|
| 64 | + $files = ['reset.css', 'clear.css', 'minipres.css']; |
|
| 65 | + if ($all_inline) { |
|
| 66 | + // inliner les CSS (optimisation de la page minipres qui passe en un seul hit a la demande) |
|
| 67 | + foreach ($files as $name) { |
|
| 68 | + $file = direction_css(find_in_theme($name)); |
|
| 69 | + if (function_exists('minifier')) { |
|
| 70 | + $file = minifier($file); |
|
| 71 | + } else { |
|
| 72 | + $file = url_absolue_css($file); // precaution |
|
| 73 | + } |
|
| 74 | + lire_fichier($file, $c); |
|
| 75 | + $css .= $c; |
|
| 76 | + } |
|
| 77 | + $css = "<style type='text/css'>" . $css . '</style>'; |
|
| 78 | + } else { |
|
| 79 | + foreach ($files as $name) { |
|
| 80 | + $file = direction_css(find_in_theme($name)); |
|
| 81 | + $css .= "<link rel='stylesheet' href='$file' type='text/css' />\n"; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + |
|
| 85 | + // au cas ou minipres() est appele avant spip_initialisation_suite() |
|
| 86 | + if (!defined('_DOCTYPE_ECRIRE')) { |
|
| 87 | + define('_DOCTYPE_ECRIRE', ''); |
|
| 88 | + } |
|
| 89 | + |
|
| 90 | + return _DOCTYPE_ECRIRE . |
|
| 91 | + html_lang_attributes() . |
|
| 92 | + "<head>\n" . |
|
| 93 | + '<title>' . |
|
| 94 | + textebrut($titre) . |
|
| 95 | + "</title>\n" . |
|
| 96 | + "<meta name='viewport' content='width=device-width' />\n" . |
|
| 97 | + $css . |
|
| 98 | + '</head> |
|
| 99 | 99 | <body' . $onLoad . " class='minipres'> |
| 100 | 100 | <div id='minipres'> |
| 101 | 101 | <h1>" . |
| 102 | - $titre . |
|
| 103 | - "</h1> |
|
| 102 | + $titre . |
|
| 103 | + "</h1> |
|
| 104 | 104 | <div>\n"; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -110,7 +110,7 @@ discard block |
||
| 110 | 110 | * @return string Code HTML |
| 111 | 111 | */ |
| 112 | 112 | function install_fin_html() { |
| 113 | - return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 113 | + return "\n\t</div>\n\t</div>\n</body>\n</html>"; |
|
| 114 | 114 | } |
| 115 | 115 | |
| 116 | 116 | |
@@ -148,88 +148,88 @@ discard block |
||
| 148 | 148 | */ |
| 149 | 149 | function minipres($titre = '', $corps = '', $options = []) { |
| 150 | 150 | |
| 151 | - // compat signature old |
|
| 152 | - // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | - $args = func_get_args(); |
|
| 154 | - if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | - $options = ['onload' => $args[2]]; |
|
| 156 | - } |
|
| 157 | - if (isset($args[3])) { |
|
| 158 | - $options['all_inline'] = $args[3]; |
|
| 159 | - } |
|
| 160 | - |
|
| 161 | - $options = array_merge([ |
|
| 162 | - 'onload' => '', |
|
| 163 | - 'all_inline' => false, |
|
| 164 | - ], $options); |
|
| 165 | - |
|
| 166 | - if (!defined('_AJAX')) { |
|
| 167 | - define('_AJAX', false); |
|
| 168 | - } // par securite |
|
| 169 | - if (!$titre) { |
|
| 170 | - if (!isset($options['status'])) { |
|
| 171 | - $options['status'] = 403; |
|
| 172 | - } |
|
| 173 | - if ( |
|
| 174 | - !$titre = _request('action') |
|
| 175 | - and !$titre = _request('exec') |
|
| 176 | - and !$titre = _request('page') |
|
| 177 | - ) { |
|
| 178 | - $titre = '?'; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $titre = spip_htmlspecialchars($titre); |
|
| 182 | - |
|
| 183 | - $titre = ($titre == 'install') |
|
| 184 | - ? _T('avis_espace_interdit') |
|
| 185 | - : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | - |
|
| 187 | - $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | - $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | - |
|
| 190 | - if ($statut != '0minirezo') { |
|
| 191 | - $titre = _T('info_acces_interdit'); |
|
| 192 | - } |
|
| 193 | - |
|
| 194 | - if ($statut and test_espace_prive()) { |
|
| 195 | - $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | - } |
|
| 197 | - elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | - $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | - } |
|
| 200 | - else { |
|
| 201 | - $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | - } |
|
| 203 | - $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | - spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | - } |
|
| 206 | - |
|
| 207 | - if (!_AJAX) { |
|
| 208 | - if (isset($options['status'])) { |
|
| 209 | - http_response_code($options['status']); |
|
| 210 | - } |
|
| 211 | - |
|
| 212 | - $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | - . $corps |
|
| 214 | - . install_fin_html(); |
|
| 215 | - |
|
| 216 | - if ( |
|
| 217 | - $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | - and empty($options['all_inline']) |
|
| 219 | - ) { |
|
| 220 | - define('_SET_HTML_BASE', true); |
|
| 221 | - include_spip('public/assembler'); |
|
| 222 | - $GLOBALS['html'] = true; |
|
| 223 | - page_base_href($html); |
|
| 224 | - } |
|
| 225 | - return $html; |
|
| 226 | - } else { |
|
| 227 | - include_spip('inc/headers'); |
|
| 228 | - include_spip('inc/actions'); |
|
| 229 | - $url = self('&', true); |
|
| 230 | - foreach ($_POST as $v => $c) { |
|
| 231 | - $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | - } |
|
| 233 | - ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | - } |
|
| 151 | + // compat signature old |
|
| 152 | + // minipres($titre='', $corps="", $onload='', $all_inline = false) |
|
| 153 | + $args = func_get_args(); |
|
| 154 | + if (isset($args[2]) and is_string($args[2])) { |
|
| 155 | + $options = ['onload' => $args[2]]; |
|
| 156 | + } |
|
| 157 | + if (isset($args[3])) { |
|
| 158 | + $options['all_inline'] = $args[3]; |
|
| 159 | + } |
|
| 160 | + |
|
| 161 | + $options = array_merge([ |
|
| 162 | + 'onload' => '', |
|
| 163 | + 'all_inline' => false, |
|
| 164 | + ], $options); |
|
| 165 | + |
|
| 166 | + if (!defined('_AJAX')) { |
|
| 167 | + define('_AJAX', false); |
|
| 168 | + } // par securite |
|
| 169 | + if (!$titre) { |
|
| 170 | + if (!isset($options['status'])) { |
|
| 171 | + $options['status'] = 403; |
|
| 172 | + } |
|
| 173 | + if ( |
|
| 174 | + !$titre = _request('action') |
|
| 175 | + and !$titre = _request('exec') |
|
| 176 | + and !$titre = _request('page') |
|
| 177 | + ) { |
|
| 178 | + $titre = '?'; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $titre = spip_htmlspecialchars($titre); |
|
| 182 | + |
|
| 183 | + $titre = ($titre == 'install') |
|
| 184 | + ? _T('avis_espace_interdit') |
|
| 185 | + : $titre . ' : ' . _T('info_acces_interdit'); |
|
| 186 | + |
|
| 187 | + $statut = $GLOBALS['visiteur_session']['statut'] ?? ''; |
|
| 188 | + $nom = $GLOBALS['visiteur_session']['nom'] ?? ''; |
|
| 189 | + |
|
| 190 | + if ($statut != '0minirezo') { |
|
| 191 | + $titre = _T('info_acces_interdit'); |
|
| 192 | + } |
|
| 193 | + |
|
| 194 | + if ($statut and test_espace_prive()) { |
|
| 195 | + $corps = bouton_action(_T('public:accueil_site'), generer_url_ecrire('accueil')); |
|
| 196 | + } |
|
| 197 | + elseif (!empty($_COOKIE['spip_admin'])) { |
|
| 198 | + $corps = bouton_action(_T('public:lien_connecter'), generer_url_public('login')); |
|
| 199 | + } |
|
| 200 | + else { |
|
| 201 | + $corps = bouton_action(_T('public:accueil_site'), $GLOBALS['meta']['adresse_site']); |
|
| 202 | + } |
|
| 203 | + $corps = "<div class='boutons'>$corps</div>"; |
|
| 204 | + spip_log($nom . " $titre " . $_SERVER['REQUEST_URI']); |
|
| 205 | + } |
|
| 206 | + |
|
| 207 | + if (!_AJAX) { |
|
| 208 | + if (isset($options['status'])) { |
|
| 209 | + http_response_code($options['status']); |
|
| 210 | + } |
|
| 211 | + |
|
| 212 | + $html = install_debut_html($titre, $options['onload'], $options['all_inline']) |
|
| 213 | + . $corps |
|
| 214 | + . install_fin_html(); |
|
| 215 | + |
|
| 216 | + if ( |
|
| 217 | + $GLOBALS['profondeur_url'] >= (_DIR_RESTREINT ? 1 : 2) |
|
| 218 | + and empty($options['all_inline']) |
|
| 219 | + ) { |
|
| 220 | + define('_SET_HTML_BASE', true); |
|
| 221 | + include_spip('public/assembler'); |
|
| 222 | + $GLOBALS['html'] = true; |
|
| 223 | + page_base_href($html); |
|
| 224 | + } |
|
| 225 | + return $html; |
|
| 226 | + } else { |
|
| 227 | + include_spip('inc/headers'); |
|
| 228 | + include_spip('inc/actions'); |
|
| 229 | + $url = self('&', true); |
|
| 230 | + foreach ($_POST as $v => $c) { |
|
| 231 | + $url = parametre_url($url, $v, $c, '&'); |
|
| 232 | + } |
|
| 233 | + ajax_retour('<div>' . $titre . redirige_formulaire($url) . '</div>', false); |
|
| 234 | + } |
|
| 235 | 235 | } |
@@ -102,8 +102,8 @@ discard block |
||
| 102 | 102 | && autoriser('onglet', "_$id") |
| 103 | 103 | ) { |
| 104 | 104 | $onglets[$id] = new Bouton( |
| 105 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | - $infos['titre'], // titre |
|
| 105 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 106 | + $infos['titre'], // titre |
|
| 107 | 107 | (isset($infos['action']) and $infos['action']) |
| 108 | 108 | ? generer_url_ecrire( |
| 109 | 109 | $infos['action'], |
@@ -142,5 +142,5 @@ discard block |
||
| 142 | 142 | $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 145 | + return !$res ? '' : (debut_onglet($class).$res.fin_onglet()); |
|
| 146 | 146 | } |
@@ -19,7 +19,7 @@ discard block |
||
| 19 | 19 | */ |
| 20 | 20 | |
| 21 | 21 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 22 | - return; |
|
| 22 | + return; |
|
| 23 | 23 | } |
| 24 | 24 | |
| 25 | 25 | /** |
@@ -35,35 +35,35 @@ discard block |
||
| 35 | 35 | */ |
| 36 | 36 | function definir_barre_onglets($script) { |
| 37 | 37 | |
| 38 | - $onglets = []; |
|
| 39 | - $liste_onglets = []; |
|
| 38 | + $onglets = []; |
|
| 39 | + $liste_onglets = []; |
|
| 40 | 40 | |
| 41 | - // ajouter les onglets issus des plugin via paquet.xml |
|
| 42 | - if (function_exists('onglets_plugins')) { |
|
| 43 | - $liste_onglets = onglets_plugins(); |
|
| 44 | - } |
|
| 41 | + // ajouter les onglets issus des plugin via paquet.xml |
|
| 42 | + if (function_exists('onglets_plugins')) { |
|
| 43 | + $liste_onglets = onglets_plugins(); |
|
| 44 | + } |
|
| 45 | 45 | |
| 46 | 46 | |
| 47 | - foreach ($liste_onglets as $id => $infos) { |
|
| 48 | - if ( |
|
| 49 | - ($parent = $infos['parent']) |
|
| 50 | - && $parent == $script |
|
| 51 | - && autoriser('onglet', "_$id") |
|
| 52 | - ) { |
|
| 53 | - $onglets[$id] = new Bouton( |
|
| 54 | - isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 55 | - $infos['titre'], // titre |
|
| 56 | - (isset($infos['action']) and $infos['action']) |
|
| 57 | - ? generer_url_ecrire( |
|
| 58 | - $infos['action'], |
|
| 59 | - (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 60 | - ) |
|
| 61 | - : null |
|
| 62 | - ); |
|
| 63 | - } |
|
| 64 | - } |
|
| 47 | + foreach ($liste_onglets as $id => $infos) { |
|
| 48 | + if ( |
|
| 49 | + ($parent = $infos['parent']) |
|
| 50 | + && $parent == $script |
|
| 51 | + && autoriser('onglet', "_$id") |
|
| 52 | + ) { |
|
| 53 | + $onglets[$id] = new Bouton( |
|
| 54 | + isset($infos['icone']) ? find_in_theme($infos['icone']) : '', // icone |
|
| 55 | + $infos['titre'], // titre |
|
| 56 | + (isset($infos['action']) and $infos['action']) |
|
| 57 | + ? generer_url_ecrire( |
|
| 58 | + $infos['action'], |
|
| 59 | + (isset($infos['parametres']) and $infos['parametres']) ? $infos['parametres'] : '' |
|
| 60 | + ) |
|
| 61 | + : null |
|
| 62 | + ); |
|
| 63 | + } |
|
| 64 | + } |
|
| 65 | 65 | |
| 66 | - return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 66 | + return pipeline('ajouter_onglets', ['data' => $onglets, 'args' => $script]); |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | * @return string |
| 82 | 82 | */ |
| 83 | 83 | function barre_onglets($rubrique, $ongletCourant, $class = 'barre_onglet') { |
| 84 | - include_spip('inc/presentation'); |
|
| 84 | + include_spip('inc/presentation'); |
|
| 85 | 85 | |
| 86 | - $res = ''; |
|
| 86 | + $res = ''; |
|
| 87 | 87 | |
| 88 | - foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 89 | - $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 90 | - $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 91 | - } |
|
| 88 | + foreach (definir_barre_onglets($rubrique) as $exec => $onglet) { |
|
| 89 | + $url = $onglet->url ?: generer_url_ecrire($exec); |
|
| 90 | + $res .= onglet(_T($onglet->libelle), $url, $exec, $ongletCourant, $onglet->icone); |
|
| 91 | + } |
|
| 92 | 92 | |
| 93 | - return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 93 | + return !$res ? '' : (debut_onglet($class) . $res . fin_onglet()); |
|
| 94 | 94 | } |
@@ -67,7 +67,7 @@ discard block |
||
| 67 | 67 | $_id_table = reset($_id_table); |
| 68 | 68 | } |
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 70 | + $requete['SELECT'][] = 't.'.$_id_table; |
|
| 71 | 71 | $a = []; |
| 72 | 72 | // Recherche fulltext |
| 73 | 73 | foreach ($champs as $champ => $poids) { |
@@ -78,13 +78,13 @@ discard block |
||
| 78 | 78 | $champ = "t.$champ"; |
| 79 | 79 | } |
| 80 | 80 | $requete['SELECT'][] = $champ; |
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 81 | + $a[] = $champ.' '.$methode.' '.$q; |
|
| 82 | 82 | } |
| 83 | 83 | } |
| 84 | 84 | if ($a) { |
| 85 | 85 | $requete['WHERE'][] = join(' OR ', $a); |
| 86 | 86 | } |
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table).' AS t'; |
|
| 88 | 88 | |
| 89 | 89 | $results = []; |
| 90 | 90 | |
@@ -252,8 +252,8 @@ discard block |
||
| 252 | 252 | ); |
| 253 | 253 | } // cas table de liaison generique spip_xxx_yyy |
| 254 | 254 | elseif ( |
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 255 | + $t = $trouver_table($table_arrivee.'_'.$table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart.'_'.$table_arrivee, $serveur) |
|
| 257 | 257 | ) { |
| 258 | 258 | $s = sql_select( |
| 259 | 259 | "$cle_depart,$cle_arrivee", |
@@ -292,12 +292,12 @@ discard block |
||
| 292 | 292 | } |
| 293 | 293 | if (isset($joint['champs']) and $joint['champs']) { |
| 294 | 294 | foreach ($joint['champs'] as $c => $val) { |
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 295 | + $results[$id]['champs'][$table_liee.'.'.$c] = $val; |
|
| 296 | 296 | } |
| 297 | 297 | } |
| 298 | 298 | if (isset($joint['matches']) and $joint['matches']) { |
| 299 | 299 | foreach ($joint['matches'] as $c => $val) { |
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 300 | + $results[$id]['matches'][$table_liee.'.'.$c] = $val; |
|
| 301 | 301 | } |
| 302 | 302 | } |
| 303 | 303 | } |
@@ -11,298 +11,298 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | |
| 18 | 18 | // methodes sql |
| 19 | 19 | function inc_recherche_to_array_dist($recherche, $options = []) { |
| 20 | 20 | |
| 21 | - // options par defaut |
|
| 22 | - $options = array_merge( |
|
| 23 | - [ |
|
| 24 | - 'score' => true, |
|
| 25 | - 'champs' => false, |
|
| 26 | - 'toutvoir' => false, |
|
| 27 | - 'matches' => false, |
|
| 28 | - 'jointures' => false |
|
| 29 | - ], |
|
| 30 | - $options |
|
| 31 | - ); |
|
| 21 | + // options par defaut |
|
| 22 | + $options = array_merge( |
|
| 23 | + [ |
|
| 24 | + 'score' => true, |
|
| 25 | + 'champs' => false, |
|
| 26 | + 'toutvoir' => false, |
|
| 27 | + 'matches' => false, |
|
| 28 | + 'jointures' => false |
|
| 29 | + ], |
|
| 30 | + $options |
|
| 31 | + ); |
|
| 32 | 32 | |
| 33 | - include_spip('inc/rechercher'); |
|
| 34 | - include_spip('inc/autoriser'); |
|
| 33 | + include_spip('inc/rechercher'); |
|
| 34 | + include_spip('inc/autoriser'); |
|
| 35 | 35 | |
| 36 | - $requete = [ |
|
| 37 | - 'SELECT' => [], |
|
| 38 | - 'FROM' => [], |
|
| 39 | - 'WHERE' => [], |
|
| 40 | - 'GROUPBY' => [], |
|
| 41 | - 'ORDERBY' => [], |
|
| 42 | - 'LIMIT' => '', |
|
| 43 | - 'HAVING' => [] |
|
| 44 | - ]; |
|
| 36 | + $requete = [ |
|
| 37 | + 'SELECT' => [], |
|
| 38 | + 'FROM' => [], |
|
| 39 | + 'WHERE' => [], |
|
| 40 | + 'GROUPBY' => [], |
|
| 41 | + 'ORDERBY' => [], |
|
| 42 | + 'LIMIT' => '', |
|
| 43 | + 'HAVING' => [] |
|
| 44 | + ]; |
|
| 45 | 45 | |
| 46 | - $table = sinon($options['table'], 'article'); |
|
| 47 | - if ($options['champs']) { |
|
| 48 | - $champs = $options['champs']; |
|
| 49 | - } else { |
|
| 50 | - $l = liste_des_champs(); |
|
| 51 | - $champs = $l['article']; |
|
| 52 | - } |
|
| 53 | - $serveur = $options['serveur']; |
|
| 46 | + $table = sinon($options['table'], 'article'); |
|
| 47 | + if ($options['champs']) { |
|
| 48 | + $champs = $options['champs']; |
|
| 49 | + } else { |
|
| 50 | + $l = liste_des_champs(); |
|
| 51 | + $champs = $l['article']; |
|
| 52 | + } |
|
| 53 | + $serveur = $options['serveur']; |
|
| 54 | 54 | |
| 55 | - [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 55 | + [$methode, $q, $preg] = expression_recherche($recherche, $options); |
|
| 56 | 56 | |
| 57 | - $jointures = $options['jointures'] |
|
| 58 | - ? liste_des_jointures() |
|
| 59 | - : []; |
|
| 57 | + $jointures = $options['jointures'] |
|
| 58 | + ? liste_des_jointures() |
|
| 59 | + : []; |
|
| 60 | 60 | |
| 61 | - $_id_table = id_table_objet($table); |
|
| 61 | + $_id_table = id_table_objet($table); |
|
| 62 | 62 | |
| 63 | - // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | - // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | - if (strpos($_id_table, ',') !== false) { |
|
| 66 | - $_id_table = explode(',', $_id_table); |
|
| 67 | - $_id_table = reset($_id_table); |
|
| 68 | - } |
|
| 63 | + // c'est un pis-aller : ca a peu de chance de marcher, mais mieux quand meme que en conservant la ',' |
|
| 64 | + // (aka ca marche au moins dans certains cas comme avec spip_formulaires_reponses_champs) |
|
| 65 | + if (strpos($_id_table, ',') !== false) { |
|
| 66 | + $_id_table = explode(',', $_id_table); |
|
| 67 | + $_id_table = reset($_id_table); |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | - $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | - $a = []; |
|
| 72 | - // Recherche fulltext |
|
| 73 | - foreach ($champs as $champ => $poids) { |
|
| 74 | - if (is_array($champ)) { |
|
| 75 | - spip_log('requetes imbriquees interdites'); |
|
| 76 | - } else { |
|
| 77 | - if (strpos($champ, '.') === false) { |
|
| 78 | - $champ = "t.$champ"; |
|
| 79 | - } |
|
| 80 | - $requete['SELECT'][] = $champ; |
|
| 81 | - $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | - } |
|
| 83 | - } |
|
| 84 | - if ($a) { |
|
| 85 | - $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | - } |
|
| 87 | - $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 70 | + $requete['SELECT'][] = 't.' . $_id_table; |
|
| 71 | + $a = []; |
|
| 72 | + // Recherche fulltext |
|
| 73 | + foreach ($champs as $champ => $poids) { |
|
| 74 | + if (is_array($champ)) { |
|
| 75 | + spip_log('requetes imbriquees interdites'); |
|
| 76 | + } else { |
|
| 77 | + if (strpos($champ, '.') === false) { |
|
| 78 | + $champ = "t.$champ"; |
|
| 79 | + } |
|
| 80 | + $requete['SELECT'][] = $champ; |
|
| 81 | + $a[] = $champ . ' ' . $methode . ' ' . $q; |
|
| 82 | + } |
|
| 83 | + } |
|
| 84 | + if ($a) { |
|
| 85 | + $requete['WHERE'][] = join(' OR ', $a); |
|
| 86 | + } |
|
| 87 | + $requete['FROM'][] = table_objet_sql($table) . ' AS t'; |
|
| 88 | 88 | |
| 89 | - $results = []; |
|
| 89 | + $results = []; |
|
| 90 | 90 | |
| 91 | - $s = sql_select( |
|
| 92 | - $requete['SELECT'], |
|
| 93 | - $requete['FROM'], |
|
| 94 | - $requete['WHERE'], |
|
| 95 | - implode(' ', $requete['GROUPBY']), |
|
| 96 | - $requete['ORDERBY'], |
|
| 97 | - $requete['LIMIT'], |
|
| 98 | - $requete['HAVING'], |
|
| 99 | - $serveur |
|
| 100 | - ); |
|
| 91 | + $s = sql_select( |
|
| 92 | + $requete['SELECT'], |
|
| 93 | + $requete['FROM'], |
|
| 94 | + $requete['WHERE'], |
|
| 95 | + implode(' ', $requete['GROUPBY']), |
|
| 96 | + $requete['ORDERBY'], |
|
| 97 | + $requete['LIMIT'], |
|
| 98 | + $requete['HAVING'], |
|
| 99 | + $serveur |
|
| 100 | + ); |
|
| 101 | 101 | |
| 102 | - while ( |
|
| 103 | - $t = sql_fetch($s, $serveur) |
|
| 104 | - and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | - ) { |
|
| 106 | - $id = intval($t[$_id_table]); |
|
| 102 | + while ( |
|
| 103 | + $t = sql_fetch($s, $serveur) |
|
| 104 | + and (!isset($t['score']) or $t['score'] > 0) |
|
| 105 | + ) { |
|
| 106 | + $id = intval($t[$_id_table]); |
|
| 107 | 107 | |
| 108 | - if ( |
|
| 109 | - $options['toutvoir'] |
|
| 110 | - or autoriser('voir', $table, $id) |
|
| 111 | - ) { |
|
| 112 | - // indiquer les champs concernes |
|
| 113 | - $champs_vus = []; |
|
| 114 | - $score = 0; |
|
| 115 | - $matches = []; |
|
| 108 | + if ( |
|
| 109 | + $options['toutvoir'] |
|
| 110 | + or autoriser('voir', $table, $id) |
|
| 111 | + ) { |
|
| 112 | + // indiquer les champs concernes |
|
| 113 | + $champs_vus = []; |
|
| 114 | + $score = 0; |
|
| 115 | + $matches = []; |
|
| 116 | 116 | |
| 117 | - $vu = false; |
|
| 118 | - foreach ($champs as $champ => $poids) { |
|
| 119 | - $champ = explode('.', $champ); |
|
| 120 | - $champ = end($champ); |
|
| 121 | - // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | - $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | - if ( |
|
| 124 | - $n = |
|
| 125 | - ($options['score'] || $options['matches']) |
|
| 126 | - ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | - : preg_match($preg, $value) |
|
| 128 | - ) { |
|
| 129 | - $vu = true; |
|
| 117 | + $vu = false; |
|
| 118 | + foreach ($champs as $champ => $poids) { |
|
| 119 | + $champ = explode('.', $champ); |
|
| 120 | + $champ = end($champ); |
|
| 121 | + // translitteration_rapide uniquement si on est deja en utf-8 |
|
| 122 | + $value = ($GLOBALS['meta']['charset'] == 'utf-8' ? translitteration_rapide($t[$champ]) : translitteration($t[$champ])); |
|
| 123 | + if ( |
|
| 124 | + $n = |
|
| 125 | + ($options['score'] || $options['matches']) |
|
| 126 | + ? preg_match_all($preg, $value, $regs, PREG_SET_ORDER) |
|
| 127 | + : preg_match($preg, $value) |
|
| 128 | + ) { |
|
| 129 | + $vu = true; |
|
| 130 | 130 | |
| 131 | - if ($options['champs']) { |
|
| 132 | - $champs_vus[$champ] = $t[$champ]; |
|
| 133 | - } |
|
| 134 | - if ($options['score']) { |
|
| 135 | - // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | - $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | - } |
|
| 131 | + if ($options['champs']) { |
|
| 132 | + $champs_vus[$champ] = $t[$champ]; |
|
| 133 | + } |
|
| 134 | + if ($options['score']) { |
|
| 135 | + // compter les points avec un peu de discernement : on pondere par la longueur du match compte en chars |
|
| 136 | + $score += $poids * strlen(implode('', array_column($regs, 0))); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - if ($options['matches']) { |
|
| 140 | - $matches[$champ] = $regs; |
|
| 141 | - } |
|
| 139 | + if ($options['matches']) { |
|
| 140 | + $matches[$champ] = $regs; |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | - if ( |
|
| 144 | - !$options['champs'] |
|
| 145 | - and !$options['score'] |
|
| 146 | - and !$options['matches'] |
|
| 147 | - ) { |
|
| 148 | - break; |
|
| 149 | - } |
|
| 150 | - } |
|
| 151 | - } |
|
| 143 | + if ( |
|
| 144 | + !$options['champs'] |
|
| 145 | + and !$options['score'] |
|
| 146 | + and !$options['matches'] |
|
| 147 | + ) { |
|
| 148 | + break; |
|
| 149 | + } |
|
| 150 | + } |
|
| 151 | + } |
|
| 152 | 152 | |
| 153 | - if ($vu) { |
|
| 154 | - if (!isset($results)) { |
|
| 155 | - $results = []; |
|
| 156 | - } |
|
| 157 | - $results[$id] = []; |
|
| 158 | - if ($champs_vus) { |
|
| 159 | - $results[$id]['champs'] = $champs_vus; |
|
| 160 | - } |
|
| 161 | - if ($score) { |
|
| 162 | - $results[$id]['score'] = $score; |
|
| 163 | - } |
|
| 164 | - if ($matches) { |
|
| 165 | - $results[$id]['matches'] = $matches; |
|
| 166 | - } |
|
| 167 | - } |
|
| 168 | - } |
|
| 169 | - } |
|
| 153 | + if ($vu) { |
|
| 154 | + if (!isset($results)) { |
|
| 155 | + $results = []; |
|
| 156 | + } |
|
| 157 | + $results[$id] = []; |
|
| 158 | + if ($champs_vus) { |
|
| 159 | + $results[$id]['champs'] = $champs_vus; |
|
| 160 | + } |
|
| 161 | + if ($score) { |
|
| 162 | + $results[$id]['score'] = $score; |
|
| 163 | + } |
|
| 164 | + if ($matches) { |
|
| 165 | + $results[$id]['matches'] = $matches; |
|
| 166 | + } |
|
| 167 | + } |
|
| 168 | + } |
|
| 169 | + } |
|
| 170 | 170 | |
| 171 | 171 | |
| 172 | - // Gerer les donnees associees |
|
| 173 | - // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | - // on ne sait passer que par table de laison en 1 coup |
|
| 175 | - if ( |
|
| 176 | - isset($jointures[$table]) |
|
| 177 | - and $joints = recherche_en_base( |
|
| 178 | - $recherche, |
|
| 179 | - $jointures[$table], |
|
| 180 | - array_merge($options, ['jointures' => false]) |
|
| 181 | - ) |
|
| 182 | - ) { |
|
| 183 | - include_spip('action/editer_liens'); |
|
| 184 | - $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | - $cle_depart = id_table_objet($table); |
|
| 186 | - $table_depart = table_objet($table, $serveur); |
|
| 187 | - $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | - $depart_associable = objet_associable($table); |
|
| 189 | - foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | - // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | - if ( |
|
| 192 | - !( |
|
| 193 | - $rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true) |
|
| 194 | - or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true) |
|
| 195 | - or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true) |
|
| 196 | - ) |
|
| 197 | - ) { |
|
| 198 | - $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | - $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | - $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | - // cas simple : $cle_depart dans la table_liee |
|
| 202 | - if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | - $s = sql_select( |
|
| 204 | - "$cle_depart, $cle_arrivee", |
|
| 205 | - $desc_arrivee['table_sql'], |
|
| 206 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | - '', |
|
| 208 | - '', |
|
| 209 | - '', |
|
| 210 | - '', |
|
| 211 | - $serveur |
|
| 212 | - ); |
|
| 213 | - } // cas simple : $cle_arrivee dans la table |
|
| 214 | - elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | - $s = sql_select( |
|
| 216 | - "$cle_depart, $cle_arrivee", |
|
| 217 | - $desc_depart['table_sql'], |
|
| 218 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | - '', |
|
| 220 | - '', |
|
| 221 | - '', |
|
| 222 | - '', |
|
| 223 | - $serveur |
|
| 224 | - ); |
|
| 225 | - } |
|
| 226 | - // sinon cherchons une table de liaison |
|
| 227 | - // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | - elseif ($l = objet_associable($table_liee)) { |
|
| 229 | - [$primary, $table_liens] = $l; |
|
| 230 | - $s = sql_select( |
|
| 231 | - "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | - $table_liens, |
|
| 233 | - ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | - '', |
|
| 235 | - '', |
|
| 236 | - '', |
|
| 237 | - '', |
|
| 238 | - $serveur |
|
| 239 | - ); |
|
| 240 | - } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | - elseif ($l = $depart_associable) { |
|
| 242 | - [$primary, $table_liens] = $l; |
|
| 243 | - $s = sql_select( |
|
| 244 | - "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | - $table_liens, |
|
| 246 | - ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | - '', |
|
| 248 | - '', |
|
| 249 | - '', |
|
| 250 | - '', |
|
| 251 | - $serveur |
|
| 252 | - ); |
|
| 253 | - } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | - elseif ( |
|
| 255 | - $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | - or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | - ) { |
|
| 258 | - $s = sql_select( |
|
| 259 | - "$cle_depart,$cle_arrivee", |
|
| 260 | - $t['table_sql'], |
|
| 261 | - sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | - '', |
|
| 263 | - '', |
|
| 264 | - '', |
|
| 265 | - '', |
|
| 266 | - $serveur |
|
| 267 | - ); |
|
| 268 | - } |
|
| 269 | - } else { |
|
| 270 | - [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | - $table, |
|
| 272 | - $table_liee, |
|
| 273 | - array_keys($ids_trouves), |
|
| 274 | - $serveur |
|
| 275 | - ); |
|
| 276 | - } |
|
| 172 | + // Gerer les donnees associees |
|
| 173 | + // ici on est un peu naze : pas capables de reconstruire une jointure complexe |
|
| 174 | + // on ne sait passer que par table de laison en 1 coup |
|
| 175 | + if ( |
|
| 176 | + isset($jointures[$table]) |
|
| 177 | + and $joints = recherche_en_base( |
|
| 178 | + $recherche, |
|
| 179 | + $jointures[$table], |
|
| 180 | + array_merge($options, ['jointures' => false]) |
|
| 181 | + ) |
|
| 182 | + ) { |
|
| 183 | + include_spip('action/editer_liens'); |
|
| 184 | + $trouver_table = charger_fonction('trouver_table', 'base'); |
|
| 185 | + $cle_depart = id_table_objet($table); |
|
| 186 | + $table_depart = table_objet($table, $serveur); |
|
| 187 | + $desc_depart = $trouver_table($table_depart, $serveur); |
|
| 188 | + $depart_associable = objet_associable($table); |
|
| 189 | + foreach ($joints as $table_liee => $ids_trouves) { |
|
| 190 | + // on peut definir une fonction de recherche jointe pour regler les cas particuliers |
|
| 191 | + if ( |
|
| 192 | + !( |
|
| 193 | + $rechercher_joints = charger_fonction("rechercher_joints_{$table}_{$table_liee}", 'inc', true) |
|
| 194 | + or $rechercher_joints = charger_fonction("rechercher_joints_objet_{$table_liee}", 'inc', true) |
|
| 195 | + or $rechercher_joints = charger_fonction("rechercher_joints_{$table}_objet_lie", 'inc', true) |
|
| 196 | + ) |
|
| 197 | + ) { |
|
| 198 | + $cle_arrivee = id_table_objet($table_liee); |
|
| 199 | + $table_arrivee = table_objet($table_liee, $serveur); |
|
| 200 | + $desc_arrivee = $trouver_table($table_arrivee, $serveur); |
|
| 201 | + // cas simple : $cle_depart dans la table_liee |
|
| 202 | + if (isset($desc_arrivee['field'][$cle_depart])) { |
|
| 203 | + $s = sql_select( |
|
| 204 | + "$cle_depart, $cle_arrivee", |
|
| 205 | + $desc_arrivee['table_sql'], |
|
| 206 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 207 | + '', |
|
| 208 | + '', |
|
| 209 | + '', |
|
| 210 | + '', |
|
| 211 | + $serveur |
|
| 212 | + ); |
|
| 213 | + } // cas simple : $cle_arrivee dans la table |
|
| 214 | + elseif (isset($desc_depart['field'][$cle_arrivee])) { |
|
| 215 | + $s = sql_select( |
|
| 216 | + "$cle_depart, $cle_arrivee", |
|
| 217 | + $desc_depart['table_sql'], |
|
| 218 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 219 | + '', |
|
| 220 | + '', |
|
| 221 | + '', |
|
| 222 | + '', |
|
| 223 | + $serveur |
|
| 224 | + ); |
|
| 225 | + } |
|
| 226 | + // sinon cherchons une table de liaison |
|
| 227 | + // cas recherche principale article, objet lie document : passer par spip_documents_liens |
|
| 228 | + elseif ($l = objet_associable($table_liee)) { |
|
| 229 | + [$primary, $table_liens] = $l; |
|
| 230 | + $s = sql_select( |
|
| 231 | + "id_objet as $cle_depart, $primary as $cle_arrivee", |
|
| 232 | + $table_liens, |
|
| 233 | + ["objet='$table'", sql_in($primary, array_keys($ids_trouves))], |
|
| 234 | + '', |
|
| 235 | + '', |
|
| 236 | + '', |
|
| 237 | + '', |
|
| 238 | + $serveur |
|
| 239 | + ); |
|
| 240 | + } // cas recherche principale auteur, objet lie article: passer par spip_auteurs_liens |
|
| 241 | + elseif ($l = $depart_associable) { |
|
| 242 | + [$primary, $table_liens] = $l; |
|
| 243 | + $s = sql_select( |
|
| 244 | + "$primary as $cle_depart, id_objet as $cle_arrivee", |
|
| 245 | + $table_liens, |
|
| 246 | + ["objet='$table_liee'", sql_in('id_objet', array_keys($ids_trouves))], |
|
| 247 | + '', |
|
| 248 | + '', |
|
| 249 | + '', |
|
| 250 | + '', |
|
| 251 | + $serveur |
|
| 252 | + ); |
|
| 253 | + } // cas table de liaison generique spip_xxx_yyy |
|
| 254 | + elseif ( |
|
| 255 | + $t = $trouver_table($table_arrivee . '_' . $table_depart, $serveur) |
|
| 256 | + or $t = $trouver_table($table_depart . '_' . $table_arrivee, $serveur) |
|
| 257 | + ) { |
|
| 258 | + $s = sql_select( |
|
| 259 | + "$cle_depart,$cle_arrivee", |
|
| 260 | + $t['table_sql'], |
|
| 261 | + sql_in($cle_arrivee, array_keys($ids_trouves)), |
|
| 262 | + '', |
|
| 263 | + '', |
|
| 264 | + '', |
|
| 265 | + '', |
|
| 266 | + $serveur |
|
| 267 | + ); |
|
| 268 | + } |
|
| 269 | + } else { |
|
| 270 | + [$cle_depart, $cle_arrivee, $s] = $rechercher_joints( |
|
| 271 | + $table, |
|
| 272 | + $table_liee, |
|
| 273 | + array_keys($ids_trouves), |
|
| 274 | + $serveur |
|
| 275 | + ); |
|
| 276 | + } |
|
| 277 | 277 | |
| 278 | - while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | - $id = $t[$cle_depart]; |
|
| 280 | - $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | - if (!isset($results)) { |
|
| 282 | - $results = []; |
|
| 283 | - } |
|
| 284 | - if (!isset($results[$id])) { |
|
| 285 | - $results[$id] = []; |
|
| 286 | - } |
|
| 287 | - if (isset($joint['score']) and $joint['score']) { |
|
| 288 | - if (!isset($results[$id]['score'])) { |
|
| 289 | - $results[$id]['score'] = 0; |
|
| 290 | - } |
|
| 291 | - $results[$id]['score'] += $joint['score']; |
|
| 292 | - } |
|
| 293 | - if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | - foreach ($joint['champs'] as $c => $val) { |
|
| 295 | - $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | - } |
|
| 297 | - } |
|
| 298 | - if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | - foreach ($joint['matches'] as $c => $val) { |
|
| 300 | - $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | - } |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - } |
|
| 305 | - } |
|
| 278 | + while ($t = is_array($s) ? array_shift($s) : sql_fetch($s)) { |
|
| 279 | + $id = $t[$cle_depart]; |
|
| 280 | + $joint = $ids_trouves[$t[$cle_arrivee]]; |
|
| 281 | + if (!isset($results)) { |
|
| 282 | + $results = []; |
|
| 283 | + } |
|
| 284 | + if (!isset($results[$id])) { |
|
| 285 | + $results[$id] = []; |
|
| 286 | + } |
|
| 287 | + if (isset($joint['score']) and $joint['score']) { |
|
| 288 | + if (!isset($results[$id]['score'])) { |
|
| 289 | + $results[$id]['score'] = 0; |
|
| 290 | + } |
|
| 291 | + $results[$id]['score'] += $joint['score']; |
|
| 292 | + } |
|
| 293 | + if (isset($joint['champs']) and $joint['champs']) { |
|
| 294 | + foreach ($joint['champs'] as $c => $val) { |
|
| 295 | + $results[$id]['champs'][$table_liee . '.' . $c] = $val; |
|
| 296 | + } |
|
| 297 | + } |
|
| 298 | + if (isset($joint['matches']) and $joint['matches']) { |
|
| 299 | + foreach ($joint['matches'] as $c => $val) { |
|
| 300 | + $results[$id]['matches'][$table_liee . '.' . $c] = $val; |
|
| 301 | + } |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + } |
|
| 305 | + } |
|
| 306 | 306 | |
| 307 | - return $results; |
|
| 307 | + return $results; |
|
| 308 | 308 | } |
@@ -11,71 +11,71 @@ |
||
| 11 | 11 | \***************************************************************************/ |
| 12 | 12 | |
| 13 | 13 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 14 | - return; |
|
| 14 | + return; |
|
| 15 | 15 | } |
| 16 | 16 | |
| 17 | 17 | include_spip('inc/boutons'); |
| 18 | 18 | include_spip('base/objets'); |
| 19 | 19 | |
| 20 | 20 | function inc_icone_renommer_dist($fond, $fonction) { |
| 21 | - $size = 24; |
|
| 22 | - if ( |
|
| 23 | - preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match) |
|
| 24 | - and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1])) |
|
| 25 | - ) { |
|
| 26 | - if (isset($match[1]) and $match[1]) { |
|
| 27 | - $size = $match[1]; |
|
| 28 | - } |
|
| 29 | - $type = substr($fond, 0, -strlen($match[0])); |
|
| 30 | - if (!isset($match[2]) or !$match[2]) { |
|
| 31 | - $fond .= '.png'; |
|
| 32 | - } |
|
| 33 | - } else { |
|
| 34 | - $type = $fond; |
|
| 35 | - $fond .= '.png'; |
|
| 36 | - } |
|
| 21 | + $size = 24; |
|
| 22 | + if ( |
|
| 23 | + preg_match('/(?:-([0-9]{1,3}))?([.](gif|png|svg))?$/i', $fond, $match) |
|
| 24 | + and ((isset($match[0]) and $match[0]) or (isset($match[1]) and $match[1])) |
|
| 25 | + ) { |
|
| 26 | + if (isset($match[1]) and $match[1]) { |
|
| 27 | + $size = $match[1]; |
|
| 28 | + } |
|
| 29 | + $type = substr($fond, 0, -strlen($match[0])); |
|
| 30 | + if (!isset($match[2]) or !$match[2]) { |
|
| 31 | + $fond .= '.png'; |
|
| 32 | + } |
|
| 33 | + } else { |
|
| 34 | + $type = $fond; |
|
| 35 | + $fond .= '.png'; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | - $rtl = false; |
|
| 39 | - if (preg_match(',[-_]rtl$,i', $type, $match)) { |
|
| 40 | - $rtl = true; |
|
| 41 | - $type = substr($type, 0, -strlen($match[0])); |
|
| 42 | - } |
|
| 38 | + $rtl = false; |
|
| 39 | + if (preg_match(',[-_]rtl$,i', $type, $match)) { |
|
| 40 | + $rtl = true; |
|
| 41 | + $type = substr($type, 0, -strlen($match[0])); |
|
| 42 | + } |
|
| 43 | 43 | |
| 44 | - // objet_type garde invariant tout ce qui ne commence par par id_, spip_ |
|
| 45 | - // et ne finit pas par un s, sauf si c'est une exception declaree |
|
| 46 | - $type = objet_type($type, false); |
|
| 44 | + // objet_type garde invariant tout ce qui ne commence par par id_, spip_ |
|
| 45 | + // et ne finit pas par un s, sauf si c'est une exception declaree |
|
| 46 | + $type = objet_type($type, false); |
|
| 47 | 47 | |
| 48 | - $dir = 'images/'; |
|
| 49 | - $f = "$type-$size.png"; |
|
| 50 | - if ($icone = find_in_theme($dir . $f)) { |
|
| 51 | - $dir = dirname($icone); |
|
| 52 | - $fond = $icone; |
|
| 48 | + $dir = 'images/'; |
|
| 49 | + $f = "$type-$size.png"; |
|
| 50 | + if ($icone = find_in_theme($dir . $f)) { |
|
| 51 | + $dir = dirname($icone); |
|
| 52 | + $fond = $icone; |
|
| 53 | 53 | |
| 54 | - if ( |
|
| 55 | - $rtl |
|
| 56 | - and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | - and file_exists($fr) |
|
| 58 | - ) { |
|
| 59 | - $fond = $fr; |
|
| 60 | - } |
|
| 54 | + if ( |
|
| 55 | + $rtl |
|
| 56 | + and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | + and file_exists($fr) |
|
| 58 | + ) { |
|
| 59 | + $fond = $fr; |
|
| 60 | + } |
|
| 61 | 61 | |
| 62 | - $action = $fonction; |
|
| 63 | - if ($action == 'supprimer.gif') { |
|
| 64 | - $action = 'del'; |
|
| 65 | - } elseif ($action == 'creer.gif') { |
|
| 66 | - $action = 'new'; |
|
| 67 | - } elseif ($action == 'edit.gif') { |
|
| 68 | - $action = 'edit'; |
|
| 69 | - } |
|
| 62 | + $action = $fonction; |
|
| 63 | + if ($action == 'supprimer.gif') { |
|
| 64 | + $action = 'del'; |
|
| 65 | + } elseif ($action == 'creer.gif') { |
|
| 66 | + $action = 'new'; |
|
| 67 | + } elseif ($action == 'edit.gif') { |
|
| 68 | + $action = 'edit'; |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - $fonction = ''; |
|
| 72 | - if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 73 | - $fonction = $action; |
|
| 74 | - } |
|
| 71 | + $fonction = ''; |
|
| 72 | + if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 73 | + $fonction = $action; |
|
| 74 | + } |
|
| 75 | 75 | |
| 76 | - // c'est bon ! |
|
| 77 | - return [$fond, $fonction]; |
|
| 78 | - } |
|
| 76 | + // c'est bon ! |
|
| 77 | + return [$fond, $fonction]; |
|
| 78 | + } |
|
| 79 | 79 | |
| 80 | - return [$fond, $fonction]; |
|
| 80 | + return [$fond, $fonction]; |
|
| 81 | 81 | } |
@@ -47,13 +47,13 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | $dir = 'images/'; |
| 49 | 49 | $f = "$type-$size.png"; |
| 50 | - if ($icone = find_in_theme($dir . $f)) { |
|
| 50 | + if ($icone = find_in_theme($dir.$f)) { |
|
| 51 | 51 | $dir = dirname($icone); |
| 52 | 52 | $fond = $icone; |
| 53 | 53 | |
| 54 | 54 | if ( |
| 55 | 55 | $rtl |
| 56 | - and $fr = $dir . '/' . str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 56 | + and $fr = $dir.'/'.str_replace("$type-", "$type-rtl-", basename($icone)) |
|
| 57 | 57 | and file_exists($fr) |
| 58 | 58 | ) { |
| 59 | 59 | $fond = $fr; |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | $fonction = ''; |
| 72 | - if (in_array($action, ['add','del', 'new', 'edit', 'config'])) { |
|
| 72 | + if (in_array($action, ['add', 'del', 'new', 'edit', 'config'])) { |
|
| 73 | 73 | $fonction = $action; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -82,12 +82,12 @@ discard block |
||
| 82 | 82 | $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
| 83 | 83 | if (!isset($cache[$serveur][$table][$recherche])) { |
| 84 | 84 | $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
| 85 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 86 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 85 | + $hash = substr(md5($recherche.$table), 0, 16); |
|
| 86 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=".sql_quote($table)." AND resultats.serveur='$hash_serv')"; |
|
| 87 | 87 | $row = sql_fetsel( |
| 88 | 88 | 'recherche', |
| 89 | 89 | 'spip_resultats AS resultats', |
| 90 | - $where . " AND $where_resultat_recent", |
|
| 90 | + $where." AND $where_resultat_recent", |
|
| 91 | 91 | '', |
| 92 | 92 | '', |
| 93 | 93 | '0,1' |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | } |
| 197 | 197 | |
| 198 | 198 | foreach ($listes_ids as $p => $ids) { |
| 199 | - $select .= "+$p*(" . |
|
| 199 | + $select .= "+$p*(". |
|
| 200 | 200 | sql_in("$table.$primary", $ids, '', $serveur) |
| 201 | 201 | . ') '; |
| 202 | 202 | } |
@@ -17,12 +17,12 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/rechercher'); |
| 24 | 24 | if (!defined('_DELAI_CACHE_resultats')) { |
| 25 | - define('_DELAI_CACHE_resultats', 600); |
|
| 25 | + define('_DELAI_CACHE_resultats', 600); |
|
| 26 | 26 | } |
| 27 | 27 | |
| 28 | 28 | /** |
@@ -49,129 +49,129 @@ discard block |
||
| 49 | 49 | * @return array |
| 50 | 50 | */ |
| 51 | 51 | function inc_prepare_recherche_dist( |
| 52 | - $recherche, |
|
| 53 | - $table = 'articles', |
|
| 54 | - $cond = false, |
|
| 55 | - $serveur = '', |
|
| 56 | - $modificateurs = [], |
|
| 57 | - $primary = '' |
|
| 52 | + $recherche, |
|
| 53 | + $table = 'articles', |
|
| 54 | + $cond = false, |
|
| 55 | + $serveur = '', |
|
| 56 | + $modificateurs = [], |
|
| 57 | + $primary = '' |
|
| 58 | 58 | ) { |
| 59 | - $where = null; |
|
| 60 | - $rows = null; |
|
| 61 | - static $cache = []; |
|
| 62 | - $delai_fraicheur = min( |
|
| 63 | - \_DELAI_CACHE_resultats, |
|
| 64 | - time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 65 | - ); |
|
| 66 | - |
|
| 67 | - // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 68 | - // ca permet de faire des inclure simple. |
|
| 69 | - if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 70 | - $recherche = $GLOBALS['recherche']; |
|
| 71 | - } |
|
| 72 | - |
|
| 73 | - // traiter le cas {recherche?} |
|
| 74 | - if ($cond and !strlen($recherche)) { |
|
| 75 | - return [ |
|
| 76 | - '0 as points' /* as points */, /* where */ |
|
| 77 | - '' |
|
| 78 | - ]; |
|
| 79 | - } |
|
| 80 | - |
|
| 81 | - |
|
| 82 | - $rechercher = false; |
|
| 83 | - |
|
| 84 | - $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 85 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 86 | - $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 87 | - $hash = substr(md5($recherche . $table), 0, 16); |
|
| 88 | - $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 89 | - $row = sql_fetsel( |
|
| 90 | - 'recherche', |
|
| 91 | - 'spip_resultats AS resultats', |
|
| 92 | - $where . " AND $where_resultat_recent", |
|
| 93 | - '', |
|
| 94 | - '', |
|
| 95 | - '0,1' |
|
| 96 | - ); |
|
| 97 | - if ( |
|
| 98 | - !$row |
|
| 99 | - or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 100 | - ) { |
|
| 101 | - $rechercher = true; |
|
| 102 | - } |
|
| 103 | - } |
|
| 104 | - |
|
| 105 | - // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 106 | - if ($rechercher) { |
|
| 107 | - //$tables = liste_des_champs(); |
|
| 108 | - $x = objet_type($table); |
|
| 109 | - $points = recherche_en_base( |
|
| 110 | - $recherche, |
|
| 111 | - $x, |
|
| 112 | - [ |
|
| 113 | - 'score' => true, |
|
| 114 | - 'toutvoir' => true, |
|
| 115 | - 'jointures' => true |
|
| 116 | - ], |
|
| 117 | - $serveur |
|
| 118 | - ); |
|
| 119 | - // pas de résultat, pas de point |
|
| 120 | - $points = $points[$x] ?? []; |
|
| 121 | - |
|
| 122 | - // permettre aux plugins de modifier le resultat |
|
| 123 | - $points = pipeline('prepare_recherche', [ |
|
| 124 | - 'args' => [ |
|
| 125 | - 'type' => $x, |
|
| 126 | - 'recherche' => $recherche, |
|
| 127 | - 'serveur' => $serveur, |
|
| 128 | - 'modificateurs' => $modificateurs |
|
| 129 | - ], |
|
| 130 | - 'data' => $points |
|
| 131 | - ]); |
|
| 132 | - |
|
| 133 | - // supprimer les anciens resultats de cette recherche |
|
| 134 | - // et les resultats trop vieux avec une marge |
|
| 135 | - // pas de AS resultats dans un delete (mysql) |
|
| 136 | - $whered = str_replace( |
|
| 137 | - ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 138 | - ['recherche', 'table_objet', 'serveur'], |
|
| 139 | - $where |
|
| 140 | - ); |
|
| 141 | - |
|
| 142 | - sql_delete( |
|
| 143 | - 'spip_resultats', |
|
| 144 | - "NOT($where_resultat_recent) OR ($whered)" |
|
| 145 | - ); |
|
| 146 | - |
|
| 147 | - // inserer les resultats dans la table de cache des resultats |
|
| 148 | - if (is_countable($points) ? count($points) : 0) { |
|
| 149 | - $tab_couples = []; |
|
| 150 | - foreach ($points as $id => $p) { |
|
| 151 | - $tab_couples[] = [ |
|
| 152 | - 'recherche' => $hash, |
|
| 153 | - 'id' => $id, |
|
| 154 | - 'points' => $p['score'], |
|
| 155 | - 'table_objet' => $table, |
|
| 156 | - 'serveur' => $hash_serv, |
|
| 157 | - ]; |
|
| 158 | - } |
|
| 159 | - sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 160 | - } |
|
| 161 | - } |
|
| 162 | - |
|
| 163 | - if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 164 | - if (!$serveur) { |
|
| 165 | - $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 166 | - } else { |
|
| 167 | - if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 168 | - $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 169 | - } |
|
| 170 | - $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 171 | - } |
|
| 172 | - } |
|
| 173 | - |
|
| 174 | - return $cache[$serveur][$table][$recherche]; |
|
| 59 | + $where = null; |
|
| 60 | + $rows = null; |
|
| 61 | + static $cache = []; |
|
| 62 | + $delai_fraicheur = min( |
|
| 63 | + \_DELAI_CACHE_resultats, |
|
| 64 | + time() - ($GLOBALS['meta']['derniere_modif'] ?? 0) |
|
| 65 | + ); |
|
| 66 | + |
|
| 67 | + // si recherche n'est pas dans le contexte, on va prendre en globals |
|
| 68 | + // ca permet de faire des inclure simple. |
|
| 69 | + if (!isset($recherche) and isset($GLOBALS['recherche'])) { |
|
| 70 | + $recherche = $GLOBALS['recherche']; |
|
| 71 | + } |
|
| 72 | + |
|
| 73 | + // traiter le cas {recherche?} |
|
| 74 | + if ($cond and !strlen($recherche)) { |
|
| 75 | + return [ |
|
| 76 | + '0 as points' /* as points */, /* where */ |
|
| 77 | + '' |
|
| 78 | + ]; |
|
| 79 | + } |
|
| 80 | + |
|
| 81 | + |
|
| 82 | + $rechercher = false; |
|
| 83 | + |
|
| 84 | + $where_resultat_recent = sql_date_proche('maj', (0 - ($delai_fraicheur + 100)), ' SECOND'); |
|
| 85 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 86 | + $hash_serv = ($serveur ? substr(md5($serveur), 0, 16) : ''); |
|
| 87 | + $hash = substr(md5($recherche . $table), 0, 16); |
|
| 88 | + $where = "(resultats.recherche='$hash' AND resultats.table_objet=" . sql_quote($table) . " AND resultats.serveur='$hash_serv')"; |
|
| 89 | + $row = sql_fetsel( |
|
| 90 | + 'recherche', |
|
| 91 | + 'spip_resultats AS resultats', |
|
| 92 | + $where . " AND $where_resultat_recent", |
|
| 93 | + '', |
|
| 94 | + '', |
|
| 95 | + '0,1' |
|
| 96 | + ); |
|
| 97 | + if ( |
|
| 98 | + !$row |
|
| 99 | + or (defined('_VAR_MODE') and _VAR_MODE == 'recalcul') |
|
| 100 | + ) { |
|
| 101 | + $rechercher = true; |
|
| 102 | + } |
|
| 103 | + } |
|
| 104 | + |
|
| 105 | + // si on n'a pas encore traite les donnees dans une boucle precedente |
|
| 106 | + if ($rechercher) { |
|
| 107 | + //$tables = liste_des_champs(); |
|
| 108 | + $x = objet_type($table); |
|
| 109 | + $points = recherche_en_base( |
|
| 110 | + $recherche, |
|
| 111 | + $x, |
|
| 112 | + [ |
|
| 113 | + 'score' => true, |
|
| 114 | + 'toutvoir' => true, |
|
| 115 | + 'jointures' => true |
|
| 116 | + ], |
|
| 117 | + $serveur |
|
| 118 | + ); |
|
| 119 | + // pas de résultat, pas de point |
|
| 120 | + $points = $points[$x] ?? []; |
|
| 121 | + |
|
| 122 | + // permettre aux plugins de modifier le resultat |
|
| 123 | + $points = pipeline('prepare_recherche', [ |
|
| 124 | + 'args' => [ |
|
| 125 | + 'type' => $x, |
|
| 126 | + 'recherche' => $recherche, |
|
| 127 | + 'serveur' => $serveur, |
|
| 128 | + 'modificateurs' => $modificateurs |
|
| 129 | + ], |
|
| 130 | + 'data' => $points |
|
| 131 | + ]); |
|
| 132 | + |
|
| 133 | + // supprimer les anciens resultats de cette recherche |
|
| 134 | + // et les resultats trop vieux avec une marge |
|
| 135 | + // pas de AS resultats dans un delete (mysql) |
|
| 136 | + $whered = str_replace( |
|
| 137 | + ['resultats.recherche', 'resultats.table_objet', 'resultats.serveur'], |
|
| 138 | + ['recherche', 'table_objet', 'serveur'], |
|
| 139 | + $where |
|
| 140 | + ); |
|
| 141 | + |
|
| 142 | + sql_delete( |
|
| 143 | + 'spip_resultats', |
|
| 144 | + "NOT($where_resultat_recent) OR ($whered)" |
|
| 145 | + ); |
|
| 146 | + |
|
| 147 | + // inserer les resultats dans la table de cache des resultats |
|
| 148 | + if (is_countable($points) ? count($points) : 0) { |
|
| 149 | + $tab_couples = []; |
|
| 150 | + foreach ($points as $id => $p) { |
|
| 151 | + $tab_couples[] = [ |
|
| 152 | + 'recherche' => $hash, |
|
| 153 | + 'id' => $id, |
|
| 154 | + 'points' => $p['score'], |
|
| 155 | + 'table_objet' => $table, |
|
| 156 | + 'serveur' => $hash_serv, |
|
| 157 | + ]; |
|
| 158 | + } |
|
| 159 | + sql_insertq_multi('spip_resultats', $tab_couples, []); |
|
| 160 | + } |
|
| 161 | + } |
|
| 162 | + |
|
| 163 | + if (!isset($cache[$serveur][$table][$recherche])) { |
|
| 164 | + if (!$serveur) { |
|
| 165 | + $cache[$serveur][$table][$recherche] = ['resultats.points AS points', $where]; |
|
| 166 | + } else { |
|
| 167 | + if (sql_countsel('spip_resultats as resultats', $where)) { |
|
| 168 | + $rows = sql_allfetsel('resultats.id,resultats.points', 'spip_resultats as resultats', $where); |
|
| 169 | + } |
|
| 170 | + $cache[$serveur][$table][$recherche] = generer_select_where_explicites($table, $primary, $rows, $serveur); |
|
| 171 | + } |
|
| 172 | + } |
|
| 173 | + |
|
| 174 | + return $cache[$serveur][$table][$recherche]; |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | |
@@ -187,22 +187,22 @@ discard block |
||
| 187 | 187 | * @return array |
| 188 | 188 | */ |
| 189 | 189 | function generer_select_where_explicites($table, $primary, $rows, $serveur) { |
| 190 | - # calculer le {id_article IN()} et le {... as points} |
|
| 191 | - if (!count($rows)) { |
|
| 192 | - return ["''", '0=1']; |
|
| 193 | - } else { |
|
| 194 | - $listes_ids = []; |
|
| 195 | - $select = '0'; |
|
| 196 | - foreach ($rows as $r) { |
|
| 197 | - $listes_ids[$r['points']][] = $r['id']; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - foreach ($listes_ids as $p => $ids) { |
|
| 201 | - $select .= "+$p*(" . |
|
| 202 | - sql_in("$table.$primary", $ids, '', $serveur) |
|
| 203 | - . ') '; |
|
| 204 | - } |
|
| 205 | - |
|
| 206 | - return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 207 | - } |
|
| 190 | + # calculer le {id_article IN()} et le {... as points} |
|
| 191 | + if (!count($rows)) { |
|
| 192 | + return ["''", '0=1']; |
|
| 193 | + } else { |
|
| 194 | + $listes_ids = []; |
|
| 195 | + $select = '0'; |
|
| 196 | + foreach ($rows as $r) { |
|
| 197 | + $listes_ids[$r['points']][] = $r['id']; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + foreach ($listes_ids as $p => $ids) { |
|
| 201 | + $select .= "+$p*(" . |
|
| 202 | + sql_in("$table.$primary", $ids, '', $serveur) |
|
| 203 | + . ') '; |
|
| 204 | + } |
|
| 205 | + |
|
| 206 | + return ["$select AS points ", sql_in("$table.$primary", array_map('reset', $rows), '', $serveur)]; |
|
| 207 | + } |
|
| 208 | 208 | } |
@@ -173,8 +173,7 @@ |
||
| 173 | 173 | // sinon on ecrit directement sur stdout |
| 174 | 174 | if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
| 175 | 175 | $fichier = 'php://output'; |
| 176 | - } |
|
| 177 | - else { |
|
| 176 | + } else { |
|
| 178 | 177 | $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
| 179 | 178 | } |
| 180 | 179 | |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | include_spip('inc/charsets'); |
@@ -32,13 +32,13 @@ discard block |
||
| 32 | 32 | * @return string |
| 33 | 33 | */ |
| 34 | 34 | function exporter_csv_champ($champ) { |
| 35 | - #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | - #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | - #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | - $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | - $champ = str_replace('"', '""', $champ); |
|
| 35 | + #$champ = str_replace("\r", "\n", $champ); |
|
| 36 | + #$champ = preg_replace(",[\n]+,ms", "\n", $champ); |
|
| 37 | + #$champ = str_replace("\n", ", ", $champ); |
|
| 38 | + $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
|
| 39 | + $champ = str_replace('"', '""', $champ); |
|
| 40 | 40 | |
| 41 | - return '"' . $champ . '"'; |
|
| 41 | + return '"' . $champ . '"'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -55,15 +55,15 @@ discard block |
||
| 55 | 55 | * @return string |
| 56 | 56 | */ |
| 57 | 57 | function exporter_csv_ligne_numerotee($nb, $ligne, $delim = ',', $importer_charset = null, ?callable $callback = null) { |
| 58 | - if ($callback) { |
|
| 59 | - $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 60 | - } |
|
| 61 | - $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | - if ($importer_charset) { |
|
| 63 | - $output = str_replace('’', '\'', $output); |
|
| 64 | - $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | - } |
|
| 66 | - return $output; |
|
| 58 | + if ($callback) { |
|
| 59 | + $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
|
| 60 | + } |
|
| 61 | + $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 62 | + if ($importer_charset) { |
|
| 63 | + $output = str_replace('’', '\'', $output); |
|
| 64 | + $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
|
| 65 | + } |
|
| 66 | + return $output; |
|
| 67 | 67 | } |
| 68 | 68 | |
| 69 | 69 | /** |
@@ -75,7 +75,7 @@ discard block |
||
| 75 | 75 | * @return string |
| 76 | 76 | */ |
| 77 | 77 | function exporter_csv_ligne($ligne, $delim = ',', $importer_charset = null) { |
| 78 | - return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 78 | + return exporter_csv_ligne_numerotee(null, $ligne, $delim, $importer_charset); |
|
| 79 | 79 | } |
| 80 | 80 | |
| 81 | 81 | /** |
@@ -101,101 +101,101 @@ discard block |
||
| 101 | 101 | */ |
| 102 | 102 | function inc_exporter_csv_dist($titre, $resource, $options = []) { |
| 103 | 103 | |
| 104 | - // support ancienne syntaxe |
|
| 105 | - // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | - if (is_string($options)) { |
|
| 107 | - $args = func_get_args(); |
|
| 108 | - $options = []; |
|
| 109 | - foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | - if (!empty($args[$k])) { |
|
| 111 | - $options[$option] = $args[$k]; |
|
| 112 | - } |
|
| 113 | - } |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - $default_options = [ |
|
| 117 | - 'delim' => ', ', |
|
| 118 | - 'entetes' => null, |
|
| 119 | - 'envoyer' => true, |
|
| 120 | - 'charset' => null, |
|
| 121 | - 'callback' => null, |
|
| 122 | - ]; |
|
| 123 | - $options = array_merge($default_options, $options); |
|
| 124 | - |
|
| 125 | - $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | - |
|
| 127 | - if ($options['delim'] == 'TAB') { |
|
| 128 | - $options['delim'] = "\t"; |
|
| 129 | - } |
|
| 130 | - if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | - $options['delim'] = ','; |
|
| 132 | - } |
|
| 133 | - |
|
| 134 | - $charset = $GLOBALS['meta']['charset']; |
|
| 135 | - $importer_charset = null; |
|
| 136 | - if ($options['delim'] == ',') { |
|
| 137 | - $extension = 'csv'; |
|
| 138 | - } else { |
|
| 139 | - $extension = 'xls'; |
|
| 140 | - # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | - $charset = 'iso-8859-1'; |
|
| 142 | - } |
|
| 143 | - // mais si une option charset est explicite, elle a la priorite |
|
| 144 | - if (!empty($options['charset'])) { |
|
| 145 | - $charset = $options['charset']; |
|
| 146 | - } |
|
| 147 | - |
|
| 148 | - $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | - |
|
| 150 | - $filename = "$filename.$extension"; |
|
| 151 | - |
|
| 152 | - $output = ''; |
|
| 153 | - $nb = 0; |
|
| 154 | - if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | - $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | - } |
|
| 157 | - // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | - $nb++; |
|
| 159 | - |
|
| 160 | - if ($options['envoyer']) { |
|
| 161 | - $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | - header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | - header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | - |
|
| 165 | - // Vider tous les tampons |
|
| 166 | - $level = @ob_get_level(); |
|
| 167 | - while ($level--) { |
|
| 168 | - @ob_end_flush(); |
|
| 169 | - } |
|
| 170 | - } |
|
| 171 | - |
|
| 172 | - // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | - // sinon on ecrit directement sur stdout |
|
| 174 | - if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | - $fichier = 'php://output'; |
|
| 176 | - } |
|
| 177 | - else { |
|
| 178 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | - } |
|
| 180 | - |
|
| 181 | - $fp = fopen($fichier, 'w'); |
|
| 182 | - $length = fwrite($fp, $output); |
|
| 183 | - |
|
| 184 | - while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | - $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | - $length += fwrite($fp, $output); |
|
| 187 | - $nb++; |
|
| 188 | - } |
|
| 189 | - fclose($fp); |
|
| 190 | - |
|
| 191 | - if ($options['envoyer']) { |
|
| 192 | - if ($options['envoyer'] === 'attachment') { |
|
| 193 | - header("Content-Length: $length"); |
|
| 194 | - readfile($fichier); |
|
| 195 | - } |
|
| 196 | - // si on a envoye inline, c'est deja tout bon |
|
| 197 | - exit; |
|
| 198 | - } |
|
| 199 | - |
|
| 200 | - return $fichier; |
|
| 104 | + // support ancienne syntaxe |
|
| 105 | + // inc_exporter_csv_dist($titre, $resource, $delim = ', ', $entetes = null, $envoyer = true) |
|
| 106 | + if (is_string($options)) { |
|
| 107 | + $args = func_get_args(); |
|
| 108 | + $options = []; |
|
| 109 | + foreach ([2 => 'delim', 3 => 'entetes', 4 => 'envoyer'] as $k => $option) { |
|
| 110 | + if (!empty($args[$k])) { |
|
| 111 | + $options[$option] = $args[$k]; |
|
| 112 | + } |
|
| 113 | + } |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + $default_options = [ |
|
| 117 | + 'delim' => ', ', |
|
| 118 | + 'entetes' => null, |
|
| 119 | + 'envoyer' => true, |
|
| 120 | + 'charset' => null, |
|
| 121 | + 'callback' => null, |
|
| 122 | + ]; |
|
| 123 | + $options = array_merge($default_options, $options); |
|
| 124 | + |
|
| 125 | + $filename = preg_replace(',[^-_\w]+,', '_', translitteration(textebrut(typo($titre)))); |
|
| 126 | + |
|
| 127 | + if ($options['delim'] == 'TAB') { |
|
| 128 | + $options['delim'] = "\t"; |
|
| 129 | + } |
|
| 130 | + if (!in_array($options['delim'], [',', ';', "\t"])) { |
|
| 131 | + $options['delim'] = ','; |
|
| 132 | + } |
|
| 133 | + |
|
| 134 | + $charset = $GLOBALS['meta']['charset']; |
|
| 135 | + $importer_charset = null; |
|
| 136 | + if ($options['delim'] == ',') { |
|
| 137 | + $extension = 'csv'; |
|
| 138 | + } else { |
|
| 139 | + $extension = 'xls'; |
|
| 140 | + # Excel n'accepte pas l'utf-8 ni les entites html... on transcode tout ce qu'on peut |
|
| 141 | + $charset = 'iso-8859-1'; |
|
| 142 | + } |
|
| 143 | + // mais si une option charset est explicite, elle a la priorite |
|
| 144 | + if (!empty($options['charset'])) { |
|
| 145 | + $charset = $options['charset']; |
|
| 146 | + } |
|
| 147 | + |
|
| 148 | + $importer_charset = (($charset === $GLOBALS['meta']['charset']) ? null : $charset); |
|
| 149 | + |
|
| 150 | + $filename = "$filename.$extension"; |
|
| 151 | + |
|
| 152 | + $output = ''; |
|
| 153 | + $nb = 0; |
|
| 154 | + if (!empty($options['entetes']) and is_array($options['entetes'])) { |
|
| 155 | + $output = exporter_csv_ligne_numerotee($nb, $options['entetes'], $options['delim'], $importer_charset, $options['callback']); |
|
| 156 | + } |
|
| 157 | + // les donnees commencent toujours a la ligne 1, qu'il y ait ou non des entetes |
|
| 158 | + $nb++; |
|
| 159 | + |
|
| 160 | + if ($options['envoyer']) { |
|
| 161 | + $disposition = ($options['envoyer'] === 'attachment' ? 'attachment' : 'inline'); |
|
| 162 | + header("Content-Type: text/comma-separated-values; charset=$charset"); |
|
| 163 | + header("Content-Disposition: $disposition; filename=$filename"); |
|
| 164 | + |
|
| 165 | + // Vider tous les tampons |
|
| 166 | + $level = @ob_get_level(); |
|
| 167 | + while ($level--) { |
|
| 168 | + @ob_end_flush(); |
|
| 169 | + } |
|
| 170 | + } |
|
| 171 | + |
|
| 172 | + // si envoyer=='attachment' on passe par un fichier temporaire |
|
| 173 | + // sinon on ecrit directement sur stdout |
|
| 174 | + if ($options['envoyer'] and $options['envoyer'] !== 'attachment') { |
|
| 175 | + $fichier = 'php://output'; |
|
| 176 | + } |
|
| 177 | + else { |
|
| 178 | + $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 179 | + } |
|
| 180 | + |
|
| 181 | + $fp = fopen($fichier, 'w'); |
|
| 182 | + $length = fwrite($fp, $output); |
|
| 183 | + |
|
| 184 | + while ($row = is_array($resource) ? array_shift($resource) : sql_fetch($resource)) { |
|
| 185 | + $output = exporter_csv_ligne_numerotee($nb, $row, $options['delim'], $importer_charset, $options['callback']); |
|
| 186 | + $length += fwrite($fp, $output); |
|
| 187 | + $nb++; |
|
| 188 | + } |
|
| 189 | + fclose($fp); |
|
| 190 | + |
|
| 191 | + if ($options['envoyer']) { |
|
| 192 | + if ($options['envoyer'] === 'attachment') { |
|
| 193 | + header("Content-Length: $length"); |
|
| 194 | + readfile($fichier); |
|
| 195 | + } |
|
| 196 | + // si on a envoye inline, c'est deja tout bon |
|
| 197 | + exit; |
|
| 198 | + } |
|
| 199 | + |
|
| 200 | + return $fichier; |
|
| 201 | 201 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | $champ = preg_replace(',[\s]+,ms', ' ', $champ); |
| 39 | 39 | $champ = str_replace('"', '""', $champ); |
| 40 | 40 | |
| 41 | - return '"' . $champ . '"'; |
|
| 41 | + return '"'.$champ.'"'; |
|
| 42 | 42 | } |
| 43 | 43 | |
| 44 | 44 | /** |
@@ -58,7 +58,7 @@ discard block |
||
| 58 | 58 | if ($callback) { |
| 59 | 59 | $ligne = $callback($nb, $ligne, $delim, $importer_charset); |
| 60 | 60 | } |
| 61 | - $output = join($delim, array_map('exporter_csv_champ', $ligne)) . "\r\n"; |
|
| 61 | + $output = join($delim, array_map('exporter_csv_champ', $ligne))."\r\n"; |
|
| 62 | 62 | if ($importer_charset) { |
| 63 | 63 | $output = str_replace('’', '\'', $output); |
| 64 | 64 | $output = unicode2charset(html2unicode(charset2unicode($output)), $importer_charset); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | $fichier = 'php://output'; |
| 176 | 176 | } |
| 177 | 177 | else { |
| 178 | - $fichier = sous_repertoire(_DIR_CACHE, 'export') . $filename; |
|
| 178 | + $fichier = sous_repertoire(_DIR_CACHE, 'export').$filename; |
|
| 179 | 179 | } |
| 180 | 180 | |
| 181 | 181 | $fp = fopen($fichier, 'w'); |
@@ -17,7 +17,7 @@ discard block |
||
| 17 | 17 | **/ |
| 18 | 18 | |
| 19 | 19 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 20 | - return; |
|
| 20 | + return; |
|
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | |
@@ -40,29 +40,29 @@ discard block |
||
| 40 | 40 | * Code HTML de la liste |
| 41 | 41 | */ |
| 42 | 42 | function inc_lister_objets_dist($vue, $contexte = [], $force = false) { |
| 43 | - $res = ''; // debug |
|
| 44 | - if (!is_array($contexte)) { |
|
| 45 | - return _L('$contexte doit etre un tableau dans inc/lister_objets'); |
|
| 46 | - } |
|
| 43 | + $res = ''; // debug |
|
| 44 | + if (!is_array($contexte)) { |
|
| 45 | + return _L('$contexte doit etre un tableau dans inc/lister_objets'); |
|
| 46 | + } |
|
| 47 | 47 | |
| 48 | - $fond = "prive/objets/liste/$vue"; |
|
| 49 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 50 | - // traiter les cas particuliers |
|
| 51 | - include_spip('base/connect_sql'); |
|
| 52 | - $vue = table_objet($vue); |
|
| 53 | - $fond = "prive/objets/liste/$vue"; |
|
| 54 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 55 | - return _L("vue $vue introuvable pour lister les objets"); |
|
| 56 | - } |
|
| 57 | - } |
|
| 48 | + $fond = "prive/objets/liste/$vue"; |
|
| 49 | + if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 50 | + // traiter les cas particuliers |
|
| 51 | + include_spip('base/connect_sql'); |
|
| 52 | + $vue = table_objet($vue); |
|
| 53 | + $fond = "prive/objets/liste/$vue"; |
|
| 54 | + if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 55 | + return _L("vue $vue introuvable pour lister les objets"); |
|
| 56 | + } |
|
| 57 | + } |
|
| 58 | 58 | |
| 59 | 59 | |
| 60 | - $contexte['sinon'] = ($force ? $contexte['titre'] : ''); |
|
| 60 | + $contexte['sinon'] = ($force ? $contexte['titre'] : ''); |
|
| 61 | 61 | |
| 62 | - $res = recuperer_fond($fond, $contexte, ['ajax' => true]); |
|
| 63 | - if (_request('var_liste')) { |
|
| 64 | - echo var_export($contexte, true); |
|
| 65 | - } |
|
| 62 | + $res = recuperer_fond($fond, $contexte, ['ajax' => true]); |
|
| 63 | + if (_request('var_liste')) { |
|
| 64 | + echo var_export($contexte, true); |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return $res; |
|
| 67 | + return $res; |
|
| 68 | 68 | } |
@@ -46,12 +46,12 @@ |
||
| 46 | 46 | } |
| 47 | 47 | |
| 48 | 48 | $fond = "prive/objets/liste/$vue"; |
| 49 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 49 | + if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) { |
|
| 50 | 50 | // traiter les cas particuliers |
| 51 | 51 | include_spip('base/connect_sql'); |
| 52 | 52 | $vue = table_objet($vue); |
| 53 | 53 | $fond = "prive/objets/liste/$vue"; |
| 54 | - if (!find_in_path($fond . '.' . _EXTENSION_SQUELETTES)) { |
|
| 54 | + if (!find_in_path($fond.'.'._EXTENSION_SQUELETTES)) { |
|
| 55 | 55 | return _L("vue $vue introuvable pour lister les objets"); |
| 56 | 56 | } |
| 57 | 57 | } |
@@ -93,7 +93,7 @@ discard block |
||
| 93 | 93 | |
| 94 | 94 | $titre = '<title>[' |
| 95 | 95 | . $nom_site_spip |
| 96 | - . '] ' . $match |
|
| 96 | + . '] '.$match |
|
| 97 | 97 | . '</title>'; |
| 98 | 98 | |
| 99 | 99 | $texte = substr_replace($texte, $titre, $p + 6, 0); |
@@ -155,7 +155,7 @@ discard block |
||
| 155 | 155 | $flux['data']['texte'] = pipeline( |
| 156 | 156 | 'affiche_droite', |
| 157 | 157 | ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
| 158 | - ) . liste_objets_bloques( |
|
| 158 | + ).liste_objets_bloques( |
|
| 159 | 159 | $exec, |
| 160 | 160 | $flux['args']['contexte'] |
| 161 | 161 | ); |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
| 191 | 191 | 'prive/objets/editer/traductions', |
| 192 | 192 | ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
| 193 | - ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 193 | + ).'<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 194 | 194 | $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
| 195 | 195 | 'args' => [ |
| 196 | 196 | 'contexte' => $flux['args']['contexte'], |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | $full_marqueur = "$ouvrir$marqueur$fermer"; |
| 259 | 259 | |
| 260 | 260 | // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
| 261 | - if ($marqueur_pos === false) { |
|
| 261 | + if ($marqueur_pos === false) { |
|
| 262 | 262 | $texte = preg_replace( |
| 263 | 263 | ",$inserer_avant,", |
| 264 | 264 | "$full_marqueur\\0", |
@@ -305,7 +305,7 @@ discard block |
||
| 305 | 305 | } |
| 306 | 306 | } |
| 307 | 307 | if ($res) { |
| 308 | - $flux['data'] = $res . $flux['data']; |
|
| 308 | + $flux['data'] = $res.$flux['data']; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | return $flux; |
@@ -16,7 +16,7 @@ discard block |
||
| 16 | 16 | * @package SPIP\Core\Pipelines |
| 17 | 17 | **/ |
| 18 | 18 | if (!defined('_ECRIRE_INC_VERSION')) { |
| 19 | - return; |
|
| 19 | + return; |
|
| 20 | 20 | } |
| 21 | 21 | |
| 22 | 22 | |
@@ -35,36 +35,36 @@ discard block |
||
| 35 | 35 | * @return string Contenu complété des scripts javascripts, dont jQuery |
| 36 | 36 | **/ |
| 37 | 37 | function f_jQuery_prive($texte) { |
| 38 | - $x = ''; |
|
| 39 | - $jquery_plugins = pipeline( |
|
| 40 | - 'jquery_plugins', |
|
| 41 | - [ |
|
| 42 | - 'prive/javascript/jquery.js', |
|
| 43 | - 'prive/javascript/jquery.form.js', |
|
| 44 | - 'prive/javascript/jquery.autosave.js', |
|
| 45 | - 'prive/javascript/jquery.placeholder-label.js', |
|
| 46 | - 'prive/javascript/ajaxCallback.js', |
|
| 47 | - 'prive/javascript/js.cookie.js', |
|
| 48 | - 'prive/javascript/spip_barre.js', |
|
| 49 | - ] |
|
| 50 | - ); |
|
| 51 | - foreach (array_unique($jquery_plugins) as $script) { |
|
| 52 | - if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 53 | - $script = timestamp($script); |
|
| 54 | - $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 55 | - } |
|
| 56 | - } |
|
| 57 | - // inserer avant le premier script externe ou a la fin |
|
| 58 | - if ( |
|
| 59 | - preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 60 | - and $p = strpos($texte, (string) $match[0]) |
|
| 61 | - ) { |
|
| 62 | - $texte = substr_replace($texte, $x, $p, 0); |
|
| 63 | - } else { |
|
| 64 | - $texte .= $x; |
|
| 65 | - } |
|
| 38 | + $x = ''; |
|
| 39 | + $jquery_plugins = pipeline( |
|
| 40 | + 'jquery_plugins', |
|
| 41 | + [ |
|
| 42 | + 'prive/javascript/jquery.js', |
|
| 43 | + 'prive/javascript/jquery.form.js', |
|
| 44 | + 'prive/javascript/jquery.autosave.js', |
|
| 45 | + 'prive/javascript/jquery.placeholder-label.js', |
|
| 46 | + 'prive/javascript/ajaxCallback.js', |
|
| 47 | + 'prive/javascript/js.cookie.js', |
|
| 48 | + 'prive/javascript/spip_barre.js', |
|
| 49 | + ] |
|
| 50 | + ); |
|
| 51 | + foreach (array_unique($jquery_plugins) as $script) { |
|
| 52 | + if ($script = find_in_path(supprimer_timestamp($script))) { |
|
| 53 | + $script = timestamp($script); |
|
| 54 | + $x .= "\n<script src=\"$script\" type=\"text/javascript\"></script>\n"; |
|
| 55 | + } |
|
| 56 | + } |
|
| 57 | + // inserer avant le premier script externe ou a la fin |
|
| 58 | + if ( |
|
| 59 | + preg_match(',<script[^><]*src=,', $texte, $match) |
|
| 60 | + and $p = strpos($texte, (string) $match[0]) |
|
| 61 | + ) { |
|
| 62 | + $texte = substr_replace($texte, $x, $p, 0); |
|
| 63 | + } else { |
|
| 64 | + $texte .= $x; |
|
| 65 | + } |
|
| 66 | 66 | |
| 67 | - return $texte; |
|
| 67 | + return $texte; |
|
| 68 | 68 | } |
| 69 | 69 | |
| 70 | 70 | |
@@ -77,42 +77,42 @@ discard block |
||
| 77 | 77 | * @return string |
| 78 | 78 | */ |
| 79 | 79 | function affichage_final_prive_title_auto($texte) { |
| 80 | - if ( |
|
| 81 | - strpos($texte, '<title>') === false |
|
| 82 | - and |
|
| 83 | - (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 84 | - or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 85 | - and $match = textebrut(trim($match[1])) |
|
| 86 | - and ($p = strpos($texte, '<head>')) !== false |
|
| 87 | - ) { |
|
| 88 | - if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 89 | - $nom_site_spip = _T('info_mon_site_spip'); |
|
| 90 | - } |
|
| 80 | + if ( |
|
| 81 | + strpos($texte, '<title>') === false |
|
| 82 | + and |
|
| 83 | + (preg_match(',<h1[^>]*>(.+)</h1>,Uims', $texte, $match) |
|
| 84 | + or preg_match(',<h[23][^>]*>(.+)</h[23]>,Uims', $texte, $match)) |
|
| 85 | + and $match = textebrut(trim($match[1])) |
|
| 86 | + and ($p = strpos($texte, '<head>')) !== false |
|
| 87 | + ) { |
|
| 88 | + if (!$nom_site_spip = textebrut(typo($GLOBALS['meta']['nom_site']))) { |
|
| 89 | + $nom_site_spip = _T('info_mon_site_spip'); |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - $titre = '<title>[' |
|
| 93 | - . $nom_site_spip |
|
| 94 | - . '] ' . $match |
|
| 95 | - . '</title>'; |
|
| 92 | + $titre = '<title>[' |
|
| 93 | + . $nom_site_spip |
|
| 94 | + . '] ' . $match |
|
| 95 | + . '</title>'; |
|
| 96 | 96 | |
| 97 | - $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 98 | - } |
|
| 97 | + $texte = substr_replace($texte, $titre, $p + 6, 0); |
|
| 98 | + } |
|
| 99 | 99 | |
| 100 | - return $texte; |
|
| 100 | + return $texte; |
|
| 101 | 101 | } |
| 102 | 102 | |
| 103 | 103 | |
| 104 | 104 | // Fonction standard pour le pipeline 'boite_infos' |
| 105 | 105 | function f_boite_infos($flux) { |
| 106 | - $args = $flux['args']; |
|
| 107 | - $type = $args['type']; |
|
| 108 | - unset($args['row']); |
|
| 109 | - if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 110 | - $type = 'objet'; |
|
| 111 | - } |
|
| 112 | - $args['espace_prive'] = 1; |
|
| 113 | - $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 106 | + $args = $flux['args']; |
|
| 107 | + $type = $args['type']; |
|
| 108 | + unset($args['row']); |
|
| 109 | + if (!trouver_fond($type, 'prive/objets/infos/')) { |
|
| 110 | + $type = 'objet'; |
|
| 111 | + } |
|
| 112 | + $args['espace_prive'] = 1; |
|
| 113 | + $flux['data'] .= recuperer_fond("prive/objets/infos/$type", $args); |
|
| 114 | 114 | |
| 115 | - return $flux; |
|
| 115 | + return $flux; |
|
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | |
@@ -131,97 +131,97 @@ discard block |
||
| 131 | 131 | * @return array Données du pipeline |
| 132 | 132 | */ |
| 133 | 133 | function f_afficher_blocs_ecrire($flux) { |
| 134 | - static $o = []; |
|
| 135 | - if (is_string($fond = $flux['args']['fond'])) { |
|
| 136 | - $exec = $flux['args']['contexte']['exec'] ?? _request('exec'); |
|
| 137 | - if (!isset($o[$exec])) { |
|
| 138 | - $o[$exec] = trouver_objet_exec($exec); |
|
| 139 | - } |
|
| 140 | - // cas particulier |
|
| 141 | - if ($exec == 'infos_perso') { |
|
| 142 | - $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 143 | - } |
|
| 144 | - $typepage = ($flux['args']['contexte']['type-page'] ?? $exec); |
|
| 145 | - if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 146 | - $flux['data']['texte'] = pipeline( |
|
| 147 | - 'affiche_gauche', |
|
| 148 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 149 | - ); |
|
| 150 | - } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 151 | - include_spip('inc/presentation_mini'); |
|
| 152 | - $flux['data']['texte'] = pipeline( |
|
| 153 | - 'affiche_droite', |
|
| 154 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 155 | - ) . liste_objets_bloques( |
|
| 156 | - $exec, |
|
| 157 | - $flux['args']['contexte'] |
|
| 158 | - ); |
|
| 159 | - } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 160 | - // id non defini sur les formulaire de nouveaux objets |
|
| 161 | - $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 162 | - $flux['data']['texte'] = pipeline( |
|
| 163 | - 'affiche_hierarchie', |
|
| 164 | - ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 165 | - ); |
|
| 166 | - } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 167 | - // Préparation du marqueur affiche_milieu |
|
| 168 | - // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 169 | - $est_page_objet = !empty($o[$exec]['type']); |
|
| 170 | - $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 171 | - $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 172 | - $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 173 | - $flux['data']['texte'], |
|
| 174 | - '<!--affiche_milieu-->', |
|
| 175 | - '<div id=["\']wysiwyg', |
|
| 176 | - $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 177 | - $encapsuler_milieu ? '</div>' : '' |
|
| 178 | - ); |
|
| 179 | - if ( |
|
| 180 | - $o[$exec] |
|
| 181 | - and $objet = $o[$exec]['type'] |
|
| 182 | - and $o[$exec]['edition'] == false |
|
| 183 | - and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 184 | - and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 185 | - ) { |
|
| 186 | - // inserer le formulaire de traduction |
|
| 187 | - $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 188 | - 'prive/objets/editer/traductions', |
|
| 189 | - ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 190 | - ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 191 | - $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 192 | - 'args' => [ |
|
| 193 | - 'contexte' => $flux['args']['contexte'], |
|
| 194 | - 'type' => $objet, |
|
| 195 | - 'id' => $id |
|
| 196 | - ], |
|
| 197 | - 'data' => $flux['data']['texte'] |
|
| 198 | - ]); |
|
| 199 | - } |
|
| 200 | - $flux['data']['texte'] = pipeline( |
|
| 201 | - 'affiche_milieu', |
|
| 202 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 203 | - ); |
|
| 204 | - } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 205 | - $flux['data']['texte'] = pipeline( |
|
| 206 | - 'affiche_pied', |
|
| 207 | - ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 208 | - ); |
|
| 209 | - } elseif ( |
|
| 210 | - strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 211 | - and $objet = basename($fond) |
|
| 212 | - and $objet == substr($fond, 21) |
|
| 213 | - and isset($o[$objet]) |
|
| 214 | - and $o[$objet] |
|
| 215 | - ) { |
|
| 216 | - $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 217 | - $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 218 | - 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 219 | - 'data' => $flux['data']['texte'] |
|
| 220 | - ]); |
|
| 221 | - } |
|
| 222 | - } |
|
| 134 | + static $o = []; |
|
| 135 | + if (is_string($fond = $flux['args']['fond'])) { |
|
| 136 | + $exec = $flux['args']['contexte']['exec'] ?? _request('exec'); |
|
| 137 | + if (!isset($o[$exec])) { |
|
| 138 | + $o[$exec] = trouver_objet_exec($exec); |
|
| 139 | + } |
|
| 140 | + // cas particulier |
|
| 141 | + if ($exec == 'infos_perso') { |
|
| 142 | + $flux['args']['contexte']['id_auteur'] = $GLOBALS['visiteur_session']['id_auteur']; |
|
| 143 | + } |
|
| 144 | + $typepage = ($flux['args']['contexte']['type-page'] ?? $exec); |
|
| 145 | + if ($fond == "prive/squelettes/navigation/$typepage") { |
|
| 146 | + $flux['data']['texte'] = pipeline( |
|
| 147 | + 'affiche_gauche', |
|
| 148 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 149 | + ); |
|
| 150 | + } elseif ($fond == "prive/squelettes/extra/$typepage") { |
|
| 151 | + include_spip('inc/presentation_mini'); |
|
| 152 | + $flux['data']['texte'] = pipeline( |
|
| 153 | + 'affiche_droite', |
|
| 154 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 155 | + ) . liste_objets_bloques( |
|
| 156 | + $exec, |
|
| 157 | + $flux['args']['contexte'] |
|
| 158 | + ); |
|
| 159 | + } elseif ($fond == "prive/squelettes/hierarchie/$typepage" and $o[$exec]) { |
|
| 160 | + // id non defini sur les formulaire de nouveaux objets |
|
| 161 | + $id = isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) ? intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) : 0; |
|
| 162 | + $flux['data']['texte'] = pipeline( |
|
| 163 | + 'affiche_hierarchie', |
|
| 164 | + ['args' => ['objet' => $o[$exec]['type'], 'id_objet' => $id], 'data' => $flux['data']['texte']] |
|
| 165 | + ); |
|
| 166 | + } elseif ($fond == "prive/squelettes/contenu/$typepage") { |
|
| 167 | + // Préparation du marqueur affiche_milieu |
|
| 168 | + // Si c'est la page d'un objet pas en édition, on l'encapsule dans un div |
|
| 169 | + $est_page_objet = !empty($o[$exec]['type']); |
|
| 170 | + $est_en_edition = (isset($o[$exec]['edition']) and $o[$exec]['edition'] === true); |
|
| 171 | + $encapsuler_milieu = ($est_page_objet and !$est_en_edition); |
|
| 172 | + $flux['data']['texte'] = afficher_blocs_ecrire_preparer_marqueur( |
|
| 173 | + $flux['data']['texte'], |
|
| 174 | + '<!--affiche_milieu-->', |
|
| 175 | + '<div id=["\']wysiwyg', |
|
| 176 | + $encapsuler_milieu ? '<div class="affiche_milieu">' : '', |
|
| 177 | + $encapsuler_milieu ? '</div>' : '' |
|
| 178 | + ); |
|
| 179 | + if ( |
|
| 180 | + $o[$exec] |
|
| 181 | + and $objet = $o[$exec]['type'] |
|
| 182 | + and $o[$exec]['edition'] == false |
|
| 183 | + and isset($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 184 | + and $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]) |
|
| 185 | + ) { |
|
| 186 | + // inserer le formulaire de traduction |
|
| 187 | + $flux['data']['texte'] = str_replace('<!--affiche_milieu-->', recuperer_fond( |
|
| 188 | + 'prive/objets/editer/traductions', |
|
| 189 | + ['objet' => $objet, 'id_objet' => $id, 'espace_prive' => 1] |
|
| 190 | + ) . '<!--affiche_milieu-->', $flux['data']['texte']); |
|
| 191 | + $flux['data']['texte'] = pipeline('afficher_fiche_objet', [ |
|
| 192 | + 'args' => [ |
|
| 193 | + 'contexte' => $flux['args']['contexte'], |
|
| 194 | + 'type' => $objet, |
|
| 195 | + 'id' => $id |
|
| 196 | + ], |
|
| 197 | + 'data' => $flux['data']['texte'] |
|
| 198 | + ]); |
|
| 199 | + } |
|
| 200 | + $flux['data']['texte'] = pipeline( |
|
| 201 | + 'affiche_milieu', |
|
| 202 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 203 | + ); |
|
| 204 | + } elseif ($fond == 'prive/squelettes/inclure/pied') { |
|
| 205 | + $flux['data']['texte'] = pipeline( |
|
| 206 | + 'affiche_pied', |
|
| 207 | + ['args' => $flux['args']['contexte'], 'data' => $flux['data']['texte']] |
|
| 208 | + ); |
|
| 209 | + } elseif ( |
|
| 210 | + strncmp($fond, 'prive/objets/contenu/', 21) == 0 |
|
| 211 | + and $objet = basename($fond) |
|
| 212 | + and $objet == substr($fond, 21) |
|
| 213 | + and isset($o[$objet]) |
|
| 214 | + and $o[$objet] |
|
| 215 | + ) { |
|
| 216 | + $id = intval($flux['args']['contexte'][$o[$exec]['id_table_objet']]); |
|
| 217 | + $flux['data']['texte'] = pipeline('afficher_contenu_objet', [ |
|
| 218 | + 'args' => ['type' => $objet, 'id_objet' => $id, 'contexte' => $flux['args']['contexte']], |
|
| 219 | + 'data' => $flux['data']['texte'] |
|
| 220 | + ]); |
|
| 221 | + } |
|
| 222 | + } |
|
| 223 | 223 | |
| 224 | - return $flux; |
|
| 224 | + return $flux; |
|
| 225 | 225 | } |
| 226 | 226 | |
| 227 | 227 | /** |
@@ -249,36 +249,36 @@ discard block |
||
| 249 | 249 | */ |
| 250 | 250 | function afficher_blocs_ecrire_preparer_marqueur(?string $texte, string $marqueur, string $inserer_avant, string $ouvrir = '', string $fermer = ''): ?string { |
| 251 | 251 | |
| 252 | - if ($texte) { |
|
| 253 | - $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 254 | - $marqueur_pos = strpos($texte, $marqueur); |
|
| 255 | - $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 252 | + if ($texte) { |
|
| 253 | + $encapsuler = (($ouvrir and $fermer) ? true : false); |
|
| 254 | + $marqueur_pos = strpos($texte, $marqueur); |
|
| 255 | + $full_marqueur = "$ouvrir$marqueur$fermer"; |
|
| 256 | 256 | |
| 257 | - // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 258 | - if ($marqueur_pos === false) { |
|
| 259 | - $texte = preg_replace( |
|
| 260 | - ",$inserer_avant,", |
|
| 261 | - "$full_marqueur\\0", |
|
| 262 | - $texte |
|
| 263 | - ); |
|
| 264 | - // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 265 | - // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 266 | - // Il ne faut donc aucun espace blanc en trop. |
|
| 267 | - } elseif ( |
|
| 268 | - $marqueur_pos !== false |
|
| 269 | - and $encapsuler |
|
| 270 | - and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 271 | - ) { |
|
| 272 | - $texte = substr_replace( |
|
| 273 | - $texte, |
|
| 274 | - $full_marqueur, |
|
| 275 | - $marqueur_pos, |
|
| 276 | - strlen($marqueur) |
|
| 277 | - ); |
|
| 278 | - } |
|
| 279 | - } |
|
| 257 | + // Le marqueur est absent : on l'ajoute avant l'élément indiqué |
|
| 258 | + if ($marqueur_pos === false) { |
|
| 259 | + $texte = preg_replace( |
|
| 260 | + ",$inserer_avant,", |
|
| 261 | + "$full_marqueur\\0", |
|
| 262 | + $texte |
|
| 263 | + ); |
|
| 264 | + // Le marqueur est présent mais pas encapsulé : on ajoute les balises ouvrantes et fermantes. |
|
| 265 | + // Pour vérifier, on prend le texte précédent et on regarde si ça correspond à la balise ouvrante. |
|
| 266 | + // Il ne faut donc aucun espace blanc en trop. |
|
| 267 | + } elseif ( |
|
| 268 | + $marqueur_pos !== false |
|
| 269 | + and $encapsuler |
|
| 270 | + and substr($texte, $marqueur_pos - strlen($ouvrir), strlen($ouvrir)) !== $ouvrir |
|
| 271 | + ) { |
|
| 272 | + $texte = substr_replace( |
|
| 273 | + $texte, |
|
| 274 | + $full_marqueur, |
|
| 275 | + $marqueur_pos, |
|
| 276 | + strlen($marqueur) |
|
| 277 | + ); |
|
| 278 | + } |
|
| 279 | + } |
|
| 280 | 280 | |
| 281 | - return $texte; |
|
| 281 | + return $texte; |
|
| 282 | 282 | } |
| 283 | 283 | |
| 284 | 284 | /** |
@@ -289,23 +289,23 @@ discard block |
||
| 289 | 289 | * @return string |
| 290 | 290 | */ |
| 291 | 291 | function f_queue_affiche_milieu($flux) { |
| 292 | - $args = $flux['args']; |
|
| 293 | - $res = ''; |
|
| 294 | - foreach ($args as $key => $arg) { |
|
| 295 | - if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 296 | - $objet = preg_replace(',^id_,', '', $key); |
|
| 297 | - $res .= recuperer_fond( |
|
| 298 | - 'modeles/object_jobs_list', |
|
| 299 | - ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 300 | - ['ajax' => true] |
|
| 301 | - ); |
|
| 302 | - } |
|
| 303 | - } |
|
| 304 | - if ($res) { |
|
| 305 | - $flux['data'] = $res . $flux['data']; |
|
| 306 | - } |
|
| 292 | + $args = $flux['args']; |
|
| 293 | + $res = ''; |
|
| 294 | + foreach ($args as $key => $arg) { |
|
| 295 | + if (preg_match(',^id_,', $key) and is_numeric($arg) and $arg = intval($arg)) { |
|
| 296 | + $objet = preg_replace(',^id_,', '', $key); |
|
| 297 | + $res .= recuperer_fond( |
|
| 298 | + 'modeles/object_jobs_list', |
|
| 299 | + ['id_objet' => $arg, 'objet' => $objet, 'espace_prive' => 1], |
|
| 300 | + ['ajax' => true] |
|
| 301 | + ); |
|
| 302 | + } |
|
| 303 | + } |
|
| 304 | + if ($res) { |
|
| 305 | + $flux['data'] = $res . $flux['data']; |
|
| 306 | + } |
|
| 307 | 307 | |
| 308 | - return $flux; |
|
| 308 | + return $flux; |
|
| 309 | 309 | } |
| 310 | 310 | |
| 311 | 311 | /** |
@@ -319,39 +319,39 @@ discard block |
||
| 319 | 319 | * @return array|bool |
| 320 | 320 | */ |
| 321 | 321 | function trouver_objet_exec(?string $exec) { |
| 322 | - static $objet_exec = []; |
|
| 323 | - if (!$exec) { |
|
| 324 | - return false; |
|
| 325 | - } |
|
| 326 | - // cas particulier |
|
| 327 | - if ($exec === 'infos_perso') { |
|
| 328 | - $exec = 'auteur'; |
|
| 329 | - set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 330 | - } |
|
| 331 | - if (!isset($objet_exec[$exec])) { |
|
| 332 | - $objet_exec[$exec] = false; |
|
| 333 | - $infos = lister_tables_objets_sql(); |
|
| 334 | - foreach ($infos as $t => $info) { |
|
| 335 | - if ($exec === $info['url_edit'] and $info['editable']) { |
|
| 336 | - return $objet_exec[$exec] = [ |
|
| 337 | - 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 338 | - 'table_objet_sql' => $t, |
|
| 339 | - 'table' => $info['table_objet'], |
|
| 340 | - 'type' => $info['type'], |
|
| 341 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 342 | - ]; |
|
| 343 | - } |
|
| 344 | - if ($exec === $info['url_voir']) { |
|
| 345 | - return $objet_exec[$exec] = [ |
|
| 346 | - 'edition' => false, |
|
| 347 | - 'table_objet_sql' => $t, |
|
| 348 | - 'table' => $info['table_objet'], |
|
| 349 | - 'type' => $info['type'], |
|
| 350 | - 'id_table_objet' => id_table_objet($info['type']) |
|
| 351 | - ]; |
|
| 352 | - } |
|
| 353 | - } |
|
| 354 | - } |
|
| 322 | + static $objet_exec = []; |
|
| 323 | + if (!$exec) { |
|
| 324 | + return false; |
|
| 325 | + } |
|
| 326 | + // cas particulier |
|
| 327 | + if ($exec === 'infos_perso') { |
|
| 328 | + $exec = 'auteur'; |
|
| 329 | + set_request('id_auteur', $GLOBALS['visiteur_session']['id_auteur']); |
|
| 330 | + } |
|
| 331 | + if (!isset($objet_exec[$exec])) { |
|
| 332 | + $objet_exec[$exec] = false; |
|
| 333 | + $infos = lister_tables_objets_sql(); |
|
| 334 | + foreach ($infos as $t => $info) { |
|
| 335 | + if ($exec === $info['url_edit'] and $info['editable']) { |
|
| 336 | + return $objet_exec[$exec] = [ |
|
| 337 | + 'edition' => $exec == $info['url_voir'] ? '' : true, |
|
| 338 | + 'table_objet_sql' => $t, |
|
| 339 | + 'table' => $info['table_objet'], |
|
| 340 | + 'type' => $info['type'], |
|
| 341 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 342 | + ]; |
|
| 343 | + } |
|
| 344 | + if ($exec === $info['url_voir']) { |
|
| 345 | + return $objet_exec[$exec] = [ |
|
| 346 | + 'edition' => false, |
|
| 347 | + 'table_objet_sql' => $t, |
|
| 348 | + 'table' => $info['table_objet'], |
|
| 349 | + 'type' => $info['type'], |
|
| 350 | + 'id_table_objet' => id_table_objet($info['type']) |
|
| 351 | + ]; |
|
| 352 | + } |
|
| 353 | + } |
|
| 354 | + } |
|
| 355 | 355 | |
| 356 | - return $objet_exec[$exec]; |
|
| 356 | + return $objet_exec[$exec]; |
|
| 357 | 357 | } |