mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-25 12:34:47 -04:00
Refactor PHP.
This commit is contained in:
parent
8fd393d34a
commit
903b29c4c0
4 changed files with 10 additions and 11 deletions
|
@ -103,7 +103,7 @@ class Api {
|
||||||
$response["all_items"] = $this->app->get_all_items();
|
$response["all_items"] = $this->app->get_all_items();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (count($_REQUEST)) {
|
if (AS_ADMIN && count($_REQUEST)) {
|
||||||
$response["unused"] = $_REQUEST;
|
$response["unused"] = $_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
- var app_href = "<?php echo APP_HREF; ?>"
|
- var app_href = "<?php echo APP_HREF; ?>"
|
||||||
- var fallback = "<?php echo FALLBACK; ?>"
|
- var fallback = "<?php echo FALLBACK; ?>"
|
||||||
|
|
||||||
|
<?php header("Content-type: text/html;charset=utf-8"); ?>
|
||||||
doctype 5
|
doctype 5
|
||||||
//if lt IE 10
|
//if lt IE 10
|
||||||
<html class="no-js no-browser" lang="en">
|
<html class="no-js no-browser" lang="en">
|
||||||
|
|
|
@ -3,14 +3,18 @@
|
||||||
|
|
||||||
function normalize_path($path, $trailing_slash = false) {
|
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 ? "/" : ""));
|
return preg_match("#^(\w:)?/$#", $path) ? $path : (rtrim($path, "/") . ($trailing_slash ? "/" : ""));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
function json_exit($obj = array()) {
|
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);
|
echo json_encode($obj);
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
@ -19,8 +23,7 @@ function json_exit($obj = array()) {
|
||||||
function json_fail($code, $msg = "", $cond = true) {
|
function json_fail($code, $msg = "", $cond = true) {
|
||||||
|
|
||||||
if ($cond) {
|
if ($cond) {
|
||||||
echo json_encode(array("code" => $code, "msg" => $msg));
|
json_exit(array("code" => $code, "msg" => $msg));
|
||||||
exit;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ define("PASSHASH", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||||
|
|
||||||
function normalized_require_once($lib) {
|
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");
|
normalized_require_once("util");
|
||||||
|
@ -28,14 +28,9 @@ setup();
|
||||||
$app = new App();
|
$app = new App();
|
||||||
|
|
||||||
if (has_request_param("action")) {
|
if (has_request_param("action")) {
|
||||||
|
|
||||||
header("Content-type: application/json;charset=utf-8");
|
|
||||||
$api = new Api($app);
|
$api = new Api($app);
|
||||||
$api->apply();
|
$api->apply();
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
header("Content-type: text/html;charset=utf-8");
|
|
||||||
define("FALLBACK", $app->get_fallback());
|
define("FALLBACK", $app->get_fallback());
|
||||||
normalized_require_once("page");
|
normalized_require_once("page");
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue