Small update
[iDB.git] / sql.php
blob19df8695a9445e1f9c853b6408cd376e6e464085
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-2019 iDB Support - https://idb.osdn.jp/support/category.php?act=view&id=1
12 Copyright 2004-2019 Game Maker 2k - https://idb.osdn.jp/support/category.php?act=view&id=2
14 $FileInfo: sql.php - Last Update: 08/02/2019 SVN 905 - 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 if(!in_array("ini_set", $disfunc)&&$Settings['qstr']!="/"&&$Settings['qstr']!="&") {
67 ini_set("arg_separator.output",htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']));
68 ini_set("arg_separator.input",$Settings['qstr']); } }
69 if(!isset($Settings['idburl'])) { $Settings['idburl'] = null; }
70 if(isset($Settings['BoardUUID'])) { $Settings['BoardUUID'] = base64_decode($Settings['BoardUUID']);
71 header("Board-Unique-ID: ".$Settings['BoardUUID']); }
72 function unparse_url($parsed_url) {
73 $scheme = isset($parsed_url['scheme']) ? $parsed_url['scheme'] . '://' : '';
74 $host = isset($parsed_url['host']) ? $parsed_url['host'] : '';
75 $port = isset($parsed_url['port']) ? ':' . $parsed_url['port'] : '';
76 $user = isset($parsed_url['user']) ? $parsed_url['user'] : '';
77 $pass = isset($parsed_url['pass']) ? ':' . $parsed_url['pass'] : '';
78 $pass = ($user || $pass) ? "$pass@" : '';
79 $path = isset($parsed_url['path']) ? $parsed_url['path'] : '';
80 $query = isset($parsed_url['query']) ? '?' . $parsed_url['query'] : '';
81 $fragment = isset($parsed_url['fragment']) ? '#' . $parsed_url['fragment'] : '';
82 return $scheme.$user.$pass.$host.$port.$path.$query.$fragment;
84 $OrgBoardURL = $Settings['idburl'];
85 $PreBestURL = parse_url($Settings['idburl']);
86 $PreServURL = parse_url((isset($_SERVER['HTTPS']) ? "https" : "http") . "://".$_SERVER['HTTP_HOST'].substr($_SERVER['REQUEST_URI'], 0, strrpos($_SERVER['REQUEST_URI'], '/') + 1));
87 if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
88 $PreBestURL['host'] = "localhost";
89 $PreBestURL['path'] = $PreServURL['path'];
90 $Settings['idburl'] = unparse_url($PreBestURL); }
91 if($PreBestURL['host']=="localhost.url"&&str_replace("/", "", $PreBestURL['path'])!="localpath") {
92 $PreBestURL['host'] = $PreServURL['host'];
93 $Settings['idburl'] = unparse_url($PreBestURL); }
94 if($PreBestURL['host']!="localhost.url"&&str_replace("/", "", $PreBestURL['path'])=="localpath") {
95 $PreBestURL['path'] = $PreServURL['path'];
96 $Settings['idburl'] = unparse_url($PreBestURL); }
97 $OrgWebSiteURL = $Settings['weburl'];
98 $PreWestURL = parse_url($Settings['weburl']);
99 if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
100 $PreWestURL['host'] = $PreServURL['host'];
101 $PreWestURL['path'] = $PreServURL['path'];
102 $Settings['weburl'] = unparse_url($PreWestURL); }
103 if($PreWestURL['host']=="localhost.url"&&str_replace("/", "", $PreWestURL['path'])!="localpath") {
104 $PreWestURL['host'] = $PreServURL['host'];
105 $Settings['weburl'] = unparse_url($PreWestURL); }
106 if($PreWestURL['host']!="localhost.url"&&str_replace("/", "", $PreWestURL['path'])=="localpath") {
107 $PreWestURL['path'] = $PreServURL['path'];
108 $Settings['weburl'] = unparse_url($PreWestURL); }
109 if(!isset($Settings['fixbasedir'])) { $Settings['fixbasedir'] = null; }
110 if(!isset($Settings['fixpathinfo'])) { $Settings['fixpathinfo'] = null; }
111 if(!isset($Settings['fixcookiedir'])) { $Settings['fixcookiedir'] = null; }
112 if(!isset($Settings['fixredirectdir'])) { $Settings['fixcookiedir'] = null; }
113 if(!isset($Settings['idb_time_format'])) { $Settings['idb_time_format'] = "g:i A"; }
114 if(!isset($Settings['idb_date_format'])) { $Settings['idb_date_format'] = "F j Y"; }
115 if(!isset($Settings['showverinfo'])) {
116 $Settings['showverinfo'] = "on"; }
117 if(!isset($Settings['sqldb'])) {
118 header("Content-Type: text/plain; charset=UTF-8");
119 header('Location: install.php?act=Part1'); }
120 if(!isset($Settings['fixpathinfo'])) {
121 $Settings['fixpathinfo'] = "off"; }
122 if($Settings['fixpathinfo']=="off") {
123 $Settings['fixpathinfo'] = null; }
124 if(!isset($Settings['fixbasedir'])) {
125 $Settings['fixbasedir'] = "off"; }
126 if($Settings['fixbasedir']=="off") {
127 $Settings['fixbasedir'] = null; }
128 if(!isset($Settings['fixcookiedir'])) {
129 $Settings['fixcookiedir'] = "off"; }
130 if($Settings['fixcookiedir']=="off") {
131 $Settings['fixcookiedir'] = null; }
132 if(!isset($Settings['fixredirectdir'])) {
133 $Settings['fixredirectdir'] = "off"; }
134 if($Settings['fixredirectdir']=="off") {
135 $Settings['fixredirectdir'] = null; }
136 $OldSettings['fixpathinfo'] = $Settings['fixpathinfo'];
137 $OldSettings['fixbasedir'] = $Settings['fixbasedir'];
138 $OldSettings['fixcookiedir'] = $Settings['fixcookiedir'];
139 $OldSettings['fixredirectdir'] = $Settings['fixredirectdir'];
140 if($Settings['idburl']=="localhost") {
141 header("Content-Type: text/plain; charset=UTF-8");
142 echo "500 Error: URL is malformed. Try reinstalling iDB."; die(); }
143 if($Settings['fixbasedir']=="on") {
144 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
145 $PathsTest = parse_url($Settings['idburl']);
146 $Settings['fixbasedir'] = $PathsTest['path']."/";
147 $Settings['fixbasedir'] = str_replace("//", "/", $Settings['fixbasedir']); } }
148 if($Settings['fixcookiedir']=="on") {
149 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
150 $PathsTest = parse_url($Settings['idburl']);
151 $Settings['fixcookiedir'] = $PathsTest['path']."/";
152 $Settings['fixcookiedir'] = str_replace("//", "/", $Settings['fixcookiedir']); } }
153 if($Settings['fixredirectdir']=="on") {
154 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
155 $PathsTest = parse_url($Settings['idburl']);
156 $Settings['fixredirectdir'] = $PathsTest['path']."/";
157 $Settings['fixredirectdir'] = str_replace("//", "/", $Settings['fixredirectdir']); } }
158 if(!isset($Settings['charset'])) {
159 $Settings['charset'] = "ISO-8859-15"; }
160 if(isset($Settings['charset'])) {
161 if($Settings['charset']!="ISO-8859-15"&&$Settings['charset']!="ISO-8859-1"&&
162 $Settings['charset']!="UTF-8"&&$Settings['charset']!="CP866"&&
163 $Settings['charset']!="Windows-1251"&&$Settings['charset']!="Windows-1252"&&
164 $Settings['charset']!="KOI8-R"&&$Settings['charset']!="BIG5"&&
165 $Settings['charset']!="GB2312"&&$Settings['charset']!="BIG5-HKSCS"&&
166 $Settings['charset']!="Shift_JIS"&&$Settings['charset']!="EUC-JP") {
167 $Settings['charset'] = "ISO-8859-15"; } }
168 $chkcharset = $Settings['charset'];
169 if(!in_array("ini_set", $disfunc)) {
170 @ini_set('default_charset', $Settings['charset']); }
171 //session_save_path($SettDir['inc']."temp/");
172 if(!isset($Settings['sqldb'])) {
173 if(file_exists("install.php")) { header('Location: install.php?act=Part1'); die(); }
174 if(!file_exists("install.php")) { header("Content-Type: text/plain; charset=UTF-8");
175 echo "403 Error: Sorry could not find install.php\nTry uploading files again and if that dose not work try download iDB again."; die(); } }
176 if(isset($Settings['sqldb'])) {
177 $deftz = new DateTimeZone(date_default_timezone_get());
178 $defcurtime = new DateTime();
179 $defcurtime->setTimezone($deftz);
180 $utctz = new DateTimeZone("UTC");
181 $utccurtime = new DateTime();
182 $utccurtime->setTimestamp($defcurtime->getTimestamp());
183 $utccurtime->setTimezone($utctz);
184 $servtz = new DateTimeZone($Settings['DefaultTimeZone']);
185 $servcurtime = new DateTime();
186 $servcurtime->setTimestamp($defcurtime->getTimestamp());
187 $servcurtime->setTimezone($servtz);
188 $usercurtime = new DateTime();
189 $usercurtime->setTimestamp($defcurtime->getTimestamp()); }
190 if(!isset($Settings['sqlhost'])) { $Settings['sqlhost'] = "localhost"; }
191 if($Settings['fixpathinfo']=="on") {
192 $_SERVER['PATH_INFO'] = $_SERVER['ORIG_PATH_INFO'];
193 putenv("PATH_INFO=".$_SERVER['ORIG_PATH_INFO']); }
194 // Check to see if variables are set
195 if(!isset($SettDir['inc'])) { $SettDir['inc'] = "inc/"; }
196 if(!isset($SettDir['archive'])) { $SettDir['archive'] = "archive/"; }
197 if(!isset($SettDir['misc'])) { $SettDir['misc'] = "inc/misc/"; }
198 if(!isset($SettDir['sql'])) { $SettDir['sql'] = "inc/misc/sql/"; }
199 if(!isset($SettDir['admin'])) { $SettDir['admin'] = "inc/admin/"; }
200 if(!isset($SettDir['sqldumper'])) { $SettDir['sqldumper'] = "inc/admin/sqldumper/"; }
201 if(!isset($SettDir['mod'])) { $SettDir['mod'] = "inc/mod/"; }
202 if(!isset($SettDir['mplayer'])) { $SettDir['mplayer'] = "inc/mplayer/"; }
203 if(!isset($SettDir['themes'])) { $SettDir['themes'] = "themes/"; }
204 if(!isset($SettDir['maindir'])||!file_exists($SettDir['maindir'])||!is_dir($SettDir['maindir'])) {
205 $SettDir['maindir'] = addslashes(str_replace("\\","/",dirname(__FILE__)."/")); }
206 if(isset($SettDir['maindir'])) { @chdir($SettDir['maindir']); }
207 if(!isset($Settings['use_iniset'])) { $Settings['use_iniset'] = null; }
208 if(!isset($Settings['clean_ob'])) { $Settings['clean_ob'] = "off"; }
209 if(!isset($_SERVER['PATH_INFO'])) { $_SERVER['PATH_INFO'] = null; }
210 if(!isset($_SERVER['HTTP_ACCEPT_ENCODING'])) {
211 $_SERVER['HTTP_ACCEPT_ENCODING'] = null; }
212 if(!isset($_SERVER["HTTP_ACCEPT"])) { $_SERVER["HTTP_ACCEPT"] = null; }
213 if(!isset($_SERVER['HTTP_REFERER'])) { $_SERVER['HTTP_REFERER'] = null; }
214 if(!isset($_GET['page'])) { $_GET['page'] = null; }
215 if(!isset($_GET['act'])) { $_GET['act'] = null; }
216 if(!isset($_POST['act'])) { $_POST['act'] = null; }
217 if(!isset($_GET['modact'])) { $_GET['modact'] = null; }
218 if(!isset($_POST['modact'])) { $_POST['modact'] = null; }
219 if(!isset($_GET['id'])) { $_GET['id'] = null; }
220 if(!isset($_GET['debug'])) { $_GET['debug'] = "off"; }
221 if(!isset($_GET['post'])) { $_GET['post'] = null; }
222 if(!isset($_POST['License'])) { $_POST['License'] = null; }
223 if(!isset($_SERVER['HTTPS'])) { $_SERVER['HTTPS'] = "off"; }
224 if(!isset($Settings['SQLThemes'])) { $Settings['SQLThemes'] = "off"; }
225 if($Settings['SQLThemes']!="on"&&$Settings['SQLThemes']!="off") {
226 $Settings['SQLThemes'] = "off"; }
227 require_once($SettDir['misc'].'utf8.php');
228 require_once($SettDir['inc'].'filename.php');
229 if(!isset($Settings['use_hashtype'])) {
230 $Settings['use_hashtype'] = "sha1"; }
231 if(!function_exists('hash')||!function_exists('hash_algos')) {
232 if($Settings['use_hashtype']!="md5"&&
233 $Settings['use_hashtype']!="sha1"&&
234 $Settings['use_hashtype']!="bcrypt") {
235 $Settings['use_hashtype'] = "sha1"; } }
236 if((function_exists('hash')&&function_exists('hash_algos'))||function_exists('password_hash')) {
237 if(!in_array($Settings['use_hashtype'],hash_algos())&&$Settings['use_hashtype']!="bcrypt") {
238 $Settings['use_hashtype'] = "sha1"; }
239 if($Settings['use_hashtype']!="md2"&&
240 $Settings['use_hashtype']!="md4"&&
241 $Settings['use_hashtype']!="md5"&&
242 $Settings['use_hashtype']!="sha1"&&
243 $Settings['use_hashtype']!="sha224"&&
244 $Settings['use_hashtype']!="sha256"&&
245 $Settings['use_hashtype']!="sha384"&&
246 $Settings['use_hashtype']!="sha512"&&
247 $Settings['use_hashtype']!="sha3-224"&&
248 $Settings['use_hashtype']!="sha3-256"&&
249 $Settings['use_hashtype']!="sha3-384"&&
250 $Settings['use_hashtype']!="sha3-512"&&
251 $Settings['use_hashtype']!="ripemd128"&&
252 $Settings['use_hashtype']!="ripemd160"&&
253 $Settings['use_hashtype']!="ripemd256"&&
254 $Settings['use_hashtype']!="ripemd320"&&
255 $Settings['use_hashtype']!="bcrypt") {
256 $Settings['use_hashtype'] = "sha1"; } }
257 // Check to see if variables are set
258 require_once($SettDir['misc'].'setcheck.php');
259 $dayconv = array("year" => 29030400, "month" => 2419200, "week" => 604800, "day" => 86400, "hour" => 3600, "minute" => 60, "second" => 1);
260 require_once($SettDir['inc'].'function.php');
261 $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)));
262 $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)));
263 if($Settings['enable_pathinfo']=="on") {
264 mrstring(); /* Change Path info to Get Vars :P */ }
265 // Check to see if variables are set
266 $qstrhtml = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
267 if($Settings['enable_https']=="on"&&$_SERVER['HTTPS']=="on") {
268 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
269 $HTTPsTest = parse_url($Settings['idburl']); if($HTTPsTest['scheme']=="http") {
270 $Settings['idburl'] = preg_replace("/http\:\/\//i", "https://", $Settings['idburl']); } } }
271 $cookieDomain = null; $cookieSecure = false;
272 if($Settings['idburl']!=null&&$Settings['idburl']!="localhost") {
273 $URLsTest = parse_url($Settings['idburl']);
274 $cookieDomain = $URLsTest['host'];
275 if($cookieDomain=="localhost") { $cookieDomain = false; }
276 if($Settings['enable_https']=="on") {
277 if($URLsTest['scheme']=="https") { $cookieSecure = true; }
278 if($URLsTest['scheme']!="https") { $cookieSecure = false; } } }
279 if(!in_array("ini_set", $disfunc)) {
280 @ini_set('default_charset', $Settings['charset']); }
281 $File1Name = dirname($_SERVER['SCRIPT_NAME'])."/";
282 $File2Name = $_SERVER['SCRIPT_NAME'];
283 $File3Name=str_replace($File1Name, null, $File2Name);
284 if ($File3Name=="sql.php"||$File3Name=="/sql.php") {
285 header('Location: index.php');
286 exit(); }
287 //error_reporting(E_ERROR);
288 // Check if gzip is on and if user's browser can accept gzip pages
289 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
290 $Settings['use_gzip'] = 'off'; }
291 if($Settings['use_gzip']=="on") {
292 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) {
293 $GZipEncode['Type'] = "gzip"; } else {
294 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) {
295 $GZipEncode['Type'] = "deflate"; } else {
296 $Settings['use_gzip'] = "off"; $GZipEncode['Type'] = "none"; } } }
297 if($Settings['use_gzip']=="gzip") {
298 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "gzip")) { $Settings['use_gzip'] = "on";
299 $GZipEncode['Type'] = "gzip"; } else { $Settings['use_gzip'] = "off"; } }
300 if($Settings['use_gzip']=="deflate") {
301 if(strstr($_SERVER['HTTP_ACCEPT_ENCODING'], "deflate")) { $Settings['use_gzip'] = "on";
302 $GZipEncode['Type'] = "deflate"; } else { $Settings['use_gzip'] = "off"; } }
303 $iWrappers = array(null);
304 function idb_output_handler($buffer) { return $buffer; }
305 function idb_suboutput_handler($buffer) { return $buffer; }
306 if($Settings['clean_ob']=="on") {
307 /* Check for other output handlers/buffers are open
308 and close and get the contents in an array */
309 $numob = count(ob_list_handlers()); $iob = 0;
310 while ($iob < $numob) {
311 $old_ob_var[$iob] = ob_get_clean();
312 ++$iob; } } ob_start("idb_output_handler");
313 if($Settings['use_gzip']=="on") {
314 if($GZipEncode['Type']!="gzip") { if($GZipEncode['Type']!="deflate") { $GZipEncode['Type'] = "gzip"; } }
315 if($GZipEncode['Type']=="gzip") {
316 header("Content-Encoding: gzip"); }
317 if($GZipEncode['Type']=="deflate") {
318 header("Content-Encoding: deflate"); } }
319 /* if(eregi("msie",$browser) && !eregi("opera",$browser)){
320 header('P3P: CP="NOI ADM DEV PSAi COM NAV OUR OTRo STP IND DEM"'); } */
321 // Some http stuff
322 $SQLStat = sql_connect_db($Settings['sqlhost'],$Settings['sqluser'],$Settings['sqlpass'],$Settings['sqldb']);
323 if(isset($Settings['sql_collate'])&&!isset($Settings['sql_charset'])) {
324 if($Settings['sql_collate']=="ascii_bin"||
325 $Settings['sql_collate']=="ascii_generel_ci") {
326 $Settings['sql_charset'] = "ascii"; }
327 if($Settings['sql_collate']=="latin1_bin"||
328 $Settings['sql_collate']=="latin1_general_ci"||
329 $Settings['sql_collate']=="latin1_general_cs") {
330 $Settings['sql_charset'] = "latin1"; }
331 if($Settings['sql_collate']=="utf8_bin"||
332 $Settings['sql_collate']=="utf8_general_ci"||
333 $Settings['sql_collate']=="utf8_unicode_ci"||
334 $Settings['sql_collate']=="utf8mb4_bin"||
335 $Settings['sql_collate']=="utf8mb4_general_ci"||
336 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
337 $Settings['sql_charset'] = "utf8"; } }
338 if(isset($Settings['sql_collate'])&&isset($Settings['sql_charset'])) {
339 if($Settings['sql_charset']=="ascii") {
340 if($Settings['sql_collate']!="ascii_bin"&&
341 $Settings['sql_collate']!="ascii_generel_ci") {
342 $Settings['sql_collate'] = "ascii_generel_ci"; } }
343 if($Settings['sql_charset']=="latin1") {
344 if($Settings['sql_collate']!="latin1_bin"&&
345 $Settings['sql_collate']!="latin1_general_ci"&&
346 $Settings['sql_collate']!="latin1_general_cs") {
347 $Settings['sql_collate'] = "latin1_general_ci"; } }
348 if($Settings['sql_charset']=="utf8" || $Settings['sql_charset']=="utf8mb4") {
349 if($Settings['sql_collate']!="utf8_bin"&&
350 $Settings['sql_collate']!="utf8_general_ci"&&
351 $Settings['sql_collate']!="utf8_unicode_ci"&&
352 $Settings['sql_collate']!="utf8mb4_bin"&&
353 $Settings['sql_collate']!="utf8mb4_general_ci"&&
354 $Settings['sql_collate']!="utf8mb4_unicode_ci") {
355 $Settings['sql_collate'] = "utf8mb4_unicode_ci"; } }
356 if($Settings['sql_collate']=="utf8_bin"||
357 $Settings['sql_collate']=="utf8_general_ci"||
358 $Settings['sql_collate']=="utf8_unicode_ci") {
359 $Settings['sql_charset'] = "utf8"; }
360 if($Settings['sql_collate']=="utf8mb4_bin"||
361 $Settings['sql_collate']=="utf8mb4_general_ci"||
362 $Settings['sql_collate']=="utf8mb4_unicode_ci") {
363 $Settings['sql_charset'] = "utf8mb4"; }
364 $SQLCollate = $Settings['sql_collate'];
365 $SQLCharset = $Settings['sql_charset']; }
366 if(!isset($Settings['sql_collate'])||!isset($Settings['sql_charset'])) {
367 $SQLCollate = "latin1_general_ci";
368 $SQLCharset = "latin1";
369 if($Settings['charset']=="ISO-8859-1") {
370 $SQLCollate = "latin1_general_ci";
371 $SQLCharset = "latin1"; }
372 if($Settings['charset']=="ISO-8859-15") {
373 $SQLCollate = "latin1_general_ci";
374 $SQLCharset = "latin1"; }
375 if($Settings['charset']=="UTF-8") {
376 $SQLCollate = "utf8mb4_unicode_ci";
377 $SQLCharset = "utf8mb4"; }
378 $Settings['sql_collate'] = $SQLCollate;
379 $Settings['sql_charset'] = $SQLCharset; }
380 sql_set_charset($SQLCharset,$SQLStat);
381 if($SQLStat===false) {
382 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
383 ob_clean(); echo "Sorry could not connect to sql database.\nContact the board admin about error. Error log below.";
384 echo "\n".sql_errorno($SQLStat); $urlstatus = 503;
385 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
386 $sqltable = $Settings['sqltable'];
387 $temp_user_ip = $_SERVER['REMOTE_ADDR'];
388 if(!isset($_SERVER['HTTP_USER_AGENT'])) {
389 $_SERVER['HTTP_USER_AGENT'] = ""; }
390 if(strpos($_SERVER['HTTP_USER_AGENT'], "msie") &&
391 !strpos($_SERVER['HTTP_USER_AGENT'], "opera")){
392 header("X-UA-Compatible: IE=Edge"); }
393 if(strpos($_SERVER['HTTP_USER_AGENT'], "chromeframe")) {
394 header("X-UA-Compatible: IE=Edge,chrome=1"); }
395 $temp_user_agent = $_SERVER['HTTP_USER_AGENT'];
396 if($Settings['file_ext']!="no+ext"&&$Settings['file_ext']!="no ext") {
397 $MkIndexFile = $exfile['index'].$Settings['file_ext']; }
398 if($Settings['file_ext']=="no+ext"||$Settings['file_ext']=="no ext") {
399 $MkIndexFile = $exfile['index']; }
400 $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']."\";";
401 $alt_temp_session_data['ViewingPage'] = "?act=view";
402 $alt_temp_session_data['ViewingFile'] = $MkIndexFile;
403 $alt_temp_session_data['PreViewingTitle'] = "Viewing";
404 $alt_temp_session_data['ViewingTitle'] = "Board index";
405 $alt_temp_session_data['UserID'] = "0";
406 $alt_temp_session_data['UserIP'] = $_SERVER['REMOTE_ADDR'];
407 $alt_temp_session_data['UserGroupID'] = "4";
408 $alt_temp_session_data['UserTimeZone'] = $Settings['DefaultTimeZone'];
409 $alttemp_session_data = serialize($alt_temp_session_data);
410 $alt_temp_session_data = $alttemp_session_data;
411 $alttemp_session_data = null;
412 $SQLSType = $Settings['sqltype'];
413 //Session Open Function
414 function sql_session_open($save_path, $session_name ) {
415 global $sess_save_path;
416 $sess_save_path = $save_path;
417 return true; }
418 //Session Close Function
419 $iDBSessCloseDB = true;
420 function sql_session_close() {
421 global $SQLStat,$iDBSessCloseDB;
422 if($iDBSessCloseDB===true) {
423 sql_disconnect_db($SQLStat); }
424 return true; }
425 //Session Read Function
426 function sql_session_read($id) {
427 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent,$temp_session_data,$alt_temp_session_data;
428 $result = sql_query(sql_pre_query("SELECT * FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '%s'", array($id)),$SQLStat);
429 if (!sql_num_rows($result)) {
430 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\"<>'%s' AND \"ip_address\"='%s' AND \"user_agent\"='%s'", array($id,$temp_user_ip,$temp_user_agent)),$SQLStat);
431 $utctz = new DateTimeZone("UTC");
432 $utccurtime = new DateTime();
433 $utccurtime->setTimezone($utctz);
434 $time = $utccurtime->getTimestamp();
435 sql_query(sql_pre_query("INSERT INTO \"".$sqltable."sessions\" (\"session_id\", \"session_data\", \"serialized_data\", \"user_agent\", \"ip_address\", \"expires\") VALUES\n".
436 "('%s', '%s', '%s', '%s', '%s', %i)", array($id,$temp_session_data,$alt_temp_session_data,$temp_user_agent,$temp_user_ip,$time)),$SQLStat);
437 return '';
438 } else {
439 $utctz = new DateTimeZone("UTC");
440 $utccurtime = new DateTime();
441 $utccurtime->setTimezone($utctz);
442 $time = $utccurtime->getTimestamp();
443 $predata = sql_num_rows($result);
444 $data = "";
445 if($predata > 0) {
446 $row = sql_fetch_assoc($result);
447 $data = $row['session_data']; }
448 /*sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,$time,$id)),$SQLStat);*/
449 return $data; } }
450 //Session Write Function
451 function sql_session_write($id,$data) {
452 global $sqltable,$SQLStat,$SQLSType,$temp_user_ip,$temp_user_agent;
453 $utctz = new DateTimeZone("UTC");
454 $utccurtime = new DateTime();
455 $utccurtime->setTimezone($utctz);
456 $time = $utccurtime->getTimestamp();
457 $rs = sql_query(sql_pre_query("UPDATE \"".$sqltable."sessions\" SET \"session_data\"='%s',\"serialized_data\"='%s',\"user_agent\"='%s',\"ip_address\"='%s',\"expires\"=%i WHERE \"session_id\"='%s'", array($data,serialize($_SESSION),$temp_user_agent,$temp_user_ip,$time,$id)),$SQLStat);
458 return true; }
459 //Session Destroy Function
460 function sql_session_destroy($id) {
461 global $sqltable,$SQLStat;
462 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"session_id\" = '$id'", array($id)),$SQLStat);
463 return true; }
464 //Session Garbage Collection Function
465 function sql_session_gc($maxlifetime) {
466 global $sqltable,$SQLStat;
467 $utctz = new DateTimeZone("UTC");
468 $utccurtime = new DateTime();
469 $utccurtime->setTimezone($utctz);
470 $time = $utccurtime->getTimestamp() - $maxlifetime;
471 //sql_query(sql_pre_query('DELETE FROM \"'.$sqltable.'sessions\" WHERE \"expires\" < UNIX_TIMESTAMP();', array(null)),$SQLStat);
472 sql_query(sql_pre_query("DELETE FROM \"".$sqltable."sessions\" WHERE \"expires\" < %i", array($time)),$SQLStat);
473 return true; }
474 if (session_id()) { session_destroy(); }
475 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
476 if($cookieDomain==null) {
477 session_set_cookie_params(0, $cbasedir); }
478 if($cookieDomain!=null) {
479 if($cookieSecure===true) {
480 session_set_cookie_params(0, $cbasedir, $cookieDomain, 1); }
481 if($cookieSecure===false) {
482 session_set_cookie_params(0, $cbasedir, $cookieDomain); } }
483 session_cache_limiter("private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
484 header("Cache-Control: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
485 header("Pragma: private, no-cache, no-store, must-revalidate, pre-check=0, post-check=0, max-age=0");
486 header("P3P: CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\"");
487 header("Date: ".gmdate("D, d M Y H:i:s")." GMT");
488 header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
489 header("Expires: ".gmdate("D, d M Y H:i:s")." GMT");
490 if(!isset($_COOKIE[$Settings['sqltable']."sess"])) {
491 $exptime = $utccurtime->getTimestamp() - ini_get("session.gc_maxlifetime");
492 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); }
493 if(!isset($_SESSION['CheckCookie'])) {
494 if(isset($_COOKIE['SessPass'])&&isset($_COOKIE['MemberName'])) {
495 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
496 session_name($Settings['sqltable']."sess");
497 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
498 session_start([
499 'use_trans_sid' => false,
500 'use_cookies' => true,
501 'use_only_cookies' => true,
502 'gc_probability' => 1,
503 'gc_divisor' => 100,
504 'gc_maxlifetime' => 1440,
505 'hash_function' => 1,
506 'hash_bits_per_character' => 6,
507 'name' => $Settings['sqltable']."sess",
508 ]); }
509 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
510 $iDBSessCloseDB = false;
511 $_SESSION['ShowActHidden'] = "no";
512 output_reset_rewrite_vars();
513 require($SettDir['inc'].'prelogin.php');
514 session_write_close(); } }
515 session_set_save_handler("sql_session_open", "sql_session_close", "sql_session_read", "sql_session_write", "sql_session_destroy", "sql_session_gc");
516 session_name($Settings['sqltable']."sess");
517 if (version_compare(phpversion(), '7.0', '<')) { session_start(); } else {
518 session_start([
519 'use_trans_sid' => false,
520 'use_cookies' => true,
521 'use_only_cookies' => true,
522 'gc_probability' => 1,
523 'gc_divisor' => 100,
524 'gc_maxlifetime' => 1440,
525 'hash_function' => 1,
526 'hash_bits_per_character' => 6,
527 'name' => $Settings['sqltable']."sess",
528 ]); }
529 if(!isset($_SESSION['UserFormID'])) { $_SESSION['UserFormID'] = null; }
530 $iDBSessCloseDB = true;
531 output_reset_rewrite_vars();
532 //@register_shutdown_function("session_write_close");
533 //header("Set-Cookie: PHPSESSID=" . session_id() . "; path=".$cbasedir);
534 if(!in_array("ini_set", $disfunc)) {
535 // Set user agent if we can use ini_set and have to do any http requests. :P
536 $iverstring = "FR 0.0.0 ".$VER2[2]." 0";
537 if($Settings['hideverinfohttp']=="off") {
538 $iverstring = $VER2[1]." ".$VER1[0].".".$VER1[1].".".$VER1[2]." ".$VER2[2]." ".$SubVerN; }
539 if($Settings['hideverinfohttp']=="on") {
540 $iverstring = "FR 0.0.0 ".$VER2[2]." 0"; }
541 $qstrtest = htmlentities($Settings['qstr'], ENT_QUOTES, $Settings['charset']);
542 $qseptest = htmlentities($Settings['qsep'], ENT_QUOTES, $Settings['charset']);
543 $isiteurl = $Settings['idburl'].url_maker($exfile['index'],$Settings['file_ext'],"act=view",$Settings['qstr'],$Settings['qsep'],$prexqstr['index'],$exqstr['index']);
544 @ini_set("user_agent", "Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")");
545 if (function_exists("stream_context_create")) {
546 $iopts = array(
547 'http' => array(
548 'method' => "GET",
549 'header' => "Accept-Language: *\r\n".
550 "User-Agent: Mozilla/5.0 (compatible; ".$UserAgentName."/".$iverstring."; +".$isiteurl.")\r\n".
551 "Accept: */*\r\n".
552 "Connection: keep-alive\r\n".
553 "Referer: ".$isiteurl."\r\n".
554 "From: ".$isiteurl."\r\n".
555 "Via: ".$_SERVER['REMOTE_ADDR']."\r\n".
556 "Forwarded: ".$_SERVER['REMOTE_ADDR']."\r\n".
557 "X-Forwarded-For: ".$_SERVER['REMOTE_ADDR']."\r\n".
558 "Client-IP: ".$_SERVER['REMOTE_ADDR']."\r\n"
561 $icontext = stream_context_create($iopts);
562 function file_get_contents_alt($filename,$use_include_path=null,$offset=-1,$maxlen=null) {
563 global $icontext;
564 if($maxlen!==null) {
565 return file_get_contents($filename,$use_include_path,$icontext,$offset,$maxlen); }
566 if($maxlen===null) {
567 return file_get_contents($filename,$use_include_path,$icontext,$offset); } } } }
568 $iDBVerName = $VerCheckName."|".$VER2[1]."|".$VER1[0].".".$VER1[1].".".$VER1[2]."|".$VER2[2]."|".$SubVerN;
570 This way checks iDB version by sending the iDBVerName to the iDB Version Checker.
571 $Settings['vercheck'] = 1;
572 This way checks iDB version by sending the board url to the iDB Version Checker.
573 $Settings['vercheck'] = 2;
575 if(!isset($Settings['vercheck'])) {
576 $Settings['vercheck'] = 2; }
577 if($Settings['vercheck']!=1&&
578 $Settings['vercheck']!=2) {
579 $Settings['vercheck'] = 2; }
580 if($Settings['vercheck']===2) {
581 if($_GET['act']=="vercheckxsl") {
582 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
583 header("Content-Type: application/xml; charset=".$Settings['charset']); }
584 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
585 xml_doc_start("1.0",$Settings['charset']);
586 echo "\n"; ?>
587 <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
589 <xsl:template match="/">
590 <html xsl:version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns="http://www.w3.org/1999/xhtml">
591 <body style="font-family:Arial;font-size:12pt;background-color:#EEEEEE">
592 <xsl:for-each select="versioninfo/version">
593 <div style="background-color:teal;color:white;padding:4px">
594 <span style="font-weight:bold"><xsl:value-of select="vname"/></span>
595 </div>
596 <div style="margin-left:20px;margin-bottom:1em;font-size:10pt">
597 <span style="font-style:italic">
598 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>
599 </div>
600 </xsl:for-each>
601 </body>
602 </html>
603 </xsl:template>
605 </xsl:stylesheet>
606 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
607 if($_GET['act']=="versioninfo") {
608 if(stristr($_SERVER["HTTP_ACCEPT"],"application/xml") ) {
609 header("Content-Type: application/xml; charset=".$Settings['charset']); }
610 else { header("Content-Type: text/xml; charset=".$Settings['charset']); }
611 xml_doc_start("1.0",$Settings['charset']);
612 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"; ?>
614 <!DOCTYPE versioninfo [
615 <!ELEMENT versioninfo (version*)>
616 <!ELEMENT version (charset,title,name,vname)>
617 <!ELEMENT charset (#PCDATA)>
618 <!ELEMENT title (#PCDATA)>
619 <!ELEMENT name (#PCDATA)>
620 <!ELEMENT vname (#PCDATA)>
623 <versioninfo>
625 <version>
626 <charset><?php echo $Settings['charset']; ?></charset>
627 <title><?php echo $Settings['board_name']; ?></title>
628 <?php echo "<name>".$iDBVerName."</name>\n"; ?>
629 <vname><?php echo $VerCheckName; ?> Version Checker</vname>
630 </version>
632 </versioninfo>
633 <?php gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
634 if($Settings['vercheck']===1) {
635 if($_GET['act']=="versioninfo") { header("Content-Type: text/plain; charset=UTF-8");
636 header("Location: ".$VerCheckURL."&name=".urlencode($iDBVerName)); $urlstatus = 302;
637 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); } }
638 if($_GET['act']=="homepage") { header("Content-Type: text/plain; charset=UTF-8");
639 header("Location: ".$Settings['weburl']); $urlstatus = 302;
640 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
641 if($_GET['act']=="bsdl"||$_GET['act']=="BSDL"||$_GET['act']=="license"||
642 $_GET['act']=="LICENSE"||$_GET['act']=="License") { $_GET['act']="bsd"; }
643 if($_GET['act']=="bsd") {
644 header("Content-Type: text/plain; charset=".$Settings['charset']);
645 require("LICENSE"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
646 if($_GET['act']=="README"||$_GET['act']=="ReadME") { $_GET['act']="readme"; }
647 if($_GET['act']=="readme"||$_GET['act']=="ReadMe") {
648 header("Content-Type: text/plain; charset=".$Settings['charset']);
649 require("README"); gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
650 if($_GET['act']=="js"||$_GET['act']=="javascript") {
651 header("Content-Script-Type: text/javascript");
652 if(stristr($_SERVER["HTTP_ACCEPT"],"application/x-javascript") ) {
653 header("Content-Type: application/x-javascript; charset=".$Settings['charset']); } else {
654 if(stristr($_SERVER["HTTP_ACCEPT"],"application/javascript") ) {
655 header("Content-Type: application/javascript; charset=".$Settings['charset']); } else {
656 header("Content-Type: text/javascript; charset=".$Settings['charset']); } }
657 require($SettDir['inc'].'javascript.php');
658 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); die(); }
659 if($Settings['use_captcha']=="on") {
660 if($_GET['act']=="MkCaptcha"||$_GET['act']=="Captcha") {
661 if($Settings['captcha_clean']=="on") { ob_clean(); }
662 require($SettDir['inc']."captcha.php");
663 $aFontDir = dirname(__FILE__)."/inc/fonts/";
664 $aFonts = array($aFontDir.'VeraBd.ttf', $aFontDir.'VeraBI.ttf', $aFontDir.'VeraIt.ttf', $aFontDir.'Vera.ttf');
665 $oPhpCaptcha = new PhpCaptcha($aFonts, 200, 60);
666 $RNumSize = rand(7,17); $i=0; $RandNum = null;
667 while ($i <= $RNumSize) {
668 $RandNum=$RandNum.dechex(rand(1,15)); ++$i; }
669 $RandNum=strtoupper($RandNum);
670 $oPhpCaptcha->SetOwnerText("Fake Code: ".$RandNum);
671 $oPhpCaptcha->UseColour(true);
672 $oPhpCaptcha->Create(); session_write_close(); die(); } }
673 require($SettDir['inc'].'groupsetup.php');
674 if($Settings['board_offline']=="on"&&$GroupInfo['CanViewOffLine']!="yes") {
675 header("Content-Type: text/plain; charset=".$Settings['charset']); sql_free_result($peresult);
676 ob_clean(); if(!isset($Settings['offline_text'])) {
677 echo "Sorry the board is off line.\nIf you are a admin you can login by the admin cp."; }
678 if(isset($Settings['offline_text'])) { echo $Settings['offline_text']; } $urlstatus = 503;
679 //echo "\n".sql_errorno($SQLStat);
680 gzip_page($Settings['use_gzip'],$GZipEncode['Type']); session_write_close(); die(); }
681 //Time Format Set
682 if(!isset($_SESSION['iDBDateFormat'])) {
683 if(isset($Settings['idb_date_format'])) {
684 $_SESSION['iDBDateFormat'] = $Settings['idb_date_format'];
685 if(!isset($Settings['idb_date_format'])) {
686 $_SESSION['iDBDateFormat'] = "g:i A"; } } }
687 if(!isset($_SESSION['iDBTimeFormat'])) {
688 if(isset($Settings['idb_time_format'])) {
689 $_SESSION['iDBTimeFormat'] = $Settings['idb_time_format'];
690 if(!isset($Settings['idb_time_format'])) {
691 $_SESSION['iDBTimeFormat'] = "F j Y"; } } }
692 //Time Zone Set
693 if(!isset($_SESSION['UserTimeZone'])) {
694 if(isset($Settings['DefaultTimeZone'])) {
695 $_SESSION['UserTimeZone'] = $Settings['DefaultTimeZone'];
696 if(!isset($Settings['DefaultTimeZone'])) {
697 $_SESSION['UserTimeZone'] = date_default_timezone_get(); } } }
698 $usertz = new DateTimeZone($_SESSION['UserTimeZone']);
699 $usercurtime->setTimestamp($defcurtime->getTimestamp());
700 $usercurtime->setTimezone($usertz);
701 // Guest Stuff
702 if(isset($_SESSION['MemberName'])||
703 isset($_COOKIE['MemberName'])) {
704 $_SESSION['GuestName'] = null;
705 $_COOKIE['GuestName'] = null; }
706 if(!isset($_SESSION['MemberName'])&&!isset($_COOKIE['MemberName'])) {
707 if(!isset($_SESSION['GuestName'])&&isset($_COOKIE['GuestName'])) {
708 $_SESSION['GuestName'] = $_COOKIE['GuestName']; } }
709 if(!isset($_SESSION['LastPostTime'])) { $_SESSION['LastPostTime'] = "0"; }
710 // Skin Stuff
711 if(!isset($_SESSION['Theme'])) { $_SESSION['Theme'] = null; }
712 if(!isset($_GET['theme'])) { $_GET['theme'] = null; }
713 if(!isset($_POST['theme'])) { $_POST['theme'] = null; }
714 if(!isset($_GET['skin'])) { $_GET['skin'] = null; }
715 if(!isset($_POST['skin'])) { $_POST['skin'] = null; }
716 if(!isset($_GET['style'])) { $_GET['style'] = null; }
717 if(!isset($_POST['style'])) { $_POST['style'] = null; }
718 if(!isset($_GET['css'])) { $_GET['css'] = null; }
719 if(!isset($_POST['css'])) { $_POST['css'] = null; }
720 if($_GET['theme']==null) {
721 if($_POST['theme']!=null) {
722 $_GET['theme'] = $_POST['theme']; }
723 if($_POST['skin']!=null) {
724 $_GET['theme'] = $_POST['skin']; }
725 if($_POST['style']!=null) {
726 $_GET['theme'] = $_POST['style']; }
727 if($_POST['css']!=null) {
728 $_GET['theme'] = $_POST['css']; }
729 if($_GET['skin']!=null) {
730 $_GET['theme'] = $_GET['skin']; }
731 if($_GET['style']!=null) {
732 $_GET['theme'] = $_GET['style']; }
733 if($_GET['css']!=null) {
734 $_GET['theme'] = $_GET['css']; } }
735 if($Settings['SQLThemes']=="off") {
736 if($_GET['theme']!=null) {
737 $_GET['theme'] = chack_themes($_GET['theme']);
738 if($_GET['theme']=="../"||$_GET['theme']=="./") {
739 $_GET['theme']=$Settings['DefaultTheme']; $_SESSION['Theme']=$Settings['DefaultTheme']; }
740 if (file_exists($SettDir['themes'].$_GET['theme']."/settings.php")) {
741 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
742 $NewDay=$utccurtime->getTimestamp();
743 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
744 sql_query($qnewskin,$SQLStat); }
745 /* The file Theme Exists */ }
746 else { $_GET['theme'] = $Settings['DefaultTheme'];
747 $_SESSION['Theme'] = $Settings['DefaultTheme'];
748 /* The file Theme Dose Not Exists */ } }
749 if($_GET['theme']==null) {
750 if($_SESSION['Theme']!=null) {
751 $OldTheme = $_SESSION['Theme'];
752 $_SESSION['Theme'] = chack_themes($_SESSION['Theme']);
753 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
754 if($OldTheme!=$_SESSION['Theme']) {
755 $NewDay=$utccurtime->getTimestamp();
756 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
757 sql_query($qnewskin,$SQLStat); } }
758 $_GET['theme']=$_SESSION['Theme']; }
759 if($_SESSION['Theme']==null) {
760 $_SESSION['Theme']=$Settings['DefaultTheme'];
761 $_GET['theme']=$Settings['DefaultTheme']; } }
762 $PreSkin['skindir1'] = $_SESSION['Theme'];
763 $PreSkin['skindir2'] = $SettDir['themes'].$_SESSION['Theme'];
764 require($SettDir['themes'].$_GET['theme']."/settings.php"); }
765 if($Settings['SQLThemes']=="on") {
766 if($_GET['theme']==null&&$_SESSION['Theme']==null) {
767 $_GET['theme'] = $Settings['DefaultTheme'];
768 $_SESSION['Theme'] = $Settings['DefaultTheme']; }
769 if($_GET['theme']!=null) {
770 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme'])); }
771 if($_GET['theme']==null) {
772 if($_SESSION['Theme']!=null) {
773 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_SESSION['Theme'])); } }
774 $themeresult=sql_query($themequery,$SQLStat);
775 $themenum=sql_num_rows($themeresult);
776 if($themenum<=0) {
777 $_GET['theme'] = $Settings['DefaultTheme'];
778 $_SESSION['Theme'] = $Settings['DefaultTheme'];
779 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
780 $NewDay=$utccurtime->getTimestamp();
781 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_SESSION['Theme'],$NewDay,$_SESSION['UserID']));
782 sql_query($qnewskin,$SQLStat); }
783 $themequery = sql_pre_query("SELECT * FROM \"".$Settings['sqltable']."themes\" WHERE \"Name\"='%s'", array($_GET['theme']));
784 $themeresult=sql_query($themequery,$SQLStat);
785 $themenum=sql_num_rows($themeresult); }
786 else {
787 if($_GET['theme']==null) {
788 if($_SESSION['Theme']!=null) {
789 $_GET['theme'] = $_SESSION['Theme']; } }
790 if($_SESSION['UserGroup']!=$Settings['GuestGroup']) {
791 $NewDay=$utccurtime->getTimestamp();
792 $qnewskin = sql_pre_query("UPDATE \"".$Settings['sqltable']."members\" SET \"UseTheme\"='%s',\"LastActive\"='%s' WHERE \"id\"=%i", array($_GET['theme'],$NewDay,$_SESSION['UserID']));
793 sql_query($qnewskin,$SQLStat); } }
794 require($SettDir['inc'].'sqlthemes.php');
795 sql_free_result($themeresult); }
796 $_SESSION['Theme'] = $_GET['theme'];
797 function get_theme_values($matches) {
798 global $ThemeSet;
799 $return_text = null;
800 if(isset($ThemeSet[$matches[1]])) { $return_text = $ThemeSet[$matches[1]]; }
801 if(!isset($ThemeSet[$matches[1]])) { $return_text = null; }
802 return $return_text; }
803 foreach($ThemeSet AS $key => $value) {
804 $ThemeSet[$key] = preg_replace("/%%/s", "{percent}p", $ThemeSet[$key]);
805 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}T/s", "get_theme_values", $ThemeSet[$key]);
806 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}e/s", "get_env_values", $ThemeSet[$key]);
807 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}i/s", "get_server_values", $ThemeSet[$key]);
808 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}s/s", "get_setting_values", $ThemeSet[$key]);
809 $ThemeSet[$key] = preg_replace_callback("/%\{([^\}]*)\}t/s", "get_time", $ThemeSet[$key]);
810 $ThemeSet[$key] = preg_replace("/\{percent\}p/s", "%", $ThemeSet[$key]); }
811 if(!isset($ThemeSet['TableStyle'])) {
812 $ThemeSet['TableStyle'] = "table"; }
813 if(isset($ThemeSet['TableStyle'])) {
814 if($ThemeSet['TableStyle']!="div"&&
815 $ThemeSet['TableStyle']!="table") {
816 $ThemeSet['TableStyle'] = "table"; } }
817 if(!isset($_SESSION['DBName'])) { $_SESSION['DBName'] = null; }
818 if($_SESSION['DBName']==null) {
819 $_SESSION['DBName'] = $Settings['sqldb']; }
820 if($_SESSION['DBName']!=null) {
821 if($_SESSION['DBName']!=$Settings['sqldb']) {
822 redirect("location",$rbasedir.url_maker($exfile['member'],$Settings['file_ext'],"act=logout",$Settings['qstr'],$Settings['qsep'],$prexqstr['member'],$exqstr['member'],false)); } }