From 084725f658123367dcd395a0b47c32439a0e60d1 Mon Sep 17 00:00:00 2001
From: Aviortheking <2bazert@gmail.com>
Date: Mon, 14 Jan 2019 15:09:56 +0100
Subject: [PATCH 1/2] router mis en place !
---
project/assets/html/404.html | 7 ++
project/assets/html/includes/footer.html | 2 +-
project/assets/html/index.html | 4 +-
project/assets/html/post.html | 8 ++
project/assets/html/search.html | 8 ++
project/assets/php/handler.php | 17 ++-
project/assets/php/pages.php | 153 ++++++++---------------
project/assets/php/router.php | 31 +++++
project/assets/php/tagHandler.php | 14 ++-
9 files changed, 128 insertions(+), 116 deletions(-)
create mode 100644 project/assets/html/404.html
create mode 100644 project/assets/html/search.html
create mode 100644 project/assets/php/router.php
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");
From 94fa0c2870d84edb07906d2b3fbfb104a215a9de Mon Sep 17 00:00:00 2001
From: Aviortheking <2bazert@gmail.com>
Date: Mon, 14 Jan 2019 16:50:21 +0100
Subject: [PATCH 2/2] =?UTF-8?q?=C3=A7a'?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
project/assets/html/post.html | 10 ++-
project/assets/php/functions.php | 12 +++-
project/assets/php/handler.php | 107 +++++++-----------------------
project/assets/php/pages.php | 60 +++--------------
project/assets/php/router.php | 24 +++++--
project/assets/php/tagHandler.php | 67 ++++++++++---------
project/assets/php/tags.txt | 2 -
7 files changed, 108 insertions(+), 174 deletions(-)
delete mode 100644 project/assets/php/tags.txt
diff --git a/project/assets/html/post.html b/project/assets/html/post.html
index 702c990..34bfe9e 100644
--- a/project/assets/html/post.html
+++ b/project/assets/html/post.html
@@ -3,6 +3,14 @@
- wow awesome post
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/project/assets/php/functions.php b/project/assets/php/functions.php
index 618b970..201bebb 100644
--- a/project/assets/php/functions.php
+++ b/project/assets/php/functions.php
@@ -1 +1,11 @@
-/* Fichier de fontions que nous utiliserons a travers les différents fichiers */
\ No newline at end of file
+ 1) {
+ $_GET["post"] = explode("/", $_GET["page"])[1];
+}
+
+// $_get[page] = $_get[page][0]
$_GET['page'] = "/" . explode('/', $_GET['page'])[0];
+// si len $_get[page] > 1 (mot ou autre) on rajoute le slash de fin
if(strlen($_GET['page']) > 1) {
$_GET['page'] = $_GET["page"] . "/";
}
// var_dump($_GET["page"]);
+//page de test pour des functions
+// A ENLEVER LORS DES COMMITS DE FIN
if($_GET["page"] == "test") {
include_once "test.php";
die;
}
+/**
+ * Démarrage du routage du contenu
+ */
+
include_once "router.php";
$router = new Router();
include_once "pages.php";
-
+//chargement des tags contenu sur la page
include_once "tagHandler.php";
$pokemon = loadTags($router->search($_GET["page"])(), false);
-// var_dump(mb_detect_encoding($pokemon));
+//TODO trouver pourquoi il y a un pb avec l'UTF-8
+//(actuellement forcer des compiler en "Windows 1252")
$pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
echo $pokemon;
-// var_dump(mb_detect_encoding($pokemon));
-function endsWith($haystack, $needle)
-{
- $length = strlen($needle);
- if ($length == 0) {
- return true;
- }
-
- return (substr($haystack, -$length) === $needle);
-}
-
-/**
- * classe Pages
- * a constructor to load additionnal pages and initialize the whole class and load the pages
- */
-
-/**
- * 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)
- */
-
-/**
- * class Page
- * contain the Page to load (on init only a light version but when using loadPage the whole page is in the class)
- * here it contains three extended classes (Index/Search/Post where we will add functions to the loadPage)
- */
-
-/**
- * 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()
- *
- */
diff --git a/project/assets/php/pages.php b/project/assets/php/pages.php
index 3b869cf..9fda8d8 100644
--- a/project/assets/php/pages.php
+++ b/project/assets/php/pages.php
@@ -1,66 +1,26 @@
id = $id;
-// }
-
-// public function loadPost() {
-
-// }
-
-// }
-
-
-// class Posts implements Page {
-// public function __construct() {}
-
-// }
-
include_once "router.php";
+//recupération du router
$router = Router::getRouter();
-$home = function() {
+//page d'accueil
+$home = function () {
return file_get_contents("../html/index.html");
};
-$router->addRoute("/^\/$/", $home);
+$router->addRoute("/^\/$/", $home); // route : "/"
-$post = function() {
+//page de post
+$post = function () {
return file_get_contents("../html/post.html");
};
-$router->addRoute("/^\/post\/$/", $post);
+$router->addRoute("/^\/post\/$/", $post); // route "/post/*"
-$search = function() {
+//page de recherche
+$search = function () {
return file_get_contents("../html/search.html");
};
-$router->addRoute("/^\/search\/$/", $search);
+$router->addRoute("/^\/search\/$/", $search); // route "/search/*"
diff --git a/project/assets/php/router.php b/project/assets/php/router.php
index 7d53759..d8f941c 100644
--- a/project/assets/php/router.php
+++ b/project/assets/php/router.php
@@ -1,31 +1,45 @@
routeList[$route] = $page;
}
- public function dump() {
- return $this->routeList;
- }
-
+ //fonction de recherche d'une route par rapport a un texte
+ //return function
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");};
+ return function () {
+ return file_get_contents("../html/404.html");
+ };
}
}
diff --git a/project/assets/php/tagHandler.php b/project/assets/php/tagHandler.php
index 2801831..71abda4 100644
--- a/project/assets/php/tagHandler.php
+++ b/project/assets/php/tagHandler.php
@@ -1,11 +1,4 @@
- */
-
-
-$debug = false;
-
class Tag {
@@ -34,44 +27,41 @@ class Tag {
public function render() {}
}
//ce tag est juste la pour donner les possibilité de mon composant
-//input test
-
-//result test
+/**
+ * input test
+ * result test
+ */
class Bold extends Tag {
public function render() {
//recuperation de la balise de base (pouet)
$pok = $this->getDOM();
- //recuperation du document (necessaire a la création de balises
+ //recuperation du document (necessaire a la création de balises
$doc = $this->getDoc();
- //creation de la balise "div"
+ //creation de la balise "span"
$res = $doc->createElement("span");
//creation du texte et assignation du texte se trouvant dans la balise de base
$text = $doc->createTextNode($pok->textContent);
- //on rajoute a notre balise div notre texte
+ //rajout dans la balise span notre texte
$res->appendChild($text);
- //on rajoute a la balise div du style pour le mettre en gras
+ //on rajoute a la balise span du style pour le mettre en gras
$res->setAttribute("style", "font-weight: bold");
- //on retourne la div
-
//enfin on met la div final dans le fichier
$pok->parentNode->insertBefore($res, $pok);
}
}
/**
* inputs "pokemon",
+ 'url'=> "pokemongo",
'content'=> "azerthjjhhdsqmlkjhgfd
"
);
-
-
$pok = $this->getDOM();
$attr = $pok->getAttribute("column");
@@ -91,7 +81,15 @@ class Article extends Tag {
}
/**
- * return element is user
+ * input
+ *
+ *
+ *
+ *
+ *
+ *
+ *
+ *
*/
class IsLoggedIn extends Tag {
public function render() {
@@ -113,6 +111,10 @@ class IsLoggedIn extends Tag {
}
}
+/**
+ * input
+ * return text
+ */
class Author extends Tag {
public function render() {
@@ -135,6 +137,10 @@ class Author extends Tag {
}
}
+/**
+ * input
+ * return the content of the file
+ */
class Includes extends Tag {
public function render() {
$el = $this->getDOM();
@@ -149,6 +155,7 @@ class Includes extends Tag {
$el->setAttribute("style", $el->getAttribute("style"));
}
}
+
/**
* input
*/
@@ -164,7 +171,8 @@ class Svg extends Tag {
}
/**
- * input
+ * input
+ * return something
*/
class Loop extends Tag {
public function render() {
@@ -237,6 +245,7 @@ class Loop extends Tag {
}
}
+//function qui ajoute du html dans la node
function appendHTML(DOMNode $parent, $source) {
$tmpDoc = new DOMDocument();
$html = "";
@@ -249,10 +258,8 @@ function appendHTML(DOMNode $parent, $source) {
}
}
-//testing purpose
-//$content = file_get_contents("./test.html");
-
-function loadTags($ctnt, $debug) {
+// function de gestion
+function loadTags($ctnt) {
$dom = new DOMDocument();
libxml_use_internal_errors(true);
$dom->loadHTML($ctnt);
@@ -266,17 +273,15 @@ function loadTags($ctnt, $debug) {
$t->appendXML($p);
$head->item(0)->appendChild($t);
- //remove all tag components
+ //charge et supprimme les tags
while($list->length >= 1) {
-
$lst = $list->item(0);
$tgs = ucfirst($lst->getAttribute("type"));
- // var_dump($tgs);
- $tg = new $tgs($dom, $lst, $debug);
+ $tg = new $tgs($dom, $lst, false);
$tg->render();
- $list[0]->parentNode->removeChild($list[0]);
+ $list[0]->parentNode->removeChild($list[0]);
$list = $dom->getElementsByTagName("tag");
}
diff --git a/project/assets/php/tags.txt b/project/assets/php/tags.txt
deleted file mode 100644
index a8b3a5c..0000000
--- a/project/assets/php/tags.txt
+++ /dev/null
@@ -1,2 +0,0 @@
-bold text
-ne pas utiliser c'est juste pour montrer les possibilité
\ No newline at end of file