-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathossearch.php
More file actions
1543 lines (1398 loc) · 59.8 KB
/
Copy pathossearch.php
File metadata and controls
1543 lines (1398 loc) · 59.8 KB
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
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?php
$title = "Casperia Prime • Command Hub";
include_once __DIR__ . "/include/config.php";
if (session_status() === PHP_SESSION_NONE) {
@session_start();
}
// ViewerOS mode: strip chrome in embedded browser
if (file_exists(__DIR__ . "/include/viewer_context.php")) {
include_once __DIR__ . "/include/viewer_context.php";
}
$con = db();
if (!$con) { die("CORE SYSTEM OFFLINE."); }
/* -------------------------------------------------------
Core Helpers
------------------------------------------------------- */
function h($s): string { return htmlspecialchars((string)$s, ENT_QUOTES, 'UTF-8'); }
function clamp_int($v, int $min, int $max, int $fallback): int {
if (!is_numeric($v)) return $fallback;
$n = (int)$v;
if ($n < $min) return $min;
if ($n > $max) return $max;
return $n;
}
function db_scalar(mysqli $con, string $sql, $default = 0) {
try {
$res = mysqli_query($con, $sql);
if (!$res) return $default;
$row = mysqli_fetch_row($res);
return ($row && isset($row[0])) ? $row[0] : $default;
} catch (Throwable $e) { return $default; }
}
function stmt_rows(mysqli $con, string $sql, string $types = "", array $params = []): array {
try {
$stmt = mysqli_prepare($con, $sql);
if (!$stmt) return [];
if ($types !== "" && !empty($params)) {
mysqli_stmt_bind_param($stmt, $types, ...$params);
}
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
$rows = [];
if ($res) while ($r = mysqli_fetch_assoc($res)) $rows[] = $r;
mysqli_stmt_close($stmt);
return $rows;
} catch (Throwable $e) { return []; }
}
function stmt_exec(mysqli $con, string $sql, string $types = "", array $params = []): bool {
try {
$stmt = mysqli_prepare($con, $sql);
if (!$stmt) return false;
if ($types !== "" && !empty($params)) {
mysqli_stmt_bind_param($stmt, $types, ...$params);
}
$ok = mysqli_stmt_execute($stmt);
mysqli_stmt_close($stmt);
return (bool)$ok;
} catch (Throwable $e) { return false; }
}
function table_exists(mysqli $con, string $table): bool {
try {
$sql = "SELECT 1 FROM information_schema.tables
WHERE table_schema = DATABASE()
AND table_name = ?
LIMIT 1";
$stmt = mysqli_prepare($con, $sql);
if (!$stmt) return false;
mysqli_stmt_bind_param($stmt, "s", $table);
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
$ok = ($res && mysqli_num_rows($res) > 0);
mysqli_stmt_close($stmt);
return $ok;
} catch (Throwable $e) { return false; }
}
function safe_ident(string $name): string {
// restrict identifiers used in dynamic SQL
return preg_match('/^[A-Za-z0-9_]+$/', $name) ? $name : '';
}
function column_exists_ci(mysqli $con, string $table, string $col): bool {
try {
$sql = "SELECT 1 FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = ?
AND LOWER(column_name) = LOWER(?)
LIMIT 1";
$stmt = mysqli_prepare($con, $sql);
if (!$stmt) return false;
mysqli_stmt_bind_param($stmt, "ss", $table, $col);
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
$ok = ($res && mysqli_num_rows($res) > 0);
mysqli_stmt_close($stmt);
return $ok;
} catch (Throwable $e) { return false; }
}
function column_datatype_ci(mysqli $con, string $table, string $col): ?string {
try {
$sql = "SELECT DATA_TYPE FROM information_schema.columns
WHERE table_schema = DATABASE()
AND table_name = ?
AND LOWER(column_name) = LOWER(?)
LIMIT 1";
$stmt = mysqli_prepare($con, $sql);
if (!$stmt) return null;
mysqli_stmt_bind_param($stmt, "ss", $table, $col);
mysqli_stmt_execute($stmt);
$res = mysqli_stmt_get_result($stmt);
$row = $res ? mysqli_fetch_assoc($res) : null;
mysqli_stmt_close($stmt);
return $row['DATA_TYPE'] ?? null;
} catch (Throwable $e) { return null; }
}
function first_existing_column_ci(mysqli $con, string $table, array $candidates): ?string {
foreach ($candidates as $c) {
if (column_exists_ci($con, $table, $c)) return $c;
}
return null;
}
function current_user_is_admin(): bool {
if (defined('ADMIN_USERLEVEL_MIN')) {
$lvl = $_SESSION['userlevel'] ?? $_SESSION['user_level'] ?? 0;
if (is_numeric($lvl) && (int)$lvl >= (int)ADMIN_USERLEVEL_MIN) return true;
}
if (!empty($_SESSION['is_admin'])) return true;
return false;
}
function csrf_token(): string {
if (empty($_SESSION['csrf'])) $_SESSION['csrf'] = bin2hex(random_bytes(16));
return (string)$_SESSION['csrf'];
}
function csrf_ok(): bool {
$t = (string)($_POST['csrf'] ?? '');
return ($t !== '' && !empty($_SESSION['csrf']) && hash_equals((string)$_SESSION['csrf'], $t));
}
/* -------------------------------------------------------
Auto-Discovery: Presence + Regions
------------------------------------------------------- */
function find_presence_schema(mysqli $con): array {
$preferred = ['presence', 'Presence'];
$userCandidates = ['UserID','userID','userid','PrincipalID','principalID','AgentID','agentID'];
$lastCandidates = ['LastSeen','lastseen','last_seen','Lastseen','lastSeen'];
foreach ($preferred as $t) {
if (!table_exists($con, $t)) continue;
$u = first_existing_column_ci($con, $t, $userCandidates);
$l = first_existing_column_ci($con, $t, $lastCandidates);
if ($u) {
$dt = $l ? (column_datatype_ci($con, $t, $l) ?? '') : '';
return [$t, $u, $l, strtolower((string)$dt)];
}
}
// find any table with a LastSeen-ish column
$rows = stmt_rows(
$con,
"SELECT DISTINCT table_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND LOWER(column_name) IN ('lastseen','last_seen','lastseen')
LIMIT 50"
);
foreach ($rows as $r) {
$t = (string)($r['table_name'] ?? '');
if ($t === '' || !table_exists($con, $t)) continue;
$u = first_existing_column_ci($con, $t, $userCandidates);
$l = first_existing_column_ci($con, $t, $lastCandidates);
if ($u) {
$dt = $l ? (column_datatype_ci($con, $t, $l) ?? '') : '';
return [$t, $u, $l, strtolower((string)$dt)];
}
}
return [null, null, null, null];
}
function find_regions_schema(mysqli $con): array {
$preferredTables = ['regions','Regions','gridregions','GridRegions','GridRegion','gridregion'];
$nameCandidates = ['regionName','RegionName','name','Name','region_name','Region_Name'];
foreach ($preferredTables as $t) {
if (!table_exists($con, $t)) continue;
$nameCol = first_existing_column_ci($con, $t, $nameCandidates);
if ($nameCol) return [$t, $nameCol];
}
// find any table with regionName-ish column
$rows = stmt_rows(
$con,
"SELECT DISTINCT table_name
FROM information_schema.columns
WHERE table_schema = DATABASE()
AND LOWER(column_name) IN ('regionname','region_name')
LIMIT 80"
);
foreach ($rows as $r) {
$t = (string)($r['table_name'] ?? '');
if ($t === '' || !table_exists($con, $t)) continue;
$nameCol = first_existing_column_ci($con, $t, ['regionName','RegionName','region_name','Region_Name']);
if ($nameCol) return [$t, $nameCol];
}
return [null, null];
}
/* -------------------------------------------------------
FIX #1: Accurate Online Count (auto-detect scales)
------------------------------------------------------- */
function get_online_count(mysqli $con, string &$meta = ''): int {
[$t, $userCol, $lastCol, $dt] = find_presence_schema($con);
if ($t && $userCol) {
$tSafe = safe_ident($t);
$uSafe = safe_ident($userCol);
$lSafe = $lastCol ? safe_ident($lastCol) : '';
if ($tSafe && $uSafe) {
// datetime/timestamp
if ($lSafe && in_array($dt, ['timestamp','datetime','date'], true)) {
$meta = "Presence: {$tSafe}.{$lSafe} ({$dt})";
return (int)db_scalar(
$con,
"SELECT COUNT(DISTINCT `$uSafe`) FROM `$tSafe`
WHERE `$lSafe` >= (NOW() - INTERVAL 10 MINUTE)",
0
);
}
// numeric: detect seconds vs ms vs ticks
if ($lSafe && in_array($dt, ['int','integer','bigint','mediumint','smallint','tinyint','decimal','numeric'], true)) {
$max = (int)db_scalar($con, "SELECT MAX(`$lSafe`) FROM `$tSafe`", 0);
if ($max > 10000000000000000) { // >1e16 : .NET ticks
$meta = "Presence: {$tSafe}.{$lSafe} (ticks)";
return (int)db_scalar(
$con,
"SELECT COUNT(DISTINCT `$uSafe`) FROM `$tSafe`
WHERE `$lSafe` >= ((UNIX_TIMESTAMP() - 600 + 62135596800) * 10000000)",
0
);
} elseif ($max > 1000000000000) { // >1e12 : unix ms
$meta = "Presence: {$tSafe}.{$lSafe} (ms)";
return (int)db_scalar(
$con,
"SELECT COUNT(DISTINCT `$uSafe`) FROM `$tSafe`
WHERE `$lSafe` >= ((UNIX_TIMESTAMP() * 1000) - 600000)",
0
);
} else { // unix seconds
$meta = "Presence: {$tSafe}.{$lSafe} (sec)";
return (int)db_scalar(
$con,
"SELECT COUNT(DISTINCT `$uSafe`) FROM `$tSafe`
WHERE `$lSafe` >= (UNIX_TIMESTAMP() - 600)",
0
);
}
}
// no usable last seen: still count distinct sessions/users
$meta = "Presence: {$tSafe} (no LastSeen filter)";
return (int)db_scalar($con, "SELECT COUNT(DISTINCT `$uSafe`) FROM `$tSafe`", 0);
}
}
// Fallback: GridUser
if (table_exists($con, 'GridUser')) {
$meta = "GridUser fallback";
if (column_exists_ci($con, 'GridUser', 'Online')) {
return (int)db_scalar($con, "SELECT COUNT(*) FROM GridUser WHERE Online IN (1,'1','True','TRUE','true')", 0);
}
if (column_exists_ci($con, 'GridUser', 'Logout') && column_exists_ci($con, 'GridUser', 'Login')) {
return (int)db_scalar(
$con,
"SELECT COUNT(*) FROM GridUser
WHERE (Logout IS NULL OR Logout = 0 OR Logout < Login)
AND Login >= (UNIX_TIMESTAMP() - 86400)",
0
);
}
}
$meta = "No Presence/GridUser source found in this DB";
return 0;
}
/* -------------------------------------------------------
ViewerOS tables (content + telemetry)
------------------------------------------------------- */
function ensure_vo_schema(mysqli $con): void {
mysqli_query($con, "
CREATE TABLE IF NOT EXISTS ws_hub_destinations (
id INT AUTO_INCREMENT PRIMARY KEY,
category VARCHAR(32) NOT NULL,
title VARCHAR(80) NOT NULL,
region VARCHAR(128) NOT NULL,
x SMALLINT NOT NULL DEFAULT 128,
y SMALLINT NOT NULL DEFAULT 128,
z SMALLINT NOT NULL DEFAULT 25,
description TEXT NULL,
tags VARCHAR(255) NULL,
image_url VARCHAR(255) NULL,
maturity VARCHAR(16) NOT NULL DEFAULT 'general',
active TINYINT(1) NOT NULL DEFAULT 1,
sort_order INT NOT NULL DEFAULT 0,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
updated_at DATETIME NULL,
INDEX idx_cat_active (category, active),
INDEX idx_region (region)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");
mysqli_query($con, "
CREATE TABLE IF NOT EXISTS ws_hub_events (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(120) NOT NULL,
start_time DATETIME NOT NULL,
end_time DATETIME NULL,
region VARCHAR(128) NOT NULL,
x SMALLINT NOT NULL DEFAULT 128,
y SMALLINT NOT NULL DEFAULT 128,
z SMALLINT NOT NULL DEFAULT 25,
host VARCHAR(80) NULL,
category VARCHAR(32) NULL,
description TEXT NULL,
maturity VARCHAR(16) NOT NULL DEFAULT 'general',
active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_start_active (start_time, active),
INDEX idx_region (region)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");
mysqli_query($con, "
CREATE TABLE IF NOT EXISTS ws_hub_land (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(120) NOT NULL,
region VARCHAR(128) NOT NULL,
x SMALLINT NOT NULL DEFAULT 128,
y SMALLINT NOT NULL DEFAULT 128,
z SMALLINT NOT NULL DEFAULT 25,
price INT NULL,
prims INT NULL,
size_m2 INT NULL,
rental_period VARCHAR(32) NULL,
contact VARCHAR(80) NULL,
description TEXT NULL,
active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_active_created (active, created_at),
INDEX idx_region (region)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");
mysqli_query($con, "
CREATE TABLE IF NOT EXISTS ws_hub_jobs (
id INT AUTO_INCREMENT PRIMARY KEY,
title VARCHAR(120) NOT NULL,
pay VARCHAR(64) NULL,
region VARCHAR(128) NULL,
x SMALLINT NOT NULL DEFAULT 128,
y SMALLINT NOT NULL DEFAULT 128,
z SMALLINT NOT NULL DEFAULT 25,
contact VARCHAR(80) NULL,
description TEXT NULL,
active TINYINT(1) NOT NULL DEFAULT 1,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_active_created (active, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");
mysqli_query($con, "
CREATE TABLE IF NOT EXISTS ws_hub_teleport_log (
id BIGINT AUTO_INCREMENT PRIMARY KEY,
region VARCHAR(128) NOT NULL,
x SMALLINT NOT NULL,
y SMALLINT NOT NULL,
z SMALLINT NOT NULL,
case_name VARCHAR(32) NULL,
label VARCHAR(120) NULL,
user_agent VARCHAR(255) NULL,
ip VARCHAR(64) NULL,
created_at DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
INDEX idx_created (created_at),
INDEX idx_region_created (region, created_at)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
");
}
ensure_vo_schema($con);
/* -------------------------------------------------------
FIX #2: Places search (auto-detect regions table + name column)
------------------------------------------------------- */
function collect_place_names(mysqli $con, string $like, string &$meta = ''): array {
$names = [];
$lower = function($s) {
return function_exists('mb_strtolower') ? mb_strtolower($s, 'UTF-8') : strtolower($s);
};
$add = function($n) use (&$names, $lower) {
$n = trim((string)$n);
if ($n === '') return;
$names[$lower($n)] = $n;
};
// Regions table discovery (sim names)
[$rt, $rc] = find_regions_schema($con);
if ($rt && $rc) {
$rtSafe = safe_ident($rt);
$rcSafe = safe_ident($rc);
if ($rtSafe && $rcSafe) {
$meta = "Regions: {$rtSafe}.{$rcSafe}";
$rows = stmt_rows(
$con,
"SELECT `$rcSafe` AS regionName
FROM `$rtSafe`
WHERE `$rcSafe` LIKE ?
ORDER BY `$rcSafe`
LIMIT 150",
"s",
[$like]
);
foreach ($rows as $r) $add($r['regionName'] ?? '');
} else {
$meta = "Regions found but identifier unsafe (name contains non [A-Za-z0-9_])";
}
} else {
$meta = "Regions: NOT FOUND in this DB";
}
// ViewerOS content tables as secondary sources
$sources = [
['ws_hub_destinations', 'region'],
['ws_hub_events', 'region'],
['ws_hub_land', 'region'],
['ws_hub_jobs', 'region'],
];
foreach ($sources as [$t, $c]) {
if (!table_exists($con, $t) || !column_exists_ci($con, $t, $c)) continue;
$tSafe = safe_ident($t);
$cSafe = safe_ident($c);
if (!$tSafe || !$cSafe) continue;
$rows = stmt_rows(
$con,
"SELECT DISTINCT `$cSafe` AS regionName
FROM `$tSafe`
WHERE active=1 AND `$cSafe` LIKE ?
LIMIT 150",
"s",
[$like]
);
foreach ($rows as $r) $add($r['regionName'] ?? '');
}
$list = array_values($names);
usort($list, fn($a, $b) => strcasecmp($a, $b));
$list = array_slice($list, 0, 25);
return array_map(fn($n) => ['regionName' => $n], $list);
}
/* -------------------------------------------------------
Inputs / Routing
------------------------------------------------------- */
$case = strtolower(trim((string)($_GET['case'] ?? 'hub')));
// Accept both local search params and viewer-style params
$query = trim((string)(
$_GET['q']
?? $_GET['query']
?? $_GET['query_term']
?? ''
));
$allowedCases = ['hub','shops','events','clubs','land','jobs','adult','dwell','vitals'];
if (!in_array($case, $allowedCases, true)) $case = 'hub';
// Accept viewer-style search type names and normalize them
$type_raw = strtolower(trim((string)(
$_GET['type']
?? $_GET['search_type']
?? $_GET['collection']
?? $_GET['category']
?? 'all'
)));
$type_map = [
'all' => 'all',
'people' => 'people',
'person' => 'people',
'agent' => 'people',
'agents' => 'people',
'places' => 'places',
'place' => 'places',
'parcel' => 'places',
'parcels' => 'places',
'land' => 'places',
'groups' => 'groups',
'group' => 'groups',
];
$type = $type_map[$type_raw] ?? 'all';
$is_search_mode = ($query !== '');
$adult_ok = (bool)($_SESSION['adult_ok'] ?? false);
if (isset($_GET['adult_ok']) && $_GET['adult_ok'] === '1') {
$_SESSION['adult_ok'] = true;
$adult_ok = true;
}
$like = '%' . $query . '%';
/* -------------------------------------------------------
Vitals
------------------------------------------------------- */
$online_meta = '';
$online = get_online_count($con, $online_meta);
$users = table_exists($con, 'UserAccounts') ? (int)db_scalar($con, "SELECT COUNT(*) FROM UserAccounts", 0) : 0;
// regions count from discovered schema (so it matches your DB reality)
[$rtCountTable, $rtCountCol] = find_regions_schema($con);
$regions = 0;
if ($rtCountTable && $rtCountCol) {
$tS = safe_ident($rtCountTable);
if ($tS) $regions = (int)db_scalar($con, "SELECT COUNT(*) FROM `$tS`", 0);
}
/* -------------------------------------------------------
Teleport Link Builder
------------------------------------------------------- */
function tp_url(string $region, int $x=128, int $y=128, int $z=25, string $case='hub', string $label=''): string {
return "go.php?region=" . rawurlencode($region) . "&x=$x&y=$y&z=$z&case=" . rawurlencode($case) . "&label=" . rawurlencode($label);
}
/* -------------------------------------------------------
Admin actions
------------------------------------------------------- */
$is_admin = current_user_is_admin();
$flash = "";
if ($_SERVER['REQUEST_METHOD'] === 'POST' && $is_admin && csrf_ok()) {
$action = (string)($_POST['action'] ?? '');
if ($action === 'add_dest') {
$cat = strtolower(trim((string)($_POST['category'] ?? 'featured')));
$title2 = trim((string)($_POST['title'] ?? ''));
$region2 = trim((string)($_POST['region'] ?? ''));
$x = clamp_int($_POST['x'] ?? 128, 0, 255, 128);
$y = clamp_int($_POST['y'] ?? 128, 0, 255, 128);
$z = clamp_int($_POST['z'] ?? 25, 0, 4096, 25);
$desc = trim((string)($_POST['description'] ?? ''));
$tags = trim((string)($_POST['tags'] ?? ''));
$img = trim((string)($_POST['image_url'] ?? ''));
$mat = strtolower(trim((string)($_POST['maturity'] ?? 'general')));
if ($title2 !== '' && $region2 !== '') {
stmt_exec($con,
"INSERT INTO ws_hub_destinations (category, title, region, x, y, z, description, tags, image_url, maturity, active, sort_order, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, 0, NOW())",
"sssiiissss",
[$cat, $title2, $region2, $x, $y, $z, $desc, $tags, $img, $mat]
);
$flash = "Destination added.";
} else $flash = "Missing title or region.";
}
if ($action === 'add_event') {
$title2 = trim((string)($_POST['title'] ?? ''));
$start = trim((string)($_POST['start_time'] ?? ''));
$end = trim((string)($_POST['end_time'] ?? ''));
$region2 = trim((string)($_POST['region'] ?? ''));
$x = clamp_int($_POST['x'] ?? 128, 0, 255, 128);
$y = clamp_int($_POST['y'] ?? 128, 0, 255, 128);
$z = clamp_int($_POST['z'] ?? 25, 0, 4096, 25);
$host = trim((string)($_POST['host'] ?? ''));
$cat = trim((string)($_POST['category'] ?? ''));
$desc = trim((string)($_POST['description'] ?? ''));
$mat = strtolower(trim((string)($_POST['maturity'] ?? 'general')));
$endVal = ($end !== '') ? $end : null;
if ($title2 !== '' && $start !== '' && $region2 !== '') {
stmt_exec($con,
"INSERT INTO ws_hub_events (title, start_time, end_time, region, x, y, z, host, category, description, maturity, active, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, NOW())",
"ssssiiissss",
[$title2, $start, $endVal, $region2, $x, $y, $z, $host, $cat, $desc, $mat]
);
$flash = "Event added.";
} else $flash = "Missing title, start time, or region.";
}
if ($action === 'add_land') {
$title2 = trim((string)($_POST['title'] ?? ''));
$region2 = trim((string)($_POST['region'] ?? ''));
$x = clamp_int($_POST['x'] ?? 128, 0, 255, 128);
$y = clamp_int($_POST['y'] ?? 128, 0, 255, 128);
$z = clamp_int($_POST['z'] ?? 25, 0, 4096, 25);
$price = (is_numeric($_POST['price'] ?? null) ? (int)$_POST['price'] : 0);
$prims = (is_numeric($_POST['prims'] ?? null) ? (int)$_POST['prims'] : 0);
$size = (is_numeric($_POST['size_m2'] ?? null) ? (int)$_POST['size_m2'] : 0);
$period = trim((string)($_POST['rental_period'] ?? ''));
$contact = trim((string)($_POST['contact'] ?? ''));
$desc = trim((string)($_POST['description'] ?? ''));
if ($title2 !== '' && $region2 !== '') {
stmt_exec($con,
"INSERT INTO ws_hub_land (title, region, x, y, z, price, prims, size_m2, rental_period, contact, description, active, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, 1, NOW())",
"ssiiiiiisss",
[$title2, $region2, $x, $y, $z, $price, $prims, $size, $period, $contact, $desc]
);
$flash = "Land listing added.";
} else $flash = "Missing title or region.";
}
if ($action === 'add_job') {
$title2 = trim((string)($_POST['title'] ?? ''));
$pay = trim((string)($_POST['pay'] ?? ''));
$region2 = trim((string)($_POST['region'] ?? ''));
$x = clamp_int($_POST['x'] ?? 128, 0, 255, 128);
$y = clamp_int($_POST['y'] ?? 128, 0, 255, 128);
$z = clamp_int($_POST['z'] ?? 25, 0, 4096, 25);
$contact = trim((string)($_POST['contact'] ?? ''));
$desc = trim((string)($_POST['description'] ?? ''));
if ($title2 !== '') {
stmt_exec($con,
"INSERT INTO ws_hub_jobs (title, pay, region, x, y, z, contact, description, active, created_at)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, 1, NOW())",
"sssiiiss",
[$title2, $pay, $region2, $x, $y, $z, $contact, $desc]
);
$flash = "Job added.";
} else $flash = "Missing job title.";
}
if ($action === 'delete' && isset($_POST['table'], $_POST['id'])) {
$tbl = (string)$_POST['table'];
$id = (int)$_POST['id'];
$allowedTbl = ['ws_hub_destinations','ws_hub_events','ws_hub_land','ws_hub_jobs'];
if (in_array($tbl, $allowedTbl, true) && $id > 0) {
stmt_exec($con, "DELETE FROM `$tbl` WHERE id = ?", "i", [$id]);
$flash = "Deleted.";
}
}
}
/* -------------------------------------------------------
Directory Search (People / Places / Groups)
------------------------------------------------------- */
$people = $places = $groups = [];
$places_meta = "";
if ($query !== "") {
$like = '%' . $query . '%';
if (($type === 'all' || $type === 'people') && table_exists($con, 'UserAccounts')) {
$people = stmt_rows(
$con,
"SELECT PrincipalID, FirstName, LastName
FROM UserAccounts
WHERE CONCAT(FirstName,' ',LastName) LIKE ?
ORDER BY LastName, FirstName
LIMIT 25",
"s",
[$like]
);
}
if ($type === 'all' || $type === 'places') {
$places = collect_place_names($con, $like, $places_meta);
}
// Groups: keep your existing table name, but only if it exists
if ($type === 'all' || $type === 'groups') {
if (table_exists($con, 'os_groups_groups')) {
$groups = stmt_rows(
$con,
"SELECT GroupID, Name
FROM os_groups_groups
WHERE Name LIKE ?
ORDER BY Name
LIMIT 25",
"s",
[$like]
);
}
}
}
/* -------------------------------------------------------
Load App Data by case
------------------------------------------------------- */
$destinations = [];
$events = [];
$land = [];
$jobs = [];
$hotSites = [];
if ($case === 'hub') {
$destinations = stmt_rows($con,
"SELECT * FROM ws_hub_destinations
WHERE category='featured' AND active=1
ORDER BY sort_order DESC, created_at DESC
LIMIT 8"
);
// fallback: random regions from discovered regions schema
if (empty($destinations)) {
[$rt, $rc] = find_regions_schema($con);
$rtS = $rt ? safe_ident($rt) : '';
$rcS = $rc ? safe_ident($rc) : '';
if ($rtS && $rcS) {
$destinations = stmt_rows($con,
"SELECT `$rcS` AS title, `$rcS` AS region, 128 AS x, 128 AS y, 25 AS z, '' AS description
FROM `$rtS`
ORDER BY RAND()
LIMIT 8"
);
}
}
}
if (in_array($case, ['shops','clubs','adult'], true)) {
if ($case !== 'adult' || $adult_ok) {
$destinations = stmt_rows($con,
"SELECT * FROM ws_hub_destinations
WHERE category=? AND active=1
ORDER BY sort_order DESC, created_at DESC
LIMIT 60",
"s",
[$case]
);
}
}
if ($case === 'events') {
$events = stmt_rows($con,
"SELECT * FROM ws_hub_events
WHERE active=1 AND start_time >= (NOW() - INTERVAL 2 HOUR)
ORDER BY start_time ASC
LIMIT 80"
);
}
if ($case === 'land') {
$land = stmt_rows($con,
"SELECT * FROM ws_hub_land
WHERE active=1
ORDER BY created_at DESC
LIMIT 80"
);
}
if ($case === 'jobs') {
$jobs = stmt_rows($con,
"SELECT * FROM ws_hub_jobs
WHERE active=1
ORDER BY created_at DESC
LIMIT 80"
);
}
if ($case === 'dwell') {
$hotSites = stmt_rows($con,
"SELECT region, COUNT(*) AS hits
FROM ws_hub_teleport_log
WHERE created_at >= (NOW() - INTERVAL 7 DAY)
GROUP BY region
ORDER BY hits DESC
LIMIT 25"
);
if (empty($hotSites)) {
[$rt, $rc] = find_regions_schema($con);
$rtS = $rt ? safe_ident($rt) : '';
$rcS = $rc ? safe_ident($rc) : '';
if ($rtS && $rcS) {
$hotSites = stmt_rows($con,
"SELECT `$rcS` AS region, 0 AS hits
FROM `$rtS`
ORDER BY RAND()
LIMIT 12"
);
}
}
}
include_once __DIR__ . "/include/" . HEADER_FILE;
?>
<style>
<?php if (!empty($IS_VIEWER)): ?>
header, .navbar, nav, footer, .site-header, .site-footer { display: none !important; }
body { padding: 0 !important; margin: 0 !important; overflow-x: hidden; }
<?php endif; ?>
:root {
--neon-blue: #00d2ff;
--danger: #ff4b2b;
--panel-bg: #0a0c10;
--module-bg: #141920;
--border-glow: #1f2630;
--muted: #7a8a9a;
--ok: #4caf50;
}
body {
background: radial-gradient(1200px 600px at 50% 0%, rgba(0,210,255,0.10) 0%, rgba(0,0,0,0) 55%),
linear-gradient(135deg, #0a0c10 0%, #101622 100%);
color: #e0e6ed;
font-family: 'Segoe UI', sans-serif;
font-size: 16px;
}
/* Fixed Pulse HUD */
.pulse-bar {
background: #001a23;
padding: 10px 14px;
border-bottom: 2px solid var(--neon-blue);
display: flex;
justify-content: space-between;
gap: 12px;
font-size: 12px;
font-weight: 800;
position: fixed;
top: 0;
width: 100%;
z-index: 1000;
}
.pulse-right { text-align:right; }
.badge {
display:inline-block;
padding: 6px 10px;
border-radius: 999px;
border: 1px solid var(--border-glow);
background: rgba(0,0,0,0.25);
margin-left: 8px;
font-size: 12px;
font-weight: 900;
}
.dot { color: var(--ok); margin-right: 6px; }
.page { padding-top: 62px; }
/* Hero */
.hub-hero {
padding: 34px 16px 18px;
text-align: center;
border-bottom: 1px solid rgba(255,255,255,0.08);
background: linear-gradient(135deg, rgba(0,210,255,0.10) 0%, rgba(111,66,193,0.08) 100%);
}
.hub-hero h1 {
margin: 0 0 8px 0;
font-size: 34px;
font-weight: 900;
letter-spacing: .3px;
}
.hub-hero p {
margin: 0;
color: rgba(255,255,255,0.65);
font-size: 15px;
font-weight: 700;
}
/* Command Console */
.cmd-input-container { padding: 0 16px; margin-top: -16px; margin-bottom: 12px; }
.cmd-box {
background: rgba(20,25,32,0.92);
border: 2px solid var(--neon-blue);
border-radius: 14px;
padding: 10px 12px;
display: flex;
align-items: center;
gap: 10px;
box-shadow: 0 12px 30px rgba(0,0,0,0.60);
}
.cmd-box input {
background: transparent;
border: none;
color: #fff;
flex: 1;
padding: 10px 8px;
outline: none;
font-size: 17px;
font-weight: 700;
}
.cmd-box button {
background: rgba(0,0,0,0.35);
border: 1px solid var(--border-glow);
color: var(--neon-blue);
border-radius: 12px;
padding: 10px 12px;
cursor: pointer;
font-size: 16px;
font-weight: 900;
}
/* Directory type chips */
.type-chips {
display:flex;
flex-wrap:wrap;
gap: 10px;
padding: 0 16px 16px;
}
.type-chip {
text-decoration:none;
color:#cfe8ff;
font-weight: 900;
font-size: 13px;
padding: 10px 14px;
border-radius: 999px;
border: 1px solid var(--border-glow);
background: rgba(0,0,0,0.25);
}
.type-chip.active {
border-color: var(--neon-blue);
color: var(--neon-blue);
box-shadow: 0 0 0 2px rgba(0,210,255,0.12) inset;
}
/* App Grid */
.wrap { padding: 0 16px 26px; }
.category-grid {
display: grid;
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
gap: 14px;
}
.cat-card {
background: linear-gradient(135deg, rgba(44,44,78,0.55) 0%, rgba(20,25,32,0.95) 100%);
border: 1px solid rgba(255,255,255,0.10);
border-radius: 14px;
padding: 18px 12px;
text-align: center;
text-decoration: none;
color: #fff;
transition: all 0.18s ease;
display: flex;
flex-direction: column;
align-items: center;
gap: 8px;
min-height: 108px;
}
.cat-card:hover {
transform: translateY(-4px);
border-color: var(--neon-blue);
box-shadow: 0 14px 28px rgba(0,0,0,0.55);
}
.cat-ico { font-size: 30px; line-height: 1; color: var(--neon-blue); }
.cat-title {
font-size: 15px;
font-weight: 900;
letter-spacing: 1px;
text-transform: uppercase;
}
/* Panels & rows */
.section-title {
margin: 22px 0 12px;
font-size: 13px;
font-weight: 900;
letter-spacing: 2px;
text-transform: uppercase;
color: var(--neon-blue);
}
.panel {
background: rgba(0,0,0,0.25);
border: 1px solid var(--border-glow);
border-radius: 14px;