Exemplo n.º 1
0
 private function add_recursive(&$nodes, $items, $relative_path = '.')
 {
     $key = array_shift($items);
     foreach ($nodes as $node) {
         if ($key == $node->text) {
             return $this->add_recursive($node->children, $items, $relative_path . DIRECTORY_SEPARATOR . $key);
         }
     }
     $full_path = simplify_path($this->root_path . DIRECTORY_SEPARATOR . $relative_path . DIRECTORY_SEPARATOR . $key);
     $new_file = new File($full_path, $key);
     $new_file->leaf = !is_dir($full_path);
     $new_file->checked = $this->checkboxes ? false : 'undefined';
     array_push($nodes, $new_file);
     if (count($items) > 0) {
         return $this->add_recursive($new_file->children, $items, $relative_path . DIRECTORY_SEPARATOR . $key);
     }
 }
Exemplo n.º 2
0
function relative2absolute ($string, $directory) {
	if (path_is_relative($string)) {
		return simplify_path(addslash($directory) . $string);
	} else {
		return simplify_path($string);
	}
}
Exemplo n.º 3
0
Arquivo: data.php Projeto: RiJo/m3uer
function parse_playlist($root, $playlist)
{
    $playlist_file_info = get_file_info($playlist);
    $contents = "";
    if (filesize($playlist_file_info['path']) > 0) {
        $handle = @fopen($playlist_file_info['path'], 'r') or die("Error: could not open file '{$playlist_file_info['path']}' for reading");
        $contents = fread($handle, filesize($playlist_file_info['path']));
        fclose($handle);
    }
    $result = array(KEY_CONTENTS => array(), KEY_VALID => array(), KEY_INVALID => array(), KEY_COMMENT => array());
    $comments = array();
    foreach (explode(LINE_BREAK, $contents) as $line) {
        $line = trim($line);
        if (strlen($line) > 0) {
            if ($line[0] == COMMENT_SYMBOL) {
                array_push($result[KEY_CONTENTS], array('type' => KEY_COMMENT, 'content' => trim(substr($line, 1))));
                array_push($result[KEY_COMMENT], trim(substr($line, 1)));
            } else {
                $file_path = realpath($line);
                if (strlen($file_path) == 0) {
                    // Check if path is relative
                    $file_path = simplify_path($playlist_file_info['dirname'] . DIRECTORY_SEPARATOR . $line);
                }
                if (file_exists($file_path)) {
                    array_push($result[KEY_CONTENTS], array('type' => KEY_VALID, 'content' => $line));
                    array_push($result[KEY_VALID], $file_path);
                } else {
                    array_push($result[KEY_CONTENTS], array('type' => KEY_INVALID, 'content' => $line));
                    array_push($result[KEY_INVALID], $file_path);
                }
            }
        }
    }
    return $result;
}
Exemplo n.º 4
0
    }
    echo "<br>";
    $test_number++;
}
echo "<br><b>simplify_path()</b><br>";
test(simplify_path("/foo/bar/baz"), "/foo/bar/baz");
test(simplify_path("./foo/bar/baz"), "foo/bar/baz");
test(simplify_path("../foo/bar/baz"), "../foo/bar/baz");
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), "../..");