Ejemplo n.º 1
0
function load_global($force_reload = false)
{
    if (!isset($_SESSION[SESSION_PLAYLISTS]) || !isset($_SESSION[SESSION_MEDIA]) || $force_reload) {
        // Load filesystem
        $extensions = array(SESSION_PLAYLISTS => explode(',', PLAYLIST_FORMATS), SESSION_MEDIA => explode(',', MEDIA_FORMATS));
        $skip_patterns = SKIP_FILE_PATTERNS == '' ? array() : explode(',', SKIP_FILE_PATTERNS);
        $filesystem_trees = load_filesystem(ROOT_DIRECTORY, $extensions, $skip_patterns);
        // Build playlists tree
        $playlist_tree = new Filesystem(ROOT_DIRECTORY, false);
        $playlist_tree->add($filesystem_trees['directories']);
        $playlist_tree->add($filesystem_trees[SESSION_PLAYLISTS]);
        $playlist_tree->expand($filesystem_trees[SESSION_PLAYLISTS]);
        // Build media tree
        $media_tree = new Filesystem(ROOT_DIRECTORY, $filesystem_trees[SESSION_MEDIA], true);
        $media_tree->add($filesystem_trees['directories']);
        $media_tree->add($filesystem_trees[SESSION_MEDIA]);
        $media_tree->remove_empty_nodes();
        $_SESSION[SESSION_PLAYLISTS] = serialize($playlist_tree);
        $_SESSION[SESSION_MEDIA] = serialize($media_tree);
    }
    return "ok";
}
Ejemplo n.º 2
0
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>";