From aa87ec15b074880d6bcf2fd57e50dbab2f6d3d74 Mon Sep 17 00:00:00 2001 From: Lars Jung Date: Sun, 29 May 2016 17:35:15 +0200 Subject: [PATCH] Add fallback mode. --- CHANGELOG.md | 2 ++ src/_h5ai/private/conf/options.json | 2 ++ src/_h5ai/private/php/class-bootstrap.php | 1 + src/_h5ai/private/php/core/class-context.php | 8 ++++++++ src/_h5ai/private/php/core/class-setup.php | 1 + src/_h5ai/private/php/pages/page.tpl.jade | 4 ++++ 6 files changed, 18 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 642b6395..dd06e2f9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,7 @@ # Changelog +* adds `view.fallbackMode` option to generally serve only fallback mode +* serves fallback mode for text browsers (`curl`, `links`, `lynx`, `w3m`) * change type `txt-svg` to `img-svg`, no thumbs but preview * fixes a tree indentaion glitch * fixes shell command detection on Windows diff --git a/src/_h5ai/private/conf/options.json b/src/_h5ai/private/conf/options.json index 1ef43d17..9f1c9dcd 100644 --- a/src/_h5ai/private/conf/options.json +++ b/src/_h5ai/private/conf/options.json @@ -32,6 +32,7 @@ General view options. - binaryPrefix: boolean, set to true uses 1024B=1KiB when formatting file sizes (see http://en.wikipedia.org/wiki/Binary_prefix) + - fallbackMode: boolean, serve fallback mode - fastBrowsing: boolean, use History API if available (no need to reload the whole page) - fonts: array of strings, fonts to use in regular context - fontsMono: array of strings, fonts to use in monopspaced context @@ -58,6 +59,7 @@ */ "view": { "binaryPrefix": false, + "fallbackMode": false, "fastBrowsing": true, "fonts": ["Ubuntu", "Roboto", "Helvetica", "Arial", "sans-serif"], "fontsMono": ["Ubuntu Mono", "Monaco", "Lucida Sans Typewriter", "monospace"], diff --git a/src/_h5ai/private/php/class-bootstrap.php b/src/_h5ai/private/php/class-bootstrap.php index 67df539e..3afd7ba4 100644 --- a/src/_h5ai/private/php/class-bootstrap.php +++ b/src/_h5ai/private/php/class-bootstrap.php @@ -24,6 +24,7 @@ class Bootstrap { } else { $public_href = $setup->get('PUBLIC_HREF'); $x_head_tags = $context->get_x_head_html(); + $fallback_mode = $context->is_fallback_mode(); $fallback_html = (new Fallback($context))->get_html(); require __DIR__ . '/pages/index.php'; } diff --git a/src/_h5ai/private/php/core/class-context.php b/src/_h5ai/private/php/core/class-context.php index 18fe487a..5484f8f9 100644 --- a/src/_h5ai/private/php/core/class-context.php +++ b/src/_h5ai/private/php/core/class-context.php @@ -68,6 +68,14 @@ class Context { return Util::starts_with($this->setup->get('REQUEST_HREF') . '/', $this->setup->get('PUBLIC_HREF')); } + public function is_text_browser() { + return preg_match('/curl|links|lynx|w3m/i', $this->setup->get('HTTP_USER_AGENT')) === 1; + } + + public function is_fallback_mode() { + return $this->query_option('view.fallbackMode', false) || $this->is_text_browser(); + } + public function to_href($path, $trailing_slash = true) { $rel_path = substr($path, strlen($this->setup->get('ROOT_PATH'))); $parts = explode('/', $rel_path); diff --git a/src/_h5ai/private/php/core/class-setup.php b/src/_h5ai/private/php/core/class-setup.php index b9219c70..8b836db8 100644 --- a/src/_h5ai/private/php/core/class-setup.php +++ b/src/_h5ai/private/php/core/class-setup.php @@ -53,6 +53,7 @@ class Setup { $this->set('REQUEST_HREF', parse_url(getenv('REQUEST_URI'), PHP_URL_PATH)); $this->set('SCRIPT_NAME', getenv('SCRIPT_NAME')); $this->set('SERVER_SOFTWARE', getenv('SERVER_SOFTWARE')); + $this->set('HTTP_USER_AGENT', getenv('HTTP_USER_AGENT')); } private function add_php_checks() { diff --git a/src/_h5ai/private/php/pages/page.tpl.jade b/src/_h5ai/private/php/pages/page.tpl.jade index 6d61259d..c7a4333a 100644 --- a/src/_h5ai/private/php/pages/page.tpl.jade +++ b/src/_h5ai/private/php/pages/page.tpl.jade @@ -14,14 +14,18 @@ html(class='no-js', lang='en') link(rel='shortcut icon', href!='images/favicon/favicon-16-32.ico') link(rel='apple-touch-icon-precomposed', type='image/png', href!='images/favicon/favicon-152.png') link(rel='stylesheet', href!='css/styles.css') + script(src!='js/scripts.js', data-module='#{module}') + body#root(class='#{module}') div#fallback-hints + span.noJsMsg Works best with JavaScript enabled! span.noBrowserMsg Works best in #[a(href='http://browsehappy.com') modern browsers]! + span.backlink #[a(href='#{pkg.homepage}', title='h5ai v#{pkg.version} - #{pkg.description}') powered by h5ai] block body