mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-04-14 09:31:54 +02:00
More refactorings.
This commit is contained in:
parent
bd65025a4c
commit
b8b6d32a33
src/_h5ai
client
server/php
2
src/_h5ai/client/css/inc/apache-autoindex-table.less → src/_h5ai/client/css/inc/fallback-table.less
2
src/_h5ai/client/css/inc/apache-autoindex-table.less → src/_h5ai/client/css/inc/fallback-table.less
@ -1,7 +1,7 @@
|
||||
|
||||
#data-apache-autoindex, #data-php-no-js-fallback {
|
||||
max-width: 960px;
|
||||
margin: 0 auto;
|
||||
margin: 0 auto 80px auto;
|
||||
|
||||
table {
|
||||
display: block;
|
@ -26,7 +26,7 @@
|
||||
@import "inc/extended-grid";
|
||||
// @import "inc/context-menu";
|
||||
@import "inc/dropbox";
|
||||
@import "inc/apache-autoindex-table";
|
||||
@import "inc/fallback-table";
|
||||
|
||||
@import "inc/responsive";
|
||||
|
||||
|
@ -29,13 +29,14 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
||||
$.ajax({
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'getchecks'
|
||||
action: 'get',
|
||||
checks: true
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
callback(json.checks);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
@ -44,19 +45,21 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
||||
});
|
||||
},
|
||||
|
||||
getEntries = function (href, content, callback) {
|
||||
getEntries = function (href, what, callback) {
|
||||
|
||||
$.ajax({
|
||||
url: resource.api(),
|
||||
data: {
|
||||
action: 'getentries',
|
||||
href: href,
|
||||
content: content
|
||||
action: 'get',
|
||||
entries: true,
|
||||
entriesHref: href,
|
||||
entriesWhat: what
|
||||
},
|
||||
type: 'POST',
|
||||
dataType: 'json',
|
||||
success: function (json) {
|
||||
|
||||
callback(json);
|
||||
callback(json.entries);
|
||||
},
|
||||
error: function () {
|
||||
|
||||
@ -154,6 +157,7 @@ modulejs.define('core/ajax', ['$', 'amplify', 'base64', 'core/resource'], functi
|
||||
|
||||
$.ajax({
|
||||
url: url,
|
||||
type: 'POST',
|
||||
dataType: 'html',
|
||||
success: function (html) {
|
||||
|
||||
|
@ -5,7 +5,7 @@ modulejs.define('core/refresh', ['_', 'core/mode', 'core/ajax', 'model/entry'],
|
||||
|
||||
var found = {};
|
||||
|
||||
_.each(json.entries, function (jsonEntry) {
|
||||
_.each(json, function (jsonEntry) {
|
||||
|
||||
found[jsonEntry.absHref] = true;
|
||||
Entry.get(jsonEntry.absHref, jsonEntry.time, jsonEntry.size, jsonEntry.status, jsonEntry.content);
|
||||
|
@ -1,14 +1,76 @@
|
||||
<?php
|
||||
|
||||
require_once(str_replace("\\", "/", dirname(__FILE__)) . "/inc/init.php");
|
||||
$h5ai = $APP;
|
||||
$options = $h5ai->get_options();
|
||||
$app = $APP;
|
||||
$options = $app->get_options();
|
||||
|
||||
|
||||
list($action) = use_request_params(array("action"));
|
||||
|
||||
|
||||
if ($action === "getthumbsrc") {
|
||||
if ($action === "get") {
|
||||
|
||||
$response = array();
|
||||
|
||||
if (array_key_exists("options", $_REQUEST)) {
|
||||
|
||||
use_request_params("options");
|
||||
$response["options"] = $app->get_options();
|
||||
}
|
||||
|
||||
if (array_key_exists("types", $_REQUEST)) {
|
||||
|
||||
use_request_params("types");
|
||||
$response["types"] = $app->get_types();
|
||||
}
|
||||
|
||||
if (array_key_exists("langs", $_REQUEST)) {
|
||||
|
||||
use_request_params("langs");
|
||||
$response["langs"] = $app->get_l10n_list();
|
||||
}
|
||||
|
||||
if (array_key_exists("l10n", $_REQUEST)) {
|
||||
|
||||
list($iso_codes) = use_request_params("l10nCodes", "l10n");
|
||||
$iso_codes = explode(",", $iso_codes);
|
||||
$response["l10n"] = $app->get_l10n($iso_codes);
|
||||
}
|
||||
|
||||
if (array_key_exists("checks", $_REQUEST)) {
|
||||
|
||||
use_request_params("checks");
|
||||
$response["checks"] = $app->get_server_checks();
|
||||
}
|
||||
|
||||
if (array_key_exists("server", $_REQUEST)) {
|
||||
|
||||
use_request_params("server");
|
||||
$response["server"] = $app->get_server_details();
|
||||
}
|
||||
|
||||
if (array_key_exists("custom", $_REQUEST)) {
|
||||
|
||||
list($abs_href) = use_request_params("customHref", "custom");
|
||||
$response["custom"] = $app->get_customizations($abs_href);
|
||||
}
|
||||
|
||||
if (array_key_exists("entries", $_REQUEST)) {
|
||||
|
||||
list($abs_href, $what) = use_request_params("entriesHref", "entriesWhat", "entries");
|
||||
$what = intval($what, 10);
|
||||
$response["entries"] = $app->get_entries($abs_href, $what);
|
||||
}
|
||||
|
||||
if (count($_REQUEST)) {
|
||||
$response["unused"] = $_REQUEST;
|
||||
}
|
||||
|
||||
json_exit($response);
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "getthumbsrc") {
|
||||
|
||||
if (!$options["thumbnails"]["enabled"]) {
|
||||
json_fail(1, "thumbnails disabled");
|
||||
@ -21,7 +83,7 @@ if ($action === "getthumbsrc") {
|
||||
|
||||
list($type, $srcAbsHref, $mode, $width, $height) = use_request_params(array("type", "href", "mode", "width", "height"));
|
||||
|
||||
$thumb = new Thumb($h5ai);
|
||||
$thumb = new Thumb($app);
|
||||
$thumbHref = $thumb->thumb($type, $srcAbsHref, $mode, $width, $height);
|
||||
if ($thumbHref === null) {
|
||||
json_fail(3, "thumbnail creation failed");
|
||||
@ -38,7 +100,7 @@ else if ($action === "archive") {
|
||||
list($execution, $format, $hrefs) = use_request_params(array("execution", "format", "hrefs"));
|
||||
|
||||
normalized_require_once("/server/php/inc/Archive.php");
|
||||
$archive = new Archive($h5ai);
|
||||
$archive = new Archive($app);
|
||||
|
||||
$hrefs = explode(":", trim($hrefs));
|
||||
$target = $archive->create($execution, $format, $hrefs);
|
||||
@ -58,7 +120,7 @@ else if ($action === "getarchive") {
|
||||
list($id, $as) = use_request_params(array("id", "as"));
|
||||
json_fail(2, "file not found", !preg_match("/^package-/", $id));
|
||||
|
||||
$target = $h5ai->get_cache_abs_path() . "/" . $id;
|
||||
$target = $app->get_cache_abs_path() . "/" . $id;
|
||||
json_fail(3, "file not found", !file_exists($target));
|
||||
|
||||
header("Content-Type: application/octet-stream");
|
||||
@ -70,46 +132,6 @@ else if ($action === "getarchive") {
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "getchecks") {
|
||||
|
||||
$php = version_compare(PHP_VERSION, "5.2.1") >= 0;
|
||||
$archive = class_exists("PharData");
|
||||
$gd = false;
|
||||
if (function_exists("gd_info")) {
|
||||
$gdinfo = gd_info();
|
||||
$gd = array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"];
|
||||
}
|
||||
$cache = @is_writable($h5ai->get_cache_abs_path());
|
||||
$tar = @preg_match("/tar$/", `which tar`) > 0;
|
||||
$zip = @preg_match("/zip$/", `which zip`) > 0;
|
||||
$convert = @preg_match("/convert$/", `which convert`) > 0;
|
||||
$ffmpeg = @preg_match("/ffmpeg$/", `which ffmpeg`) > 0;
|
||||
$du = @preg_match("/du$/", `which du`) > 0;
|
||||
|
||||
json_exit(array(
|
||||
"php" => $php,
|
||||
"cache" => $cache,
|
||||
"thumbs" => $gd,
|
||||
"archive" => $archive,
|
||||
"tar" => $tar,
|
||||
"zip" => $zip,
|
||||
"convert" => $convert,
|
||||
"ffmpeg" => $ffmpeg,
|
||||
"du" => $du
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "getentries") {
|
||||
|
||||
list($href, $content) = use_request_params(array("href", "content"));
|
||||
|
||||
$content = intval($content, 10);
|
||||
|
||||
json_exit(array("entries" => $h5ai->get_entries($href, $content)));
|
||||
}
|
||||
|
||||
|
||||
else if ($action === "upload") {
|
||||
|
||||
list($href) = use_request_params(array("href"));
|
||||
@ -122,10 +144,10 @@ else if ($action === "upload") {
|
||||
json_fail(3, "something went wrong [" . $userfile["error"] . "]", $userfile["error"] !== 0);
|
||||
json_fail(4, "folders not supported", file_get_contents($userfile["tmp_name"]) === "null");
|
||||
|
||||
$upload_dir = $h5ai->get_abs_path($href);
|
||||
$code = $h5ai->get_http_code($href);
|
||||
$upload_dir = $app->get_abs_path($href);
|
||||
$code = $app->get_http_code($href);
|
||||
|
||||
json_fail(5, "upload dir no h5ai folder or ignored", $code !== "h5ai" || $h5ai->is_ignored($upload_dir));
|
||||
json_fail(5, "upload dir no h5ai folder or ignored", $code !== "h5ai" || $app->is_ignored($upload_dir));
|
||||
|
||||
$dest = $upload_dir . "/" . utf8_encode($userfile["name"]);
|
||||
|
||||
@ -150,13 +172,13 @@ else if ($action === "delete") {
|
||||
$d = normalize_path(dirname($href), true);
|
||||
$n = basename($href);
|
||||
|
||||
$code = $h5ai->get_http_code($d);
|
||||
$code = $app->get_http_code($d);
|
||||
if ($code == 401) {
|
||||
}
|
||||
|
||||
if ($code == "h5ai" && !$h5ai->is_ignored($n)) {
|
||||
if ($code == "h5ai" && !$app->is_ignored($n)) {
|
||||
|
||||
$absPath = $h5ai->get_abs_path($href);
|
||||
$absPath = $app->get_abs_path($href);
|
||||
|
||||
if (!unlink($absPath)) {
|
||||
$errors[] = $href;
|
||||
@ -181,13 +203,13 @@ else if ($action === "rename") {
|
||||
$d = normalize_path(dirname($href), true);
|
||||
$n = basename($href);
|
||||
|
||||
$code = $h5ai->get_http_code($d);
|
||||
$code = $app->get_http_code($d);
|
||||
if ($code == 401) {
|
||||
}
|
||||
|
||||
if ($code == "h5ai" && !$h5ai->is_ignored($n)) {
|
||||
if ($code == "h5ai" && !$app->is_ignored($n)) {
|
||||
|
||||
$absPath = $h5ai->get_abs_path($href);
|
||||
$absPath = $app->get_abs_path($href);
|
||||
$folder = normalize_path(dirname($absPath));
|
||||
|
||||
if (!rename($absPath, $folder . "/" . $name)) {
|
||||
|
@ -63,12 +63,6 @@ class App {
|
||||
}
|
||||
|
||||
|
||||
public function get_options() {
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
|
||||
public function get_abs_href($abs_path = null, $trailing_slash = true) {
|
||||
|
||||
if ($abs_path === null) {
|
||||
@ -136,6 +130,12 @@ class App {
|
||||
}
|
||||
|
||||
|
||||
public function get_options() {
|
||||
|
||||
return $this->options;
|
||||
}
|
||||
|
||||
|
||||
public function get_http_code($abs_href) {
|
||||
|
||||
if (!is_dir($this->get_abs_path($abs_href))) {
|
||||
@ -222,18 +222,6 @@ class App {
|
||||
|
||||
date_default_timezone_set("UTC");
|
||||
|
||||
// function _cmp_no_js_fallback($entry1, $entry2) {
|
||||
|
||||
// if ($entry1->isFolder && !$entry2->isFolder) {
|
||||
// return -1;
|
||||
// }
|
||||
// if (!$entry1->isFolder && $entry2->isFolder) {
|
||||
// return 1;
|
||||
// }
|
||||
|
||||
// return strcasecmp($entry1->abs_href, $entry2->abs_href);
|
||||
// }
|
||||
|
||||
$cache = array();
|
||||
$folder = Entry::get($this, $this->abs_path, $cache);
|
||||
$entries = $folder->get_content($cache);
|
||||
@ -242,7 +230,7 @@ class App {
|
||||
$html = "<table>";
|
||||
$html .= "<tr><th></th><th><span>Name</span></th><th><span>Last modified</span></th><th><span>Size</span></th></tr>";
|
||||
if ($folder->get_parent($cache)) {
|
||||
$html .= "<tr><td></td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
|
||||
$html .= "<tr><td>[^]</td><td><a href=\"..\">Parent Directory</a></td><td></td><td></td></tr>";
|
||||
}
|
||||
foreach ($entries as $entry) {
|
||||
$html .= "<tr>";
|
||||
@ -256,6 +244,108 @@ class App {
|
||||
|
||||
return $html;
|
||||
}
|
||||
|
||||
|
||||
public function get_types() {
|
||||
|
||||
return load_commented_json($this->app_abs_path . "/conf/types.json");
|
||||
}
|
||||
|
||||
|
||||
public function get_l10n_list() {
|
||||
|
||||
$langs = array();
|
||||
$l10nDir = $this->app_abs_path . "/conf/l10n";
|
||||
if (is_dir($l10nDir)) {
|
||||
if ($dir = opendir($l10nDir)) {
|
||||
while (($file = readdir($dir)) !== false) {
|
||||
if (ends_with($file, ".json")) {
|
||||
$translations = load_commented_json($l10nDir . "/" . $file);
|
||||
$langs[basename($file, ".json")] = $translations["lang"];
|
||||
}
|
||||
}
|
||||
closedir($dir);
|
||||
}
|
||||
}
|
||||
ksort($langs);
|
||||
return $langs;
|
||||
}
|
||||
|
||||
|
||||
public function get_l10n($iso_codes) {
|
||||
|
||||
if (!is_array($iso_codes)) {
|
||||
$iso_codes = func_get_args();
|
||||
}
|
||||
|
||||
$result = array();
|
||||
foreach ($iso_codes as $iso_code) {
|
||||
if ($iso_code !== "") {
|
||||
$file = $this->app_abs_path . "/conf/l10n/" . $iso_code . ".json";
|
||||
$result[$iso_code] = load_commented_json($file);
|
||||
$result[$iso_code]["isoCode"] = $iso_code;
|
||||
}
|
||||
}
|
||||
|
||||
return $result;
|
||||
}
|
||||
|
||||
|
||||
public function get_server_checks() {
|
||||
|
||||
$php = version_compare(PHP_VERSION, "5.2.1") >= 0;
|
||||
$archive = class_exists("PharData");
|
||||
$gd = false;
|
||||
if (function_exists("gd_info")) {
|
||||
$gdinfo = gd_info();
|
||||
$gd = array_key_exists("JPG Support", $gdinfo) && $gdinfo["JPG Support"] || array_key_exists("JPEG Support", $gdinfo) && $gdinfo["JPEG Support"];
|
||||
}
|
||||
$cache = @is_writable($this->get_cache_abs_path());
|
||||
$tar = @preg_match("/tar$/", `which tar`) > 0;
|
||||
$zip = @preg_match("/zip$/", `which zip`) > 0;
|
||||
$convert = @preg_match("/convert$/", `which convert`) > 0;
|
||||
$ffmpeg = @preg_match("/ffmpeg$/", `which ffmpeg`) > 0;
|
||||
$du = @preg_match("/du$/", `which du`) > 0;
|
||||
|
||||
return array(
|
||||
"php" => $php,
|
||||
"cache" => $cache,
|
||||
"thumbs" => $gd,
|
||||
"archive" => $archive,
|
||||
"tar" => $tar,
|
||||
"zip" => $zip,
|
||||
"convert" => $convert,
|
||||
"ffmpeg" => $ffmpeg,
|
||||
"du" => $du
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function get_server_details() {
|
||||
|
||||
return array(
|
||||
"backend" => "php",
|
||||
"apiHref" => $this->app_abs_href . "server/php/api.php",
|
||||
"name" => strtolower(preg_replace("/\\/.*$/", "", getenv("SERVER_SOFTWARE"))),
|
||||
"version" => strtolower(preg_replace("/^.*\\//", "", preg_replace("/\\s.*$/", "", getenv("SERVER_SOFTWARE"))))
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
public function get_customizations($abs_href) {
|
||||
|
||||
$abs_path = $this->get_abs_path($abs_href);
|
||||
|
||||
$file = $abs_path . "/" . App::$FILE_PREFIX . ".header.html";
|
||||
$header = is_string($file) && file_exists($file) ? file_get_contents($file) : null;
|
||||
$file = $abs_path . "/" . App::$FILE_PREFIX . ".footer.html";
|
||||
$footer = is_string($file) && file_exists($file) ? file_get_contents($file) : null;
|
||||
|
||||
return array(
|
||||
"header" => $header,
|
||||
"footer" => $footer
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
@ -6,6 +6,13 @@ class Entry {
|
||||
|
||||
public static function cmp($entry1, $entry2) {
|
||||
|
||||
if ($entry1->is_folder && !$entry2->is_folder) {
|
||||
return -1;
|
||||
}
|
||||
if (!$entry1->is_folder && $entry2->is_folder) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
return strcasecmp($entry1->abs_path, $entry2->abs_path);
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user