function cacheurl($url, $browser_req = true, $cookies = "", $browser = "Firefox")
{
    global $myconfig;
    #find cache file
    $hash = md5($url);
    $datei = "cache/" . $hash;
    if (file_exists($datei)) {
        if (time() - filemtime($datei) < $myconfig['cachetime']) {
            return implode('', file($datei));
        }
    }
    #no cache file exists send browser request
    if ($browser_req == true) {
        $objekt = new Browser($browser);
        if ($cookies != "") {
            $objekt->cookies_set($cookies);
        }
        $objekt->url = $url;
        $t_html = $objekt->read();
    } else {
        $t_html = implode('', file($url));
    }
    d_write($datei, $t_html);
    return $t_html;
}
function getdir()
{
    global $UpdURL, $faketxt, $faketxtDL, $links;
    $r = split("/", trim($_GET['dir'], "/"));
    if (count($r) == 2) {
        $retArray = $links;
    }
    if (count($r) == 3) {
        $UpdURL = $links[$r[2]]['url'];
        $retArray = input($UpdURL);
    }
    if (count($r) == 4) {
        $retArray = $faketxt;
    }
    if (count($r) == 5) {
        $UpdURL = $links[$r[2]]['url'];
        $scripts = input($UpdURL);
        $scriptUrl = $scripts[$r[3]][url];
        $scriptName = $scripts[$r[3]][name];
        $down = cacheurl($scriptUrl);
        $sFunction = $r[4];
        switch ($sFunction) {
            case "Download":
                d_write("scripts/" . urldecode($scriptName), $down);
                $retArray = $faketxtDL;
                break;
            case "Info":
                preg_match('|<info>(.*?)</info>|si', $down, $row);
                $infoText = $row[1];
                $retArray = showText($infoText);
                break;
            case "Changelog":
                preg_match('|<changelog>(.*?)</changelog>|si', $down, $row);
                $infoText = $row[1];
                $retArray = showText($infoText);
                break;
            default:
                break;
        }
    }
    return gennavi($retArray);
}
function geturl($pfad)
{
    global $links, $search, $orderby, $seite;
    $r = explode("/", trim($pfad, "/"));
    #youtube suche
    if (count($r) == 6) {
        $index = $seite[$r[4]]['nr'] * 50 + 1;
        $ur = str_replace("%string%", urlencode($links[$r[2]]['suche']), $search);
        $ur = str_replace("%orderby%", $orderby[$r[3]]['api'], $ur);
        $ur = str_replace("%index%", $index, $ur);
        #youtube api: search video within the specified time
        #we only need this_week and this_month
        $ur = preg_match('/month|week/i', $r[3], $match) ? str_replace('%time%', '&time=this_' . strtolower($match[0]), $ur) : ($ur = str_replace('%time%', '', $ur));
        $ar = input($ur, implode("/", $r));
        d_write("fav/" . md5(implode("/", $r)), " ");
        $key = $r[5];
        if (!isset($ar[$key])) {
            $key = substr($key, 1);
        }
        return dlflv($ar[$key]['url']);
    }
    #Standardlinks
    $in = input($links[$r[2]]['url']);
    $t = stripslashes($r[3]);
    return dlflv($in[$t]['url']);
}
function geturl($pfad)
{
    global $links, $search, $orderby, $seite;
    $r = explode("/", trim($pfad, "/"));
    #youtube suche
    if (count($r) == 6) {
        $index = $seite[$r[4]]['nr'];
        $ur = str_replace("%string%", urlencode($links[$r[2]]['suche']), $search);
        $ur = str_replace("%orderby%", $orderby[$r[3]]['api'], $ur);
        $ur = str_replace("%index%", $index, $ur);
        $ar = input($ur);
        d_write("fav/" . md5(implode("/", $r)), " ");
        $key = $r[5];
        if (!isset($ar[$key])) {
            $key = substr($key, 1);
        }
        return dlflv($ar[$key]['url']);
    }
    #Standardlinks
    $in = input($links[$r[2]]['url']);
    $t = stripslashes($r[3]);
    return dlflv($in[$t]['url']);
}