lib.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. function write_metadata($filename, $desc, $source)
  3. {
  4. $metafile = fopen($filename . ".txt", 'w');
  5. fwrite($metafile, "Source:\n\t" . implode('', sanitize_long_input($source, "\t")) . "\n");
  6. fwrite($metafile, "Descri:\n\t" . implode('', sanitize_long_input($desc, "\t")) . "\t");
  7. fclose($metafile);
  8. }
  9. function sanitize_long_input($sanitizee, $preface)
  10. {
  11. $sanitized = [];
  12. $sani_len = strlen($sanitizee) - 1;
  13. if ($sani_len + 1 == 0)
  14. {
  15. $sanitized = "N/A";
  16. return $sanitized;
  17. }
  18. $j = 0;
  19. for($i = 0; $i <= $sani_len; $i++)
  20. {
  21. if ($i % 80 == 0 && $i != 0)
  22. {
  23. if (substr($sanitizee, $i, 1) == ' ')
  24. {
  25. $sanitized[$j] = "\n";
  26. $sanitized[$j + 1] = $preface;
  27. $j++;
  28. }
  29. else
  30. {
  31. $sanitized[$j] = "-";
  32. $sanitized[$j + 1] = "\n";
  33. $sanitized[$j + 2] = $preface;
  34. $sanitized[$j + 3] = $sanitizee[$i];
  35. $j += 3;
  36. }
  37. }
  38. else
  39. {
  40. $sanitized[$j] = $sanitizee[$i];
  41. }
  42. $j++;
  43. }
  44. return $sanitized;
  45. }
  46. function sanitize_filename($sanitizee)
  47. {
  48. $sanitized = str_replace(" ", "_", $sanitizee);
  49. $sanitized = str_replace("..", "_", $sanitized);
  50. $sanitized = str_replace("/", "_", $sanitized);
  51. $sanitized = str_replace("\\", "_", $sanitized);
  52. return $sanitized;
  53. }
  54. function url_to_filename($url)
  55. {
  56. $working = explode('/', $url);
  57. $filename = $working[count($working) - 1];
  58. return $filename;
  59. }
  60. ?>