-
Notifications
You must be signed in to change notification settings - Fork 7
/
include.php
78 lines (61 loc) · 1.62 KB
/
include.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<?
//set this to true if you want the site on
$PASS = TRUE;
$FILE_LEN = 6;
$languages = array(
array("lang"=>"c", "val"=>'C', "mime"=>'text/x-csrc'),
array("lang"=>"cpp", "val"=>'C++', "mime"=>'text/x-c++src'),
//"java" => "Java",
//"asm" => "Assembly (x86)",
);
function get_code($str){
switch($str){
case "c":
return 0;
case "cpp":
return 1;
# case "java":
# return 2;
case "asm":
return 3;
default:
return -1;
}
}
function uid($length = 16){
$characters = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
$randomString = '';
for ($i = 0; $i < $length; $i++) {
$randomString .= $characters[rand(0, strlen($characters) - 1)];
}
return $randomString;
}
//returns a relative path to the sample/ directory, without trailing slash
function basePath() {
$commonPath = __FILE__;
$requestPath = $_SERVER['SCRIPT_FILENAME'];
//count the number of slashes
// number of .. needed for include level is numslashes(request) - numslashes(common)
// then add one more to get to base
$commonSlashes = substr_count($commonPath, '/');
$requestSlashes = substr_count($requestPath, '/');
$numParent = $requestSlashes - $commonSlashes + 1;
$basePath = ".";
for($i = 0; $i < $numParent-1; $i++) {
$basePath .= "/..";
}
return $basePath;
}
function get_page($page, $args = array()) {
//let pages use some variables
extract($args);
$basePath = basePath();
$page_include = $basePath . "/views/$page.php";
include("header.php");
include($page_include);
include("footer.php");
}
function base_url() {
return "http://".$_SERVER['SERVER_NAME']."/sample";
}
?>