Add initial theme support. Remove get_http_code.

This commit is contained in:
Lars Jung 2014-05-29 03:55:46 +02:00
parent 0ce49c3535
commit 844b37d165
169 changed files with 29998 additions and 294 deletions

View file

@ -139,9 +139,8 @@ class Api {
json_fail(4, "folders not supported", file_get_contents($userfile["tmp_name"]) === "null");
$upload_dir = $this->app->to_path($href);
$code = $this->app->get_http_code($href);
json_fail(5, "upload dir no h5ai folder or ignored", $code !== MAGIC_SEQUENCE || $this->app->is_ignored($upload_dir));
json_fail(5, "upload dir no h5ai folder or ignored", !$this->app->is_managed_url($href) || $this->app->is_ignored($upload_dir));
$dest = $upload_dir . "/" . utf8_encode($userfile["name"]);
@ -165,9 +164,7 @@ class Api {
$d = normalize_path(dirname($href), true);
$n = basename($href);
$code = $this->app->get_http_code($d);
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
if ($this->app->is_managed_url($href) && !$this->app->is_ignored($n)) {
$path = $this->app->to_path($href);
@ -192,9 +189,7 @@ class Api {
$d = normalize_path(dirname($href), true);
$n = basename($href);
$code = $this->app->get_http_code($d);
if ($code == MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
if ($this->app->is_managed_url($d) && !$this->app->is_ignored($n)) {
$path = $this->app->to_path($href);
$folder = normalize_path(dirname($path));

View file

@ -91,38 +91,41 @@ class App {
}
public function get_http_code($url) {
public function is_managed_url($url) {
$path = $this->to_path($url);
return $this->is_managed_path($this->to_path($url));
}
public function is_managed_path($path) {
if (!is_dir($path) || strpos($path, '../') || strpos($path, '/..') || $path == '..') {
return 500;
return false;
}
foreach ($this->options["view"]["indexFiles"] as $name) {
if (file_exists($path . "/" . $name)) {
return 200;
return false;
}
}
while ($path !== ROOT_PATH) {
if (@is_dir($path . "/_h5ai/server")) {
return 200;
return false;
}
$parent_path = normalize_path(dirname($path));
if ($parent_path === $path) {
return 200;
return false;
}
$path = $parent_path;
}
return MAGIC_SEQUENCE;
return true;
}
public function get_items($url, $what) {
$code = $this->get_http_code($url);
if ($code !== MAGIC_SEQUENCE) {
if (!$this->is_managed_url($url)) {
return array();
}
@ -171,7 +174,7 @@ class App {
if ($folder->get_parent($cache)) {
$html .= "<tr>";
$html .= "<td class='fb-i'><img src='" . APP_URL . "client/icons/96/folder-parent.png' alt='folder-parent'/></td>";
$html .= "<td class='fb-i'><img src='" . APP_URL . "client/images/fallback/parent.png' alt='folder-parent'/></td>";
$html .= "<td class='fb-n'><a href='..'>Parent Directory</a></td>";
$html .= "<td class='fb-d'></td>";
$html .= "<td class='fb-s'></td>";
@ -179,10 +182,13 @@ class App {
}
foreach ($items as $item) {
$type = $item->is_folder ? "folder" : "default";
$type = "file";
if ($item->is_folder) {
$type = $this->is_managed_url($item->url) ? "folder" : "folder-page";
}
$html .= "<tr>";
$html .= "<td class='fb-i'><img src='" . APP_URL . "client/icons/96/" . $type . ".png' alt='" . $type . "'/></td>";
$html .= "<td class='fb-i'><img src='" . APP_URL . "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-d'>" . date("Y-m-d H:i", $item->date) . "</td>";
$html .= "<td class='fb-s'>" . ($item->size !== null ? intval($item->size / 1000) . " KB" : "" ) . "</td>";

View file

@ -148,9 +148,7 @@ class Archive {
$d = normalize_path(dirname($href), true);
$n = basename($href);
$code = $this->app->get_http_code($d);
if ($code === MAGIC_SEQUENCE && !$this->app->is_ignored($n)) {
if ($this->app->is_managed_url($d) && !$this->app->is_ignored($n)) {
$real_file = $this->app->to_path($href);
$archived_file = preg_replace("!^" . preg_quote(normalize_path(CURRENT_PATH, true)) . "!", "", $real_file);
@ -175,9 +173,7 @@ class Archive {
private function add_dir($real_dir, $archived_dir) {
$code = $this->app->get_http_code($this->app->to_url($real_dir));
if ($code === MAGIC_SEQUENCE) {
if ($this->app->is_managed_path($real_dir)) {
$this->dirs[] = $archived_dir;
$files = $this->app->read_dir($real_dir);

View file

@ -99,7 +99,7 @@ class Item {
);
if ($this->is_folder) {
$obj["status"] = $this->app->get_http_code($this->url);
$obj["is_managed"] = $this->app->is_managed_url($this->url);
$obj["content"] = $this->is_content_fetched;
}
@ -121,7 +121,7 @@ class Item {
$items = array();
if ($this->app->get_http_code($this->url) !== MAGIC_SEQUENCE) {
if (!$this->app->is_managed_url($this->url)) {
return $items;
}

View file

@ -10,7 +10,6 @@ function setup() {
define("BACKEND", "PHP");
define("API", true);
define("MAGIC_SEQUENCE", "={{pkg.name}}=");
define("FILE_PREFIX", "_{{pkg.name}}");