controller.php 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. <?php
  2. session_start();
  3. $cmd = isset($_GET["cmd"]) ? $_GET["cmd"] : null;
  4. include "../dompdf_config.inc.php";
  5. include "functions.inc.php";
  6. switch ($cmd) {
  7. case "clear-font-cache":
  8. $files = glob(DOMPDF_FONT_DIR."*.{UFM,AFM,ufm,afm}.php", GLOB_BRACE);
  9. foreach($files as $file) {
  10. unlink($file);
  11. }
  12. break;
  13. case "install-font":
  14. if (!auth_ok()) break;
  15. $family = $_POST["family"];
  16. $data = $_FILES["file"];
  17. foreach($data["error"] as $name => $error) {
  18. if ($error) {
  19. switch($error) {
  20. case UPLOAD_ERR_INI_SIZE:
  21. case UPLOAD_ERR_FORM_SIZE:
  22. echo "The uploaded file exceeds the upload_max_filesize directive in php.ini."; break;
  23. case UPLOAD_ERR_PARTIAL:
  24. echo "The uploaded file was only partially uploaded."; break;
  25. case UPLOAD_ERR_NO_FILE:
  26. break;
  27. case UPLOAD_ERR_NO_TMP_DIR:
  28. echo "Missing a temporary folder."; break;
  29. default:
  30. echo "Unknown error";
  31. }
  32. continue;
  33. }
  34. $weight = "normal";
  35. $style = "normal";
  36. switch($name) {
  37. case "bold":
  38. $weight = "bold"; break;
  39. case "italic":
  40. $style = "italic"; break;
  41. case "bold_italic":
  42. $weight = "bold";
  43. $style = "italic";
  44. break;
  45. }
  46. $style_arr = array(
  47. "family" => $family,
  48. "weight" => $weight,
  49. "style" => $style,
  50. );
  51. Font_Metrics::init();
  52. if (!Font_Metrics::register_font($style_arr, $data["tmp_name"][$name])) {
  53. echo $data["name"][$name]." is not a valid font file";
  54. }
  55. else {
  56. echo "The <strong>$family $weight $style</strong> font was successfully installed !<br />";
  57. }
  58. }
  59. break;
  60. }