More refactorings.

This commit is contained in:
Lars Jung 2014-05-21 02:21:46 +02:00
parent 351c395f82
commit 0b28a9eea1
3 changed files with 163 additions and 156 deletions

View file

@ -3,21 +3,31 @@
class Api { class Api {
private $app; private $actions, $app, $options;
public function __construct($app) { public function __construct($app) {
$this->actions = array("get", "getThumbHref", "download", "upload", "delete", "rename");
$this->app = $app; $this->app = $app;
$this->options = $app->get_options();
} }
public function apply() { public function apply() {
$options = $this->app->get_options();
$action = use_request_param("action"); $action = use_request_param("action");
if ($action === "get") { if (in_array($action, $this->actions)) {
$methodname = "on_$action";
$this->$methodname();
}
json_fail(100, "unsupported request");
}
private function on_get() {
$response = array(); $response = array();
@ -77,9 +87,9 @@ class Api {
} }
else if ($action === "getThumbHref") { private function on_getThumbHref() {
json_fail(1, "thumbnails disabled", !$options["thumbnails"]["enabled"]); json_fail(1, "thumbnails disabled", !$this->options["thumbnails"]["enabled"]);
json_fail(2, "thumbnails not supported", !HAS_PHP_JPG); json_fail(2, "thumbnails not supported", !HAS_PHP_JPG);
$type = use_request_param("type"); $type = use_request_param("type");
@ -96,9 +106,9 @@ class Api {
} }
else if ($action === "download") { private function on_download() {
json_fail(1, "downloads disabled", !$options["download"]["enabled"]); json_fail(1, "downloads disabled", !$this->options["download"]["enabled"]);
$as = use_request_param("as"); $as = use_request_param("as");
$type = use_request_param("type"); $type = use_request_param("type");
@ -119,7 +129,7 @@ class Api {
} }
else if ($action === "upload") { private function on_upload() {
$href = use_request_param("href"); $href = use_request_param("href");
@ -144,9 +154,9 @@ class Api {
} }
else if ($action === "delete") { private function on_delete() {
json_fail(1, "deletion disabled", !$options["delete"]["enabled"]); json_fail(1, "deletion disabled", !$this->options["delete"]["enabled"]);
$hrefs = use_request_param("hrefs"); $hrefs = use_request_param("hrefs");
@ -175,9 +185,9 @@ class Api {
} }
else if ($action === "rename") { private function on_rename() {
json_fail(1, "renaming disabled", !$options["rename"]["enabled"]); json_fail(1, "renaming disabled", !$this->options["rename"]["enabled"]);
$href = use_request_param("href"); $href = use_request_param("href");
$name = use_request_param("name"); $name = use_request_param("name");
@ -199,7 +209,4 @@ class Api {
json_exit(); json_exit();
} }
json_fail(100, "unsupported request");
}
} }

View file

@ -22,8 +22,8 @@ class App {
public function get_setup() { public function get_setup() {
$consts = get_defined_constants(true)['user']; $consts = get_defined_constants(true)["user"];
$consts['PHP_VERSION'] = PHP_VERSION; $consts["PHP_VERSION"] = PHP_VERSION;
return $consts; return $consts;
} }
@ -99,8 +99,8 @@ class App {
return 500; return 500;
} }
foreach ($this->options["view"]["indexFiles"] as $if) { foreach ($this->options["view"]["indexFiles"] as $name) {
if (file_exists($path . "/" . $if)) { if (file_exists($path . "/" . $name)) {
return 200; return 200;
} }
} }

View file

@ -43,7 +43,7 @@ function setup() {
// PATHS // PATHS
$script_name = getenv("SCRIPT_NAME"); $script_name = getenv("SCRIPT_NAME");
if (SERVER_NAME === "lighttpd") { if (SERVER_NAME === "lighttpd") {
$script_name = preg_replace("#^.*//#", "/", $script_name); $script_name = preg_replace("#^.*?//#", "/", $script_name);
} }
define("APP_URL", normalize_path(dirname(dirname(dirname($script_name))), true)); define("APP_URL", normalize_path(dirname(dirname(dirname($script_name))), true));
define("APP_PATH", normalize_path(dirname(dirname(dirname(dirname(__FILE__)))), false)); define("APP_PATH", normalize_path(dirname(dirname(dirname(dirname(__FILE__)))), false));