Refactor PHP.

This commit is contained in:
Lars Jung 2014-06-30 03:15:27 +02:00
parent 122546eae1
commit 8fd393d34a
2 changed files with 11 additions and 28 deletions

View File

@ -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) {

View File

@ -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");