Commit e7ffa7e6 authored by Corentin Bettiol's avatar Corentin Bettiol 💻

little change; the website generate slug when a blogpost/project is created,...

little change; the website generate slug when a blogpost/project is created, and this slug is used in the url to access the blogpost/project
parent 87ec978e
......@@ -11,5 +11,4 @@ require_once('site/controller/adminController.php');
// afficher le contenu (qui va switcher sur le contenu dynamique à afficher)
require_once('site/layout/layout.php');
?>
\ No newline at end of file
......@@ -12,17 +12,8 @@
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
RewriteRule ^/article/([-a-z0-9]+)$ /index.php?action=blog&title=$1
RewriteRule ^/project/([-a-z0-9]+)$ /index.php?action=project&title=$1
RewriteRule ^/patate/(blog|project)/([-a-z0-9]+)/(edit|submit|delete)$ /index.php?action=patate&type=$1$3&title=$2
</VirtualHost>
......@@ -6,8 +6,7 @@ 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'];
$_SESSION['user'] = user;
header('Location:/patate');
}
else
......@@ -17,10 +16,14 @@ function loginAdminPage($pageName){
// 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(isset($_GET['type'])){
switch ($_GET['type']){
case 'blogedit':
if(!isset($_POST['title'])){
$title = htmlspecialchars($_GET['title']);
if($blogpost = $admin->getBlogPost($title))
require('site/view/private/editblogView.php');
else
......@@ -30,9 +33,26 @@ function writeAdminPage($pageName){
$admin->updateBlogPost();
header('Location:/patate');
}
break;
case 'blogsubmit':
if(isset($_POST['title'])){
$admin->sendBlogPost();
//header('Location:/patate');
}
else if(isset($_GET['editp'])){
else
require('site/view/private/createBlogView.php');
break;
case 'blogdelete':
if(isset($_GET['title'])){
$admin->deleteBlogPost($_GET['title']);
header('Location:/patate');
}
break;
case 'projectedit':
if(!isset($_POST['name'])){
$title = urldecode($_GET['title']);
$project = $admin->getProject($title);
require('site/view/private/editProjectView.php');
......@@ -41,37 +61,30 @@ function writeAdminPage($pageName){
$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'])){
break;
case 'projectsubmit':
if(isset($_POST['name'])){
$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'])){
else
require('site/view/private/createProjectView.php');
break;
case 'projectdelete':
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$admin->deleteProject($title);
$admin->deleteProject($_GET['title']);
header('Location:/patate');
}
break;
default:
# code...
break;
}
}
else{
$blogposts = $admin->getBlogPosts();
$projects = $admin->getProjects();
......
......@@ -87,8 +87,8 @@ function writeBlogPage($pageName){
$blogpost = $blog->get($title);
if($blogpost != false)
require('site/view/public/blogPostView.php');
else
header('Location:/404');
//else
// header('Location:/404');
}
// si on affiche la liste des posts
else{
......@@ -106,10 +106,11 @@ function writeProjectPage($pageName){
if(isset($_GET['title'])){
$title = urldecode($_GET['title']);
$project = $project->get($title);
if($project != false)
if($project != false){
require('site/view/public/projectView.php');
else
header('Location:/404');
}
//else
// header('Location:/404');
}
// si on affiche la liste des projets
else{
......
......@@ -17,19 +17,19 @@ class AdminManager extends Base
public function getBlogPost($link)
{
$blogpost = new BlogManager(null, null, null, null, null, null); // moche :c
$blogpost = new BlogManager(null, null, null, null, null, null);
return $blogpost->get($link);
}
public function getProject($link)
{
$project = new ProjectManager(null,null,null,null,null); // moche :c
$project = new ProjectManager(null,null,null,null,null);
return $project->get($link);
}
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;
}
public function updateBlogPost(){
......@@ -43,13 +43,13 @@ class AdminManager extends Base
}
public function sendBlogPost(){
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$blog = new BlogManager($_POST['time'], $_POST['title'], $_POST['content'], $_POST['shortContent'], null);
$blog->send();
}
public function sendProject(){
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], $_POST['id']);
$project = new ProjectManager($_POST['name'], $_POST['link'], $_POST['content'], $_POST['shortContent'], null);
$project->send();
}
......
......@@ -7,4 +7,14 @@ class Base
$db = new PDO('mysql:host=localhost;dbname='. dbName .';charset=utf8', dbUser, dbPass);
return $db;
}
# thanks https://www.matthecat.com/supprimer-les-accents-dune-chaine-en-php/ & http://php.net/manual/fr/transliterator.transliterate.php#110598
protected function slugify($text){
$slug = preg_replace('/&amp;/', 'et', $text);
$slug = transliterator_transliterate("Any-Latin; NFD; [:Nonspacing Mark:] Remove; NFC; [:Punctuation:] Remove; Lower();", $slug);
$slug = preg_replace('/[-\s]+/', '-', $slug);
$slug = preg_replace('/-$/', '', $slug);
$slug = preg_replace('/[^a-z0-9-]+/', '', $slug);
return $slug;
}
}
\ No newline at end of file
......@@ -29,20 +29,16 @@ class BlogManager extends Base
public function get($link)
{
$link = htmlspecialchars($link);
$title = str_replace('-', ' ', $link);
$db = $this->dbConnect();
$req = $db->prepare('SELECT * FROM l3m_blog WHERE title = ?');
$req->execute([$title]);
$req = $db->prepare('SELECT * FROM l3m_blog WHERE slug = ?');
$req->execute([$link]);
$post = $req->fetch();
if($post == false)
return false;
$post['link'] = urlencode($link);
$post['datetime'] = new DateTime($post['time']);
return $post;
......@@ -73,11 +69,15 @@ class BlogManager extends Base
if(strlen($this->shortContent) < 1){
$this->shortContent = 'Ce billet de blog ne dispose d\'aucune description.';
}
$this->slug = $this->slugify($this->title);
$db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_blog(time, title, content, shortcontent) VALUES(:time, :title, :content, :shortContent)');
$req = $db->prepare('INSERT INTO l3m_blog(time, title, slug, content, shortcontent) VALUES(:time, :title, :slug, :content, :shortContent)');
$req->execute([
'time' => $this->time,
'title' => $this->title,
'slug' => $this->slug,
'content' => $this->content,
'shortContent' => $this->shortContent
]);
......@@ -85,12 +85,10 @@ class BlogManager extends Base
public function delete($link){
$title = str_replace('-', ' ', $link);
$link = htmlspecialchars($link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_blog WHERE title = :title');
$req->execute([
'title' => $title
]);
$req = $db->prepare('DELETE FROM l3m_blog WHERE slug = ?');
$req->execute([$link]);
}
}
\ No newline at end of file
......@@ -26,11 +26,10 @@ class ProjectManager extends Base
public function get($link)
{
$link = htmlspecialchars($link);
$name = str_replace('-', ' ', $link);
$db = $this->dbConnect();
$req = $db->prepare('SELECT * FROM l3m_projects WHERE name = ?');
$req->execute([$name]);
$req = $db->prepare('SELECT * FROM l3m_projects WHERE slug = ?');
$req->execute([$link]);
$project = $req->fetch();
if($project == false)
......@@ -60,10 +59,13 @@ class ProjectManager extends Base
if(strlen($this->shortContent) < 1){
$this->shortContent = 'Pas de description.';
}
$this->slug = $this->slugify($this->name);
$db = $this->dbConnect();
$req = $db->prepare('INSERT INTO l3m_projects(name, link, content, shortcontent) VALUES(:name, :link, :content, :shortContent)');
$req = $db->prepare('INSERT INTO l3m_projects(name, slug, link, content, shortcontent) VALUES(:name, :slug, :link, :content, :shortContent)');
$req->execute([
'name' => $this->name,
'slug' => $this->slug,
'link' => $this->link,
'content' => $this->content,
'shortContent' => $this->shortContent
......@@ -71,12 +73,10 @@ class ProjectManager extends Base
}
public function delete($link){
$title = str_replace('-', ' ', $link);
$link = htmlspecialchars($link);
$db = $this->dbConnect();
$req = $db->prepare('DELETE FROM l3m_projects WHERE name = :name');
$req->execute([
'name' => $title
]);
$req = $db->prepare('DELETE FROM l3m_projects WHERE slug = ?');
$req->execute([$link]);
}
}
\ No newline at end of file
......@@ -10,7 +10,7 @@
<article>
<h3>Post d'un billet de blog</h3>
<form action="/patate/blog/send" method="post" accept-charset="utf-8">
<form action="/patate/blog/submit" method="post" accept-charset="utf-8">
<section class="input">
<label for="inputTitle">Titre</label>
......
......@@ -10,7 +10,7 @@
<article>
<h3>Post d'un nouveau projet</h3>
<form action="/patate/project/send" method="post" accept-charset="utf-8">
<form action="/patate/project/submit" method="post" accept-charset="utf-8">
<input type="hidden" name="id" value="<?php echo $project['id']; ?>" />
......
......@@ -8,7 +8,7 @@
<article>
<h3>Édition du projet #<?php echo $project['id']; ?></h3>
<form action="/patate/project/edit" method="post" accept-charset="utf-8">
<form action="/patate/project/<?php echo $project['slug'] ?>/edit" method="post" accept-charset="utf-8">
<input type="hidden" name="id" value="<?php echo $project['id']; ?>" />
......
......@@ -8,7 +8,7 @@
<article>
<h3>Édition du billet de blog #<?php echo $blogpost['id']; ?></h3>
<form action="/patate/blog/edit" method="post" accept-charset="utf-8">
<form action="/patate/blog/<?php echo $blogpost['slug']; ?>/edit" method="post" accept-charset="utf-8">
<input type="hidden" name="id" value="<?php echo $blogpost['id']; ?>" />
......
......@@ -4,17 +4,14 @@
exit();
}
$hr = false;
foreach ($blogposts as $post){
$post['datetime'] = new DateTime($post['time']);
$post['link'] = urlencode(str_replace(' ', '-', $post['title']));
$exist = true;
?>
<article>
<p class="listAdmin">
<b><a href="/article/<?php echo $post['link']; ?>"><?php echo $post['title'] ?></a></b>
<span class="postInfos"><?php echo date_format($post['datetime'], 'd/m/Y à H:i'); ?></span> <a class="button" href="/patate/blog/<?php echo $post['link']; ?>/edit">éditer</a> <a class="button" href="/patate/blog/<?php echo $post['link'] ."/delete"; ?>" onclick="return confirm('C\'est certain ?')"></a>
<b><a href="/article/<?php echo $post['slug']; ?>"><?php echo $post['title'] ?></a></b>
<span class="postInfos"><?php echo date_format($post['datetime'], 'd/m/Y à H:i'); ?></span> <a class="button" href="/patate/blog/<?php echo $post['slug']; ?>/edit">éditer</a> <a class="button" href="/patate/blog/<?php echo $post['slug'] ."/delete"; ?>" onclick="return confirm('C\'est certain ?')"></a>
</p>
</article>
<?php
......
......@@ -4,16 +4,14 @@
exit();
}
$hr = false;
foreach ($projects as $project){
$project['internalLink'] = urlencode(str_replace(' ', '-', $project['name']));
$exist = true;
?>
<article>
<p class="listAdmin">
<b><a href="/project/<?php echo $project['internalLink']; ?>"><?php echo $project['name'] ?></a></b>
<span class="postInfos"><?php echo $project['link']; ?></span> <a class="button" href="/patate/project/<?php echo $project['internalLink'] ."/edit"; ?>">éditer</a> <a class="button" href="/patate/project/<?php echo $project['internalLink'] ."/delete"; ?>" onclick="return confirm('C\'est certain ?')"></a>
<b><a href="/project/<?php echo $project['slug']; ?>"><?php echo $project['name'] ?></a></b>
<span class="postInfos"><?php echo $project['link']; ?></span> <a class="button" href="/patate/project/<?php echo $project['slug'] ."/edit"; ?>">éditer</a> <a class="button" href="/patate/project/<?php echo $project['slug'] ."/delete"; ?>" onclick="return confirm('C\'est certain ?')"></a>
</p>
</article>
<?php
......
......@@ -6,14 +6,14 @@
?>
<article>
<h3><a href="/article/<?php echo $blogpost['link']; ?>"><?php echo $blogpost['title']; ?></a></h3>
<h3><a href="/article/<?php echo $blogpost['slug']; ?>"><?php echo $blogpost['title']; ?></a></h3>
<p class="postInfos">
Le <time datetime="<?php echo $blogpost['time']; ?>"><?php echo date_format($blogpost['datetime'], 'd/m/Y à H:i'); ?></time>.
</p>
<section>
<p>
<?php
if(isset($hr))
if(isset($_GET['title']))
echo $blogpost['shortContent'];
else
echo nl2br($blogpost['content']);
......
......@@ -4,10 +4,7 @@
exit();
}
$hr = false;
foreach ($blogposts as $blogpost){
$blogpost['link'] = urlencode(str_replace(' ', '-', $blogpost['title']));
$blogpost['datetime'] = new DateTime($blogpost['time']);
$exist = true;
......
<article>
<h3><a href="">01/03/19</a></h3>
<h3><a href="">01/03/19</a> (encore)</h3>
<ul>
<li>Réorganisation de la gestion des url des pages :
<ul>
<li>Modification du fichier l3m-website-dist.conf, avec les bonnes règles d'urlrewriting</li>
<li>Beauuucoup de changements dans les fichiers de classe d'admin, de blog & de projet</li>
<li>Utilisation de l'extension IntL pour la fonction slugify() dans la classe Base (servant à générer les url)</li>
</ul>
</li>
</ul>
</article>
<article>
<h3><a href="https://git.bitmycode.com/sodimel/l3m-website/commit/3e33e9c76cc1f335ff91be357168352791c4d3a2" title="3e33e9c7">01/03/19</a></h3>
<ul>
<li>Suppression de toutes les balises &lt;hr /&gt; (qui servent à séparer des paragraphes et pas des sections)</li>
<li>Création du fichier adminController.php, avec les fonctions d'administration dedans</li>
......
......@@ -24,19 +24,19 @@
<ul>
<li>
<a href="https://git.bitmycode.com/sodimel/">git.bitmycode</a>.com
<a href="https://git.bitmycode.com/sodimel/">git.bitmycode.com</a>, l'instange gitlab de BitMyCode.
</li>
<li>
<a href="https://gitlab.com/sodimel/">gitlab</a>.com
<a href="https://gitlab.com/sodimel/">gitlab.com</a>
</li>
<li>
<a href="https://github.com/corentinbettiol/">github</a>
<a href="https://github.com/corentinbettiol/">github</a>, comme gitlab mais en moins bien
</li>
<li>
<a href="https://codepen.io/lmmm/">codepen</a>
<a href="https://codepen.io/lmmm/">codepen</a>, parce que le CSS c'est rigolo
</li>
<li>
<a href="https://dribbble.com/sodimel">dribbble</a>
<a href="https://dribbble.com/sodimel">dribbble</a>, parce que le CSS c'est une forme de design
</li>
</ul>
</article>
......
......@@ -3,23 +3,12 @@
header('Location:/');
exit();
}
$project['internalLink'] = urlencode(str_replace(' ', '-', $project['name']));
?>
<article>
<h3><a href="<?php echo $project['link']; ?>"><?php echo $project['name']; ?></a></h3>
<p>
<?php
if(isset($project['pageProject'])){
echo nl2br($project['content']);
}
else{
echo $project['shortContent'];
?>
<br />
<span class="postInfos"><a href="/project/<?php echo $project['internalLink']; ?>">Plus d'infos.</a></span>
<?php
}
?>
</p>
</article>
\ No newline at end of file
......@@ -5,14 +5,13 @@
}
foreach ($projects as $project){
$project['internalLink'] = urlencode(str_replace(' ', '-', $project['name']));
$exist = true;
?>
<article>
<h3><a href="<?php echo $project['link']; ?>"><?php echo $project['name']; ?></a></h3>
<p>
<?php echo $project['shortContent']; ?><br />
<span class="postInfos"><a href="/project/<?php echo $project['internalLink']; ?>">Plus d'infos.</a></span>
<span class="postInfos"><a href="/project/<?php echo $project['slug']; ?>">Plus d'infos.</a></span>
</p>
</article>
<?php
......
<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
RewriteRule ^/patate/project/send$ /index.php?action=patate&sendp
</VirtualHost>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment