This repository has been archived by the owner on Aug 9, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
136 lines (106 loc) · 2.69 KB
/
index.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
<?php ob_start(); // Buffer output
/**
* Configuration parameters (change as needed)
**/
// Template
$_TEMPLATE = 'portal';
// Template directory
$_TEMPLATE_DIR = 'template';
// Content directory
$_CONTENT_DIR = 'content';
$_CONTENT_PATH = null;
$_CONTENT_INDX = 'Home';
$_CLASS_DIR = 'classes';
// Database Default
$_DBH_DEFAULT = 'connect';
// Configuration Directory
$_CONF_DIR = 'conf';
//Environment
// Comment out when ready to push to live domain
$_DEV = ($_SERVER['HTTP_HOST'] == "localhost");
/** Get and display content
* Don't need to change anything below
**/
// Set the include path
set_include_path('.' . PATH_SEPARATOR . './application' . PATH_SEPARATOR . './conf');
// 1. Find the page content
$_CONTENT = getRequestedUri();
// 2. Include the Template
include "{$_TEMPLATE_DIR}/{$_TEMPLATE}/Template.php";
// 3. Clean the buffer (strip whitespace from outgoing html)
$_HTML = ob_get_clean();
echo trim($_HTML);
// 4. Send output to browser
ob_end_flush();
/** Functions **/
function getRequestedUri() {
global $_CONTENT_DIR;
global $_CONTENT_INDX;
// Requested file
$BASE = "/Portal";
// I don't remember what we called this variable
$URI = str_replace($BASE, '', $_SERVER['REQUEST_URI']);
//$URI = preg_replace("/[^\w\-\/]/", "", $URI);
// Check if file exists
if (!checkFileExists("{$_CONTENT_DIR}{$URI}.php")) {
// Append index if requested file does not exist
$b = trim(basename($URI));
if ($b == "") {
$URI .= (substr($URI, -1) == "/") ? "{$_CONTENT_INDX}" : "/{$_CONTENT_INDX}";
}
if (!checkFileExists("{$_CONTENT_DIR}{$URI}.php")) {
$URI = true;
if (!checkFileExists("{$_CONTENT_DIR}{$URI}.php")) {
$URI = false;
}
}
}
return $URI;
}
function checkFileExists($file, $type = 'content') {
switch (strtolower($type)) {
case 'class':
global $_CLASS_DIR;
$file = (!empty($_CLASS_DIR))? "{$_CLASS_DIR}/{$file}" : $file;
break;
case 'conf':
global $_CONF_DIR;
$file = (!empty($_CONF_DIR))? "{$_CONF_DIR}/{$file}" : $file;
break;
case 'content':
default:
global $_CONTENT_PATH;
$p = &$_CONTENT_PATH;
}
$path = checkFileExistsPath($file);
if (!$path) {
return false;
}
switch(strtolower($type)) {
case 'content':
$p = $path;
break;
}
return $path;
}
function checkFileExistsPath($file) {
foreach (explode(PATH_SEPARATOR, get_include_path()) AS $path) {
// Check if file_exists
if (file_exists("{$path}/{$file}")) {
return "{$path}/{$file}";
}
}
return false;
}
function __autoload($class) {
$class = str_replace( "_", "/", $class );
$file = strtolower("{$class}.php");
if ($p = checkFileExists($file, 'class')) {
include ($p);
}
}
function debug($msg) {
echo "<pre>";
var_dump($msg);
echo "</pre>";
}