summaryrefslogtreecommitdiffstats
path: root/application/controllers/api.php
diff options
context:
space:
mode:
authorFlorian Pritz <bluewind@xinu.at>2014-10-25 13:55:08 +0200
committerFlorian Pritz <bluewind@xinu.at>2015-01-16 17:38:38 +0100
commitd59962443687127ea1defc2f8ac41af1c2c02fe4 (patch)
treef33a9f358efdd1e30a27e0244314d0ef81b2ce7e /application/controllers/api.php
parent9535ede862e01d834ebdd553184b1f6544b06d2c (diff)
first go at reworking; needs to be redesigned
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'application/controllers/api.php')
-rw-r--r--application/controllers/api.php38
1 files changed, 38 insertions, 0 deletions
diff --git a/application/controllers/api.php b/application/controllers/api.php
new file mode 100644
index 000000000..626e7b91a
--- /dev/null
+++ b/application/controllers/api.php
@@ -0,0 +1,38 @@
+<?php
+/*
+ * Copyright 2014 Florian "Bluewind" Pritz <bluewind@server-speed.net>
+ *
+ * Licensed under AGPLv3
+ * (see COPYING for full license text)
+ *
+ */
+
+class Api extends MY_Controller {
+
+ public function __construct()
+ {
+ parent::__construct();
+
+ $this->load->model('mfile');
+ $this->load->model('mmultipaste');
+ }
+
+ public function route() {
+ $requested_version = $this->uri->segment(2);
+ $function = $this->uri->segment(3);
+ $major = intval(explode(".", $requested_version)[0]);
+
+ $class = "controllers\\api\\v".$major;
+
+ if (!class_exists($class) || version_compare($class::get_version(), $requested_version, "<")) {
+ return send_json_error_reply("Requested API version is not supported");
+ }
+
+ if (!preg_match("/^[a-zA-Z-_]+$/", $function)) {
+ return send_json_error_reply("Invalid function requested");
+ }
+
+ $controller = new $class;
+ return $controller->$function();
+ }
+}