function playlist_contents($playlist_path, $data) { // Make data paths relative to playlist path, and skip directories $playlist_content = array(); foreach ($data as $file) { if (file_exists($file) && !is_dir($file)) { array_push($playlist_content, make_relative_path($playlist_path, $file)); } } return $playlist_content; }
test(simplify_path("/foo/./bar/baz"), "/foo/bar/baz"); test(simplify_path("/foo/abc/../bar/baz"), "/foo/bar/baz"); test(simplify_path("/foo/abc/.././bar/baz"), "/foo/bar/baz"); test(simplify_path("/abc/def/ghi/../../jkl"), "/abc/jkl"); test(simplify_path("./././."), ""); test(simplify_path("././././."), ""); test(simplify_path("../../../.."), "../../../.."); test(simplify_path("../../../../.."), "../../../../.."); echo "<br><b>make_relative_path()</b><br>"; // Test relative to file test(make_relative_path("foo.m3u", "bar.mp3", true), "bar.mp3"); test(make_relative_path("/foo/bar.m3u", "/foo/bar.mp3", true), "bar.mp3"); test(make_relative_path("/foo/bar.m3u", "/foo/bar.m3u", true), "bar.m3u"); test(make_relative_path("/foo/bar.m3u", "/", true), ".."); test(make_relative_path("/", "/foo/bar.mp3", true), "foo/bar.mp3"); test(make_relative_path("/foo/bar.m3u", "/foo/bar/baz.mp3", true), "bar/baz.mp3"); test(make_relative_path("/foo/bar/baz.m3u", "/foo/bar.mp3", true), "../bar.mp3"); test(make_relative_path("/foo/bar/baz.m3u", "/foo/baz/bar.mp3", true), "../baz/bar.mp3"); // Test relative to directory test(make_relative_path("foo", "bar.mp3", false), "../bar.mp3"); test(make_relative_path("/foo", "/foo/bar.mp3", false), "bar.mp3"); test(make_relative_path("/foo/bar", "/foo/bar", false), ""); test(make_relative_path("/foo/bar", "/", false), "../.."); test(make_relative_path("/", "/foo/bar.mp3", false), "foo/bar.mp3"); test(make_relative_path("/foo/bar/baz", "/foo/bar.mp3", false), "../../bar.mp3"); test(make_relative_path("/foo/bar/baz", "/foo/baz/bar.mp3", false), "../../baz/bar.mp3"); $root = '/home/rijo/programming/github/m3uer/src'; $extensions = array('playlists' => array('m3u'), 'music' => array('wav', 'mp3')); $tree = load_filesystem($root, $extensions); echo "<pre>" . print_r($tree, true) . "</pre>"; echo "<br><br><b>" . ($passed_all ? "<font color=\"#009900\">All tests passed!</font>" : "<font color=\"#990000\">Did not pass all tests!</font>") . "</b>";
public function checkFolders() { // image base folder if (preg_match('#^(?:[a-zA-Z]+:)?[/\\\\]#', $this->imagesfolder)) { // starts with a leading slash (UNIX) or a drive letter designation and a backslash (Windows) // absolute path $path = realpath($this->imagesfolder); if ($path === false) { throw new SIGPlusBaseFolderException($this->imagesfolder); } if ($this->baseurl === false && strpos($path, JPATH_ROOT . DIRECTORY_SEPARATOR) === 0) { // starts with Joomla root folder $this->baseurl = JURI::base(true) . str_replace(DIRECTORY_SEPARATOR, '/', substr($path, strlen(JPATH_ROOT))); } } else { $folder = make_relative_path($this->imagesfolder); if ($folder === false) { throw new SIGPlusBaseFolderException($this->imagesfolder); } $path = JPATH_ROOT . DIRECTORY_SEPARATOR . str_replace('/', DIRECTORY_SEPARATOR, $folder); if (!is_dir($path)) { throw new SIGPlusBaseFolderPermissionException($path); } if ($this->baseurl === false) { $this->baseurl = JURI::base(true) . '/' . $folder; } } $this->imagesfolder = $path; // base URL if ($this->baseurl === false) { throw new SIGPlusBaseURLException(); } // thumbnail folder (either inside image folder or cache folder) $thumbsfolder = make_relative_path($this->thumbsfolder); if ($thumbsfolder === false) { throw new SIGPlusThumbFolderException($this->thumbsfolder); } // preview image folder (either inside image folder or cache folder) $previewfolder = make_relative_path($this->previewfolder); if ($previewfolder === false) { throw new SIGPlusPreviewFolderException($this->previewfolder); } // check that thumbnail folder and preview folder are not identical if (!$this->thumbscache && $thumbsfolder == $previewfolder) { throw new SIGPlusFolderConflictException($this->previewfolder); } // set folders $this->previewfolder = $previewfolder; $this->thumbsfolder = $thumbsfolder; // full size image folder if ($this->fullsizefolder) { $fullsizefolder = make_relative_path($this->fullsizefolder); if ($fullsizefolder === false) { throw new SIGPlusFullsizeFolderException($this->fullsizefolder); } $this->fullsizefolder = $fullsizefolder; } else { // no folder available for high-resolution images $this->fullsizefolder = false; } }
function load_filesystem_recursive($root_path, $relative_path, $extensions, $skip_patterns, &$tree) { $full_path = $root_path . DIRECTORY_SEPARATOR . $relative_path; if (!is_dir($full_path)) { die("\"{$full_path}\" is not a directory"); } $directory = opendir($full_path); if (!$directory) { die("Could not open directory \"{$full_path}\""); } while (false !== ($file = readdir($directory))) { $skip = false; foreach ($skip_patterns as $pattern) { if (preg_match($pattern, $file)) { $skip = true; } } if ($skip) { continue; } $file_info = get_file_info($full_path . DIRECTORY_SEPARATOR . $file); if (is_dir($file_info['path'])) { // Directory if (!in_array($file, array('.', '..'))) { array_push($tree['directories'], make_relative_path($root_path, $file_info['path'], false)); load_filesystem_recursive($root_path, $relative_path . DIRECTORY_SEPARATOR . $file, $extensions, $skip_patterns, $tree); } } elseif (isset($file_info['extension'])) { // File foreach ($extensions as $key => $value) { if (in_array($file_info['extension'], $value)) { array_push($tree[$key], make_relative_path($root_path, $file_info['path'], false)); } } } } closedir($directory); }