m1k1oblog/ajax.php

32 lines
601 B
PHP
Raw Permalink 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();
2019-12-20 17:38:48 +00:00
2016-12-28 13:02:55 +00:00
// 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
}
2019-12-20 17:38:48 +00:00
2016-12-28 13:02:55 +00:00
$method = ['Post', $request["action"]];
2019-12-20 17:38:48 +00:00
2016-12-28 13:02:55 +00:00
// If method exists
if(!is_callable($method)){
throw new Exception("Method was not found.");
}
2019-12-20 17:38:48 +00:00
2016-12-28 13:02:55 +00:00
// CAll method
$response = call_user_func($method, $request);
$ajax->set_response($response);
2019-12-20 17:38:48 +00:00
2016-12-28 13:02:55 +00:00
// 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();