-
Notifications
You must be signed in to change notification settings - Fork 0
/
_functions.php
613 lines (501 loc) · 16.9 KB
/
_functions.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
<?php
/*
##########################################################################
# #
# Version 4 / / / #
# -----------__---/__---__------__----__---/---/- #
# | /| / /___) / ) (_ ` / ) /___) / / #
# _|/_|/__(___ _(___/_(__)___/___/_(___ _/___/___ #
# Free Content / Management System #
# / #
# #
# #
# Copyright 2005-2015 by webspell.org #
# #
# visit webSPELL.org, webspell.info to get webSPELL for free #
# - Script runs under the GNU GENERAL PUBLIC LICENSE #
# - It's NOT allowed to remove this copyright-tag #
# -- http://www.fsf.org/licensing/licenses/gpl.html #
# #
# Code based on WebSPELL Clanpackage (Michael Gruber - webspell.at), #
# Far Development by Development Team - webspell.org #
# #
# visit webspell.org #
# #
##########################################################################
*/
// -- LOGIN SESSION -- //
systeminc('session');
systeminc('ip');
// -- GLOBAL WEBSPELL FUNCTIONS -- //
function makepagelink($link, $page, $pages, $sub = '')
{
if ($pages < 2) {
return '';
}
$pageLinkArray = array();
if ($page != 1) {
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=1">«</a></li>';
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . ($page - 1) . '">‹</a></li>';
}
if ($page >= 6) {
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . ($page - 5) . '">...</a></li>';
}
if ($page + 4 >= $pages) {
$pagex = $pages;
} else {
$pagex = $page + 4;
}
$start = (($page - 4) > 0) ? ($page - 4) : 1;
for ($i = $start; $i <= $pagex; $i++) {
if ($i == $page) {
$pageLinkArray[] = '<li class="active"><a href="#" aria-label="Previous"><span aria-hidden="true">' . $i . '</span></a></li>';
} else {
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . $i . '">' . $i . '</a></li>';
}
}
if (($pages - $page) >= 5) {
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . ($page + 5) . '">...</a></li>';
}
if ($page != $pages) {
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . ($page + 1) . '">›</a></li>';
$pageLinkArray[] = '<li><a href="' . $link . '&' . $sub . 'page=' . $pages . '">»</a></li>';
}
return '<nav><ul class="pagination pagination-sm">' . implode('', $pageLinkArray) . '</ul></nav>';
}
function str_break($str, $maxlen)
{
$nobr = 0;
$str_br = '';
$len = mb_strlen($str);
for ($i = 0; $i < $len; $i++) {
$char = mb_substr($str, $i, 1);
if (($char != ' ') && ($char != '-') && ($char != "\n")) {
$nobr++;
} else {
$nobr = 0;
if ($maxlen + $i > $len) {
$str_br .= mb_substr($str, $i);
break;
}
}
if ($nobr > $maxlen) {
$str_br .= '- ' . $char;
$nobr = 1;
} else {
$str_br .= $char;
}
}
return $str_br;
}
function substri_count_array($haystack, $needle)
{
$return = 0;
foreach ($haystack as $value) {
if (is_array($value)) {
$return += substri_count_array($value, $needle);
} else {
$return += substr_count(strtolower($value), strtolower($needle));
}
}
return $return;
}
function js_replace($string)
{
$output = preg_replace("/(\\\)/si", '\\\\\1', $string);
return str_replace(
array("\r\n", "\n", "'", "<script>", "</script>", "<noscript>", "</noscript>"),
array("\\n", "\\n", "\'", "\\x3Cscript\\x3E", "\\x3C/script\\x3E", "\\x3Cnoscript\\x3E", "\\x3C/noscript\\x3E"),
$output
);
}
function percent($sub, $total, $dec)
{
if ($sub) {
$perc = $sub / $total * 100;
return round($perc, $dec);
} else {
return 0;
}
}
function showlock($reason)
{
$gettitle = mysqli_fetch_array(safe_query("SELECT title FROM `" . PREFIX . "styles`"));
$pagetitle = $gettitle['title'];
$data_array = array();
$data_array['$pagetitle'] = $pagetitle;
if (isset($GLOBALS['_modRewrite']) && $GLOBALS['_modRewrite']->enabled()) {
$data_array['$rewriteBase'] = $GLOBALS['_modRewrite']->getRewriteBase();
} else {
$data_array['$rewriteBase'] = '';
}
$data_array['$reason'] = $reason;
$lock = $GLOBALS["_template"]->replaceTemplate("lock", $data_array);
die($lock);
}
function checkenv($systemvar, $checkfor)
{
return stristr(ini_get($systemvar), $checkfor);
}
function mail_protect($mailaddress)
{
$protected_mail = "";
$arr = unpack("C*", $mailaddress);
foreach ($arr as $entry) {
$protected_mail .= sprintf("%%%X", $entry);
}
return $protected_mail;
}
function validate_url($url)
{
return preg_match(
// @codingStandardsIgnoreStart
"/^(ht|f)tps?:\/\/([^:@]+:[^:@]+@)?(?!\.)(\.?(?!-)[0-9\p{L}-]+(?<!-))+(:[0-9]{2,5})?(\/[^#\?]*(\?[^#\?]*)?(#.*)?)?$/sui",
// @codingStandardsIgnoreEnd
$url
);
}
function validate_email($email)
{
return preg_match(
// @codingStandardsIgnoreStart
"/^(?!\.)(\.?[\p{L}0-9!#\$%&'\*\+\/=\?^_`\{\|}~-]+)+@(?!\.)(\.?(?!-)[0-9\p{L}-]+(?<!-))+\.[\p{L}0-9]{2,}$/sui",
// @codingStandardsIgnoreEnd
$email
);
}
if (!function_exists('array_combine')) {
function array_combine($keyarray, $valuearray)
{
$keys = array();
$values = array();
$result = array();
foreach ($keyarray as $key) {
$keys[] = $key;
}
foreach ($valuearray as $value) {
$values[] = $value;
}
foreach ($keys as $access => $resultkey) {
$result[$resultkey] = $values[$access];
}
return $result;
}
}
if (!function_exists("hash_equals")) {
function hash_equals($known_str, $user_str)
{
$result = 0;
if (!is_string($known_str) || !is_string($user_str)) {
return false;
}
if (strlen($known_str) != strlen($user_str)) {
return false;
}
for ($j = 0; $j < strlen($known_str); $j++) {
$result |= ord($known_str[$j]) ^ ord($user_str[$j]);
}
return $result === 0;
}
}
/* counts empty variables in an array */
function countempty($checkarray)
{
$ret = 0;
foreach ($checkarray as $value) {
if (is_array($value)) {
$ret += countempty($value);
} else if (trim($value) == "") {
$ret++;
}
}
return $ret;
}
/* checks, if given request-variables are empty */
function checkforempty($valuearray)
{
$check = array();
foreach ($valuearray as $value) {
$check[] = $_REQUEST[$value];
}
if (countempty($check) > 0) {
return false;
}
return true;
}
// -- Convenience functions -- //
systeminc('func/convenience');
// -- FILESYSTEM -- //
systeminc('func/filesystem');
// -- DATE-TIME INFORMATION -- //
systeminc('func/datetime');
// -- USER INFORMATION -- //
systeminc('func/user');
// -- ACCESS INFORMATION -- //
systeminc('func/useraccess');
// -- MESSENGER INFORMATION -- //
systeminc('func/messenger');
// -- NEWS INFORMATION -- //
systeminc('func/news');
// -- FILES INFORMATION -- //
systeminc('func/files');
// -- GAME INFORMATION -- //
systeminc('func/game');
// -- BOARD INFORMATION -- //
systeminc('func/board');
// -- Page INFORMATION -- //
systeminc('func/page');
// -- CAPTCHA -- //
systeminc('func/captcha');
// -- LANGUAGE SYSTEM -- //
systeminc('func/language');
$_language = new \webspell\Language;
$_language->setLanguage($default_language);
// -- TEMPLATE SYSTEM -- //
systeminc('func/template');
if (!stristr($_SERVER['SCRIPT_NAME'], '/admin/')) {
$_template = new \webspell\Template();
} else {
$_template = new \webspell\Template('../templates/');
}
// -- GALLERY -- //
systeminc('func/gallery');
// -- PASSWORD_HASH -- //
if (version_compare(PHP_VERSION, '5.3.7', '>') && version_compare(PHP_VERSION, '5.5.0', '<')) {
systeminc('func/password');
}
// -- SPAM -- //
systeminc('func/spam');
// -- BB CODE -- //
systeminc('func/bbcode');
// -- Tags -- //
systeminc('func/tags');
// -- Upload -- //
systeminc('func/upload');
systeminc('func/httpupload');
systeminc('func/urlupload');
// -- Images -- //
systeminc('func/images');
// -- Constants -- //
systeminc('func/constants');
// -- Mod Rewrite -- //
systeminc('modrewrite');
$GLOBALS['_modRewrite'] = new \webspell\ModRewrite();
if (!stristr($_SERVER['SCRIPT_NAME'], '/admin/') && $modRewrite) {
$GLOBALS['_modRewrite']->enable();
}
function cleartext($text, $bbcode = true, $calledfrom = 'root')
{
$text = htmlspecialchars($text);
$text = strip_tags($text);
$text = smileys($text, 1);
$text = insertlinks($text, $calledfrom);
$text = flags($text, $calledfrom);
$text = replacement($text, $bbcode);
$text = htmlnl($text);
return nl2br($text);
}
function htmloutput($text)
{
$text = smileys($text);
$text = insertlinks($text);
$text = flags($text);
$text = replacement($text);
$text = htmlnl($text);
return nl2br($text);
}
function clearfromtags($text)
{
$text = getinput($text);
$text = strip_tags($text);
$text = htmlnl($text);
return nl2br($text);
}
function getinput($text)
{
return htmlspecialchars($text);
}
function getforminput($text)
{
$text = str_replace(array('\r', '\n'), array("\r", "\n"), $text);
$text = stripslashes($text);
return getinput($text);
}
// -- LOGIN -- //
systeminc('login');
if (isset($_COOKIE['language'])) {
$_language->setLanguage($_COOKIE['language']);
} else if (isset($_SESSION['language'])) {
$_language->setLanguage($_SESSION['language']);
} else if ($autoDetectLanguage) {
$lang = detectUserLanguage();
if (!empty($lang)) {
$_language->setLanguage($lang);
$_SESSION['language'] = $lang;
}
}
// -- SITE VARIABLE -- //
if (isset($_GET['site'])) {
$site = $_GET['site'];
} else {
$site = '';
}
if ($closed && !isanyadmin($userID)) {
$dl = mysqli_fetch_array(safe_query("SELECT * FROM `" . PREFIX . "lock` LIMIT 0,1"));
$reason = $dl['reason'];
showlock($reason);
}
if (!isset($_SERVER['HTTP_REFERER'])) {
$_SERVER['HTTP_REFERER'] = "";
}
if (!isset($_SERVER[getConstNameRequestUri()])) {
$_SERVER[getConstNameRequestUri()] = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
$_SERVER[getConstNameRequestUri()] .= '?' . $_SERVER['QUERY_STRING'];
}
}
// -- BANNED USERS -- //
if (date("dh", $lastBanCheck) != date("dh")) {
$get = safe_query("SELECT userID, banned FROM `" . PREFIX . "user` WHERE banned IS NOT NULL");
$removeBan = array();
while ($ds = mysqli_fetch_assoc($get)) {
if (($ds['banned'] != "perm") && ($ds['banned'] <= time())) {
$removeBan[] = 'userID="' . $ds['userID'] . '"';
}
}
if (!empty($removeBan)) {
$where = implode(" OR ", $removeBan);
safe_query("UPDATE " . PREFIX . "user SET banned=NULL WHERE " . $where);
}
safe_query("UPDATE " . PREFIX . "settings SET bancheck='" . time() . "'");
}
$banned =
safe_query(
"SELECT userID, banned, ban_reason FROM `" . PREFIX . "user`
WHERE (userID='" . $userID . "' OR ip='" . $GLOBALS[ 'ip' ] . "') AND banned IS NOT NULL"
);
while ($bq = mysqli_fetch_array($banned)) {
if ($bq['ban_reason']) {
$reason = "<br>Reason: <mark>" . $bq['ban_reason'] . '</mark>';
} else {
$reason = '';
}
if ($bq['banned']) {
$_SESSION = array();
// remove session cookie
if (isset($_COOKIE[ session_name() ])) {
setcookie(session_name(), '', time() - 42000, '/');
}
session_destroy();
// remove login cookie
webspell\LoginCookie::clear('ws_auth');
system_error('<strong>You have been banned.</strong>' . $reason, 0);
}
}
// -- BANNED IPs -- //
safe_query("DELETE FROM `" . PREFIX . "banned_ips` WHERE deltime < '" . time() . "'");
// -- WHO IS - WAS ONLINE -- //
$timeout = 5; // 1 second
$deltime = time() - ($timeout * 60); // IS 1m
$wasdeltime = time() - (60 * 60 * 24); // WAS 24h
safe_query("DELETE FROM `" . PREFIX . "whoisonline` WHERE time < '" . $deltime . "'"); // IS online
safe_query("DELETE FROM `" . PREFIX . "whowasonline` WHERE time < '" . $wasdeltime . "'"); // WAS online
// -- HELP MODE -- //
systeminc('help');
// -- WHOISONLINE -- //
if (mb_strlen($site)) {
if ($userID) {
// IS online
if (mysqli_num_rows(safe_query("SELECT userID FROM " . PREFIX . "whoisonline WHERE userID='$userID'"))) {
safe_query(
"UPDATE " . PREFIX . "whoisonline SET time='" . time() .
"', site='$site' WHERE userID='$userID'"
);
safe_query("UPDATE " . PREFIX . "user SET lastlogin='" . time() . "' WHERE userID='$userID'");
} else {
safe_query(
"INSERT INTO " . PREFIX . "whoisonline (time, userID, site) VALUES ('" . time() .
"', '$userID', '$site')"
);
}
// WAS online
if (mysqli_num_rows(safe_query("SELECT userID FROM " . PREFIX . "whowasonline WHERE userID='$userID'"))) {
safe_query(
"UPDATE " . PREFIX . "whowasonline SET time='" . time() .
"', site='$site' WHERE userID='$userID'"
);
} else {
safe_query(
"INSERT INTO " . PREFIX . "whowasonline (time, userID, site) VALUES ('" . time() .
"', '$userID', '$site')"
);
}
} else {
$anz =
mysqli_num_rows(
safe_query(
"SELECT ip FROM `" . PREFIX . "whoisonline` WHERE ip='" . $GLOBALS[ 'ip' ] . "'"
)
);
if ($anz) {
safe_query(
"UPDATE " . PREFIX . "whoisonline SET time='" . time() . "', site='$site' WHERE ip='" .
$GLOBALS[ 'ip' ] . "'"
);
} else {
safe_query(
"INSERT INTO " . PREFIX . "whoisonline (time, ip, site) VALUES ('" . time() . "','" .
$GLOBALS[ 'ip' ] . "', '$site')"
);
}
}
}
// -- COUNTER -- //
$time = time();
$date = date("d.m.Y", $time);
$deltime = $time - (3600 * 24);
safe_query("DELETE FROM `" . PREFIX . "counter_iplist` WHERE del<" . $deltime);
if (!mysqli_num_rows(safe_query("SELECT ip FROM `" . PREFIX . "counter_iplist` WHERE ip='" . $GLOBALS[ 'ip' ] . "'"))) {
if ($userID) {
safe_query("UPDATE `" . PREFIX . "user` SET ip='" . $GLOBALS[ 'ip' ] . "' WHERE userID='" . $userID . "'");
}
safe_query("UPDATE `" . PREFIX . "counter` SET hits=hits+1");
safe_query(
"INSERT INTO `" . PREFIX . "counter_iplist` (dates, del, ip) VALUES ('" . $date . "', '" . $time . "', '" .
$GLOBALS[ 'ip' ] . "')"
);
if (!mysqli_num_rows(safe_query("SELECT dates FROM `" . PREFIX . "counter_stats` WHERE dates='" . $date . "'"))) {
safe_query("INSERT INTO `" . PREFIX . "counter_stats` (`dates`, `count`) VALUES ('" . $date . "', '1')");
} else {
safe_query("UPDATE " . PREFIX . "counter_stats SET count=count+1 WHERE dates='" . $date . "'");
}
}
/* update maxonline if necessary */
$res = mysqli_fetch_assoc(safe_query("SELECT count(*) as maxuser FROM `" . PREFIX . "whoisonline`"));
safe_query(
"UPDATE `" . PREFIX . "counter`
SET maxonline = '" . $res[ 'maxuser' ] . "'
WHERE maxonline < '" . $res[ 'maxuser' ] . "'"
);
// -- SEARCH ENGINE OPTIMIZATION (SEO) -- //
if (stristr($_SERVER[ 'PHP_SELF' ], "/admin/") === false) {
systeminc('seo');
define('PAGETITLE', getPageTitle());
} else {
define('PAGETITLE', $GLOBALS['hp_title']);
}
// -- RSS FEEDS -- //
systeminc('func/feeds');
function recursiveRemoveDirectory($directory)
{
foreach (glob("{$directory}/*") as $file) {
if (is_dir($file)) {
recursiveRemoveDirectory($file);
} else {
unlink($file);
}
}
rmdir($directory);
}
// -- Composer -- //
require_once(__DIR__ . '/vendor/autoload.php');