Refactor PHP.

This commit is contained in:
Lars Jung 2014-07-01 03:03:41 +02:00
parent 8fd393d34a
commit 903b29c4c0
4 changed files with 10 additions and 11 deletions

View file

@ -103,7 +103,7 @@ class Api {
$response["all_items"] = $this->app->get_all_items();
}
if (count($_REQUEST)) {
if (AS_ADMIN && count($_REQUEST)) {
$response["unused"] = $_REQUEST;
}

View file

@ -2,6 +2,7 @@
- var app_href = "<?php echo APP_HREF; ?>"
- var fallback = "<?php echo FALLBACK; ?>"
<?php header("Content-type: text/html;charset=utf-8"); ?>
doctype 5
//if lt IE 10
<html class="no-js no-browser" lang="en">

View file

@ -3,14 +3,18 @@
function normalize_path($path, $trailing_slash = false) {
$path = preg_replace("#\\\\+|/+#", "/", $path);
$path = preg_replace("#[\\\\/]+#", "/", $path);
return preg_match("#^(\w:)?/$#", $path) ? $path : (rtrim($path, "/") . ($trailing_slash ? "/" : ""));
}
function json_exit($obj = array()) {
$obj["code"] = 0;
if (!isset($obj["code"])) {
$obj["code"] = 0;
}
header("Content-type: application/json;charset=utf-8");
echo json_encode($obj);
exit;
}
@ -19,8 +23,7 @@ function json_exit($obj = array()) {
function json_fail($code, $msg = "", $cond = true) {
if ($cond) {
echo json_encode(array("code" => $code, "msg" => $msg));
exit;
json_exit(array("code" => $code, "msg" => $msg));
}
}

View file

@ -13,7 +13,7 @@ define("PASSHASH", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
function normalized_require_once($lib) {
require_once(preg_replace("#\\\\+|/+#", "/", dirname(__FILE__) . "/inc/${lib}.php"));
require_once(preg_replace("#[\\\\/]+#", "/", dirname(__FILE__) . "/inc/${lib}.php"));
}
normalized_require_once("util");
@ -28,14 +28,9 @@ setup();
$app = new App();
if (has_request_param("action")) {
header("Content-type: application/json;charset=utf-8");
$api = new Api($app);
$api->apply();
} else {
header("Content-type: text/html;charset=utf-8");
define("FALLBACK", $app->get_fallback());
normalized_require_once("page");
}