This commit is contained in:
adrien 2019-01-14 16:54:59 +01:00
commit 15a60475db
10 changed files with 169 additions and 239 deletions

View File

@ -0,0 +1,7 @@
<html>
<head>
</head>
<body>
<p>404</p>
</body>
</html>

View File

@ -1,7 +1,7 @@
<!DOCTYPE html>
<html>
<head>
</head>
<head>
</head>
<body>
<header>
<tag type="includes" file="header" />

View File

@ -0,0 +1,8 @@
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<p>searching...</p>
</body>
</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,119 +2,65 @@
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")) {
echo file_get_contents("../css/style.css");
die;
}
//si on cherche un fichier js
//renvoie vers le fichier js si demandé
if(endsWith($_GET["page"], ".js")) {
echo file_get_contents("../js/script.js");
die;
}
//va cherche l'image uploader
if(false) {
}
// var_dump(sizeof($_GET));
//rajout d'un / a la fin (parceque c'est jolie)
if($_GET["page"] != "" && !endsWith($_GET["page"], "/")) {
// si page non / & finit pas par / at pas de ?
if($_GET["page"] != "" && !endsWith($_GET["page"], "/") && sizeof($_GET) <= 1) {
header("Location: /".$_GET["page"]."/");
die;
}
//enleve les / du début & fin
$_GET['page'] = trim($_GET['page'], '/');
$_GET['page'] = explode('/', $_GET['page'])[0];
if($_GET['page'] == '') {
$_GET['page'] = 'index';
// si taille supérieur à 1 $_getpost = element
if(sizeof(explode("/", $_GET["page"])) > 1) {
$_GET["post"] = explode("/", $_GET["page"])[1];
}
// die;
// $_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;
}
include_once "tagHandler.php";
$pokemon = loadTags("../html/".$_GET["page"].".html", false);
// var_dump(mb_detect_encoding($pokemon));
/**
* 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);
//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()
*
*/

View File

@ -1,119 +1,26 @@
<?php
include_once "router.php";
/**
* classe Pages
* a constructor to load additionnal pages and initialize the whole class and load the pages
*/
//recupération du router
$router = Router::getRouter();
/**
* 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)
*/
//page d'accueil
$home = function () {
return file_get_contents("../html/index.html");
};
/**
* 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)
*/
$router->addRoute("/^\/$/", $home); // route : "/"
/**
* abstract Class Page
*
* attributes
* id
* title
* regex
* content
* isLoaded: boolean
*
* functions:
* abstract __construct()
* absract loadPage()
*
*/
//page de post
$post = function () {
return file_get_contents("../html/post.html");
};
/**
* 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 {
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() {}
}
$router->addRoute("/^\/post\/$/", $post); // route "/post/*"
//page de recherche
$search = function () {
return file_get_contents("../html/search.html");
};
$router->addRoute("/^\/search\/$/", $search); // route "/search/*"

View File

@ -0,0 +1,45 @@
<?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 {
//variable static pour stocker le router
private static $router;
//definit le router
public function __construct() {
//TODO faire que si un router existe dajà retourner le routeur existant
Router::$router = $this;
}
//fonction static pour recuperer un router déjà créé
public static function getRouter() {
return Router::$router;
}
//liste des routes
private $routeList = array();
//ajout d'une route
public function addRoute($route, $page) {
$this->routeList[$route] = $page;
}
//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");
};
}
}

View File

@ -1,11 +1,4 @@
<?php
/**
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
*/
$debug = false;
class Tag {
@ -34,42 +27,41 @@ class Tag {
public function render() {}
}
//ce tag est juste la pour donner les possibilité de mon composant
//input <tag type="bold">test</tag>
//result <span style="font-weight: bold">test</span>
/**
* input <tag type="bold">test</tag>
* result <span style="font-weight: bold">test</span>
*/
class Bold extends Tag {
public function render() {
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
$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 <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)/>
* return text
*/
class Article extends Tag {
public function render() {
$post = array( //testing purpose
'title'=> "test",
'url'=> "pokemon",
'url'=> "pokemongo",
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
);
$pok = $this->getDOM();
$attr = $pok->getAttribute("column");
@ -89,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 {
public function render() {
@ -111,6 +111,10 @@ class IsLoggedIn extends Tag {
}
}
/**
* input <tag type="author" column="(column name)"/>
* return text
*/
class Author extends Tag {
public function render() {
@ -133,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 {
public function render() {
$el = $this->getDOM();
@ -148,6 +156,9 @@ class Includes extends Tag {
}
}
/**
* input <tag type="svg" style="color: white; width: 18px; height: 18px""/>
*/
class Svg extends Tag {
public function render() {
$el = $this->getDOM();
@ -160,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 {
public function render() {
@ -233,6 +245,7 @@ class Loop extends Tag {
}
}
//function qui ajoute du html dans la node
function appendHTML(DOMNode $parent, $source) {
$tmpDoc = new DOMDocument();
$html = "<html><body>";
@ -245,13 +258,11 @@ 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->loadHTMLFile($ctnt);
$dom->loadHTML($ctnt);
libxml_clear_errors();
$list = $dom->getElementsByTagName("tag");
@ -262,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");
}

View File

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