include("config.php");
include("func.php");
$FullUrl = $HTTP_SERVER_VARS["QUERY_STRING"];
if (empty($FullUrl)) {
$FullUrl= $URL.$MainPage;
// echo $FullUrl; exit;
}
if (empty($Language)) {
$Language = $DefaultLanguage;
}
if ($Language=="big5") {
header("Location: $FullUrl");
exit;
}
if (!strstr($FullUrl, $URL)) {
header("Location: $FullUrl");
// echo "Sorry, We do not relay. Any questions mail to: Web Admin.";
exit;
}
if (strstr($FullUrl, ".PNG")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, ".png")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, ".GIF")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, ".gif")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, ".JPG")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, ".jpg")) {
ReadImage($FullUrl);
exit;
}
if (strstr($FullUrl, "cgi")) {
include("$FullUrl");
exit;
}
if (strstr($FullUrl, ".zip")) {
header("Location: $FullUrl");
exit;
}
$Page = fopen($FullUrl, "r");
$BIG5Src = fread($Page, 65535);
$BIG5 = str_replace("¡@"," ", $BIG5Src);
$StrLenTmp = strlen($FullUrl);
// echo $FullUrl;
// echo $StrLenTmp; exit;
$URLLayerTmp = substr($FullUrl, 7-$StrLenTmp);
$URLLayer = explode("/", $URLLayerTmp);
// for ($i = 0; $i < count($URLLayer); $i++) {
// echo "$i:$URLLayer[$i]
";
// }
# Layer 1 = "./"
$Layer[1] = "http://";
for ($j = 0; $j < count($URLLayer) - 1; $j++) {
$Layer[1].=$URLLayer[$j]."/";
}
// echo $Layer[1];
# Layer 2 = "../"
$Layer[2] = "http://";
for ($j = 0; $j < count($URLLayer) - 2; $j++) {
$Layer[2].=$URLLayer[$j]."/";
}
//echo $Layer[2];
# Layer 3 = "../../"
$Layer[3] = "http://";
for ($j = 0; $j < count($URLLayer) - 3; $j++) {
$Layer[3].=$URLLayer[$j]."/";
}
//echo $Layer[3];
$BIG5 = str_replace("SRC=\"","SRC=\"".$ServerScriptURL."?".$Layer[1],$BIG5);
$BIG5 = str_replace("src=\"","src=\"".$ServerScriptURL."?".$Layer[1],$BIG5);
$BIG5 = str_replace("../",$ServerScriptURL."?".$Layer[2],$BIG5);
$BIG5 = str_replace("./",$ServerScriptURL."?".$Layer[1],$BIG5);
$BIG5 = str_replace("href=\"","href=\"$ServerScriptURL"."?$URL/",$BIG5);
$BIG5 = str_replace("HREF=\"","href=\"$ServerScriptURL"."?$URL/",$BIG5);
# mailto:
$BIG5 = str_replace("href=\"$ServerScriptURL"."?$URL/"."mailto:","href=\"mailto:",$BIG5);
$BIG5 = str_replace("HREF=\"$ServerScriptURL"."?$URL/"."mailto:","href=\"mailto:",$BIG5);
# news:
$BIG5 = str_replace("href=\"$ServerScriptURL"."?$URL/"."news:","href=\"news:",$BIG5);
$BIG5 = str_replace("HREF=\"$ServerScriptURL"."?$URL/"."news:","href=\"news:",$BIG5);
# javascript
$BIG5 = str_replace("href=\"$ServerScriptURL"."?$URL/"."javascript:","href=\"javascript:",$BIG5);
$BIG5 = str_replace("HREF=\"$ServerScriptURL"."?$URL/"."javascript:","href=\"javascript:",$BIG5);
$BIG5 = str_replace("images/",$URL."/images/",$BIG5);
$BIG5 = str_replace("charset=big5","charset=gb2312",$BIG5);
$BIG5 = str_replace($URL."/http://","http://", $BIG5);
$BIG5 = str_replace($Layer[1].$ServerScriptURL,$ServerScriptURL, $BIG5);
# Special process
$BIG5 = str_replace($ServerScriptURL."?".$ServerScriptURL."?".$ServerScriptURL, $ServerScriptURL, $BIG5);
$BIG5 = str_replace($ServerScriptURL."?".$ServerScriptURL, $ServerScriptURL, $BIG5);
$BIG5 = str_replace("action=\"$ServerScriptURL?","action=\"",$BIG5);
$BIG5 = str_replace("http://www.tango.idv.tw/study-area/", $ServerScriptURL2, $BIG5);
$BIG5 = str_replace($ServerScriptURL2."todo/","http://www.tango.idv.tw/study-area/todo/",$BIG5);
$BIG5 = str_replace($ServerScriptURL."?".$ServerScriptURL2, $ServerScriptURL2, $BIG5);
fclose($Page);
echo big52gb($BIG5);
?>