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

add tag slug

parent bb7298ee
Loading
Loading
Loading
Loading
+9 −6
Original line number Diff line number Diff line
@@ -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{
+7 −7
Original line number Diff line number Diff line
@@ -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 */;
+13 −11
Original line number Diff line number Diff line
@@ -33,6 +33,7 @@ class Base
			$slug = "default";

		// check if the slug already exist
		if($table == "blog" || $table == "project"){
			$i = 1;
			$old = $slug;
			do{
@@ -46,6 +47,7 @@ class Base
				}
			}
			while($slugExist);
		}

		return $slug;
	}
+1 −1
Original line number Diff line number Diff line
@@ -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();
+9 −6
Original line number Diff line number Diff line
@@ -5,21 +5,24 @@ class TagManager extends Base
	public function addTag($tags, $post)
	{

		// donne tags = [[tag1], [tag2], ...]
		// 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);
		$tags = str_replace(' ', '-', $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();

Loading