util.php 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. <?
  2. require 'config.php';
  3. # Cleanup the provided series name
  4. # This does NOT provide comprehensively safe output,
  5. # it merely attempts to make names compatible with the filesystem and local convetions
  6. function cleanSeries($series) {
  7. # Clearly unreasonable characters
  8. $series = preg_replace('/[\0\n\r]/', ' ', $series);
  9. # Not allowed on our filesystem
  10. $series = preg_replace('/\s+[\/\:]\s+/', ' - ', $series);
  11. # General string cleanup
  12. $series = preg_replace('/\s+/', ' ', $series);
  13. # Ensure we don't go out-of-scope
  14. $series = basename($series);
  15. return $series;
  16. }
  17. # True if the input path is junk -- self-links, OS X noise, etc.
  18. function isJunk($path) {
  19. $path = basename($path);
  20. # Ignore certain fixed paths
  21. foreach (array('.', '..', '.DS_Store') as $value) {
  22. if ($path == $value) {
  23. return true;
  24. }
  25. }
  26. # Ignore ._ paths
  27. if (preg_match('/^\.\_/', $path)) {
  28. return true;
  29. }
  30. # Otherwise the path is good
  31. return false;
  32. }
  33. function sortTitle($title) {
  34. $title = displayTitle($title);
  35. $title = preg_replace('/^The\s+/i', '', $title);
  36. $title = preg_replace('/^A\s+/i', '', $title);
  37. return $title;
  38. }
  39. function displayTitle($title) {
  40. $title = preg_replace('/\xEF\x80\xA9$/', '.', $title);
  41. $title = preg_replace('/\xEF\x80\xA5/', '?', $title);
  42. return $title;
  43. }
  44. ?>