From ce1f76a96cb3c786a81ec9386404b9775eee8c3a Mon Sep 17 00:00:00 2001 From: Gregory Trolliet Date: Mon, 23 Nov 2020 21:59:39 +0100 Subject: [PATCH 1/2] Avoid multiple insertion Avoid multiple insertion of the same word on the same vote --- save.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/save.php b/save.php index 99f623a..00a8818 100644 --- a/save.php +++ b/save.php @@ -9,13 +9,15 @@ include 'templates/header.php'; $id = null; $cpt = 0; +$already_used = array(); foreach ($_POST as $name => $value) { $cpt; if ($name == 'fid') { $id = $value; continue; } - if (isset($id)) { + if (isset($id) && !in_array($value, $already_used)) { + $already_used[] = $value; $value = trim(strtolower($value)); $db->addWord($id, $value); } From 39d4be9eb33e13cef7c2f5d825ac0a210feb0319 Mon Sep 17 00:00:00 2001 From: Gregory Trolliet Date: Mon, 23 Nov 2020 22:17:30 +0100 Subject: [PATCH 2/2] Add words similarity test Should put the almost same words in the same counter --- db.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/db.php b/db.php index 017be28..747df42 100644 --- a/db.php +++ b/db.php @@ -85,6 +85,19 @@ class DataBase } else { return false; } + $stmt = $this->db->prepare(" + SELECT * + FROM words + WHERE cloud_id = :cid; + "); + $stmt->bindValue(':cid', $cloudId, PDO::PARAM_INT); + $stmt->execute(); + while($data = $stmt->fetch()) { + if ($this->areWordsSimilar($data['word'], $word)) { + $word = $data['word']; + break; + } + } $stmt = $this->db->prepare(" SELECT * FROM words @@ -275,4 +288,13 @@ class DataBase return false; } + function areWordsSimilar(string $word1, string $word2) + { + $sim = similar_text($word1, $word2, $perc); + $sim_meta = similar_text(metaphone($word1), metaphone($word2), $perc_meta); + if ($perc >= 80 && $perc_meta >= 80) { + return true; + } + return false; + } }