Update versioninfo.php
[iDB.git] / sql.php
blob841fa51a979e712b9f70d9a3f0e178aed2da0e37
1 <?php
2 /*
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the Revised BSD License.
6 This program is distributed in the hope that it will be useful,
7 but WITHOUT ANY WARRANTY; without even the implied warranty of
8 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
9 Revised BSD License for more details.
11 Copyright 2004-2024 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2024 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: sql.php - Last Update: 8/26/2024 SVN 1048 - Author: cooldude2k $
16 /* Some ini setting changes uncomment if you need them.
17 Display PHP Errors */
18 $disfunc = @ini_get("disable_functions");
19 $disfunc = @trim($disfunc);
20 $disfunc = @preg_replace("/([\\s+|\\t+|\\n+|\\r+|\\0+|\\x0B+])/i", "", $disfunc);
21 if($disfunc!="ini_set") { $disfunc = explode(",",$disfunc); }
22 if($disfunc=="ini_set") { $disfunc = array("ini_set"); }
23 if(!in_array("ini_set", $disfunc)) {
24 @ini_set("html_errors", false);
25 @ini_set("track_errors", false);
26 @ini_set("display_errors", false);
27 @ini_set("report_memleaks", false);
28 @ini_set("display_startup_errors", false);
29 //@ini_set("error_log","logs/error.log");
30 //@ini_set("log_errors","On");
31 @ini_set("docref_ext", "");
32 @ini_set("docref_root", "http://php.net/"); }
33 if(!defined("E_DEPRECATED")) { define("E_DEPRECATED", 0); }
34 @error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED);
35 /* Get rid of session id in urls */
36 if(!in_array("ini_set", $disfunc)) {
37 @ini_set("default_mimetype","text/html");
38 @ini_set("zlib.output_compression", false);
39 @ini_set("zlib.output_compression_level", -1);
40 @ini_set("session.use_trans_sid", false);
41 @ini_set("session.use_cookies", true);
42 @ini_set("session.use_only_cookies", true);
43 @ini_set("url_rewriter.tags","");
44 @ini_set('zend.ze1_compatibility_mode', 0);
45 @ini_set("ignore_user_abort", 1); }
46 @set_time_limit(30); @ignore_user_abort(true);
47 /* Change session garbage collection settings */
48 if(!in_array("ini_set", $disfunc)) {
49 @ini_set("session.gc_probability", 1);
50 @ini_set("session.gc_divisor", 100);
51 @ini_set("session.gc_maxlifetime", 1440);
52 /* Change session hash type here */
53 @ini_set("session.hash_function", 1);
54 @ini_set("session.hash_bits_per_character", 6); }
55 /* Do not change anything below this line unless you know what you are doing */
56 $File3Name = basename($_SERVER['SCRIPT_NAME']);
57 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
58 header('Location: index.php');
59 exit(); }
60 if(file_exists('settings.php')) {
61 require_once('settings.php');
62 if(file_exists('extrasettings.php')) {
63 require_once('extrasettings.php'); }
64 if(file_exists('extendsettings.php')) {
65 require_once('extendsettings.php'); }
66 // Custom error handler for non-fatal errors
67 // Configuration settings
68 $errorDisplay = true; // Set to true to display errors on the screen
69 $errorLogFile = true; // Set to true to log errors to a file
70 $logFilePath = $SettDir['maindir'] . $SettDir['logs'] . '/php_error_log.txt'; // Define your log file path
72 // Custom Error Handler Function
73 function customErrorHandler($errno, $errstr, $errfile, $errline) {
74 global $errorDisplay, $errorLogFile, $logFilePath;
76 // List of error types we want to handle
77 $errorTypes = [
78 E_ERROR => 'Fatal Error',
79 E_WARNING => 'Warning',
80 E_PARSE => 'Parse Error',
81 E_NOTICE => 'Notice',
82 E_CORE_ERROR => 'Core Error',
83 E_CORE_WARNING => 'Core Warning',
84 E_COMPILE_ERROR => 'Compile Error',
85 E_COMPILE_WARNING => 'Compile Warning',
86 E_USER_ERROR => 'User Error',
87 E_USER_WARNING => 'User Warning',
88 E_USER_NOTICE => 'User Notice',
89 E_STRICT => 'Strict Notice',
90 E_RECOVERABLE_ERROR => 'Recoverable Error',
91 E_DEPRECATED => 'Deprecated Notice',
92 E_USER_DEPRECATED => 'User Deprecated Notice'
95 // Safely retrieve and clean the output buffer
96 $output = '';
97 if (ob_get_length()) {
98 $output = ob_get_clean(); // Get and clear the buffer without sending it
101 // Check if the error type is in our list of handled types
102 $errorType = isset($errorTypes[$errno]) ? $errorTypes[$errno] : 'Unknown Error';
104 // Prepare the error message
105 $errorMessage = "<b>{$errorType}:</b> [$errno] $errstr - $errfile:$errline<br>";
107 // Get the backtrace
108 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
109 $backtraceMessage = getBacktraceAsString($backtrace);
111 // Display the error if enabled
112 if ($errorDisplay) {
113 echo $errorMessage;
114 echo "<b>Backtrace:</b><br>";
115 echo $backtraceMessage;
118 // Log the error to a file if enabled
119 if ($errorLogFile) {
120 logErrorToFile($logFilePath, $errorType, $errno, $errstr, $errfile, $errline, $backtrace);
123 // Output the captured content again if needed
124 echo $output;
126 // Depending on the error, you might want to stop the script
127 if ($errno === E_ERROR || $errno === E_PARSE || $errno === E_CORE_ERROR || $errno === E_COMPILE_ERROR) {
128 die();
131 // Return true to prevent the PHP internal error handler from executing
132 return true;
135 // Custom Shutdown Handler Function
136 function shutdownHandler() {
137 global $errorDisplay, $errorLogFile, $logFilePath;
139 $last_error = error_get_last();
141 // Check if $last_error is not null before accessing its elements
142 if ($last_error !== null) {
143 // Check if the error type is E_ERROR or E_PARSE (fatal errors)
144 if ($last_error['type'] === E_ERROR || $last_error['type'] === E_PARSE || $last_error['type'] === E_CORE_ERROR || $last_error['type'] === E_COMPILE_ERROR) {
146 // Safely retrieve and clean the output buffer
147 $output = '';
148 if (ob_get_length()) {
149 $output = ob_get_clean(); // Get and clear the buffer without sending it
152 // Prepare the error message
153 $errorMessage = "<b>Fatal Error:</b> {$last_error['message']} - {$last_error['file']}:{$last_error['line']}<br>";
155 // Get the backtrace
156 $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
157 $backtraceMessage = getBacktraceAsString($backtrace);
159 // Display the error if enabled
160 if ($errorDisplay) {
161 echo $errorMessage;
162 echo "<b>Backtrace:</b><br>";
163 echo $backtraceMessage;
166 // Log the error to a file if enabled
167 if ($errorLogFile) {
168 logErrorToFile($logFilePath, 'Fatal Error', $last_error['type'], $last_error['message'], $last_error['file'], $last_error['line'], $backtrace);
171 // Output the captured content again if needed
172 echo $output;
177 // Custom Exception Handler Function
178 // Custom Exception Handler Function
179 function customExceptionHandler($exception) {
180 global $errorDisplay, $errorLogFile, $logFilePath;
182 // Safely retrieve and clean the output buffer
183 $output = '';
184 if (ob_get_length()) {
185 $output = ob_get_clean(); // Get and clear the buffer without sending it
188 // Prepare the uncaught exception message
189 $errorMessage = "<b>Uncaught Exception:</b> " . $exception->getMessage() . " in " . $exception->getFile() . " on line " . $exception->getLine() . "<br>";
191 // Get the backtrace from the exception
192 $backtrace = $exception->getTrace();
193 $backtraceMessage = getBacktraceAsString($backtrace);
195 // Display the exception if enabled
196 if ($errorDisplay) {
197 echo $errorMessage;
198 echo "<b>Backtrace:</b><br>";
199 echo $backtraceMessage;
202 // Log the exception to a file if enabled
203 if ($errorLogFile) {
204 logErrorToFile($logFilePath, 'Uncaught Exception', 0, $exception->getMessage(), $exception->getFile(), $exception->getLine(), $backtrace);
207 // Output the captured content again if needed
208 echo $output;
210 // Stop the script after an uncaught exception
211 die();
214 // Function to Convert Backtrace Array to String for Display/Logging
215 function getBacktraceAsString($backtrace) {
216 $backtraceMessage = "";
217 foreach ($backtrace as $trace) {
218 if (isset($trace['file'])) {
219 $backtraceMessage .= "Called in <b>{$trace['file']}</b> on line <b>{$trace['line']}</b>";
220 if (isset($trace['function'])) {
221 $backtraceMessage .= " (function <b>{$trace['function']}</b>)";
223 $backtraceMessage .= "<br>";
226 return $backtraceMessage;
229 // Function to Log Errors to a File
230 function logErrorToFile($logFile, $errorType, $errno, $errstr, $errfile, $errline, $backtrace) {
231 $logMessage = "[" . date('Y-m-d H:i:s') . "] {$errorType}: [{$errno}] {$errstr} in {$errfile} on line {$errline}\n";
233 // Append backtrace to the log
234 foreach ($backtrace as $trace) {
235 if (isset($trace['file'])) {
236 $logMessage .= "Called in {$trace['file']} on line {$trace['line']}";
237 if (isset($trace['function'])) {
238 $logMessage .= " (function {$trace['function']})";
240 $logMessage .= "\n";
244 // Append to the log file
245 file_put_contents($logFile, $logMessage, FILE_APPEND);
248 // Set the custom error handler
249 set_error_handler("customErrorHandler");
251 // Register the shutdown function to catch fatal errors
252 register_shutdown_function('shutdownHandler');
254 // Set exception handler to catch uncaught exceptions
255 set_exception_handler('customExceptionHandler');
257 if(isset($Settings['qstr'])&&isset($Settings['qstr'])) {
258 if(!in_array("ini_set", $disfunc)&&$Settings['qstr']!="/"&&$Settings['qstr']!="&") {
259 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
260 ini_set("arg_separator.input",$Settings['qstr']); } } }
261 if(!isset($Settings['idburl'])) { $Settings['idburl'] = null; }
262 if(isset($Settings['BoardUUID'])) { $Settings['BoardUUID'] = base64_decode($Settings['BoardUUID']);
263 header("Board-Unique-ID: ".$Settings['BoardUUID']); }
264 function unparse_url($parsed_url) {
265 $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
266 $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
267 $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
268 $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
269 $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
270 $pass = ($user || $pass) ? "$pass@" : '';
271 $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
272 $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
273 $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
274 return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
276 $OrgBoardURL = $Settings['idburl'];
277 if(isset($Settings['idburl'])) {
278 $PreBestURL = parse_url($Settings['idburl']); }
279 $PreServURL = parse_url((isset($_SERVER['HTTPS']) ? "https" : "http") . "://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
280 if(isset($PreBestURL['host'])&&$PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
281 $PreBestURL['host'] = "localhost";
282 $PreBestURL['path'] = $PreServURL['path'];
283 $Settings['idburl'] = unparse_url($PreBestURL); }
284 if(isset($PreBestURL['host'])&&$PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])!="localpath") {
285 $PreBestURL['host'] = $PreServURL['host'];
286 $Settings['idburl'] = unparse_url($PreBestURL); }
287 if(isset($PreBestURL['host'])&&$PreBestURL['host']!="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
288 $PreBestURL['path'] = $PreServURL['path'];
289 $Settings['idburl'] = unparse_url($PreBestURL); }
290 if(isset($Settings['weburl'])) {
291 $OrgWebSiteURL = $Settings['weburl']; }
292 else {
293 $OrgWebSiteURL = ""; }
294 if(isset($Settings['idburl'])) {
295 $PreWestURL = parse_url($Settings['weburl']); }
296 if(isset($PreWestURL['host'])&&$PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
297 $PreWestURL['host'] = $PreServURL['host'];
298 $PreWestURL['path'] = $PreServURL['path'];
299 $Settings['weburl'] = unparse_url($PreWestURL); }
300 if(isset($PreWestURL['host'])&&$PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])!="localpath") {
301 $PreWestURL['host'] = $PreServURL['host'];
302 $Settings['weburl'] = unparse_url($PreWestURL); }
303 if(isset($PreWestURL['host'])&&$PreWestURL['host']!="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
304 $PreWestURL['path'] = $PreServURL['path'];
305 $Settings['weburl'] = unparse_url($PreWestURL); }
306 if(!isset($Settings['fixbasedir'])) { $Settings['fixbasedir'] = null; }
307 if(!isset($Settings['fixpathinfo'])) { $Settings['fixpathinfo'] = null; }
308 if(!isset($Settings['fixcookiedir'])) { $Settings['fixcookiedir'] = null; }
309 if(!isset($Settings['fixredirectdir'])) { $Settings['fixcookiedir'] = null; }
310 if(!isset($Settings['idb_time_format'])) { $Settings['idb_time_format'] = "g:i A"; }
311 if(!isset($Settings['idb_date_format'])) { $Settings['idb_date_format'] = "F j Y"; }
312 if(!isset($Settings['showverinfo'])) {
313 $Settings['showverinfo'] = "on"; }
314 if(!isset($Settings['sqldb'])) {
315 header("Content-Type: text/plain; charset=UTF-8");
316 header('Location: install.php?act=Part1'); }
317 if(!isset($Settings['fixpathinfo'])) {
318 $Settings['fixpathinfo'] = "off"; }
319 if($Settings['fixpathinfo']=="off") {
320 $Settings['fixpathinfo'] = null; }
321 if(!isset($Settings['fixbasedir'])) {
322 $Settings['fixbasedir'] = "off"; }
323 if($Settings['fixbasedir']=="off") {
324 $Settings['fixbasedir'] = null; }
325 if(!isset($Settings['fixcookiedir'])) {
326 $Settings['fixcookiedir'] = "off"; }
327 if($Settings['fixcookiedir']=="off") {
328 $Settings['fixcookiedir'] = null; }
329 if(!isset($Settings['fixredirectdir'])) {
330 $Settings['fixredirectdir'] = "off"; }
331 if($Settings['fixredirectdir']=="off") {
332 $Settings['fixredirectdir'] = null; }
333 $OldSettings['fixpathinfo'] = $Settings['fixpathinfo'];
334 $OldSettings['fixbasedir'] = $Settings['fixbasedir'];
335 $OldSettings['fixcookiedir'] = $Settings['fixcookiedir'];
336 $OldSettings['fixredirectdir'] = $Settings['fixredirectdir'];
337 if($Settings['idburl']=="localhost") {
338 header("Content-Type: text/plain; charset=UTF-8");
339 echo "500 Error: URL is malformed. Try reinstalling iDB."; die(); }
340 if($Settings['fixbasedir']=="on") {
341 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
342 $PathsTest = parse_url($Settings['idburl']);
343 $Settings['fixbasedir'] = $PathsTest['path']."/";
344 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
345 if($Settings['fixcookiedir']=="on") {
346 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
347 $PathsTest = parse_url($Settings['idburl']);
348 $Settings['fixcookiedir'] = $PathsTest['path']."/";
349 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
350 if($Settings['fixredirectdir']=="on") {
351 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
352 $PathsTest = parse_url($Settings['idburl']);
353 $Settings['fixredirectdir'] = $PathsTest['path']."/";
354 $Settings['fixredirectdir'] = str_replace("//", "/", $Settings['fixredirectdir']); } }
355 if(!isset($Settings['charset'])) {
356 $Settings['charset'] = "ISO-8859-15"; }
357 if(isset($Settings['charset'])) {
358 if($Settings['charset']!="ISO-8859-15"&&$Settings['charset']!="ISO-8859-1"&&
359 $Settings['charset']!="UTF-8"&&$Settings['charset']!="CP866"&&
360 $Settings['charset']!="Windows-1251"&&$Settings['charset']!="Windows-1252"&&
361 $Settings['charset']!="KOI8-R"&&$Settings['charset']!="BIG5"&&
362 $Settings['charset']!="GB2312"&&$Settings['charset']!="BIG5-HKSCS"&&
363 $Settings['charset']!="Shift_JIS"&&$Settings['charset']!="EUC-JP") {
364 $Settings['charset'] = "ISO-8859-15"; } }
365 $chkcharset = $Settings['charset'];
366 if(!in_array("ini_set", $disfunc)) {
367 @ini_set('default_charset', $Settings['charset']); }
368 //session_save_path($SettDir['inc']."temp/");
369 if(!isset($Settings['sqldb'])) {
370 if(file_exists("install.php")) { header('Location: install.php?act=Part1'); die(); }
371 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
372 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
373 if(isset($Settings['sqldb'])) {
374 $deftz = new DateTimeZone(date_default_timezone_get());
375 $defcurtime = new DateTime();
376 $defcurtime->setTimezone($deftz);
377 $utctz = new DateTimeZone("UTC");
378 $utccurtime = new DateTime();
379 $utccurtime->setTimestamp($defcurtime->getTimestamp());
380 $utccurtime->setTimezone($utctz);
381 $servtz = new DateTimeZone($Settings['DefaultTimeZone']);
382 $servcurtime = new DateTime();
383 $servcurtime->setTimestamp($defcurtime->getTimestamp());
384 $servcurtime->setTimezone($servtz);
385 $usercurtime = new DateTime();
386 $usercurtime->setTimestamp($defcurtime->getTimestamp()); }
387 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
388 if($Settings['fixpathinfo']=="on") {
389 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
390 putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
391 // Check to see if variables are set
392 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
393 if(!isset($SettDir['archive'])) { $SettDir['archive'] = "archive/"; }
394 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
395 if(!isset($SettDir['sql'])) { $SettDir['sql'] = "inc/misc/sql/"; }
396 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
397 if(!isset($SettDir['sqldumper'])) { $SettDir['sqldumper'] = "inc/admin/sqldumper/"; }
398 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
399 if(!isset($SettDir['mplayer'])) { $SettDir['mplayer'] = "inc/mplayer/"; }
400 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
401 if(!isset($SettDir['maindir'])||!file_exists($SettDir['maindir'])||!is_dir($SettDir['maindir'])) {
402 $SettDir['maindir'] = addslashes(str_replace("\\","/",dirname(__FILE__)."/")); }
403 if(isset($SettDir['maindir'])) { @chdir($SettDir['maindir']); }
404 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
405 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = "off"; }
406 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
407 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
408 $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
409 if(!isset($_SERVER['HTTP_ACCEPT'])) { $_SERVER['HTTP_ACCEPT'] = null; }
410 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
411 if(!isset($_GET['page'])) { $_GET['page'] = null; }
412 if(!isset($_GET['act'])) { $_GET['act'] = null; }
413 if(!isset($_POST['act'])) { $_POST['act'] = null; }
414 if(!isset($_GET['modact'])) { $_GET['modact'] = null; }
415 if(!isset($_POST['modact'])) { $_POST['modact'] = null; }
416 if(!isset($_GET['id'])) { $_GET['id'] = null; }
417 if(!isset($_GET['debug'])) { $_GET['debug'] = "off"; }
418 if(!isset($_GET['post'])) { $_GET['post'] = null; }
419 if(!isset($_POST['License'])) { $_POST['License'] = null; }
420 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
421 if(!isset($Settings['SQLThemes'])) { $Settings['SQLThemes'] = "off"; }
422 if($Settings['SQLThemes']!="on"&&$Settings['SQLThemes']!="off") {
423 $Settings['SQLThemes'] = "off"; }
424 require_once($SettDir['misc'].'utf8.php');
425 require_once($SettDir['inc'].'filename.php');
426 if(!isset($Settings['use_hashtype'])) {
427 $Settings['use_hashtype'] = "sha1"; }
428 if(!function_exists('hash')||!function_exists('hash_algos')) {
429 if($Settings['use_hashtype']!="md5"&&
430 $Settings['use_hashtype']!="sha1"&&
431 $Settings['use_hashtype']!="bcrypt"&&
432 $Settings['use_hashtype']!="argon2i"&&
433 $Settings['use_hashtype']!="argon2id") {
434 $Settings['use_hashtype'] = "sha1"; } }
435 if((function_exists('hash')&&function_exists('hash_algos'))||function_exists('password_hash')) {
436 if(!in_array($Settings['use_hashtype'],hash_algos())&&$Settings['use_hashtype']!="bcrypt") {
437 $Settings['use_hashtype'] = "sha1"; }
438 if($Settings['use_hashtype']!="md2"&&
439 $Settings['use_hashtype']!="md4"&&
440 $Settings['use_hashtype']!="md5"&&
441 $Settings['use_hashtype']!="sha1"&&
442 $Settings['use_hashtype']!="sha224"&&
443 $Settings['use_hashtype']!="sha256"&&
444 $Settings['use_hashtype']!="sha384"&&
445 $Settings['use_hashtype']!="sha512"&&
446 $Settings['use_hashtype']!="sha3-224"&&
447 $Settings['use_hashtype']!="sha3-256"&&
448 $Settings['use_hashtype']!="sha3-384"&&
449 $Settings['use_hashtype']!="sha3-512"&&
450 $Settings['use_hashtype']!="ripemd128"&&
451 $Settings['use_hashtype']!="ripemd160"&&
452 $Settings['use_hashtype']!="ripemd256"&&
453 $Settings['use_hashtype']!="ripemd320"&&
454 $Settings['use_hashtype']!="bcrypt"&&
455 $Settings['use_hashtype']!="argon2i"&&
456 $Settings['use_hashtype']!="argon2id") {
457 $Settings['use_hashtype'] = "sha1"; } }
458 // Check to see if variables are set
459 require_once($SettDir['misc'].'setcheck.php');
460 $dayconv = array("year" => 29030400, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
461 require_once($SettDir['inc'].'function.php');
462 $Settings['bid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=versioninfo",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)));
463 $Settings['ubid'] = base64_encode(urlencode($Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=versioninfo",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index'],false)));
464 if($Settings['enable_pathinfo']=="on") {
465 mrstring(); /* Change Path info to Get Vars :P */ }
466 // Check to see if variables are set
467 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
468 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
469 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
470 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
471 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
472 $cookieDomain = null; $cookieSecure = false;
473 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
474 $URLsTest = parse_url($Settings['idburl']);
475 $cookieDomain = $URLsTest['host'];
476 if($cookieDomain=="localhost") { $cookieDomain = false; }
477 if($Settings['enable_https']=="on") {
478 if($URLsTest['scheme']=="https") { $cookieSecure = true; }
479 if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
480 if(!in_array("ini_set", $disfunc)) {
481 @ini_set('default_charset', $Settings['charset']); }
482 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
483 $File2Name = $_SERVER['SCRIPT_NAME'];
484 /*$File3Name=str_replace($File1Name, null, $File2Name);
485 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
486 header('Location: index.php');
487 exit(); }*/
488 $File3Name = basename($_SERVER['SCRIPT_NAME']);
489 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
490 header('Location: index.php');
491 exit(); }
492 //error_reporting(E_ERROR);
493 // Check if gzip is on and if user's browser can accept gzip pages
494 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
495 $Settings['use_gzip'] = 'off'; }
496 if($Settings['use_gzip']=="on") {
497 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")&&function_exists('brotli_compress')) {
498 $GZipEncode['Type'] = "brotli"; }
499 elseif(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "zstd")&&function_exists('zstd_compress')) {
500 $GZipEncode['Type'] = "zstd"; } else {
501 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) {
502 $GZipEncode['Type'] = "gzip"; } else {
503 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) {
504 $GZipEncode['Type'] = "deflate"; } else {
505 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } } }
506 if($Settings['use_gzip']=="brotli"&&function_exists('brotli_compress')) {
507 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")) { $Settings['use_brotli'] = "on";
508 $GZipEncode['Type'] = "brotli"; } else { $Settings['use_gzip'] = "off"; } }
509 if($Settings['use_gzip']=="zstd"&&function_exists('zstd_compress')) {
510 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "br")) { $Settings['use_zstd'] = "on";
511 $GZipEncode['Type'] = "zstd"; } else { $Settings['use_gzip'] = "off"; } }
512 if($Settings['use_gzip']=="brotli"&&!function_exists('brotli_compress')) { $GZipEncode['Type'] = "gzip"; }
513 if($Settings['use_gzip']=="zstd"&&!function_exists('zstd_compress')) { $GZipEncode['Type'] = "gzip"; }
514 if($Settings['use_gzip']=="gzip") {
515 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
516 $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
517 if($Settings['use_gzip']=="deflate") {
518 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
519 $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
520 $iWrappers = array(null);
521 function idb_output_handler($buffer) { return $buffer; }
522 function idb_suboutput_handler($buffer) { return $buffer; }
523 if($Settings['clean_ob']=="on") {
524 /* Check for other output handlers/buffers are open
525 and close and get the contents in an array */
526 $numob = count(ob_list_handlers()); $iob = 0;
527 while ($iob < $numob) {
528 $old_ob_var[$iob] = ob_get_clean();
529 ++$iob; } } ob_start("idb_output_handler");
530 if($Settings['use_gzip']=="on") {
531 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
532 if($GZipEncode['Type']=="gzip") {
533 header("Content-Encoding: gzip"); }
534 if($GZipEncode['Type']=="deflate") {
535 header("Content-Encoding: deflate"); } }
536 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
537 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
538 // Some http stuff
539 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
540 if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
541 if($Settings['sql_collate']=="ascii_bin"||
542 $Settings['sql_collate']=="ascii_generel_ci") {
543 $Settings['sql_charset'] = "ascii"; }
544 if($Settings['sql_collate']=="latin1_bin"||
545 $Settings['sql_collate']=="latin1_general_ci"||
546 $Settings['sql_collate']=="latin1_general_cs") {
547 $Settings['sql_charset'] = "latin1"; }
548 if($Settings['sql_collate']=="utf8mb3_bin"||
549 $Settings['sql_collate']=="utf8mb3_general_ci"||
550 $Settings['sql_collate']=="utf8mb3_unicode_ci") {
551 $Settings['sql_charset'] = "utf8mb3"; }
552 if($Settings['sql_collate']=="utf8mb4_bin"||
553 $Settings['sql_collate']=="utf8mb4_general_ci"||
554 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
555 $Settings['sql_charset'] = "utf8mb4"; } }
556 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
557 if($Settings['sql_charset']=="ascii") {
558 if($Settings['sql_collate']!="ascii_bin"&&
559 $Settings['sql_collate']!="ascii_generel_ci") {
560 $Settings['sql_collate'] = "ascii_generel_ci"; } }
561 if($Settings['sql_charset']=="latin1") {
562 if($Settings['sql_collate']!="latin1_bin"&&
563 $Settings['sql_collate']!="latin1_general_ci"&&
564 $Settings['sql_collate']!="latin1_general_cs") {
565 $Settings['sql_collate'] = "latin1_general_ci"; } }
566 if($Settings['sql_charset']=="utf8" || $Settings['sql_charset']=="utf8mb4") {
567 if($Settings['sql_collate']!="utf8mb3_bin"&&
568 $Settings['sql_collate']!="utf8mb3_general_ci"&&
569 $Settings['sql_collate']!="utf8mb3_unicode_ci"&&
570 $Settings['sql_collate']!="utf8mb4_bin"&&
571 $Settings['sql_collate']!="utf8mb4_general_ci"&&
572 $Settings['sql_collate']!="utf8mb4_unicode_ci") {
573 $Settings['sql_collate'] = "utf8mb4_unicode_ci"; } }
574 if($Settings['sql_collate']=="utf8mb3_bin"||
575 $Settings['sql_collate']=="utf8mb3_general_ci"||
576 $Settings['sql_collate']=="utf8mb3_unicode_ci") {
577 $Settings['sql_charset'] = "utf8mb3"; }
578 if($Settings['sql_collate']=="utf8mb4_bin"||
579 $Settings['sql_collate']=="utf8mb4_general_ci"||
580 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
581 $Settings['sql_charset'] = "utf8mb4"; }
582 $SQLCollate = $Settings['sql_collate'];
583 $SQLCharset = $Settings['sql_charset']; }
584 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
585 $SQLCollate = "latin1_general_ci";
586 $SQLCharset = "latin1";
587 if($Settings['charset']=="ISO-8859-1") {
588 $SQLCollate = "latin1_general_ci";
589 $SQLCharset = "latin1"; }
590 if($Settings['charset']=="ISO-8859-15") {
591 $SQLCollate = "latin1_general_ci";
592 $SQLCharset = "latin1"; }
593 if($Settings['charset']=="UTF-8") {
594 $SQLCollate = "utf8mb4_unicode_ci";
595 $SQLCharset = "utf8mb4"; }
596 $Settings['sql_collate'] = $SQLCollate;
597 $Settings['sql_charset'] = $SQLCharset; }
598 sql_set_charset($SQLCharset,$SQLStat);
599 if($SQLStat===false) {
600 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
601 ob_clean(); echo "Sorry could not connect to sql database.\nContact the board admin about error. Error log below.";
602 echo "\n".sql_errorno($SQLStat); $urlstatus = 503;
603 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
604 $sqltable = $Settings['sqltable'];
605 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
606 if(!isset($_SERVER['HTTP_USER_AGENT'])) {
607 $_SERVER['HTTP_USER_AGENT'] = ""; }
608 // Create an array to store browser hints
609 $client_hints_json = [];
610 $client_hints = [
611 'user_agent' => isset($_SERVER['HTTP_SEC_CH_UA']) ? $_SERVER['HTTP_SEC_CH_UA'] : null,
612 'is_mobile' => isset($_SERVER['HTTP_SEC_CH_UA_MOBILE']) ? $_SERVER['HTTP_SEC_CH_UA_MOBILE'] : null,
613 'full_version' => isset($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION'] : null,
614 'full_version_list' => isset($_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST']) ? $_SERVER['HTTP_SEC_CH_UA_FULL_VERSION_LIST'] : null,
615 'platform' => isset($_SERVER['HTTP_SEC_CH_UA_PLATFORM']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM'] : null,
616 'platform_version' => isset($_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION']) ? $_SERVER['HTTP_SEC_CH_UA_PLATFORM_VERSION'] : null,
617 'architecture' => isset($_SERVER['HTTP_SEC_CH_UA_ARCH']) ? $_SERVER['HTTP_SEC_CH_UA_ARCH'] : null,
618 'bitness' => isset($_SERVER['HTTP_SEC_CH_UA_BITNESS']) ? $_SERVER['HTTP_SEC_CH_UA_BITNESS'] : null,
619 'wow64' => isset($_SERVER['HTTP_SEC_CH_UA_WOW64']) ? $_SERVER['HTTP_SEC_CH_UA_WOW64'] : null,
620 'model' => isset($_SERVER['HTTP_SEC_CH_UA_MODEL']) ? $_SERVER['HTTP_SEC_CH_UA_MODEL'] : null,
621 'form_factor' => isset($_SERVER['HTTP_SEC_CH_UA_FORM_FACTOR']) ? $_SERVER['HTTP_SEC_CH_UA_FORM_FACTOR'] : null,
622 'lang' => isset($_SERVER['HTTP_SEC_CH_LANG']) ? $_SERVER['HTTP_SEC_CH_LANG'] : null,
623 'save_data' => isset($_SERVER['HTTP_SEC_CH_SAVE_DATA']) ? $_SERVER['HTTP_SEC_CH_SAVE_DATA'] : null,
624 'width' => isset($_SERVER['HTTP_SEC_CH_WIDTH']) ? $_SERVER['HTTP_SEC_CH_WIDTH'] : null,
625 'viewport_width' => isset($_SERVER['HTTP_SEC_CH_VIEWPORT_WIDTH']) ? $_SERVER['HTTP_SEC_CH_VIEWPORT_WIDTH'] : null,
626 'viewport_height' => isset($_SERVER['HTTP_SEC_CH_VIEWPORT_HEIGHT']) ? $_SERVER['HTTP_SEC_CH_VIEWPORT_HEIGHT'] : null,
627 'dpr' => isset($_SERVER['HTTP_SEC_CH_DPR']) ? $_SERVER['HTTP_SEC_CH_DPR'] : null,
628 'device_memory' => isset($_SERVER['HTTP_SEC_CH_DEVICE_MEMORY']) ? $_SERVER['HTTP_SEC_CH_DEVICE_MEMORY'] : null,
629 'rtt' => isset($_SERVER['HTTP_SEC_CH_RTT']) ? $_SERVER['HTTP_SEC_CH_RTT'] : null,
630 'downlink' => isset($_SERVER['HTTP_SEC_CH_DOWNLINK']) ? $_SERVER['HTTP_SEC_CH_DOWNLINK'] : null,
631 'ect' => isset($_SERVER['HTTP_SEC_CH_ECT']) ? $_SERVER['HTTP_SEC_CH_ECT'] : null,
632 'prefers_color_scheme' => isset($_SERVER['HTTP_SEC_CH_PREFERS_COLOR_SCHEME']) ? $_SERVER['HTTP_SEC_CH_PREFERS_COLOR_SCHEME'] : null,
633 'prefers_reduced_motion' => isset($_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_MOTION']) ? $_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_MOTION'] : null,
634 'prefers_reduced_transparency' => isset($_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_TRANSPARENCY']) ? $_SERVER['HTTP_SEC_CH_PREFERS_REDUCED_TRANSPARENCY'] : null,
635 'prefers_contrast' => isset($_SERVER['HTTP_SEC_CH_PREFERS_CONTRAST']) ? $_SERVER['HTTP_SEC_CH_PREFERS_CONTRAST'] : null,
636 'forced_colors' => isset($_SERVER['HTTP_SEC_CH_FORCED_COLORS']) ? $_SERVER['HTTP_SEC_CH_FORCED_COLORS'] : null
638 $client_hints_json = json_encode($client_hints);
639 if($client_hints_json=="") { $client_hints_json = []; }
640 if(strpos($_SERVER['HTTP_USER_AGENT'], "msie") &&
641 !strpos($_SERVER['HTTP_USER_AGENT'], "opera")){
642 header("X-UA-Compatible: IE=Edge"); }
643 if(strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
644 header("X-UA-Compatible: IE=Edge,chrome=1"); }
645 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
646 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
647 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
648 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
649 $MkIndexFile = $exfile['index']; }
650 $temp_session_data = "ViewingPage|s:9:\"?act=view\";ViewingFile|s:".strlen($MkIndexFile).":\"".$MkIndexFile."\";PreViewingTitle|s:7:\"Viewing\";ViewingTitle|s:11:\"Board index\";UserID|s:1:\"0\";UserIP|s:".strlen($_SERVER['REMOTE_ADDR']).":\"".$_SERVER['REMOTE_ADDR']."\";UserGroup|s:".strlen($Settings['GuestGroup']).":\"".$Settings['GuestGroup']."\";UserGroupID|s:1:\"4\";UserTimeZone|s:".strlen($Settings['DefaultTimeZone']).":\"".$Settings['DefaultTimeZone']."\";";
651 $alt_temp_session_data['ViewingPage'] = "?act=view";
652 $alt_temp_session_data['ViewingFile'] = $MkIndexFile;
653 $alt_temp_session_data['PreViewingTitle'] = "Viewing";
654 $alt_temp_session_data['ViewingTitle'] = "Board index";
655 $alt_temp_session_data['UserID'] = "0";
656 $alt_temp_session_data['UserIP'] = $_SERVER['REMOTE_ADDR'];
657 $alt_temp_session_data['UserGroupID'] = "4";
658 $alt_temp_session_data['UserTimeZone'] = $Settings['DefaultTimeZone'];
659 $alttemp_session_data = serialize($alt_temp_session_data);
660 $alt_temp_session_data = $alttemp_session_data;
661 $alttemp_session_data = null;
662 $SQLSType = $Settings['sqltype'];
663 $use_old_session = true;
664 if ($use_old_session == true) {
665 // Session Open Function
666 function sql_session_open($save_path, $session_name) {
667 global $sess_save_path;
668 $sess_save_path = $save_path;
669 return true;
672 // Session Close Function
673 $iDBSessCloseDB = true;
674 function sql_session_close() {
675 global $SQLStat, $iDBSessCloseDB;
676 if ($iDBSessCloseDB === true) {
677 sql_disconnect_db($SQLStat);
679 return true;
682 // Session Read Function
683 function sql_session_read($id) {
684 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json, $temp_session_data, $alt_temp_session_data;
686 // Select session
687 $rs = sql_query(sql_pre_query("SELECT * FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id)), $SQLStat);
688 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
689 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
691 if ($sessionExists == 0) {
692 // If session does not exist, delete previous sessions with same IP and User-Agent
693 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" <> '%s' AND \"ip_address\" = '%s' AND \"user_agent\" = '%s'",
694 array($id, $temp_user_ip, $temp_user_agent)), $SQLStat);
696 // Insert new session
697 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
698 sql_query(sql_pre_query("INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
699 array($id, $temp_session_data, $alt_temp_session_data, $temp_user_agent, $client_hints_json, $temp_user_ip, $time)), $SQLStat);
700 return '';
701 } else {
702 // Fetch the session data if it exists
703 $row = sql_fetch_assoc($rs);
704 return $row ? $row['session_data'] : '';
708 // Session Write Function
709 function sql_session_write($id, $data) {
710 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json;
712 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
713 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
714 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
716 if ($sessionExists == 0) {
717 // Insert new session
718 sql_query(sql_pre_query("INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
719 array($id, $data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time)), $SQLStat);
720 } else {
721 // Update existing session
722 sql_query(sql_pre_query("UPDATE \"" . $sqltable . "sessions\" SET \"session_data\" = '%s', \"serialized_data\" = '%s', \"user_agent\" = '%s', \"client_hints\" = '%s', \"ip_address\" = '%s', \"expires\" = %i WHERE \"session_id\" = '%s'",
723 array($data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time, $id)), $SQLStat);
726 return true;
729 // Session Destroy Function
730 function sql_session_destroy($id) {
731 global $sqltable, $SQLStat;
732 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id)), $SQLStat);
733 return true;
736 // Session Garbage Collection Function
737 function sql_session_gc($maxlifetime) {
738 global $sqltable, $SQLStat;
739 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp() - $maxlifetime;
740 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"expires\" < %i", array($time)), $SQLStat);
741 return true;
744 if (session_id()) {
745 session_destroy();
747 } else {
748 // Alternative session management logic
750 function sql_session_open($save_path, $session_name) {
751 global $sess_save_path;
752 $sess_save_path = $save_path;
753 return true;
756 function sql_session_close() {
757 global $SQLStat;
758 sql_disconnect_db($SQLStat);
759 return true;
762 function sql_session_read($id) {
763 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json, $temp_session_data, $alt_temp_session_data;
765 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
766 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
768 if ($sessionExists == 0) {
769 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" <> '%s' AND \"ip_address\" = '%s' AND \"user_agent\" = '%s'",
770 array($id, $temp_user_ip, $temp_user_agent)), $SQLStat);
772 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
773 sql_query(sql_pre_query("INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
774 array($id, $temp_session_data, $alt_temp_session_data, $temp_user_agent, $client_hints_json, $temp_user_ip, $time)), $SQLStat);
775 return '';
776 } else {
777 $query = sql_pre_query("SELECT * FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
778 $rs = sql_query($query, $SQLStat);
779 $row = sql_fetch_assoc($rs);
780 return $row ? $row['session_data'] : '';
784 function sql_session_write($id, $data) {
785 global $sqltable, $SQLStat, $temp_user_ip, $temp_user_agent, $client_hints_json;
787 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp();
788 $checkQuery = sql_pre_query("SELECT COUNT(*) AS cnt FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id));
789 $sessionExists = sql_count_rows($checkQuery, $SQLStat);
791 if ($sessionExists == 0) {
792 sql_query(sql_pre_query("INSERT INTO \"" . $sqltable . "sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"client_hints\", \"ip_address\", \"expires\") VALUES ('%s', '%s', '%s', '%s', '%s', '%s', %i)",
793 array($id, $data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time)), $SQLStat);
794 } else {
795 sql_query(sql_pre_query("UPDATE \"" . $sqltable . "sessions\" SET \"session_data\" = '%s', \"serialized_data\" = '%s', \"user_agent\" = '%s', \"client_hints\" = '%s', \"ip_address\" = '%s', \"expires\" = %i WHERE \"session_id\" = '%s'",
796 array($data, serialize($_SESSION), $temp_user_agent, $client_hints_json, $temp_user_ip, $time, $id)), $SQLStat);
799 return true;
802 function sql_session_destroy($id) {
803 global $sqltable, $SQLStat;
804 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"session_id\" = '%s'", array($id)), $SQLStat);
805 return true;
808 function sql_session_gc($maxlifetime) {
809 global $sqltable, $SQLStat;
810 $time = (new DateTime('now', new DateTimeZone("UTC")))->getTimestamp() - $maxlifetime;
811 sql_query(sql_pre_query("DELETE FROM \"" . $sqltable . "sessions\" WHERE \"expires\" < %i", array($time)), $SQLStat);
812 return true;
815 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
816 if($cookieDomain==null) {
817 session_set_cookie_params(0, $cbasedir); }
818 if($cookieDomain!=null) {
819 if($cookieSecure===true) {
820 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
821 if($cookieSecure===false) {
822 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
823 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
824 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
825 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
826 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
827 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
828 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
829 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
830 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
831 $exptime = $utccurtime->getTimestamp() - ini_get("session.gc_maxlifetime");
832 sql_query(sql_pre_query("DELETE FROM \"".$Settings['sqltable']."sessions\" WHERE \"expires\" < %i OR \"ip_address\"='%s' AND \"user_agent\"='%s'", array($exptime,$temp_user_ip,$temp_user_agent)),$SQLStat); }
833 if(!isset($_SESSION['CheckCookie'])) {
834 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
835 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
836 session_name($Settings['sqltable']."sess");
837 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
838 session_start([
839 'use_trans_sid' => false,
840 'use_cookies' => true,
841 'use_only_cookies' => true,
842 'gc_probability' => 1,
843 'gc_divisor' => 100,
844 'gc_maxlifetime' => 1440,
845 //'hash_function' => 1,
846 //'hash_bits_per_character' => 6,
847 'name' => $Settings['sqltable']."sess",
848 ]); }
849 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
850 $iDBSessCloseDB = false;
851 $_SESSION['ShowActHidden'] = "no";
852 output_reset_rewrite_vars();
853 require($SettDir['inc'].'prelogin.php');
854 session_write_close(); } }
855 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
856 session_name($Settings['sqltable']."sess");
857 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
858 session_start([
859 'use_trans_sid' => false,
860 'use_cookies' => true,
861 'use_only_cookies' => true,
862 'gc_probability' => 1,
863 'gc_divisor' => 100,
864 'gc_maxlifetime' => 1440,
865 //'hash_function' => 1,
866 //'hash_bits_per_character' => 6,
867 'name' => $Settings['sqltable']."sess",
868 ]); }
869 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
870 $iDBSessCloseDB = true;
871 output_reset_rewrite_vars();
872 //@register_shutdown_function("session_write_close");
873 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
874 if(!in_array("ini_set", $disfunc)) {
875 // Set user agent if we can use ini_set and have to do any http requests. :P
876 $iverstring = "FR 0.0.0 ".$VER2[2]." 0";
877 if($Settings['hideverinfohttp']=="off") {
878 $iverstring = $VER2[1]." ".$VER1[0].".".$VER1[1].".".$VER1[2]." ".$VER2[2]." ".$SubVerN; }
879 if($Settings['hideverinfohttp']=="on") {
880 $iverstring = "FR 0.0.0 ".$VER2[2]." 0"; }
881 $qstrtest = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
882 $qseptest = htmlentities($Settings['qsep'], ENT_QUOTES, $Settings['charset']);
883 $isiteurl = $Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']);
884 @ini_set("user_agent", "Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")");
885 if (function_exists("stream_context_create")) {
886 $iopts = array(
887 'http' => array(
888 'method' => "GET",
889 'header' => "Accept-Language: *\r\n".
890 "User-Agent: Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")\r\n".
891 "Accept: */*\r\n".
892 "Connection: keep-alive\r\n".
893 "Referer: ".$isiteurl."\r\n".
894 "From: ".$isiteurl."\r\n".
895 "Via: ".$_SERVER['REMOTE_ADDR']."\r\n".
896 "Forwarded: ".$_SERVER['REMOTE_ADDR']."\r\n".
897 "X-Real-IP: ".$_SERVER['REMOTE_ADDR']."\r\n".
898 "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR']."\r\n".
899 "X-Forwarded-Host: ".$URLsTest['host']."\r\n".
900 "X-Forwarded-Proto: ".$URLsTest['scheme']."\r\n".
901 "Board-Unique-ID: ".$Settings['BoardUUID']."\r\n".
902 "Client-IP: ".$_SERVER['REMOTE_ADDR']."\r\n"
905 $icontext = stream_context_create($iopts);
906 function file_get_contents_alt($filename,$use_include_path=null,$offset=-1,$maxlen=null) {
907 global $icontext;
908 if($maxlen!==null) {
909 return file_get_contents($filename,$use_include_path,$icontext,$offset,$maxlen); }
910 if($maxlen===null) {
911 return file_get_contents($filename,$use_include_path,$icontext,$offset); } } } }
912 $iDBVerName = $VerCheckName."|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
914 This way checks iDB version by sending the iDBVerName to the iDB Version Checker.
915 $Settings['vercheck'] = 1;
916 This way checks iDB version by sending the board url to the iDB Version Checker.
917 $Settings['vercheck'] = 2;
919 if(!isset($Settings['vercheck'])) {
920 $Settings['vercheck'] = 2; }
921 if($Settings['vercheck']!=1&&
922 $Settings['vercheck']!=2) {
923 $Settings['vercheck'] = 2; }
924 if($Settings['vercheck']===2) {
925 if($_GET['act']=="vercheckxsl") {
926 if(stristr($_SERVER['HTTP_ACCEPT'],"application/xml") ) {
927 header("Content-Type: application/xml; charset=".$Settings['charset']); }
928 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
929 xml_doc_start("1.0",$Settings['charset']);
930 echo "\n"; ?>
931 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
933 <xsl:template match="/">
934 <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
935 <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
936 <xsl:for-each select="versioninfo/version">
937 <div style="background-color:teal;color:white;padding:4px">
938 <span style="font-weight:bold"><xsl:value-of select="vname"/></span>
939 </div>
940 <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
941 <span style="font-style:italic">
942 Board Name: <a href="<?php echo url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']); ?>"><xsl:value-of select="title"/></a></span>
943 </div>
944 </xsl:for-each>
945 </body>
946 </html>
947 </xsl:template>
949 </xsl:stylesheet>
950 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
951 if($_GET['act']=="versioninfo") {
952 if(stristr($_SERVER['HTTP_ACCEPT'],"application/xml") ) {
953 header("Content-Type: application/xml; charset=".$Settings['charset']); }
954 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
955 xml_doc_start("1.0",$Settings['charset']);
956 echo '<?xml-stylesheet type="text/xsl" href="'.url_maker($exfile['index'],$Settings['file_ext'],"act=vercheckxsl",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']).'"?>'."\n"; ?>
958 <!DOCTYPE versioninfo [
959 <!ELEMENT versioninfo (version*)>
960 <!ELEMENT version (charset,title,name,vname)>
961 <!ELEMENT charset (#PCDATA)>
962 <!ELEMENT title (#PCDATA)>
963 <!ELEMENT name (#PCDATA)>
964 <!ELEMENT vname (#PCDATA)>
967 <versioninfo>
969 <version>
970 <charset><?php echo $Settings['charset']; ?></charset>
971 <title><?php echo $Settings['board_name']; ?></title>
972 <?php echo "<name>".$iDBVerName."</name>\n"; ?>
973 <vname><?php echo $VerCheckName; ?> Version Checker</vname>
974 </version>
976 </versioninfo>
977 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
978 if($Settings['vercheck']===1) {
979 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
980 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); $urlstatus = 302;
981 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
982 if($_GET['act']=="homepage") { header("Content-Type: text/plain; charset=UTF-8");
983 header("Location: ".$Settings['weburl']); $urlstatus = 302;
984 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
985 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
986 $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
987 if($_GET['act']=="bsd") {
988 header("Content-Type: text/plain; charset=".$Settings['charset']);
989 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
990 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
991 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
992 header("Content-Type: text/plain; charset=".$Settings['charset']);
993 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
994 if($_GET['act']=="js"||$_GET['act']=="javascript") {
995 header("Content-Script-Type: text/javascript");
996 if(stristr($_SERVER['HTTP_ACCEPT'],"application/x-javascript") ) {
997 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
998 if(stristr($_SERVER['HTTP_ACCEPT'],"application/javascript") ) {
999 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
1000 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
1001 require($SettDir['inc'].'javascript.php');
1002 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
1003 $Settings['use_captcha'] = "off";
1004 /*if($Settings['use_captcha']=="on") {
1005 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
1006 if($Settings['captcha_clean']=="on") { ob_clean(); }
1007 require($SettDir['inc']."captcha.php");
1008 $aFontDir = dirname(__FILE__)."/inc/fonts/";
1009 $aFonts = array($aFontDir.'VeraBd.ttf', $aFontDir.'VeraBI.ttf', $aFontDir.'VeraIt.ttf', $aFontDir.'Vera.ttf');
1010 $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
1011 $RNumSize = rand(7,17); $i=0; $RandNum = null;
1012 while ($i <= $RNumSize) {
1013 $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
1014 $RandNum=strtoupper($RandNum);
1015 $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
1016 $oPhpCaptcha->UseColour(true);
1017 $oPhpCaptcha->Create(); session_write_close(); die(); } }*/
1018 require($SettDir['inc'].'groupsetup.php');
1019 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
1020 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
1021 ob_clean(); if(!isset($Settings['offline_text'])) {
1022 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
1023 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; } $urlstatus = 503;
1024 //echo "\n".sql_errorno($SQLStat);
1025 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
1026 //Time Format Set
1027 if(!isset($_SESSION['iDBDateFormat'])) {
1028 if(isset($Settings['idb_date_format'])) {
1029 $_SESSION['iDBDateFormat'] = $Settings['idb_date_format'];
1030 if(!isset($Settings['idb_date_format'])) {
1031 $_SESSION['iDBDateFormat'] = "g:i A"; } } }
1032 if(!isset($_SESSION['iDBTimeFormat'])) {
1033 if(isset($Settings['idb_time_format'])) {
1034 $_SESSION['iDBTimeFormat'] = $Settings['idb_time_format'];
1035 if(!isset($Settings['idb_time_format'])) {
1036 $_SESSION['iDBTimeFormat'] = "F j Y"; } } }
1037 //Time Zone Set
1038 if(!isset($_SESSION['UserTimeZone'])) {
1039 if(isset($Settings['DefaultTimeZone'])) {
1040 $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
1041 if(!isset($Settings['DefaultTimeZone'])) {
1042 $_SESSION['UserTimeZone'] = date_default_timezone_get(); } } }
1043 $usertz = new DateTimeZone($_SESSION['UserTimeZone']);
1044 $usercurtime->setTimestamp($defcurtime->getTimestamp());
1045 $usercurtime->setTimezone($usertz);
1046 // Guest Stuff
1047 if(isset($_SESSION['MemberName'])||
1048 isset($_COOKIE['MemberName'])) {
1049 $_SESSION['GuestName'] = null;
1050 $_COOKIE['GuestName'] = null; }
1051 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
1052 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
1053 $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
1054 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
1055 // Skin Stuff
1056 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
1057 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
1058 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
1059 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
1060 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
1061 if(!isset($_GET['style'])) { $_GET['style'] = null; }
1062 if(!isset($_POST['style'])) { $_POST['style'] = null; }
1063 if(!isset($_GET['css'])) { $_GET['css'] = null; }
1064 if(!isset($_POST['css'])) { $_POST['css'] = null; }
1065 if($_GET['theme']==null) {
1066 if($_POST['theme']!=null) {
1067 $_GET['theme'] = $_POST['theme']; }
1068 if($_POST['skin']!=null) {
1069 $_GET['theme'] = $_POST['skin']; }
1070 if($_POST['style']!=null) {
1071 $_GET['theme'] = $_POST['style']; }
1072 if($_POST['css']!=null) {
1073 $_GET['theme'] = $_POST['css']; }
1074 if($_GET['skin']!=null) {
1075 $_GET['theme'] = $_GET['skin']; }
1076 if($_GET['style']!=null) {
1077 $_GET['theme'] = $_GET['style']; }
1078 if($_GET['css']!=null) {
1079 $_GET['theme'] = $_GET['css']; } }
1080 if($Settings['SQLThemes']=="off") {
1081 if($_GET['theme']!=null) {
1082 $_GET['theme'] = chack_themes($_GET['theme']);
1083 if($_GET['theme']=="../"||$_GET['theme']=="./") {
1084 $_GET['theme']=$Settings['DefaultTheme']; $_SESSION['Theme']=$Settings['DefaultTheme']; }
1085 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
1086 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
1087 $NewDay=$utccurtime->getTimestamp();
1088 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
1089 sql_query($qnewskin,$SQLStat); }
1090 /* The file Theme Exists */ }
1091 else { $_GET['theme'] = $Settings['DefaultTheme'];
1092 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1093 /* The file Theme Dose Not Exists */ } }
1094 if($_GET['theme']==null) {
1095 if($_SESSION['Theme']!=null) {
1096 $OldTheme = $_SESSION['Theme'];
1097 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
1098 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
1099 if($OldTheme!=$_SESSION['Theme']) {
1100 $NewDay=$utccurtime->getTimestamp();
1101 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
1102 sql_query($qnewskin,$SQLStat); } }
1103 $_GET['theme']=$_SESSION['Theme']; }
1104 if($_SESSION['Theme']==null) {
1105 $_SESSION['Theme']=$Settings['DefaultTheme'];
1106 $_GET['theme']=$Settings['DefaultTheme']; } }
1107 $PreSkin['skindir1'] = $_SESSION['Theme'];
1108 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
1109 require($SettDir['themes'].$_GET['theme']."/settings.php"); }
1110 if($Settings['SQLThemes']=="on") {
1111 if($_GET['theme']==null&&$_SESSION['Theme']==null) {
1112 $_GET['theme'] = $Settings['DefaultTheme'];
1113 $_SESSION['Theme'] = $Settings['DefaultTheme']; }
1114 if($_GET['theme']!=null) {
1115 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme'])); }
1116 if($_GET['theme']==null) {
1117 if($_SESSION['Theme']!=null) {
1118 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])); } }
1119 $themeresult=sql_query($themequery,$SQLStat);
1120 $themenum=sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])), $SQLStat);
1121 if($themenum<=0) {
1122 $_GET['theme'] = $Settings['DefaultTheme'];
1123 $_SESSION['Theme'] = $Settings['DefaultTheme'];
1124 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
1125 $NewDay=$utccurtime->getTimestamp();
1126 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
1127 sql_query($qnewskin,$SQLStat); }
1128 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
1129 $themeresult=sql_query($themequery,$SQLStat);
1130 $themenum=sql_count_rows(sql_pre_query("SELECT COUNT(*) AS cnt FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])), $SQLStat); }
1131 else {
1132 if($_GET['theme']==null) {
1133 if($_SESSION['Theme']!=null) {
1134 $_GET['theme'] = $_SESSION['Theme']; } }
1135 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
1136 $NewDay=$utccurtime->getTimestamp();
1137 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
1138 sql_query($qnewskin,$SQLStat); } }
1139 require($SettDir['inc'].'sqlthemes.php');
1140 sql_free_result($themeresult); }
1141 $_SESSION['Theme'] = $_GET['theme'];
1142 function get_theme_values($matches) {
1143 global $ThemeSet;
1144 $return_text = null;
1145 if(isset($ThemeSet[$matches[1]])) { $return_text = $ThemeSet[$matches[1]]; }
1146 if(!isset($ThemeSet[$matches[1]])) { $return_text = null; }
1147 return $return_text; }
1148 foreach($ThemeSet AS $key => $value) {
1149 if(isset($ThemeSet[$key])) {
1150 $ThemeSet[$key] = preg_replace("/%%/s", "{percent}p", $ThemeSet[$key]);
1151 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}T/s", "get_theme_values", $ThemeSet[$key]);
1152 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}e/s", "get_env_values", $ThemeSet[$key]);
1153 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}i/s", "get_server_values", $ThemeSet[$key]);
1154 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}s/s", "get_setting_values", $ThemeSet[$key]);
1155 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}t/s", "get_time", $ThemeSet[$key]);
1156 $ThemeSet[$key] = preg_replace("/\{percent\}p/s", "%", $ThemeSet[$key]); } }
1157 if(!isset($ThemeSet['TableStyle'])) {
1158 $ThemeSet['TableStyle'] = "table"; }
1159 if(isset($ThemeSet['TableStyle'])) {
1160 if($ThemeSet['TableStyle']!="div"&&
1161 $ThemeSet['TableStyle']!="table") {
1162 $ThemeSet['TableStyle'] = "table"; } }
1163 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
1164 if($_SESSION['DBName']==null) {
1165 $_SESSION['DBName'] = $Settings['sqldb']; }
1166 if($_SESSION['DBName']!=null) {
1167 if($_SESSION['DBName']!=$Settings['sqldb']) {
1168 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }