-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathinitialize.php
50 lines (46 loc) · 1.93 KB
/
initialize.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
<?php
/* Don't change the codes below: */
$GLOBALS["NEST"] = empty($GLOBALS["ASEQ"])?0:preg_match_all("/(?<=\S|\s)\.(?=\S|\s)/",$ASEQ)+1;
if(!isset($GLOBALS["HOST"])){
$GLOBALS["HOST"] = (isset($_SERVER['HTTPS'])?"https://":"http://");
if($NEST > 0){
if(preg_match("/(\d+\.)+$/",$_SERVER["HTTP_HOST"]))
$host_parts = explode(".", strtolower(trim($_SERVER["HTTP_HOST"])));
elseif(preg_match("/localhost$/", $_SERVER["HTTP_HOST"]))
$host_parts = [...explode(".", strtolower(trim($_SERVER["HTTP_HOST"]))), ""];
else $host_parts = explode(".", strtolower(trim($_SERVER["HTTP_HOST"])));
$hpc = count($host_parts);
$GLOBALS["HOST"] .= $host_parts[$hpc-(1+$NEST)];
for ($i = $NEST; $i > 0; $i--) $GLOBALS["HOST"] .= ".".$host_parts[$hpc-$i];
}
else $GLOBALS["HOST"] .= strtolower(trim($_SERVER["HTTP_HOST"]));
}
$directory = __DIR__.DIRECTORY_SEPARATOR;
$GLOBALS["BASE_ROOT"] = $GLOBALS["HOST"]."/".$GLOBALS["BASE"]."/";
$GLOBALS["BASE_DIR"] = $directory;
for ($i = $NEST; $i > 0; $i--) $GLOBALS["BASE_DIR"] .= "..".DIRECTORY_SEPARATOR;
$GLOBALS["BASE_DIR"] .= $GLOBALS["BASE"].DIRECTORY_SEPARATOR;
/* Convert sub domains to sub directories */
$aseq = $GLOBALS["NEST"]>0?preg_replace("/(?<=\S|\s)\.(?=\S|\s)/", "/", $GLOBALS["ASEQ"])."/":"";
if(isset($GLOBALS["DIR"])) $GLOBALS["SEQUENCES"][$directory] = $GLOBALS["HOST"]."/".$aseq;
else {
$GLOBALS["ASEQBASE"] = $GLOBALS["ASEQ"];
$GLOBALS["SEQUENCES"] = array();
$GLOBALS["ROOT"] = $GLOBALS["HOST"]."/".$aseq;
$GLOBALS["DIR"] = $directory;
}
/* Filter the sequences */
if(count($GLOBALS["SEQUENCES_PATCH"]) > 0){
$sequences = $GLOBALS["SEQUENCES"];
foreach($GLOBALS["SEQUENCES_PATCH"] as $newdir=>$newaseq) {
$notFind = true;
foreach($sequences as $dir => $aseq)
if($newdir === $dir) {
$notFind = false;
if(empty($newaseq)) unset($GLOBALS["SEQUENCES"][$newdir]);
else $GLOBALS["SEQUENCES"][$newdir] = $newaseq;
}
if($notFind) $GLOBALS["SEQUENCES"][$newdir] = $newaseq;
}
}
?>