PageRenderTime 26ms CodeModel.GetById 26ms RepoModel.GetById 0ms app.codeStats 0ms

/_plugins_/lilyspip/lilyspip/install_server/server.php

https://bitbucket.org/pombredanne/spip-zone-treemap
PHP | 116 lines | 76 code | 27 blank | 13 comment | 24 complexity | 79fa515dedb1acfd3684b1033e3b9732 MD5 | raw file
  1. <?php
  2. //
  3. // Serveur d'images Lilypond developpe pour SPIP par
  4. // Richard Christophe � partir du serveur Tex de Philippe Riviere <fil@rezo.net> et Benjamin Sonntag <benjamin@sonntag.fr>
  5. // Distribue sous licence GNU/GPL
  6. // � 2007 - v0.1
  7. //
  8. //
  9. // Le format peut prendre trois valeurs 'png' pour l'image, 'midi' pour le fichier MIDI
  10. // et 'test' pour afficher la version du serveur dans les parametres du plugin
  11. // Necessite l'installation de lilypond et ImageMagick
  12. $convert_bin = "/usr/bin/convert";
  13. $lilypond_bin = "/usr/local/bin/lilypond";
  14. $lilypond_version = "2.10.33";
  15. // Cache du serveur
  16. $cache_dir = "CACHE/lilyspip";
  17. if (get_magic_quotes_gpc()) {
  18. $code = stripslashes($_GET['code']);
  19. }
  20. else {
  21. $code = ($_GET['code']);
  22. }
  23. $format = $_GET['format'];
  24. function lilypond_enhance($texte,$code_format) {
  25. global $lilypond_version;
  26. if ($code_format=="test"){//Pour afficher la version dans les parametres du Plugin
  27. $textem = "\\"."version \"$lilypond_version\"
  28. \header {}
  29. \paper {
  30. ragged-right = ##t
  31. indent = 60.0\mm
  32. paper-width = 100.0\mm
  33. paper-height = 60.0\mm
  34. }
  35. {\\relative c''{\\time 4/4 c4 c g g a a g g}}";
  36. }
  37. else {// Correction pour supprimer le bas de page et centrer l'image
  38. $textem = "\\"."version \"$lilypond_version\"
  39. \header {
  40. tagline= \"\"
  41. }
  42. \paper {
  43. ragged-right = ##t
  44. }
  45. $texte";
  46. }
  47. return $textem;
  48. }
  49. function lilypond_($texte, $code_format) {
  50. global $cache_dir;
  51. global $convert_bin;
  52. global $lilypond_bin;
  53. $fichier = "$cache_dir/".md5(trim($texte)); //contiendra le log en cas d echec
  54. $fichier_source = $fichier.'.ly';
  55. $fichier_image = $fichier.'.png';
  56. $fichier_son = $fichier.'.midi';
  57. $fichier_ps = $fichier.'.ps';
  58. $texte = lilypond_enhance($texte, $code_format);
  59. if ($f = @fopen($fichier_source, 'w')) {
  60. @fwrite($f, $texte);
  61. @fclose($f);
  62. }
  63. if (!file_exists($fichier_image) OR (filemtime($fichier_image)<filemtime("server.php"))) {
  64. $cmd = $lilypond_bin." --safe --png --output=$cache_dir"." ".$fichier_source." 2> ".$fichier ;
  65. exec($cmd);
  66. if (@file_exists($fichier_image)){
  67. $cmd2 = $convert_bin." -trim ".$fichier_image." ".$fichier_image;
  68. exec($cmd2);
  69. }
  70. else { // insertion du fichier log dans l image
  71. $cmd3 = $convert_bin." -size 800x150 xc:white -pointsize 10 -gravity northwest -annotate 0 @".$fichier." ".$fichier_image;
  72. exec($cmd3);
  73. }
  74. }
  75. //efface fichiers ly log et ps du CACHE
  76. if (@file_exists($fichier_ps) && chmod($fichier_ps,0777)) unlink($fichier_ps);
  77. if (@file_exists($fichier_source) && chmod($fichier_source,0777)) unlink($fichier_source);
  78. if (@file_exists($fichier) && chmod($fichier,0777)) unlink($fichier);
  79. if ($code_format=="test" || $code_format=="png")
  80. return $fichier_image;
  81. else if ($code_format == "midi" && file_exists($fichier_son))
  82. return $fichier_son;
  83. }
  84. // Retourner l'image ou le son demande
  85. if (($format=="test" || $format=="png")) $type_header = "image/png";
  86. else if ($format=="midi") $type_header = "audio/x-midi";
  87. header("Content-Type: ".$type_header);
  88. readfile(lilypond_(rawurldecode($code),$format));
  89. ?>