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

change project/blog organization

parent 8f90b9e5
<?php
// session pour quand on est admin
session_start();
// le gros gros controlleur (peut-être le casser en plusieurs morceaux plus tard)
require_once("site/controller/mainController.php");
// afficher le contenu (qui va switcher sur le contenu dynamique à afficher)
require_once("site/layout/layout.php");
?>
\ No newline at end of file
<?php
// fichier de config pour la bdd & le compte pour la partie administrateur
require_once("site/model/config.php");
// connexion à la base de données
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
require_once("site/model/BlogManager.php");
// classe pour la gestion des projets
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(){
// si on a une url personnalisée
if(isset($_GET['action'])){
switch ($_GET['action']) {
case 'contact':
case 'contact': // contact
return ["Contact", "contact"];
break;
case 'about':
case 'about': // à propos
return ["À Propos", "about"];
break;
case 'projects':
case 'projects': // projets
return ["Projets", "projects"];
break;
case 'project':
case 'project': // projet
return ["Projet", "project"];
break;
case 'changelog':
case 'changelog': // historique des versions
return ["Changelog", "changelog"];
break;
case 'eplucher':
case 'eplucher': // déconnexion (la première valeur n'est jamais utilisée)
return ["COUCOU AHAH", "eplucher"];
break;
case 'rss':
case 'rss': // rss
return ["Rss", "rss"];
break;
case '404':
case '404': // page not found
return ["Erreur 404 - File not found", "404"];
break;
case 'article':
case 'article': // billet de blog
return [$_GET['title'], $_GET['title']];
break;
case 'patate':
case 'patate': // administration
return ["Administration", "administration"];
break;
default:
default: // si l'argument n'est pas compris on affiche le blog
return ["Blog", "blog"];
break;
}
}
// si on est sur l'accueil du site
else{
return ["Blog", "blog"];
}
}
// affiche le menu du site (avec le titre de la page)
function writeMenu($pageName){
?>
<ul id="listMenu">
......@@ -60,40 +74,46 @@ function writeMenu($pageName){
</ul>
<?php }
// affiche la page du blog
function writeBlogPage($pageName){
// si on n'accède pas au fichier mais bien au site (var définie)
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'])){
$title = urldecode($_GET['title']);
$blogpost = $blog->getBlogPost($title);
$blogpost = $blog->get($title);
if($blogpost != false)
require("site/view/public/blogPostView.php");
else
header("Location:/404");
}
// si on affiche la liste des posts
else{
$blogposts = $blog->getBlog(0);
$blogposts = $blog->getPage(0);
require("site/view/public/blogView.php");
}
}
}
// affiche la liste des projets
function writeProjectsPage($pageName){
$projects = new ProjectManager();
$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){
$project = new ProjectManager();
$project = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$project = $project->getProject($title);
$project = $project->get($title);
if($project != false){
$project['pageProject'] = true;
require("site/view/public/projectView.php");
......@@ -106,6 +126,7 @@ function writeProjectPage($pageName){
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'];
......@@ -116,7 +137,7 @@ function loginAdminPage($pageName){
header("Location:/patate");
}
// afficher le panneau d'administration & gère l'administration du site
function writeAdminPage($pageName){
$admin = new AdminManager();
if($admin->verifyAdminConnect()){
......@@ -184,10 +205,11 @@ function writeAdminPage($pageName){
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)
$pageName = getPageName();
\ No newline at end of file
......@@ -4,10 +4,10 @@
<meta charset="utf-8" />
<meta name="description" content="Site perso de Corentin Bettiol." />
<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" />
<?php
if($pageName[1] == 404){ ?>
if($pageName[1] == 404){ // le css pour la page 404 ?>
<link rel="stylesheet" href="/css/404.css" />
<?php } ?>
<link rel="icon" type="image/png" href="img/icon.png" />
......@@ -29,49 +29,50 @@
--><h1 id="title">l3m website</h1>
</header>
<nav id="menu">
<?php writeMenu($pageName[0]); ?>
<?php writeMenu($pageName[0]); // voir mainController ?>
</nav>
</header>
<?php switch ($pageName[1]) {
case 'blog':
writeBlogPage($pageName);
<?php
// le gros switch qui fait peur
switch ($pageName[1]){
case 'blog': // blog
writeBlogPage($pageName); // voir mainController
break;
case 'about':
require("site/view/public/about.php");
case 'about': // à propos
require("site/view/public/about.php"); // statique
break;
case 'projects':
writeProjectsPage($pageName);
case 'projects': // projets
writeProjectsPage($pageName); // voir mainController
break;
case 'project':
writeProjectPage($pageName);
case 'project': // projet en particulier
writeProjectPage($pageName); // voir mainController
break;
case 'eplucher':
decoAdminPage();
case 'contact':
require("site/view/public/contact.php");
case 'eplucher': // déconnexion du panneau d'administration
decoAdminPage(); // voir mainController
case 'contact': // contact
require("site/view/public/contact.php"); // statique
break;
case 'changelog':
require("site/view/public/changelog.php");
case 'changelog': // historique de développement
require("site/view/public/changelog.php"); // statique
break;
case 'rss':
require("site/view/public/rss.php");
case 'rss': // rss
require("site/view/public/rss.php"); // todo
break;
case '404':
require("site/view/public/404.php");
case '404': // page not found
require("site/view/public/404.php"); // statique
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'])){
loginAdminPage($pageName);
}
// afficher le login screen
else{
writeAdminPage($pageName);
}
break;
case 'eplucher':
decoAdminPage();
break;
default:
default: // page non connue (n'est pas senser arriver)
header('Location:/404');
break;
} ?>
......
......@@ -17,14 +17,14 @@ class AdminManager extends Base
public function getBlogPost($link)
{
$blogpost = new BlogManager();
return $blogpost->getBlogPost($link);
$blogpost = new BlogManager(NULL, NULL, NULL, NULL, NULL, NULL); // moche :c
return $blogpost->get($link);
}
public function getProject($link)
{
$project = new ProjectManager();
return $project->getProject($link);
$project = new ProjectManager(NULL,NULL,NULL,NULL,NULL); // moche :c
return $project->get($link);
}
......@@ -33,133 +33,34 @@ class AdminManager extends Base
}
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
));
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['comments'], $_POST['id']);
$blog->update();
}
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
));
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$project->update();
}
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
));
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['comments'], $_POST['id']);
$blog->send();
}
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
));
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$project->sendProject();
}
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
));
$blog = new BlogManager(NULL, NULL, NULL, NULL, NULL, NULL);
$blog->deleteBlogPost($link);
}
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
));
$project = new ProjectManager(NULL, NULL, NULL, NULL, NULL);
$project->deleteProject($link);
}
}
\ No newline at end of file
<?php
// connexion à la bdd
class Base
{
protected function dbConnect()
......
<?php
class BlogManager extends Base
{
public function getBlog($page)
{
$start = $page*5;
$stop = $start + 5;
private $time;
private $title;
private $content;
private $shortContent;
private $comments;
private $id;
$db = $this->dbConnect();
$req = $db->query('SELECT * FROM l3m_blog ORDER BY id DESC LIMIT '. $start .', '. $stop .'');
function __construct($time, $title, $content, $shortContent, $comments, $id){
$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();
$req = $db->prepare('SELECT * FROM l3m_blog WHERE title = ?');
$req->execute(array($title));
$post = $req->fetch();
public function get($link)
{
if($post == false)
return false;
$link = htmlspecialchars($link);
$post["link"] = urlencode($link);
$post['datetime'] = new DateTime($post['time']);
$title = str_replace("-", " ", $link);
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
class ProjectManager extends Base
{
public function getProjects()
{
$db = $this->dbConnect();
$req = $db->query('SELECT * FROM l3m_projects ORDER BY id DESC');
private $name;
private $link;
private $content;
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)
{
$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;
}
// todo vérifier qu'on poste pas un truc vide
public function update(){
$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' => $this->name,
'link' => $this->link,
'content' => $this->content,
'shortContent' => $this->shortContent,
'id' => $this->id
));
}
public function send(){
if(strlen($this->name) < 1){
header("Location:/patate");
exit();
}
if(strlen($this->shortContent) < 1){
$this->shortContent = "Pas de description.";
}
$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;
}
$req = $db->prepare('INSERT INTO l3m_projects(name, link, content, shortcontent) VALUES(:name, :link, :content, :shortContent)');
$req->execute(array(
'name' => $this->name,
'link' => $this->link,
'content' => $this->content,
'shortContent' => $this->shortContent
));
}
public function delete($link){
$title = str_replace("-", " ", $link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_projects WHERE name = :name');
$req->execute(array(
'name' => $title
));
}
}
\ No newline at end of file
<?php
// config file
// rename this file config.php
// database config
define('dbName', 'l3m');
define('dbUser', 'corentin');
define('dbPass', 'mariadbpsswd');
// login config
define('user', 'corentin');
define('pass', '$2y$10$k55Qz7eRbb5V2Ctcx9DeK.WfS5iVgpaWLv99RBeauUFsfIJV3WYwm');
\ No newline at end of file
<article>
<h3>14/01/19 (encore)</h3>
<h3>04/02/19</h3>
<ul>
<li>Ajout de commentaires au code</li>
<li>Modification du fichier urlrewriting.txt (nouveau contenu = contenu du fichier nomdusite.conf de apache)</li>
<li>Changement des classes BlogManager & ProjectManager ; déplacement du code depuis AdminManager</li>
</ul>
</article>
<article>
<h3><a href="https://git.bitmycode.com/sodimel/l3m-website/commit/8f90b9e5bafe27fd6486ab3ce806762c4e86ec96" title="8f90b9e5">14/01/19</a> (encore)</h3>
<ul>
<li>Ajout d'un fichier "l3m.sql" pour montrer la base de données (supression du fichier sql.txt)</li>
......
RewriteEngine On
RewriteRule /(about|changelog|blog|rss|projects|contact|patate|eplucher)$ /index.php?action=$1
RewriteRule /article/([a-zA-Z0-9\-]*)$ /index.php?action=blog&title=$1
\ No newline at end of file
<VirtualHost *:80>
ServerName l3m.local
Serveralias www.l3m.local
ServerAdmin corentin@
DocumentRoot /path/to/l3m-website
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