mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-14 11:09:19 +00:00
plein de modifs :O
This commit is contained in:
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");
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user