diff --git a/project/assets/html/404.html b/project/assets/html/404.html new file mode 100644 index 0000000..45c6692 --- /dev/null +++ b/project/assets/html/404.html @@ -0,0 +1,7 @@ + + + + +

404

+ + \ No newline at end of file diff --git a/project/assets/html/includes/footer.html b/project/assets/html/includes/footer.html index 1ffae81..4145499 100644 --- a/project/assets/html/includes/footer.html +++ b/project/assets/html/includes/footer.html @@ -1 +1 @@ -
Copiright IMIE, work hard to don't be bloké on the tépé
\ No newline at end of file +
Copiright IMIE, work hard to don't be bloké on the tépé
\ No newline at end of file diff --git a/project/assets/html/index.html b/project/assets/html/index.html index 2f71c8a..c98a0b2 100644 --- a/project/assets/html/index.html +++ b/project/assets/html/index.html @@ -1,7 +1,7 @@ - - + +
diff --git a/project/assets/html/post.html b/project/assets/html/post.html index e69de29..702c990 100644 --- a/project/assets/html/post.html +++ b/project/assets/html/post.html @@ -0,0 +1,8 @@ + + + + + +

wow awesome post

+ + \ No newline at end of file diff --git a/project/assets/html/search.html b/project/assets/html/search.html new file mode 100644 index 0000000..1f1e5bd --- /dev/null +++ b/project/assets/html/search.html @@ -0,0 +1,8 @@ + + + + + +

searching...

+ + \ No newline at end of file diff --git a/project/assets/php/handler.php b/project/assets/php/handler.php index 7732ef4..084c43a 100755 --- a/project/assets/php/handler.php +++ b/project/assets/php/handler.php @@ -27,20 +27,27 @@ if($_GET["page"] != "" && !endsWith($_GET["page"], "/")) { } $_GET['page'] = trim($_GET['page'], '/'); -$_GET['page'] = explode('/', $_GET['page'])[0]; -if($_GET['page'] == '') { - $_GET['page'] = 'index'; +$_GET['page'] = "/" . explode('/', $_GET['page'])[0]; + +if(strlen($_GET['page']) > 1) { + $_GET['page'] = $_GET["page"] . "/"; } -// die; +// var_dump($_GET["page"]); if($_GET["page"] == "test") { include_once "test.php"; die; } +include_once "router.php"; +$router = new Router(); +include_once "pages.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)); $pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5); diff --git a/project/assets/php/pages.php b/project/assets/php/pages.php index 65f7ea8..3b869cf 100644 --- a/project/assets/php/pages.php +++ b/project/assets/php/pages.php @@ -1,119 +1,66 @@ id = $id; - } +// public function __construct($id) { +// $this->id = $id; +// } - public function loadPost() { +// public function loadPost() { - } +// } -} +// } -class Posts implements Page { - public function __construct() {} +// class Posts implements Page { +// 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); diff --git a/project/assets/php/router.php b/project/assets/php/router.php new file mode 100644 index 0000000..7d53759 --- /dev/null +++ b/project/assets/php/router.php @@ -0,0 +1,31 @@ +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");}; + } +} diff --git a/project/assets/php/tagHandler.php b/project/assets/php/tagHandler.php index d18a664..2801831 100644 --- a/project/assets/php/tagHandler.php +++ b/project/assets/php/tagHandler.php @@ -57,8 +57,10 @@ class Bold extends Tag { $pok->parentNode->insertBefore($res, $pok); } } -//inputs getAttribute("style")); } } - +/** + * input + */ class Svg extends Tag { public function render() { $el = $this->getDOM(); @@ -160,7 +164,7 @@ class Svg extends Tag { } /** - * input + * input */ class Loop extends Tag { public function render() { @@ -251,7 +255,7 @@ function appendHTML(DOMNode $parent, $source) { function loadTags($ctnt, $debug) { $dom = new DOMDocument(); libxml_use_internal_errors(true); - $dom->loadHTMLFile($ctnt); + $dom->loadHTML($ctnt); libxml_clear_errors(); $list = $dom->getElementsByTagName("tag");