Use an i18n tool

This commit is contained in:
Gregory Trolliet 2020-11-23 11:01:37 +01:00
parent e487438606
commit 16dec853f9
12 changed files with 662 additions and 97 deletions

View File

@ -0,0 +1,40 @@
<?php
class L {
const title = 'SimpleWordsCloud';
const create = 'Créer';
const cloud_description = 'Description du nuage';
const cloud_description_message = 'Entrez ici le descriptif de votre nuage';
const cloud_duration = 'Durée de vie du nuage';
const cloud_duration_tooltip = 'Durée après laquelle le nuage sera supprimé';
const cloud_size = 'Nombre de mots maximum par entrée';
const cloud_create_message = 'Voulez-vous créer un nouveau nuage de mots?';
const cloud_links_warning = 'Attention, il n\'y a aucun moyen de retrouver ces liens par la suite.';
const cloud_noId = 'Aucun nuage se trouve à cet endroit, désolé.';
const cloud_empty = 'Il n\'y a pas encore de mots dans ce nuage.';
const cloud_link_view_title = 'Voici le lien pour <b>visualiser</b> le nuage de mots, il permet de voir le résultat.';
const cloud_link_view_tooltip = 'Lien pour visualiser le nuage de mots';
const cloud_link_vote_title = 'Voici le lien pour <b>participer</b> au nuage, c\'est le lien à partager avec les autres personnes.';
const cloud_link_vote_tooltip = 'Lien pour participer au nuage';
const save_message = 'Vous pouvez entrer ici un ou plusieurs mots, les mots vides ne seront pas pris en compte.';
const save_submit = 'Enregistrer';
const save_word = 'Mot %d';
const save_success = 'Vos mots ont bien été enregistrés, merci de votre participation.';
const duration_day = 'un jour';
const duration_week = 'une semaine';
const duration_week2 = 'deux semaines';
const duration_month = 'un mois';
const db_init_error = 'Error d\'initialisation de la base de données';
const wordsList_title = 'Liste des mots du nuage';
const wordsList_word = 'Mot';
const wordsList_count = 'Nombre';
const wordsList_percent = '%';
public static function __callStatic($string, $args) {
if (defined("self::" . $string)) {
return vsprintf(constant("self::" . $string), $args);
}
}
function L($string, $args=NULL) {
$return = constant("L::".$string);
return $args ? vsprintf($return,$args) : $return;
}
}

View File

@ -0,0 +1,13 @@
<?php
class L {
const home = 'Accueil';
public static function __callStatic($string, $args) {
if (defined("self::" . $string)) {
return vsprintf(constant("self::" . $string), $args);
}
}
function L($string, $args=NULL) {
$return = constant("L::".$string);
return $args ? vsprintf($return,$args) : $return;
}
}

View File

