X-Git-Url: https://git.infodrom.org/?p=infodrom.org%2Fservice.infodrom.org;a=blobdiff_plain;f=src%2Fajax.php;h=c613aabc262661322cdf964d814bc3f347a99286;hp=6c38fa603c32ce63d52159e836a23cadf35deeea;hb=50019920e380e7acf33b7483a38ad9c962236fd2;hpb=4170693210c2f27fb6617ade76d249bfafc59da5
diff --git a/src/ajax.php b/src/ajax.php
index 6c38fa6..c613aab 100644
--- a/src/ajax.php
+++ b/src/ajax.php
@@ -2,38 +2,40 @@
require_once('config.php');
require_once('future.php');
-$data = array();
-
-if (strlen($_POST['func'])) {
- $backend = new AJAXBackend();
-
- if (method_exists($backend, $_POST['func'])) {
- $func = $_POST['func'];
- json_return($backend->$func());
+function route_request()
+{
+ if (empty($_SERVER['REMOTE_USER']))
+ return ajax_error('Die Sitzung ist abgelaufen, Sie werden zur Startseite weitergeleiet.', true);
+
+ list($class, $function) = explode('/', $_POST['route'], 2);
+ $method = 'ajax'.$function;
+
+ if (!class_exists($class))
+ return ajax_error('Klasse '.htmlspecialchars($class).' existiert nicht.');
+
+ try {
+ if (array_key_exists('id', $_POST))
+ $object = Factory::get($class, $_POST['id']);
+ else
+ $object = Factory::get($class);
+ } catch (Exception $e) {
+ return ajax_error('Klasse '.htmlspecialchars($class).'kann nicht instanziiert werden:
'.htmlspecialchars($e->getMessage()));
}
- $path = substr($_SERVER['HTTP_REFERER'], strpos($_SERVER['HTTP_REFERER'], $_SERVER['SERVER_NAME'])+strlen($_SERVER['SERVER_NAME'])+1);
- $slash = strpos($path, '/', strpos($path, '/')+1);
-
- if ($slash !== false) {
- $path = getcwd() . '/' . substr($path, 0, $slash) . '/' . 'moduleajaxbackend.class.php';
-
- if (file_exists($path)) {
- require_once($path);
- $backend = new ModuleAJAXBackend();
+ if (!method_exists($object, $method))
+ return ajax_error('Klasse '.htmlspecialchars($class).':
AJAX-Backend '.htmlspecialchars($function).' existiert nicht.');
- $method = 'ajax_' . $_POST['func'];
- if (method_exists($backend, $method)) {
- json_return($backend->$method());
- }
- }
- }
-
- error_log('Unknown function '.$_POST['func']);
- json_return(array('status' => false,
- 'error' => 'Unknown function '.urlencode($_POST['func']).'.'));
+ $return = $object->$method($_POST);
+ if (is_bool($return)) $return = array('status' => $return);
+ return $return;
}
-error_log('Unknown usage');
-json_return(array('status' => false, 'error' => 'Unknown usage'));
+if (strlen($_POST['route'])) {
+ $data = route_request();
+ if (!array_key_exists('status', $data))
+ $data['status'] = true;
+} else {
+ $data = array('status' => false, 'error' => 'Keine Route angegeben');
+}
+json_return($data);