v3.0.0.2
FlatlyPage
- <?php
- header('Content-Type: application/json; charset=utf-8');
- if (isset($_SERVER['HTTP_ORIGIN'])) {
- $originHost = parse_url($_SERVER['HTTP_ORIGIN'], PHP_URL_HOST);
- $serverHost = $_SERVER['HTTP_HOST'];
- $serverParts = explode('.', $serverHost);
- $baseDomain = implode('.', array_slice($serverParts, -2));
- if (
- $originHost === $baseDomain ||
- str_ends_with($originHost, '.' . $baseDomain)
- ) {
- header('Access-Control-Allow-Origin: ' . $_SERVER['HTTP_ORIGIN']);
- header('Access-Control-Allow-Credentials: true');
- header('Access-Control-Allow-Methods: GET, POST, OPTIONS');
- header('Access-Control-Allow-Headers: Content-Type, Authorization');
- }
- }
- if ($_SERVER['REQUEST_METHOD'] === 'OPTIONS') {
- http_response_code(200);
- exit;
- }
- $xmlPath = __DIR__ . '/../data/translate-api.xml';
- if (!file_exists($xmlPath)) {
- http_response_code(404);
- die(json_encode(['error' => 'Config not found']));
- }
- $xml = simplexml_load_file($xmlPath);
- $apis = [];
- foreach ($xml->apis->api as $api) {
- $id = (string)$api->id;
- $apis[$id] = [
- 'name' => (string)$api->name,
- 'free' => (string)$api->free === 'true',
- 'rateLimit' => (string)$api->rateLimit ?? ''
- ];
- }
- echo json_encode($apis);