-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathitself.php
151 lines (133 loc) · 4.14 KB
/
itself.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
<?
require_once "object/object.class.php";
require_once "loader/loader.class.php";
require_once "scope/scope.class.php";
require_once "factory/factory.class.php";
require_once "factory/class/class.class.php";
define('OXYGEN_JSON_RESONSE',1);
define('OXYGEN_JSONP_RESPONSE',6);
define('OXYGEN_TEXT_RESONSE',2);
define('OXYGEN_HTML_RESONSE',3);
define('OXYGEN_XML_RESPONSE',4);
define('OXYGEN_REDIRECT_RESPONSE',5);
function o($tag = 'div', $data=array()) {
if(is_array($tag)) {
$data = $tag;
$tag = 'div';
}
if($tag{0}=='/'){
Oxygen::close();
} else {
Oxygen::open($tag, $data);
}
}
function rpcResponse($error,$data, $callback) {
$error = $error ? $error->getMessage() : null;
$resp = json_encode(array(
'data'=>$data,
'error'=>$error
));
return array(
'header' => 'Content-Type: text/javascript; Charset=UTF-8',
'type' => OXYGEN_JSONP_RESPONSE,
'body' => $callback.'('. $resp . ')'
);
}
function jsonResponse($data, $headers = array()) {
return array(
'header' => 'Content-Type: application/json; Charset=UTF-8',
'type' => OXYGEN_JSON_RESONSE,
'body' => $data
);
}
function htmlResponse($data) {
return array(
'header' =>'Content-Type: text/html; Charset=UTF-8',
'type' => OXYGEN_HTML_RESONSE,
'body' => $data
);
}
function xmlResponse($data) {
return array(
'header' => 'Content-Type: application/xml; Charset=UTF-8',
'type' => OXYGEN_XML_RESONSE,
'body' => $data
);
}
function textResponse($data) {
return array(
'header' => 'Content-Type: text/plain; Charset=UTF-8',
'type' => OXYGEN_TEXT_RESONSE,
'data' => $data
);
}
function redirectResponse($data) {
return array(
'header' => 'Location:' . $data,
'type' => OXYGEN_REDIRECT_RESPONSE,
'data' => false
);
}
function registerOxygenCommons($scope) {
$array = array(
'LogonPage' => 'Oxygen_Common_LogonPage',
'Authenticator' => 'Oxygen_Common_Authenticator',
'Application' => 'Oxygen_Common_Application',
'Page' => 'Oxygen_Common_Page'
);
foreach($array as $name => $class) {
$scope->register($name, $class);
}
}
function handleHttpRequest($scope, $root, $model = false, $debug = true) {
$scope->__setEnvironment(array(
'SERVER' => $_SERVER,
'REQUEST' => $_REQUEST,
'ENV' => $_ENV,
'COOKIE' => $_COOKIE,
'POST' => $_POST,
'GET' => $_GET,
'FILES' => $_FILES,
'SESSION' => $scope->Session()
));
try {
if ($scope->assets->handled($scope->OXYGEN_PATH_INFO)) exit;
registerOxygenCommons($scope);
$userScope = $scope->Scope();
$root = $userScope->$root($model);
$scope->httpStatus = 200;
$scope->httpHeaders = array();
$root->setPath($scope->OXYGEN_ROOT_URI);
$last = $root[$scope->OXYGEN_PATH_INFO];
$result = $last->handleRequest();
if (is_string($result)) {
if($result === '') $result=$scope->SERVER['REQUEST_URI'];
$result = redirectResponse($result);
}
header($result['header']);
foreach($scope->httpHeaders as $h) {
header($h);
}
if(isset($result['body'])) {
$body = $result['body'];
if($body) {
if(is_string($body)) echo $body;
else call_user_func($body);
}
}
} catch(Exception $ex) {
if ($debug) {
try {
$scope->__wrapException($ex)->put_page_view();
} catch(Exception $ex) {
echo $ex->getMessage();
print_r($ex);
}
} else {
header('HTTP/1.0 500 OxygenError');
echo $ex->getMessage();
}
}
}
return Oxygen_Scope::newRoot(dirname(dirname(__FILE__)));
?>