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 ...@@ -9,26 +9,26 @@ CSS
} }
#page{ #page{
padding: 0;
width: 100%; width: 100%;
margin: auto; margin: auto;
padding: 0;
font-family: ubuntulight;
font-size: 1.5em; font-size: 1.5em;
font-family: ubuntulight;
background-color: #e3e3e3; background-color: #e3e3e3;
} }
#header{ #header{
padding: 2px;
display: flex; display: flex;
flex-direction: row; flex-direction: row;
justify-content: space-between;
align-items: center; align-items: center;
font-family: ubuntumono; font-family: ubuntumono;
background-color: #f0f0f0; background-color: #f0f0f0;
padding: 2px;
border-bottom: 5px solid #ccc; 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; max-width: 1500px;
margin: 30px auto; margin: 30px auto;
} }
...@@ -44,9 +44,9 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{ ...@@ -44,9 +44,9 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{
} }
#title{ #title{
display: flex;
width: auto; width: auto;
margin: auto; margin: auto;
display: flex;
color: #2E2E2E; color: #2E2E2E;
text-shadow: 0 0 3px #69f; text-shadow: 0 0 3px #69f;
} }
...@@ -56,11 +56,11 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{ ...@@ -56,11 +56,11 @@ article p, #pageTitle, article h3, article ul, article form, #listAdmin{
} }
h2{ h2{
display: inline-block;
margin: 0; margin: 0;
padding: 0; padding: 0;
font-weight: normal;
font-size: 1.5em; font-size: 1.5em;
font-weight: normal;
display: inline-block;
} }
h3 a{ h3 a{
...@@ -76,13 +76,13 @@ h3 a:hover{ ...@@ -76,13 +76,13 @@ h3 a:hover{
} }
#listMenu{ #listMenu{
list-style-type: none; padding: 0;
width: auto;
display: flex; display: flex;
margin: 15px 0;
flex-direction: row; flex-direction: row;
list-style-type: none;
justify-content: space-around; justify-content: space-around;
width: auto;
margin: 15px 0;
padding: 0;
} }
#listMenu a{ #listMenu a{
...@@ -116,11 +116,11 @@ article .postInfos{ ...@@ -116,11 +116,11 @@ article .postInfos{
#footer{ #footer{
width: 98%; width: 98%;
background-color: #f0f0f0;
margin: auto;
padding: 1%; padding: 1%;
text-align: center; margin: auto;
font-size: 0.8em; font-size: 0.8em;
text-align: center;
background-color: #f0f0f0;
} }
hr{ hr{
...@@ -137,34 +137,36 @@ a:hover{ ...@@ -137,34 +137,36 @@ a:hover{
transition: color 0.3s; transition: color 0.3s;
} }
input{ input, textarea{
width: 50%; width: 50%;
display: block; border: none;
box-sizing: border-box;
margin: 15px auto;
padding: 10px; padding: 10px;
display: block;
font-size: 1em; font-size: 1em;
} margin: 15px auto;
input[type="text"], input[type="password"]{
background-color: white;
border: none;
padding-left: 13px; padding-left: 13px;
border-bottom: 3px solid #ccc; box-sizing: border-box;
background-color: white;
border-left: 0px solid #ccc; border-left: 0px solid #ccc;
border-bottom: 3px solid #ccc;
transition: border-left 0.05s, padding-left 0.05s; 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{ .input input, .input textarea{
border-left: 3px solid #ccc; margin: 0 0 0 20px;
}
input:hover, input:focus, textarea:hover, textarea:focus{
padding-left: 10px; padding-left: 10px;
border-left: 3px solid #ccc;
transition: border-left 0.05s, padding-left 0.05s; transition: border-left 0.05s, padding-left 0.05s;
} }
input[type="submit"]{ input[type="submit"]{
background-color: #ccc; padding-left: 13px;
border: none; border: none;
background-color: #ccc;
transition: background-color 0.3s; transition: background-color 0.3s;
} }
...@@ -173,6 +175,46 @@ input[type="submit"]:hover{ ...@@ -173,6 +175,46 @@ 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{
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{ #listAdmin{
display: flex; display: flex;
flex-wrap: wrap; flex-wrap: wrap;
...@@ -200,8 +242,8 @@ input[type="submit"]:hover{ ...@@ -200,8 +242,8 @@ input[type="submit"]:hover{
} }
.listAdmin b{ .listAdmin b{
display: inline-block;
width: 50%; width: 50%;
display: inline-block;
border-right: 1px solid #ccc; border-right: 1px solid #ccc;
} }
...@@ -209,14 +251,20 @@ input[type="submit"]:hover{ ...@@ -209,14 +251,20 @@ input[type="submit"]:hover{
padding: 3px; padding: 3px;
} }
.editLink{ .listAdmin .postInfos{
width: 200px;
}
.button{
margin-left: 2px;
text-decoration: none;
background-color: #d9d9d9; background-color: #d9d9d9;
padding: 7px 7px 10px 7px; padding: 7px 7px 10px 7px;
border-bottom: 0px solid #ccc; border-bottom: 0px solid #ccc;
transition: background-color 0.3s, color 0.3s, border 0.05s, padding 0.05s; transition: background-color 0.3s, color 0.3s, border 0.05s, padding 0.05s;
} }
.editLink:hover{ .button:hover{
background-color: #f0f0f0; background-color: #f0f0f0;
padding: 7px; padding: 7px;
border-bottom: 3px solid #ccc; border-bottom: 3px solid #ccc;
...@@ -242,12 +290,12 @@ Media Queries ...@@ -242,12 +290,12 @@ Media Queries
font-size: 1.2em; font-size: 1.2em;
} }
#header, #title{ #header, #title{
flex-direction: column;
padding-top: 5px; padding-top: 5px;
flex-direction: column;
} }
#title{ #title{
font-size: 1.4em;
margin: 0; margin: 0;
font-size: 1.4em;
text-align: center; text-align: center;
} }
#logo{ #logo{
...@@ -281,9 +329,9 @@ Media Queries ...@@ -281,9 +329,9 @@ Media Queries
text-align: center; text-align: center;
} }
#listMenu a{ #listMenu a{
display: inline-block;
padding: 3px 0;
margin: 0; margin: 0;
padding: 3px 0;
display: inline-block;
} }
#listMenu .selected{ #listMenu .selected{
border: none; 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(){ ...@@ -18,9 +18,15 @@ function getPageName(){
case 'projects': case 'projects':
return ["Projets", "projects"]; return ["Projets", "projects"];
break; break;
case 'project':
return ["Projet", "project"];
break;
case 'changelog': case 'changelog':
return ["Changelog", "changelog"]; return ["Changelog", "changelog"];
break; break;
case 'eplucher':
return ["COUCOU AHAH", "eplucher"];
break;
case 'rss': case 'rss':
return ["Rss", "rss"]; return ["Rss", "rss"];
break; break;
...@@ -33,9 +39,6 @@ function getPageName(){ ...@@ -33,9 +39,6 @@ function getPageName(){
case 'patate': case 'patate':
return ["Administration", "administration"]; return ["Administration", "administration"];
break; break;
case 'eplucher':
return ["prout hihi", "eplucher"];
break;
default: default:
return ["Blog", "blog"]; return ["Blog", "blog"];
break; break;
...@@ -52,7 +55,7 @@ function writeMenu($pageName){ ...@@ -52,7 +55,7 @@ function writeMenu($pageName){
<?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 } ?>
<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"){ ?>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> <li><h2><a href="/contact" title="Contact" <?php if($pageName == "Contact"){ ?>class="selected"<?php } ?>>Contact</a></h2></li>
</ul> </ul>
<?php } <?php }
...@@ -63,7 +66,7 @@ function writeBlogPage($pageName){ ...@@ -63,7 +66,7 @@ function writeBlogPage($pageName){
$blog = new BlogManager(); $blog = new BlogManager();
if(isset($_GET['title'])){ if(isset($_GET['title'])){
$title = $_GET['title']; $title = urldecode($_GET['title']);
$blogpost = $blog->getBlogPost($title); $blogpost = $blog->getBlogPost($title);
if($blogpost != false) if($blogpost != false)
require("site/view/public/blogPostView.php"); require("site/view/public/blogPostView.php");
...@@ -85,6 +88,24 @@ function writeProjectsPage($pageName){ ...@@ -85,6 +88,24 @@ function writeProjectsPage($pageName){
require("site/view/public/projectsView.php"); 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){ 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'];
...@@ -92,19 +113,73 @@ function loginAdminPage($pageName){ ...@@ -92,19 +113,73 @@ function loginAdminPage($pageName){
header("Location:/patate"); header("Location:/patate");
} }
else else
echo "nan"; header("Location:/patate");
} }
function writeAdminPage($pageName){ function writeAdminPage($pageName){
$admin = new AdminManager(); $admin = new AdminManager();
if($admin->verifyAdminConnect()){ 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(); $blogposts = $admin->getBlogPosts();
$projects = $admin->getProjects(); $projects = $admin->getProjects();
require("site/view/private/admin.php"); require("site/view/private/admin.php");
} }
}
else else
require("site/view/private/loginFormView.php"); require("site/view/private/loginFormView.php");
} }
......
...@@ -43,6 +43,11 @@ ...@@ -43,6 +43,11 @@
case 'projects': case 'projects':
writeProjectsPage($pageName); writeProjectsPage($pageName);
break; break;
case 'project':
writeProjectPage($pageName);
break;
case 'eplucher':
decoAdminPage();
case 'contact': case 'contact':
require("site/view/public/contact.php"); require("site/view/public/contact.php");
break; break;
...@@ -66,9 +71,8 @@ ...@@ -66,9 +71,8 @@
case 'eplucher': case 'eplucher':
decoAdminPage(); decoAdminPage();
break; break;
default: default:
# code... header('Location:/404');
break; break;
} ?> } ?>
......
...@@ -15,9 +15,151 @@ class AdminManager extends Base ...@@ -15,9 +15,151 @@ class AdminManager extends Base
return $req; 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(){ public function verifyAdminConnect(){
return isset($_SESSION['user']) && $_SESSION['user'] == user && isset($_SESSION['pass']) && password_verify($_SESSION['pass'], pass); 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");