mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-04-22 10:52:09 +00:00
commit
This commit is contained in:
parent
401cb920d2
commit
c2e310e5d9
@ -25,6 +25,9 @@
|
|||||||
<p class="post text">
|
<p class="post text">
|
||||||
<tag type="editor" element="content"/>
|
<tag type="editor" element="content"/>
|
||||||
</p>
|
</p>
|
||||||
|
<button class="bloc-plus submitPost">
|
||||||
|
Créer
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
|
@ -41,15 +41,18 @@ var addTag = (element) => {
|
|||||||
|
|
||||||
var addingTag = (element) => {
|
var addingTag = (element) => {
|
||||||
var input = document.createElement("input");
|
var input = document.createElement("input");
|
||||||
var uuid = Math.floor(Math.random() * Math.floor(10000));
|
var uuid = Math.floor(Math.random() * Math.floor(-1000000));
|
||||||
|
var addtag = element.target.parentElement.querySelector(".add-tag");
|
||||||
input.setAttribute("type", "checkbox");
|
input.setAttribute("type", "checkbox");
|
||||||
input.setAttribute("id", uuid);
|
input.setAttribute("id", uuid);
|
||||||
|
input.setAttribute("data-text", addTag.value);
|
||||||
|
|
||||||
var label = document.createElement("label");
|
var label = document.createElement("label");
|
||||||
label.setAttribute("for", uuid);
|
label.setAttribute("for", uuid);
|
||||||
var addtag = element.target.parentElement.querySelector(".add-tag");
|
|
||||||
label.innerText = addtag.value;
|
label.innerText = addtag.value;
|
||||||
|
|
||||||
|
input.setAttribute("data-text", label.innerText);
|
||||||
|
|
||||||
element.target.parentElement.insertBefore(input, element.target);
|
element.target.parentElement.insertBefore(input, element.target);
|
||||||
element.target.parentElement.insertBefore(label, element.target);
|
element.target.parentElement.insertBefore(label, element.target);
|
||||||
|
|
||||||
@ -62,3 +65,28 @@ var addingTag = (element) => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
document.querySelector(".addTag").addEventListener("click", addTag);
|
document.querySelector(".addTag").addEventListener("click", addTag);
|
||||||
|
|
||||||
|
|
||||||
|
var submit = (el) => {
|
||||||
|
|
||||||
|
var major = document.querySelector('.post.text > textarea');
|
||||||
|
var title = document.querySelector("h2.title > input");
|
||||||
|
var category = document.querySelector("span.cat > select");
|
||||||
|
var tags = document.querySelectorAll("input[type='checkbox']:checked");
|
||||||
|
console.log(title.value);
|
||||||
|
console.log(category.value);
|
||||||
|
console.log(major.value);
|
||||||
|
console.log(tags);
|
||||||
|
var tglst = "";
|
||||||
|
tags.forEach(element => {
|
||||||
|
tglst += "," + element.getAttribute("id") + (element.hasAttribute("data-text") ? ":" + element.getAttribute("data-text") : "");
|
||||||
|
});
|
||||||
|
tglst = tglst.substr(1);
|
||||||
|
|
||||||
|
window.location.search = "title="+ title.value +"&category=" + category.value + "&content=" + major.value + "&tags=" + tglst;
|
||||||
|
|
||||||
|
//?title=$title&category=$category&content=$major&
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
document.querySelector(".submitPost").addEventListener("click", submit);
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\Controller;
|
namespace App\Controller;
|
||||||
|
|
||||||
use App\Controller;
|
use App\Controller;
|
||||||
|
use App\DB\Post;
|
||||||
|
use App\DB\Tag;
|
||||||
|
|
||||||
class HomeController extends Controller {
|
class HomeController extends Controller {
|
||||||
|
|
||||||
@ -18,6 +20,34 @@ class HomeController extends Controller {
|
|||||||
* @route /^\/post\/new\/*$/
|
* @route /^\/post\/new\/*$/
|
||||||
*/
|
*/
|
||||||
public function postAdd() {
|
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");
|
return file_get_contents(DIR."/html/post_new.html");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ class Editor extends \App\Tags\Tag {
|
|||||||
case 'categories':
|
case 'categories':
|
||||||
$option = $doc->createElement("option");
|
$option = $doc->createElement("option");
|
||||||
$text = $doc->createTextNode("Categorie");
|
$text = $doc->createTextNode("Categorie");
|
||||||
$option->setAttribute("value", "-1");
|
$option->setAttribute("value", "0");
|
||||||
$option->setAttribute("disabled", "true");
|
$option->setAttribute("disabled", "true");
|
||||||
$option->setAttribute("selected", "selected");
|
$option->setAttribute("selected", "selected");
|
||||||
$option->appendChild($text);
|
$option->appendChild($text);
|
||||||
|
@ -70,7 +70,7 @@ class Author {
|
|||||||
|
|
||||||
public static function list($recent = true, $limit = 100) {
|
public static function list($recent = true, $limit = 100) {
|
||||||
$sort = $recent ? "DESC" : "ASC";
|
$sort = $recent ? "DESC" : "ASC";
|
||||||
$query = "SELECT * FROM author ORDER BY " . $sort . " LIMIT " . $limit;
|
$query = "SELECT * FROM users ORDER BY id " . $sort . " LIMIT " . $limit;
|
||||||
|
|
||||||
$pdo = Functions::connect();
|
$pdo = Functions::connect();
|
||||||
$cats = $pdo->query($query)->fetchAll();
|
$cats = $pdo->query($query)->fetchAll();
|
||||||
|
@ -3,6 +3,8 @@
|
|||||||
namespace App\DB;
|
namespace App\DB;
|
||||||
|
|
||||||
use App\Functions;
|
use App\Functions;
|
||||||
|
use DateTime;
|
||||||
|
use PDO;
|
||||||
|
|
||||||
class Post {
|
class Post {
|
||||||
|
|
||||||
@ -11,12 +13,8 @@ class Post {
|
|||||||
|
|
||||||
private $title;
|
private $title;
|
||||||
|
|
||||||
private $url;
|
|
||||||
|
|
||||||
private $content;
|
private $content;
|
||||||
|
|
||||||
private $short;
|
|
||||||
|
|
||||||
private $category;
|
private $category;
|
||||||
|
|
||||||
private $author;
|
private $author;
|
||||||
@ -34,19 +32,10 @@ class Post {
|
|||||||
$this->title = $title;
|
$this->title = $title;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public function setUrl($url) {
|
|
||||||
$this->url = $url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setContent($content) {
|
public function setContent($content) {
|
||||||
$this->content = $content;
|
$this->content = $content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function setShort($short) {
|
|
||||||
$this->short = $short;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function setCategory($category) {
|
public function setCategory($category) {
|
||||||
$this->category = $category;
|
$this->category = $category;
|
||||||
}
|
}
|
||||||
@ -75,18 +64,10 @@ class Post {
|
|||||||
return $this->title;
|
return $this->title;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getUrl() {
|
|
||||||
return $this->url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getContent() {
|
public function getContent() {
|
||||||
return $this->content;
|
return $this->content;
|
||||||
}
|
}
|
||||||
|
|
||||||
public function getShort() {
|
|
||||||
return $this->short;
|
|
||||||
}
|
|
||||||
|
|
||||||
public function getCategory() {
|
public function getCategory() {
|
||||||
return Category::get($this->category);
|
return Category::get($this->category);
|
||||||
}
|
}
|
||||||
@ -135,9 +116,7 @@ class Post {
|
|||||||
$post = new Post();
|
$post = new Post();
|
||||||
$post->setId($array["id"]);
|
$post->setId($array["id"]);
|
||||||
$post->setTitle($array["title"]);
|
$post->setTitle($array["title"]);
|
||||||
$post->setUrl($array["url"]);
|
|
||||||
$post->setContent($array["content"]);
|
$post->setContent($array["content"]);
|
||||||
$post->setShort($array["short"]);
|
|
||||||
if(isset($array["category"])) $post->setCategory($array["category"]);
|
if(isset($array["category"])) $post->setCategory($array["category"]);
|
||||||
$post->setAuthor($array["author"]);
|
$post->setAuthor($array["author"]);
|
||||||
$post->setDateTime($array["dt"]);
|
$post->setDateTime($array["dt"]);
|
||||||
@ -240,19 +219,33 @@ 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)
|
$query = "INSERT INTO posts (id, title, content, categorie, author, dt)
|
||||||
VALUES (NULL, ':title', ':url', ':content', ':short', ':categorie', ':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"));
|
||||||
|
|
||||||
|
|
||||||
$pdo = Functions::connect();
|
$pdo = Functions::connect();
|
||||||
$prepared = $pdo->prepare($query);
|
$prepared = $pdo->prepare($query);
|
||||||
$prepared->bindParam(":title", $post->getTitle());
|
$prepared->bindParam(":title", $post->getTitle());
|
||||||
$prepared->bindParam(":url", $post->getUrl());
|
|
||||||
$prepared->bindParam(":content", $post->getContent());
|
$prepared->bindParam(":content", $post->getContent());
|
||||||
$prepared->bindParam(":short", $post->getShort());
|
$prepared->bindParam(":category", $post->getCategory()->getId(), PDO::PARAM_INT);
|
||||||
$prepared->bindParam(":categorie", $post->getCategory());
|
$prepared->bindParam(":author", $post->getAuthor()->getId(), PDO::PARAM_INT);
|
||||||
$prepared->bindParam(":author", $post->getAuthor());
|
$prepared->bindParam(":dt", (new DateTime())->format("d/m/Y h:i:s"));
|
||||||
$prepared->bindParam(":dt", $post->getDateTime());
|
|
||||||
$prepared->execute();
|
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");
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -279,11 +272,9 @@ class Post {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
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(
|
Functions::connect()->prepare("UPDATE posts SET title=':title', content=':content', category=':category', author=':author', dt=':dt' WHERE id=:id")->execute(array(
|
||||||
":title" => $post->getTitle(),
|
":title" => $post->getTitle(),
|
||||||
":url" => $post->getUrl(),
|
|
||||||
":content" => $post->getContent(),
|
":content" => $post->getContent(),
|
||||||
":short" => $post->getShort(),
|
|
||||||
":categorie" => $post->getCategorie(),
|
":categorie" => $post->getCategorie(),
|
||||||
":author" => $post->getAuthor(),
|
":author" => $post->getAuthor(),
|
||||||
":dt" => $post->getDt(),
|
":dt" => $post->getDt(),
|
||||||
|
@ -49,14 +49,24 @@ class Tag {
|
|||||||
return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch());
|
return Tag::fromArray(Functions::connect()->query("SELECT * FROM tag WHERE id=" . $id)->fetch());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Undocumented function
|
||||||
|
*
|
||||||
|
* @param Tag $tag
|
||||||
|
*
|
||||||
|
* @return Tag
|
||||||
|
*/
|
||||||
public static function add(Tag $tag) {
|
public static function add(Tag $tag) {
|
||||||
$query = "INSERT INTO tag (id, name)
|
$query = "INSERT INTO tag (id, name)
|
||||||
VALUES (NULL, ':name');";
|
VALUES (NULL, :name);";
|
||||||
|
|
||||||
|
// var_dump($tag);
|
||||||
|
|
||||||
$pdo = Functions::connect();
|
$pdo = Functions::connect();
|
||||||
$prepared = $pdo->prepare($query);
|
$prepared = $pdo->prepare($query);
|
||||||
$prepared->bindParam(":name", $tag->getName());
|
$prepared->execute(array(":name" => $tag->getName()));
|
||||||
$prepared->execute();
|
|
||||||
|
return Tag::list(true, 1)[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
public static function remove(Tag $tag) {
|
public static function remove(Tag $tag) {
|
||||||
|
@ -4,6 +4,9 @@ use App\Router;
|
|||||||
use App\Functions;
|
use App\Functions;
|
||||||
use App\Tags\Tag;
|
use App\Tags\Tag;
|
||||||
use App\Controller;
|
use App\Controller;
|
||||||
|
use App\DB\Author;
|
||||||
|
|
||||||
|
session_start();
|
||||||
|
|
||||||
error_reporting(E_ALL);
|
error_reporting(E_ALL);
|
||||||
ini_set('display_errors', 'On');
|
ini_set('display_errors', 'On');
|
||||||
@ -11,6 +14,8 @@ ini_set('display_errors', 'On');
|
|||||||
/** @var Composer\Autoload\ClassLoader $loader */
|
/** @var Composer\Autoload\ClassLoader $loader */
|
||||||
$loader = require "../../vendor/autoload.php";
|
$loader = require "../../vendor/autoload.php";
|
||||||
|
|
||||||
|
$_SESSION["author"] = Author::list(true, 1)[0];
|
||||||
|
|
||||||
define("DIR", str_replace("/php", "", __DIR__));
|
define("DIR", str_replace("/php", "", __DIR__));
|
||||||
|
|
||||||
//renvoie vers le fichier css si il est demandé
|
//renvoie vers le fichier css si il est demandé
|
||||||
|
Loading…
x
Reference in New Issue
Block a user