mirror of
https://github.com/lrsjng/h5ai.git
synced 2025-05-24 12:07:10 -04:00
Refactor PHP. Switch to explicit string literals where possible.
This commit is contained in:
parent
1e11b804ab
commit
cb9b8c6244
1 changed files with 44 additions and 44 deletions
|
@ -15,32 +15,32 @@ class Api {
|
|||
|
||||
public function apply() {
|
||||
|
||||
$action = $this->request->query("action");
|
||||
$supported = ["download", "get", "login", "logout"];
|
||||
Util::json_fail(Util::ERR_UNSUPPORTED, "unsupported action", !in_array($action, $supported));
|
||||
$action = $this->request->query('action');
|
||||
$supported = ['download', 'get', 'login', 'logout'];
|
||||
Util::json_fail(Util::ERR_UNSUPPORTED, 'unsupported action', !in_array($action, $supported));
|
||||
|
||||
$methodname = "on_${action}";
|
||||
$methodname = 'on_' . $action;
|
||||
$this->$methodname();
|
||||
}
|
||||
|
||||
private function on_download() {
|
||||
|
||||
Util::json_fail(Util::ERR_DISABLED, "download disabled", !$this->app->query_option("download.enabled", false));
|
||||
Util::json_fail(Util::ERR_DISABLED, 'download disabled', !$this->app->query_option('download.enabled', false));
|
||||
|
||||
$as = $this->request->query("as");
|
||||
$type = $this->request->query("type");
|
||||
$base_href = $this->request->query("baseHref");
|
||||
$hrefs = $this->request->query("hrefs");
|
||||
$as = $this->request->query('as');
|
||||
$type = $this->request->query('type');
|
||||
$base_href = $this->request->query('baseHref');
|
||||
$hrefs = $this->request->query('hrefs');
|
||||
|
||||
$archive = new Archive($this->app);
|
||||
|
||||
set_time_limit(0);
|
||||
header("Content-Type: application/octet-stream");
|
||||
header("Content-Disposition: attachment; filename=\"$as\"");
|
||||
header("Connection: close");
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-Disposition: attachment; filename="' . $as . '"');
|
||||
header('Connection: close');
|
||||
$ok = $archive->output($type, $base_href, $hrefs);
|
||||
|
||||
Util::json_fail(Util::ERR_FAILED, "packaging failed", !$ok);
|
||||
Util::json_fail(Util::ERR_FAILED, 'packaging failed', !$ok);
|
||||
exit;
|
||||
}
|
||||
|
||||
|
@ -48,68 +48,68 @@ class Api {
|
|||
|
||||
$response = [];
|
||||
|
||||
foreach (["langs", "options", "types"] as $name) {
|
||||
foreach (['langs', 'options', 'types'] as $name) {
|
||||
if ($this->request->query_boolean($name, false)) {
|
||||
|
||||
$methodname = "get_${name}";
|
||||
$methodname = 'get_' . $name;
|
||||
$response[$name] = $this->app->$methodname();
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->request->query_boolean("setup", false)) {
|
||||
if ($this->request->query_boolean('setup', false)) {
|
||||
|
||||
$response["setup"] = $this->setup->to_jsono();
|
||||
$response['setup'] = $this->setup->to_jsono();
|
||||
}
|
||||
|
||||
if ($this->request->query_boolean("theme", false)) {
|
||||
if ($this->request->query_boolean('theme', false)) {
|
||||
|
||||
$theme = new Theme($this->app);
|
||||
$response["theme"] = $theme->get_icons();
|
||||
$response['theme'] = $theme->get_icons();
|
||||
}
|
||||
|
||||
if ($this->request->query("items", false)) {
|
||||
if ($this->request->query('items', false)) {
|
||||
|
||||
$href = $this->request->query("items.href");
|
||||
$what = $this->request->query_numeric("items.what");
|
||||
$href = $this->request->query('items.href');
|
||||
$what = $this->request->query_numeric('items.what');
|
||||
|
||||
$response["items"] = $this->app->get_items($href, $what);
|
||||
$response['items'] = $this->app->get_items($href, $what);
|
||||
}
|
||||
|
||||
if ($this->request->query("custom", false)) {
|
||||
if ($this->request->query('custom', false)) {
|
||||
|
||||
Util::json_fail(Util::ERR_DISABLED, "custom disabled", !$this->app->query_option("custom.enabled", false));
|
||||
$href = $this->request->query("custom");
|
||||
Util::json_fail(Util::ERR_DISABLED, 'custom disabled', !$this->app->query_option('custom.enabled', false));
|
||||
$href = $this->request->query('custom');
|
||||
|
||||
$custom = new Custom($this->app);
|
||||
$response["custom"] = $custom->get_customizations($href);
|
||||
$response['custom'] = $custom->get_customizations($href);
|
||||
}
|
||||
|
||||
if ($this->request->query("l10n", false)) {
|
||||
if ($this->request->query('l10n', false)) {
|
||||
|
||||
Util::json_fail(Util::ERR_DISABLED, "l10n disabled", !$this->app->query_option("l10n.enabled", false));
|
||||
$iso_codes = $this->request->query_array("l10n");
|
||||
Util::json_fail(Util::ERR_DISABLED, 'l10n disabled', !$this->app->query_option('l10n.enabled', false));
|
||||
$iso_codes = $this->request->query_array('l10n');
|
||||
|
||||
$iso_codes = array_filter($iso_codes);
|
||||
$response["l10n"] = $this->app->get_l10n($iso_codes);
|
||||
$response['l10n'] = $this->app->get_l10n($iso_codes);
|
||||
}
|
||||
|
||||
if ($this->request->query("search", false)) {
|
||||
if ($this->request->query('search', false)) {
|
||||
|
||||
Util::json_fail(Util::ERR_DISABLED, "search disabled", !$this->app->query_option("search.enabled", false));
|
||||
$href = $this->request->query("search.href");
|
||||
$pattern = $this->request->query("search.pattern");
|
||||
Util::json_fail(Util::ERR_DISABLED, 'search disabled', !$this->app->query_option('search.enabled', false));
|
||||
$href = $this->request->query('search.href');
|
||||
$pattern = $this->request->query('search.pattern');
|
||||
|
||||
$search = new Search($this->app);
|
||||
$response["search"] = $search->get_items($href, $pattern);
|
||||
$response['search'] = $search->get_items($href, $pattern);
|
||||
}
|
||||
|
||||
if ($this->request->query("thumbs", false)) {
|
||||
if ($this->request->query('thumbs', false)) {
|
||||
|
||||
Util::json_fail(Util::ERR_DISABLED, "thumbnails disabled", !$this->app->query_option("thumbnails.enabled", false));
|
||||
Util::json_fail(Util::ERR_UNSUPPORTED, "thumbnails not supported", !$this->setup->get("HAS_PHP_JPEG"));
|
||||
$thumbs = $this->request->query_array("thumbs");
|
||||
Util::json_fail(Util::ERR_DISABLED, 'thumbnails disabled', !$this->app->query_option('thumbnails.enabled', false));
|
||||
Util::json_fail(Util::ERR_UNSUPPORTED, 'thumbnails not supported', !$this->setup->get('HAS_PHP_JPEG'));
|
||||
$thumbs = $this->request->query_array('thumbs');
|
||||
|
||||
$response["thumbs"] = $this->app->get_thumbs($thumbs);
|
||||
$response['thumbs'] = $this->app->get_thumbs($thumbs);
|
||||
}
|
||||
|
||||
Util::json_exit($response);
|
||||
|
@ -117,12 +117,12 @@ class Api {
|
|||
|
||||
private function on_login() {
|
||||
|
||||
$pass = $this->request->query("pass");
|
||||
Util::json_exit(["asAdmin" => $this->app->login_admin($pass)]);
|
||||
$pass = $this->request->query('pass');
|
||||
Util::json_exit(['asAdmin' => $this->app->login_admin($pass)]);
|
||||
}
|
||||
|
||||
private function on_logout() {
|
||||
|
||||
Util::json_exit(["asAdmin" => $this->app->logout_admin()]);
|
||||
Util::json_exit(['asAdmin' => $this->app->logout_admin()]);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue