Commit 89a7796a authored by Corentin Bettiol's avatar Corentin Bettiol 💻

add tag slug

parent bb7298ee
......@@ -329,7 +329,7 @@ form .small{
}
.alignleft{
text-align: left;
text-align: left;
}
.aligncenter{
......@@ -340,14 +340,17 @@ form .small{
text-align: right;
}
.tag{
.tag a{
margin: 2px;
padding: 2px 7px;
text-decoration: none;
background-color: #ddd;
margin: 2px;
transition: background-color 0.2s;
}
.tag a{
text-decoration: none;
.tag a:hover{
background-color: #f0f0f0;
transition: background-color 0.2s;
}
img{
......@@ -496,7 +499,7 @@ Media Queries
border-bottom: 0px solid black;
padding: 0;
}
#toggle:checked ~ #listMenu{
border-bottom: 5px solid #ccc;
transition: border-bottom 0.3s;
......
......@@ -3,7 +3,7 @@
-- https://www.phpmyadmin.net/
--
-- Client : localhost:3306
-- Généré le : Mer 20 Mars 2019 à 13:12
-- Généré le : Jeu 21 Mars 2019 à 18:13
-- Version du serveur : 5.7.25-0ubuntu0.18.04.2
-- Version de PHP : 7.2.15-0ubuntu0.18.04.1
......@@ -19,8 +19,7 @@ SET time_zone = "+00:00";
--
-- Base de données : `l3m`
--
DROP DATABASE IF EXISTS `l3m`;
CREATE DATABASE IF NOT EXISTS `l3m` DEFAULT CHARACTER SET latin1 COLLATE latin1_swedish_ci;
CREATE DATABASE IF NOT EXISTS `l3m` DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
USE `l3m`;
-- --------------------------------------------------------
......@@ -64,7 +63,8 @@ CREATE TABLE `l3m_projects` (
DROP TABLE IF EXISTS `l3m_tag`;
CREATE TABLE `l3m_tag` (
`id` int(11) NOT NULL,
`tag` varchar(255) NOT NULL
`tag` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci NOT NULL,
`slug` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
-- --------------------------------------------------------
......@@ -116,7 +116,7 @@ ALTER TABLE `l3m_tag_post`
-- AUTO_INCREMENT pour la table `l3m_blog`
--
ALTER TABLE `l3m_blog`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;
--
-- AUTO_INCREMENT pour la table `l3m_projects`
--
......@@ -126,12 +126,12 @@ ALTER TABLE `l3m_projects`
-- AUTO_INCREMENT pour la table `l3m_tag`
--
ALTER TABLE `l3m_tag`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=17;
--
-- AUTO_INCREMENT pour la table `l3m_tag_post`
--
ALTER TABLE `l3m_tag_post`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=30;
/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
......@@ -33,19 +33,21 @@ class Base
$slug = "default";
// check if the slug already exist
$i = 1;
$old = $slug;
do{
$req = self::$db->prepare('SELECT slug FROM l3m_'. $table .' WHERE slug = ?');
$req->execute([$slug]);
$slugExist = $req->fetch();
if($slugExist)
{
$i++;
$slug = $old . "-" . $i;
if($table == "blog" || $table == "project"){
$i = 1;
$old = $slug;
do{
$req = self::$db->prepare('SELECT slug FROM l3m_'. $table .' WHERE slug = ?');
$req->execute([$slug]);
$slugExist = $req->fetch();
if($slugExist)
{
$i++;
$slug = $old . "-" . $i;
}
}
while($slugExist);
}
while($slugExist);
return $slug;
}
......
......@@ -59,7 +59,7 @@ class BlogManager extends Base
public function getTag($tag)
{
$req = self::$db->prepare('SELECT l3m_blog.* FROM l3m_blog, l3m_tag_post, l3m_tag WHERE l3m_blog.id = l3m_tag_post.post AND l3m_tag.id = l3m_tag_post.tag AND l3m_tag.tag = ? ORDER BY id DESC');
$req = self::$db->prepare('SELECT l3m_blog.*, l3m_tag.tag FROM l3m_blog, l3m_tag_post, l3m_tag WHERE l3m_blog.id = l3m_tag_post.post AND l3m_tag.id = l3m_tag_post.tag AND l3m_tag.slug = ? ORDER BY id DESC');
$req->execute([$tag]);
$posts = $req->fetchAll();
......
......@@ -5,21 +5,24 @@ class TagManager extends Base
public function addTag($tags, $post)
{
// donne tags = [[tag1], [tag2], ...]
$tags = explode(', ', $tags);
$tags = str_replace(' ', '-', $tags);
// remplace "tag1, tag2 , tag3,tag4, tag5" en "tag1,tag2,tag3,tag4,tag5"
$tags = preg_replace('( ,|, )', ',', $tags);
// crée le tableau tags = ["tag1", "tag2", ...]
$tags = explode(',', $tags);
if($tags[0] != ''){
// on ajoute chaque tag dans les tables correspondantes
foreach ($tags as $tag)
{
$slug = $this->slugify($tag, null);
$idTag = $this->exist($tag);
// si le tag n'existe pas, on l'ajoute dans la liste des tags
if(!$idTag)
{
$req = self::$db->prepare('INSERT INTO l3m_tag(tag) VALUES(:tag)');
$req = self::$db->prepare('INSERT INTO l3m_tag(tag, slug) VALUES(:tag, :slug)');
$req->execute([
'tag' => $tag
'tag' => $tag,
'slug' => $slug
]);
// on sait que c'est ce tag qui vient d'être ajouté
......@@ -58,7 +61,7 @@ class TagManager extends Base
// permet de récupérer les tags pour les afficher
function getTags($id)
{
$req = self::$db->prepare('SELECT l3m_tag.tag FROM l3m_tag, l3m_tag_post WHERE l3m_tag.id = l3m_tag_post.tag AND l3m_tag_post.post = ?');
$req = self::$db->prepare('SELECT l3m_tag.tag, l3m_tag.slug FROM l3m_tag, l3m_tag_post WHERE l3m_tag.id = l3m_tag_post.tag AND l3m_tag_post.post = ?');
$req->execute([$id]);
$tags = $req->fetchAll();
......
......@@ -9,7 +9,7 @@
if(isset($blogpost['tags']) && $blogpost['tags'])
{
foreach ($blogpost['tags'] as $tag) {
$tags .= "<em class=\"tag\"><a href=\"/tag/". $tag["tag"] ."\">". $tag["tag"]."</a></em>";
$tags .= "<em class=\"tag\"><a href=\"/tag/". $tag["slug"] ."\">". $tag["tag"]."</a></em>";
}
}
else
......
<article>
<h3><a href="">20/03/19</a></h3>
<h3><a href="">21/03/19</a></h3>
<ul>
<li>Ajout d'un slug pour les tags + possibilité de stocker des tags "emoji" dans la bdd</li>
<li>Ajout d'un effet de hover sur les tags</li>
</ul>
</article>
<article>
<h3><a href="https://git.bitmycode.com/sodimel/l3m-website/commit/72e337a3db699bac92f4e25828a8c0b4dee47bd6">20/03/19</a></h3>
<ul>
<li>Création des tags :
<ul>
......
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