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
|
<?php
define('E_DEFAULT', error_reporting(E_ALL|E_STRICT));
require_once('../shared/include/includes.php');
require_once('include/error_handling.php');
register_shutdown_function('onshutdown', realpath('include/footer.php'), realpath('include/header.php')); // Needed to ensure that errors are printed
require_once('include/setup.php');
if (get_magic_quotes_gpc()) r_stripslashes($_REQUEST);
$routing=fopen('routing.csv', 'r');
for ($line=fgets($routing, 32768); !feof($routing); $line=fgets($routing, 32768)) {
$line=trim($line, "\r\n");
if (substr($line, 0, 1) == '#' || strlen($line) == 0) {
continue;
}
$line=explode("\t", $line, 3);
if (count($line) < 2) {
continue;
} elseif (count($line) == 2) {
list($expr, $dest)=$line;
$vars=array();
} else {
list($expr, $dest, $vars)=$line;
$vars=explode("\t", $vars);
}
unset($line);
if (preg_match('{^'.$expr.'$}',$S['request'],$matches)) {
fclose($routing);
for ($i=0; $i < count($vars); $i++) {
if (strpos($vars[$i],'=')) {
$_REQUEST[substr($vars[$i],0,strpos($vars[$i],'='))]=substr($vars[$i],strpos($vars[$i],'=')+1);
} else {
if ($i+1 > count($matches)-1) {
debug('routing',print_error('Routing failure','Trying to set request variable "'.$vars[$i].'" but ran out of matches (page='.$dest.')'));
} else {
$_REQUEST[$vars[$i]]=$matches[$i+1];
}
}
}
while ($dest != null) {
debug('routing','Routing to '.$dest);
if (!is_file('pages/'.$dest.'.php')) {
throw_exception('Routing to '.$dest.' but pages/'.$dest.'.php doesn\'t exist.');
}
require_once('pages/'.$dest.'.php');
$dest=str_replace(array('/', '-'), '_', $dest);
$initfunc='init_'.$dest;
if (function_exists($initfunc)) {
$value=$initfunc($S);
if ($value === null) {
break;
} elseif (is_array($value)) {
if (isset($value['dest'])) {
$dest=$value['dest'];
unset($value['dest']);
$S=array_merge($S, $value);
} else {
$S=array_merge($S, $value);
break;
}
} else {
$dest=$value;
}
} else {
debug('routing','No init function for '.$dest.'... continuing to body');
break;
// require_once('include/header.php');
// die(print_error('Routing Failure', 'Init function undefined for '.$dest.'.'));
}
}
if (!$S['notemplates']) {
require_once('include/header.php');
}
$bodyfunc='body_'.str_replace('/','_',$dest);
if (function_exists($bodyfunc)) {
$bodyresult=$bodyfunc($S);
if ($bodyresult !== null) {
require($bodyresult);
}
} else {
if ($S['notemplates']) {
debug('Routing', 'Body function missing for page '.$dest);
} else {
die(print_error('Routing failure', 'Body function missing for page '.$dest));
}
}
die;
}
}
die(print_error('Routing Failure', 'You should never see this message. Please contact an administrator.'));
?>
|