@ -1,88 +1,75 @@
<?php
include('init.php');
include('templates/header.php');
include('db.php');
if (empty($_POST)) {
?>
<div id="cloud_create">
<form method="post" action="create.php">
<div class="cloud_create_element">
<label id="ftext_l" for="ftext">Description du nuage</label>
<textarea id="ftext" name="ftext" rows="3" cols="60" placeholder="Votre texte ici"></textarea>
<label id="ftext_l" for="ftext"><?php echo L::cloud_description ?></label>
<textarea id="ftext" name="ftext" rows="3" cols="50" placeholder="<?php echo L::cloud_description_message ?>"></textarea>
</div>
<div class="cloud_create_element">
<label for="fduration">
<span title="Durée après laquelle le nuage sera supprimé">
Durée de vie du nuage
</span>
</label>
<label for="fduration"><span title="<?php echo L::cloud_duration_tooltip ?>"><?php echo L::cloud_duration ?></span></label>
<select id="fduration" name="fduration">
<?php
foreach (DataBase::OPTIONS_DURATION as $name => $duration) {
echo sprintf('<option valu="%s">%s</option>', $name, $name);
echo sprintf('<option value="%s">%s</option>', $name, constant('L::duration_' . $name));
}
?>
</select>
</div>
<div class="cloud_create_element">
<label for="fsize">Nombre de mots maximum par entrée</label>
<input type="number" id="fsize" name="fsize" min="1" max="9">
<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 ?>>
</div>
<input type="submit" value="Créer">
<input type="submit" id="cloud_create_submit" value="<?php echo L::create ?>">
</form>
</div>
<?php
} else {
$db = new DataBase();
if (!$db->isInit()) {
echo 'Error db init';
return;
}
$db->cleanCloud();
$length = 6;
$token = bin2hex(random_bytes($length));
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
$size = $_POST['fsize'];
} else {
$size = 3;
}
if (isset($_POST['ftext'])) {
$text = $_POST['ftext'];
} else {
$text = '';
}
if (isset($_POST['fduration']) && in_array($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
$duration = $_POST['fduration'];
} else {
$duration = DataBase::DEFAULT_DURATION;
}
$cpt = 0;
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
$length = 6;
$token = bin2hex(random_bytes($length));
$cpt++;
}
$viewUrl = 'result.php?id=' . $token;
$viewName = $_SERVER['HTTP_ORIGIN'] . '/'. $viewUrl;
$voteUrl = 'index.php?id=' . $token;
$voteName = $_SERVER['HTTP_ORIGIN'] . '/' . $voteUrl;
if (isset($_POST['fsize']) && is_numeric($_POST['fsize'])) {
$size = $_POST['fsize'];
} else {
$size = 3;
}
if (isset($_POST['ftext'])) {
$text = $_POST['ftext'];
} else {
$text = '';
}
if (isset($_POST['fduration']) && in_array($_POST['fduration'], DataBase::OPTIONS_DURATION)) {
$duration = $_POST['fduration'];
} else {
$duration = DataBase::DEFAULT_DURATION;
}
$cpt = 0;
while (!$db->createCloud($token, $text, $size, $duration) && $cpt < 10) {
$token = bin2hex(random_bytes($length));
$cpt++;
}
$viewUrl = 'result.php?id=' . $token;
$viewName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $viewUrl;
$voteUrl = 'index.php?id=' . $token;
$voteName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $voteUrl;
?>
<h2>Attention, il n'y a aucun moyen de retrouver ces liens par la suite.</h2>
<h2><?php echo L::cloud_links_warning ?></h2>
<div id="cloud_links">
<div id="cloud_links_results" class="cloud_link">
<div class="label">Voici le lien pour <b>visualiser</b> le nuage de mots, il permet de voir le résultat.</div>
<div class="label"><?php echo L::cloud_link_view_title ?></div>
<div class="link">
<a href="<?php echo $viewUrl ?>"><?php echo $viewName ?></a>
<a href="<?php echo $viewUrl ?>" title="<?php echo L::cloud_link_view_tooltip ?>"><?php echo $viewName ?></a>
</div>
</div>
<div id="cloud_links_vote" class="cloud_link">
<div class="label">Voici le lien pour <b>participer</b> au nuage, c'est le lien à partager avec les autres personnes.</div>
<div class="label"><?php echo L::cloud_link_vote_title ?></div>
<div class="link">
<a href="<?php echo $voteUrl ?>"><?php echo $voteName ?></a>
<a href="<?php echo $voteUrl ?>" title="<?php echo L::cloud_link_vote_tooltip ?>"><?php echo $voteName ?></a>
</div>
</div>
</div>

View File

@ -91,10 +91,19 @@ footer, #page-wrap:after {
.cloud_words_input {
margin: 1em;
}
.cloud_words input:nth-of-type(2) {
margin-left: 0;
}
.cloud_words input:nth-last-of-type(2) {
margin-right: 0;
}
#cloud_words_submit {
display: block;
margin-top: 1em;
}
#cloud_create_submit {
margin-top: 1em;
}
.cloud_link {
margin-bottom: 1em;
}
@ -102,3 +111,10 @@ footer, #page-wrap:after {
#cloud_create #ftext_l{
vertical-align: top;
}
#cloud_create label::after{
content: '\00a0:';
}
summary:active, summary:focus {
outline: none;
}

