1
0
mirror of https://github.com/lrsjng/h5ai.git synced 2025-08-14 09:54:21 +02:00

Refactor url to href, to be more consistent.

This commit is contained in:
Lars Jung
2015-05-03 19:36:17 +02:00
parent 0f0d97dab5
commit 675efd6cd3
6 changed files with 40 additions and 40 deletions

View File

@@ -6,19 +6,19 @@ modulejs.define('boot', ['$'], function ($) {
var module = $('script[data-module]').data('module'); var module = $('script[data-module]').data('module');
var data = {action: 'get', setup: true, options: true, types: true, theme: true, langs: true}; var data = {action: 'get', setup: true, options: true, types: true, theme: true, langs: true};
var url; var href;
if (module === 'index') { if (module === 'index') {
url = '.'; href = '.';
} else if (module === 'info') { } else if (module === 'info') {
data.updatecmds = true; data.updatecmds = true;
url = 'server/php/index.php'; href = 'server/php/index.php';
} else { } else {
return; return;
} }
$.ajax({ $.ajax({
url: url, url: href,
data: data, data: data,
type: 'post', type: 'post',
dataType: 'json' dataType: 'json'

View File

@@ -58,16 +58,16 @@ class Api {
if (Util::get_boolean_request_param("custom", false)) { if (Util::get_boolean_request_param("custom", false)) {
$url = Util::get_request_param("customHref"); $href = Util::get_request_param("customHref");
$response["custom"] = $this->app->get_customizations($url); $response["custom"] = $this->app->get_customizations($href);
} }
if (Util::get_boolean_request_param("items", false)) { if (Util::get_boolean_request_param("items", false)) {
$url = Util::get_request_param("itemsHref"); $href = Util::get_request_param("itemsHref");
$what = Util::get_request_param("itemsWhat"); $what = Util::get_request_param("itemsWhat");
$what = is_numeric($what) ? intval($what, 10) : 1; $what = is_numeric($what) ? intval($what, 10) : 1;
$response["items"] = $this->app->get_items($url, $what); $response["items"] = $this->app->get_items($href, $what);
} }
Util::json_exit($response); Util::json_exit($response);
@@ -80,15 +80,15 @@ class Api {
Util::json_fail(Util::ERR_UNSUPPORTED, "thumbnails not supported", !HAS_PHP_JPEG); Util::json_fail(Util::ERR_UNSUPPORTED, "thumbnails not supported", !HAS_PHP_JPEG);
$type = Util::get_request_param("type"); $type = Util::get_request_param("type");
$src_url = Util::get_request_param("href"); $src_href = Util::get_request_param("href");
$width = Util::get_request_param("width"); $width = Util::get_request_param("width");
$height = Util::get_request_param("height"); $height = Util::get_request_param("height");
$thumb = new Thumb($this->app); $thumb = new Thumb($this->app);
$thumb_url = $thumb->thumb($type, $src_url, $width, $height); $thumb_href = $thumb->thumb($type, $src_href, $width, $height);
Util::json_fail(Util::ERR_FAILED, "thumbnail creation failed", $thumb_url === null); Util::json_fail(Util::ERR_FAILED, "thumbnail creation failed", $thumb_href === null);
Util::json_exit(array("absHref" => $thumb_url)); Util::json_exit(array("absHref" => $thumb_href));
} }

View File

@@ -110,7 +110,7 @@ class App {
} }
public function to_url($path, $trailing_slash = true) { public function to_href($path, $trailing_slash = true) {
$rel_path = substr($path, strlen(ROOT_PATH)); $rel_path = substr($path, strlen(ROOT_PATH));
$parts = explode("/", $rel_path); $parts = explode("/", $rel_path);
@@ -125,10 +125,10 @@ class App {
} }
public function to_path($url) { public function to_path($href) {
$rel_url = substr($url, strlen(ROOT_HREF)); $rel_href = substr($href, strlen(ROOT_HREF));
return Util::normalize_path(ROOT_PATH . "/" . rawurldecode($rel_url)); return Util::normalize_path(ROOT_PATH . "/" . rawurldecode($rel_href));
} }
@@ -157,7 +157,7 @@ class App {
foreach (scandir($path) as $name) { foreach (scandir($path) as $name) {
if ( if (
$this->is_hidden($name) $this->is_hidden($name)
|| $this->is_hidden($this->to_url($path) . $name) || $this->is_hidden($this->to_href($path) . $name)
|| (!is_readable($path .'/'. $name) && $this->get_option("view.hideIf403", false)) || (!is_readable($path .'/'. $name) && $this->get_option("view.hideIf403", false))
) { ) {
continue; continue;
@@ -169,9 +169,9 @@ class App {
} }
public function is_managed_url($url) { public function is_managed_href($href) {
return $this->is_managed_path($this->to_path($url)); return $this->is_managed_path($this->to_path($href));
} }
@@ -205,14 +205,14 @@ class App {
} }
public function get_items($url, $what) { public function get_items($href, $what) {
if (!$this->is_managed_url($url)) { if (!$this->is_managed_href($href)) {
return array(); return array();
} }
$cache = array(); $cache = array();
$folder = Item::get($this, $this->to_path($url), $cache); $folder = Item::get($this, $this->to_path($href), $cache);
// add content of subfolders // add content of subfolders
if ($what >= 2 && $folder !== null) { if ($what >= 2 && $folder !== null) {
@@ -286,7 +286,7 @@ class App {
$html .= "<tr>"; $html .= "<tr>";
$html .= "<td class='fb-i'><img src='" . APP_HREF . "client/images/fallback/" . $type . ".png' alt='" . $type . "'/></td>"; $html .= "<td class='fb-i'><img src='" . APP_HREF . "client/images/fallback/" . $type . ".png' alt='" . $type . "'/></td>";
$html .= "<td class='fb-n'><a href='" . $item->url . "'>" . basename($item->path) . "</a></td>"; $html .= "<td class='fb-n'><a href='" . $item->href . "'>" . basename($item->path) . "</a></td>";
$html .= "<td class='fb-d'>" . date("Y-m-d H:i", $item->date) . "</td>"; $html .= "<td class='fb-d'>" . date("Y-m-d H:i", $item->date) . "</td>";
$html .= "<td class='fb-s'>" . ($item->size !== null ? intval($item->size / 1000) . " KB" : "" ) . "</td>"; $html .= "<td class='fb-s'>" . ($item->size !== null ? intval($item->size / 1000) . " KB" : "" ) . "</td>";
$html .= "</tr>"; $html .= "</tr>";
@@ -350,7 +350,7 @@ class App {
} }
public function get_customizations($url) { public function get_customizations($href) {
if (!$this->get_option("custom.enabled", false)) { if (!$this->get_option("custom.enabled", false)) {
return array( return array(
@@ -361,7 +361,7 @@ class App {
); );
} }
$path = $this->to_path($url); $path = $this->to_path($href);
$header = null; $header = null;
$header_type = null; $header_type = null;

View File

@@ -15,9 +15,9 @@ class Archive {
} }
public function output($type, $base_url, $urls) { public function output($type, $base_href, $hrefs) {
$this->base_path = $this->app->to_path($base_url); $this->base_path = $this->app->to_path($base_href);
if (!$this->app->is_managed_path($this->base_path)) { if (!$this->app->is_managed_path($this->base_path)) {
return 500; return 500;
} }
@@ -25,7 +25,7 @@ class Archive {
$this->dirs = array(); $this->dirs = array();
$this->files = array(); $this->files = array();
$this->add_hrefs($urls); $this->add_hrefs($hrefs);
if (count($this->dirs) === 0 && count($this->files) === 0) { if (count($this->dirs) === 0 && count($this->files) === 0) {
if ($type === "php-tar") { if ($type === "php-tar") {
@@ -150,9 +150,9 @@ class Archive {
} }
private function add_hrefs($urls) { private function add_hrefs($hrefs) {
foreach ($urls as $href) { foreach ($hrefs as $href) {
if (trim($href) === "") { if (trim($href) === "") {
continue; continue;
@@ -161,7 +161,7 @@ class Archive {
$d = Util::normalize_path(dirname($href), true); $d = Util::normalize_path(dirname($href), true);
$n = basename($href); $n = basename($href);
if ($this->app->is_managed_url($d) && !$this->app->is_hidden($n)) { if ($this->app->is_managed_href($d) && !$this->app->is_hidden($n)) {
$real_file = $this->app->to_path($href); $real_file = $this->app->to_path($href);
$archived_file = preg_replace("!^" . preg_quote(Util::normalize_path($this->base_path, true)) . "!", "", $real_file); $archived_file = preg_replace("!^" . preg_quote(Util::normalize_path($this->base_path, true)) . "!", "", $real_file);

View File

@@ -35,7 +35,7 @@ class Item {
public $app; public $app;
public $path, $url, $date, $size; public $path, $href, $date, $size;
public $is_folder, $is_content_fetched; public $is_folder, $is_content_fetched;
@@ -45,7 +45,7 @@ class Item {
$this->path = Util::normalize_path($path, false); $this->path = Util::normalize_path($path, false);
$this->is_folder = is_dir($this->path); $this->is_folder = is_dir($this->path);
$this->url = $app->to_url($this->path, $this->is_folder); $this->href = $app->to_href($this->path, $this->is_folder);
$this->date = @filemtime($this->path); $this->date = @filemtime($this->path);
$this->size = Util::filesize($app, $this->path); $this->size = Util::filesize($app, $this->path);
$this->is_content_fetched = false; $this->is_content_fetched = false;
@@ -55,13 +55,13 @@ class Item {
public function to_json_object() { public function to_json_object() {
$obj = array( $obj = array(
"absHref" => $this->url, "absHref" => $this->href,
"time" => $this->date * 1000, // seconds (PHP) to milliseconds (JavaScript) "time" => $this->date * 1000, // seconds (PHP) to milliseconds (JavaScript)
"size" => $this->size "size" => $this->size
); );
if ($this->is_folder) { if ($this->is_folder) {
$obj["isManaged"] = $this->app->is_managed_url($this->url); $obj["isManaged"] = $this->app->is_managed_href($this->href);
$obj["content"] = $this->is_content_fetched; $obj["content"] = $this->is_content_fetched;
} }
@@ -83,7 +83,7 @@ class Item {
$items = array(); $items = array();
if (!$this->app->is_managed_url($this->url)) { if (!$this->app->is_managed_href($this->href)) {
return $items; return $items;
} }

View File

@@ -23,9 +23,9 @@ class Thumb {
} }
public function thumb($type, $source_url, $width, $height) { public function thumb($type, $source_href, $width, $height) {
$source_path = $this->app->to_path($source_url); $source_path = $this->app->to_path($source_href);
if (!file_exists($source_path) || Util::starts_with($source_path, CACHE_PATH)) { if (!file_exists($source_path) || Util::starts_with($source_path, CACHE_PATH)) {
return null; return null;
} }
@@ -55,7 +55,7 @@ class Thumb {
$name = "thumb-" . sha1("$source_path") . "-" . $width . "x" . $height . ".jpg"; $name = "thumb-" . sha1("$source_path") . "-" . $width . "x" . $height . ".jpg";
$thumb_path = $this->thumbs_path . "/" . $name; $thumb_path = $this->thumbs_path . "/" . $name;
$thumb_url = $this->thumbs_href . "/" . $name; $thumb_href = $this->thumbs_href . "/" . $name;
if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) { if (!file_exists($thumb_path) || filemtime($source_path) >= filemtime($thumb_path)) {
@@ -77,7 +77,7 @@ class Thumb {
$image->save_dest_jpeg($thumb_path, 80); $image->save_dest_jpeg($thumb_path, 80);
} }
return file_exists($thumb_path) ? $thumb_url : null; return file_exists($thumb_path) ? $thumb_href : null;
} }