Newer
Older
<?php
// Display execution time?
//$displaytime = TRUE;
// start the clock (this is just temporary cause I'm interested in how long all this takes)
if (@$displaytime) {
$time = microtime();
$time = explode(' ', $time);
$time = $time[1] + $time[0];
$begintime = $time;
}
/* --------------------------------------------------------
Settings
-------------------------------------------------------- */
include("settings.php");
if (!(isset($base) && isset($preferred_hostname) && isset($dbname))) {
echo "Website unconfigured";
exit();
}
/* --------------------------------------------------------
Libraries
-------------------------------------------------------- */
// Include our custom error handling business
require("../lib/error.php");
// Include the Smarty templating engine
define('SMARTY_DIR', '/usr/share/php/smarty/libs/');
require("/usr/share/php/smarty/libs/Smarty.class.php");
$smarty = new Smarty;
$smarty->template_dir = $base."templates";
$smarty->compile_dir = $base."templates_c";
$smarty->plugins_dir[] = $base."plugins";
$smarty->assign("baseurl", $baseurl);
// Initialise the database
require("/usr/share/php/adodb/adodb.inc.php");
$DB->Connect('dbname='.$dbname.' user=dez');
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
$DB->SetFetchMode(ADODB_FETCH_ASSOC);
// Include the session library
require($base."lib/session.php");
$session = new Session;
$smarty->assign_by_ref("session", $session);
/* --------------------------------------------------------
Debugging
-------------------------------------------------------- */
// Turn on adodb debugging by uncommenting:
//$DB->debug = true;
// Turn on Smarty debugging by uncommenting:
//$smarty->assign("debug",TRUE);
// Should we display unexpected output from components?
$compdebug = TRUE;
/* --------------------------------------------------------
Read Browser's settings
-------------------------------------------------------- */
// Determine the language to serve pages in
$languagelist = explode(',', @$_SERVER['HTTP_ACCEPT_LANGUAGE']);
$language = array();
$language['code'] = "en";
/*
The following is hideously unscientific, but works for now. What really needs
to happen is the list get searched to see if cy is higher priority than en
*/
if ($languagelist[0]=="cy") $language['code'] = "cy";
$language['file'] = ".".$language['code'];
$language['db'] = "_".$language['code'];
if ($language['code']=="en") {
$language['file'] = "";
$language['db'] = "";
}
$smarty->assign("language", $language);
// SSL?
$ssl_path = @$_SERVER['REQUEST_URI'];
if (($n=strpos($ssl_path,"?"))!==FALSE) $ssl_path=substr($ssl_path,0,$n);
$ssl_url = "https://".$preferred_hostname.$ssl_path;
$smarty->assign("ssl_url", $ssl_url);
// Determine which component to run
$pathlist = explode('/', parse_url(@$_SERVER['ORIG_PATH_INFO'],PHP_URL_PATH));
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
137
138
139
140
141
142
143
144
145
146
while (end($pathlist) === "") array_pop($pathlist);
$smarty->assign_by_ref("pathlist", $pathlist);
$path = '';
$query = "select * from pagemap where path='/' ";
foreach($pathlist as $item) {
if ($item && $item != '/') {
$query .= "or path = '".addslashes($path)."/*' ";
$path .= "/$item";
$query .= "or path = '".addslashes($path)."' ";
}
}
// Determine the path of the request
$smarty->assign_by_ref("path", $path);
$query .= "order by depth desc";
$pagemap = $DB->GetAll($query);
//echo $query;
if (!$pagemap) $smarty->assign("error", $DB->ErrorMsg());
if (!$pagemap || count($pagemap)<1) {
$smarty->assign("component", "Default");
$component = "";
} else {
$smarty->assign("component", $pagemap[0]['component']);
$component = $pagemap[0];
}
if ($path == "") $path="/";
// Prep values for the components to use
$smarty->assign("title", "Set Me");
$smarty->assign("body", "Empty Body");
// Load the component
$comppath = $base."components/".$component['component'].".php";
$compoutput = "";
if (file_exists($comppath)) {
ob_start();
include($comppath);
$compoutput = ob_get_contents();
ob_end_clean();
} else {
$smarty->assign("body", "Component ".$component['component']." not found");
}
// Pass error/warning/info messages to the template
$smarty->assign("user_messages", $messages);
include($base."components/menu.php");
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
// Render the results
if (!(isset($no_template)) || (!$no_template)) {
// Send appropriate Content-Type
if (ereg('application/xhtml\+xml', @$_SERVER['HTTP_ACCEPT'])) {
header('Content-Type: application/xhtml+xml');
echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
} else {
header('Content-Type: text/html');
}
$smarty->display("head.tpl");
$smarty->display("index.tpl");
if ($compdebug) {
$smarty->assign("compoutput",$compoutput);
$smarty->display("debug.tpl");
}
// Last chance to stop the clock and still end up with valid HTML
if (@$displaytime) {
$time = microtime();
$time = explode(" ", $time);
$time = $time[1] + $time[0];
$endtime = $time;
$totaltime = ($endtime - $begintime);
$smarty->assign("totaltime", $totaltime);
}
$smarty->display("foot".$language['file'].".tpl");
} else {
echo $compoutput;
}
// Save any changes made to the session data
$session->save();
?>