mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 19:02:10 +00:00
router mis en place !
This commit is contained in:
parent
013e14b1ed
commit
084725f658
7
project/assets/html/404.html
Normal file
7
project/assets/html/404.html
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>404</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -1 +1 @@
|
|||||||
<div>Copiright IMIE, work hard to don't be bloké on the tépé</div>
|
<div class="pokemon">Copiright IMIE, work hard to don't be bloké on the tépé</div>
|
@ -1,7 +1,7 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html>
|
<html>
|
||||||
<head>
|
<head>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<tag type="includes" file="header" />
|
<tag type="includes" file="header" />
|
||||||
|
@ -0,0 +1,8 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>wow awesome post</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
8
project/assets/html/search.html
Normal file
8
project/assets/html/search.html
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
</head>
|
||||||
|
<body>
|
||||||
|
<p>searching...</p>
|
||||||
|
</body>
|
||||||
|
</html>
|
@ -27,20 +27,27 @@ if($_GET["page"] != "" && !endsWith($_GET["page"], "/")) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$_GET['page'] = trim($_GET['page'], '/');
|
$_GET['page'] = trim($_GET['page'], '/');
|
||||||
$_GET['page'] = explode('/', $_GET['page'])[0];
|
$_GET['page'] = "/" . explode('/', $_GET['page'])[0];
|
||||||
if($_GET['page'] == '') {
|
|
||||||
$_GET['page'] = 'index';
|
if(strlen($_GET['page']) > 1) {
|
||||||
|
$_GET['page'] = $_GET["page"] . "/";
|
||||||
}
|
}
|
||||||
|
|
||||||
// die;
|
// var_dump($_GET["page"]);
|
||||||
|
|
||||||
if($_GET["page"] == "test") {
|
if($_GET["page"] == "test") {
|
||||||
include_once "test.php";
|
include_once "test.php";
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
include_once "router.php";
|
||||||
|
$router = new Router();
|
||||||
|
include_once "pages.php";
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
include_once "tagHandler.php";
|
include_once "tagHandler.php";
|
||||||
$pokemon = loadTags("../html/".$_GET["page"].".html", false);
|
$pokemon = loadTags($router->search($_GET["page"])(), false);
|
||||||
// var_dump(mb_detect_encoding($pokemon));
|
// var_dump(mb_detect_encoding($pokemon));
|
||||||
|
|
||||||
$pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
|
$pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
|
||||||
|
@ -1,119 +1,66 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
/**
|
// abstract class Page {
|
||||||
* classe Pages
|
// private $id;
|
||||||
* a constructor to load additionnal pages and initialize the whole class and load the pages
|
// private $title;
|
||||||
*/
|
// private $regex;
|
||||||
|
// private $content;
|
||||||
|
// private $isLoaded = false;
|
||||||
|
|
||||||
/**
|
// abstract function loadPage();
|
||||||
* Class Pages
|
// }
|
||||||
*
|
|
||||||
* attributes
|
|
||||||
* pageList : Array
|
|
||||||
*
|
|
||||||
* functions
|
|
||||||
*
|
|
||||||
* __construct($pages = array())
|
|
||||||
* # load the pages list from db and static files (index/search)
|
|
||||||
* loadPage($url)
|
|
||||||
* # return a class of type Page (see below)
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
// interface Page {
|
||||||
* class Page
|
// public function __construct();
|
||||||
* contain the Page to load (on init only a light version but when using loadPage the whole page is in the class)
|
// public function loadPage();
|
||||||
* here it contains three extended classes (Index/Search/Post where we will add functions to the loadPage)
|
// public function getId();
|
||||||
*/
|
// public function getTitle();
|
||||||
|
// public function getRegex();
|
||||||
/**
|
// }
|
||||||
* abstract Class Page
|
|
||||||
*
|
|
||||||
* attributes
|
|
||||||
* id
|
|
||||||
* title
|
|
||||||
* regex
|
|
||||||
* content
|
|
||||||
* isLoaded: boolean
|
|
||||||
*
|
|
||||||
* functions:
|
|
||||||
* abstract __construct()
|
|
||||||
* absract loadPage()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Post
|
|
||||||
* contains a post
|
|
||||||
* with basics informations at first and when loadPost is launche the whole class will be usable
|
|
||||||
*/
|
|
||||||
|
|
||||||
/**
|
|
||||||
* class Post
|
|
||||||
*
|
|
||||||
* attributes
|
|
||||||
* id
|
|
||||||
* authorName
|
|
||||||
* authorLinkedin
|
|
||||||
* content
|
|
||||||
* isloaded: false
|
|
||||||
*
|
|
||||||
* __construct(id);
|
|
||||||
*
|
|
||||||
* loadPost()
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
|
|
||||||
abstract class Pages {
|
|
||||||
private $pageList = array();
|
|
||||||
|
|
||||||
public function __construct($pages = array()) {
|
|
||||||
$pouet = array();
|
|
||||||
$pages = array_merge($pouet, $pages);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
abstract class Page {
|
|
||||||
private $id;
|
|
||||||
private $title;
|
|
||||||
private $regex;
|
|
||||||
private $content;
|
|
||||||
private $isLoaded = false;
|
|
||||||
|
|
||||||
abstract function loadPage();
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Page {
|
|
||||||
public function __construct();
|
|
||||||
public function loadPage();
|
|
||||||
public function getId();
|
|
||||||
public function getTitle();
|
|
||||||
public function getRegex();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Post {
|
// class Post {
|
||||||
private $id;
|
// private $id;
|
||||||
private $authorName;
|
// private $authorName;
|
||||||
private $authorLinkedin;
|
// private $authorLinkedin;
|
||||||
private $content;
|
// private $content;
|
||||||
private $isLoaded = false;
|
// private $isLoaded = false;
|
||||||
|
|
||||||
public function __construct($id) {
|
// public function __construct($id) {
|
||||||
$this->id = $id;
|
// $this->id = $id;
|
||||||
}
|
// }
|
||||||
|
|
||||||
public function loadPost() {
|
// public function loadPost() {
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
|
||||||
class Posts implements Page {
|
// class Posts implements Page {
|
||||||
public function __construct() {}
|
// public function __construct() {}
|
||||||
|
|
||||||
}
|
// }
|
||||||
|
|
||||||
|
include_once "router.php";
|
||||||
|
|
||||||
|
$router = Router::getRouter();
|
||||||
|
|
||||||
|
$home = function() {
|
||||||
|
return file_get_contents("../html/index.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/$/", $home);
|
||||||
|
|
||||||
|
$post = function() {
|
||||||
|
return file_get_contents("../html/post.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/post\/$/", $post);
|
||||||
|
|
||||||
|
$search = function() {
|
||||||
|
return file_get_contents("../html/search.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/search\/$/", $search);
|
||||||
|
31
project/assets/php/router.php
Normal file
31
project/assets/php/router.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
class Router {
|
||||||
|
private static $router;
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
Router::$router = $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function getRouter() {
|
||||||
|
return Router::$router;
|
||||||
|
}
|
||||||
|
|
||||||
|
private $routeList = array();
|
||||||
|
|
||||||
|
public function addRoute($route, $page) {
|
||||||
|
$this->routeList[$route] = $page;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function dump() {
|
||||||
|
return $this->routeList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function search($path) {
|
||||||
|
foreach ($this->routeList as $reg => $page) {
|
||||||
|
if(preg_match($reg, $path)) {
|
||||||
|
return $page;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return function() {return file_get_contents("../html/404.html");};
|
||||||
|
}
|
||||||
|
}
|
@ -57,8 +57,10 @@ class Bold extends Tag {
|
|||||||
$pok->parentNode->insertBefore($res, $pok);
|
$pok->parentNode->insertBefore($res, $pok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//inputs <tag type="article" column="(voir les collones de la table post)
|
/**
|
||||||
//return #text
|
* inputs <tag type="article" column="(voir les collones de la table post)/>
|
||||||
|
*
|
||||||
|
*/
|
||||||
class Article extends Tag {
|
class Article extends Tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
@ -147,7 +149,9 @@ class Includes extends Tag {
|
|||||||
$el->setAttribute("style", $el->getAttribute("style"));
|
$el->setAttribute("style", $el->getAttribute("style"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* input <tag type="svg" style="color: white; width: 18px; height: 18px""/>
|
||||||
|
*/
|
||||||
class Svg extends Tag {
|
class Svg extends Tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
$el = $this->getDOM();
|
$el = $this->getDOM();
|
||||||
@ -160,7 +164,7 @@ class Svg extends Tag {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* input <tag type="loop" for="(table)" limit="(nombre-max généré)">
|
* input <tag type="loop" for="(table)" limit="(nombre-max généré)">
|
||||||
*/
|
*/
|
||||||
class Loop extends Tag {
|
class Loop extends Tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
@ -251,7 +255,7 @@ function appendHTML(DOMNode $parent, $source) {
|
|||||||
function loadTags($ctnt, $debug) {
|
function loadTags($ctnt, $debug) {
|
||||||
$dom = new DOMDocument();
|
$dom = new DOMDocument();
|
||||||
libxml_use_internal_errors(true);
|
libxml_use_internal_errors(true);
|
||||||
$dom->loadHTMLFile($ctnt);
|
$dom->loadHTML($ctnt);
|
||||||
libxml_clear_errors();
|
libxml_clear_errors();
|
||||||
|
|
||||||
$list = $dom->getElementsByTagName("tag");
|
$list = $dom->getElementsByTagName("tag");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user