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

81 lines
1.9 KiB
PHP
Raw Normal View History

2015-07-01 18:22:45 +00:00
<?php
/*
* Sakura API
*/
// Declare Namespace
namespace Sakura;
// Include components
require_once str_replace(basename(__DIR__), '', dirname(__FILE__)) .'_sakura/sakura.php';
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]) {
// 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]))
$elems[] = "";
}
// Make sure the GET requests aren't present in the last entry
if(strpos($elems[max(array_keys($elems))], '?')) {
// 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) {
// API Version 1
case 'v1':
switch(isset($elems[1]) ? $elems[1] : false) {
// Authentication
case 'authenticate':
switch(isset($elems[2]) ? $elems[2] : false) {
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
}
2015-07-03 17:33:02 +00:00
echo isset($_GET['pretty']) ? Main::jsonPretty(json_encode([$return])) : json_encode([$return]);