mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-23 19:32:15 +00:00
ça'
This commit is contained in:
parent
22fc7cfe22
commit
94fa0c2870
@ -3,6 +3,14 @@
|
||||
<head>
|
||||
</head>
|
||||
<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>
|
||||
</html>
|
@ -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);
|
||||
}
|
||||
|
@ -2,126 +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'], '/');
|
||||
|
||||
// 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];
|
||||
|
||||
// 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()
|
||||
*
|
||||
*/
|
||||
|
@ -1,66 +1,26 @@
|
||||
<?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";
|
||||
|
||||
//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/*"
|
||||
|
@ -1,31 +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;
|
||||
}
|
||||
|
||||
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");
|
||||
};
|
||||
}
|
||||
}
|
||||
|
@ -1,11 +1,4 @@
|
||||
<?php
|
||||
/**
|
||||
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
|
||||
*/
|
||||
|
||||
|
||||
$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 <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
|
||||
*/
|
||||
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");
|
||||
|
||||
@ -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 {
|
||||
public function render() {
|
||||
@ -113,6 +111,10 @@ class IsLoggedIn extends Tag {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* input <tag type="author" column="(column name)"/>
|
||||
* return text
|
||||
*/
|
||||
class Author extends Tag {
|
||||
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 {
|
||||
public function render() {
|
||||
$el = $this->getDOM();
|
||||
@ -149,6 +155,7 @@ class Includes extends Tag {
|
||||
$el->setAttribute("style", $el->getAttribute("style"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 {
|
||||
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 = "<html><body>";
|
||||
@ -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");
|
||||
}
|
||||
|
@ -1,2 +0,0 @@
|
||||
<tag type="bold">bold text</tag>
|
||||
ne pas utiliser c'est juste pour montrer les possibilité
|
Loading…
x
Reference in New Issue
Block a user