mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 02:42:13 +00:00
plein de modifs :O
This commit is contained in:
parent
c2e310e5d9
commit
1800118247
@ -24,7 +24,7 @@ RewriteCond %{REQUEST_FILENAME} !-f
|
||||
# on redirige vers le fichier handler.php avec $1 qui est la page entré (ex: blog/1/2)
|
||||
# le L con connait déjà, QSA va mettre toutes les requetes a la suite
|
||||
# (ex : blog.delta-wings.net/flag?p=5 va devenir de notre coté -> blog.delta-wings.net/assets/php/handler.php?page=flag&p=5)
|
||||
RewriteRule ^(.*)$ /assets/php/handler.php?page=$1 [L,QSA]
|
||||
RewriteRule ^(.*)$ /assets/php/handler.php?page=$1 [QSA,L]
|
||||
|
||||
# indique une redirection lorque on obtient une page d'erreur 403 (interdiction d'accès (permet de "cacher" les fichiers critiques))
|
||||
# on redirige vars note handler pour qu'il afficher la page 404
|
||||
|
@ -744,3 +744,15 @@ input {
|
||||
height: 650px;
|
||||
}
|
||||
}
|
||||
|
||||
form.login > input {
|
||||
text-align: center;
|
||||
display: block;
|
||||
margin: auto;
|
||||
}
|
||||
|
||||
form.login >input[type="submit"] {
|
||||
left: -46%;
|
||||
position: relative;
|
||||
margin-top: 10px;
|
||||
}
|
||||
|
@ -4,13 +4,14 @@
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>404</p>
|
||||
</body>
|
||||
<header>
|
||||
<tag type="includes" file="header" />
|
||||
</header>
|
||||
<h1 style="font-size:xx-large">Error 404</h1>
|
||||
|
||||
<footer>
|
||||
<tag type="includes" file="footer" />
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
||||
|
@ -12,6 +12,9 @@
|
||||
<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 link" style="float: left">
|
||||
<tag type="user" />
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
36
assets/html/login.html
Normal file
36
assets/html/login.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<tag type="includes" file="header" />
|
||||
</header>
|
||||
<main class="test container">
|
||||
<div class="bloc_principal">
|
||||
<div class="cover-black">
|
||||
<div class="bloc_principal_titre">
|
||||
<h1>LE BLOG DES APPRENANTS</h1>
|
||||
</div>
|
||||
<div class="cover-text">
|
||||
<h2 id="titre-home">Merci de bien vouloir vous connecter pour continuer</h2>
|
||||
<div class="p-home">
|
||||
<form name="login" id="name" method="POST" class="login" action="/login/">
|
||||
<input name="username" id="username" type="text" placeholder="username" />
|
||||
<input name="password" id="password" type="password" placeholder="password" />
|
||||
|
||||
<input type="submit" class="bloc-plus" value="Login"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
<tag type="includes" file="footer" />
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -10,7 +10,7 @@
|
||||
</header>
|
||||
<main class="test container">
|
||||
<div class="bloc-post">
|
||||
<div class="container-post post column-cat">
|
||||
<div class="container-post post article-cat">
|
||||
<h2 class="title"><tag type="article" column="title" /></h2>
|
||||
<div class="etiquettes">
|
||||
<span class="cat"><tag type="article" column="category"/></span>
|
||||
@ -51,7 +51,7 @@
|
||||
|
||||
<h3 id="titre-between">Dans le même thème</h3>
|
||||
<div class="row articles">
|
||||
<tag type="loop" for="posts" limit="6" category="true">
|
||||
<tag type="loop" limit="6" category="true">
|
||||
<a class="col-12 col-md-6 col-lg-4 column-link">
|
||||
<div class="article column-category">
|
||||
<h4 class="title">
|
||||
|
@ -11,67 +11,29 @@
|
||||
<main class="test container">
|
||||
<div class="bloc-post">
|
||||
<div class="container-post post column-cat">
|
||||
<h2 class="title"><tag type="article" column="title" /></h2>
|
||||
<h2 class="title">
|
||||
<tag type="editor" element="title"/>
|
||||
</h2>
|
||||
<div class="etiquettes">
|
||||
<span class="cat"><tag type="article" column="category"/></span>
|
||||
<span class="date"><tag type="article" column="datetime"/></span>
|
||||
<span class="cat"><select>
|
||||
<tag type="editor" element="categories"/>
|
||||
</select></span>
|
||||
<span class="date">
|
||||
<tag type="editor" element="datetime"/>
|
||||
</span>
|
||||
</div>
|
||||
<p class="post text">
|
||||
<tag type="article" column="content"/>
|
||||
<tag type="editor" element="content"/>
|
||||
</p>
|
||||
</div>
|
||||
<div class="credit">
|
||||
<h3>Auteur</h3>
|
||||
<div class="author">
|
||||
<a>
|
||||
<tag type="svg" file="avatar" style="color: white; height: 64px" /></a>
|
||||
<div class="by">
|
||||
<h3 class="name"><tag type="authorTag" column="username" /></h3>
|
||||
<h3 class="job"><tag type="authorTag" column="job" /></h3>
|
||||
</div>
|
||||
</div>
|
||||
<button class="bloc-plus submitPost">
|
||||
Créer
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bloc-filter">
|
||||
<h3>Plus d'articles</h3>
|
||||
<p class="title-small">Catégories</p>
|
||||
<div class="filtre dev-color">dev</div>
|
||||
<div class="filtre digi-color">digi</div>
|
||||
<div class="filtre ops-color">ops</div>
|
||||
<div class="filtre devops-color">devops</div>
|
||||
<p class="title-small">Tags</p>
|
||||
<tag type="tags" />
|
||||
</div>
|
||||
|
||||
<div class="bloc-recent">
|
||||
<div class="contenue-recent">Article précédent</div>
|
||||
<div class="contenue-recent next">Article suivant</div>
|
||||
</div>
|
||||
|
||||
<h3 id="titre-between">Dans le même thème</h3>
|
||||
<div class="row articles">
|
||||
<tag type="loop" for="posts" limit="6" category="true">
|
||||
<a class="col-12 col-md-6 col-lg-4 column-link">
|
||||
<div class="article column-category">
|
||||
<h4 class="title">
|
||||
<loop column="title" />
|
||||
</h4>
|
||||
<div class="etiquettes">
|
||||
<span class="cat">
|
||||
<loop column="category" />
|
||||
</span>
|
||||
<span class="date">
|
||||
<loop column="datetime" />
|
||||
</span>
|
||||
</div>
|
||||
<div class="text">
|
||||
<loop column="content" />
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
</tag>
|
||||
<p class="title-small">Tags</p>
|
||||
<tag type="editor" element="tags" />
|
||||
</div>
|
||||
</main>
|
||||
</body>
|
||||
|
36
assets/html/register.html
Normal file
36
assets/html/register.html
Normal file
@ -0,0 +1,36 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="fr">
|
||||
|
||||
<head>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<tag type="includes" file="header" />
|
||||
</header>
|
||||
<main class="test container">
|
||||
<div class="bloc_principal">
|
||||
<div class="cover-black">
|
||||
<div class="bloc_principal_titre">
|
||||
<h1>LE BLOG DES APPRENANTS</h1>
|
||||
</div>
|
||||
<div class="cover-text">
|
||||
<h2 id="titre-home">Mercie de bien vous enregistrer chez nous</h2>
|
||||
<div class="p-home">
|
||||
<form name="login" id="name" method="POST" class="login" action="/register/">
|
||||
<input name="username" id="username" type="text" placeholder="username" />
|
||||
<input name="password" id="password" type="password" placeholder="password" />
|
||||
|
||||
<input type="submit" class="bloc-plus" value="Login"/>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
<footer>
|
||||
<tag type="includes" file="footer" />
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
@ -22,20 +22,24 @@
|
||||
<!-- <tag type="search" /> -->
|
||||
<div class="bloc-post search">
|
||||
<tag type="loop" limit="20">
|
||||
<div class="container-post post column-category">
|
||||
<h2 class="title">
|
||||
<loop column="title" />
|
||||
</h2>
|
||||
<div class="etiquettes">
|
||||
<span class="cat">
|
||||
<loop column="category" /></span>
|
||||
<span class="date">
|
||||
<loop column="dateTime" /></span>
|
||||
<a class="column-link">
|
||||
<div class="container-post post column-category">
|
||||
<h2 class="title">
|
||||
<loop column="title" />
|
||||
</h2>
|
||||
<div class="etiquettes">
|
||||
<span class="cat">
|
||||
<loop column="category" />
|
||||
</span>
|
||||
<span class="date">
|
||||
<loop column="dateTime" />
|
||||
</span>
|
||||
</div>
|
||||
<p class="post text">
|
||||
<loop column="content" />
|
||||
</p>
|
||||
</div>
|
||||
<p class="post text">
|
||||
<loop column="content" />
|
||||
</p>
|
||||
</div>
|
||||
</a>
|
||||
</tag>
|
||||
</div>
|
||||
|
||||
|
@ -22,12 +22,7 @@ var addTag = (element) => {
|
||||
cancelBtn.classList.add("cancelBtn");
|
||||
|
||||
cancelBtn.innerText = "Annuler";
|
||||
cancelBtn.addEventListener("click", function(element) {
|
||||
var input = element.target.parentElement.querySelector(".add-tag");
|
||||
input.parentElement.querySelector(".addTag").innerText = "Add Tag";
|
||||
input.parentElement.removeChild(input);
|
||||
element.target.parentElement.removeChild(element.target);
|
||||
});
|
||||
cancelBtn.addEventListener("click", cancel);
|
||||
|
||||
btn.removeEventListener("click", addTag);
|
||||
btn.addEventListener("click", addingTag);
|
||||
@ -39,6 +34,16 @@ var addTag = (element) => {
|
||||
|
||||
}
|
||||
|
||||
var cancel = (element) => {
|
||||
var input = element.target.parentElement.querySelector(".add-tag");
|
||||
var btn = input.parentElement.querySelector(".addTag");
|
||||
btn.removeEventListener("click", addingTag);
|
||||
btn.addEventListener("click", addTag);
|
||||
btn.innerText = "Add Tag";
|
||||
input.parentElement.removeChild(input);
|
||||
element.target.parentElement.removeChild(element.target);
|
||||
}
|
||||
|
||||
var addingTag = (element) => {
|
||||
var input = document.createElement("input");
|
||||
var uuid = Math.floor(Math.random() * Math.floor(-1000000));
|
||||
@ -64,10 +69,7 @@ var addingTag = (element) => {
|
||||
element.target.addEventListener("click", addTag);
|
||||
}
|
||||
|
||||
document.querySelector(".addTag").addEventListener("click", addTag);
|
||||
|
||||
|
||||
var submit = (el) => {
|
||||
var submit = () => {
|
||||
|
||||
var major = document.querySelector('.post.text > textarea');
|
||||
var title = document.querySelector("h2.title > input");
|
||||
@ -79,7 +81,7 @@ var submit = (el) => {
|
||||
console.log(tags);
|
||||
var tglst = "";
|
||||
tags.forEach(element => {
|
||||
tglst += "," + element.getAttribute("id") + (element.hasAttribute("data-text") ? ":" + element.getAttribute("data-text") : "");
|
||||
tglst += "," + element.getAttribute("data-text");
|
||||
});
|
||||
tglst = tglst.substr(1);
|
||||
|
||||
@ -89,4 +91,7 @@ var submit = (el) => {
|
||||
|
||||
}
|
||||
|
||||
document.querySelector(".submitPost").addEventListener("click", submit);
|
||||
if(document.querySelector(".addTag") != null) {
|
||||
document.querySelector(".addTag").addEventListener("click", addTag);
|
||||
document.querySelector(".submitPost").addEventListener("click", submit);
|
||||
}
|
||||
|
@ -34,15 +34,25 @@ class Controller {
|
||||
$arr = preg_split("/ /", $annot);
|
||||
if($arr[0] === "route") {
|
||||
if(preg_match($arr[1], $route)) {
|
||||
$cl = $class;
|
||||
$instance = new $class();
|
||||
$function = ($method->getName());
|
||||
return $instance->$function();
|
||||
// return $instance->$function();
|
||||
}
|
||||
} elseif ($arr[0] === "editor" && isset($cl) && $cl == $class) {
|
||||
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_EDITOR")) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]);
|
||||
} elseif($arr[0] === "admin" && isset($cl) && $cl ==$class) {
|
||||
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && $_SESSION["author"]->getRole() != "ROLE_ADMIN")) header("Location: /login/?redirect=".$_SERVER["REQUEST_URI"]);
|
||||
}
|
||||
}
|
||||
if(isset($instance)) {
|
||||
return $instance->$function();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
return file_get_contents(DIR."/html/404.html");
|
||||
|
||||
}
|
||||
}
|
||||
|
78
assets/php/Controller/AddEditController.php
Normal file
78
assets/php/Controller/AddEditController.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller;
|
||||
use App\DB\Post;
|
||||
use App\DB\Tag;
|
||||
|
||||
|
||||
class AddEditController extends Controller {
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/edit\/$/
|
||||
* @editor
|
||||
*/
|
||||
public function postEdit() {
|
||||
if(isset($_GET["post"]) && isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
$post = Post::get($_GET["post"]);
|
||||
|
||||
$post->setTitle($_GET["title"]);
|
||||
$post->setContent($_GET["content"]);
|
||||
$post->setCategory($_GET["category"]);
|
||||
|
||||
$tags = explode(",", $_GET["tags"]);
|
||||
$tgs = array();
|
||||
foreach ($tags as $tag) {
|
||||
var_dump($tag);
|
||||
var_dump(Tag::getByName($tag));
|
||||
if(!(Tag::getByName($tag))) {
|
||||
$tgs[] = Tag::add((new Tag())->setName($tag))->getId();
|
||||
} else {
|
||||
$tgs[] = Tag::getByName($tag)->getId();
|
||||
}
|
||||
}
|
||||
|
||||
$post->setTags($tgs);
|
||||
$post->setAuthor($_SESSION["author"]->getId());
|
||||
Post::update($post);
|
||||
}
|
||||
return file_get_contents(DIR."/html/post_edit.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/new\/*$/
|
||||
* @editor
|
||||
*/
|
||||
public function postAdd() {
|
||||
|
||||
// var_dump($_SESSION["author"]);
|
||||
// die;
|
||||
|
||||
if(isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
$post = new Post();
|
||||
|
||||
$post->setTitle($_GET["title"]);
|
||||
$post->setContent($_GET["content"]);
|
||||
$post->setCategory($_GET["category"]);
|
||||
// $post->setAuthor();
|
||||
$tags = explode(",", $_GET["tags"]);
|
||||
$tgs = array();
|
||||
foreach ($tags as $tag) {
|
||||
var_dump($tag);
|
||||
var_dump(Tag::getByName($tag));
|
||||
if(!(Tag::getByName($tag))) {
|
||||
$tgs[] = Tag::add((new Tag())->setName($tag))->getId();
|
||||
} else {
|
||||
$tgs[] = Tag::getByName($tag)->getId();
|
||||
}
|
||||
}
|
||||
// var_dump($tgs);
|
||||
// die;
|
||||
$post->setTags($tgs);
|
||||
$post->setAuthor($_SESSION["author"]->getId());
|
||||
Post::add($post);
|
||||
}
|
||||
|
||||
return file_get_contents(DIR."/html/post_new.html");
|
||||
}
|
||||
}
|
@ -17,58 +17,12 @@ class HomeController extends Controller {
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/new\/*$/
|
||||
*/
|
||||
public function postAdd() {
|
||||
|
||||
// var_dump($_SESSION["author"]);
|
||||
// die;
|
||||
|
||||
if(isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
$post = new Post();
|
||||
|
||||
$post->setTitle($_GET["title"]);
|
||||
$post->setContent($_GET["content"]);
|
||||
$post->setCategory($_GET["category"]);
|
||||
// $post->setAuthor();
|
||||
$tags = explode(",", $_GET["tags"]);
|
||||
$tgs = array();
|
||||
foreach ($tags as $tag) {
|
||||
$new_tag = explode(":", $tag);
|
||||
if(count($new_tag) > 1) {
|
||||
$t = new Tag();
|
||||
$t->setName($new_tag[1]);
|
||||
$tgs[] = Tag::add($t)->getId();
|
||||
} else {
|
||||
$tgs[] = $tag;
|
||||
}
|
||||
}
|
||||
$post->setTags($tgs);
|
||||
$post->setAuthor($_SESSION["author"]->getId());
|
||||
Post::add($post);
|
||||
}
|
||||
|
||||
return file_get_contents(DIR."/html/post_new.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/[a-z0-9]+\/$/
|
||||
* @route /^\/post\/[0-9]+\/$/
|
||||
*/
|
||||
public function post() {
|
||||
return file_get_contents(DIR."/html/post.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/[a-z0-9]+\/edit\/$/
|
||||
*/
|
||||
public function postEdit() {
|
||||
return file_get_contents(DIR."/html/post_edit.html");
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* @route /^\/search\//
|
||||
*/
|
||||
|
54
assets/php/Controller/LoginController.php
Normal file
54
assets/php/Controller/LoginController.php
Normal file
@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
|
||||
use App\Controller;
|
||||
use App\DB\Author;
|
||||
|
||||
|
||||
class LoginController extends Controller {
|
||||
|
||||
|
||||
/**
|
||||
* @route /^\/login\/$/
|
||||
*/
|
||||
public function login() {
|
||||
|
||||
if(isset($_POST["username"]) && isset($_POST["password"])) {
|
||||
$user = Author::getByUsername($_POST["username"]);
|
||||
var_dump($user);
|
||||
if($user->checkPassword($_POST["password"])) {
|
||||
$_SESSION["author"] = $user;
|
||||
if(isset($_GET["redirect"])) header("Location: " . $_GET["redirect"]);
|
||||
header("Location: /");
|
||||
}
|
||||
else var_dump("login incorreect");
|
||||
}
|
||||
|
||||
return file_get_contents(DIR."/html/login.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/logout\/$/
|
||||
*/
|
||||
public function logout() {
|
||||
session_destroy();
|
||||
header("Location: /");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/register\/$/
|
||||
*/
|
||||
public function register() {
|
||||
if(isset($_POST["password"]) && isset($_POST["username"]) && Author::getByUsername($_POST["username"]) === null) {
|
||||
$user = new Author();
|
||||
$user->setUsername($_POST["username"]);
|
||||
$user->setPassword($_POST["password"]);
|
||||
$user = Author::add($user);
|
||||
$_SESSION["author"] = $user;
|
||||
header("Location: /");
|
||||
}
|
||||
return file_get_contents(DIR."/html/register.html");
|
||||
}
|
||||
|
||||
}
|
@ -32,7 +32,9 @@ class Article extends Tag {
|
||||
|
||||
Functions::appendHTML($pok->parentNode, $post->getContent());
|
||||
} elseif($attr == "category") {
|
||||
$txt = $doc->createTextNode($post->getCategory()->getName());
|
||||
if($post->getCategory() != null) $t = $post->getCategory()->getName();
|
||||
else $t = "";
|
||||
$txt = $doc->createTextNode($t);
|
||||
$pok->parentNode->insertBefore($txt, $pok);
|
||||
} else {
|
||||
$col = "get" . ucfirst($attr);
|
||||
@ -41,9 +43,14 @@ class Article extends Tag {
|
||||
}
|
||||
|
||||
$finder = new DomXPath($doc);
|
||||
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
|
||||
$nodes = $finder->query("//*[contains(@class, 'article-cat')]");
|
||||
|
||||
if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-cat", $post->getCategory()->getName() , $nodes[0]->getAttribute("class")));
|
||||
|
||||
|
||||
|
||||
if(count($nodes) >= 1) {
|
||||
if($post->getCategory() != null) $nodes[0]->setAttribute("class", str_replace("article-cat", $post->getCategory()->getName() , $nodes[0]->getAttribute("class")));
|
||||
else $nodes[0]->setAttribute("class", str_replace("article-cat", "", $nodes[0]->getAttribute("class")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,10 +5,13 @@ namespace App\Tags;
|
||||
use App\DB\Category;
|
||||
use DateTime;
|
||||
use App\DB\Tag;
|
||||
use App\DB\Post;
|
||||
|
||||
|
||||
class Editor extends \App\Tags\Tag {
|
||||
public function render() {
|
||||
if($_GET["post"] == "new") $_GET["post"] = null;
|
||||
else $post = Post::get($_GET["post"]);
|
||||
//recuperation de la balise de base (<tag type="bold">pouet</tag>)
|
||||
$pok = $this->getElement();
|
||||
//recuperation du document (necessaire a la création de balises
|
||||
@ -20,9 +23,9 @@ class Editor extends \App\Tags\Tag {
|
||||
case 'categories':
|
||||
$option = $doc->createElement("option");
|
||||
$text = $doc->createTextNode("Categorie");
|
||||
$option->setAttribute("value", "0");
|
||||
$option->setAttribute("value", "1");
|
||||
$option->setAttribute("disabled", "true");
|
||||
$option->setAttribute("selected", "selected");
|
||||
if(!isset($post)) $option->setAttribute("selected", "selected");
|
||||
$option->appendChild($text);
|
||||
$pok->parentNode->insertBefore($option, $pok);
|
||||
foreach (Category::list() as $cat) {
|
||||
@ -30,15 +33,18 @@ class Editor extends \App\Tags\Tag {
|
||||
$text = $doc->createTextNode($cat->getName());
|
||||
$option->appendChild($text);
|
||||
$option->setAttribute("value", $cat->getId());
|
||||
if(isset($post) && $post->getCategory()->getId() == $cat->getId()) $option->setAttribute("selected", "selected");
|
||||
$pok->parentNode->insertBefore($option, $pok);
|
||||
}
|
||||
break;
|
||||
case 'datetime':
|
||||
$dt = new DateTime();
|
||||
$pok->parentNode->insertBefore($doc->createTextNode($dt->format('d/m/Y H:i:s')), $pok);
|
||||
if(isset($post)) $txt = $post->getDateTime();
|
||||
else $txt = (new DateTime())->format('d/m/Y H:i:s');
|
||||
$pok->parentNode->insertBefore($doc->createTextNode($txt), $pok);
|
||||
break;
|
||||
case 'content':
|
||||
$tarea = $doc->createElement("textarea");
|
||||
if(isset($post)) $tarea->appendChild($doc->createTextNode($post->getContent()));
|
||||
$tarea->setAttribute("style", "width: 100%; min-height: 200px");
|
||||
$pok->parentNode->insertBefore($tarea, $pok);
|
||||
break;
|
||||
@ -46,6 +52,7 @@ class Editor extends \App\Tags\Tag {
|
||||
$input = $doc->createElement("input");
|
||||
$input->setAttribute("style", "width: 100%");
|
||||
$input->setAttribute("placeholder", "titre");
|
||||
if(isset($post)) $input->setAttribute("value", $post->getTitle());
|
||||
$pok->parentNode->insertBefore($input, $pok);
|
||||
break;
|
||||
case 'tags':
|
||||
@ -53,6 +60,10 @@ class Editor extends \App\Tags\Tag {
|
||||
$tg = $doc->createElement("input");
|
||||
$tg->setAttribute("id", $el->getId());
|
||||
$tg->setAttribute("type", "checkbox");
|
||||
$tg->setAttribute("data-text", $el->getName());
|
||||
if(isset($post)) {
|
||||
if(in_array($el, $post->getTags())) $tg->setAttribute("checked", "checked");
|
||||
}
|
||||
$txt = $doc->createElement("label");
|
||||
$txt->appendChild($doc->createTextNode($el->getName()));
|
||||
$txt->setAttribute("for", $el->getId());
|
||||
|
@ -25,25 +25,22 @@ class Loop extends Tag {
|
||||
|
||||
$isRecent = isset($_GET["recent"]) && $_GET["recent"] == "false" ? false : true;
|
||||
$category = isset($_GET["category"]) && intval($_GET["category"]) ? (int) $_GET["category"] : -1;
|
||||
$category = $el->getAttribute("category") != '' ? Post::get($_GET["post"])->getCategory()->getId() : $category;
|
||||
$tag = isset($_GET["tag"]) && intval($_GET["tag"]) ? (int) $_GET["tag"] : -1;
|
||||
|
||||
if($el->getAttribute("category") != '') {
|
||||
$posts = Post::listByCategory(Post::get($_GET["post"])->getCategory()->getId(), $isRecent, 6);
|
||||
$postsList = array();
|
||||
foreach ($posts as $post) {
|
||||
if($post->getId() != $_GET["post"]) $postsList[] = $post;
|
||||
}
|
||||
$posts = $postsList;
|
||||
} else {
|
||||
$posts = Post::list(true, 6);
|
||||
|
||||
}
|
||||
|
||||
if($category != -1) {
|
||||
$posts = Post::listByCategory($category, $isRecent, 20);
|
||||
$posts = Post::listByCategory($category, $isRecent, $limit);
|
||||
if(isset($_GET["post"])) {
|
||||
$postsList = array();
|
||||
foreach ($posts as $post) {
|
||||
if($post->getId() != $_GET["post"]) $postsList[] = $post;
|
||||
}
|
||||
$posts = $postsList;
|
||||
}
|
||||
} else {
|
||||
$posts = Post::list($isRecent, 10);
|
||||
$posts = Post::list($isRecent, $limit);
|
||||
}
|
||||
|
||||
if($tag != -1) {
|
||||
$tposts = array();
|
||||
foreach ($posts as $post) {
|
||||
@ -68,9 +65,11 @@ class Loop extends Tag {
|
||||
|
||||
foreach ($elements as $ele) {
|
||||
if($ele->getAttribute("column") == "content") {
|
||||
Functions::appendHTML($ele->parentNode, $posts[$i]->getShort());
|
||||
Functions::appendHTML($ele->parentNode, substr($posts[$i]->getContent(), 0, 255));
|
||||
} elseif($ele->getAttribute("column") == "category") {
|
||||
$txt = $doc->createTextNode($posts[$i]->getCategory()->getName());
|
||||
// var_dump($posts[$i]->getCategory()->getName());
|
||||
if($posts[$i]->getCategory() != null) $txt = $doc->createTextNode($posts[$i]->getCategory()->getName());
|
||||
else $txt = $doc->createTextNode("no category");
|
||||
$ele->parentNode->insertBefore($txt, $ele);
|
||||
} else {
|
||||
$col = 'get' . ucfirst($ele->getAttribute("column"));
|
||||
@ -80,9 +79,12 @@ class Loop extends Tag {
|
||||
}
|
||||
|
||||
$finder = new DomXPath($doc);
|
||||
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
|
||||
$nodes = $finder->query("//*[contains(@class, 'column-category')]");
|
||||
|
||||
if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-category", $posts[$i]->getCategory()->getName() , $nodes[0]->getAttribute("class")));
|
||||
if(count($nodes) >= 1) {
|
||||
if($posts[$i]->getCategory() != null) $nodes[0]->setAttribute("class", str_replace("column-category", $posts[$i]->getCategory()->getName() , $nodes[0]->getAttribute("class")));
|
||||
else $nodes[0]->setAttribute("class", str_replace("column-category", "", $nodes[0]->getAttribute("class")));
|
||||
}
|
||||
|
||||
$nodes = $finder->query("//*[contains(@class, 'column-link')]");
|
||||
|
||||
|
10
assets/php/Tags/User.php
Normal file
10
assets/php/Tags/User.php
Normal file
@ -0,0 +1,10 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tags;
|
||||
|
||||
class User extends Tag {
|
||||
public function render() {
|
||||
$el = $this->getElement();
|
||||
if(isset($_SESSION["author"])) $el->parentNode->insertBefore($this->getDoc()->createTextNode($_SESSION["author"]->getId()), $el);
|
||||
}
|
||||
}
|
@ -14,6 +14,8 @@ class Author {
|
||||
|
||||
private $job;
|
||||
|
||||
private $role = "ROLE_USER";
|
||||
|
||||
public function __construct(){}
|
||||
|
||||
public function getId() {
|
||||
@ -36,6 +38,10 @@ class Author {
|
||||
return $this->job;
|
||||
}
|
||||
|
||||
public function getRole() {
|
||||
return $this->role;
|
||||
}
|
||||
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
}
|
||||
@ -45,13 +51,21 @@ class Author {
|
||||
}
|
||||
|
||||
public function setPassword($password) {
|
||||
$this->password = \password_hash($password, PASSWORD_DEFAULT);
|
||||
$this->password = password_hash($password, PASSWORD_DEFAULT);
|
||||
}
|
||||
|
||||
public function setHashedPassword($password) {
|
||||
$this->password = $password;
|
||||
}
|
||||
|
||||
public function setJob($job) {
|
||||
$this->job = $job;
|
||||
}
|
||||
|
||||
public function setRole($role) {
|
||||
$this->role = $role;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
@ -60,11 +74,13 @@ class Author {
|
||||
|
||||
|
||||
public static function fromArray($array) {
|
||||
if($array == false) return null;
|
||||
$au = new Self();
|
||||
$au->setId($array["id"]);
|
||||
$au->setUsername($array["username"]);
|
||||
$au->setPassword($array["password"]);
|
||||
$au->setHashedPassword($array["password"]);
|
||||
$au->setJob($array["job"]);
|
||||
$au->setRole($array["role"]);
|
||||
return $au;
|
||||
}
|
||||
|
||||
@ -88,16 +104,33 @@ class Author {
|
||||
return Author::fromArray(Functions::connect()->query("SELECT * FROM users WHERE id=" . $id)->fetch());
|
||||
}
|
||||
|
||||
public static function getByUsername(String $username) {
|
||||
$query = "SELECT * FROM users WHERE username=:username";
|
||||
$prepared = Functions::connect()->prepare($query);
|
||||
$prepared->bindValue(":username", $username);
|
||||
$prepared->execute();
|
||||
return Author::fromArray($prepared->fetch());
|
||||
}
|
||||
|
||||
public static function add(Author $author) {
|
||||
$query = "INSERT INTO author (id, username, password, job)
|
||||
VALUES (NULL, ':username', ':password', ':job');";
|
||||
$query = "INSERT INTO users (id, username, password, job, role)
|
||||
VALUES (NULL, :username, :password, :job, :role);";
|
||||
|
||||
$username = $author->getUsername();
|
||||
$password = $author->getPassword();
|
||||
$job = $author->getJob();
|
||||
$role = $author->getRole();
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$prepared = $pdo->prepare($query);
|
||||
$prepared->bindParam(":username", $author->getUsername());
|
||||
$prepared->bindParam(":password", $author->getPassword());
|
||||
$prepared->bindParam(":job", $author->getjob());
|
||||
$prepared->bindParam(":username", $username);
|
||||
$prepared->bindParam(":password", $password);
|
||||
$prepared->bindParam(":job", $job);
|
||||
$prepared->bindParam(":role", $role);
|
||||
$prepared->execute();
|
||||
// var_dump($prepared->errorInfo());
|
||||
// die;
|
||||
return Author::list(true, 1)[0];
|
||||
}
|
||||
|
||||
public static function remove(Author $author) {
|
||||
|
@ -69,7 +69,8 @@ class Post {
|
||||
}
|
||||
|
||||
public function getCategory() {
|
||||
return Category::get($this->category);
|
||||
if($this->category != null) return Category::get($this->category);
|
||||
else return null;
|
||||
}
|
||||
|
||||
public function getAuthor() {
|
||||
@ -87,10 +88,14 @@ class Post {
|
||||
public function getTags() {
|
||||
$temp = array();
|
||||
if ($this->tags == null) return $temp;
|
||||
/** @var int $tag */
|
||||
foreach ($this->tags as $tag) {
|
||||
// var_dump($tag);
|
||||
// die;
|
||||
$temp[] = Tag::get($tag);
|
||||
}
|
||||
return $temp;
|
||||
// die;
|
||||
return array_unique($temp, SORT_REGULAR);
|
||||
}
|
||||
|
||||
|
||||
@ -129,7 +134,7 @@ class Post {
|
||||
* @param boolean $recent sort by most recent or not
|
||||
* @param integer $limit limit the number of result
|
||||
*
|
||||
* @return array(Post)
|
||||
* @return Post[]
|
||||
*/
|
||||
|
||||
public static function list($recent = true, $limit = 100) {
|
||||
@ -219,32 +224,42 @@ class Post {
|
||||
*
|
||||
*/
|
||||
public static function add(Post $post) {
|
||||
$query = "INSERT INTO posts (id, title, content, categorie, author, dt)
|
||||
VALUES (NULL, ':title', ':content', ':category', ':author', ':dt');";
|
||||
$query = "INSERT INTO posts (id, title, content, category, author, dt)
|
||||
VALUES (NULL, :title, :content, :category, :author, :dt);";
|
||||
|
||||
$title = $post->getTitle());
|
||||
$content = $post->getContent());
|
||||
$category = $post->getCategory()->getId(), PDO::PARAM_INT);
|
||||
$author = $post->getAuthor()->getId(), PDO::PARAM_INT);
|
||||
$dt = (new DateTime())->format("d/m/Y h:i:s"));
|
||||
$title = $post->getTitle();
|
||||
$content = $post->getContent();
|
||||
$category = $post->getCategory()->getId();
|
||||
$author = $post->getAuthor()->getId();
|
||||
$dt = (new DateTime())->format("d/m/Y h:i:s");
|
||||
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$prepared = $pdo->prepare($query);
|
||||
$prepared->bindParam(":title", $post->getTitle());
|
||||
$prepared->bindParam(":content", $post->getContent());
|
||||
$prepared->bindParam(":category", $post->getCategory()->getId(), PDO::PARAM_INT);
|
||||
$prepared->bindParam(":author", $post->getAuthor()->getId(), PDO::PARAM_INT);
|
||||
$prepared->bindParam(":dt", (new DateTime())->format("d/m/Y h:i:s"));
|
||||
$prepared->bindValue(":title", $title);
|
||||
$prepared->bindValue(":content", $content);
|
||||
$prepared->bindValue(":category", $category, PDO::PARAM_INT);
|
||||
$prepared->bindValue(":author", $author, PDO::PARAM_INT);
|
||||
$prepared->bindValue(":dt", $dt);
|
||||
|
||||
var_dump($prepared->execute(array(
|
||||
":title" => $post->getTitle(),
|
||||
":content" => $post->getContent(),
|
||||
":category" => $post->getCategory()->getId(),
|
||||
":author" => $post->getAuthor()->getId(),
|
||||
":dt" => (new DateTime())->format("d/m/Y h:i:s"),
|
||||
)));
|
||||
var_dump("t");
|
||||
$prepared->execute();
|
||||
|
||||
$p = Post::list(true, 1)[0]->getId();
|
||||
|
||||
$tags = $post->getTags();
|
||||
var_dump($tags);
|
||||
if(count($tags) >= 1) {
|
||||
$q = "INSERT INTO post_tag (post_id, tag) VALUES ( :post , :tag )";
|
||||
$prepared = $pdo->prepare($q);
|
||||
$prepared->bindValue(":post", $p);
|
||||
foreach ($tags as $tg) {
|
||||
$id = $tg->getId();
|
||||
$prepared->bindValue(":tag", $id);
|
||||
|
||||
$prepared->execute();
|
||||
}
|
||||
}
|
||||
// var_dump($prepared->errorInfo());
|
||||
|
||||
}
|
||||
|
||||
@ -272,14 +287,39 @@ class Post {
|
||||
*
|
||||
*/
|
||||
public static function update(Post $post) {
|
||||
Functions::connect()->prepare("UPDATE posts SET title=':title', content=':content', category=':category', author=':author', dt=':dt' WHERE id=:id")->execute(array(
|
||||
":title" => $post->getTitle(),
|
||||
":content" => $post->getContent(),
|
||||
":categorie" => $post->getCategorie(),
|
||||
":author" => $post->getAuthor(),
|
||||
":dt" => $post->getDt(),
|
||||
":id" => $post->getId()
|
||||
));
|
||||
|
||||
$title = $post->getTitle();
|
||||
$content = $post->getContent();
|
||||
$category = $post->getCategory()->getId();
|
||||
$author = $post->getAuthor()->getId();
|
||||
$dt = $post->getDateTime();
|
||||
$id = $post->getid();
|
||||
|
||||
$pdo = Functions::connect();
|
||||
|
||||
|
||||
$prepared = $pdo->prepare("UPDATE posts SET title=:title, content=:content, category=:category, author=:author, dt=:dt WHERE id=:id");
|
||||
$prepared->bindValue(":title", $title);
|
||||
$prepared->bindValue(":content", $content);
|
||||
$prepared->bindValue(":category", $category, PDO::PARAM_INT);
|
||||
$prepared->bindValue(":author", $author, PDO::PARAM_INT);
|
||||
$prepared->bindValue(":dt", $dt);
|
||||
$prepared->bindValue(":id", $id);
|
||||
$prepared->execute();
|
||||
|
||||
$tags = $post->getTags();
|
||||
if(count($tags) >= 1) {
|
||||
$pdo->exec("DELETE FROM post_tag WHERE post_id=" . $id);
|
||||
$q = "INSERT INTO post_tag (post_id, tag) VALUES ( :post , :tag )";
|
||||
$prepared = $pdo->prepare($q);
|
||||
$prepared->bindValue(":post", $id);
|
||||
foreach ($tags as $tg) {
|
||||
$id = $tg->getId();
|
||||
$prepared->bindValue(":tag", $id);
|
||||
|
||||
$prepared->execute();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class Tag {
|
||||
public function __construct() {}
|
||||
|
||||
public static function fromArray($array) {
|
||||
if($array == false) return false;
|
||||
$tag = new Tag();
|
||||
$tag->setId($array["id"]);
|
||||
$tag->setName($array["name"]);
|
||||
@ -27,7 +28,7 @@ class Tag {
|
||||
* @param boolean $recent sort by most recent of less recent
|
||||
* @param int $limit
|
||||
*
|
||||
* @return Categorie[]
|
||||
* @return Tag[]
|
||||
*/
|
||||
public static function list($recent = true, $limit = 100) {
|
||||
$sort = $recent ? "DESC" : "ASC";
|
||||
@ -49,6 +50,23 @@ class Tag {
|
||||
return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch());
|
||||
}
|
||||
|
||||
public static function getByName(String $name) {
|
||||
$query = "SELECT * FROM tag WHERE name=:name LIMIT 1";
|
||||
$prepared = Functions::connect()->prepare($query);
|
||||
$prepared->bindValue(":name", $name, PDO::PARAM_STR);
|
||||
// $prepared->fetch();
|
||||
// $q = Functions::connect()->query("SELECT * FROM tag WHERE name=\"" . $name . "\"");
|
||||
// if(!$q) return false;
|
||||
$prepared->execute();
|
||||
$res = $prepared->fetch(PDO::FETCH_ASSOC);
|
||||
// var_dump($res);
|
||||
return Tag::fromArray($res);
|
||||
// var_dump($name);
|
||||
// var_dump($prepared->fetch());
|
||||
// var_dump($prepared->errorCode());
|
||||
// die;
|
||||
}
|
||||
|
||||
/**
|
||||
* Undocumented function
|
||||
*
|
||||
@ -62,10 +80,11 @@ class Tag {
|
||||
|
||||
// var_dump($tag);
|
||||
|
||||
$name = $tag->getName();
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$prepared = $pdo->prepare($query);
|
||||
$prepared->execute(array(":name" => $tag->getName()));
|
||||
|
||||
$prepared->execute(array(":name" => $name));
|
||||
return Tag::list(true, 1)[0];
|
||||
}
|
||||
|
||||
@ -108,5 +127,6 @@ class Tag {
|
||||
}
|
||||
public function setId($id) {
|
||||
$this->id = $id;
|
||||
return $this;
|
||||
}
|
||||
}
|
||||
|
@ -6,7 +6,6 @@ use App\Tags\Tag;
|
||||
use App\Controller;
|
||||
use App\DB\Author;
|
||||
|
||||
session_start();
|
||||
|
||||
error_reporting(E_ALL);
|
||||
ini_set('display_errors', 'On');
|
||||
@ -14,7 +13,17 @@ ini_set('display_errors', 'On');
|
||||
/** @var Composer\Autoload\ClassLoader $loader */
|
||||
$loader = require "../../vendor/autoload.php";
|
||||
|
||||
$_SESSION["author"] = Author::list(true, 1)[0];
|
||||
// $_SESSION["author"] = Author::list(true, 1)[0];
|
||||
|
||||
$auth = new Author(); //chargement de la class Author avant le début de session (pour que la classe dans la session rester complète)
|
||||
|
||||
session_start();
|
||||
|
||||
if(isset($_SESSION["author"])) { //wip
|
||||
$_SESSION["author"] = Author::get($_SESSION["author"]->getId());
|
||||
}
|
||||
|
||||
// var_dump($_SESSION["author"]);
|
||||
|
||||
define("DIR", str_replace("/php", "", __DIR__));
|
||||
|
||||
|
BIN
favicon.ico
Normal file
BIN
favicon.ico
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
Loading…
x
Reference in New Issue
Block a user