This repository has been archived on 2024-06-26. You can view files and clone it, but cannot push or open issues or pull requests.
sakura/api/api.php

75 lines
1.9 KiB
PHP
Raw Normal View History

2015-07-01 18:22:45 +00:00
<?php
/*
* Sakura API
*/
// Declare Namespace
namespace Sakura;
2015-07-30 01:12:53 +00:00
// Define that this page won't require templating
define('SAKURA_NO_TPL', true);
2015-07-01 18:22:45 +00:00
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) . '_sakura/sakura.php';
2015-07-01 18:22:45 +00:00
2015-07-03 17:33:02 +00:00
// Change to content type to text/plain and set the charset to UTF-8
header('Content-Type: text/plain; charset=utf-8');
2015-07-01 18:22:45 +00:00
// Trim leading slashes
$path = ltrim($_SERVER['REQUEST_URI'], '/');
// Explode the elements
$elems = explode('/', $path);
// Correct the path if mod_rewrite isn't used
if ($elems[0] == explode('/', ltrim($_SERVER['PHP_SELF'], '/'))[0]) {
2015-07-01 18:22:45 +00:00
// Remove the entry
unset($elems[0]);
// Resort the array
$elems = array_values($elems);
2015-07-03 17:33:02 +00:00
// Make sure there's at least one entry (even if empty)
if (!isset($elems[0])) {
2015-07-03 17:33:02 +00:00
$elems[] = "";
}
2015-07-03 17:33:02 +00:00
}
// Make sure the GET requests aren't present in the last entry
if (strpos($elems[max(array_keys($elems))], '?')) {
2015-07-03 17:33:02 +00:00
// If there are cut them all
$elems[max(array_keys($elems))] = strstr($elems[max(array_keys($elems))], '?', true);
}
// Predefine the return variable
$return = [];
// Select API version
switch (isset($elems[0]) ? $elems[0] : false) {
2015-07-03 17:33:02 +00:00
// API Version 1
case 'v1':
switch (isset($elems[1]) ? $elems[1] : false) {
2015-07-03 17:33:02 +00:00
// Authentication
case 'authenticate':
switch (isset($elems[2]) ? $elems[2] : false) {
2015-07-03 17:33:02 +00:00
case 'login':
$return = ['success' => 'LOGIN_PROCESS_HERE'];
break;
default:
$return = ['error' => ['NO_DATA_REQ']];
}
break;
default:
$return = ['error' => ['NO_DATA_REQ']];
}
break;
// Default fallback
default:
$return = ['error' => ['NO_API_VERSION']];
2015-07-01 18:22:45 +00:00
}
echo json_encode($return, (isset($_GET['pretty']) ? JSON_PRETTY_PRINT : 0));