forked from shannah/xataface
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinit.php
More file actions
145 lines (132 loc) · 6.49 KB
/
init.php
File metadata and controls
145 lines (132 loc) · 6.49 KB
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
<?php
/*-------------------------------------------------------------------------------
* Xataface Web Application Framework
* Copyright (C) 2005-2008 Web Lite Solutions Corp (shannah@sfu.ca)
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*-------------------------------------------------------------------------------
*/
function init($site_path, $dataface_url){
$originalUrl = isset($_SERVER['HTTP_X_ORIGINAL_URL']) ? parse_url($_SERVER['HTTP_X_ORIGINAL_URL']) : null;
if ($originalUrl) {
$host = @$originalUrl["host"];
$port = @$originalUrl["port"];
$protocol = $originalUrl["scheme"];
if (!$port) {
if ($protocol == 'https') {
$port = 443;
} else {
$port = 80;
}
}
$_SERVER['QUERY_STRING'] = @$originalUrl["query"];
$_SERVER['REQUEST_URI'] = @$originalUrl["path"];
$_SERVER['PHP_SELF'] = @$originalUrl['path'];
if (@$originalUrl["query"]) {
$_SERVER['REQUEST_URI'] .= '?' . $originalUrl['query'];
}
if (strpos($dataface_url, 'http:') === 0 or strpos($dataface_url, 'https:') === 0) {
// We leave dataface_url alone
} else {
if ($dataface_url{0} !== '/') {
$dataface_url = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')) . '/' . $dataface_url;
}
}
} else {
// first we resolve some differences between CGI and Module php
if ( !isset( $_SERVER['QUERY_STRING'] ) ){
$_SERVER['QUERY_STRING'] = @$_ENV['QUERY_STRING'];
}
// define a HOST_URI variable to contain the host portion of all urls
$host = $_SERVER['HTTP_HOST'];
if (isset($_SERVER['HTTP_X_FORWARDED_HOST'])) {
$host = $_SERVER['HTTP_X_FORWARDED_HOST'];
}
$port = $_SERVER['SERVER_PORT'];
if (isset($_SERVER['HTTP_X_FORWARDED_PORT'])) {
$port = intval($_SERVER['HTTP_X_FORWARDED_PORT']);
}
$protocol = $_SERVER['SERVER_PROTOCOL'];
if ( strtolower($protocol) == 'included' ){
$protocol = 'HTTP/1.0';
}
$protocol = substr( $protocol, 0, strpos($protocol, '/'));
$protocol = ((@$_SERVER['HTTPS'] == 'on' || "$port" == "443") ? $protocol.'s' : $protocol );
$protocol = strtolower($protocol);
if (isset($_SERVER['HTTP_X_FORWARDED_PROTO'])) {
$protocol = $_SERVER['HTTP_X_FORWARDED_PROTO'];
if ($protocol == 'https' and "$port" == "80") {
$port = 443;
} else if ($protocol == 'http' and "$port" == "443") {
$port = 80;
}
}
if (isset($_SERVER['HTTP_X_FORWARDED_PATH'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['HTTP_X_FORWARDED_PATH'];
if (strpos($_SERVER['REQUEST_URI'], '?') === false and @$_SERVER['QUERY_STRING']) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
$_SERVER['PHP_SELF'] = $_SERVER['HTTP_X_FORWARDED_PATH'];
if (strpos($dataface_url, 'http:') === 0 or strpos($dataface_url, 'https:') === 0) {
// We leave dataface_url alone
} else {
if ($dataface_url{0} !== '/') {
$dataface_url = substr($_SERVER['PHP_SELF'], 0, strrpos($_SERVER['PHP_SELF'], '/')) . '/' . $dataface_url;
}
}
}
}
$_SERVER['HOST_URI'] = $protocol.'://'.$host;//.($port != 80 ? ':'.$port : '');
if ( (strpos($host, ':') === false) and !($protocol == 'https' and "$port" == "443" ) and !($protocol == 'http' and "$port" == "80") ){
$_SERVER['HOST_URI'] .= ':'.$port;
}
if (defined('DATAFACE_SITE_PATH')){
trigger_error("Error in ".__FILE__."
DATAFACE_SITE_PATH previously defined when trying to initialize the site."/*.Dataface_Error::printStackTrace()*/, E_USER_ERROR);
}
if (defined('DATAFACE_URL')){
trigger_error("Error in ".__FILE__."
DATAFACE_URL previously defined when trying to initialize the site."/*.Dataface_Error::printStackTrace()*/, E_USER_ERROR);
}
define('DATAFACE_SITE_PATH', str_replace('\\','/', dirname($site_path)));
if (!@$_SERVER['PHP_SELF'] and @$_SERVER['SCRIPT_NAME']){
$_SERVER['PHP_SELF'] = $_SERVER['SCRIPT_NAME'];
}
$temp_site_url = dirname($_SERVER['PHP_SELF']);
if ( $temp_site_url{strlen($temp_site_url)-1} == '/'){
$temp_site_url = substr($temp_site_url,0, strlen($temp_site_url)-1);
}
define('DATAFACE_SITE_URL', str_replace('\\','/',$temp_site_url));
define('DATAFACE_SITE_HREF', (DATAFACE_SITE_URL != '/' ? DATAFACE_SITE_URL.'/':'/').basename($_SERVER['PHP_SELF']) );
if ( !preg_match('#^https?://#', $dataface_url) and $dataface_url and $dataface_url{0} != '/' ){
$dataface_url = DATAFACE_SITE_URL.'/'.$dataface_url;
}
define('DATAFACE_URL', str_replace('\\','/',$dataface_url));
require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'config.inc.php');
if ( @$_GET['-action'] == 'js' ){
include dirname(__FILE__).DIRECTORY_SEPARATOR.'js.php';
}
if ( @$_GET['-action'] == 'css' ){
include dirname(__FILE__).DIRECTORY_SEPARATOR.'css.php';
}
if ( !is_writable(DATAFACE_SITE_PATH.DIRECTORY_SEPARATOR.'templates_c') ){
die(
sprintf(
'As of Xataface 1.3 all applications are now required to have its own templates_c directory to house its compiled templates. Please create the directory "%s" and ensure that it is writable by the web server.',
DATAFACE_SITE_PATH.DIRECTORY_SEPARATOR.'templates_c'
)
);
}
}