Commit 919427bd authored by Corentin Bettiol's avatar Corentin Bettiol 💻

change project/blog organization

parent 8f90b9e5
<?php <?php
// session pour quand on est admin
session_start(); session_start();
// le gros gros controlleur (peut-être le casser en plusieurs morceaux plus tard)
require_once("site/controller/mainController.php"); require_once("site/controller/mainController.php");
// afficher le contenu (qui va switcher sur le contenu dynamique à afficher)
require_once("site/layout/layout.php"); require_once("site/layout/layout.php");
?> ?>
\ No newline at end of file
<?php <?php
// fichier de config pour la bdd & le compte pour la partie administrateur
require_once("site/model/config.php"); require_once("site/model/config.php");
// connexion à la base de données
require_once("site/model/Base.php"); require_once("site/model/Base.php");
// classe pour l'administration du contenu du site
require_once("site/model/AdminManager.php"); require_once("site/model/AdminManager.php");
// classe pour la gesion des billets de blog
require_once("site/model/BlogManager.php"); require_once("site/model/BlogManager.php");
// classe pour la gestion des projets
require_once("site/model/ProjectsManager.php"); require_once("site/model/ProjectsManager.php");
// récupérer le nom de la page en fonction de l'url
// premier texte = affiché dans l'onglet (title), second texte = voir le switch dans site/layout/layout.php
function getPageName(){ function getPageName(){
// si on a une url personnalisée
if(isset($_GET['action'])){ if(isset($_GET['action'])){
switch ($_GET['action']) { switch ($_GET['action']) {
case 'contact': case 'contact': // contact
return ["Contact", "contact"]; return ["Contact", "contact"];
break; break;
case 'about': case 'about': // à propos
return ["À Propos", "about"]; return ["À Propos", "about"];
break; break;
case 'projects': case 'projects': // projets
return ["Projets", "projects"]; return ["Projets", "projects"];
break; break;
case 'project': case 'project': // projet
return ["Projet", "project"]; return ["Projet", "project"];
break; break;
case 'changelog': case 'changelog': // historique des versions
return ["Changelog", "changelog"]; return ["Changelog", "changelog"];
break; break;
case 'eplucher': case 'eplucher': // déconnexion (la première valeur n'est jamais utilisée)
return ["COUCOU AHAH", "eplucher"]; return ["COUCOU AHAH", "eplucher"];
break; break;
case 'rss': case 'rss': // rss
return ["Rss", "rss"]; return ["Rss", "rss"];
break; break;
case '404': case '404': // page not found
return ["Erreur 404 - File not found", "404"]; return ["Erreur 404 - File not found", "404"];
break; break;
case 'article': case 'article': // billet de blog
return [$_GET['title'], $_GET['title']]; return [$_GET['title'], $_GET['title']];
break; break;
case 'patate': case 'patate': // administration
return ["Administration", "administration"]; return ["Administration", "administration"];
break; break;
default: default: // si l'argument n'est pas compris on affiche le blog
return ["Blog", "blog"]; return ["Blog", "blog"];
break; break;
} }
} }
// si on est sur l'accueil du site
else{ else{
return ["Blog", "blog"]; return ["Blog", "blog"];
} }
} }
// affiche le menu du site (avec le titre de la page)
function writeMenu($pageName){ function writeMenu($pageName){
?> ?>
<ul id="listMenu"> <ul id="listMenu">
...@@ -60,40 +74,46 @@ function writeMenu($pageName){ ...@@ -60,40 +74,46 @@ function writeMenu($pageName){
</ul> </ul>
<?php } <?php }
// affiche la page du blog
function writeBlogPage($pageName){ function writeBlogPage($pageName){
// si on n'accède pas au fichier mais bien au site (var définie)
if($pageName[1] == "blog"){ if($pageName[1] == "blog"){
$blog = new BlogManager(); $blog = new BlogManager(NULL, NULL, NULL, NULL, NULL, NULL); // on a un blogmanager
// si on affiche un post en particulier
if(isset($_GET['title'])){ if(isset($_GET['title'])){
$title = urldecode($_GET['title']); $title = urldecode($_GET['title']);
$blogpost = $blog->getBlogPost($title); $blogpost = $blog->get($title);
if($blogpost != false) if($blogpost != false)
require("site/view/public/blogPostView.php"); require("site/view/public/blogPostView.php");
else else
header("Location:/404"); header("Location:/404");
} }
// si on affiche la liste des posts
else{ else{
$blogposts = $blog->getBlog(0); $blogposts = $blog->getPage(0);
require("site/view/public/blogView.php"); require("site/view/public/blogView.php");
} }
} }
} }
// affiche la liste des projets
function writeProjectsPage($pageName){ function writeProjectsPage($pageName){
$projects = new ProjectManager(); $projects = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
$projects = $projects->getProjects(); $projects = $projects->getProjects();
require("site/view/public/projectsView.php"); require("site/view/public/projectsView.php");
} }
// affiche un projet en particulier
function writeProjectPage($pageName){ function writeProjectPage($pageName){
$project = new ProjectManager(); $project = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
if(isset($_GET['title'])){ if(isset($_GET['title'])){
$title = urldecode($_GET['title']); $title = urldecode($_GET['title']);
$project = $project->getProject($title); $project = $project->get($title);
if($project != false){ if($project != false){
$project['pageProject'] = true; $project['pageProject'] = true;
require("site/view/public/projectView.php"); require("site/view/public/projectView.php");
...@@ -106,6 +126,7 @@ function writeProjectPage($pageName){ ...@@ -106,6 +126,7 @@ function writeProjectPage($pageName){
require("site/view/public/projectsView.php"); require("site/view/public/projectsView.php");
} }
// tente de connecter l'administrateur
function loginAdminPage($pageName){ function loginAdminPage($pageName){
if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){ if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
$_SESSION['user'] = $_POST['user']; $_SESSION['user'] = $_POST['user'];
...@@ -116,7 +137,7 @@ function loginAdminPage($pageName){ ...@@ -116,7 +137,7 @@ function loginAdminPage($pageName){
header("Location:/patate"); header("Location:/patate");
} }
// afficher le panneau d'administration & gère l'administration du site
function writeAdminPage($pageName){ function writeAdminPage($pageName){
$admin = new AdminManager(); $admin = new AdminManager();
if($admin->verifyAdminConnect()){ if($admin->verifyAdminConnect()){
...@@ -184,10 +205,11 @@ function writeAdminPage($pageName){ ...@@ -184,10 +205,11 @@ function writeAdminPage($pageName){
require("site/view/private/loginFormView.php"); require("site/view/private/loginFormView.php");
} }
// déconnexion de la partie administration
function decoAdminPage(){ function decoAdminPage(){
$_SESSION = array(); $_SESSION = array();
header("Location:/"); header("Location:/");
} }
// on récupère le nom de la page ici (avant d'inclure le layout)
$pageName = getPageName(); $pageName = getPageName();
\ No newline at end of file
...@@ -4,10 +4,10 @@ ...@@ -4,10 +4,10 @@
<meta charset="utf-8" /> <meta charset="utf-8" />
<meta name="description" content="Site perso de Corentin Bettiol." /> <meta name="description" content="Site perso de Corentin Bettiol." />
<meta name="viewport" content="width=device-width" /> <meta name="viewport" content="width=device-width" />
<title>l3m website - <?php echo $pageName[0]; ?></title> <title>l3m website - <?php echo $pageName[0]; // voir getPageName() dans mainController ?></title>
<link rel="stylesheet" href="/css/design.css" /> <link rel="stylesheet" href="/css/design.css" />
<?php <?php
if($pageName[1] == 404){ ?> if($pageName[1] == 404){ // le css pour la page 404 ?>
<link rel="stylesheet" href="/css/404.css" /> <link rel="stylesheet" href="/css/404.css" />
<?php } ?> <?php } ?>
<link rel="icon" type="image/png" href="img/icon.png" /> <link rel="icon" type="image/png" href="img/icon.png" />
...@@ -29,49 +29,50 @@ ...@@ -29,49 +29,50 @@
--><h1 id="title">l3m website</h1> --><h1 id="title">l3m website</h1>
</header> </header>
<nav id="menu"> <nav id="menu">
<?php writeMenu($pageName[0]); ?> <?php writeMenu($pageName[0]); // voir mainController ?>
</nav> </nav>
</header> </header>
<?php switch ($pageName[1]) { <?php
case 'blog': // le gros switch qui fait peur
writeBlogPage($pageName); switch ($pageName[1]){
case 'blog': // blog
writeBlogPage($pageName); // voir mainController
break; break;
case 'about': case 'about': // à propos
require("site/view/public/about.php"); require("site/view/public/about.php"); // statique
break; break;
case 'projects': case 'projects': // projets
writeProjectsPage($pageName); writeProjectsPage($pageName); // voir mainController
break; break;
case 'project': case 'project': // projet en particulier
writeProjectPage($pageName); writeProjectPage($pageName); // voir mainController
break; break;
case 'eplucher': case 'eplucher': // déconnexion du panneau d'administration
decoAdminPage(); decoAdminPage(); // voir mainController
case 'contact': case 'contact': // contact
require("site/view/public/contact.php"); require("site/view/public/contact.php"); // statique
break; break;
case 'changelog': case 'changelog': // historique de développement
require("site/view/public/changelog.php"); require("site/view/public/changelog.php"); // statique
break; break;
case 'rss': case 'rss': // rss
require("site/view/public/rss.php"); require("site/view/public/rss.php"); // todo
break; break;
case '404': case '404': // page not found
require("site/view/public/404.php"); require("site/view/public/404.php"); // statique
break; break;
case 'administration': case 'administration': // panneau d'administration (url = patate)
// si on envoie les données en post
if(isset($_POST['user']) && isset($_POST['pass'])){ if(isset($_POST['user']) && isset($_POST['pass'])){
loginAdminPage($pageName); loginAdminPage($pageName);
} }
// afficher le login screen
else{ else{
writeAdminPage($pageName); writeAdminPage($pageName);
} }
break; break;
case 'eplucher': default: // page non connue (n'est pas senser arriver)
decoAdminPage();
break;
default:
header('Location:/404'); header('Location:/404');
break; break;
} ?> } ?>
......
...@@ -17,14 +17,14 @@ class AdminManager extends Base ...@@ -17,14 +17,14 @@ class AdminManager extends Base
public function getBlogPost($link) public function getBlogPost($link)
{ {
$blogpost = new BlogManager(); $blogpost = new BlogManager(NULL, NULL, NULL, NULL, NULL, NULL); // moche :c
return $blogpost->getBlogPost($link); return $blogpost->get($link);
} }
public function getProject($link) public function getProject($link)
{ {
$project = new ProjectManager(); $project = new ProjectManager(NULL,NULL,NULL,NULL,NULL); // moche :c
return $project->getProject($link); return $project->get($link);
} }
...@@ -33,133 +33,34 @@ class AdminManager extends Base ...@@ -33,133 +33,34 @@ class AdminManager extends Base
} }
public function updateBlogPost(){ public function updateBlogPost(){
$time = htmlspecialchars($_POST['time']); $blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['comments'], $_POST['id']);
$title = htmlspecialchars($_POST['title']); $blog->update();
$content = htmlspecialchars($_POST['content']);
$shortContent = htmlspecialchars($_POST['shortContent']);
$comments = 0;
if($_POST['comments'] == "on")
$comments = 1;
$id = htmlspecialchars($_POST['id']);
$db = $this->dbConnect();
$req = $db->prepare('UPDATE l3m_blog SET time = :time, title = :title, content = :content, shortContent = :shortContent, comments = :comments WHERE id = :id');
$req->execute(array(
'time' => $time,
'title' => $title,
'content' => $content,
'shortContent' => $shortContent,
'comments' => $comments,
'id' => $id
));
} }
public function updateProject(){ public function updateProject(){
$name = htmlspecialchars($_POST['name']); $project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$link = htmlspecialchars($_POST['link']); $project->update();
$content = htmlspecialchars($_POST['content']);
$shortContent = htmlspecialchars($_POST['shortContent']);
$id = htmlspecialchars($_POST['id']);
$db = $this->dbConnect();
$req = $db->prepare('UPDATE l3m_projects SET name = :name, link = :link, content = :content, shortContent = :shortContent WHERE id = :id');
$req->execute(array(
'name' => $name,
'link' => $link,
'content' => $content,
'shortContent' => $shortContent,
'id' => $id
));
} }
public function sendBlogPost(){ public function sendBlogPost(){
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['comments'], $_POST['id']);
$time = htmlspecialchars($_POST['time']); $blog->send();
if($time == ""){
$time = new datetime();
$time = $time->format('Y-m-d H:i:s');
}
$title = htmlspecialchars($_POST['title']);
if(strlen($title) < 1){
header("Location:/patate");
exit();
}
$content = htmlspecialchars($_POST['content']);
$shortContent = htmlspecialchars($_POST['shortContent']);
if(strlen($shortContent) < 1){
$shortContent = "Ce billet de blog ne dispose d'aucune description.";
}
$comments = 0;
if($_POST['comments'] == "on")
$comments = 1;
$db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_blog(time, title, content, shortcontent, comments) VALUES(:time, :title, :content, :shortContent, :comments)');
$req->execute(array(
'time' => $time,
'title' => $title,
'content' => $content,
'shortContent' => $shortContent,
'comments' => $comments
));
} }
public function sendProject(){ public function sendProject(){
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$name = htmlspecialchars($_POST['name']); $project->sendProject();
if(strlen($name) < 1){
header("Location:/patate");
exit();
}
$link = htmlspecialchars($_POST['link']);
$content = htmlspecialchars($_POST['content']);
$shortContent = htmlspecialchars($_POST['shortContent']);
if(strlen($shortContent) < 1){
$shortContent = "Pas de description.";
}
$id = htmlspecialchars($_POST['id']);
$db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_projects(name, link, content, shortcontent) VALUES(:name, :link, :content, :shortContent)');
$req->execute(array(
'name' => $name,
'link' => $link,
'content' => $content,
'shortContent' => $shortContent
));
} }
public function deleteBlogPost($link){ public function deleteBlogPost($link){
$title = str_replace("-", " ", $link); $blog = new BlogManager(NULL, NULL, NULL, NULL, NULL, NULL);
$blog->deleteBlogPost($link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_blog WHERE title = :title');
$req->execute(array(
'title' => $title
));
} }
public function deleteProject($link){ public function deleteProject($link){
$name = str_replace("-", " ", $link); $project = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
$project->deleteProject($link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_projects WHERE name = :name');
$req->execute(array(
'name' => $name
));
} }
} }
\ No newline at end of file
<?php <?php
// connexion à la bdd
class Base class Base
{ {
protected function dbConnect() protected function dbConnect()
......
<?php <?php
class BlogManager extends Base class BlogManager extends Base
{ {
public function getBlog($page) private $time;
{ private $title;
$start = $page*5; private $content;
$stop = $start + 5; private $shortContent;
private $comments;
private $id;
$db = $this->dbConnect(); function __construct($time, $title, $content, $shortContent, $comments, $id){
$req = $db->query('SELECT * FROM l3m_blog ORDER BY id DESC LIMIT '. $start .', '. $stop .''); $this->time = htmlspecialchars($time);
$this->title = htmlspecialchars($title);
$this->content = htmlspecialchars($content);
$this->shortContent = htmlspecialchars($shortContent);
if($comments == "on")
$this->comments = 1;
else
$this->comments = 0;
$this->id = htmlspecialchars($id);
return $req; }
}
public function getBlogPost($link) public function getPage($page)
{ {
$start = $page*5;
$stop = $start + 5;
$link = htmlspecialchars($link); $db = $this->dbConnect();
$req = $db->query('SELECT * FROM l3m_blog ORDER BY id DESC LIMIT '. $start .', '. $stop .'');
$title = str_replace("-", " ", $link); return $req;
}
$db = $this->dbConnect(); public function get($link)
$req = $db->prepare('SELECT * FROM l3m_blog WHERE title = ?'); {
$req->execute(array($title));
$post = $req->fetch();
if($post == false) $link = htmlspecialchars($link);
return false;
$post["link"] = urlencode($link); $title = str_replace("-", " ", $link);
$post['datetime'] = new DateTime($post['time']);
return $post; $db = $this->dbConnect();
} $req = $db->prepare('SELECT * FROM l3m_blog WHERE title = ?');
$req->execute(array($title));
$post = $req->fetch();
if($post == false)
return false;
$post["link"] = urlencode($link);
$post['datetime'] = new DateTime($post['time']);
return $post;
}
// todo vérifier qu'on poste pas un truc vide
public function update(){
$db = $this->dbConnect();
$req = $db->prepare('UPDATE l3m_blog SET time = :time, title = :title, content = :content, shortContent = :shortContent, comments = :comments WHERE id = :id');
$req->execute(array(
'time' => $this->time,
'title' => $this->title,
'content' => $this->content,
'shortContent' => $this->shortContent,
'comments' => $this->comments,
'id' => $this->id
));
}
public function send(){
if($this->time == ""){
$this->time = new datetime();
$this->time = $this->time->format('Y-m-d H:i:s');
}
if(strlen($this->title) < 1){
header("Location:/patate");
exit();
}
if(strlen($this->shortContent) < 1){
$this->shortContent = "Ce billet de blog ne dispose d'aucune description.";
}
$db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_blog(time, title, content, shortcontent, comments) VALUES(:time, :title, :content, :shortContent, :comments)');
$req->execute(array(
'time' => $this->time,
'title' => $this->title,
'content' => $this->content,
'shortContent' => $this->shortContent,
'comments' => $this->comments
));
}
public function delete($link){
$title = str_replace("-", " ", $link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_blog WHERE title = :title');
$req->execute(array(
'title' => $title
));
}
} }
\ No newline at end of file
<?php <?php
class ProjectManager extends Base class ProjectManager extends Base
{ {
public function getProjects() private $name;
{ private $link;
$db = $this->dbConnect(); private $content;
$req = $db->query('SELECT * FROM l3m_projects ORDER BY id DESC'); private $shortContent;
private $id;
function __construct($name, $link, $content, $shortContent, $id){
$this->name = htmlspecialchars($name);
$this->link = htmlspecialchars($link);
$this->content = htmlspecialchars($content);
$this->shortContent = htmlspecialchars($shortContent);
$this->id = htmlspecialchars($id);
}
public function getProjects()
{
$db = $this->dbConnect();
$req = $db->query('SELECT * FROM l3m_projects ORDER BY id DESC');
return $req;
}
return $req; public function get($link)
} {
$link = htmlspecialchars($link);
$name = str_replace("-", " ", $link);
public function getProject($link) $db = $this->dbConnect();
{ $req = $db->prepare('SELECT * FROM l3m_projects WHERE name = ?');
$link = htmlspecialchars($link); $req->execute(array($name));