removed pokemon

This commit is contained in:
2018-12-03 13:41:25 +01:00
parent 66e357d009
commit 589506478b
9 changed files with 259 additions and 150 deletions

View File

@ -1,7 +1,27 @@
<?php
/* Fichier qui va gerer la creation de la page et la redirection au cas ou */
ini_set('display_errors', 'On');
// var_dump($_SERVER);
if(endsWith($_GET["page"], ".css")) {
echo file_get_contents("../css/style.css");
die;
}
//si on cherche un fichier js
if(endsWith($_GET["page"], ".js")) {
echo file_get_contents("../js/script.js");
die;
}
//rajout d'un / a la fin (parceque c'est jolie)
if($_GET["page"] != "" && !endsWith($_GET["page"], "/")) {
header("Location: /".$_GET["page"]."/");
die;
}
$_GET['page'] = trim($_GET['page'], '/');
$_GET['page'] = explode('/', $_GET['page'])[0];
@ -9,11 +29,88 @@ if($_GET['page'] == '') {
$_GET['page'] = 'index';
}
// é
// var_dump($_POST);
// var_dump($_GET);
// die;
include_once "tagHandler.php";
$pokemon = loadTags("../html/".$_GET["page"].".html", false);
$pokemon = mb_convert_encoding($pokemon, "utf-16");
// var_dump(mb_detect_encoding($pokemon));
$pokemon = htmlspecialchars_decode($pokemon, ENT_HTML5);
echo $pokemon;
// echo mb_convert_encoding($pokemon, "ascii");
// 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:
* __construct(id, title, regex)
* 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

@ -3,12 +3,11 @@
* <tag type="pokemon" arg="pokemongo"><div class="pokemon-item"></div></tag>
*/
ini_set('display_errors', 'On');
$debug = false;
class tag {
class Tag {
private $DOM;
private $doc;
@ -38,7 +37,7 @@ class tag {
//input <tag type="bold">test</tag>
//result <span style="font-weight: bold">test</span>
class bold extends tag {
class Bold extends Tag {
public function render() {
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
$pok = $this->getDOM();
@ -56,12 +55,11 @@ class bold extends tag {
//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 {
class Article extends Tag {
public function render() {
$post = array( //testing purpose
@ -87,16 +85,13 @@ class article extends tag {
$txt = $doc->createTextNode($post[$attr]);
$pok->parentNode->insertBefore($txt, $pok);
}
}
}
/**
* return element is user
*/
class isLoggedIn extends tag {
class IsLoggedIn extends Tag {
public function render() {
$el = $this->getDOM();
@ -104,20 +99,19 @@ class isLoggedIn extends tag {
//debugging purpose
$loggedin = false;
foreach ($el->getElementsByTagName("if") as $element) {
if($element->hasAttribute("true") && $loggedin){
$r = $element->childNodes->item(1);
$el->parentNode->insertBefore($r, $el);
} elseif ($element->hasAttribute("false")) {
$r = $element->childNodes->item(1);
$el->parentNode->insertBefore($r, $el);
}
foreach ($el->getElementsByTagName("if") as $element) {
if($element->hasAttribute("true") && $loggedin) {
$r = $element->childNodes->item(1);
$el->parentNode->insertBefore($r, $el);
} elseif ($element->hasAttribute("false")) {
$r = $element->childNodes->item(1);
$el->parentNode->insertBefore($r, $el);
}
}
}
}
class author extends tag {
class Author extends Tag {
public function render() {
$post = array( //testing purpose
@ -136,11 +130,10 @@ class author extends tag {
$txt = $doc->createTextNode($post[$attr]);
$pok->parentNode->insertBefore($txt, $pok);
}
}
class includes extends tag {
class Includes extends Tag {
public function render() {
$el = $this->getDOM();
$doc = $this->getDoc();
@ -148,7 +141,6 @@ class includes extends tag {
$t = $doc->createDocumentFragment();
$p = file_get_contents("../html/includes/".$attr.".html");
appendHTML($el->parentNode, $p);
}
}
@ -156,7 +148,7 @@ class includes extends tag {
/**
* input <tag type="loop" for="(table)" limit="(nombre-max généré)">
*/
class loop extends tag {
class Loop extends Tag {
public function render() {
$el = $this->getDOM();
@ -210,7 +202,6 @@ class loop extends tag {
$elements = $pok->getElementsByTagName("loop");
foreach ($elements as $ele) {
if($ele->getAttribute("column") == "content") {
appendHTML($ele, $posts[$i][$ele->getAttribute("column")]);
} else {
@ -260,7 +251,7 @@ function loadTags($ctnt, $debug) {
for ($i=0; $i < $list->count(); $i++) {
$lst = $list->item($i);
$tgs = $lst->getAttribute("type");
$tgs = ucfirst($lst->getAttribute("type"));
$tg = new $tgs($dom, $lst, $debug);