m1k1oblog/ajax.php

32 lines
606 B
PHP
Raw Normal View History

2016-12-27 20:25:32 +00:00
<?php
include 'common.php';
2016-12-28 13:02:55 +00:00
$ajax = new Ajax();
2016-12-27 20:25:32 +00:00
2016-12-28 13:02:55 +00:00
try {
$ajax->token();
// Prepare inputs
$request = array_merge(@$_POST, @$_GET);
if(empty($request["action"])){
throw new Exception("No action specified.");
2016-12-27 20:25:32 +00:00
}
2016-12-28 13:02:55 +00:00
$method = ['Post', $request["action"]];
// If method exists
if(!is_callable($method)){
throw new Exception("Method was not found.");
}
// CAll method
$response = call_user_func($method, $request);
$ajax->set_response($response);
// Log
Log::put("ajax_access", $request["action"]);
} catch (Exception $e) {
$ajax->set_error($e->getMessage());
2016-12-27 20:25:32 +00:00
}
2016-12-28 13:02:55 +00:00
$ajax->json_response();