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
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
|
<?php
/**
* @package kernel
* @subpackage functions
*/
/**
* required setup
*/
namespace Bitweaver;
require_once BIT_ROOT_PATH.'kernel/includes/autoload.php';
// include the bitweaver configuration file - this needs to happen first
$config_file = empty( $_SERVER['CONFIG_INC'] ) ? BIT_ROOT_PATH.'config/kernel/config_inc.php' : $_SERVER['CONFIG_INC'];
if( file_exists( $config_file ) ) {
include_once $config_file;
}
// when running scripts
global $gShellScript;
if( !empty( $gShellScript ) ) {
$siteName = 'localhost';
// keep notices quiet
$serverDefaults = [
'DOCUMENT_ROOT' => dirname( dirname( dirname( __FILE__ ) ) ),
'HTTP_HOST' => $siteName,
'HTTP_SERVER_VARS' => '',
'HTTP_USER_AGENT' => 'cron',
'REMOTE_ADDR' => $siteName,
'REQUEST_METHOD' => 'GET',
'REQUEST_URI' => __FILE__,
'REQUEST_URL' => __FILE__,
'SCRIPT_URI' => $_SERVER['SCRIPT_FILENAME'],
'SCRIPT_URL' => $_SERVER['SCRIPT_NAME'],
'SERVER_ADDR' => $siteName,
'SERVER_ADMIN' => 'support@'.$siteName,
'SERVER_NAME' => '',
'SERVER_PROTOCOL' => 'http',
];
foreach( $serverDefaults as $key=>$value ) {
if( empty( $_SERVER[$key] ) ) {
$_SERVER[$key] = $value;
}
}
// Process some global arguments
global $gArgs, $argv;
$gArgs = [];
if( $argv ) {
foreach( $argv AS $arg ) {
$argKey = $arg;
if( strpos( $arg, '--' ) === 0 ) {
$argKey = substr( $arg, 2 );
}
$argValue = true;
if( strpos( $arg, '=' ) ) {
$argKey = substr( $arg, 2, strpos( $arg, '=' )-2 );
$argValue = substr( $arg, strpos( $arg, '=' ) +1);
}
switch( $argKey ) {
case 'debug':
$gDebug = $argValue;
break;
}
$gArgs[$argKey] = $argValue;
$_REQUEST[$argKey] = $argValue;
}
}
}
// =================== Essential Defines ===================
// These defines can be set in config/kernel/config_inc.php. If they haven't been set, we set default values here
// database settings
if( !defined( 'BIT_DB_PREFIX' ) ) {
define( 'BIT_DB_PREFIX', '' );
}
if( !defined( 'BIT_CACHE_OBJECTS' ) ) {
define( 'BIT_CACHE_OBJECTS', false );
}
if( !defined( 'BIT_QUERY_CACHE_TIME' ) ) {
define( 'BIT_QUERY_CACHE_TIME', 86400 );
}
// default theme after installation
if( !defined( 'DEFAULT_THEME' ) ) {
define( 'DEFAULT_THEME', 'basic' );
}
if( !defined( 'DISPLAY_ERRORS' ) ) {
define( 'DISPLAY_ERRORS', 0 );
}
// name of session variable in browser cookie - deprecated, replaced by site specific name
//if( !defined( 'BIT_SESSION_NAME' ) ) {//
// define( 'BIT_SESSION_NAME', 'BWSESSION'); // '__Secure-BWSESSION' );
//}
// define where errors are sent
if( !defined( 'BIT_PHP_ERROR_REPORTING' ) ) {
define( 'BIT_PHP_ERROR_REPORTING', E_ALL & ~E_NOTICE & ~E_WARNING );
}
// don't change / set _IDs unless you know exactly what you are doing
if( !defined( 'ROOT_USER_ID' ) ) {
define( 'ROOT_USER_ID', 1 );
}
if( !defined( 'ANONYMOUS_USER_ID' ) ) {
define( 'ANONYMOUS_USER_ID', -1 );
}
if( !defined( 'EVIL_EXTENSION_PATTERN' )) {
define( 'EVIL_EXTENSION_PATTERN', "#\.(htaccess|pl|php|php3|php4|phtml|py|cgi|asp|jsp|sh|shtml)$#i" );
}
if( !defined( 'ANONYMOUS_TEAM_ID' ) ) {
define( 'ANONYMOUS_TEAM_ID', -1 );
}
// Uncomment the following line if you require attachment and file id's to match the content id
// This is used to simplify content mamagment where fisheye and treasury content is used internally
define( 'LINKED_ATTACHMENTS', true );
// Empty SCRIPT_NAME and incorrect SCRIPT_NAME due to php-cgiwrap - wolff_borg
if( empty( $_SERVER['SCRIPT_NAME'] ) ) {
$_SERVER['SCRIPT_NAME'] = $_SERVER['SCRIPT_URL'];
}
// BIT_ROOT_URL should be set as soon as the system is installed. until then we
// need to make sure we have the correct value, otherwise installations won't
// work. The recent changes have caused problems during installation. i'll try
// combining both methods by applying the less successful one after the more
// successful one - xing
if( !defined( 'BIT_ROOT_URL' ) ) {
// version one which seems to only cause problems seldomly
preg_match( '/.*'.basename( dirname( dirname( __FILE__ ) ) ).'\//', $_SERVER['SCRIPT_NAME'], $match );
$subpath = !empty($match[0] ) ? $match[0] : '/';
// version two which doesn't work well on it's own
if( $subpath == "/" ) {
$subpath = dirname( dirname( $_SERVER['SCRIPT_NAME'] ) );
$subpath .= ( substr( $subpath,-1,1 )!='/' ) ? '/' : '';
}
$subpath = str_replace( '//', '/', str_replace( "\\", '/', $subpath ) ); // do some de-windows-ification
define( 'BIT_ROOT_URL', $subpath );
}
// If BIT_ROOT_URI hasn't been set yet, we'll try to get one from the super global $_SERVER.
// This works with apache - not sure about other servers.
if( !defined( 'BIT_BASE_URI' )) {
// Added check for IIS $_SERVER['HTTPS'] uses 'off' value - wolff_borg
define( 'BIT_BASE_URI', 'http'.((!empty($_SERVER['HTTPS'])&&$_SERVER['HTTPS'] != 'off')?'s':'').'://'.(empty($_SERVER['HTTP_HOST'])?'localhost':$_SERVER['HTTP_HOST']) );
}
if( !defined( 'BIT_ROOT_URI' )) {
// Added check for IIS $_SERVER['HTTPS'] uses 'off' value - wolff_borg
define( 'BIT_ROOT_URI', BIT_BASE_URI.BIT_ROOT_URL );
}
// custom storage host
if( !defined( 'STORAGE_BASE_URI' ) ) {
define( 'STORAGE_BASE_URI', BIT_BASE_URI );
}
// custom storage host
if( !defined( 'STORAGE_HOST_URI' ) ) {
define( 'STORAGE_HOST_URI', BIT_ROOT_URI );
}
if( substr_count( $_SERVER['HTTP_HOST'], '.' ) >= 2 ) {
define( 'BIT_BASE_HOST', substr( $_SERVER['HTTP_HOST'], strpos( $_SERVER['HTTP_HOST'], '.') + 1 ) );
} else {
define( 'BIT_BASE_HOST', $_SERVER['HTTP_HOST'] );
}
// set the currect version of bitweaver
// if this version of bitweaver needs a visit to the installer, update the number in /bit_setup_inc.php
if( !defined( 'BIT_MAJOR_VERSION' ) ) {
define( 'BIT_MAJOR_VERSION', '5' );
define( 'BIT_MINOR_VERSION', '0' );
define( 'BIT_SUB_VERSION', '0' );
define( 'BIT_LEVEL', 'dev' ); // dev < alpha < beta < RC# < '' < pl
}
// When updating to certain versions of bitweaver, we need to force a visit to the installer to fix certain stuff in the database.
// Enter the minimum version number here in the format: '2.1.0-beta'
if( !defined( 'MIN_BIT_VERSION' ) ) {
define( 'MIN_BIT_VERSION', '5.0.1' );
}
if( !defined( 'BITWEAVER_VERSION' ) ) {
define( 'BITWEAVER_VERSION', '5.0.1' );
}
// These defines have to happen FIRST because core classes depend on them.
// This means these packages *CANNOT* be renamed
define( 'INSTALL_PKG_PATH', BIT_ROOT_PATH.'install/' );
define( 'INSTALL_PKG_URL', BIT_ROOT_URL.'install/' );
define( 'KERNEL_PKG_DIR', 'kernel' );
define( 'KERNEL_PKG_NAME', 'kernel' );
define( 'KERNEL_PKG_PATH', BIT_ROOT_PATH.'kernel/' );
define( 'KERNEL_PKG_URL', BIT_ROOT_URL.KERNEL_PKG_DIR.'/' );
define( 'KERNEL_PKG_INCLUDE_PATH', KERNEL_PKG_PATH.'includes/' );
define( 'KERNEL_PKG_CLASS_PATH', KERNEL_PKG_INCLUDE_PATH.'classes/' );
define( 'KERNEL_PKG_ADMIN_PATH', KERNEL_PKG_PATH.'admin/' );
define( 'CONFIG_PKG_PATH', BIT_ROOT_PATH.'config/' );
define( 'CONFIG_PKG_URL', BIT_ROOT_URL.'config/' );
define( 'CONFIG_PKG_INCLUDE_PATH', CONFIG_PKG_PATH.'includes/' );
define( 'CONFIG_PKG_CLASS_PATH', CONFIG_PKG_INCLUDE_PATH.'classes/' );
define( 'CONFIG_PKG_ADMIN_PATH', CONFIG_PKG_PATH.'admin/' );
define( 'LANGUAGES_PKG_PATH', BIT_ROOT_PATH.'languages/' );
define( 'LANGUAGES_PKG_INCLUDE_PATH', LANGUAGES_PKG_PATH.'includes/' );
define( 'LANGUAGES_PKG_CLASS_PATH', LANGUAGES_PKG_INCLUDE_PATH.'classes/' );
define( 'LANGUAGES_PKG_ADMIN_PATH', LANGUAGES_PKG_PATH.'admin/' );
define( 'LIBERTY_PKG_DIR', 'liberty' );
define( 'LIBERTY_PKG_NAME', 'liberty' );
define( 'LIBERTY_PKG_PATH', BIT_ROOT_PATH.'liberty/' );
define( 'LIBERTY_PKG_INCLUDE_PATH', LIBERTY_PKG_PATH.'includes/' );
define( 'LIBERTY_PKG_CLASS_PATH', LIBERTY_PKG_INCLUDE_PATH.'classes/' );
define( 'LIBERTY_PKG_ADMIN_PATH', LIBERTY_PKG_PATH.'admin/' );
if( !defined( 'STORAGE_PKG_NAME' ) ) {
define( 'STORAGE_PKG_NAME', 'storage' );
}
if( !defined( 'STORAGE_PKG_PATH' ) ) {
define( 'STORAGE_PKG_PATH', BIT_ROOT_PATH.'storage/' );
}
if( !defined( 'STORAGE_PKG_URL' ) ) {
define( 'STORAGE_PKG_URL', BIT_ROOT_URL.'storage/' );
}
if( !defined( 'STORAGE_PKG_INCLUDE_PATH' ) ) {
define( 'STORAGE_PKG_INCLUDE_PATH', STORAGE_PKG_PATH.'includes/' );
}
if( !defined( 'STORAGE_PKG_CLASS_PATH' ) ) {
define( 'STORAGE_PKG_CLASS_PATH', STORAGE_PKG_INCLUDE_PATH.'classes/' );
}
if( !defined( 'STORAGE_PKG_ADMIN_PATH' ) ) {
define( 'STORAGE_PKG_ADMIN_PATH', STORAGE_PKG_PATH.'admin/' );
}
define( 'THEMES_PKG_PATH', BIT_ROOT_PATH.'themes/' );
define( 'THEMES_PKG_INCLUDE_PATH', THEMES_PKG_PATH.'includes/' );
define( 'THEMES_PKG_CLASS_PATH', THEMES_PKG_INCLUDE_PATH.'classes/' );
define( 'THEMES_PKG_ADMIN_PATH', THEMES_PKG_PATH.'admin/' );
define( 'USERS_PKG_PATH', BIT_ROOT_PATH.'users/' );
define( 'USERS_PKG_INCLUDE_PATH', USERS_PKG_PATH.'includes/' );
define( 'USERS_PKG_CLASS_PATH', USERS_PKG_INCLUDE_PATH.'classes/' );
define( 'USERS_PKG_ADMIN_PATH', USERS_PKG_PATH.'admin/' );
define( 'UTIL_PKG_PATH', BIT_ROOT_PATH.'util/' );
define( 'UTIL_PKG_INCLUDE_PATH', BIT_ROOT_PATH.'util/includes/' );
define( 'UTIL_PKG_CLASS_PATH', UTIL_PKG_INCLUDE_PATH.'classes/' );
define( 'UTIL_PKG_ADMIN_PATH', UTIL_PKG_PATH.'admin/' );
if( !defined( 'EXTERNAL_LIBS_PATH' ) ) {
define( 'EXTERNAL_LIBS_PATH', BIT_ROOT_PATH.'externals/' );
}
if( !defined( 'TEMP_PKG_PATH' ) ) {
define( 'TEMP_PKG_PATH', sys_get_temp_dir().'/php/'.$_SERVER['HTTP_HOST'] .'/');
if( !file_exists( TEMP_PKG_PATH ) ) {
mkdir( TEMP_PKG_PATH, 2775, true );
}
}
// =================== Global Variables ===================
// If for any reason this isn't set, nothing will work - nada, zilch...
if( empty( $gBitDbHost ) ) {
$gBitDbHost = 'localhost';
}
// If you want to go a step further with template debugging then this enables
// smarty's debugging console. A popup with a dump of all of the vars the
// template(s) have been passed.
$smarty_debugging = false;
// $gPreScan can be used to specify the order in which packages are scanned by
// the kernel. In the example provided below, the kernel package is processed
// first, followed by the users and liberty packages. Any packages not
// specified in $gPreScan are processed in the traditional order
global $gPreScan;
if( empty( $gPreScan ) ) {
$gPreScan = [ 'config', 'kernel', 'storage', 'liberty', 'themes', 'users' ];
}
// here we set the default thumbsizes we use in bitweaver.
// order matters since successively smaller thumbs are used from the preceding thumb for speed increase.
// you can override these by populating this hash in your config/kernel/config_inc.php
global $gThumbSizes;
if( empty( $gThumbSizes )) {
$gThumbSizes = [
'large' => [ 'width' => 1200, 'height' => 900 ],
'medium' => [ 'width' => 800, 'height' => 600 ],
'small' => [ 'width' => 400, 'height' => 300 ],
'avatar' => [ 'width' => 200, 'height' => 150 ],
'icon' => [ 'width' => 100, 'height' => 100 ],
];
}
function kernel_autoload( $className ) {
$prefix = 'Bitweaver\\';
$base_dir = __DIR__ . '/classes/';
$len = strlen($prefix);
if (strncmp($prefix, $className, $len) !== 0) {
return;
}
$relative_class = substr($className, $len);
$file = "$base_dir$relative_class.php";
if (file_exists($file)) {
require $file;
}
}
|