mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 10:52:09 +00:00
changements
This commit is contained in:
parent
246ae7582a
commit
b339e09082
@ -131,7 +131,7 @@ gere la redirection des requetes et gere le cache de certains fichiers
|
|||||||
- sql
|
- sql
|
||||||
|
|
||||||
|
|
||||||
# Types de pages (pour design) :
|
# Types de pages (pour design)
|
||||||
|
|
||||||
- / (page ou post)
|
- / (page ou post)
|
||||||
- /page/
|
- /page/
|
||||||
|
@ -33,17 +33,17 @@
|
|||||||
<h3 id="titre-between">Articles récents</h3>
|
<h3 id="titre-between">Articles récents</h3>
|
||||||
<div class="row articles">
|
<div class="row articles">
|
||||||
<tag type="loop" for="posts" limit="6">
|
<tag type="loop" for="posts" limit="6">
|
||||||
<div class="col-12 col-md-6 col-lg-4">
|
<a class="col-12 col-md-6 col-lg-4 column-link">
|
||||||
<div class="article column-categorie">
|
<div class="article column-category">
|
||||||
<h4 class="title">
|
<h4 class="title">
|
||||||
<loop column="title" />
|
<loop column="title" />
|
||||||
</h4>
|
</h4>
|
||||||
<div class="etiquettes">
|
<div class="etiquettes">
|
||||||
<span class="cat">
|
<span class="cat">
|
||||||
<loop column="categorie" />
|
<loop column="category" />
|
||||||
</span>
|
</span>
|
||||||
<span class="date">
|
<span class="date">
|
||||||
<loop column="date" />
|
<loop column="dateTime" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
@ -51,7 +51,7 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
</tag>
|
</tag>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
@ -11,64 +11,37 @@
|
|||||||
<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"><tag type="article" column="title" /></h2>
|
||||||
<div class="etiquettes">
|
<div class="etiquettes">
|
||||||
<span class="cat">OPS</span>
|
<span class="cat"><tag type="article" column="category"/></span>
|
||||||
<span class="date">26-06-2018</span>
|
<span class="date"><tag type="article" column="datetime"/></span>
|
||||||
</div>
|
</div>
|
||||||
<p class="post text">Dum apud Persas, ut supra narravimus, perfidia regis motus agitat insperatos,
|
<p class="post text">
|
||||||
et in eois tractibus bella rediviva consurgunt, anno sexto decimo et eo diutius
|
<tag type="article" column="content"/>
|
||||||
post Nepotiani exitium, saeviens per urbem aeternam urebat cuncta Bellona, ex primordiis
|
|
||||||
<br>
|
|
||||||
<br>
|
|
||||||
Dum apud Persas, ut supra narravimus, perfidia regis motus agitat insperatos,
|
|
||||||
et in eois tractibus bella rediviva consurgunt, anno sexto decimo et eo diutius
|
|
||||||
post Nepotiani exitium, saeviens per urbem aeternam urebat cuncta Bellona, ex primordiis
|
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
<p class="post text">Dum apud Persas, ut supra narravimus, perfidia regis motus agitat insperatos,
|
<div class="credit">
|
||||||
et in eois tractibus bella rediviva consurgunt, anno sexto decimo et eo diutius
|
<h3>Auteur</h3>
|
||||||
post Nepotiani exitium, saeviens per urbem aeternam urebat cuncta Bellona, ex primordiis
|
<div class="author">
|
||||||
<br>
|
<a>
|
||||||
<br>
|
<tag type="svg" file="avatar" style="color: white; height: 64px" /></a>
|
||||||
Dum apud Persas, ut supra narravimus, perfidia regis motus agitat insperatos,
|
<div class="by">
|
||||||
et in eois tractibus bella rediviva consurgunt, anno sexto decimo et eo diutius
|
<h3 class="name"><tag type="authorTag" column="username" /></h3>
|
||||||
post Nepotiani exitium, saeviens per urbem aeternam urebat cuncta Bellona, ex primordiis
|
<h3 class="job"><tag type="authorTag" column="job" /></h3>
|
||||||
</p>
|
</div>
|
||||||
</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">Adrien Huchet</h3>
|
|
||||||
<h3 class="job">Apprenant IT START</h3>
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bloc-filter">
|
|
||||||
<p class="title-second">Plus d'articles</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>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="bloc-filter">
|
<div class="bloc-filter">
|
||||||
<h3>Plus d'articles</h3>
|
<h3>Plus d'articles</h3>
|
||||||
<p class="title-small">Catégories</p>
|
<p class="title-small">Catégories</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>
|
||||||
<div class="filtre ops-color">ops</div>
|
<div class="filtre ops-color">ops</div>
|
||||||
<div class="filtre devops-color">devops</div>
|
<div class="filtre devops-color">devops</div>
|
||||||
<p class="title-small">Tags</p>
|
<p class="title-small">Tags</p>
|
||||||
<div class="tag">html</div>
|
<tag type="tags" />
|
||||||
<div class="tag">js</div>
|
|
||||||
<div class="tag">css</div>
|
|
||||||
<div class="tag">html</div>
|
|
||||||
<div class="tag">php</div>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="bloc-recent">
|
<div class="bloc-recent">
|
||||||
@ -79,17 +52,17 @@
|
|||||||
<h3 id="titre-between">Dans le même thème</h3>
|
<h3 id="titre-between">Dans le même thème</h3>
|
||||||
<div class="row articles">
|
<div class="row articles">
|
||||||
<tag type="loop" for="posts" limit="6">
|
<tag type="loop" for="posts" limit="6">
|
||||||
<div class="col-12 col-md-6 col-lg-4">
|
<a class="col-12 col-md-6 col-lg-4 column-link">
|
||||||
<div class="article column-categorie">
|
<div class="article column-category">
|
||||||
<h4 class="title">
|
<h4 class="title">
|
||||||
<loop column="title" />
|
<loop column="title" />
|
||||||
</h4>
|
</h4>
|
||||||
<div class="etiquettes">
|
<div class="etiquettes">
|
||||||
<span class="cat">
|
<span class="cat">
|
||||||
<loop column="categorie" />
|
<loop column="category" />
|
||||||
</span>
|
</span>
|
||||||
<span class="date">
|
<span class="date">
|
||||||
<loop column="date" />
|
<loop column="datetime" />
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
@ -97,16 +70,15 @@
|
|||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</a>
|
||||||
</tag>
|
</tag>
|
||||||
</div>
|
</div>
|
||||||
</main>
|
</main>
|
||||||
|
|
||||||
<footer>
|
|
||||||
<tag type="includes" file="footer" />
|
|
||||||
</footer>
|
|
||||||
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
|
|
||||||
crossorigin="anonymous"></script>
|
|
||||||
</body>
|
</body>
|
||||||
|
<footer>
|
||||||
|
<tag type="includes" file="footer" />
|
||||||
|
</footer>
|
||||||
|
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
|
||||||
|
crossorigin="anonymous"></script>
|
||||||
|
|
||||||
</html>
|
</html>
|
||||||
|
@ -5,6 +5,7 @@ namespace App;
|
|||||||
use DOMDocument;
|
use DOMDocument;
|
||||||
use DOMNode;
|
use DOMNode;
|
||||||
use PDO;
|
use PDO;
|
||||||
|
use App\Router;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Avior <florian.bouillon@delta-wings.net>
|
* @author Avior <florian.bouillon@delta-wings.net>
|
||||||
|
@ -4,6 +4,7 @@ namespace App\Tags;
|
|||||||
|
|
||||||
use App\Tags\Tag;
|
use App\Tags\Tag;
|
||||||
use App\Functions;
|
use App\Functions;
|
||||||
|
use App\DB\Post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* inputs <tag type="article" column="(voir les collones de la table post)/>
|
* inputs <tag type="article" column="(voir les collones de la table post)/>
|
||||||
@ -12,11 +13,13 @@ use App\Functions;
|
|||||||
class Article extends Tag {
|
class Article extends Tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
$post = array( //testing purpose
|
// $post = array( //testing purpose
|
||||||
'title'=> "test",
|
// 'title'=> "test",
|
||||||
'url'=> "pokemongo",
|
// 'url'=> "pokemongo",
|
||||||
'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
// 'content'=> "<p>azerthjjhhdsqmlkjhgfd</p>"
|
||||||
);
|
// );
|
||||||
|
|
||||||
|
$post = Post::get($_GET["post"]);
|
||||||
|
|
||||||
$pok = $this->getElement();
|
$pok = $this->getElement();
|
||||||
$attr = $pok->getAttribute("column");
|
$attr = $pok->getAttribute("column");
|
||||||
@ -24,9 +27,14 @@ class Article extends Tag {
|
|||||||
$doc = $this->getDoc();
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
if($attr == "content") {
|
if($attr == "content") {
|
||||||
Functions::appendHTML($pok->parentNode, $post[$attr]);
|
|
||||||
|
Functions::appendHTML($pok->parentNode, $post->getContent());
|
||||||
|
} elseif($attr == "category") {
|
||||||
|
$txt = $doc->createTextNode($post->getCategory()->getName());
|
||||||
|
$pok->parentNode->insertBefore($txt, $pok);
|
||||||
} else {
|
} else {
|
||||||
$txt = $doc->createTextNode($post[$attr]);
|
$col = "get" . ucfirst($attr);
|
||||||
|
$txt = $doc->createTextNode($post->$col());
|
||||||
$pok->parentNode->insertBefore($txt, $pok);
|
$pok->parentNode->insertBefore($txt, $pok);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,19 +3,16 @@
|
|||||||
namespace App\Tags;
|
namespace App\Tags;
|
||||||
|
|
||||||
use App\Tags\Tag;
|
use App\Tags\Tag;
|
||||||
|
use App\DB\Post;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* input <tag type="author" column="(column name)"/>
|
* input <tag type="author" column="(column name)"/>
|
||||||
* return text
|
* return text
|
||||||
*/
|
*/
|
||||||
class Author extends Tag {
|
class AuthorTag extends Tag {
|
||||||
public function render() {
|
public function render() {
|
||||||
|
|
||||||
$post = array( //testing purpose
|
$author = Post::get($_GET["post"])->getAuthor();
|
||||||
'name'=> "test",
|
|
||||||
'image'=> "pokemon",
|
|
||||||
'linkedin'=> "pouet"
|
|
||||||
);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -24,7 +21,9 @@ class Author extends Tag {
|
|||||||
|
|
||||||
$doc = $this->getDoc();
|
$doc = $this->getDoc();
|
||||||
|
|
||||||
$txt = $doc->createTextNode($post[$attr]);
|
$col = "get" . ucfirst($attr);
|
||||||
|
|
||||||
|
$txt = $doc->createTextNode($author->$col());
|
||||||
|
|
||||||
$pok->parentNode->insertBefore($txt, $pok);
|
$pok->parentNode->insertBefore($txt, $pok);
|
||||||
}
|
}
|
@ -6,6 +6,7 @@ use App\Tags\Tag;
|
|||||||
use DomXPath;
|
use DomXPath;
|
||||||
use App\Functions;
|
use App\Functions;
|
||||||
use App\DB\Post;
|
use App\DB\Post;
|
||||||
|
use App\DB\Category;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* input
|
* input
|
||||||
@ -21,15 +22,18 @@ class Loop extends Tag {
|
|||||||
|
|
||||||
$limit = (int) $el->getAttribute("limit");
|
$limit = (int) $el->getAttribute("limit");
|
||||||
|
|
||||||
$posts = Post::list($limit);
|
if($el->getAttribute("category") !== null) {
|
||||||
|
$posts = Post::listByCategory(Post::get($_GET["post"])->getCategory()->getId(), true, 6);
|
||||||
|
$postsList = array();
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
if($post->getId() != $_GET["post"]) $postsList[] = $post;
|
||||||
|
}
|
||||||
|
$posts = $postsList;
|
||||||
|
} else {
|
||||||
|
$posts = Post::list(true, 6);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
$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;
|
$parent = $el->parentNode;
|
||||||
//var_dump($parent);
|
//var_dump($parent);
|
||||||
@ -46,9 +50,13 @@ class Loop extends Tag {
|
|||||||
|
|
||||||
foreach ($elements as $ele) {
|
foreach ($elements as $ele) {
|
||||||
if($ele->getAttribute("column") == "content") {
|
if($ele->getAttribute("column") == "content") {
|
||||||
Functions::appendHTML($ele->parentNode, $posts[$i]["content"]);
|
Functions::appendHTML($ele->parentNode, $posts[$i]->getShort());
|
||||||
|
} elseif($ele->getAttribute("column") == "category") {
|
||||||
|
$txt = $doc->createTextNode($posts[$i]->getCategory()->getName());
|
||||||
|
$ele->parentNode->insertBefore($txt, $ele);
|
||||||
} else {
|
} else {
|
||||||
$txt = $doc->createTextNode($posts[$i][$ele->getAttribute("column")]);
|
$col = 'get' . ucfirst($ele->getAttribute("column"));
|
||||||
|
$txt = $doc->createTextNode($posts[$i]->$col());
|
||||||
$ele->parentNode->insertBefore($txt, $ele);
|
$ele->parentNode->insertBefore($txt, $ele);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,7 +64,13 @@ class Loop extends Tag {
|
|||||||
$finder = new DomXPath($doc);
|
$finder = new DomXPath($doc);
|
||||||
$nodes = $finder->query("//*[contains(@class, 'column-cat')]");
|
$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")));
|
if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-category", $posts[$i]->getCategory()->getName() , $nodes[0]->getAttribute("class")));
|
||||||
|
|
||||||
|
$nodes = $finder->query("//*[contains(@class, 'column-link')]");
|
||||||
|
|
||||||
|
if(count($nodes) >= 1) $nodes[0]->setAttribute("href", "/post/".$posts[$i]->getId());
|
||||||
|
if(count($nodes) >= 1) $nodes[0]->setAttribute("class", str_replace("column-link", "", $nodes[0]->getAttribute("class")));
|
||||||
|
|
||||||
|
|
||||||
$loop = $pok->getElementsByTagName("loop");
|
$loop = $pok->getElementsByTagName("loop");
|
||||||
|
|
||||||
|
31
assets/php/Tags/Tags.php
Normal file
31
assets/php/Tags/Tags.php
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Tags;
|
||||||
|
|
||||||
|
use App\Tags\Tag;
|
||||||
|
use App\DB\Post;
|
||||||
|
|
||||||
|
//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 Tags 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"
|
||||||
|
$post = Post::get($_GET["post"]);
|
||||||
|
/** @var \App\DB\Tag $tag */
|
||||||
|
foreach ($post->getTags() as $tag) {
|
||||||
|
$res = $doc->createElement("a");
|
||||||
|
$res->setAttribute("href", "/search?tag=" . $tag->getId());
|
||||||
|
$res->setAttribute("class", "tag");
|
||||||
|
$text = $doc->createTextNode($tag->getName());
|
||||||
|
$res->appendChild($text);
|
||||||
|
$pok->parentNode->insertBefore($res, $pok);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -2,11 +2,118 @@
|
|||||||
|
|
||||||
namespace App\DB;
|
namespace App\DB;
|
||||||
|
|
||||||
|
use App\Functions;
|
||||||
|
|
||||||
class Author {
|
class Author {
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
private $username;
|
private $username;
|
||||||
|
|
||||||
private $linkedin;
|
private $password;
|
||||||
|
|
||||||
|
private $job;
|
||||||
|
|
||||||
|
public function __construct(){}
|
||||||
|
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUsername() {
|
||||||
|
return $this->username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function checkPassword($password) {
|
||||||
|
return password_verify($password, $this->password);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getPassword() {
|
||||||
|
return $this->password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getJob() {
|
||||||
|
return $this->job;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setUsername($username) {
|
||||||
|
$this->username = $username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setPassword($password) {
|
||||||
|
$this->password = \password_hash($password, PASSWORD_DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setJob($job) {
|
||||||
|
$this->job = $job;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public static function fromArray($array) {
|
||||||
|
$au = new Self();
|
||||||
|
$au->setId($array["id"]);
|
||||||
|
$au->setUsername($array["username"]);
|
||||||
|
$au->setPassword($array["password"]);
|
||||||
|
$au->setJob($array["job"]);
|
||||||
|
return $au;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
|
$query = "SELECT * FROM author ORDER BY " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$cats = $pdo->query($query)->fetchAll();
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
foreach ($cats as $cat) {
|
||||||
|
$res[] = Author::fromArray($cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(int $id) {
|
||||||
|
return Author::fromArray(Functions::connect()->query("SELECT * FROM users WHERE id=" . $id)->fetch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add(Author $author) {
|
||||||
|
$query = "INSERT INTO author (id, username, password, job)
|
||||||
|
VALUES (NULL, ':username', ':password', ':job');";
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$prepared = $pdo->prepare($query);
|
||||||
|
$prepared->bindParam(":username", $author->getUsername());
|
||||||
|
$prepared->bindParam(":password", $author->getPassword());
|
||||||
|
$prepared->bindParam(":job", $author->getjob());
|
||||||
|
$prepared->execute();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function remove(Author $author) {
|
||||||
|
Functions::connect()->prepare("DELETE FROM author WHERE id=:id")->execute(array(":id" => $author->getId()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update(Author $author) {
|
||||||
|
Functions::connect()->prepare("UPDATE author SET name=':name', password=':password', job=':job' WHERE id=:id")->execute(array(
|
||||||
|
":username" => $author->getUsername(),
|
||||||
|
":password" => $author->getPassword(),
|
||||||
|
":job" => $author->getJob(),
|
||||||
|
":id" => $author->getId()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,99 +0,0 @@
|
|||||||
<?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;
|
|
||||||
}
|
|
||||||
}
|
|
105
assets/php/db/Category.php
Normal file
105
assets/php/db/Category.php
Normal file
@ -0,0 +1,105 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\DB;
|
||||||
|
|
||||||
|
use App\Functions;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
|
||||||
|
class Category {
|
||||||
|
|
||||||
|
private $id;
|
||||||
|
|
||||||
|
private $name;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public static function fromArray($array) {
|
||||||
|
$cat = new Category();
|
||||||
|
$cat->setId($array["id"]);
|
||||||
|
$cat->setName($array["name"]);
|
||||||
|
return $cat;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param boolean $recent sort by most recent of less recent
|
||||||
|
* @param int $limit
|
||||||
|
*
|
||||||
|
* @return Category[]
|
||||||
|
*/
|
||||||
|
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[] = Category::fromArray($cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function get(int $id) {
|
||||||
|
return Category::fromArray(Functions::connect()->query("SELECT * FROM categories WHERE id=" . $id)->fetch());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function add(Category $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(Category $categorie) {
|
||||||
|
Functions::connect()->prepare("DELETE FROM categories WHERE id=:id")->execute(array(":id" => $categorie->getId()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function update(Category $categorie) {
|
||||||
|
Functions::connect()->prepare("UPDATE categorie SET name=:name WHERE id=:id")->execute(array(":name" => $categorie->getName(), ":id" => $categorie->getId()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -2,6 +2,8 @@
|
|||||||
|
|
||||||
namespace App\DB;
|
namespace App\DB;
|
||||||
|
|
||||||
|
use App\Functions;
|
||||||
|
|
||||||
class Post {
|
class Post {
|
||||||
|
|
||||||
|
|
||||||
@ -15,12 +17,130 @@ class Post {
|
|||||||
|
|
||||||
private $short;
|
private $short;
|
||||||
|
|
||||||
private $categorie;
|
private $category;
|
||||||
|
|
||||||
private $author;
|
private $author;
|
||||||
|
|
||||||
|
private $tags;
|
||||||
|
|
||||||
private $dt;
|
private $dt;
|
||||||
|
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setTitle($title) {
|
||||||
|
$this->title = $title;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public function setUrl($url) {
|
||||||
|
$this->url = $url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setContent($content) {
|
||||||
|
$this->content = $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setShort($short) {
|
||||||
|
$this->short = $short;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setCategory($category) {
|
||||||
|
$this->category = $category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setAuthor($author) {
|
||||||
|
$this->author = $author;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setDateTime($dt) {
|
||||||
|
$this->dt = $dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function setTags($taglist) {
|
||||||
|
$this->tags = $taglist;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function getId() {
|
||||||
|
return $this->id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTitle() {
|
||||||
|
return $this->title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getUrl() {
|
||||||
|
return $this->url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getContent() {
|
||||||
|
return $this->content;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getShort() {
|
||||||
|
return $this->short;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getCategory() {
|
||||||
|
return Category::get($this->category);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getAuthor() {
|
||||||
|
return Author::get($this->author);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getDateTime() {
|
||||||
|
return $this->dt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function getTags() {
|
||||||
|
$temp = array();
|
||||||
|
|
||||||
|
if ($this->tags == null) return $temp;
|
||||||
|
foreach ($this->tags as $tag) {
|
||||||
|
$temp[] = Tag::get($tag);
|
||||||
|
}
|
||||||
|
return $temp;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public function __construct() {
|
||||||
|
$this->dt = new \DateTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static function fromArray($array) {
|
||||||
|
$post = new Post();
|
||||||
|
$post->setId($array["id"]);
|
||||||
|
$post->setTitle($array["title"]);
|
||||||
|
$post->setUrl($array["url"]);
|
||||||
|
$post->setContent($array["content"]);
|
||||||
|
$post->setShort($array["short"]);
|
||||||
|
if(isset($array["category"])) $post->setCategory($array["category"]);
|
||||||
|
$post->setAuthor($array["author"]);
|
||||||
|
$post->setDateTime($array["dt"]);
|
||||||
|
return $post;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list of posts
|
* list of posts
|
||||||
*
|
*
|
||||||
@ -29,9 +149,52 @@ class Post {
|
|||||||
*
|
*
|
||||||
* @return array(Post)
|
* @return array(Post)
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public static function list($recent = true, $limit = 100) {
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
|
$query = "SELECT * FROM posts ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$posts = $pdo->query($query)->fetchAll();
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
$res[] = Post::fromArray($post);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function listByCategory($categoryId = null, $recent = true, $limit = 100) {
|
||||||
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
|
$cat = $categoryId !== null ? "WHERE category=" . $categoryId : "";
|
||||||
|
$query = "SELECT * FROM posts " . $cat . " ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$posts = $pdo->query($query)->fetchAll();
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
foreach ($posts as $post) {
|
||||||
|
$post = Post::fromArray($post);
|
||||||
|
$query = "SELECT * FROM post_tag WHERE post_id=". $post->getId();
|
||||||
|
$tagList = array();
|
||||||
|
$bool = $pdo->query($query);
|
||||||
|
// var_dump($bool->fetchAll());
|
||||||
|
if($bool) foreach ($pdo->query($query)->fetchAll() as $tag) {
|
||||||
|
$tagList[] = $tag["tag"];
|
||||||
|
}
|
||||||
|
$post->setTags($tagList);
|
||||||
|
|
||||||
|
$res[] = $post;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* get a specific Post
|
* get a specific Post
|
||||||
@ -40,7 +203,21 @@ class Post {
|
|||||||
*
|
*
|
||||||
* @return Post
|
* @return Post
|
||||||
*/
|
*/
|
||||||
public static function get(int $id) {
|
public static function get($id) {
|
||||||
|
$post = Post::fromArray(Functions::connect()->query("SELECT * FROM posts WHERE id=" . $id)->fetch());
|
||||||
|
$query = "SELECT * FROM post_tag WHERE post_id=". $post->getId();
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$bool = $pdo->query($query);
|
||||||
|
|
||||||
|
$tagList = array();
|
||||||
|
if($bool) {
|
||||||
|
foreach ($bool->fetchAll() as $tag) {
|
||||||
|
$tagList[] = $tag["tag"];
|
||||||
|
}
|
||||||
|
if(count($tagList) >= 1) $post->setTags($tagList);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $post;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -50,22 +227,55 @@ class Post {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public static function add(Post $post) {
|
public static function add(Post $post) {
|
||||||
|
$query = "INSERT INTO posts (id, title, url, content, short, categorie, author, dt)
|
||||||
|
VALUES (NULL, ':title', ':url', ':content', ':short', ':categorie', ':author', ':dt');";
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$prepared = $pdo->prepare($query);
|
||||||
|
$prepared->bindParam(":title", $post->getTitle());
|
||||||
|
$prepared->bindParam(":url", $post->getUrl());
|
||||||
|
$prepared->bindParam(":content", $post->getContent());
|
||||||
|
$prepared->bindParam(":short", $post->getShort());
|
||||||
|
$prepared->bindParam(":categorie", $post->getCategory());
|
||||||
|
$prepared->bindParam(":author", $post->getAuthor());
|
||||||
|
$prepared->bindParam(":dt", $post->getDateTime());
|
||||||
|
$prepared->execute();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove the post
|
* remove the post
|
||||||
*
|
*
|
||||||
* @param Post $post
|
* @param Post $post
|
||||||
*
|
*
|
||||||
|
*
|
||||||
*/
|
*/
|
||||||
public static function remove(Post $post) {}
|
public static function remove(Post $post) {
|
||||||
|
Functions::connect()->prepare("DELETE FROM posts WHERE id=:id")->execute(array(":id" => $post->getId()));
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update the post data on the db
|
* update the post data on the db
|
||||||
*
|
*
|
||||||
* @param Post $post
|
* @param Post $post
|
||||||
*
|
*
|
||||||
* @return void
|
|
||||||
*/
|
*/
|
||||||
public static function update(Post $post) {}
|
public static function update(Post $post) {
|
||||||
|
Functions::connect()->prepare("UPDATE posts SET title=':title', url=':url', content=':content', short=':short', category=':category', author=':author', dt=':dt' WHERE id=:id")->execute(array(
|
||||||
|
":title" => $post->getTitle(),
|
||||||
|
":url" => $post->getUrl(),
|
||||||
|
":content" => $post->getContent(),
|
||||||
|
":short" => $post->getShort(),
|
||||||
|
":categorie" => $post->getCategorie(),
|
||||||
|
":author" => $post->getAuthor(),
|
||||||
|
":dt" => $post->getDt(),
|
||||||
|
":id" => $post->getId()
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -1,57 +1,102 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\DB;
|
namespace App\DB;
|
||||||
|
|
||||||
|
use App\Functions;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
|
|
||||||
class Tag {
|
class Tag {
|
||||||
|
|
||||||
private $id;
|
private $id;
|
||||||
|
|
||||||
private $name;
|
private $name;
|
||||||
|
|
||||||
|
public function __construct() {}
|
||||||
|
|
||||||
|
public static function fromArray($array) {
|
||||||
|
$tag = new Tag();
|
||||||
|
$tag->setId($array["id"]);
|
||||||
|
$tag->setName($array["name"]);
|
||||||
|
return $tag;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* list of posts
|
* Undocumented function
|
||||||
*
|
*
|
||||||
* @param boolean $recent sort by most recent or not
|
* @param boolean $recent sort by most recent of less recent
|
||||||
* @param integer $limit limit the number of result
|
* @param int $limit
|
||||||
*
|
*
|
||||||
* @return array(Post)
|
* @return Categorie[]
|
||||||
*/
|
*/
|
||||||
public static function list($recent = true, $limit = 100) {
|
public static function list($recent = true, $limit = 100) {
|
||||||
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
|
$query = "SELECT * FROM tag ORDER BY " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
|
$pdo = Functions::connect();
|
||||||
|
$cats = $pdo->query($query)->fetchAll();
|
||||||
|
|
||||||
|
$res = array();
|
||||||
|
|
||||||
|
foreach ($cats as $cat) {
|
||||||
|
$res[] = Tag::fromArray($cat);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $res;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
*
|
|
||||||
* get a specific Post
|
|
||||||
*
|
|
||||||
* @param integer $id the id
|
|
||||||
*
|
|
||||||
* @return Post
|
|
||||||
*/
|
|
||||||
public static function get(int $id) {
|
public static function get(int $id) {
|
||||||
|
return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public static function add(Tag $tag) {
|
||||||
* add a post to the db
|
$query = "INSERT INTO tag (id, name)
|
||||||
*
|
VALUES (NULL, ':name');";
|
||||||
* @param Post $post
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public static function add(Post $post) {
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
$pdo = Functions::connect();
|
||||||
* remove the post
|
$prepared = $pdo->prepare($query);
|
||||||
*
|
$prepared->bindParam(":name", $tag->getName());
|
||||||
* @param Post $post
|
$prepared->execute();
|
||||||
*
|
}
|
||||||
*/
|
|
||||||
public static function remove(Post $post) {}
|
public static function remove(Tag $tag) {
|
||||||
|
Functions::connect()->prepare("DELETE FROM tag WHERE id=:id")->execute(array(":id" => $tag->getId()));
|
||||||
/**
|
|
||||||
* update the post data on the db
|
}
|
||||||
*
|
|
||||||
* @param Post $post
|
public static function update(Tag $tag) {
|
||||||
*
|
Functions::connect()->prepare("UPDATE tag SET name=:name WHERE id=:id")->execute(array(":name" => $tag->getName(), ":id" => $tag->getId()));
|
||||||
* @return void
|
}
|
||||||
*/
|
|
||||||
public static function update(Post $post) {}
|
|
||||||
|
/**
|
||||||
|
* 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;
|
||||||
|
}
|
||||||
|
public function setId($id) {
|
||||||
|
$this->id = $id;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -8,7 +8,7 @@ use App\Router;
|
|||||||
use App\Functions;
|
use App\Functions;
|
||||||
use App\Tags\Tag;
|
use App\Tags\Tag;
|
||||||
|
|
||||||
//renvoie vers le fichier css si il est demand<EFBFBD>
|
//renvoie vers le fichier css si il est demandé
|
||||||
if(Functions::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;
|
||||||
@ -28,10 +28,10 @@ if($_GET["page"] != "" && !Functions::endsWith($_GET["page"], "/") && count($_GE
|
|||||||
die;
|
die;
|
||||||
}
|
}
|
||||||
|
|
||||||
//enleve les / du d<EFBFBD>but & fin
|
//enleve les / du début & fin
|
||||||
$_GET['page'] = trim($_GET['page'], '/');
|
$_GET['page'] = trim($_GET['page'], '/');
|
||||||
|
|
||||||
// si taille sup<EFBFBD>rieur <20> 1 $_getpost = element
|
// si taille supérieur à 1 $_getpost = element
|
||||||
if(count(explode("/", $_GET["page"])) > 1) {
|
if(count(explode("/", $_GET["page"])) > 1) {
|
||||||
$_GET["post"] = explode("/", $_GET["page"])[1];
|
$_GET["post"] = explode("/", $_GET["page"])[1];
|
||||||
}
|
}
|
||||||
|
@ -1,83 +0,0 @@
|
|||||||
<?php
|
|
||||||
// // include_once "router.php";
|
|
||||||
|
|
||||||
// use App\Router;
|
|
||||||
|
|
||||||
// //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
|
|
||||||
// */
|
|
||||||
|
|
||||||
// require_once "functions.php";
|
|
||||||
|
|
||||||
|
|
||||||
// $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 = 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);
|
|
@ -12,8 +12,8 @@ CREATE TABLE posts (
|
|||||||
url VARCHAR(32),
|
url VARCHAR(32),
|
||||||
content TEXT,
|
content TEXT,
|
||||||
short varchar(256),
|
short varchar(256),
|
||||||
dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
|
dt VARCHAR(100),
|
||||||
categorie INT,
|
category INT,
|
||||||
author INT
|
author INT
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -40,8 +40,9 @@ CREATE TABLE categories (
|
|||||||
|
|
||||||
CREATE TABLE users (
|
CREATE TABLE users (
|
||||||
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
|
||||||
|
password varchar(500),
|
||||||
username VARCHAR(128),
|
username VARCHAR(128),
|
||||||
linkedin VARCHAR(560)
|
job VARCHAR(560)
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
@ -64,7 +65,7 @@ VALUES ('pokemon', 'pokemon', 'cacacacacacacacacacacacaca\r\ncacacacacacacacacac
|
|||||||
('Pokemon Go', 'pokemon-go', 'I PLAY POKEMON GO EVERYDAY', 'I PLAY POKEMON GO', 2, 1);
|
('Pokemon Go', 'pokemon-go', 'I PLAY POKEMON GO EVERYDAY', 'I PLAY POKEMON GO', 2, 1);
|
||||||
|
|
||||||
-- users
|
-- users
|
||||||
INSERT INTO users (username, linkedin) VALUES ('Florian Bouillon', NULL), ('Adrien huchet', 'adrienhuchet');
|
INSERT INTO users (username, job) VALUES ('Florian Bouillon', 'HTML King'), ('Adrien huchet', 'HTML Noob');
|
||||||
|
|
||||||
-- categories
|
-- categories
|
||||||
INSERT INTO categories (name) VALUES ('devops'), ('ops'), ('dev'), ('digi');
|
INSERT INTO categories (name) VALUES ('devops'), ('ops'), ('dev'), ('digi');
|
||||||
|
Loading…
x
Reference in New Issue
Block a user