From b339e09082d89181e471db4c0fb83b4e8347946b Mon Sep 17 00:00:00 2001 From: Avior Date: Fri, 1 Mar 2019 16:42:42 +0100 Subject: [PATCH] changements --- README.md | 2 +- assets/html/index.html | 10 +- assets/html/post.html | 90 +++---- assets/php/Functions.php | 1 + assets/php/Tags/Article.php | 22 +- assets/php/Tags/{Author.php => AuthorTag.php} | 13 +- assets/php/Tags/Loop.php | 36 ++- assets/php/Tags/Tags.php | 31 +++ assets/php/db/Author.php | 109 ++++++++- assets/php/db/Categorie.php | 99 -------- assets/php/db/Category.php | 105 +++++++++ assets/php/db/Post.php | 220 +++++++++++++++++- assets/php/db/Tag.php | 117 +++++++--- assets/php/handler.php | 6 +- assets/php/pages.php | 83 ------- sql/bdd_proj.sql | 9 +- 16 files changed, 632 insertions(+), 321 deletions(-) rename assets/php/Tags/{Author.php => AuthorTag.php} (62%) create mode 100644 assets/php/Tags/Tags.php delete mode 100644 assets/php/db/Categorie.php create mode 100644 assets/php/db/Category.php delete mode 100644 assets/php/pages.php diff --git a/README.md b/README.md index 7565261..de35906 100755 --- a/README.md +++ b/README.md @@ -131,7 +131,7 @@ gere la redirection des requetes et gere le cache de certains fichiers - sql -# Types de pages (pour design) : +# Types de pages (pour design) - / (page ou post) - /page/ diff --git a/assets/html/index.html b/assets/html/index.html index 61d74be..8580d29 100644 --- a/assets/html/index.html +++ b/assets/html/index.html @@ -33,17 +33,17 @@

Articles récents

- diff --git a/assets/html/post.html b/assets/html/post.html index 54bf3e8..14c93b0 100644 --- a/assets/html/post.html +++ b/assets/html/post.html @@ -11,64 +11,37 @@
-

Mettre en place un serveur web sous linux

+

- OPS - 26-06-2018 + +
-

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 -
-
- 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 +

+

-

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 -
-
- 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 -

-
-
-

Auteur

-
- - -
-

Adrien Huchet

-

Apprenant IT START

+
+

Auteur

+
+ + +
+

+

+
-
-

Plus d'articles

-
dev
-
digi
-
ops
-
devops
-
-

Plus d'articles

-

Catégories

-
dev
-
digi
-
ops
-
devops
-

Tags

-
html
-
js
-
css
-
html
-
php
+

Catégories

+
dev
+
digi
+
ops
+
devops
+

Tags

+
@@ -79,17 +52,17 @@

Dans le même thème