47
db.php
View File

@ -7,9 +7,10 @@ class DataBase
const OPTIONS_DURATION = array(
'day' => '+1 day',
'week' => '+7 day',
'2week' => '+14 day',
'week2' => '+14 day',
'month' => '+1 month'
);
const DEFAULT_SIZE = 3;
private $db;
@ -123,12 +124,22 @@ class DataBase
");
$stmt->bindValue(':id', $id);
$stmt->execute();
$words = [];
$words = [];
$values = [];
$total = 0;
$max = 0;
while ($data = $stmt->fetch()) {
$words[] = array($data['word'], $data['count']);
$words[] = array(
'word' => $data['word'],
'count' => $data['count'],
);
$values[] = $data['count'];
$total += $data['count'];
$max = max($max, $data['count']);
}
foreach ($words as $key => $word) {
$words[$key]['relative'] = $word['count'] / $max;
$words[$key]['percent'] = $word['count'] / $total * 100;
}
array_multisort($values, SORT_DESC, $words);
@ -152,15 +163,12 @@ class DataBase
public function getWordsRelative(string $id)
{
$words = $this->getWordsList($id);
$max = 0;
foreach ($words as $word) {
$max = max($max, $word[1]);
}
$wordsClean = [];
foreach ($words as $key => $word) {
$words[$key] = array($word[0], $word[1] / $max);
$wordsClean[] = array($word['word'], $word['relative']);
}
return $words;
return $wordsClean;
}
public function createCloud(
@ -206,7 +214,7 @@ class DataBase
if ($data = $stmt->fetch()) {
return $data['size'];
}
return null;
return 0;
}
public function getCloudText(string $ref)
@ -214,7 +222,7 @@ class DataBase
$stmt = $this->db->prepare("
SELECT *
FROM clouds
WHERE code= :code;
WHERE code = :code;
");
$stmt->bindValue(':code', $ref, PDO::PARAM_STR);
$stmt->execute();
@ -224,6 +232,23 @@ class DataBase
return null;
}
public function countWords(string $cloud)
{
$stmt = $this->db->prepare("
SELECT count(*) as count
FROM clouds
JOIN words
ON id_cloud = cloud_id
WHERE code = :code;
");
$stmt->bindValue(':code', $cloud, PDO::PARAM_STR);
$stmt->execute();
if ($data = $stmt->fetch()) {
return $data['count'];
}
return null;
}
public function cleanCloud()
{
$stmt = $this->db->prepare("

377
i18n.php Normal file
View File

@ -0,0 +1,377 @@
<?php
/*
* Fork this project on GitHub!
* https://github.com/Philipp15b/php-i18n
*
* License: MIT
*/
class i18n {
/**
* Language file path
*
* This is the path for the language files.
* You must use the '{LANGUAGE}' placeholder for the language or
* the script wont find any language files.
*
* @var string
*/
protected $filePath = './lang/lang_{LANGUAGE}.ini';
/**
* Cache file path
*
* This is the path for all the cache files.
* Best is an empty directory with no other files in it.
*
* @var string
*/
protected $cachePath = './cache/lang/';
/**
* Fallback language
*
* This is the language which is used when there is no language file for
* all other user languages.
* It has the lowest priority.
* Remember to create a language file for the fallback!!
*
* @var string
*/
protected $fallbackLang = 'en';
/**
* Merge in fallback language
*
* Whether to merge current language's strings with the strings of
* the fallback language ($fallbackLang).
*
* @var bool
*/
protected $mergeFallback = true;
/**
* The class name of the compiled class that contains the translated texts.
* @var string
*/
protected $prefix = 'L';
/**
* Forced language
*
* If you want to force a specific language define it here.
*
* @var string
*/
protected $forcedLang = NULL;
/**
* This is the separator used if you use sections in your ini-file
*
* For example, if you have a string 'greeting' in a section 'welcomepage'
* you will can access it via 'L::welcomepage_greeting'.
* If you changed it to 'ABC' you could access your string
* via 'L::welcomepageABCgreeting'
*
* @var string
*/
protected $sectionSeparator = '_';
/*
* The following properties are only available after calling init().
*/
/**
* User languages
*
* These are the languages the user uses.
* Normally, if you use the getUserLangs-method this array will be
* filled in like this:
* 1. Forced language
* 2. Language in $_GET['lang']
* 3. Language in $_SESSION['lang']
* 4. Fallback language
*
* @var array
*/
protected $userLangs = array();
protected $appliedLang = NULL;
protected $langFilePath = NULL;
protected $cacheFilePath = NULL;
protected $isInitialized = false;
/**
* Constructor
*
* The constructor sets all important settings.
* All params are optional, you can set the options via extra functions too.
*
* @param string [$filePath] This is the path for the language files.
* You must use the '{LANGUAGE}' placeholder for the language.
* @param string [$cachePath] This is the path for all the cache files.
* Best is an empty directory with no other files in it. No placeholders.
* @param string [$fallbackLang] This is the language which is used
* when there is no language file for all other user languages.
* It has the lowest priority.
* @param string [$prefix] The class name of the compiled class
* that contains the translated texts. Defaults to 'L'.
*/
public function __construct(
$filePath = NULL,
$cachePath = NULL,
$fallbackLang = NULL,
$prefix = NULL)
{
// Apply settings
if ($filePath != NULL) {
$this->filePath = $filePath;
}
if ($cachePath != NULL) {
$this->cachePath = $cachePath;
}
if ($fallbackLang != NULL) {
$this->fallbackLang = $fallbackLang;
}
if ($prefix != NULL) {
$this->prefix = $prefix;
}
}
public function init() {
if ($this->isInitialized()) {
throw new BadMethodCallException(
'This object from class ' . __CLASS__ .
' is already initialized. ' .
'It is not possible to init one object twice!');
}
$this->isInitialized = true;
$this->userLangs = $this->getUserLangs();
// search for language file
$this->appliedLang = NULL;
foreach ($this->userLangs as $priority => $langcode) {
$this->langFilePath = $this->getConfigFilename($langcode);
if (file_exists($this->langFilePath)) {
$this->appliedLang = $langcode;
break;
}
}
if ($this->appliedLang == NULL) {
throw new RuntimeException('No language file was found.');
}
// search for cache file
$this->cacheFilePath =
$this->cachePath . '/php_i18n_' . md5_file(__FILE__) . '_' .
$this->prefix . '_' . $this->appliedLang . '.cache.php';
// whether we need to create a new cache file
$outdated = !file_exists($this->cacheFilePath) ||
filemtime($this->cacheFilePath) < filemtime($this->langFilePath) || // the language config was updated
($this->mergeFallback && filemtime($this->cacheFilePath) < filemtime($this->getConfigFilename($this->fallbackLang))); // the fallback language config was updated
if ($outdated || true) {
$config = $this->load($this->langFilePath);
if ($this->mergeFallback)
$config = array_replace_recursive($this->load($this->getConfigFilename($this->fallbackLang)), $config);
$compiled =
"<?php\n"
. "class " . $this->prefix . " {\n"
. $this->compile($config)
. ' public static function __callStatic($string, $args) {' . "\n"
. ' if (defined("self::" . $string)) {' . "\n"
. ' return vsprintf(constant("self::" . $string), $args);' . "\n"
. " }\n"
. " }\n"
. " function ".$this->prefix .'($string, $args=NULL) {' . "\n"
. ' $return = constant("'.$this->prefix.'::".$string);' . "\n"
. ' return $args ? vsprintf($return,$args) : $return;' . "\n"
. " }\n"
. '}';
if( ! is_dir($this->cachePath)) {
mkdir($this->cachePath, 0755, true);
}
if (file_put_contents($this->cacheFilePath, $compiled) === FALSE) {
throw new Exception("Could not write cache file to path '" . $this->cacheFilePath . "'. Is it writable?");
}
chmod($this->cacheFilePath, 0755);
}
require_once $this->cacheFilePath;
}
public function isInitialized() {
return $this->isInitialized;
}
public function getAppliedLang() {
return $this->appliedLang;
}
public function getCachePath() {
return $this->cachePath;
}
public function getFallbackLang() {
return $this->fallbackLang;
}
public function setFilePath($filePath) {
$this->fail_after_init();
$this->filePath = $filePath;
}
public function setCachePath($cachePath) {
$this->fail_after_init();
$this->cachePath = $cachePath;
}
public function setFallbackLang($fallbackLang) {
$this->fail_after_init();
$this->fallbackLang = $fallbackLang;
}
public function setMergeFallback($mergeFallback) {
$this->fail_after_init();
$this->mergeFallback = $mergeFallback;
}
public function setPrefix($prefix) {
$this->fail_after_init();
$this->prefix = $prefix;
}
public function setForcedLang($forcedLang) {
$this->fail_after_init();
$this->forcedLang = $forcedLang;
}
public function setSectionSeparator($sectionSeparator) {
$this->fail_after_init();
$this->sectionSeparator = $sectionSeparator;
}
/**
* @deprecated Use setSectionSeparator.
*/
public function setSectionSeperator($sectionSeparator) {
$this->setSectionSeparator($sectionSeparator);
}
/**
* Returns the user languages
*
* Normally it returns an array like this:
* 1. Forced language
* 2. Language in $_GET['lang']
* 3. Language in $_SESSION['lang']
* 4. HTTP_ACCEPT_LANGUAGE
* 5. Fallback language
* Note: duplicate values are deleted.
*
* @return array with the user languages sorted by priority.
*/
public function getUserLangs() {
$userLangs = array();
// Highest priority: forced language
if ($this->forcedLang != NULL) {
$userLangs[] = $this->forcedLang;
}
// 2nd highest priority: GET parameter 'lang'
if (isset($_GET['lang']) && is_string($_GET['lang'])) {
$userLangs[] = $_GET['lang'];
}
// 3rd highest priority: SESSION parameter 'lang'
if (isset($_SESSION['lang']) && is_string($_SESSION['lang'])) {
$userLangs[] = $_SESSION['lang'];
}
// 4th highest priority: HTTP_ACCEPT_LANGUAGE
if (isset($_SERVER['HTTP_ACCEPT_LANGUAGE'])) {
foreach (explode(',', $_SERVER['HTTP_ACCEPT_LANGUAGE']) as $part) {
$userLangs[] = strtolower(substr($part, 0, 2));
}
}
// Lowest priority: fallback
$userLangs[] = $this->fallbackLang;
// remove duplicate elements
$userLangs = array_unique($userLangs);
// remove illegal userLangs
$userLangs2 = array();
foreach ($userLangs as $key => $value) {
// only allow a-z, A-Z and 0-9 and _ and -
if (preg_match('/^[a-zA-Z0-9_-]*$/', $value) === 1)
$userLangs2[$key] = $value;
}
return $userLangs2;
}
protected function getConfigFilename($langcode) {
return str_replace('{LANGUAGE}', $langcode, $this->filePath);
}
protected function load($filename) {
$ext = substr(strrchr($filename, '.'), 1);
switch ($ext) {
case 'properties':
case 'ini':
$config = parse_ini_file($filename, true);
break;
case 'yml':
case 'yaml':
$config = spyc_load_file($filename);
break;
case 'json':
$config = json_decode(file_get_contents($filename), true);
break;
default:
throw new InvalidArgumentException($ext . " is not a valid extension!");
}
return $config;
}
/**
* Recursively compile an associative array to PHP code.
*/
protected function compile($config, $prefix = '') {
$code = '';
foreach ($config as $key => $value) {
if (is_array($value)) {
$code .= $this->compile($value, $prefix . $key . $this->sectionSeparator);
} else {
$fullName = $prefix . $key;
if (!preg_match('/^[a-zA-Z_\x7f-\xff][a-zA-Z0-9_\x7f-\xff]*$/', $fullName)) {
throw new InvalidArgumentException(__CLASS__ . ": Cannot compile translation key " . $fullName . " because it is not a valid PHP identifier.");
}
$code .= ' const ' . $fullName . ' = \'' . str_replace('\'', '\\\'', $value) . "';\n";
}
}
return $code;
}
protected function fail_after_init() {
if ($this->isInitialized()) {
throw new BadMethodCallException('This ' . __CLASS__ . ' object is already initalized, so you can not change any settings.');
}
}
}

View File

@ -1,18 +1,12 @@
<?php
include('init.php');
include('templates/header.php');
include('db.php');
$db = new DataBase();
if (!$db->isInit()) {
echo 'Error db init';
return;
}
$db->buildTables();
if (isset($_GET['id'])) {
$id = $_GET['id'];
if (!$db->isCloud($id)) {
echo 'NO CLOUD';
echo L::cloud_noId;
return;
}
$nbWords = $db->getCloudSize($id);
@ -23,17 +17,20 @@ if (isset($_GET['id'])) {
<?php
for ($i=0;$i<$nbWords;$i++) {
$name = 'fword' . $i;
echo sprintf('<input class="cloud_words_input" type="text" id="%s" name="%s" placeholder="Mot %d">', $name, $name, $i+1);
echo sprintf('<input class="cloud_words_input" type="text" id="%s" name="%s" placeholder="%s">',
$name, $name, L::save_word($i + 1)
);
}
?>
<input id="cloud_words_submit" type="submit" value="Enregistrer">
<input id="cloud_words_submit" type="submit" value="<?php echo L::save_submit ?>">
</form>
<p><?php echo L::save_message ?></p>
<?php
} else {
?>
<p>Voulez-vous créer un nouveau nuage de mots?</p>
<p><?php echo L::cloud_create_message ?></p>
<form method="post" action="create.php">
<input type="submit" value="Créer">
<input type="submit" value="<?php echo L::create ?>">
</form>
<?php
}

14
init.php Normal file
View File

@ -0,0 +1,14 @@
<?php
require_once 'i18n.php';
$i18n = new i18n('lang/lang_{LANGUAGE}.ini', 'cache/lang/', 'fr');
$i18n->init();
include('db.php');
$db = new DataBase();
if (!$db->isInit()) {
echo L::db_init_error;
return;
}
$db->cleanCloud();

58
lang/lang_fr.ini Normal file
View File

@ -0,0 +1,58 @@
; Language file for french
;
; The id for each value can be either:
; * a generic value
; * a class value
; * a sub-class value, of the following type:
; * message, when it's used to display a message to the user
; * action, when it's generated by a user action
; * access, when it's related to an access
; * title, when it's a title
; * dataCheck, when it's caused by a data check (formular)
; * tooltip, for html tooltips
; * label, for formular labels
; * value, for formular values
;
; @author Gregory Trolliet <gregory@trolliet.info>
;
title = "SimpleWordsCloud"
create = "Créer"
[cloud]
description = "Description du nuage"
description_message = "Entrez ici le descriptif de votre nuage"
duration = "Durée de vie du nuage"
duration_tooltip = "Durée après laquelle le nuage sera supprimé"
size = "Nombre de mots maximum par entrée"
create_message = "Voulez-vous créer un nouveau nuage de mots?"
links_warning = "Attention, il n'y a aucun moyen de retrouver ces liens par la suite."
noId = "Aucun nuage se trouve à cet endroit, désolé."
empty = "Il n'y a pas encore de mots dans ce nuage."
[cloud_link]
view_title = "Voici le lien pour <b>visualiser</b> le nuage de mots, il permet de voir le résultat."
view_tooltip = "Lien pour visualiser le nuage de mots"
vote_title = "Voici le lien pour <b>participer</b> au nuage, c'est le lien à partager avec les autres personnes."
vote_tooltip = "Lien pour participer au nuage"
[save]
message = "Vous pouvez entrer ici un ou plusieurs mots, les mots vides ne seront pas pris en compte."
submit = "Enregistrer"
word = "Mot %d"
success = "Vos mots ont bien été enregistrés, merci de votre participation."
[duration]
day = "un jour"
week = "une semaine"
week2 = "deux semaines"
month = "un mois"
[db]
init_error = "Error d'initialisation de la base de données"
[wordsList]
title = "Liste des mots du nuage"
word = "Mot"
count = "Nombre"
percent = "%"

View File

@ -1,15 +1,57 @@
<?php
include('init.php');
include('templates/header.php');
if (isset($_GET['id'])) {
$id = $_GET['id'];
if (!$db->isCloud($id)) {
echo '<p>' . L::cloud_noId . '</p>';
$id = null;
}
}
if (isset($id)) {
$nbWords = $db->countWords($id);
if ($nbWords == 0) {
echo sprintf('<h2>%s</h2>', L::cloud_empty);
} else {
$jsWordcloud = true;
}
$voteUrl = 'index.php?id=' . $id;
$voteName = 'https://' . $_SERVER['HTTP_HOST'] . '/' . $voteUrl;
?>
<div id="my_canvas">
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<br/><br/><br/><br/><br/><br/><br/><br/><br/><br/><br/>
<div class="label"><?php echo L::cloud_link_vote_title ?></div>
<div class="link">
<a href="<?php echo $voteUrl ?>" title="<?php echo L::cloud_link_vote_tooltip ?>"><?php echo $voteName ?></a>
</div>
<div id="my_canvas">
</div>
<?php
$jsWordcloud = true;
if ($nbWords > 0) {
?>
<details><summary><?php echo L::wordsList_title ?></summary>
<table>
<thead>
<tr>
<th><?php echo L::wordsList_word ?></th>
<th><?php echo L::wordsList_count ?></th>
<th><?php echo L::wordsList_percent ?></th>
</tr>
</thead>
<tbody>
<?php
foreach ($db->getWordsList($id) as $key => $word) {
echo '<tr>';
echo sprintf('<td>%s</td>', $word['word']);
echo sprintf('<td>%.0f</td>', $word['count']);
echo sprintf('<td>%.1f</td>', $word['percent']);
echo '</tr>';
}
?>
</thead>
</table>
</details>
<?php
}
}
include('templates/footer.php');

View File

@ -1,19 +1,16 @@
<?php
include('db.php');
$db = new DataBase();
if (!$db->isInit()) {
echo 'Error db init';
return;
}
include('init.php');
if (empty($_POST)) {
header('Location: index.php');
die();
}
include 'templates/header.php';
$id = null;
$cpt = 0;
foreach ($_POST as $name => $value) {
$cpt;
if ($name == 'fid') {
$id = $value;
continue;
@ -22,11 +19,10 @@ foreach ($_POST as $name => $value) {
$value = trim(strtolower($value));
$db->addWord($id, $value);
}
if ($cpt > 9) {
break;
}
}
echo sprintf('<h3>%s</h3>', L::save_success);
if (empty($id)) {
header('Location: index.php');
die();
}
header('Location: index.php');
die();
include 'templates/footer.php';

View File

@ -4,7 +4,7 @@
<head>
<meta name="description" content="Webpage description goes here" />
<meta charset="utf-8">
<title>Change_me</title>
<title><?php echo L::title ?></title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="author" content="">
<link rel="stylesheet" href="css/style.css">
@ -14,6 +14,6 @@
<body>
<div id="page-wrap">
<div id="navbar">
<a href="index.php">SimpleWordsCloud</a>
<a href="index.php"><?php echo L::title ?></a>
</div>
<div class="container">