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
|
2015-09-14 20:51:23 +00:00
|
|
|
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
|
2015-09-14 20:51:23 +00:00
|
|
|
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)
|
2015-09-14 20:51:23 +00:00
|
|
|
if (!isset($elems[0])) {
|
2015-07-03 17:33:02 +00:00
|
|
|
$elems[] = "";
|
2015-09-14 20:51:23 +00:00
|
|
|
}
|
2015-07-03 17:33:02 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure the GET requests aren't present in the last entry
|
2015-09-14 20:51:23 +00:00
|
|
|
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
|
2015-09-14 20:51:23 +00:00
|
|
|
switch (isset($elems[0]) ? $elems[0] : false) {
|
2015-07-03 17:33:02 +00:00
|
|
|
// API Version 1
|
|
|
|
case 'v1':
|
2015-09-14 20:51:23 +00:00
|
|
|
switch (isset($elems[1]) ? $elems[1] : false) {
|
2015-07-03 17:33:02 +00:00
|
|
|
// Authentication
|
|
|
|
case 'authenticate':
|
2015-09-14 20:51:23 +00:00
|
|
|
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
|
|
|
}
|
|
|
|
|
2015-07-03 17:33:02 +00:00
|
|
|
echo isset($_GET['pretty']) ? Main::jsonPretty(json_encode([$return])) : json_encode([$return]);
|