-
Notifications
You must be signed in to change notification settings - Fork 1
/
variables.php
210 lines (190 loc) · 6.66 KB
/
variables.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
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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
<?php
/*
+---------------------------------------------------------------------------+
| Revive Adserver |
| http://www.revive-adserver.com |
| |
| Copyright: See the COPYRIGHT.txt file. |
| License: GPLv2 or later, see the LICENSE.txt file. |
+---------------------------------------------------------------------------+
*/
/**
* @package OpenX
* @author Chris Nutting <[email protected]>
* @author Andrew Hill <[email protected]>
* @author Radek Maciaszek <[email protected]>
*
* A file to set up the environment for the delivery engine.
*
* Both opcode and PHP by itself slow things down when we require many
* files. Therefore maintainability has been sacrificed in order to
* speed up a delivery:
* - We are not using classes (if possible) in delivery;
* - We have as few as possible includes and add new code into
* existing files.
*/
/**
* Setup common variables - used by both delivery and admin part as well
*
* This function should be executed after the config file is read in.
*
* The reason behind using GLOBAL variables is that
* there are faster than constants
*/
function setupConfigVariables()
{
$GLOBALS['_MAX']['MAX_DELIVERY_MULTIPLE_DELIMITER'] = '|';
$GLOBALS['_MAX']['MAX_COOKIELESS_PREFIX'] = '__';
$GLOBALS['_MAX']['thread_id'] = uniqid();
// Set a flag if this request was made over an SSL connection (used more for delivery rather than UI)
$GLOBALS['_MAX']['SSL_REQUEST'] = false;
if (
(!empty($_SERVER['SERVER_PORT']) && !empty($GLOBALS['_MAX']['CONF']['openads']['sslPort']) && ($_SERVER['SERVER_PORT'] == $GLOBALS['_MAX']['CONF']['openads']['sslPort'])) ||
(!empty($_SERVER['HTTPS']) && ((strtolower($_SERVER['HTTPS']) == 'on') || ($_SERVER['HTTPS'] == 1))) ||
(!empty($_SERVER['HTTP_X_FORWARDED_PROTO']) && (strtolower($_SERVER['HTTP_X_FORWARDED_PROTO']) == 'https')) ||
(!empty($_SERVER['HTTP_X_FORWARDED_SSL']) && (strtolower($_SERVER['HTTP_X_FORWARDED_SSL']) == 'on')) ||
(!empty($_SERVER['HTTP_FRONT_END_HTTPS']) && (strtolower($_SERVER['HTTP_FRONT_END_HTTPS']) == 'on')) ||
(!empty($_SERVER['FRONT-END-HTTPS']) && (strtolower($_SERVER['FRONT-END-HTTPS']) == 'on'))
) {
// This request should be treated as if it was received over an SSL connection
$GLOBALS['_MAX']['SSL_REQUEST'] = true;
}
// Maximum random number (use default if doesn't exist - eg the case when application is upgraded)
$GLOBALS['_MAX']['MAX_RAND'] = isset($GLOBALS['_MAX']['CONF']['priority']['randmax']) ?
$GLOBALS['_MAX']['CONF']['priority']['randmax'] : 2147483647;
list($micro_seconds, $seconds) = explode(" ", microtime());
$GLOBALS['_MAX']['NOW_ms'] = round(1000 *((float)$micro_seconds + (float)$seconds));
// Always use UTC when outside the installer
if (substr($_SERVER['SCRIPT_NAME'], -11) != 'install.php') {
// Save server timezone for auto-maintenance
$GLOBALS['serverTimezone'] = date_default_timezone_get();
OA_setTimeZoneUTC();
}
}
/**
* A function to initialize $_SERVER variables which could be missing
* on some environments
*
*/
function setupServerVariables()
{
// PHP-CGI/IIS combination does not set REQUEST_URI
if (empty($_SERVER['REQUEST_URI'])) {
$_SERVER['REQUEST_URI'] = $_SERVER['SCRIPT_NAME'];
if (!empty($_SERVER['QUERY_STRING'])) {
$_SERVER['REQUEST_URI'] .= '?' . $_SERVER['QUERY_STRING'];
}
}
}
/**
* A function to initialize the environmental constants and global
* variables required by delivery.
*/
function setupDeliveryConfigVariables()
{
if (!defined('MAX_PATH')) {
define('MAX_PATH', dirname(__FILE__));
}
if (!defined('OX_PATH')) {
define('OX_PATH', MAX_PATH);
}
if (!defined('RV_PATH')) {
define('RV_PATH', MAX_PATH);
}
if (!defined('LIB_PATH')) {
define('LIB_PATH', MAX_PATH. DIRECTORY_SEPARATOR. 'lib'. DIRECTORY_SEPARATOR. 'OX');
}
// Ensure that the initialisation has not been run before
if ( !(isset($GLOBALS['_MAX']['CONF']))) {
// Parse the Max configuration file
$GLOBALS['_MAX']['CONF'] = parseDeliveryIniFile();
}
// Set up the common configuration variables
setupConfigVariables();
}
/**
* Set a timezone
*
* @param string $timezone
*/
function OA_setTimeZone($timezone)
{
// Set the new time zone
date_default_timezone_set($timezone);
// Set PEAR::Date_TimeZone default as well
//
// Ideally this should be a Date_TimeZone::setDefault() call, but for optimization
// purposes, we just override the global variable
$GLOBALS['_DATE_TIMEZONE_DEFAULT'] = $timezone;
}
/**
* Set the current default timezone to UTC
*
* @see OA_setTimeZone()
*/
function OA_setTimeZoneUTC()
{
OA_setTimeZone('UTC');
}
/**
* Set the current default timezone to local
*
* @see OA_setTimeZone()
*/
function OA_setTimeZoneLocal()
{
$tz = !empty($GLOBALS['_MAX']['PREF']['timezone']) ? $GLOBALS['_MAX']['PREF']['timezone'] : 'UTC';
OA_setTimeZone($tz);
}
/**
* Returns the hostname the script is running under.
*
* @return string containing the hostname (with port number stripped).
*/
function OX_getHostName()
{
if (!empty($_SERVER['HTTP_HOST'])) {
$host = explode(':', $_SERVER['HTTP_HOST']);
$host = $host[0];
} else if (!empty($_SERVER['SERVER_NAME'])) {
$host = explode(':', $_SERVER['SERVER_NAME']);
$host = $host[0];
}
return $host;
}
/**
* Returns the hostname (with port) the script is running under.
*
* @return string containing the hostname with port
*/
function OX_getHostNameWithPort()
{
if (!empty($_SERVER['HTTP_HOST'])) {
$host = $_SERVER['HTTP_HOST'];
} else if (!empty($_SERVER['SERVER_NAME'])) {
$host = $_SERVER['SERVER_NAME'];
}
return $host;
}
/**
* A function to define the PEAR include path in a separate method,
* as it is required by delivery only in exceptional circumstances.
*/
function setupIncludePath()
{
static $checkIfAlreadySet;
if (isset($checkIfAlreadySet)) {
return;
}
$checkIfAlreadySet = true;
$oxPearPath = MAX_PATH . DIRECTORY_SEPARATOR . 'lib' . DIRECTORY_SEPARATOR . 'pear';
$oxZendPath = MAX_PATH . DIRECTORY_SEPARATOR . 'lib';
set_include_path($oxPearPath . PATH_SEPARATOR . $oxZendPath . PATH_SEPARATOR . get_include_path());
}
/**
* @return \Psr\Container\ContainerInterface
*/
function RV_getContainer()
{
return $GLOBALS['_MAX']['DI'];
}