api.php

main 89 lines · 2.3 KB Raw
Alex Alex Commit Initial commit 01/10/2026 09:20
1<?php
2// PHP version check
3if (PHP_VERSION_ID < 80100) {
4 die('PHP 8.1 or higher is required.');
5}
6
7if (!isset($filepath)) {
8 $filepath = '../';
9}
10
11$version = '2.0.1';
12
13ob_start();
14require_once $filepath.'config.php';
15require_once $filepath.'engine/session.php';
16require_once $filepath.'engine/security.php';
17znote_session_start((array)($config['session'] ?? array()));
18znote_security_boot((array)($config['security'] ?? array()));
19
20$sessionPrefix = $config['session_prefix'];
21
22$config['ServerEngineReal'] = $config['ServerEngine'] ?? 'TFS_10';
23if (in_array($config['ServerEngineReal'], array('TFS_16', 'CANARY', 'BLACKTEK'), true)) {
24 $config['ServerEngine'] = 'TFS_10';
25 $config['TFSVersion'] = 'TFS_10';
26}
27if ($config['ServerEngineReal'] === 'CANARY') {
28 $config['twoFactorAuthenticator'] = false;
29}
30
31require_once $filepath.'engine/database/connect.php';
32require_once $filepath.'engine/function/general.php';
33require_once $filepath.'engine/function/users.php';
34require_once $filepath.'engine/function/cache.php';
35require_once $filepath.'engine/adapter/ServerAdapterInterface.php';
36require_once $filepath.'engine/adapter/TFSAdapter.php';
37require_once $filepath.'engine/adapter/CanaryAdapter.php';
38require_once $filepath.'engine/adapter/OtHireAdapter.php';
39require_once $filepath.'engine/adapter/BlackTekAdapter.php';
40require_once $filepath.'engine/adapter/factory.php';
41
42// Default API config
43$config['api']['debug'] ??= false;
44
45$response = [
46 'version' => [
47 'znote' => $version,
48 'ot' => $config['ServerEngine'] ?? null
49 ],
50];
51
52if (isset($moduleVersion)) {
53 $response['version']['module'] = $moduleVersion;
54}
55
56function UseClass($name = false, $module = false, $path = false) {
57 if ($name === false) {
58 throw new InvalidArgumentException('UseClass(): class parameter is false.');
59 }
60
61 $names = is_array($name) ? $name : [$name];
62
63 foreach ($names as $class) {
64 $mod = $module ?: $class;
65 $file = $path
66 ? "{$path}/{$class}.php"
67 : __DIR__ . "/modules/base/{$mod}/class/{$class}.php";
68
69 if (!file_exists($file)) {
70 throw new RuntimeException("Class file not found: {$file}");
71 }
72
73 require_once $file;
74 }
75}
76
77function SendResponse(array $response): void {
78 global $config;
79
80 if ($config['api']['debug']) {
81 data_dump($response, false, "Response (debug mode)");
82 return;
83 }
84
85 header('Content-Type: application/json; charset=utf-8');
86 echo json_encode($response);
87}
88?>
89
Top