include "inc/debug.inc";
include "inc/db.inc";
include "config.inc";
include "kalki.inc";
include "menu.inc";
include "inc/parse/array.inc";
//drawArray($GLOBALS);
//define("DEBUG",1);
//while(list($a,$b) = each($GLOBALS))
// echo $a.":".$b."
";
//drawaRRAY($GLOBALS);
$nhost = substr($HTTP_GET_VARS["host"],0,-1-strlen($addhost));
$url = array("host" => $nhost,
"path" => $GLOBALS["arg"]);
if((substr($url["path"],0,1) == "/") && (substr($url["path"],0,2) != "//")) {
// $url["path"] = "/".$url["path"];
$url["path"] = substr($url["path"],1);
} else {
$url["path"] = substr($url["path"],2);
}
//$url["path"] = "/".$url["path"];
//drawArray($url,0);
$active = true;
if(strpos($GLOBALS["arg"],"NACTIVE") > 0)
$active = false;
$nurl = "";
if(!is_array(($row = getData($url["host"],$url["path"])))) {
if(!is_array(($row = getData($url["host"],"error/404".$url["path"]))))
$row = getData("poelzi.org","error/404");
$row["options"] = @substr($url["path"],strpos($url["path"],"//")+2);
} else {
$nurl = $row["path"];
}
//echo $row["options"];
//$lang = $row["lang"];
if(strlen($row["options"]) == "2" || substr($row["options"],2,1) == "/") {
$lang = substr($row["options"],0,2);
}
$langs = getLangs();
if($lang == "") {
//echo substr($GLOBALS["HTTP_ACCEPT_LANGUAGE"],0,strpos($GLOBALS["HTTP_ACCEPT_LANGUAGE"],";"));
$al = explode(",",substr($GLOBALS["HTTP_ACCEPT_LANGUAGE"],0,strpos($GLOBALS["HTTP_ACCEPT_LANGUAGE"],";")));
while(list(,$n) = each($al)) {
if(isset($langs[$n])) {
$lang = $n;
break;
}
}
}
$ot = explode("/",$row["options"]);
$intree = false;
while(list($i,$co) = each($ot)) {
// set language
if($i == 0 && strlen($co) == 2) {
$language = $co;
} else {
switch($co) {
case "debug":
if(!defined("DEBUG"))
define("DEBUG",1);
break;
case "empire":
$menuroot = 2;
$menustart = 8;
$tree = "empire";
$intree = true;
break;
case "era":
$menuroot = 3;
$menustart = 12;
$tree = "era";
$intree = true;
break;
default:
if($intree) {
$tree .= "/".$co;
}
}
}
}
function handleLink($string) {
global $addhost,$active;
if(defined("DEBUG"))
echo "handleLink:".$string."
\r\n";
if($GLOBALS["HTTPS"] == "on")
$result = "https://";
else
$result = "http://";
$tags = explode(";",$string);
$nlang = "";
$ndebug = "";
$ntree = "";
if(count($tags) == 1) {
switch($tags[0]) {
case "runtime":
return substr(getRuntime(),0,6);
case "sizeinfo":
return strlen($GLOBALS["kalki"]->getData("main"))."/".strlen($GLOBALS["result"]);
default:
$row = getStructureItem($tags[0]);
if($row == false)
return "";
$tags[0] = $row["host"];
$tags[1] = $row["path"];
if($row["tree"] != "")
$tags[2] = "tree=".$row["tree"];
}
}
while(list($number,$value) = each($tags)) {
switch($number) {
case "0":
$port = "";
if(($GLOBALS["SERVER_PORT"] != "80") && ($GLOBALS["SERVER_PORT"] != "443"))
$port = ":".$GLOBALS["SERVER_PORT"];
if($value != "")
$result .= $value.".".$addhost.$port;
else
$result .= $addhost.$port;
break;
case "1":
if(substr($value,0,1) == "/")
$result .= $value."/";
elseif($value != "")
$result .= "/".$value."/";
else
$result .= "/";
break;
// handle options
default:
if(strpos($value,"=") === false) {
$na = $value;
} else {
$na = substr($value,0,strpos($value,"="));
$va = substr($value,strlen($na)+1);
}
switch($na) {
case "lang":
$nlang = $va;
break;
case "debug":
$ndebug = "debug";
break;
case "active":
$nactive = $va;
case "tree":
$ntree = $va;
break;
}
}
}
// add
//if(($nlang != "")||($GLOBALS["lang"] != "")) {
if(substr($result,-2) != "//")
$result .= "/";
//}
if(($nlang == "") && ($GLOBALS["lang"] != ""))
$result .= $GLOBALS["lang"]."/";
elseif($nlang != "")
$result .= $nlang."/";
if(($ndebug == "debug") || defined("DEBUG"))
$result .= "debug/";
if(($nactive == "true") || ($GLOBALS["active"] == false))
$result .= "NACTIVE/";
if(($ntree == "") && ($GLOBALS["tree"] != ""))
$result .= $GLOBALS["tree"];
elseif($ntree != "")
$result .= $ntree;
// $result = preg_replace("/^(.*)(\/*)$/U","\\1",$result);
if(substr($result,-2) == "//")
$result = substr($result,0,-1);
if(substr($result,-1) != "/")
$result .= '/';
// echo $result;
return $result;
}
if(defined("DEBUG"))
drawArray($row);
$eof = "";
for($i = 0; $i < 10; $i++)
$eof .= str_repeat ("a".$i, 5);
function theader($header) {
if($header != "")
header($header);
}
if($row["header"] != "") {
preg_replace("/(.*)((\015\012)|(\015)|(\012))/e","theader('\\1')",$row["header"]);
}
$kalki = new kalkitemplate;
if($row["schema"] != "" && file_exists("layout/".$row["schema"].".kt")) {
$kalki->loadTemplate("layout/".$row["schema"].".kt");
} else {
$kalki->loadTemplate("layout/index.kt");
}
// set date
if($row["date"] == 0)
$date = time();
else
$date = $row["date"];
switch($row["type"]) {
case "R":
header("Location: ".handleLink(stripslashes($row["text"])));
echo '