Merge index and info routing.

This commit is contained in:
Lars Jung 2015-05-12 18:21:30 +02:00
parent ee241e7e3f
commit b1f88f28f4
9 changed files with 48 additions and 48 deletions

View file

@ -24,10 +24,13 @@ class Bootstrap {
$setup = new Setup($request->query_boolean('refresh', false));
$context = new Context($session, $request, $setup);
if (strtolower($setup->get('REQUEST_METHOD')) === 'post') {
if ($context->is_api_request()) {
(new Api($context))->apply();
} else if ($context->is_info_request()) {
define('PUBLIC_HREF', $setup->get('PUBLIC_HREF'));
require __DIR__ . '/info.php';
} else {
define('APP_HREF', $setup->get('APP_HREF'));
define('PUBLIC_HREF', $setup->get('PUBLIC_HREF'));
define('FALLBACK', (new Fallback($context))->get_html());
require __DIR__ . '/page.php';
}

View file

@ -65,6 +65,16 @@ class Context {
return $this->session->get(Context::$AS_ADMIN_SESSION_KEY);
}
public function is_api_request() {
return strtolower($this->setup->get('REQUEST_METHOD')) === 'post';
}
public function is_info_request() {
return $this->get_current_path() === $this->setup->get('APP_PATH') . '/public';
}
public function to_href($path, $trailing_slash = true) {
$rel_path = substr($path, strlen($this->setup->get('ROOT_PATH')));
@ -154,6 +164,18 @@ class Context {
return true;
}
public function get_current_path() {
$current_href = Util::normalize_path(parse_url($this->setup->get('REQUEST_URI'), PHP_URL_PATH), true);
$current_path = $this->to_path($current_href);
if (!is_dir($current_path)) {
$current_path = Util::normalize_path(dirname($current_path), false);
}
return $current_path;
}
public function get_items($href, $what) {
if (!$this->is_managed_href($href)) {

View file

@ -3,33 +3,18 @@
class Fallback {
private $context;
private $setup;
public function __construct($context) {
$this->context = $context;
$this->setup = $context->get_setup();
}
private function get_current_path() {
$current_href = Util::normalize_path(parse_url($this->setup->get('REQUEST_URI'), PHP_URL_PATH), true);
$current_path = $this->context->to_path($current_href);
if (!is_dir($current_path)) {
$current_path = Util::normalize_path(dirname($current_path), false);
}
return $current_path;
}
public function get_html($path = null) {
if (!$path) {
$path = $this->get_current_path();
$path = $this->context->get_current_path();
}
$fallback_images_href = $this->setup->get('APP_HREF') . 'public/images/fallback/';
$fallback_images_href = $this->context->get_setup()->get('APP_HREF') . 'public/images/fallback/';
$cache = [];
$folder = Item::get($this->context, $path, $cache);

View file

@ -18,7 +18,6 @@ class Setup {
$this->add_admin_check();
$this->add_server_metadata_and_check();
$this->add_paths();
$this->add_cache_paths_and_check();
$this->add_sys_cmd_checks();
}
@ -118,14 +117,8 @@ class Setup {
$this->set('ROOT_HREF', Util::normalize_path(dirname($this->get('APP_HREF')), true));
$this->set('ROOT_PATH', Util::normalize_path(dirname($this->get('APP_PATH')), false));
$index_href = null;
if (@is_readable(Util::normalize_path($this->get('APP_PATH') . '/public/index.php', false))) {
$index_href = Util::normalize_path($this->get('APP_HREF') . '/public/index.php', false);
}
$this->set('INDEX_HREF', $index_href);
}
private function add_cache_paths_and_check() {
$this->set('PUBLIC_HREF', $this->get('APP_HREF') . 'public/');
$this->set('INDEX_HREF', $this->get('APP_HREF') . 'public/index.php');
$this->set('CACHE_HREF', Util::normalize_path($this->get('APP_HREF') . '/public/cache', true));
$this->set('CACHE_PATH', Util::normalize_path($this->get('APP_PATH') . '/public/cache', false));

View file

@ -1,3 +1,6 @@
- var PUBLIC_HREF = '<?= PUBLIC_HREF; ?>'
<?php header('Content-type: text/html;charset=utf-8'); ?>
doctype html
<!--[if lt IE 10]><html class="no-js no-browser" lang="en"><![endif]-->
<!--[if gt IE 9]><!--><html class="no-js browser" lang="en"><!--<![endif]-->
@ -5,14 +8,14 @@ doctype html
head
meta( charset="utf-8" )
meta( http-equiv="x-ua-compatible", content="ie=edge" )
title #{pkg.name} #{pkg.version} Server Setup
meta( name="description", content="#{pkg.name} #{pkg.version} Server Setup" )
title #{pkg.name} #{pkg.version} info page
meta( name="description", content="#{pkg.name} #{pkg.version} info page" )
meta( name="viewport", content="width=device-width, initial-scale=1" )
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="shortcut icon", href!="#{PUBLIC_HREF}images/favicon/favicon-16-32.ico" )
link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{PUBLIC_HREF}images/favicon/favicon-152.png" )
link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Roboto:300,400,700" )
link( rel="stylesheet", href="css/styles.css" )
script( src="js/scripts.js", data-module="info" )
link( rel="stylesheet", href!="#{PUBLIC_HREF}css/styles.css" )
script( src!="#{PUBLIC_HREF}js/scripts.js", data-module="info" )
body#root.info

View file

@ -1,4 +1,4 @@
- var APP_HREF = '<?= APP_HREF; ?>'
- var PUBLIC_HREF = '<?= PUBLIC_HREF; ?>'
- var FALLBACK = '<?= FALLBACK; ?>'
<?php header('Content-type: text/html;charset=utf-8'); ?>
@ -12,11 +12,11 @@ head
title index · powered by #{pkg.name} #{pkg.version} (#{pkg.homepage})
meta( name="description", content="index - powered by #{pkg.name} #{pkg.version} (#{pkg.homepage})" )
meta( name="viewport", content="width=device-width, initial-scale=1" )
link( rel="shortcut icon", href!="#{APP_HREF}public/images/favicon/favicon-16-32.ico" )
link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{APP_HREF}public/images/favicon/favicon-152.png" )
link( rel="shortcut icon", href!="#{PUBLIC_HREF}images/favicon/favicon-16-32.ico" )
link( rel="apple-touch-icon-precomposed", type="image/png", href!="#{PUBLIC_HREF}images/favicon/favicon-152.png" )
link( rel="stylesheet", href="//fonts.googleapis.com/css?family=Roboto:300,400,700" )
link( rel="stylesheet", href!="#{APP_HREF}public/css/styles.css" )
script( src!="#{APP_HREF}public/js/scripts.js", data-module="index" )
link( rel="stylesheet", href!="#{PUBLIC_HREF}css/styles.css" )
script( src!="#{PUBLIC_HREF}js/scripts.js", data-module="index" )
body#root

View file

@ -2,7 +2,7 @@ Satisfy all
Order allow,deny
Allow from all
DirectoryIndex info.html
DirectoryIndex index.php
<IfModule mod_autoindex.c>
Options -Indexes

View file

@ -3,8 +3,8 @@
define('MIN_PHP_VERSION', '5.4.0');
if (version_compare(PHP_VERSION, MIN_PHP_VERSION, '<')) {
header('Content-type: application/json;charset=utf-8');
echo '{"err":"ERR_PHP","msg":"PHP ' . MIN_PHP_VERSION . '+ required","ver":"' . PHP_VERSION . '"}';
header('Content-type: text/plain;charset=utf-8');
echo '[{{pkg.name}} {{pkg.version}}] PHP ' . MIN_PHP_VERSION . '+ required, only found PHP ' . PHP_VERSION;
exit;
}

View file

@ -162,12 +162,6 @@ modulejs.define('main/info', ['$', 'config'], function ($, config) {
function init() {
if (config.err === 'ERR_PHP') {
$(testsTemp).appendTo('#content');
addTest('PHP version', config.msg, false, config.ver);
return;
}
addLogin();
if (setup.AS_ADMIN) {
addTests();