mirror of
https://github.com/Aviortheking/Blog_IMIE.git
synced 2025-06-13 02:29:20 +00:00
pouet
This commit is contained in:
@ -43,6 +43,9 @@ class Controller {
|
||||
if(!isset($_SESSION["author"]) || (isset($_SESSION["author"]) && ($_SESSION["author"]->getRole() != "ROLE_EDITOR" && $_SESSION["author"]->getRole() != "ROLE_ADMIN"))) 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"]);
|
||||
} elseif($arr[0] === "title" && isset($cl) && $cl == $class) {
|
||||
array_shift($arr);
|
||||
$_GET['page_title'] = join(" ", $arr);
|
||||
}
|
||||
}
|
||||
if(isset($instance)) {
|
||||
@ -51,6 +54,7 @@ class Controller {
|
||||
}
|
||||
}
|
||||
}
|
||||
$_GET["page_title"] = "404 error";
|
||||
header("HTTP/1.0 404 Not Found");
|
||||
return file_get_contents(DIR."/html/404.html");
|
||||
|
||||
|
@ -11,20 +11,16 @@ class HomeController extends Controller {
|
||||
|
||||
/**
|
||||
* @route /^\/$/
|
||||
* @title Accueil
|
||||
*/
|
||||
public function home() {
|
||||
return file_get_contents(DIR."/html/index.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/$/
|
||||
*/
|
||||
public function post() {
|
||||
return file_get_contents(DIR."/html/post.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/search\//
|
||||
* @title Rechercher
|
||||
*/
|
||||
public function search() {
|
||||
return file_get_contents(DIR."/html/search.html");
|
||||
|
@ -11,6 +11,7 @@ class LoginController extends Controller {
|
||||
|
||||
/**
|
||||
* @route /^\/login\/$/
|
||||
* @title Login
|
||||
*/
|
||||
public function login() {
|
||||
|
||||
@ -38,6 +39,7 @@ class LoginController extends Controller {
|
||||
|
||||
/**
|
||||
* @route /^\/register\/$/
|
||||
* @title Register
|
||||
*/
|
||||
public function register() {
|
||||
if(isset($_POST["password"]) && isset($_POST["username"]) && Author::getByUsername($_POST["username"]) === null) {
|
||||
|
@ -7,10 +7,11 @@ use App\DB\Post;
|
||||
use App\DB\Tag;
|
||||
|
||||
|
||||
class AddEditController extends Controller {
|
||||
class PostController extends Controller {
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/edit\/$/
|
||||
* @editor
|
||||
* @title Modification d'article
|
||||
*/
|
||||
public function postEdit() {
|
||||
if(isset($_GET["post"]) && isset($_GET["title"]) && isset($_GET["category"]) && isset($_GET["content"]) && isset($_GET["tags"])) {
|
||||
@ -42,6 +43,7 @@ class AddEditController extends Controller {
|
||||
/**
|
||||
* @route /^\/post\/new\/*$/
|
||||
* @editor
|
||||
* @title Ajout d'Article
|
||||
*/
|
||||
public function postAdd() {
|
||||
|
||||
@ -75,4 +77,13 @@ class AddEditController extends Controller {
|
||||
|
||||
return file_get_contents(DIR."/html/post_new.html");
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @route /^\/post\/[0-9]+\/$/
|
||||
* @title Article
|
||||
*/
|
||||
public function post() {
|
||||
return file_get_contents(DIR."/html/post.html");
|
||||
}
|
||||
}
|
48
assets/php/Controller/UserController.php
Normal file
48
assets/php/Controller/UserController.php
Normal file
@ -0,0 +1,48 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controller;
|
||||
use App\Controller;
|
||||
use App\DB\Author;
|
||||
|
||||
class UserController extends Controller {
|
||||
|
||||
|
||||
/**
|
||||
* @route /^\/users\/new\/$/
|
||||
* @admin
|
||||
* @title Ajouter un utilisateur
|
||||
*/
|
||||
public function addUser() {
|
||||
|
||||
if(isset($_POST["username"]) && isset($_POST["password"]) && isset($_POST["role"])) {
|
||||
$user = new Author();
|
||||
$user->setUsername($_POST["username"]);
|
||||
$user->setPassword($_POST["password"]);
|
||||
Author::add($user);
|
||||
header("Location: /users/");
|
||||
}
|
||||
|
||||
return \file_get_contents(DIR . "/html/user_add.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/users\/$/
|
||||
* @admin
|
||||
* @title liste des utilisateurs
|
||||
*/
|
||||
public function listUser() {
|
||||
return \file_get_contents(DIR."/html/user_list.html");
|
||||
}
|
||||
|
||||
/**
|
||||
* @route /^\/user\/edit\/$/
|
||||
* @admin
|
||||
* @title Modifier un utilisateur
|
||||
*/
|
||||
public function editUser() {
|
||||
return \file_get_contents(DIR."/html/user_edit.html");
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
18
assets/php/Tags/Element.php
Normal file
18
assets/php/Tags/Element.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tags;
|
||||
|
||||
use DomXPath;
|
||||
|
||||
class Element extends Tag {
|
||||
public function render() {
|
||||
$el = $this->getElement();
|
||||
$term = isset($_GET["term"]) ? $_GET["term"] : "";
|
||||
if($el->hasAttribute("el")) $el->parentNode->insertBefore($this->getDoc()->createTextNode($term), $el);
|
||||
else {
|
||||
$finder = new DomXPath($this->getDoc());
|
||||
$nodes = $finder->query("//*[contains(@class, 'el-search')]");
|
||||
if(count($nodes) >= 1) $nodes[0]->setAttribute("value", $term);
|
||||
}
|
||||
}
|
||||
}
|
@ -20,15 +20,24 @@ class IsLoggedIn extends Tag {
|
||||
|
||||
$el = $this->getElement();
|
||||
|
||||
|
||||
if(isset($_SESSION["author"])) {
|
||||
if($el->hasAttribute("role") || !$_SESSION["author"]->getRole() == "ROLE_ADMIN") {
|
||||
$loggedin = $el->getAttribute("role") == $_SESSION["author"]->getRole();
|
||||
} else $loggedin = true;
|
||||
} else $loggedin = false;
|
||||
|
||||
|
||||
//debugging purpose
|
||||
$loggedin = false;
|
||||
// $loggedin = false;
|
||||
// var_dump($loggedin);
|
||||
|
||||
foreach ($el->getElementsByTagName("if") as $element) {
|
||||
if($element->hasAttribute("true") && $loggedin) {
|
||||
$r = $element->childNodes->item(1);
|
||||
$r = $element->childNodes->item(0);
|
||||
$el->parentNode->insertBefore($r, $el);
|
||||
} elseif ($element->hasAttribute("false")) {
|
||||
$r = $element->childNodes->item(1);
|
||||
} elseif ($element->hasAttribute("false") && !isset($_SESSION["author"])) {
|
||||
$r = $element->childNodes->item(0);
|
||||
$el->parentNode->insertBefore($r, $el);
|
||||
}
|
||||
}
|
||||
|
@ -28,8 +28,10 @@ class Loop extends Tag {
|
||||
$category = $el->getAttribute("category") != '' ? Post::get($_GET["post"])->getCategory()->getId() : $category;
|
||||
$tag = isset($_GET["tag"]) && intval($_GET["tag"]) ? (int) $_GET["tag"] : -1;
|
||||
|
||||
$term = isset($_GET["term"]) ? $_GET["term"] : "";
|
||||
|
||||
if($category != -1) {
|
||||
$posts = Post::listByCategory($category, $isRecent, $limit);
|
||||
$posts = Post::listByCategory($category, $isRecent, $limit, $term);
|
||||
if(isset($_GET["post"])) {
|
||||
$postsList = array();
|
||||
foreach ($posts as $post) {
|
||||
@ -38,7 +40,7 @@ class Loop extends Tag {
|
||||
$posts = $postsList;
|
||||
}
|
||||
} else {
|
||||
$posts = Post::list($isRecent, $limit);
|
||||
$posts = Post::list($isRecent, $limit, $term);
|
||||
}
|
||||
|
||||
if($tag != -1) {
|
||||
|
@ -81,6 +81,11 @@ class Tag {
|
||||
$head->item(0)->appendChild($t);
|
||||
}
|
||||
|
||||
$title = $dom->getElementsByTagName("title");
|
||||
if($title->count() >= 1) {
|
||||
$title->item(0)->appendChild($dom->createTextnode($_GET["page_title"]));
|
||||
}
|
||||
|
||||
|
||||
$list = $dom->getElementsByTagName("tag");
|
||||
|
||||
|
@ -4,6 +4,7 @@ namespace App\Tags;
|
||||
|
||||
use App\Tags\Tag;
|
||||
use App\DB\Post;
|
||||
use App\DB\Tag as AppTag;
|
||||
|
||||
class Tags extends Tag {
|
||||
public function render() {
|
||||
@ -12,12 +13,17 @@ class Tags extends Tag {
|
||||
|
||||
$doc = $this->getDoc();
|
||||
|
||||
$post = Post::get($_GET["post"]);
|
||||
$tags = isset($_GET["post"]) ? Post::get($_GET["post"])->getTags() : AppTag::list();
|
||||
/** @var \App\DB\Tag $tag */
|
||||
foreach ($post->getTags() as $tag) {
|
||||
foreach ($tags as $tag) {
|
||||
$res = $doc->createElement("a");
|
||||
$res->setAttribute("href", "/search/?tag=" . $tag->getId());
|
||||
$res->setAttribute("class", "tag");
|
||||
$url = "?tag=" . $tag->getId();
|
||||
if(isset($_GET["term"])) $url .= "&term=" . $_GET["term"];
|
||||
if(isset($_GET["category"])) $url .= "&category=" . $_GET["category"];
|
||||
$res->setAttribute("href", "/search/" . $url);
|
||||
$classes = "tag";
|
||||
if(isset($_GET["tag"]) && $tag->getId() == $_GET["tag"]) $classes .= " active";
|
||||
$res->setAttribute("class", $classes);
|
||||
$text = $doc->createTextNode($tag->getName());
|
||||
$res->appendChild($text);
|
||||
$pok->parentNode->insertBefore($res, $pok);
|
||||
|
@ -5,6 +5,10 @@ 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);
|
||||
if(isset($_SESSION["author"])) {
|
||||
$col = $el->getAttribute("column");
|
||||
$func = "get" . ucfirst($col);
|
||||
$el->parentNode->insertBefore($this->getDoc()->createTextNode($_SESSION["author"]->$func()), $el);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
15
assets/php/Tags/UserEditor.php
Normal file
15
assets/php/Tags/UserEditor.php
Normal file
@ -0,0 +1,15 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tags;
|
||||
|
||||
use App\DB\Category;
|
||||
use DateTime;
|
||||
use App\DB\Tag;
|
||||
use App\DB\Post;
|
||||
|
||||
|
||||
class UserEditor extends \App\Tags\Tag {
|
||||
public function render() {
|
||||
|
||||
}
|
||||
}
|
36
assets/php/Tags/Users.php
Normal file
36
assets/php/Tags/Users.php
Normal file
@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
namespace App\Tags;
|
||||
|
||||
use App\DB\Author;
|
||||
|
||||
|
||||
class Users extends Tag {
|
||||
public function render() {
|
||||
$el = $this->getElement();
|
||||
$doc = $this->getDoc();
|
||||
$parent = $el->parentNode;
|
||||
foreach (Author::list(true, 1000) as $user) {
|
||||
$pok = $el->childNodes->item(0)->cloneNode(true);
|
||||
|
||||
$parent->insertBefore($pok, $el);
|
||||
|
||||
$elements = $pok->getElementsByTagName("loop");
|
||||
|
||||
foreach ($elements as $ele) {
|
||||
$col = 'get' . ucfirst($ele->getAttribute("column"));
|
||||
$txt = $doc->createTextNode($user->$col());
|
||||
$ele->parentNode->insertBefore($txt, $ele);
|
||||
}
|
||||
|
||||
$loop = $pok->getElementsByTagName("loop");
|
||||
|
||||
while ($loop->count() >= 1) {
|
||||
$loop->item(0)->parentNode->removeChild($loop->item(0));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -137,12 +137,17 @@ class Post {
|
||||
* @return Post[]
|
||||
*/
|
||||
|
||||
public static function list($recent = true, $limit = 100) {
|
||||
public static function list($recent = true, $limit = 100, $term = "") {
|
||||
$sort = $recent ? "DESC" : "ASC";
|
||||
$query = "SELECT * FROM posts ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||
$query = "SELECT * FROM posts WHERE title LIKE :el OR content LIKE :el ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$posts = $pdo->query($query)->fetchAll();
|
||||
|
||||
$prp = $pdo->prepare($query);
|
||||
$term = "%" . $term . "%";
|
||||
$prp->bindValue(":el", $term);
|
||||
$prp->execute();
|
||||
$posts = $prp->fetchAll();
|
||||
|
||||
$res = array();
|
||||
|
||||
@ -163,13 +168,22 @@ class Post {
|
||||
return $res;
|
||||
}
|
||||
|
||||
public static function listByCategory($categoryId = null, $recent = true, $limit = 100) {
|
||||
public static function listByCategory($categoryId = null, $recent = true, $limit = 100, $el = "") {
|
||||
$sort = $recent ? "DESC" : "ASC";
|
||||
$cat = $categoryId !== null ? "WHERE category=" . $categoryId : "";
|
||||
$query = "SELECT * FROM posts " . $cat . " ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||
$cat = $categoryId !== null ? "AND category=" . $categoryId : "";
|
||||
$query = "SELECT * FROM posts WHERE (title LIKE :el OR content LIKE :el ) " . $cat . " ORDER BY dt " . $sort . " LIMIT " . $limit;
|
||||
|
||||
$pdo = Functions::connect();
|
||||
$posts = $pdo->query($query)->fetchAll();
|
||||
|
||||
$prp = $pdo->prepare($query);
|
||||
|
||||
$el = "%" . $el . "%";
|
||||
|
||||
$prp->bindValue(":el", $el);
|
||||
$prp->execute();
|
||||
// var_dump($prp->errorInfo());
|
||||
// die;
|
||||
$posts = $prp->fetchAll();
|
||||
|
||||
$res = array();
|
||||
|
||||
|
Reference in New Issue
Block a user