Compare commits
No commits in common. "5a0037f11ac56285bd2aebce481fd0491e998a54" and "76ab05c8c7ee7e36aba2a3ec178e026cd95b91e7" have entirely different histories.
5a0037f11a
...
76ab05c8c7
5 changed files with 27 additions and 63 deletions
21
README.md
21
README.md
|
@ -5,24 +5,3 @@ There is nothing stored on the server except the words.
|
||||||
## Database
|
## Database
|
||||||
Database config option is set in the dbconfig.php file,
|
Database config option is set in the dbconfig.php file,
|
||||||
example is in dbconfig_empty.php.
|
example is in dbconfig_empty.php.
|
||||||
This software is developped with PostgreSQL,
|
|
||||||
I don't know if it is working with others DB management systems.
|
|
||||||
|
|
||||||
## Libraries
|
|
||||||
|
|
||||||
### php-i18n
|
|
||||||
|
|
||||||
The internationalization is made possible by
|
|
||||||
[Philipp Schröer (php-i18n project)](https://github.com/Philipp15b/php-i18n).
|
|
||||||
For now it's only in french but the traduction should be easy.
|
|
||||||
|
|
||||||
### Wordcloud2
|
|
||||||
|
|
||||||
The display of the words cloud is done by the Wordcloud2 javascript
|
|
||||||
code, made by
|
|
||||||
[Timothy Guan-tin Chien](http://timdream.org/wordcloud2.js/).
|
|
||||||
|
|
||||||
### Soundex_fr
|
|
||||||
|
|
||||||
The words comparison is made with PHP tools and the work of
|
|
||||||
Florent Bruneau on [the french translation of soundex](http://blog.mymind.fr/blog/2007/03/15/soundex-francais/).
|
|
||||||
|
|
|
@ -24,11 +24,12 @@ if (empty($_POST)) {
|
||||||
<label for="fsize"><?php echo L::cloud_size ?></label>
|
<label for="fsize"><?php echo L::cloud_size ?></label>
|
||||||
<input type="number" id="fsize" name="fsize" min="1" max="9" value=<?php echo DataBase::DEFAULT_SIZE ?>>
|
<input type="number" id="fsize" name="fsize" min="1" max="9" value=<?php echo DataBase::DEFAULT_SIZE ?>>
|
||||||
</div>
|
</div>
|
||||||
<input type="submit" id="cloud_create_submit" value="<?php echo L::create_button ?>">
|
<input type="submit" id="cloud_create_submit" value="<?php echo L::create ?>">
|
||||||
</form>
|
</form>
|
||||||
</div>
|
</div>
|
||||||
<?php
|
<?php
|
||||||
} else {
|
} else {
|
||||||
|
/*$token = bin2hex(random_bytes(DataBase::CLOUD_CODE_LENGTH));*/
|
||||||
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
|
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
|
||||||
$size = $_POST['fsize'];
|
$size = $_POST['fsize'];
|
||||||
} else {
|
} else {
|
||||||
|
|
58
db.php
58
db.php
|
@ -14,7 +14,6 @@ class DataBase
|
||||||
const DEFAULT_SIZE = 3;
|
const DEFAULT_SIZE = 3;
|
||||||
const MAX_SIZE = 9;
|
const MAX_SIZE = 9;
|
||||||
const CLOUD_CODE_LENGTH = 6;
|
const CLOUD_CODE_LENGTH = 6;
|
||||||
const CLOUD_CODE_MAXTRY = 10;
|
|
||||||
|
|
||||||
private $db;
|
private $db;
|
||||||
private $cloud;
|
private $cloud;
|
||||||
|
@ -132,40 +131,16 @@ class DataBase
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
public function getWordsList(string $id)
|
||||||
* Get the list of the words inside the cloud
|
|
||||||
*
|
|
||||||
* If there is no $code parameter and the cloud isn't already loaded,
|
|
||||||
* return null.
|
|
||||||
*
|
|
||||||
* Return a list of words, orderer from the most used to the least,
|
|
||||||
* with the following fields:
|
|
||||||
* - word => the word
|
|
||||||
* - count => the number of occurences of the word
|
|
||||||
* - relative => the relative number of occurences,
|
|
||||||
* relative to the occurence max
|
|
||||||
* - percent => the percent of word in the cloud,
|
|
||||||
* relative to the total number of words
|
|
||||||
* @param string $code Code of the cloud
|
|
||||||
* @return array|null The words list
|
|
||||||
*/
|
|
||||||
public function getWordsList(string $code = null)
|
|
||||||
{
|
{
|
||||||
if (isset($code)) {
|
|
||||||
$this->loadCloudByCode($code);
|
|
||||||
}
|
|
||||||
if (!isset($code) && !$this->isCloudSet()) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
$stmt = $this->db->prepare("
|
$stmt = $this->db->prepare("
|
||||||
SELECT *
|
SELECT *
|
||||||
FROM words
|
FROM words
|
||||||
JOIN clouds
|
JOIN clouds
|
||||||
ON words.cloud_id = clouds.id_cloud
|
ON words.cloud_id = clouds.id_cloud
|
||||||
WHERE code = :code;
|
WHERE code = :id;
|
||||||
");
|
");
|
||||||
$stmt->bindValue(':code', $this->cloud['code']);
|
$stmt->bindValue(':id', $id);
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
$words = [];
|
$words = [];
|
||||||
$values = [];
|
$values = [];
|
||||||
|
@ -218,25 +193,34 @@ class DataBase
|
||||||
$duration = self::DEFAULT_DURATION;
|
$duration = self::DEFAULT_DURATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
for ($i = 0; $i < self::CLOUD_CODE_MAXTRY; $i++) {
|
$cpt = 0;
|
||||||
|
$codeIsUsed = true;
|
||||||
|
while ($codeIsUsed && $cpt < 0) {
|
||||||
$code = bin2hex(random_bytes(self::CLOUD_CODE_LENGTH));
|
$code = bin2hex(random_bytes(self::CLOUD_CODE_LENGTH));
|
||||||
$code = '2ae606bfb6d2';
|
$stmt = $this->db->prepare("
|
||||||
if (!$this->loadCloudByCode($code)) {
|
SELECT *
|
||||||
break;
|
FROM clouds
|
||||||
|
WHERE code = :code;
|
||||||
|
");
|
||||||
|
$stmt->bindValue(':code', $code);
|
||||||
|
$stmt->execute();
|
||||||
|
if (!$data = $stmt->fetch()) {
|
||||||
|
$codeIsUsed = false;
|
||||||
}
|
}
|
||||||
|
$cpt++;
|
||||||
}
|
}
|
||||||
if ($this->isCloudSet()) {
|
if ($codeIsUsed) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
$delete = date('Y-m-d H:i:s', strtotime(self::OPTIONS_DURATION[$duration]));
|
$duration = date('Y-m-d H:i:s', strtotime(self::OPTIONS_DURATION[$duration]));
|
||||||
$stmt = $this->db->prepare("
|
$stmt = $this->db->prepare("
|
||||||
INSERT INTO clouds(code, text, size, delete_t)
|
INSERT INTO clouds(code, text, size, delete_t)
|
||||||
VALUES (:code, :text, :size, :delete);
|
VALUES (:code, :text, :size, :duration);
|
||||||
");
|
");
|
||||||
$stmt->bindValue(':code', $code, PDO::PARAM_STR);
|
$stmt->bindValue(':code', $code, PDO::PARAM_STR);
|
||||||
$stmt->bindValue(':text', $text, PDO::PARAM_STR);
|
$stmt->bindValue(':text', $text, PDO::PARAM_STR);
|
||||||
$stmt->bindValue(':size', $size, PDO::PARAM_INT);
|
$stmt->bindValue(':size', $size, PDO::PARAM_INT);
|
||||||
$stmt->bindValue(':delete', $delete, PDO::PARAM_STR);
|
$stmt->bindValue(':duration', $duration, PDO::PARAM_STR);
|
||||||
try {
|
try {
|
||||||
$stmt->execute();
|
$stmt->execute();
|
||||||
} catch (PDOEXception $e) {
|
} catch (PDOEXception $e) {
|
||||||
|
@ -246,7 +230,7 @@ class DataBase
|
||||||
'id' => $this->db->lastInsertId(),
|
'id' => $this->db->lastInsertId(),
|
||||||
'code' => $code,
|
'code' => $code,
|
||||||
'size' => $size,
|
'size' => $size,
|
||||||
'delete_t' => $delete,
|
'delete_t' => $duration,
|
||||||
'text' => $text,
|
'text' => $text,
|
||||||
);
|
);
|
||||||
return $this->cloud;
|
return $this->cloud;
|
||||||
|
|
|
@ -29,7 +29,7 @@ if (isset($_GET['id'])) {
|
||||||
?>
|
?>
|
||||||
<p><?php echo L::cloud_create_message ?></p>
|
<p><?php echo L::cloud_create_message ?></p>
|
||||||
<form method="post" action="create.php">
|
<form method="post" action="create.php">
|
||||||
<input type="submit" value="<?php echo L::create_button ?>">
|
<input type="submit" value="<?php echo L::create ?>">
|
||||||
</form>
|
</form>
|
||||||
<?php
|
<?php
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
|
|
||||||
title = "SimpleWordsCloud"
|
title = "SimpleWordsCloud"
|
||||||
description = "Création de nuage de mots, simple, sans inscriptions et respectant la vie privée"
|
description = "Création de nuage de mots, simple, sans inscriptions et respectant la vie privée"
|
||||||
|
create = "Créer"
|
||||||
|
|
||||||
[cloud]
|
[cloud]
|
||||||
description = "Description du nuage"
|
description = "Description du nuage"
|
||||||
|
@ -46,7 +47,6 @@ cloudNotFound = "Le nuage <em>%s</em> n'a pas été trouvé, veuillez vérifier
|
||||||
|
|
||||||
[create]
|
[create]
|
||||||
errorCode = "Erreur lors de la création du nuage, désolé du dérangement."
|
errorCode = "Erreur lors de la création du nuage, désolé du dérangement."
|
||||||
button = "Créer"
|
|
||||||
|
|
||||||
[duration]
|
[duration]
|
||||||
day = "un jour"
|
day = "un jour"
|
||||||
|
|
Loading…
Reference in a new issue