예제 #1
0
function process_and_get_image($ori, $path, $baseurl, $space_deli, $cookie)
{
    $para["path"] = $path;
    $para["base"] = $baseurl;
    $para["trans"] = !$space_deli;
    $para["cookie"] = $cookie;
    if ($space_deli) {
        $reg = "/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\' >]*)[^>]*>/si";
    } else {
        $reg = "/< *im[a]?g[^>]*src *= *[\"\\']?([^\"\\'>]*)[^>]*>/si";
    }
    return preg_replace_callback($reg, function ($matches) use($para) {
        global $config, $crawled;
        $url = trim($matches[1]);
        if (stripos($url, "http://") === false && stripos($url, "https://") === false) {
            if ($para["trans"]) {
                $url = str_replace(" ", "%20", $url);
            }
            $url = $para["base"] . $url;
        }
        $url = normalizeURL($url);
        if ($crawled[$url]) {
            return $result;
        }
        $crawled[$url] = true;
        $name = basename($url);
        $name = "images/" . $para["path"] . "/" . strtr($name, ":", "_");
        $result = str_replace(trim($matches[1]), $name, $matches[0]);
        if (file_exists($config["base_local_path"] . $name)) {
            return $result;
        }
        mkdirs($config["base_local_path"] . $name);
        //echo $url;
        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $url);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        if ($para["cookie"] != "") {
            curl_setopt($ch, CURLOPT_COOKIEFILE, $para["cookie"]);
        }
        curl_setopt($ch, CURLOPT_HEADER, 0);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
        $content = curl_exec($ch);
        curl_close($ch);
        //echo $content;
        $fp = fopen($config["base_local_path"] . $name, "wb");
        fwrite($fp, $content);
        fclose($fp);
        return $result;
    }, $ori);
}
예제 #2
0
    $lang = $bests->getType();
    return $info->{$lang};
}
if (isset($_GET['u']) && !empty($_GET['u'])) {
    $url = urldecode($_GET['u']);
    $url = normalizeURL($url);
    if ($url) {
        $info = getUrlInfo($url);
        $new_url = getProperLink($url, $info);
        header('Location: ' . $new_url);
        exit;
    }
} else {
    if (isset($_GET['t']) && !empty($_GET['t'])) {
        $url = urldecode($_GET['t']);
        $url = normalizeURL($url);
        if ($url != null) {
            echo sprintf("http://%s/?u=%s", $_SERVER['HTTP_HOST'], urlencode($url));
        }
        exit;
    }
}
?>
<html>
	<head>
		<title>Wikipedia Link Translator</title>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1">

		<script type="application/javascript" src="https://code.jquery.com/jquery-2.1.4.min.js"></script>
		<script type="application/javascript">