This commit is contained in:
Florian Bouillon 2019-01-14 16:50:21 +01:00
parent 22fc7cfe22
commit 94fa0c2870
7 changed files with 108 additions and 174 deletions

View File

@ -3,6 +3,14 @@
<head> <head>
</head> </head>
<body> <body>
<p>wow awesome post</p> <div>
<tag type="article" column="title"/>
</div>
<div>
<tag type="article" column="url"/>
</div>
<div>
<tag type="article" column="content"/>
</div>
</body> </body>
</html> </html>

View File

@ -1 +1,11 @@
/* Fichier de fontions que nous utiliserons a travers les différents fichiers */ <?php
//function pour voir la fin d'un texte
function endsWith($haystack, $needle) {
$length = strlen($needle);
if ($length == 0) {
return true;
}
return (substr($haystack, -$length) === $needle);
}

View File

@ -2,126 +2,65 @@
ini_set('display_errors', 'On'); ini_set('display_errors', 'On');
//renvoie vers le fichier css si il est demandé //renvoie vers le fichier css si il est demandé
if(endsWith($_GET["page"], ".css")) { if(endsWith($_GET["page"], ".css")) {
echo file_get_contents("../css/style.css"); echo file_get_contents("../css/style.css");
die; die;
} }
//renvoie vers le fichier js si demandé
//si on cherche un fichier js
if(endsWith($_GET["page"], ".js")) { if(endsWith($_GET["page"], ".js")) {
echo file_get_contents("../js/script.js"); echo file_get_contents("../js/script.js");
die; die;
} }
//va cherche l'image uploader // var_dump(sizeof($_GET));
if(false) {
}
// si page non / & finit pas par / at pas de ?
//rajout d'un / a la fin (parceque c'est jolie) if($_GET["page"] != "" && !endsWith($_GET["page"], "/") && sizeof($_GET) <= 1) {
if($_GET["page"] != "" && !endsWith($_GET["page"], "/")) {
header("Location: /".$_GET["page"]."/"); header("Location: /".$_GET["page"]."/");
die; die;
} }
//enleve les / du début & fin
$_GET['page'] = trim($_GET['page'], '/'); $_GET['page'] = trim($_GET['page'], '/');
// si taille supérieur à 1 $_getpost = element
if(sizeof(explode("/", $_GET["page"])) > 1) {
$_GET["post"] = explode("/", $_GET["page"])[1];
}
// $_get[page] = $_get[page][0]
$_GET['page'] = "/" . explode('/', $_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) { if(strlen($_GET['page']) > 1) {
$_GET['page'] = $_GET["page"] . "/"; $_GET['page'] = $_GET["page"] . "/";
} }
// var_dump($_GET["page"]); // var_dump($_GET["page"]);
//page de test pour des functions
// A ENLEVER LORS DES COMMITS DE FIN
if($_GET["page"] == "test") { if($_GET["page"] == "test") {
include_once "test.php"; include_once "test.php";
die; die;
} }
/**
* Démarrage du routage du contenu
*/
include_once "router.php"; include_once "router.php";
$router = new Router(); $router = new Router();
include_once "pages.php"; include_once "pages.php";
//chargement des tags contenu sur la page
include_once "tagHandler.php"; include_once "tagHandler.php";
$pokemon = loadTags($router->search($_GET["page"])(), false); $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); $pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
echo $pokemon; 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()
*
*/

View File

@ -1,66 +1,26 @@
<?php <?php
// 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 {
// private $id;
// private $authorName;
// private $authorLinkedin;
// private $content;
// private $isLoaded = false;
// public function __construct($id) {
// $this->id = $id;
// }
// public function loadPost() {
// }
// }
// class Posts implements Page {
// public function __construct() {}
// }
include_once "router.php"; include_once "router.php";
//recupération du router
$router = Router::getRouter(); $router = Router::getRouter();
$home = function() { //page d'accueil
$home = function () {
return file_get_contents("../html/index.html"); 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"); 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"); return file_get_contents("../html/search.html");
}; };
$router->addRoute("/^\/search\/$/", $search); $router->addRoute("/^\/search\/$/", $search); // route "/search/*"

View File

@ -1,31 +1,45 @@
<?php <?php
/**
* classe pour gerer le routage des pages
* la variable static $router sert a utiliser le router dans plusieurs fichier
* sans forcement avoir une obligation de nom de variable
* de plus ils sert a garder une route unique
*/
class Router { class Router {
//variable static pour stocker le router
private static $router; private static $router;
//definit le router
public function __construct() { public function __construct() {
//TODO faire que si un router existe dajà retourner le routeur existant
Router::$router = $this; Router::$router = $this;
} }
//fonction static pour recuperer un router déjà créé
public static function getRouter() { public static function getRouter() {
return Router::$router; return Router::$router;
} }
//liste des routes
private $routeList = array(); private $routeList = array();
//ajout d'une route
public function addRoute($route, $page) { public function addRoute($route, $page) {
$this->routeList[$route] = $page; $this->routeList[$route] = $page;
} }
public function dump() { //fonction de recherche d'une route par rapport a un texte
return $this->routeList; //return function
}
public function search($path) { public function search($path) {
foreach ($this->routeList as $reg => $page) { foreach ($this->routeList as $reg => $page) {
if(preg_match($reg, $path)) { if(preg_match($reg, $path)) {
return $page; return $page;
} }
} }
return function() {return file_get_contents("../html/404.html");}; return function () {
return file_get_contents("../html/404.html");
};
} }
} }

