+upd routes for js +add router.js (auto-bundle + _SERVER) +upd new page directory (file struct.) +minmod

This commit is contained in:
xdrm-brackets 2018-02-20 00:52:07 +01:00
parent 2aa73856d3
commit 13bf46c9b1
6 changed files with 133 additions and 13 deletions

View File

@ -0,0 +1,78 @@
<?php
namespace router\controller;
class js{
private $page;
/* PRE-CALL
*
* @url<String> Calling URI
*
*/
public function __construct($url){
$this->page = isset($url['page']) ? $url['page'] : '';
$this->page = preg_match('/^@[a-z]+$/', $this->page) ? substr($this->page, 1) : null;
}
/* Generate _SERVER.js
*
*/
public function server(){
header('Content-Type: text/javascript; charset=utf-8');
echo "window._SERVER = ".json_encode([
'session' => [
'name' => $_SESSION['NAME'],
'connected' => isset($_SESSION['USER']) ? count($_SESSION['USER']) > 0 : false
]
])."\n";
}
/* Manage bundle hash
*
*/
public function bundle(){
if( is_null($this->page) ){
http_response_code(404);
die();
}
/* (1) Extract /public_html/js/ all .js files */
$js_scripts = glob(__PUBLIC__.'/js/bundle/'.$this->page.'@*.js');
/* (2) If match pattern 'bundle@home@*.js' */
foreach($js_scripts as $fname){
$bname = basename($fname);
// if match -> load it and exit
header("Location: /js/bundle/$bname");
die();
}
/* (3) If nothing found */
http_response_code(404);
die();
}
/* POST-CALL
*
*/
public function __destruct(){
}
}

View File

@ -15,7 +15,6 @@
*/
public function __construct($url){
$this->pagename = $url['page'];
}
@ -23,8 +22,8 @@
*
*/
public function load(){
if( file_exists(__PUBLIC__."/view/".$this->pagename.".php") )
include __PUBLIC__."/view/".$this->pagename.".php";
if( file_exists(__PUBLIC__."/page/".$this->pagename.".php") )
include __PUBLIC__."/page/".$this->pagename.".php";
else
echo "page not found";
}

View File

@ -18,8 +18,8 @@
/* CALL
*
*/
public function homepage(){
header('Location: /homepage/');
public function home(){
header('Location: /home/');
}
/* POST-CALL

View File

@ -5,6 +5,21 @@
"routes": {
"/js/_SERVER.js": {
"methods": ["GET"],
"controller": "js:server",
"arguments": {}
},
"/js/bundle{page}.js": {
"methods": ["GET"],
"controller": "js:bundle",
"arguments": {
"page":"@[a-z]+"
}
},
"/{page}/": {
"methods": ["GET"],
"controller": "page:load",
@ -23,7 +38,7 @@
"/{any}": {
"methods": ["GET"],
"controller": "redirect:homepage",
"controller": "redirect:home",
"arguments": {
"any": ".*"
}

35
public_html/page/home.php Normal file
View File

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=0.4">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>PTUT web title</title>
<!-- Icon -->
<link rel='shortcut icon' href='/favicon.ico'>
<!-- CSS dependencies -->
<link rel='stylesheet' type='text/css' href='/css/font-loader.css'>
<link rel='stylesheet' type='text/css' href='/css/layout.css'>
<link rel='stylesheet' type='text/css' href='/css/menu.css'>
<link rel='stylesheet' type='text/css' href='/css/header.css'>
<link rel='stylesheet' type='text/css' href='/css/container.css'>
<!-- JS dependencies -->
<script type='text/javascript' src='/js/_SERVER.js'></script>
</head>
<body>
<div id='main-vue'></div>
<!-- Main loop -->
<script type='text/javascript' src='/js/bundle@home.js'></script>
</body>
</html>

View File

@ -1,7 +0,0 @@
<?php use \database\core\DatabaseDriver;
echo "<pre>";
echo "home page\n";
print_r( DatabaseDriver::getPDO()->query("show databases;")->fetchAll() );
echo "</pre>";