util.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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($name) {
  34. $name = preg_replace('/^The\s+/i', '', $name);
  35. $name = preg_replace('/^A\s+/i', '', $name);
  36. return $name;
  37. }
  38. ?>