mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 10:52:09 +00:00
too much changes
This commit is contained in:
parent
13303e50d4
commit
208863abed
2
.gitignore
vendored
2
.gitignore
vendored
@ -6,3 +6,5 @@ build/
|
|||||||
ops/terraform/secrets.tf
|
ops/terraform/secrets.tf
|
||||||
.DS_Store
|
.DS_Store
|
||||||
**/.idea
|
**/.idea
|
||||||
|
|
||||||
|
/vendor/
|
||||||
|
20
composer.json
Normal file
20
composer.json
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"name": "avior/blog_imie",
|
||||||
|
"type": "project",
|
||||||
|
"require": {
|
||||||
|
},
|
||||||
|
"authors": [
|
||||||
|
{
|
||||||
|
"name": "Avior",
|
||||||
|
"email": "florian.bouillon@delta-wings.net"
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"require-dev": {
|
||||||
|
"phpunit/phpunit": "^8"
|
||||||
|
},
|
||||||
|
"autoload": {
|
||||||
|
"classmap": [
|
||||||
|
"project/assets/php/"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
1489
composer.lock
generated
Normal file
1489
composer.lock
generated
Normal file
File diff suppressed because it is too large
Load Diff
@ -61,7 +61,7 @@ body{
|
|||||||
}
|
}
|
||||||
h2{
|
h2{
|
||||||
font-weight: 600;
|
font-weight: 600;
|
||||||
font-size: 17px;
|
font-size: 17px;
|
||||||
}
|
}
|
||||||
.title-second{
|
.title-second{
|
||||||
font-weight: 400;
|
font-weight: 400;
|
||||||
@ -99,8 +99,8 @@ h2{
|
|||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
color: white;
|
color: white;
|
||||||
-webkit-transition: 400ms;
|
-webkit-transition: 400ms;
|
||||||
-o-transition: 400ms;
|
-o-transition: 400ms;
|
||||||
transition: 400ms;
|
transition: 400ms;
|
||||||
}
|
}
|
||||||
.item_nav_imie a:hover{
|
.item_nav_imie a:hover{
|
||||||
color: #a5a5a5;
|
color: #a5a5a5;
|
||||||
@ -138,8 +138,8 @@ h2{
|
|||||||
float: right;
|
float: right;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
-webkit-transition: 400ms;
|
-webkit-transition: 400ms;
|
||||||
-o-transition: 400ms;
|
-o-transition: 400ms;
|
||||||
transition: 400ms;
|
transition: 400ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
.item_nav_blog_droite:hover{
|
.item_nav_blog_droite:hover{
|
||||||
@ -192,9 +192,9 @@ h2{
|
|||||||
background-color: #150032;
|
background-color: #150032;
|
||||||
font-family: 'Open Sans', sans-serif;
|
font-family: 'Open Sans', sans-serif;
|
||||||
font-size: 20px;
|
font-size: 20px;
|
||||||
color: white;
|
color: white;
|
||||||
}
|
}
|
||||||
.test2{
|
.cover-text {
|
||||||
padding: 0px 90px;
|
padding: 0px 90px;
|
||||||
margin-top: 100px;
|
margin-top: 100px;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
@ -215,8 +215,8 @@ h2{
|
|||||||
padding: 10px 15px;
|
padding: 10px 15px;
|
||||||
color: white;
|
color: white;
|
||||||
-webkit-transition: 300ms;
|
-webkit-transition: 300ms;
|
||||||
-o-transition: 300ms;
|
-o-transition: 300ms;
|
||||||
transition: 300ms;
|
transition: 300ms;
|
||||||
|
|
||||||
}
|
}
|
||||||
.bloc-plus:hover{
|
.bloc-plus:hover{
|
||||||
@ -360,7 +360,7 @@ input {outline: none}
|
|||||||
}
|
}
|
||||||
.post .text{
|
.post .text{
|
||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
color: #737272ee;
|
color: #737272ee;
|
||||||
line-height: 1.5;
|
line-height: 1.5;
|
||||||
margin-top: 28px;
|
margin-top: 28px;
|
||||||
}
|
}
|
||||||
@ -491,8 +491,8 @@ input {outline: none}
|
|||||||
|
|
||||||
}
|
}
|
||||||
@media screen and (max-width: 640px) {
|
@media screen and (max-width: 640px) {
|
||||||
.nav_imie {
|
.nav_imie {
|
||||||
height: 0;
|
height: 0;
|
||||||
}
|
}
|
||||||
#twi{
|
#twi{
|
||||||
height: 0;
|
height: 0;
|
||||||
|
@ -1,23 +1,23 @@
|
|||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-12 pad">
|
<div class="col-12 pad">
|
||||||
<div class="fullFooter">
|
<div class="fullFooter">
|
||||||
<div class="upFooter">
|
<div class="upFooter">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="iconOnFooter"><a><tag type="svg" file="facebook" style="color: white; width: 18px; height: 18px"/></a></li>
|
<li class="iconOnFooter"><a><tag type="svg" file="facebook" style="color: white; width: 18px; height: 18px"/></a></li>
|
||||||
<li class="iconOnFooter"><a><tag type="svg" file="twitter" style="color: white; width: 18px; height: 18px"/></a></li>
|
<li class="iconOnFooter"><a><tag type="svg" file="twitter" style="color: white; width: 18px; height: 18px"/></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
<p class="phraseFooter">Suivez-nous sur les réseaux</p>
|
<p class="phraseFooter">Suivez-nous sur les réseaux</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="lowFooter">
|
<div class="lowFooter">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="lowFooterItem">Politique et confidentialité</li>
|
<li class="lowFooterItem">Politique et confidentialité</li>
|
||||||
<li class="lowFooterItem">Mentions légales</li>
|
<li class="lowFooterItem">Mentions légales</li>
|
||||||
<li class="lowFooterItem">Contact</li>
|
<li class="lowFooterItem">Contact</li>
|
||||||
<li class="lowFooterItem">Connexion</li>
|
<li class="lowFooterItem">Connexion</li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,37 +1,37 @@
|
|||||||
<div>
|
<div>
|
||||||
<div class="nav_imie">
|
<div class="nav_imie">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="item_nav_imie link" ><a>Connexion</a></li>
|
<li class="item_nav_imie link" ><a>Connexion</a></li>
|
||||||
<li class="item_nav_imie link" ><a href="https://imie44.ymag.cloud">Accès Net-Yparéo</a></li>
|
<li class="item_nav_imie link" ><a href="https://imie44.ymag.cloud">Accès Net-Yparéo</a></li>
|
||||||
<li class="item_nav_imie link" ><a href="https://www.imie.fr">IMIE Numérique</a></li>
|
<li class="item_nav_imie link" ><a href="https://www.imie.fr">IMIE Numérique</a></li>
|
||||||
<li class="item_nav_imie social" ><a href="https://twitter.com/EcoleIMIE"><tag type="svg" file="twitter" style="color: white; width: 18px; height: 18px"/></a></li>
|
<li class="item_nav_imie social" ><a href="https://twitter.com/EcoleIMIE"><tag type="svg" file="twitter" style="color: white; width: 18px; height: 18px"/></a></li>
|
||||||
<li class="item_nav_imie social" ><a href="https://www.facebook.com/EcolesIMIE/"><tag type="svg" file="facebook" style="color: white; width: 18px; height: 18px"/></a></li>
|
<li class="item_nav_imie social" ><a href="https://www.facebook.com/EcolesIMIE/"><tag type="svg" file="facebook" style="color: white; width: 18px; height: 18px"/></a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<nav class="nav_blog">
|
<nav class="nav_blog">
|
||||||
<div class="container-fluid">
|
<div class="container-fluid">
|
||||||
<div class="container">
|
<div class="container">
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
|
||||||
<ul>
|
<ul>
|
||||||
<li class="item_nav_blog_logo" ><a href="/"><tag type="svg" file="logo-imie-blog" style="color: white; width: 200px; height: 64px; margin-top: 6px;"/></a></li>
|
<li class="item_nav_blog_logo" ><a href="/"><tag type="svg" file="logo-imie-blog" style="color: white; width: 200px; height: 64px; margin-top: 6px;"/></a></li>
|
||||||
<li class="item_nav_blog_droite_icon"><input id="search" type="text" placeholder="Recherche"><a><tag type="svg" file="mignify" style="color: rgba(0, 0, 0, .5); width: 18px; height: 18px"/></a></li>
|
<li class="item_nav_blog_droite_icon"><input id="search" type="text" placeholder="Recherche"><a><tag type="svg" file="mignify" style="color: rgba(0, 0, 0, .5); width: 18px; height: 18px"/></a></li>
|
||||||
<li class="item_nav_blog_droite devops"><a>DEVOPS</a></li>
|
<li class="item_nav_blog_droite devops"><a>DEVOPS</a></li>
|
||||||
<li class="item_nav_blog_droite ops"><a>OPS</a></li>
|
<li class="item_nav_blog_droite ops"><a>OPS</a></li>
|
||||||
<li class="item_nav_blog_droite digi"><a>DIGI</a></li>
|
<li class="item_nav_blog_droite digi"><a>DIGI</a></li>
|
||||||
<li class="item_nav_blog_droite dev"><a>DEV</a></li>
|
<li class="item_nav_blog_droite dev"><a>DEV</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -12,9 +12,9 @@
|
|||||||
<div class="bloc_principal">
|
<div class="bloc_principal">
|
||||||
<div class="cover-black">
|
<div class="cover-black">
|
||||||
<div class="bloc_principal_titre">
|
<div class="bloc_principal_titre">
|
||||||
<h1>L'actualité de nos campus...</h1>
|
<h1>L'actualitée de nos campus...</h1>
|
||||||
</div>
|
</div>
|
||||||
<div class="test2">
|
<div class="cover-text">
|
||||||
<h2 id="titre-home">Ceci est un magnifique titre</h2>
|
<h2 id="titre-home">Ceci est un magnifique titre</h2>
|
||||||
<p class="p-home">
|
<p class="p-home">
|
||||||
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
|
Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
<tag type="includes" file="header" />
|
<tag type="includes" file="header" />
|
||||||
</header>
|
</header>
|
||||||
<main class="test container">
|
<main class="test container">
|
||||||
<div class="bloc-post">
|
<div class="bloc-post">
|
||||||
<div class="container-post post ops">
|
<div class="container-post post ops">
|
||||||
<h2 class="title">Mettre en place un serveur web sous linux</h2>
|
<h2 class="title">Mettre en place un serveur web sous linux</h2>
|
||||||
<div class="etiquettes">
|
<div class="etiquettes">
|
||||||
@ -34,9 +34,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bloc-filter">
|
<div class="bloc-filter">
|
||||||
<p class="title-second">Plus d'articles</p>
|
<p class="title-second">Plus d'articles</p>
|
||||||
<div class="filtre dev-color">dev</div>
|
<div class="filtre dev-color">dev</div>
|
||||||
<div class="filtre digi-color">digi</div>
|
<div class="filtre digi-color">digi</div>
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
<div class="bloc-recent">
|
<div class="bloc-recent">
|
||||||
<div class="contenue-recent">
|
<div class="contenue-recent">
|
||||||
<div class="titre-recent">
|
<div class="titre-recent">
|
||||||
<p>récent</p>
|
<p>récent</p>
|
||||||
</div>
|
</div>
|
||||||
<div class="icon-recent">
|
<div class="icon-recent">
|
||||||
<tag type="svg" file="arrow" style="color: #848484; width: 18px; height: 18px"/>
|
<tag type="svg" file="arrow" style="color: #848484; width: 18px; height: 18px"/>
|
||||||
|
148
project/assets/php/Functions.php
Normal file
148
project/assets/php/Functions.php
Normal file
@ -0,0 +1,148 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMNode;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Avior <florian.bouillon@delta-wings.net>
|
||||||
|
* @author Clément Fourrier
|
||||||
|
*/
|
||||||
|
class Functions {
|
||||||
|
public static function endsWith($haystack, $needle) {
|
||||||
|
$length = strlen($needle);
|
||||||
|
if ($length == 0) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return (substr($haystack, -$length) === $needle);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function connect() {
|
||||||
|
$host = "127.0.0.1";
|
||||||
|
$db = "blog";
|
||||||
|
$user = "blog";
|
||||||
|
$pass = "blog";
|
||||||
|
$charset="utf8mb4";
|
||||||
|
|
||||||
|
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
||||||
|
try {
|
||||||
|
$pdo = new PDO($dsn, $user, $pass, null);
|
||||||
|
} catch (\PDOException $e) {
|
||||||
|
throw new \PDOException($e->getMessage(), (int)$e->getCode());
|
||||||
|
}
|
||||||
|
return $pdo;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param DOMNode $parent
|
||||||
|
* @param [type] $source
|
||||||
|
*
|
||||||
|
* @var DOMNode $node
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function appendHTML(DOMNode $parent, $source) {
|
||||||
|
$tmpDoc = new DOMDocument("1.0", "UTF-8");
|
||||||
|
$html = "<html><body>";
|
||||||
|
$html .= $source;
|
||||||
|
$html .= "</body></html>";
|
||||||
|
$tmpDoc->loadHTML($html);
|
||||||
|
// $tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
|
||||||
|
|
||||||
|
// foreach ($tmpDoc->childNodes as $item)
|
||||||
|
// if ($item->nodeType == XML_PI_NODE)
|
||||||
|
// $tmpDoc->removeChild($item);
|
||||||
|
// $tmpDoc->encoding = 'UTF-8';
|
||||||
|
|
||||||
|
/** @var DOMNode $node */
|
||||||
|
foreach($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
|
||||||
|
$importedNode = $parent->ownerDocument->importNode($node, true);
|
||||||
|
$parent->appendChild($importedNode);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function loadRoutes() {
|
||||||
|
//recupération du router
|
||||||
|
$router = Router::getRouter();
|
||||||
|
|
||||||
|
$postCharacters = "[a-z0-9-]";
|
||||||
|
|
||||||
|
//page d'accueil
|
||||||
|
$home = function () {
|
||||||
|
return file_get_contents("../html/index.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/$/", $home); // route : "/"
|
||||||
|
|
||||||
|
//page de post
|
||||||
|
$post = function () {
|
||||||
|
return file_get_contents("../html/post.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/post\/" . $postCharacters . "+\/*$/", $post); // route "/post/*"
|
||||||
|
|
||||||
|
//page de recherche
|
||||||
|
$search = function () {
|
||||||
|
return file_get_contents("../html/search.html");
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/search\/$/", $search); // route "/search/*"
|
||||||
|
|
||||||
|
$edit = function() {
|
||||||
|
$_POST = array_merge($_POST, $_GET); //debug uniquement
|
||||||
|
var_dump($_POST);
|
||||||
|
/*
|
||||||
|
$_POST should contain
|
||||||
|
post :
|
||||||
|
id
|
||||||
|
title
|
||||||
|
content
|
||||||
|
category
|
||||||
|
author
|
||||||
|
|
||||||
|
UPDATE posts
|
||||||
|
SET
|
||||||
|
title = title,
|
||||||
|
url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], title));
|
||||||
|
content = content,
|
||||||
|
short = substr(content, 0, 253) . "...";
|
||||||
|
category = categoryId
|
||||||
|
author = authorId
|
||||||
|
WHERE id = id
|
||||||
|
*/
|
||||||
|
|
||||||
|
$request = "UPDATE posts SET `title`=:title, `url`=:url, `content`=:content, `short`=:short, `category`=:category, `author`=:author, WHERE `id`=:id";
|
||||||
|
|
||||||
|
$title = $_POST["title"];
|
||||||
|
$url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], $title));
|
||||||
|
$content = $_POST["content"];
|
||||||
|
$short = substr($content, 0, 253) . "...";
|
||||||
|
$category = intval($_POST["category"]);
|
||||||
|
$author = intval($_POST["author"]);
|
||||||
|
|
||||||
|
$id = intval($_POST["id"]);
|
||||||
|
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$prepared = $pdo->prepare($request);
|
||||||
|
$prepared->bindParam(":title", $title);
|
||||||
|
$prepared->bindParam(":url", $url);
|
||||||
|
$prepared->bindParam(":content", $content);
|
||||||
|
$prepared->bindParam(":short", $short);
|
||||||
|
$prepared->bindParam(":category", $category, PDO::PARAM_INT);
|
||||||
|
$prepared->bindParam(":author", $author, PDO::PARAM_INT);
|
||||||
|
$prepared->bindParam(":id", $id, PDO::PARAM_INT);
|
||||||
|
|
||||||
|
$prepared->execute();
|
||||||
|
};
|
||||||
|
|
||||||
|
$router->addRoute("/^\/post\/" . $postCharacters . "+\/edit\/*$/", $edit);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
8
project/assets/php/router.php → project/assets/php/Router.php
Executable file → Normal file
8
project/assets/php/router.php → project/assets/php/Router.php
Executable file → Normal file
@ -1,5 +1,7 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
|
namespace App;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* classe pour gerer le routage des pages
|
* classe pour gerer le routage des pages
|
||||||
* la variable static $router sert a utiliser le router dans plusieurs fichier
|
* la variable static $router sert a utiliser le router dans plusieurs fichier
|
||||||
@ -44,10 +46,4 @@ class Router {
|
|||||||
return file_get_contents("../html/404.html");
|
return file_get_contents("../html/404.html");
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
public function redirecter($source, $redirectPage) {
|
|
||||||
$this->addRoute($source, function() {
|
|
||||||
header("Location: " . $redirectPage);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
33
project/assets/php/Tags/Article.php
Normal file
33
project/assets/php/Tags/Article.php
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
use App\Functions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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'=> "pokemongo",
|
||||||
|
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
||||||
|
);
|
||||||
|
|
||||||
|
$pok = $this->getElement();
|
||||||
|
$attr = $pok->getAttribute("column");
|
||||||
|
|
||||||
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
|
if($attr == "content") {
|
||||||
|
Functions::appendHTML($pok->parentNode, $post[$attr]);
|
||||||
|
} else {
|
||||||
|
$txt = $doc->createTextNode($post[$attr]);
|
||||||
|
$pok->parentNode->insertBefore($txt, $pok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
31
project/assets/php/Tags/Author.php
Normal file
31
project/assets/php/Tags/Author.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* input <tag type="author" column="(column name)"/>
|
||||||
|
* return text
|
||||||
|
*/
|
||||||
|
class Author extends Tag {
|
||||||
|
public function render() {
|
||||||
|
|
||||||
|
$post = array( //testing purpose
|
||||||
|
'name'=> "test",
|
||||||
|
'image'=> "pokemon",
|
||||||
|
'linkedin'=> "pouet"
|
||||||
|
);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$pok = $this->getElement();
|
||||||
|
$attr = $pok->getAttribute("column");
|
||||||
|
|
||||||
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
|
$txt = $doc->createTextNode($post[$attr]);
|
||||||
|
|
||||||
|
$pok->parentNode->insertBefore($txt, $pok);
|
||||||
|
}
|
||||||
|
}
|
29
project/assets/php/Tags/Bold.php
Normal file
29
project/assets/php/Tags/Bold.php
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
|
||||||
|
//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>
|
||||||
|
*/
|
||||||
|
class Bold extends Tag {
|
||||||
|
public function render() {
|
||||||
|
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
|
||||||
|
$pok = $this->getElement();
|
||||||
|
//recuperation du document (necessaire a la création de balises
|
||||||
|
$doc = $this->getDoc();
|
||||||
|
//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);
|
||||||
|
//rajout dans la balise span notre texte
|
||||||
|
$res->appendChild($text);
|
||||||
|
//on rajoute a la balise span du style pour le mettre en gras
|
||||||
|
$res->setAttribute("style", "font-weight: bold");
|
||||||
|
//enfin on met la div final dans le fichier
|
||||||
|
$pok->parentNode->insertBefore($res, $pok);
|
||||||
|
}
|
||||||
|
}
|
22
project/assets/php/Tags/Includes.php
Normal file
22
project/assets/php/Tags/Includes.php
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
use App\Functions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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->getElement();
|
||||||
|
$attr = $el->getAttribute("file");
|
||||||
|
|
||||||
|
$p = file_get_contents("../html/includes/".$attr.".html");
|
||||||
|
|
||||||
|
// var_dump($p);
|
||||||
|
Functions::appendHTML($el->parentNode, $p);
|
||||||
|
}
|
||||||
|
}
|
36
project/assets/php/Tags/IsLoggedIn.php
Normal file
36
project/assets/php/Tags/IsLoggedIn.php
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* <tag type="isloggedin">
|
||||||
|
* <if true>
|
||||||
|
*
|
||||||
|
* </if>
|
||||||
|
* <if false>
|
||||||
|
*
|
||||||
|
* </if>
|
||||||
|
* </tag>
|
||||||
|
*/
|
||||||
|
class IsLoggedIn extends Tag {
|
||||||
|
public function render() {
|
||||||
|
|
||||||
|
$el = $this->getElement();
|
||||||
|
|
||||||
|
//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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
70
project/assets/php/Tags/Loop.php
Normal file
70
project/assets/php/Tags/Loop.php
Normal file
@ -0,0 +1,70 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
use DomXPath;
|
||||||
|
use App\Functions;
|
||||||
|
use App\DB\Post;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* input
|
||||||
|
* <tag type="loop" for="(table)" limit="(nombre-max g<>n<EFBFBD>r<EFBFBD>)">
|
||||||
|
* <loop column="element"/>
|
||||||
|
* </tag>
|
||||||
|
*/
|
||||||
|
class Loop extends Tag {
|
||||||
|
public function render() {
|
||||||
|
$el = $this->getElement();
|
||||||
|
|
||||||
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
|
$limit = (int) $el->getAttribute("limit");
|
||||||
|
|
||||||
|
$posts = Post::list($limit);
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$query = $pdo->query("SELECT title, categories.name as categorie, dt as date, short as content
|
||||||
|
FROM posts
|
||||||
|
INNER JOIN categories ON categories.id=posts.categorie
|
||||||
|
ORDER BY date DESC
|
||||||
|
LIMIT 6;");
|
||||||
|
$posts = $query->fetchAll();
|
||||||
|
|
||||||
|
$parent = $el->parentNode;
|
||||||
|
//var_dump($parent);
|
||||||
|
|
||||||
|
|
||||||
|
$limit = $limit > count($posts) ? count($posts) : $limit;
|
||||||
|
|
||||||
|
for ($i=0; $i < $limit; $i++) {
|
||||||
|
$pok = $el->childNodes->item(0)->cloneNode(true);
|
||||||
|
|
||||||
|
$parent->insertBefore($pok, $el);
|
||||||
|
|
||||||
|
$elements = $pok->getElementsByTagName("loop");
|
||||||
|
|
||||||
|
foreach ($elements as $ele) {
|
||||||
|
if($ele->getAttribute("column") == "content") {
|
||||||
|
Functions::appendHTML($ele->parentNode, $posts[$i]["content"]);
|
||||||
|
} else {
|
||||||
|
$txt = $doc->createTextNode($posts[$i][$ele->getAttribute("column")]);
|
||||||
|
$ele->parentNode->insertBefore($txt, $ele);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$finder = new DomXPath($doc);
|
||||||
|
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
|
||||||
|
|
||||||
|
if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-categorie", $posts[$i]["categorie"], $nodes[0]->getAttribute("class")));
|
||||||
|
|
||||||
|
$loop = $pok->getElementsByTagName("loop");
|
||||||
|
|
||||||
|
while ($loop->count() >= 1) {
|
||||||
|
$loop->item(0)->parentNode->removeChild($loop->item(0));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
20
project/assets/php/Tags/Svg.php
Normal file
20
project/assets/php/Tags/Svg.php
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
use App\Functions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* <tag type="svg" style="color: white; width: 18px; height: 18px""/>
|
||||||
|
*/
|
||||||
|
class Svg extends Tag {
|
||||||
|
public function render() {
|
||||||
|
$el = $this->getElement();
|
||||||
|
$attr = $el->getAttribute("file");
|
||||||
|
$t = $this->getDoc()->createDocumentFragment();
|
||||||
|
$p = file_get_contents("../img/".$attr.".svg");
|
||||||
|
Functions::appendHTML($el->parentNode, $p);
|
||||||
|
$el->nextSibling->setAttribute("style", $el->getAttribute("style"));
|
||||||
|
}
|
||||||
|
}
|
110
project/assets/php/Tags/Tag.php
Normal file
110
project/assets/php/Tags/Tag.php
Normal file
@ -0,0 +1,110 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use DOMDocument;
|
||||||
|
use DOMElement;
|
||||||
|
use DOMNode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author Avior <florian.bouillon@delta-wings.net>
|
||||||
|
*
|
||||||
|
* @version 1.0.0
|
||||||
|
*/
|
||||||
|
class Tag {
|
||||||
|
|
||||||
|
/** @var DOMDocument */
|
||||||
|
private $document;
|
||||||
|
|
||||||
|
/** @var DOMElement */
|
||||||
|
private $element;
|
||||||
|
|
||||||
|
/** @var boolean */
|
||||||
|
private $debug;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Tag Constructor (will receive variables used in the tags)
|
||||||
|
*
|
||||||
|
* @param DOMDocument $doc the document
|
||||||
|
* @param DOMElement $DOMContent the element
|
||||||
|
* @param boolean $debug is debug enable or not ?
|
||||||
|
*/
|
||||||
|
public function __construct(DOMDocument $document, DOMElement $element, bool $debug) {
|
||||||
|
$this->document = $document;
|
||||||
|
$this->element = $element;
|
||||||
|
$this->debug = $debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return DOMDocument return the document */
|
||||||
|
public function getDoc(): DOMDocument {
|
||||||
|
return $this->document;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* get the element
|
||||||
|
*
|
||||||
|
* @return DOMElement the element
|
||||||
|
*/
|
||||||
|
public function getElement(): DOMElement {
|
||||||
|
return $this->element;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** @return boolean */
|
||||||
|
public function isDebugging(): bool {
|
||||||
|
return $this->debug;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function render() {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Load tags from html $content and return the resulting String
|
||||||
|
*
|
||||||
|
* @param String $content base html file containing <tag />
|
||||||
|
*
|
||||||
|
* @return String the result html
|
||||||
|
*/
|
||||||
|
public static function loadTags(String $content): String {
|
||||||
|
$dom = new DOMDocument('1.0', 'UTF-8');
|
||||||
|
libxml_use_internal_errors(true);
|
||||||
|
$dom->loadHTML('<?xml encoding="UTF-8">'.$content);
|
||||||
|
libxml_clear_errors();
|
||||||
|
|
||||||
|
// fix UTF-8 problem
|
||||||
|
/** @var DOMNode $item */
|
||||||
|
foreach ($dom->childNodes as $item)
|
||||||
|
if ($item->nodeType == XML_PI_NODE)
|
||||||
|
$dom->removeChild($item);
|
||||||
|
$dom->encoding = 'UTF-8';
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$head = $dom->getElementsByTagName("head");
|
||||||
|
if($head->count() >= 1) {
|
||||||
|
$t = $dom->createDocumentFragment();
|
||||||
|
$p = file_get_contents("../html/includes/head.html");
|
||||||
|
$t->appendXML($p);
|
||||||
|
$head->item(0)->appendChild($t);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
$list = $dom->getElementsByTagName("tag");
|
||||||
|
|
||||||
|
//charge et supprimme les tags
|
||||||
|
while($lst = $list->item(0)) {
|
||||||
|
|
||||||
|
$tgs = "\\App\\Tags\\" . ucfirst($lst->getAttribute("type"));
|
||||||
|
$tg = new $tgs($dom, $lst, false);
|
||||||
|
|
||||||
|
$tg->render();
|
||||||
|
|
||||||
|
$lst->parentNode->removeChild($lst);
|
||||||
|
|
||||||
|
$list = $dom->getElementsByTagName("tag");
|
||||||
|
}
|
||||||
|
|
||||||
|
$res = $dom->saveHTML();
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
12
project/assets/php/db/Author.php
Normal file
12
project/assets/php/db/Author.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DB;
|
||||||
|
|
||||||
|
class Author {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
private $username;
|
||||||
|
|
||||||
|
private $linkedin;
|
||||||
|
}
|
99
project/assets/php/db/Categorie.php
Normal file
99
project/assets/php/db/Categorie.php
Normal file
@ -0,0 +1,99 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DB;
|
||||||
|
|
||||||
|
use App\Functions;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
|
||||||
|
class Categorie {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
public function __construct($id, $name) {
|
||||||
|
$this->id = $id;
|
||||||
|
$this->name = $name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromArray($array) {
|
||||||
|
return new Self($array["id"], $array["name"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param boolean $recent sort by most recent of less recent
|
||||||
|
* @param int $limit
|
||||||
|
*
|
||||||
|
* @return Categorie[]
|
||||||
|
*/
|
||||||
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
|
$query = "SELECT * FROM categories ORDER BY " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$cats = $pdo->query($query)->fetchAll();
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
foreach ($cats as $cat) {
|
||||||
|
$res[] = new Categorie($cat["id"], $cat["name"]);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(int $id) {
|
||||||
|
return Categorie::fromArray(Functions::connect()->query("SELECT * FROM categories WHERE id=" . $id)->fetch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add(Categorie $categorie) {
|
||||||
|
$query = "INSERT INTO categories (id, name)
|
||||||
|
VALUES (NULL, ':name');";
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$prepared = $pdo->prepare($query);
|
||||||
|
$prepared->bindParam(":name", $categorie->getName());
|
||||||
|
$prepared->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function remove(Categorie $categorie) {
|
||||||
|
Functions::connect()->prepare("DELETE FROM categories WHERE id=" . $categorie->getName())->execute();
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update(Categorie $categorie) {
|
||||||
|
$query = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of name
|
||||||
|
*/
|
||||||
|
public function getName()
|
||||||
|
{
|
||||||
|
return $this->name;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the value of name
|
||||||
|
*
|
||||||
|
* @return self
|
||||||
|
*/
|
||||||
|
public function setName($name)
|
||||||
|
{
|
||||||
|
$this->name = $name;
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the value of id
|
||||||
|
*/
|
||||||
|
public function getId()
|
||||||
|
{
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
}
|
71
project/assets/php/db/Post.php
Normal file
71
project/assets/php/db/Post.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DB;
|
||||||
|
|
||||||
|
class Post {
|
||||||
|
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
private $title;
|
||||||
|
|
||||||
|
private $url;
|
||||||
|
|
||||||
|
private $content;
|
||||||
|
|
||||||
|
private $short;
|
||||||
|
|
||||||
|
private $categorie;
|
||||||
|
|
||||||
|
private $author;
|
||||||
|
|
||||||
|
private $dt;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list of posts
|
||||||
|
*
|
||||||
|
* @param boolean $recent sort by most recent or not
|
||||||
|
* @param integer $limit limit the number of result
|
||||||
|
*
|
||||||
|
* @return array(Post)
|
||||||
|
*/
|
||||||
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* get a specific Post
|
||||||
|
*
|
||||||
|
* @param integer $id the id
|
||||||
|
*
|
||||||
|
* @return Post
|
||||||
|
*/
|
||||||
|
public static function get(int $id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a post to the db
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function add(Post $post) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove the post
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function remove(Post $post) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the post data on the db
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function update(Post $post) {}
|
||||||
|
}
|
57
project/assets/php/db/Tag.php
Normal file
57
project/assets/php/db/Tag.php
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
<?php
|
||||||
|
namespace App\DB;
|
||||||
|
|
||||||
|
class Tag {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* list of posts
|
||||||
|
*
|
||||||
|
* @param boolean $recent sort by most recent or not
|
||||||
|
* @param integer $limit limit the number of result
|
||||||
|
*
|
||||||
|
* @return array(Post)
|
||||||
|
*/
|
||||||
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
* get a specific Post
|
||||||
|
*
|
||||||
|
* @param integer $id the id
|
||||||
|
*
|
||||||
|
* @return Post
|
||||||
|
*/
|
||||||
|
public static function get(int $id) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* add a post to the db
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function add(Post $post) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* remove the post
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
public static function remove(Post $post) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the post data on the db
|
||||||
|
*
|
||||||
|
* @param Post $post
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public static function update(Post $post) {}
|
||||||
|
}
|
@ -1,27 +0,0 @@
|
|||||||
<?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);
|
|
||||||
}
|
|
||||||
|
|
||||||
function connect() {
|
|
||||||
$host = "127.0.0.1";
|
|
||||||
$db = "blog";
|
|
||||||
$user = "blog";
|
|
||||||
$pass = "blog";
|
|
||||||
$charset="utf8mb4";
|
|
||||||
|
|
||||||
$dsn = "mysql:host=$host;dbname=$db;charset=$charset";
|
|
||||||
try {
|
|
||||||
$pdo = new PDO($dsn, $user, $pass);
|
|
||||||
} catch (\PDOException $e) {
|
|
||||||
throw new \PDOException($e->getMessage(), (int)$e->getCode());
|
|
||||||
}
|
|
||||||
return $pdo;
|
|
||||||
}
|
|
@ -1,17 +1,21 @@
|
|||||||
<?php
|
<?php
|
||||||
require_once "functions.php";
|
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 'On');
|
ini_set('display_errors', 'On');
|
||||||
|
|
||||||
|
require_once "../../../vendor/autoload.php";
|
||||||
|
|
||||||
|
use App\Router;
|
||||||
|
use App\Functions;
|
||||||
|
use App\Tags\Tag;
|
||||||
|
|
||||||
//renvoie vers le fichier css si il est demandé
|
//renvoie vers le fichier css si il est demandé
|
||||||
if(endsWith($_GET["page"], ".css")) {
|
if(Functions::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é
|
//renvoie vers le fichier js si demandé
|
||||||
if(endsWith($_GET["page"], ".js")) {
|
if(Functions::endsWith($_GET["page"], ".js")) {
|
||||||
echo file_get_contents("../js/script.js");
|
echo file_get_contents("../js/script.js");
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
@ -19,7 +23,7 @@ if(endsWith($_GET["page"], ".js")) {
|
|||||||
// var_dump(sizeof($_GET));
|
// var_dump(sizeof($_GET));
|
||||||
|
|
||||||
// si page non / & finit pas par / at pas de ?
|
// si page non / & finit pas par / at pas de ?
|
||||||
if($_GET["page"] != "" && !endsWith($_GET["page"], "/") && sizeof($_GET) <= 1) {
|
if($_GET["page"] != "" && !Functions::endsWith($_GET["page"], "/") && count($_GET) <= 1) {
|
||||||
header("Location: /".$_GET["page"]."/");
|
header("Location: /".$_GET["page"]."/");
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
@ -28,7 +32,7 @@ if($_GET["page"] != "" && !endsWith($_GET["page"], "/") && sizeof($_GET) <= 1) {
|
|||||||
$_GET['page'] = trim($_GET['page'], '/');
|
$_GET['page'] = trim($_GET['page'], '/');
|
||||||
|
|
||||||
// si taille supérieur à 1 $_getpost = element
|
// si taille supérieur à 1 $_getpost = element
|
||||||
if(sizeof(explode("/", $_GET["page"])) > 1) {
|
if(count(explode("/", $_GET["page"])) > 1) {
|
||||||
$_GET["post"] = explode("/", $_GET["page"])[1];
|
$_GET["post"] = explode("/", $_GET["page"])[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -46,7 +50,7 @@ if(strlen($_GET['page']) > 1) {
|
|||||||
// A ENLEVER LORS DES COMMITS DE FIN
|
// A ENLEVER LORS DES COMMITS DE FIN
|
||||||
// var_dump($_GET);
|
// var_dump($_GET);
|
||||||
if($_GET["page"] == "/test/") {
|
if($_GET["page"] == "/test/") {
|
||||||
include_once "test.php";
|
require_once "test.php";
|
||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -54,13 +58,14 @@ if($_GET["page"] == "/test/") {
|
|||||||
* Démarrage du routage du contenu
|
* Démarrage du routage du contenu
|
||||||
*/
|
*/
|
||||||
|
|
||||||
include_once "router.php";
|
|
||||||
$router = new Router();
|
$router = new Router();
|
||||||
include_once "pages.php";
|
|
||||||
|
Functions::loadRoutes();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
//chargement des tags contenu sur la page
|
//chargement des tags contenu sur la page
|
||||||
include_once "tagHandler.php";
|
|
||||||
$pokemon = loadTags($router->search($_GET["page"])(), false);
|
$pokemon = Tag::loadTags($router->search($_GET["page"])(), false);
|
||||||
|
|
||||||
echo $pokemon;
|
echo $pokemon;
|
||||||
|
@ -1,81 +1,83 @@
|
|||||||
<?php
|
<?php
|
||||||
include_once "router.php";
|
// // include_once "router.php";
|
||||||
|
|
||||||
//recupération du router
|
// use App\Router;
|
||||||
$router = Router::getRouter();
|
|
||||||
|
|
||||||
$postCharacters = "[a-z0-9-]";
|
// //recupération du router
|
||||||
|
// $router = Router::getRouter();
|
||||||
|
|
||||||
//page d'accueil
|
// $postCharacters = "[a-z0-9-]";
|
||||||
$home = function () {
|
|
||||||
return file_get_contents("../html/index.html");
|
|
||||||
};
|
|
||||||
|
|
||||||
$router->addRoute("/^\/$/", $home); // route : "/"
|
// //page d'accueil
|
||||||
|
// $home = function () {
|
||||||
|
// return file_get_contents("../html/index.html");
|
||||||
|
// };
|
||||||
|
|
||||||
//page de post
|
// $router->addRoute("/^\/$/", $home); // route : "/"
|
||||||
$post = function () {
|
|
||||||
return file_get_contents("../html/post.html");
|
|
||||||
};
|
|
||||||
|
|
||||||
$router->addRoute("/^\/post\/" . $postCharacters . "+\/*$/", $post); // route "/post/*"
|
// //page de post
|
||||||
|
// $post = function () {
|
||||||
|
// return file_get_contents("../html/post.html");
|
||||||
|
// };
|
||||||
|
|
||||||
//page de recherche
|
// $router->addRoute("/^\/post\/" . $postCharacters . "+\/*$/", $post); // route "/post/*"
|
||||||
$search = function () {
|
|
||||||
return file_get_contents("../html/search.html");
|
|
||||||
};
|
|
||||||
|
|
||||||
$router->addRoute("/^\/search\/$/", $search); // route "/search/*"
|
// //page de recherche
|
||||||
|
// $search = function () {
|
||||||
|
// return file_get_contents("../html/search.html");
|
||||||
|
// };
|
||||||
|
|
||||||
$edit = function() {
|
// $router->addRoute("/^\/search\/$/", $search); // route "/search/*"
|
||||||
$_POST = array_merge($_POST, $_GET); //debug uniquement
|
|
||||||
var_dump($_POST);
|
|
||||||
/*
|
|
||||||
$_POST should contain
|
|
||||||
post :
|
|
||||||
id
|
|
||||||
title
|
|
||||||
content
|
|
||||||
category
|
|
||||||
author
|
|
||||||
|
|
||||||
UPDATE posts
|
// $edit = function() {
|
||||||
SET
|
// $_POST = array_merge($_POST, $_GET); //debug uniquement
|
||||||
title = title,
|
// var_dump($_POST);
|
||||||
url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], title));
|
// /*
|
||||||
content = content,
|
// $_POST should contain
|
||||||
short = substr(content, 0, 253) . "...";
|
// post :
|
||||||
category = categoryId
|
// id
|
||||||
author = authorId
|
// title
|
||||||
WHERE id = id
|
// content
|
||||||
*/
|
// category
|
||||||
|
// author
|
||||||
|
|
||||||
require_once "functions.php";
|
// UPDATE posts
|
||||||
|
// SET
|
||||||
|
// title = title,
|
||||||
|
// url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], title));
|
||||||
|
// content = content,
|
||||||
|
// short = substr(content, 0, 253) . "...";
|
||||||
|
// category = categoryId
|
||||||
|
// author = authorId
|
||||||
|
// WHERE id = id
|
||||||
|
// */
|
||||||
|
|
||||||
|
// require_once "functions.php";
|
||||||
|
|
||||||
|
|
||||||
$request = "UPDATE posts SET `title`=:title, `url`=:url, `content`=:content, `short`=:short, `category`=:category, `author`=:author, WHERE `id`=:id";
|
// $request = "UPDATE posts SET `title`=:title, `url`=:url, `content`=:content, `short`=:short, `category`=:category, `author`=:author, WHERE `id`=:id";
|
||||||
|
|
||||||
$title = $_POST["title"];
|
// $title = $_POST["title"];
|
||||||
$url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], $title));
|
// $url = strtolower(preg_replace(["/\ /", '/[\'\/~`\!@#\$%\^&\*\(\)\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/'], ["_", ""], $title));
|
||||||
$content = $_POST["content"];
|
// $content = $_POST["content"];
|
||||||
$short = substr($content, 0, 253) . "...";
|
// $short = substr($content, 0, 253) . "...";
|
||||||
$category = intval($_POST["category"]);
|
// $category = intval($_POST["category"]);
|
||||||
$author = intval($_POST["author"]);
|
// $author = intval($_POST["author"]);
|
||||||
|
|
||||||
$id = intval($_POST["id"]);
|
// $id = intval($_POST["id"]);
|
||||||
|
|
||||||
|
|
||||||
$pdo = connect();
|
// $pdo = connect();
|
||||||
$prepared = $pdo->prepare($request);
|
// $prepared = $pdo->prepare($request);
|
||||||
$prepared->bindParam(":title", $title);
|
// $prepared->bindParam(":title", $title);
|
||||||
$prepared->bindParam(":url", $url);
|
// $prepared->bindParam(":url", $url);
|
||||||
$prepared->bindParam(":content", $content);
|
// $prepared->bindParam(":content", $content);
|
||||||
$prepared->bindParam(":short", $short);
|
// $prepared->bindParam(":short", $short);
|
||||||
$prepared->bindParam(":category", $category, PDO::PARAM_INT);
|
// $prepared->bindParam(":category", $category, PDO::PARAM_INT);
|
||||||
$prepared->bindParam(":author", $author, PDO::PARAM_INT);
|
// $prepared->bindParam(":author", $author, PDO::PARAM_INT);
|
||||||
$prepared->bindParam(":id", $id, PDO::PARAM_INT);
|
// $prepared->bindParam(":id", $id, PDO::PARAM_INT);
|
||||||
|
|
||||||
$prepared->execute();
|
// $prepared->execute();
|
||||||
};
|
// };
|
||||||
|
|
||||||
$router->addRoute("/^\/post\/" . $postCharacters . "+\/edit\/*$/", $edit);
|
// $router->addRoute("/^\/post\/" . $postCharacters . "+\/edit\/*$/", $edit);
|
||||||
|
@ -1,295 +0,0 @@
|
|||||||
<?php
|
|
||||||
|
|
||||||
class Tag {
|
|
||||||
|
|
||||||
private $DOM;
|
|
||||||
private $doc;
|
|
||||||
private $debug;
|
|
||||||
|
|
||||||
public function __construct(DOMDocument $doc, DOMElement $DOMContent, bool $debug) {
|
|
||||||
$this->doc = $doc;
|
|
||||||
$this->DOM = $DOMContent;
|
|
||||||
$this->debug = $debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDoc() {
|
|
||||||
return $this->doc;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getDOM() {
|
|
||||||
return $this->DOM;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function isDebugging() {
|
|
||||||
return $this->debug;
|
|
||||||
}
|
|
||||||
|
|
||||||
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>
|
|
||||||
*/
|
|
||||||
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<63>ation de balises
|
|
||||||
$doc = $this->getDoc();
|
|
||||||
//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);
|
|
||||||
//rajout dans la balise span notre texte
|
|
||||||
$res->appendChild($text);
|
|
||||||
//on rajoute a la balise span du style pour le mettre en gras
|
|
||||||
$res->setAttribute("style", "font-weight: bold");
|
|
||||||
//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'=> "pokemongo",
|
|
||||||
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
|
||||||
);
|
|
||||||
|
|
||||||
$pok = $this->getDOM();
|
|
||||||
$attr = $pok->getAttribute("column");
|
|
||||||
|
|
||||||
$doc = $this->getDoc();
|
|
||||||
|
|
||||||
$parent = $pok->parentNode;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if($attr == "content") {
|
|
||||||
appendHTML($pok->parentNode, $post[$attr]);
|
|
||||||
} else {
|
|
||||||
$txt = $doc->createTextNode($post[$attr]);
|
|
||||||
$pok->parentNode->insertBefore($txt, $pok);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* input
|
|
||||||
* <tag type="isloggedin">
|
|
||||||
* <if true>
|
|
||||||
*
|
|
||||||
* </if>
|
|
||||||
* <if false>
|
|
||||||
*
|
|
||||||
* </if>
|
|
||||||
* </tag>
|
|
||||||
*/
|
|
||||||
class IsLoggedIn extends Tag {
|
|
||||||
public function render() {
|
|
||||||
|
|
||||||
$el = $this->getDOM();
|
|
||||||
|
|
||||||
//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);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* input <tag type="author" column="(column name)"/>
|
|
||||||
* return text
|
|
||||||
*/
|
|
||||||
class Author extends Tag {
|
|
||||||
public function render() {
|
|
||||||
|
|
||||||
$post = array( //testing purpose
|
|
||||||
'name'=> "test",
|
|
||||||
'image'=> "pokemon",
|
|
||||||
'linkedin'=> "pouet"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$pok = $this->getDOM();
|
|
||||||
$attr = $pok->getAttribute("column");
|
|
||||||
|
|
||||||
$doc = $this->getDoc();
|
|
||||||
|
|
||||||
$txt = $doc->createTextNode($post[$attr]);
|
|
||||||
|
|
||||||
$pok->parentNode->insertBefore($txt, $pok);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
$attr = $el->getAttribute("file");
|
|
||||||
|
|
||||||
$p = file_get_contents("../html/includes/".$attr.".html");
|
|
||||||
|
|
||||||
// var_dump($p);
|
|
||||||
appendHTML($el->parentNode, $p);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* input <tag type="svg" style="color: white; width: 18px; height: 18px""/>
|
|
||||||
*/
|
|
||||||
class Svg extends Tag {
|
|
||||||
public function render() {
|
|
||||||
$el = $this->getDOM();
|
|
||||||
$attr = $el->getAttribute("file");
|
|
||||||
$t = $this->getDoc()->createDocumentFragment();
|
|
||||||
$p = file_get_contents("../img/".$attr.".svg");
|
|
||||||
appendHTML($el->parentNode, $p);
|
|
||||||
$el->nextSibling->setAttribute("style", $el->getAttribute("style"));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* input
|
|
||||||
* <tag type="loop" for="(table)" limit="(nombre-max g<>n<EFBFBD>r<EFBFBD>)">
|
|
||||||
* <loop column="element"/>
|
|
||||||
* </tag>
|
|
||||||
* return something
|
|
||||||
*/
|
|
||||||
class Loop extends Tag {
|
|
||||||
public function render() {
|
|
||||||
$el = $this->getDOM();
|
|
||||||
|
|
||||||
$doc = $this->getDoc();
|
|
||||||
|
|
||||||
$limit = (int) $el->getAttribute("limit");
|
|
||||||
|
|
||||||
require_once 'functions.php';
|
|
||||||
|
|
||||||
$pdo = connect();
|
|
||||||
$query = $pdo->query("SELECT title, categories.name as categorie, dt as date, short as content
|
|
||||||
FROM posts
|
|
||||||
INNER JOIN categories ON categories.id=posts.categorie
|
|
||||||
ORDER BY date DESC
|
|
||||||
LIMIT 6;");
|
|
||||||
$posts = $query->fetchAll();
|
|
||||||
|
|
||||||
$parent = $el->parentNode;
|
|
||||||
//var_dump($parent);
|
|
||||||
|
|
||||||
|
|
||||||
$limit = $limit > sizeof($posts) ? sizeof($posts) : $limit;
|
|
||||||
|
|
||||||
for ($i=0; $i < $limit; $i++) {
|
|
||||||
//var_dump($i);
|
|
||||||
$pok = $el->childNodes->item(0)->cloneNode(true);
|
|
||||||
|
|
||||||
$parent->insertBefore($pok, $el);
|
|
||||||
|
|
||||||
$elements = $pok->getElementsByTagName("loop");
|
|
||||||
|
|
||||||
foreach ($elements as $ele) {
|
|
||||||
if($ele->getAttribute("column") == "content") {
|
|
||||||
appendHTML($ele->parentNode, $posts[$i]["content"]);
|
|
||||||
} else {
|
|
||||||
$txt = $doc->createTextNode($posts[$i][$ele->getAttribute("column")]);
|
|
||||||
$ele->parentNode->insertBefore($txt, $ele);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
$finder = new DomXPath($doc);
|
|
||||||
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
|
|
||||||
// var_dump($nodes);
|
|
||||||
if(sizeof($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-categorie", $posts[$i]["categorie"], $nodes[0]->getAttribute("class")));
|
|
||||||
|
|
||||||
$loop = $pok->getElementsByTagName("loop");
|
|
||||||
|
|
||||||
while ($loop->count() >= 1) {
|
|
||||||
$loop->item(0)->parentNode->removeChild($loop->item(0));
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
//function qui ajoute du html dans la node
|
|
||||||
function appendHTML(DOMNode $parent, $source) {
|
|
||||||
$tmpDoc = new DOMDocument();
|
|
||||||
$html = "<html><body>";
|
|
||||||
$html .= $source;
|
|
||||||
$html .= "</body></html>";
|
|
||||||
$tmpDoc->loadHTML('<?xml encoding="UTF-8">'.$html);
|
|
||||||
|
|
||||||
foreach ($tmpDoc->childNodes as $item)
|
|
||||||
if ($item->nodeType == XML_PI_NODE)
|
|
||||||
$tmpDoc->removeChild($item);
|
|
||||||
$tmpDoc->encoding = 'UTF-8';
|
|
||||||
|
|
||||||
foreach ($tmpDoc->getElementsByTagName('body')->item(0)->childNodes as $node) {
|
|
||||||
$importedNode = $parent->ownerDocument->importNode($node, true);
|
|
||||||
$parent->appendChild($importedNode);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// function de gestion
|
|
||||||
function loadTags($ctnt) {
|
|
||||||
$dom = new DOMDocument();
|
|
||||||
libxml_use_internal_errors(true);
|
|
||||||
$dom->loadHTML('<?xml encoding="UTF-8">'.$ctnt);
|
|
||||||
libxml_clear_errors();
|
|
||||||
|
|
||||||
// fix UTF-8 problem
|
|
||||||
foreach ($dom->childNodes as $item)
|
|
||||||
if ($item->nodeType == XML_PI_NODE)
|
|
||||||
$dom->removeChild($item);
|
|
||||||
$dom->encoding = 'UTF-8';
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$head = $dom->getElementsByTagName("head");
|
|
||||||
if($head->count() >= 1) {
|
|
||||||
$t = $dom->createDocumentFragment();
|
|
||||||
$p = file_get_contents("../html/includes/head.html");
|
|
||||||
$t->appendXML($p);
|
|
||||||
$head->item(0)->appendChild($t);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
$list = $dom->getElementsByTagName("tag");
|
|
||||||
|
|
||||||
//charge et supprimme les tags
|
|
||||||
while($lst = $list->item(0)) {
|
|
||||||
|
|
||||||
$tgs = ucfirst($lst->getAttribute("type"));
|
|
||||||
$tg = new $tgs($dom, $lst, false);
|
|
||||||
|
|
||||||
$tg->render();
|
|
||||||
|
|
||||||
$lst->parentNode->removeChild($lst);
|
|
||||||
|
|
||||||
$list = $dom->getElementsByTagName("tag");
|
|
||||||
}
|
|
||||||
|
|
||||||
$res = $dom->saveHTML();
|
|
||||||
|
|
||||||
return $res;
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user