Commit 3e33e9c7 authored by Corentin Bettiol's avatar Corentin Bettiol 💻

remove hr, add adminController, remove comments concept, add admin link in all pages if connected

parent ebe5a9ea
...@@ -66,18 +66,17 @@ h2{ ...@@ -66,18 +66,17 @@ h2{
h3 a{ h3 a{
text-decoration: none; text-decoration: none;
text-shadow: 0 0 1px #69f; text-shadow: 0 0 1px #69f;
transition: padding-left 0.3s, text-shadow 0.3s, color 0.3s; transition: color 0.3s;
} }
h3 a:hover{ h3 a:hover{
padding-left: 5px; color: #47476b;
text-shadow: -5px 0 4px #BBf; text-shadow: 0 0 1px #69f;
transition: padding-left 0.3s, text-shadow 0.3s, color 0.3s; transition: color 0.3s;
} }
#listMenu{ #listMenu{
padding: 0; padding: 0;
width: auto;
display: flex; display: flex;
margin: 15px 0; margin: 15px 0;
flex-direction: row; flex-direction: row;
...@@ -103,6 +102,7 @@ article{ ...@@ -103,6 +102,7 @@ article{
margin: 20px 0; margin: 20px 0;
padding: 5px 15px; padding: 5px 15px;
background-color: #f0f0f0; background-color: #f0f0f0;
border-bottom: 3px solid #ccc;
} }
#listMenu .selected{ #listMenu .selected{
...@@ -123,11 +123,6 @@ article .postInfos{ ...@@ -123,11 +123,6 @@ article .postInfos{
background-color: #f0f0f0; background-color: #f0f0f0;
} }
hr{
width: 66%;
border: 1px solid #ccc;
}
a{ a{
transition: color 0.3s; transition: color 0.3s;
} }
...@@ -156,10 +151,13 @@ input, textarea{ ...@@ -156,10 +151,13 @@ input, textarea{
margin: 0 0 0 20px; margin: 0 0 0 20px;
} }
#inputContent{
height: 10em;
}
input:hover, input:focus, textarea:hover, textarea:focus{ input:hover, input:focus, textarea:hover, textarea:focus{
padding-left: 10px;
border-left: 3px solid #ccc; border-left: 3px solid #ccc;
transition: border-left 0.05s, padding-left 0.05s; transition: border-left 0.05s;
} }
...@@ -175,25 +173,6 @@ input[type="submit"]:hover{ ...@@ -175,25 +173,6 @@ input[type="submit"]:hover{
transition: background-color 0.3s; transition: background-color 0.3s;
} }
input[type="checkbox"]{
width: 30px;
height: 30px;
margin: 15px;
cursor: pointer;
appearance: none;
border-width: 0;
display: inline-block;
box-sizing: border-box;
background-color: #eaa;
-webkit-appearance: none;
transition: background-color 0.3s;
}
input[type="checkbox"]:checked{
background-color: #aea;
transition: background-color 0.3s;
}
label{ label{
display: inline-block; display: inline-block;
width: 250px; width: 250px;
...@@ -201,7 +180,7 @@ label{ ...@@ -201,7 +180,7 @@ label{
background-color: #d9d9d9; background-color: #d9d9d9;
} }
label.large{ label .large{
width: 300px; width: 300px;
} }
...@@ -213,6 +192,7 @@ form .small{ ...@@ -213,6 +192,7 @@ form .small{
display: flex; display: flex;
align-items: flex-start; align-items: flex-start;
justify-content: center; justify-content: center;
flex-wrap: wrap;
} }
#listAdmin{ #listAdmin{
...@@ -304,6 +284,28 @@ Media Queries ...@@ -304,6 +284,28 @@ Media Queries
} }
} }
@media all and (max-width: 700px){
input, textarea, label{
width: 100%;
}
label{
margin-right: 20px;
}
#menu{
width: 100%;
}
#listMenu{
flex-direction: column;
justify-content: center;
}
#listMenu li, #listMenu h2, #listMenu a{
display: block;
width: 90%;
margin: 2px auto;
text-align: center;
}
}
@media all and (max-width: 500px){ @media all and (max-width: 500px){
#page{ #page{
font-size: 1em; font-size: 1em;
...@@ -312,30 +314,19 @@ Media Queries ...@@ -312,30 +314,19 @@ Media Queries
width: 45px; width: 45px;
height: 45px; height: 45px;
} }
#title{
margin-bottom: 15px;
}
#listMenu{ #listMenu{
width: 50%; width: 80%;
margin: auto; margin: auto;
flex-wrap: wrap;
justify-content: center;
}
#listMenu li, #listMenu h2, #listMenu a{
width: 100%;
} }
#listMenu li{ #listMenu li{
margin: 5px auto; margin: 3px auto;
text-align: center;
} }
#listMenu a{ #listMenu a{
margin: 0;
padding: 3px 0; padding: 3px 0;
display: inline-block;
} }
#listMenu .selected{ #listMenu .selected{
border: none; border: none;
background-color: #cccccc; background-color: #ccc;
} }
} }
......
...@@ -6,6 +6,9 @@ session_start(); ...@@ -6,6 +6,9 @@ session_start();
// le gros gros controlleur (peut-être le casser en plusieurs morceaux plus tard) // 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');
// le moins gros controlleur (oui c'est un morceau)
require_once('site/controller/adminController.php');
// afficher le contenu (qui va switcher sur le contenu dynamique à afficher) // afficher le contenu (qui va switcher sur le contenu dynamique à afficher)
require_once('site/layout/layout.php'); require_once('site/layout/layout.php');
......
...@@ -10,25 +10,9 @@ CREATE TABLE `l3m_blog` ( ...@@ -10,25 +10,9 @@ CREATE TABLE `l3m_blog` (
`time` datetime NOT NULL, `time` datetime NOT NULL,
`title` varchar(255) NOT NULL, `title` varchar(255) NOT NULL,
`content` text NOT NULL, `content` text NOT NULL,
`shortContent` varchar(255) NOT NULL DEFAULT 'Ce billet de blog ne dispose d''aucune description.', `shortContent` varchar(255) NOT NULL DEFAULT 'Ce billet de blog ne dispose d''aucune description.'
`comments` tinyint(4) NOT NULL DEFAULT '1'
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `l3m_blog` (`id`, `time`, `title`, `content`, `shortContent`, `comments`) VALUES
(1, '2019-01-10 00:00:00', 'Le premier article !', 'Contenu contenu contenu.', 'Le premier article du blog !', 1),
(2, '2019-01-14 12:08:00', 'Second article du blog !', 'L\'édition fonctionne.', 'WIP !', 1);
CREATE TABLE `l3m_comments` (
`id` int(11) NOT NULL,
`id_blog` int(11) NOT NULL,
`pseudo` varchar(255) NOT NULL,
`mail` varchar(255) NOT NULL,
`link` varchar(255) NOT NULL,
`content` text NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
CREATE TABLE `l3m_projects` ( CREATE TABLE `l3m_projects` (
`id` int(11) NOT NULL, `id` int(11) NOT NULL,
`name` varchar(255) NOT NULL, `name` varchar(255) NOT NULL,
...@@ -37,28 +21,8 @@ CREATE TABLE `l3m_projects` ( ...@@ -37,28 +21,8 @@ CREATE TABLE `l3m_projects` (
`shortContent` varchar(255) NOT NULL DEFAULT 'Pas de description.' `shortContent` varchar(255) NOT NULL DEFAULT 'Pas de description.'
) ENGINE=InnoDB DEFAULT CHARSET=latin1; ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
INSERT INTO `l3m_projects` (`id`, `name`, `link`, `content`, `shortContent`) VALUES
(1, 'l3m website', 'http://l3m.in', 'Ce site.', 'Pas de description.');
ALTER TABLE `l3m_blog` ALTER TABLE `l3m_blog`
ADD PRIMARY KEY (`id`); ADD PRIMARY KEY (`id`);
ALTER TABLE `l3m_comments`
ADD PRIMARY KEY (`id`),
ADD KEY `id_blog` (`id_blog`);
ALTER TABLE `l3m_projects`
ADD PRIMARY KEY (`id`);
ALTER TABLE `l3m_blog`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;
ALTER TABLE `l3m_comments`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `l3m_projects` ALTER TABLE `l3m_projects`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2; ADD PRIMARY KEY (`id`);
\ No newline at end of file
ALTER TABLE `l3m_comments`
ADD CONSTRAINT `l3m_comments_ibfk_1` FOREIGN KEY (`id_blog`) REFERENCES `l3m_blog` (`id`);
\ No newline at end of file
<?php
// classe pour l'administration du contenu du site
require_once('site/model/AdminManager.php');
// tente de connecter l'administrateur
function loginAdminPage($pageName){
if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
header('Location:/patate');
}
else
header('Location:/patate');
}
// afficher le panneau d'administration & gère l'administration du site
function writeAdminPage($pageName){
$admin = new AdminManager();
if($admin->verifyAdminConnect()){
if(isset($_GET['editb'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
if($blogpost = $admin->getBlogPost($title))
require('site/view/private/editblogView.php');
else
header('Location:/404');
}
else{
$admin->updateBlogPost();
header('Location:/patate');
}
}
else if(isset($_GET['editp'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$project = $admin->getProject($title);
require('site/view/private/editProjectView.php');
}
else{
$admin->updateProject();
header('Location:/patate');
}
}
else if(isset($_GET['submitb'])){
require('site/view/private/createBlogView.php');
}
else if(isset($_GET['submitp'])){
require('site/view/private/createProjectView.php');
}
else if(isset($_GET['sendb'])){
$admin->sendBlogPost();
header('Location:/');
}
else if(isset($_GET['sendp'])){
$admin->sendProject();
header('Location:/projects');
}
else if(isset($_GET['deleteb'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$admin->deleteBlogPost($title);
header('Location:/patate');
}
}
else if(isset($_GET['deletep'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$admin->deleteProject($title);
header('Location:/patate');
}
}
else{
$blogposts = $admin->getBlogPosts();
$projects = $admin->getProjects();
require('site/view/private/admin.php');
}
}
else
require('site/view/private/loginFormView.php');
}
// déconnexion de la partie administration
function decoAdminPage(){
$_SESSION = array();
header('Location:/');
}
\ No newline at end of file
...@@ -6,9 +6,6 @@ require_once('site/model/config.php'); ...@@ -6,9 +6,6 @@ require_once('site/model/config.php');
// connexion à la base de données // 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');
// classe pour la gesion des billets de blog // classe pour la gesion des billets de blog
require_once('site/model/BlogManager.php'); require_once('site/model/BlogManager.php');
...@@ -28,7 +25,7 @@ function getPageName(){ ...@@ -28,7 +25,7 @@ function getPageName(){
return ['À Propos', 'about']; return ['À Propos', 'about'];
break; break;
case 'projects': // projets case 'projects': // projets
return ['Projets', 'projects']; return ['Projets', 'project'];
break; break;
case 'project': // projet case 'project': // projet
return ['Projet', 'project']; return ['Projet', 'project'];
...@@ -45,9 +42,6 @@ function getPageName(){ ...@@ -45,9 +42,6 @@ function getPageName(){
case '404': // page not found case '404': // page not found
return ['Erreur 404 - File not found', '404']; return ['Erreur 404 - File not found', '404'];
break; break;
case 'article': // billet de blog
return [$_GET['title'], $_GET['title']];
break;
case 'patate': // administration case 'patate': // administration
return ['Administration', 'administration']; return ['Administration', 'administration'];
break; break;
...@@ -66,7 +60,13 @@ function getPageName(){ ...@@ -66,7 +60,13 @@ function getPageName(){
function writeMenu($pageName){ function writeMenu($pageName){
?> ?>
<ul id='listMenu'> <ul id='listMenu'>
<?php if($pageName == 'Administration'){ ?><li><h2><a href="/eplucher" class="selected">🔧</a></h2></li><?php } ?> <?php
if($pageName == 'Administration'){ ?>
<li><h2><a href="/eplucher" class="selected">🔧</a></h2></li>
<?php }
else if(isset($_SESSION['user'])){ ?>
<li><h2><a href="/patate" >🔧</a></h2></li>
<?php } ?>
<li><h2><a href="/" title="Blog" <?php if($pageName == 'Blog'){ ?>class="selected"<?php } ?>>Blog</a></h2></li> <li><h2><a href="/" title="Blog" <?php if($pageName == 'Blog'){ ?>class="selected"<?php } ?>>Blog</a></h2></li>
<li><h2><a href="/about" title="À propos" <?php if($pageName == 'À Propos'){ ?>class="selected"<?php } ?>>À propos</a></h2></li> <li><h2><a href="/about" title="À propos" <?php if($pageName == 'À Propos'){ ?>class="selected"<?php } ?>>À propos</a></h2></li>
<li><h2><a href="/projects" title="Projets" <?php if($pageName == 'Projets' || $pageName == 'Projet'){ ?>class="selected"<?php } ?>>Projets</a></h2></li> <li><h2><a href="/projects" title="Projets" <?php if($pageName == 'Projets' || $pageName == 'Projet'){ ?>class="selected"<?php } ?>>Projets</a></h2></li>
...@@ -99,116 +99,23 @@ function writeBlogPage($pageName){ ...@@ -99,116 +99,23 @@ function writeBlogPage($pageName){
} }
// affiche la liste des projets // affiche la liste des projets
function writeProjectsPage($pageName){
$projects = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
$projects = $projects->getProjects();
require('site/view/public/projectsView.php');
}
// affiche un projet en particulier
function writeProjectPage($pageName){ function writeProjectPage($pageName){
$project = new ProjectManager(NULL, NULL, NULL, NULL, NULL); $project = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
// si on affiche un projet en particulier
if(isset($_GET['title'])){ if(isset($_GET['title'])){
$title = urldecode($_GET['title']); $title = urldecode($_GET['title']);
$project = $project->get($title); $project = $project->get($title);
if($project != false){ if($project != false)
$project['pageProject'] = true;
require('site/view/public/projectView.php'); require('site/view/public/projectView.php');
} else
else{
header('Location:/404'); header('Location:/404');
}
} }
else // si on affiche la liste des projets
else{
$projects = $project->getProjects();
require('site/view/public/projectsView.php'); require('site/view/public/projectsView.php');
}
// tente de connecter l'administrateur
function loginAdminPage($pageName){
if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
$_SESSION['user'] = $_POST['user'];
$_SESSION['pass'] = $_POST['pass'];
header('Location:/patate');
}
else
header('Location:/patate');
}
// afficher le panneau d'administration & gère l'administration du site
function writeAdminPage($pageName){
$admin = new AdminManager();
if($admin->verifyAdminConnect()){
if(isset($_GET['editb'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
if($blogpost = $admin->getBlogPost($title))
require('site/view/private/editblogView.php');
else
header('Location:/404');
}
else{
$admin->updateBlogPost();
header('Location:/patate');
}
}
else if(isset($_GET['editp'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$project = $admin->getProject($title);
require('site/view/private/editProjectView.php');
}
else{
$admin->updateProject();
header('Location:/patate');
}
}
else if(isset($_GET['submitb'])){
require('site/view/private/createBlogView.php');
}
else if(isset($_GET['submitp'])){
require('site/view/private/createProjectView.php');
}
else if(isset($_GET['sendb'])){
$admin->sendBlogPost();
header('Location:/');
}
else if(isset($_GET['sendp'])){
$admin->sendProject();
header('Location:/projects');
}
else if(isset($_GET['deleteb'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$admin->deleteBlogPost($title);
header('Location:/patate');
}
}
else if(isset($_GET['deletep'])){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$admin->deleteProject($title);
header('Location:/patate');
}
}
else{
$blogposts = $admin->getBlogPosts();
$projects = $admin->getProjects();
require('site/view/private/admin.php');
}
} }
else
require('site/view/private/loginFormView.php');
}
// déconnexion de la partie administration
function decoAdminPage(){
$_SESSION = array();
header('Location:/');
} }
// on récupère le nom de la page ici (avant d'inclure le layout) // on récupère le nom de la page ici (avant d'inclure le layout)
......
...@@ -42,10 +42,7 @@ ...@@ -42,10 +42,7 @@
case 'about': // à propos case 'about': // à propos
require('site/view/public/about.php'); // statique require('site/view/public/about.php'); // statique
break; break;
case 'projects': // projets case 'project': // projet
writeProjectsPage($pageName); // voir mainController
break;
case 'project': // projet en particulier
writeProjectPage($pageName); // voir mainController writeProjectPage($pageName); // voir mainController
break; break;
case 'eplucher': // déconnexion du panneau d'administration case 'eplucher': // déconnexion du panneau d'administration
...@@ -77,8 +74,6 @@ ...@@ -77,8 +74,6 @@
break; break;
} ?> } ?>
<hr />
<footer id="footer"> <footer id="footer">
<p> <p>
Site en vanilla html5/css3/php7, fait avec ♥ - <a href="/changelog" title="changelog">Changelog</a> - <a href="/rss" title="rss">RSS</a> - v5 Site en vanilla html5/css3/php7, fait avec ♥ - <a href="/changelog" title="changelog">Changelog</a> - <a href="/rss" title="rss">RSS</a> - v5
......
...@@ -5,18 +5,13 @@ class BlogManager extends Base ...@@ -5,18 +5,13 @@ class BlogManager extends Base
private $title; private $title;
private $content; private $content;
private $shortContent; private $shortContent;
private $comments;
private $id; private $id;
function __construct($time, $title, $content, $shortContent, $comments, $id){ function __construct($time, $title, $content, $shortContent, $id){
$this->time = htmlspecialchars($time); $this->time = htmlspecialchars($time);
$this->title = htmlspecialchars($title); $this->title = htmlspecialchars($title);
$this->content = htmlspecialchars($content); $this->content = htmlspecialchars($content);
$this->shortContent = htmlspecialchars($shortContent); $this->shortContent = htmlspecialchars($shortContent);
if($comments == 'on')
$this->comments = 1;
else
$this->comments = 0;
$this->id = htmlspecialchars($id); $this->id = htmlspecialchars($id);
} }
...@@ -56,13 +51,12 @@ class BlogManager extends Base ...@@ -56,13 +51,12 @@ class BlogManager extends Base
// todo vérifier qu'on poste pas un truc vide // todo vérifier qu'on poste pas un truc vide
public function update(){ public function update(){
$db = $this->dbConnect(); $db = $this->dbConnect();
$req = $db->prepare('UPDATE l3m_blog SET time = :time, title = :title, content = :content, shortContent = :shortContent, comments = :comments WHERE id = :id'); $req = $db->prepare('UPDATE l3m_blog SET time = :time, title = :title, content = :content, shortContent = :shortContent, WHERE id = :id');
$req->execute([ $req->execute([
'time' => $this->time, 'time' => $this->time,
'title' => $this->title, 'title' => $this->title,
'content' => $this->content, 'content' => $this->content,
'shortContent' => $this->shortContent, 'shortContent' => $this->shortContent,
'comments' => $this->comments,
'id' => $this->id 'id' => $this->id
]); ]);
} }
...@@ -81,13 +75,12 @@ class BlogManager extends Base ...@@ -81,13 +75,12 @@ class BlogManager extends Base
$this->shortContent = 'Ce billet de blog ne dispose d\'aucune description.'; $this->shortContent = 'Ce billet de blog ne dispose d\'aucune description.';
} }
$db = $this->dbConnect(); $db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_blog(time, title, content, shortcontent, comments) VALUES(:time, :title, :content, :shortContent, :comments)'); $req = $db->prepare('INSERT INTO l3m_blog(time, title, content, shortcontent) VALUES(:time, :title, :content, :shortContent)');
$req->execute([ $req->execute([
'time' => $this->time, 'time' => $this->time,
'title' => $this->title, 'title' => $this->title,
'content' => $this->content, 'content' => $this->content,
'shortContent' => $this->shortContent, 'shortContent' => $this->shortContent
'comments' => $this->comments
]); ]);
} }
......
...@@ -12,30 +12,25 @@ ...@@ -12,30 +12,25 @@
<form action="/patate/blog/send" method="post" accept-charset="utf-8"> <form action="/patate/blog/send" method="post" accept-charset="utf-8">
<article class="input"> <section class="input">
<label for="inputTitle">Titre</label> <label for="inputTitle">Titre</label>
<input type="text" name="title" placeholder="Titre" id="inputTitle" required /> <input type="text" name="title" placeholder="Titre" id="inputTitle" required />
</article> </section>
<article class="input"> <section class="input">
<label for="inputDate">Date de publication</label> <label for="inputDate">Date de publication</label>
<input type="datetime-local" name="time" placeholder="<?php echo $date->format("Y-m-d\TH:i:s"); ?>" class="small" id="inputDate" /> <input type="datetime-local" name="time" placeholder="<?php echo $date->format("Y-m-d\TH:i:s"); ?>" class="small" id="inputDate" />
</article> </section>
<article class="input"> <section class="input">
<label for="inputShortContent">Description</label> <label for="inputShortContent">Description</label>
<textarea name="shortContent" id="inputShortContent"></textarea> <textarea name="shortContent" id="inputShortContent"></textarea>
</article> </section>
<article class="input"> <section class="input">
<label for="inputContent">Contenu</label> <label for="inputContent">Contenu</label>
<textarea name="content" id="inputContent"></textarea> <textarea name="content" id="inputContent"></textarea>
</article> </section>
<article class="input">
<label for="inputComments" class="large">Autoriser les commentaires</label>
<input type="checkbox" name="comments" id="inputComments" checked />
</article>