View File

@ -1,11 +1,4 @@
<?php <?php
/**
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
*/
$debug = false;
class Tag { class Tag {
@ -34,44 +27,41 @@ class Tag {
public function render() {} public function render() {}
} }
//ce tag est juste la pour donner les possibilité de mon composant //ce tag est juste la pour donner les possibilité de mon composant
//input <tag type="bold">test</tag> /**
* input <tag type="bold">test</tag>
//result <span style="font-weight: bold">test</span> * result <span style="font-weight: bold">test</span>
*/
class Bold extends Tag { class Bold extends Tag {
public function render() { public function render() {
//recuperation de la balise de base (<tag type="bold">pouet</tag>) //recuperation de la balise de base (<tag type="bold">pouet</tag>)
$pok = $this->getDOM(); $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(); $doc = $this->getDoc();
//creation de la balise "div" //creation de la balise "span"
$res = $doc->createElement("span"); $res = $doc->createElement("span");
//creation du texte et assignation du texte se trouvant dans la balise de base //creation du texte et assignation du texte se trouvant dans la balise de base
$text = $doc->createTextNode($pok->textContent); $text = $doc->createTextNode($pok->textContent);
//on rajoute a notre balise div notre texte //rajout dans la balise span notre texte
$res->appendChild($text); $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"); $res->setAttribute("style", "font-weight: bold");
//on retourne la div
//enfin on met la div final dans le fichier //enfin on met la div final dans le fichier
$pok->parentNode->insertBefore($res, $pok); $pok->parentNode->insertBefore($res, $pok);
} }
} }
/** /**
* inputs <tag type="article" column="(voir les collones de la table post)/> * inputs <tag type="article" column="(voir les collones de la table post)/>
* * return text
*/ */
class Article extends Tag { class Article extends Tag {
public function render() { public function render() {
$post = array( //testing purpose $post = array( //testing purpose
'title'=> "test", 'title'=> "test",
'url'=> "pokemon", 'url'=> "pokemongo",
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>" 'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
); );
$pok = $this->getDOM(); $pok = $this->getDOM();
$attr = $pok->getAttribute("column"); $attr = $pok->getAttribute("column");
@ -91,7 +81,15 @@ class Article extends Tag {
} }
/** /**
* return element is user * input
* <tag type="isloggedin">
* <if true>
*
* </if>
* <if false>
*
* </if>
* </tag>
*/ */
class IsLoggedIn extends Tag { class IsLoggedIn extends Tag {
public function render() { public function render() {
@ -113,6 +111,10 @@ class IsLoggedIn extends Tag {
} }
} }
/**
* input <tag type="author" column="(column name)"/>
* return text
*/
class Author extends Tag { class Author extends Tag {
public function render() { public function render() {
@ -135,6 +137,10 @@ class Author extends Tag {
} }
} }
/**
* input <tag type="includes" file="(html file in includes folder)"/>
* return the content of the file
*/
class Includes extends Tag { class Includes extends Tag {
public function render() { public function render() {
$el = $this->getDOM(); $el = $this->getDOM();
@ -149,6 +155,7 @@ 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""/> * input <tag type="svg" style="color: white; width: 18px; height: 18px""/>
*/ */
@ -164,7 +171,8 @@ 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é)" />
* return something
*/ */
class Loop extends Tag { class Loop extends Tag {
public function render() { public function render() {
@ -237,6 +245,7 @@ class Loop extends Tag {
} }
} }
//function qui ajoute du html dans la node
function appendHTML(DOMNode $parent, $source) { function appendHTML(DOMNode $parent, $source) {
$tmpDoc = new DOMDocument(); $tmpDoc = new DOMDocument();
$html = "<html><body>"; $html = "<html><body>";
@ -249,10 +258,8 @@ function appendHTML(DOMNode $parent, $source) {
} }
} }
//testing purpose // function de gestion
//$content = file_get_contents("./test.html"); function loadTags($ctnt) {
function loadTags($ctnt, $debug) {
$dom = new DOMDocument(); $dom = new DOMDocument();
libxml_use_internal_errors(true); libxml_use_internal_errors(true);
$dom->loadHTML($ctnt); $dom->loadHTML($ctnt);
@ -266,17 +273,15 @@ function loadTags($ctnt, $debug) {
$t->appendXML($p); $t->appendXML($p);
$head->item(0)->appendChild($t); $head->item(0)->appendChild($t);
//remove all tag components //charge et supprimme les tags
while($list->length >= 1) { while($list->length >= 1) {
$lst = $list->item(0); $lst = $list->item(0);
$tgs = ucfirst($lst->getAttribute("type")); $tgs = ucfirst($lst->getAttribute("type"));
// var_dump($tgs); $tg = new $tgs($dom, $lst, false);
$tg = new $tgs($dom, $lst, $debug);
$tg->render(); $tg->render();
$list[0]->parentNode->removeChild($list[0]); $list[0]->parentNode->removeChild($list[0]);
$list = $dom->getElementsByTagName("tag"); $list = $dom->getElementsByTagName("tag");
} }

View File

@ -1,2 +0,0 @@
<tag type="bold">bold text</tag>
ne pas utiliser c'est juste pour montrer les possibilité