Add theme support.

This commit is contained in:
Lars Jung 2014-06-01 03:48:53 +02:00
parent c6b35c82e8
commit 7e0420073b
20 changed files with 430 additions and 12 deletions

View file

@ -46,6 +46,12 @@ class Api {
$response["types"] = $this->app->get_types();
}
if (has_request_param("theme")) {
use_request_param("theme");
$response["theme"] = $this->app->get_theme();
}
if (has_request_param("langs")) {
use_request_param("langs");

View file

@ -3,6 +3,7 @@
class App {
private static $RE_DELIMITER = "|";
private static $ICON_EXTS = array("svg", "png", "jpg");
private $options;
@ -34,6 +35,38 @@ class App {
}
public function get_icon($theme, $type, $fallback = null) {
foreach (App::$ICON_EXTS as $ext) {
$icon = "${theme}/icons/${type}.${ext}";
if (is_file(APP_PATH . "/client/themes/${icon}")) {
return $icon;
}
}
return $fallback;
}
public function get_theme() {
$theme = $this->options["view"]["theme"];
$types = $this->get_types();
$icons = array();
foreach (array("file", "folder", "folder-page", "folder-parent") as $type) {
$icons[$type] = $this->get_icon($theme, $type, "default/icons/${type}.svg");
}
foreach ($types as $type => $exts) {
if (!array_key_exists($type, $icons)) {
$icons[$type] = $this->get_icon($theme, $type, $icons["file"]);
}
}
return $icons;
}
public function to_url($path, $trailing_slash = true) {
$rel_path = substr($path, strlen(ROOT_PATH));
@ -179,7 +212,7 @@ class App {
if ($folder->get_parent($cache)) {
$html .= "<tr>";
$html .= "<td class='fb-i'><img src='" . APP_HREF . "client/images/fallback/parent.png' alt='folder-parent'/></td>";
$html .= "<td class='fb-i'><img src='" . APP_HREF . "client/themes/fallback/icons/folder-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>";
@ -190,7 +223,7 @@ class App {
$type = $item->is_folder ? "folder" : "file";
$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/themes/fallback/icons/" . $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>";