From 7e0420073b96b0a3998829a75a70f16a94131749 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 1 Jun 2014 03:48:53 +0200 Subject: [PATCH] Add theme support. --- CHANGELOG.md | 6 +- src/_h5ai/client/js/inc/core/resource.js | 5 +- src/_h5ai/client/js/scripts.js | 2 +- .../evolvere/icons/{default.svg => file.svg} | 0 .../client/themes/faenza/icons/blank.png | Bin 119 -> 0 bytes .../faenza/icons/{default.png => file.png} | Bin .../fallback/icons}/file.png | Bin .../client/themes/fallback/icons/file.svg | 75 +++++++++++++++++ .../fallback/icons}/folder-page.png | Bin .../themes/fallback/icons/folder-page.svg | 75 +++++++++++++++++ .../fallback/icons/folder-parent-0.png} | Bin .../themes/fallback/icons/folder-parent-0.svg | 77 ++++++++++++++++++ .../themes/fallback/icons/folder-parent.png | Bin 0 -> 784 bytes .../themes/fallback/icons/folder-parent.svg | 77 ++++++++++++++++++ .../fallback/icons}/folder.png | Bin .../client/themes/fallback/icons/folder.svg | 75 +++++++++++++++++ src/_h5ai/conf/options.json | 4 +- src/_h5ai/conf/types.json | 3 +- src/_h5ai/server/php/inc/class-api.php | 6 ++ src/_h5ai/server/php/inc/class-app.php | 37 ++++++++- 20 files changed, 430 insertions(+), 12 deletions(-) rename src/_h5ai/client/themes/evolvere/icons/{default.svg => file.svg} (100%) delete mode 100644 src/_h5ai/client/themes/faenza/icons/blank.png rename src/_h5ai/client/themes/faenza/icons/{default.png => file.png} (100%) rename src/_h5ai/client/{images/fallback => themes/fallback/icons}/file.png (100%) create mode 100644 src/_h5ai/client/themes/fallback/icons/file.svg rename src/_h5ai/client/{images/fallback => themes/fallback/icons}/folder-page.png (100%) create mode 100644 src/_h5ai/client/themes/fallback/icons/folder-page.svg rename src/_h5ai/client/{images/fallback/parent.png => themes/fallback/icons/folder-parent-0.png} (100%) create mode 100644 src/_h5ai/client/themes/fallback/icons/folder-parent-0.svg create mode 100644 src/_h5ai/client/themes/fallback/icons/folder-parent.png create mode 100644 src/_h5ai/client/themes/fallback/icons/folder-parent.svg rename src/_h5ai/client/{images/fallback => themes/fallback/icons}/folder.png (100%) create mode 100644 src/_h5ai/client/themes/fallback/icons/folder.svg diff --git a/CHANGELOG.md b/CHANGELOG.md index 9304a9f5..c895be4e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,9 +8,9 @@ * adds initial theme support * adds icons from [Evolvere Icon Theme](http://franksouza183.deviantart.com/art/Evolvere-Icon-theme-440718295) * adds PHP variant to calc folder sizes -* adds scroll position reset on location change (issue #279) +* adds scroll position reset on location change (issue [#279](https://github.com/lrsjng/h5ai/issues/279)) * adds "hide if 403" option -* fixes QR code URI origin (issue #287) +* fixes QR code URI origin (issue [#287](https://github.com/lrsjng/h5ai/issues/287)) * adds Google UA support * extends selectable icon sizes (adds 128px, 192px, 256px, 384px) * updates H5BP to 4.3.0 @@ -25,7 +25,7 @@ ## v0.24.1 - *2014-04-09* -* security fixes! (issues #268, #269) +* security fixes! (issues [#268](https://github.com/lrsjng/h5ai/issues/268), [#269](https://github.com/lrsjng/h5ai/issues/269)) * language updates (`fi`, `fr`, `hi`, `it`, `zh-tw`) * fixes WinOS command detection diff --git a/src/_h5ai/client/js/inc/core/resource.js b/src/_h5ai/client/js/inc/core/resource.js index 90b5c35f..562f9c88 100644 --- a/src/_h5ai/client/js/inc/core/resource.js +++ b/src/_h5ai/client/js/inc/core/resource.js @@ -1,5 +1,5 @@ -modulejs.define('core/resource', ['core/settings'], function (settings) { +modulejs.define('core/resource', ['config', 'core/settings'], function (config, settings) { var image = function (id) { @@ -8,8 +8,7 @@ modulejs.define('core/resource', ['core/settings'], function (settings) { icon = function (id) { - return settings.appHref + 'client/themes/faenza/icons/' + id + '.png'; - // return settings.appHref + 'client/themes/evolvere/icons/' + id + '.svg'; + return settings.appHref + 'client/themes/' + config.theme[id]; }; return { diff --git a/src/_h5ai/client/js/scripts.js b/src/_h5ai/client/js/scripts.js index 24fa44dd..0250cdbf 100644 --- a/src/_h5ai/client/js/scripts.js +++ b/src/_h5ai/client/js/scripts.js @@ -46,7 +46,7 @@ $.ajax({ url: url, - data: {action: 'get', setup: true, options: true, types: true, langs: true}, + data: {action: 'get', setup: true, options: true, types: true, theme: true, langs: true}, type: 'POST', dataType: 'json', success: function (config) { diff --git a/src/_h5ai/client/themes/evolvere/icons/default.svg b/src/_h5ai/client/themes/evolvere/icons/file.svg similarity index 100% rename from src/_h5ai/client/themes/evolvere/icons/default.svg rename to src/_h5ai/client/themes/evolvere/icons/file.svg diff --git a/src/_h5ai/client/themes/faenza/icons/blank.png b/src/_h5ai/client/themes/faenza/icons/blank.png deleted file mode 100644 index 3418e3e242cfd92f3a7cbd47cad9ca410dd863b6..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 119 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeK3?y%aJ*@^(Ea{HEjtmSN`?>!lvI6 + + + + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + diff --git a/src/_h5ai/client/images/fallback/folder-page.png b/src/_h5ai/client/themes/fallback/icons/folder-page.png similarity index 100% rename from src/_h5ai/client/images/fallback/folder-page.png rename to src/_h5ai/client/themes/fallback/icons/folder-page.png diff --git a/src/_h5ai/client/themes/fallback/icons/folder-page.svg b/src/_h5ai/client/themes/fallback/icons/folder-page.svg new file mode 100644 index 00000000..7f2e4a06 --- /dev/null +++ b/src/_h5ai/client/themes/fallback/icons/folder-page.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + diff --git a/src/_h5ai/client/images/fallback/parent.png b/src/_h5ai/client/themes/fallback/icons/folder-parent-0.png similarity index 100% rename from src/_h5ai/client/images/fallback/parent.png rename to src/_h5ai/client/themes/fallback/icons/folder-parent-0.png diff --git a/src/_h5ai/client/themes/fallback/icons/folder-parent-0.svg b/src/_h5ai/client/themes/fallback/icons/folder-parent-0.svg new file mode 100644 index 00000000..bbccccd0 --- /dev/null +++ b/src/_h5ai/client/themes/fallback/icons/folder-parent-0.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + diff --git a/src/_h5ai/client/themes/fallback/icons/folder-parent.png b/src/_h5ai/client/themes/fallback/icons/folder-parent.png new file mode 100644 index 0000000000000000000000000000000000000000..2298b5179d5e6a4e320f97f6d8ac1f4b11a298dd GIT binary patch literal 784 zcmeAS@N?(olHy`uVBq!ia0vp^2_VeD1|%QND7OGoEX7WqAsj$Z!;#Vf2?p zUk71ECym(^Ktah8*NBqf{Irtt#G+J&^73-M%)IR4`<7^~W?*1S@^oVA%dDb*V%tDyq9A^3hb~P)S3^ z<7|zVl?;K$uM2QoW?0m}{;b;!rU|JvxoS<;4%s@+VujzLmw%OHvBK`f}ExEUIza-t>cDL%idUi+D>+8GLoqkd3 z^NvB8RqTkq{TrhioOfRf08HA?k@)!iHneGCuq6NmoG6?~~+Z%}5iU?Q6M&8EKb>!W#V SBJKbaCWEJ|pUXO@geCwTggD#) literal 0 HcmV?d00001 diff --git a/src/_h5ai/client/themes/fallback/icons/folder-parent.svg b/src/_h5ai/client/themes/fallback/icons/folder-parent.svg new file mode 100644 index 00000000..7ef538dc --- /dev/null +++ b/src/_h5ai/client/themes/fallback/icons/folder-parent.svg @@ -0,0 +1,77 @@ + + + + + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + diff --git a/src/_h5ai/client/images/fallback/folder.png b/src/_h5ai/client/themes/fallback/icons/folder.png similarity index 100% rename from src/_h5ai/client/images/fallback/folder.png rename to src/_h5ai/client/themes/fallback/icons/folder.png diff --git a/src/_h5ai/client/themes/fallback/icons/folder.svg b/src/_h5ai/client/themes/fallback/icons/folder.svg new file mode 100644 index 00000000..243e2ba0 --- /dev/null +++ b/src/_h5ai/client/themes/fallback/icons/folder.svg @@ -0,0 +1,75 @@ + + + + + + + + + + + + image/svg+xml + + Gnome Symbolic Icon Theme + + + + Gnome Symbolic Icon Theme + + diff --git a/src/_h5ai/conf/options.json b/src/_h5ai/conf/options.json index 52e2ea5e..751bdc36 100644 --- a/src/_h5ai/conf/options.json +++ b/src/_h5ai/conf/options.json @@ -42,6 +42,7 @@ Options - smartBrowsing: use History API if available (no need to reload the whole page) - extInNewWindow: open non-h5ai links in new window/tab - hideIf403: hide files and folders that are not readable by the server + - theme: name of one of the folders in "_h5ai/client/themes", defaults to "fallback" */ "view": { "modes": ["details", "grid", "icons"], @@ -54,7 +55,8 @@ Options "ignore": ["^\\.", "^_{{pkg.name}}"], "smartBrowsing": true, "extInNewWindow": false, - "hideIf403": true + "hideIf403": true, + "theme": "fallback" }, diff --git a/src/_h5ai/conf/types.json b/src/_h5ai/conf/types.json index 3fa61997..ccde74f3 100644 --- a/src/_h5ai/conf/types.json +++ b/src/_h5ai/conf/types.json @@ -10,7 +10,6 @@ File types mapped to file extensions "audio": [".aif", ".aiff", ".flac", ".m4a", ".mid", ".mp3", ".mpa", ".ra", ".ogg", ".wav", ".wma"], "authors": ["authors"], "bin": [".class", ".o", ".so"], - "blank": [], "bmp": [".bmp"], "c": [".c"], "calc": [".ods", ".ots", ".xlr", ".xls", ".xlsx"], @@ -19,12 +18,12 @@ File types mapped to file extensions "cpp": [".cpp"], "css": [".css", ".less"], "deb": [".deb"], - "default": [], "diff": [".diff", ".patch"], "doc": [".doc", ".docx", ".odm", ".odt", ".ott"], "draw": [".drw"], "eps": [".eps"], "exe": [".bat", ".cmd", ".exe"], + "file": [], "folder": [], "folder-page": [], "folder-parent": [], diff --git a/src/_h5ai/server/php/inc/class-api.php b/src/_h5ai/server/php/inc/class-api.php index 0a55da6b..2313851f 100644 --- a/src/_h5ai/server/php/inc/class-api.php +++ b/src/_h5ai/server/php/inc/class-api.php @@ -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"); diff --git a/src/_h5ai/server/php/inc/class-app.php b/src/_h5ai/server/php/inc/class-app.php index 0b208153..a67dbef4 100644 --- a/src/_h5ai/server/php/inc/class-app.php +++ b/src/_h5ai/server/php/inc/class-app.php @@ -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 .= ""; - $html .= "folder-parent"; + $html .= "folder-parent"; $html .= "Parent Directory"; $html .= ""; $html .= ""; @@ -190,7 +223,7 @@ class App { $type = $item->is_folder ? "folder" : "file"; $html .= ""; - $html .= "" . $type . ""; + $html .= "" . $type . ""; $html .= "" . basename($item->path) . ""; $html .= "" . date("Y-m-d H:i", $item->date) . ""; $html .= "" . ($item->size !== null ? intval($item->size / 1000) . " KB" : "" ) . "";