- -
- -
- +
+ +
+ diff --git a/assets/php/Functions.php b/assets/php/Functions.php index 8689fc0..2e8daa4 100644 --- a/assets/php/Functions.php +++ b/assets/php/Functions.php @@ -5,6 +5,7 @@ namespace App; use DOMDocument; use DOMNode; use PDO; +use App\Router; /** * @author Avior diff --git a/assets/php/Tags/Article.php b/assets/php/Tags/Article.php index 09f2e24..f833fb8 100644 --- a/assets/php/Tags/Article.php +++ b/assets/php/Tags/Article.php @@ -4,6 +4,7 @@ namespace App\Tags; use App\Tags\Tag; use App\Functions; +use App\DB\Post; /** * inputs "pokemongo", - 'content'=> "

azerthjjhhdsqmlkjhgfd

" - ); + // $post = array( //testing purpose + // 'title'=> "test", + // 'url'=> "pokemongo", + // 'content'=> "

azerthjjhhdsqmlkjhgfd

" + // ); + + $post = Post::get($_GET["post"]); $pok = $this->getElement(); $attr = $pok->getAttribute("column"); @@ -24,9 +27,14 @@ class Article extends Tag { $doc = $this->getDoc(); 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 { - $txt = $doc->createTextNode($post[$attr]); + $col = "get" . ucfirst($attr); + $txt = $doc->createTextNode($post->$col()); $pok->parentNode->insertBefore($txt, $pok); } } diff --git a/assets/php/Tags/Author.php b/assets/php/Tags/AuthorTag.php similarity index 62% rename from assets/php/Tags/Author.php rename to assets/php/Tags/AuthorTag.php index 31b20b4..b537e51 100644 --- a/assets/php/Tags/Author.php +++ b/assets/php/Tags/AuthorTag.php @@ -3,19 +3,16 @@ namespace App\Tags; use App\Tags\Tag; +use App\DB\Post; /** * input * return text */ -class Author extends Tag { +class AuthorTag extends Tag { public function render() { - $post = array( //testing purpose - 'name'=> "test", - 'image'=> "pokemon", - 'linkedin'=> "pouet" - ); + $author = Post::get($_GET["post"])->getAuthor(); @@ -24,7 +21,9 @@ class Author extends Tag { $doc = $this->getDoc(); - $txt = $doc->createTextNode($post[$attr]); + $col = "get" . ucfirst($attr); + + $txt = $doc->createTextNode($author->$col()); $pok->parentNode->insertBefore($txt, $pok); } diff --git a/assets/php/Tags/Loop.php b/assets/php/Tags/Loop.php index 5259b78..25a5521 100644 --- a/assets/php/Tags/Loop.php +++ b/assets/php/Tags/Loop.php @@ -6,6 +6,7 @@ use App\Tags\Tag; use DomXPath; use App\Functions; use App\DB\Post; +use App\DB\Category; /** * input @@ -21,15 +22,18 @@ class Loop extends Tag { $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; //var_dump($parent); @@ -46,9 +50,13 @@ class Loop extends Tag { foreach ($elements as $ele) { 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 { - $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); } } @@ -56,7 +64,13 @@ class Loop extends Tag { $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"))); + 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"); diff --git a/assets/php/Tags/Tags.php b/assets/php/Tags/Tags.php new file mode 100644 index 0000000..abdc879 --- /dev/null +++ b/assets/php/Tags/Tags.php @@ -0,0 +1,31 @@ +test + * result test + */ +class Tags extends Tag { + public function render() { + //recuperation de la balise de base (pouet) + $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); + } + } +} diff --git a/assets/php/db/Author.php b/assets/php/db/Author.php index 7c9a32c..734d08e 100644 --- a/assets/php/db/Author.php +++ b/assets/php/db/Author.php @@ -2,11 +2,118 @@ namespace App\DB; +use App\Functions; + class Author { private $id; 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() + )); + } + + + } diff --git a/assets/php/db/Categorie.php b/assets/php/db/Categorie.php deleted file mode 100644 index 2d15228..0000000 --- a/assets/php/db/Categorie.php +++ /dev/null @@ -1,99 +0,0 @@ -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; - } -} diff --git a/assets/php/db/Category.php b/assets/php/db/Category.php new file mode 100644 index 0000000..c6e47ae --- /dev/null +++ b/assets/php/db/Category.php @@ -0,0 +1,105 @@ +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())); + } + +} diff --git a/assets/php/db/Post.php b/assets/php/db/Post.php index 6698036..35ee936 100644 --- a/assets/php/db/Post.php +++ b/assets/php/db/Post.php @@ -2,6 +2,8 @@ namespace App\DB; +use App\Functions; + class Post { @@ -15,12 +17,130 @@ class Post { private $short; - private $categorie; + private $category; private $author; + private $tags; + 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 * @@ -29,9 +149,52 @@ class Post { * * @return array(Post) */ + 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 @@ -40,7 +203,21 @@ class 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) { + $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 * * @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 * * @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() + )); + } + } diff --git a/assets/php/db/Tag.php b/assets/php/db/Tag.php index 49f582b..d7fcaaa 100644 --- a/assets/php/db/Tag.php +++ b/assets/php/db/Tag.php @@ -1,57 +1,102 @@ setId($array["id"]); + $tag->setName($array["name"]); + return $tag; + } + /** - * list of posts + * Undocumented function * - * @param boolean $recent sort by most recent or not - * @param integer $limit limit the number of result + * @param boolean $recent sort by most recent of less recent + * @param int $limit * - * @return array(Post) + * @return Categorie[] */ 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) { + return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch()); } - /** - * add a post to the db - * - * @param Post $post - * - */ - public static function add(Post $post) { - } + public static function add(Tag $tag) { + $query = "INSERT INTO tag (id, name) + VALUES (NULL, ':name');"; - /** - * 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) {} + $pdo = Functions::connect(); + $prepared = $pdo->prepare($query); + $prepared->bindParam(":name", $tag->getName()); + $prepared->execute(); +} + + public static function remove(Tag $tag) { + Functions::connect()->prepare("DELETE FROM tag WHERE id=:id")->execute(array(":id" => $tag->getId())); + + } + + 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())); + } + + + /** + * 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; + } } diff --git a/assets/php/handler.php b/assets/php/handler.php index b8b9556..63417dd 100644 --- a/assets/php/handler.php +++ b/assets/php/handler.php @@ -8,7 +8,7 @@ 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(Functions::endsWith($_GET["page"], ".css")) { echo file_get_contents("../css/style.css"); die; @@ -28,10 +28,10 @@ if($_GET["page"] != "" && !Functions::endsWith($_GET["page"], "/") && count($_GE die; } -//enleve les / du d�but & fin +//enleve les / du début & fin $_GET['page'] = trim($_GET['page'], '/'); -// si taille sup�rieur � 1 $_getpost = element +// si taille supérieur à 1 $_getpost = element if(count(explode("/", $_GET["page"])) > 1) { $_GET["post"] = explode("/", $_GET["page"])[1]; } diff --git a/assets/php/pages.php b/assets/php/pages.php deleted file mode 100644 index 8de3f0d..0000000 --- a/assets/php/pages.php +++ /dev/null @@ -1,83 +0,0 @@ -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); diff --git a/sql/bdd_proj.sql b/sql/bdd_proj.sql index 98ab8fa..1acfb3b 100644 --- a/sql/bdd_proj.sql +++ b/sql/bdd_proj.sql @@ -12,8 +12,8 @@ CREATE TABLE posts ( url VARCHAR(32), content TEXT, short varchar(256), - dt TIMESTAMP DEFAULT CURRENT_TIMESTAMP, - categorie INT, + dt VARCHAR(100), + category INT, author INT ); @@ -40,8 +40,9 @@ CREATE TABLE categories ( CREATE TABLE users ( id INT NOT NULL AUTO_INCREMENT PRIMARY KEY, + password varchar(500), 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); -- 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 INSERT INTO categories (name) VALUES ('devops'), ('ops'), ('dev'), ('digi');