| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- <?
- # Cleanup the provided series name
- # This does NOT provide comprehensively safe output,
- # it merely attempts to make names compatible with the filesystem and local convetions
- function cleanSeries($series) {
- # Clearly unreasonable characters
- $series = preg_replace('/[\0\n\r]/', ' ', $series);
- # Not allowed on our filesystem
- $series = preg_replace('/\s*[\/\:]\s*/', ' - ', $series);
- # General string cleanup
- $series = preg_replace('/\s+/', ' ', $series);
- # Ensure we don't go out-of-scope
- $series = basename($series);
- return $series;
- }
- # True if the input path is junk -- self-links, OS X noise, etc.
- function isJunk($path) {
- $path = basename($path);
-
- # Ignore certain fixed paths
- foreach (array('.', '..', '.DS_Store') as $value) {
- if ($path == $value) {
- return true;
- }
- }
-
- # Ignore ._ paths
- if (preg_match('/^\.\_/', $path)) {
- return true;
- }
-
- # Otherwise the path is good
- return false;
- }
- function sortTitle($title) {
- $title = displayTitle($title);
- $title = preg_replace('/^The\s+/i', '', $title);
- $title = preg_replace('/^A\s+/i', '', $title);
- return $title;
- }
- function displayTitle($title) {
- $title = preg_replace('/\xEF\x80\xA9$/', '.', $title);
- $title = preg_replace('/\xEF\x80\xA5/', '?', $title);
- return $title;
- }
- function clearCache() {
- global $CACHE_FILE;
- if (file_exists($CACHE_FILE)) {
- rename($CACHE_FILE, staleCacheName($CACHE_FILE));
- }
- }
- function staleCacheName($file) {
- return $file . '.stale';
- }
- function protocolName() {
- $protocol = 'http';
- if ($_SERVER['HTTPS']) {
- $protocol = 'https';
- }
- return $protocol;
- }
- function adjustProtocol($url) {
- return preg_replace('/^https?\:/i', protocolName() . ':', $url);
- }
- ?>
|