mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-03-22 13:30:05 +01:00
Refactor PHP.
This commit is contained in:
parent
122546eae1
commit
8fd393d34a
@ -1,6 +1,13 @@
|
||||
<?php
|
||||
|
||||
|
||||
function normalize_path($path, $trailing_slash = false) {
|
||||
|
||||
$path = preg_replace("#\\\\+|/+#", "/", $path);
|
||||
return preg_match("#^(\w:)?/$#", $path) ? $path : (rtrim($path, "/") . ($trailing_slash ? "/" : ""));
|
||||
}
|
||||
|
||||
|
||||
function json_exit($obj = array()) {
|
||||
|
||||
$obj["code"] = 0;
|
||||
@ -86,28 +93,10 @@ function exec_cmdv($cmdv) {
|
||||
}
|
||||
|
||||
|
||||
function delete_path($path, $recursive = false) {
|
||||
|
||||
if (is_file($path)) {
|
||||
return @unlink($path);
|
||||
}
|
||||
|
||||
if (is_dir($path)) {
|
||||
if ($recursive === true && $dir = opendir($path)) {
|
||||
while (($name = readdir($dir)) !== false) {
|
||||
delete_path($path . "/" . $name);
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
|
||||
return @rmdir($path);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// debug tools
|
||||
/*********************************************************************
|
||||
Debug Tools
|
||||
*********************************************************************/
|
||||
|
||||
function err_log($message, $obj = null) {
|
||||
|
||||
|
@ -11,15 +11,9 @@ define("PASSHASH", "da39a3ee5e6b4b0d3255bfef95601890afd80709");
|
||||
|
||||
|
||||
|
||||
function normalize_path($path, $trailing_slash = false) {
|
||||
|
||||
$path = preg_replace("#\\\\+|/+#", "/", $path);
|
||||
return preg_match("#^(\w:)?/$#", $path) ? $path : (rtrim($path, "/") . ($trailing_slash ? "/" : ""));
|
||||
}
|
||||
|
||||
function normalized_require_once($lib) {
|
||||
|
||||
require_once(normalize_path(dirname(__FILE__) . "/inc/${lib}.php", false));
|
||||
require_once(preg_replace("#\\\\+|/+#", "/", dirname(__FILE__) . "/inc/${lib}.php"));
|
||||
}
|
||||
|
||||
normalized_require_once("util");
|
||||
|
Loading…
x
Reference in New Issue
Block a user