Commit 8f90b9e5 authored by Corentin Bettiol's avatar Corentin Bettiol 💻

send/edit/delete a post or a project

parent 86643390
l3m_projects
id
name
link
content
shortContent
l3m_blog
id
time
title
content
comments (boolean)
l3m_comments
id
id_blog
pseudo
mail
link
content
\ No newline at end of file
......@@ -9,26 +9,26 @@ CSS
}
#page{
padding: 0;
width: 100%;
margin: auto;
padding: 0;
font-family: ubuntulight;
font-size: 1.5em;
font-family: ubuntulight;
background-color: #e3e3e3;
}
#header{
padding: 2px;
display: flex;
flex-direction: row;
justify-content: space-between;
align-items: center;
font-family: ubuntumono;
background-color: #f0f0f0;
padding: 2px;
border-bottom: 5px solid #ccc;
justify-content: space-between;
}
article p, #pageTitle, article h3, article ul, article form, #listAdmin{
article p, #pageTitle, article h3, article ul, article form, #listAdmin, .input{
max-width: 1500px;
margin: 30px auto;
}
......@@ -44,9 +44,9 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{
}
#title{
display: flex;
width: auto;
margin: auto;
display: flex;
color: #2E2E2E;
text-shadow: 0 0 3px #69f;
}
......@@ -56,11 +56,11 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{
}
h2{
display: inline-block;
margin: 0;
padding: 0;
font-weight: normal;
font-size: 1.5em;
font-weight: normal;
display: inline-block;
}
h3 a{
......@@ -76,13 +76,13 @@ h3 a:hover{
}
#listMenu{
list-style-type: none;
padding: 0;
width: auto;
display: flex;
margin: 15px 0;
flex-direction: row;
list-style-type: none;
justify-content: space-around;
width: auto;
margin: 15px 0;
padding: 0;
}
#listMenu a{
......@@ -116,11 +116,11 @@ article .postInfos{
#footer{
width: 98%;
background-color: #f0f0f0;
margin: auto;
padding: 1%;
text-align: center;
margin: auto;
font-size: 0.8em;
text-align: center;
background-color: #f0f0f0;
}
hr{
......@@ -137,34 +137,36 @@ a:hover{
transition: color 0.3s;
}
input{
input, textarea{
width: 50%;
display: block;
box-sizing: border-box;
margin: 15px auto;
border: none;
padding: 10px;
display: block;
font-size: 1em;
}
input[type="text"], input[type="password"]{
background-color: white;
border: none;
margin: 15px auto;
padding-left: 13px;
border-bottom: 3px solid #ccc;
box-sizing: border-box;
background-color: white;
border-left: 0px solid #ccc;
border-bottom: 3px solid #ccc;
transition: border-left 0.05s, padding-left 0.05s;
}
input[type="text"]:hover, input[type="password"]:hover, input[type="text"]:focus, input[type="password"]:focus{
border-left: 3px solid #ccc;
.input input, .input textarea{
margin: 0 0 0 20px;
}
input:hover, input:focus, textarea:hover, textarea:focus{
padding-left: 10px;
border-left: 3px solid #ccc;
transition: border-left 0.05s, padding-left 0.05s;
}
input[type="submit"]{
background-color: #ccc;
padding-left: 13px;
border: none;
background-color: #ccc;
transition: background-color 0.3s;
}
......@@ -173,6 +175,46 @@ input[type="submit"]:hover{
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{
display: inline-block;
width: 250px;
padding: 10px;
background-color: #d9d9d9;
}
label.large{
width: 300px;
}
form .small{
font-size: 0.7em;
}
.input{
display: flex;
align-items: flex-start;
justify-content: center;
}
#listAdmin{
display: flex;
flex-wrap: wrap;
......@@ -200,8 +242,8 @@ input[type="submit"]:hover{
}
.listAdmin b{
display: inline-block;
width: 50%;
display: inline-block;
border-right: 1px solid #ccc;
}
......@@ -209,14 +251,20 @@ input[type="submit"]:hover{
padding: 3px;
}
.editLink{
.listAdmin .postInfos{
width: 200px;
}
.button{
margin-left: 2px;
text-decoration: none;
background-color: #d9d9d9;
padding: 7px 7px 10px 7px;
border-bottom: 0px solid #ccc;
transition: background-color 0.3s, color 0.3s, border 0.05s, padding 0.05s;
}
.editLink:hover{
.button:hover{
background-color: #f0f0f0;
padding: 7px;
border-bottom: 3px solid #ccc;
......@@ -242,12 +290,12 @@ Media Queries
font-size: 1.2em;
}
#header, #title{
flex-direction: column;
padding-top: 5px;
flex-direction: column;
}
#title{
font-size: 1.4em;
margin: 0;
font-size: 1.4em;
text-align: center;
}
#logo{
......@@ -281,9 +329,9 @@ Media Queries
text-align: center;
}
#listMenu a{
display: inline-block;
padding: 3px 0;
margin: 0;
padding: 3px 0;
display: inline-block;
}
#listMenu .selected{
border: none;
......
<VirtualHost *:80>
ServerName l3m.local
Serveralias www.l3m.local
ServerAdmin addr@exp.ext
DocumentRoot /var/www/directory
Options Indexes FollowSymLinks MultiViews
ErrorDocument 404 /index.php?action=404
RewriteEngine On
RewriteRule ^/(about|changelog|blog|rss|projects|contact|patate|eplucher)$ /index.php?action=$1
RewriteRule ^/article/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)$ /index.php?action=blog&title=$1
RewriteRule ^/project/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)$ /index.php?action=project&title=$1
RewriteRule ^/patate/blog/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)/edit$ /index.php?action=patate&title=$1&editb
RewriteRule ^/patate/blog/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)/delete$ /index.php?action=patate&title=$1&deleteb
RewriteRule ^/patate/blog/submit$ /index.php?action=patate&submitb
RewriteRule ^/patate/blog/edit$ /index.php?action=patate&editb
RewriteRule ^/patate/blog/send$ /index.php?action=patate&sendb
RewriteRule ^/patate/project/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)/edit$ /index.php?action=patate&title=$1&editp
RewriteRule ^/patate/project/([a-zA-Z0-9\-:!?+.;/,\%9áàâäãåçéèêëíìîïñóòôöõúùûüýÿæœÁÀÂÄÃÅÇÉÈÊËÍÌÎÏÑÓÒÔÖÕÚÙÛÜÝŸÆŒ]*)/delete$ /index.php?action=patate&title=$1&deletep
RewriteRule ^/patate/project/submit$ /index.php?action=patate&submitp
RewriteRule ^/patate/project/edit$ /index.php?action=patate&editp
RewriteRule ^/patate/project/send$ /index.php?action=patate&sendp
</VirtualHost>
-- phpMyAdmin SQL Dump
-- version 4.6.6deb5
-- https://www.phpmyadmin.net/
SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET time_zone = "+00:00";
CREATE TABLE `l3m_blog` (
`id` int(11) NOT NULL,
`time` datetime NOT NULL,
`title` varchar(255) NOT NULL,
`content` text NOT NULL,
`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;
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` (
`id` int(11) NOT NULL,
`name` varchar(255) NOT NULL,
`link` varchar(255) NOT NULL,
`content` text NOT NULL,
`shortContent` varchar(255) NOT NULL DEFAULT 'Pas de description.'
) 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`
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`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
ALTER TABLE `l3m_comments`
ADD CONSTRAINT `l3m_comments_ibfk_1` FOREIGN KEY (`id_blog`) REFERENCES `l3m_blog` (`id`);
\ No newline at end of file
......@@ -18,9 +18,15 @@ function getPageName(){
case 'projects':
return ["Projets", "projects"];
break;
case 'project':
return ["Projet", "project"];
break;
case 'changelog':
return ["Changelog", "changelog"];
break;
case 'eplucher':
return ["COUCOU AHAH", "eplucher"];
break;
case 'rss':
return ["Rss", "rss"];
break;
......@@ -33,9 +39,6 @@ function getPageName(){
case 'patate':
return ["Administration", "administration"];
break;
case 'eplucher':
return ["prout hihi", "eplucher"];
break;
default:
return ["Blog", "blog"];
break;
......@@ -52,7 +55,7 @@ function writeMenu($pageName){
<?php if($pageName == "Administration"){ ?><li><h2><a href="/eplucher" class="selected">🔧</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="/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"){ ?>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>
<li><h2><a href="/contact" title="Contact" <?php if($pageName == "Contact"){ ?>class="selected"<?php } ?>>Contact</a></h2></li>
</ul>
<?php }
......@@ -63,7 +66,7 @@ function writeBlogPage($pageName){
$blog = new BlogManager();
if(isset($_GET['title'])){
$title = $_GET['title'];
$title = urldecode($_GET['title']);
$blogpost = $blog->getBlogPost($title);
if($blogpost != false)
require("site/view/public/blogPostView.php");
......@@ -85,6 +88,24 @@ function writeProjectsPage($pageName){
require("site/view/public/projectsView.php");
}
function writeProjectPage($pageName){
$project = new ProjectManager();
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$project = $project->getProject($title);
if($project != false){
$project['pageProject'] = true;
require("site/view/public/projectView.php");
}
else{
header("Location:/404");
}
}
else
require("site/view/public/projectsView.php");
}
function loginAdminPage($pageName){
if(password_verify($_POST['pass'], pass) && $_POST['user'] == user){
$_SESSION['user'] = $_POST['user'];
......@@ -92,18 +113,72 @@ function loginAdminPage($pageName){
header("Location:/patate");
}
else
echo "nan";
header("Location:/patate");
}
function writeAdminPage($pageName){
$admin = new AdminManager();
if($admin->verifyAdminConnect()){
$blogposts = $admin->getBlogPosts();
$projects = $admin->getProjects();
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");
require("site/view/private/admin.php");
}
}
else
require("site/view/private/loginFormView.php");
......
......@@ -43,6 +43,11 @@
case 'projects':
writeProjectsPage($pageName);
break;
case 'project':
writeProjectPage($pageName);
break;
case 'eplucher':
decoAdminPage();
case 'contact':
require("site/view/public/contact.php");
break;
......@@ -66,9 +71,8 @@
case 'eplucher':
decoAdminPage();
break;
default:
# code...
header('Location:/404');
break;
} ?>
......
......@@ -15,9 +15,151 @@ class AdminManager extends Base
return $req;
}
public function getBlogPost($link)
{
$blogpost = new BlogManager();
return $blogpost->getBlogPost($link);
}
public function getProject($link)
{
$project = new ProjectManager();
return $project->getProject($link);
}
public function verifyAdminConnect(){
return isset($_SESSION['user']) && $_SESSION['user'] == user && isset($_SESSION['pass']) && password_verify($_SESSION['pass'], pass);
}
public function updateBlogPost(){
$time = htmlspecialchars($_POST['time']);
$title = htmlspecialchars($_POST['title']);
$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(){
$name = htmlspecialchars($_POST['name']);
$link = htmlspecialchars($_POST['link']);
$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(){
$time = htmlspecialchars($_POST['time']);
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(){
$name = htmlspecialchars($_POST['name']);
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){
$title = str_replace("-", " ", $link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_blog WHERE title = :title');
$req->execute(array(
'title' => $title
));
}
public function deleteProject($link){
$name = str_replace("-", " ", $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
......@@ -27,7 +27,7 @@ class BlogManager extends Base
if($post == false)
return false;
$post["link"] = $link;
$post["link"] = urlencode($link);
$post['datetime'] = new DateTime($post['time']);
return $post;
......
......@@ -8,4 +8,20 @@ class ProjectManager extends Base
return $req;
}
public function getProject($link)
{
$link = htmlspecialchars($link);
$name = str_replace("-", " ", $link);
$db = $this->dbConnect();
$req = $db->prepare('SELECT * FROM l3m_projects WHERE name = ?');
$req->execute(array($name));
$project = $req->fetch();
if($project == false)
return false;
return $project;
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@
<article>
<h3>🔧 Administration</h3>
<p>Todo : toutes les fonctionnalités hyper chiadées & ultra stylées.</p>
<p>Ici c'est pour créer, éditer ou supprimer des billets de blog ou des projets.</p>
</article>
<article>
......@@ -15,7 +15,7 @@
<article>
<h3>Liste des posts de blog</h3>
<form action="patate/submitb" method="get" accept-charset="utf-8">
<form action="/patate/blog/submit" method="get" accept-charset="utf-8">
<input type="submit" value="Nouveau billet" />
</form>
......@@ -26,7 +26,7 @@
<article>
<h3>Liste des projets</h3>
<form action="patate/submitp" method="get" accept-charset="utf-8">
<form action="/patate/project/submit" method="get" accept-charset="utf-8">
<input type="submit" value="Nouveau projet" />
</form>
......
<?php
if(!isset($admin)){
header("Location:/patate");