util.php 1.2 KB

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