<?php
|
/*---------------------------------------------------------------*/
|
/*
|
Titre : Générateur de Nuage de Mots
|
|
URL : https://phpsources.net/code_s.php?id=360
|
Date édition : 19 Mars 2008
|
*/
|
/*---------------------------------------------------------------*/
|
|
|
/********************************/
|
/* CONNECTION */
|
/*******************************************************************************
|
* Remplissez avec vos logs de connection
|
***************************************************************************/
|
|
|
$mabasededonnee="";
|
|
$db = mysql_connect("localhost","root","");
|
// test la connection
|
if ( ! $db )
|
die ("connection impossible");
|
// Connecte la base
|
mysql_select_db($mabasededonnee) or die ("pas de connection");
|
|
/********************************/
|
/* ASPIRER VOS DATAS */
|
/*******************************************************************************
|
* Remplissez correctement le nom de votre table pour le nom du champ
|
***************************************************************************/
|
|
$result = mysql_query("SELECT champ FROM table");
|
while ($row = mysql_fetch_array($result)) {
|
$texte .= $row['champ'];
|
}
|
|
/********************************/
|
/* CONFIGURATION */
|
/*******************************************************************************
|
* 2 templates differents
|
* commenter le premier et decommenté le second pour utilisation
|
***************************************************************************/
|
|
/*
|
$taille_des_mots = 6; // taille des mots en nombre de lettre
|
|
// NE PAS TOUCHER
|
$x = 3; $y = 12;
|
$nbre_elements = 36; // nombre d'elements
|
$nbcol_tableau = 2; //détermine le nombre de colonnes
|
*/
|
|
$taille_des_mots = 8; // taille des mots en nombre de lettre
|
$option = 0;
|
// NE PAS TOUCHER
|
$x = 3; $y = 6;
|
$nbre_elements = 18; // nombre d'elements
|
$nbcol_tableau = 1; //détermine le nombre de colonnes
|
|
|
|
/********************************/
|
/* CSS */
|
/*******************************************************************************
|
* 3 classes et pas 1 de plus !!
|
* Vous pouvez modifier le contenu des classes
|
***************************************************************************/
|
|
?>
|
<style type="text/css">
|
a.cloud1 { font-family:Verdana; font-size:24px;text-decoration: none;}
|
a.cloud1:hover { font-family:Verdana; font-size:22px;text-decoration:underline;
|
}
|
a.cloud2 { font-family:Verdana; font-size:16px;text-decoration: none;}
|
a.cloud2:hover { font-family:Verdana; font-size:14px;text-decoration:underline;
|
}
|
a.cloud3 { font-family:Verdana; font-size:14px;text-decoration: none;}
|
a.cloud3:hover { font-family:Verdana; font-size:10px;text-decoration:underline;
|
}
|
</style> <?php
|
|
|
/********************************/
|
/* TEMPS D'EXECUTION */
|
/*******************************************************************************
|
* Mise a zero du calcul du temps d'execution du script
|
***************************************************************************/
|
|
$mtime = microtime();
|
$mtime = explode(" ",$mtime);
|
$mtime = $mtime[1] + $mtime[0];
|
$starttime = $mtime;
|
|
set_time_limit(0);
|
|
|
/********************************/
|
/* STOP WORD */
|
/*******************************************************************************
|
* C'est ici que vous mettez les mots que vous ne voulez pas !
|
***************************************************************************/
|
$tab_banni =
|
array(
|
"mais","ou","et","donc","or","ni","car",
|
"je","il","lui","ils","elle","elles","nous","vous",
|
"vos","votre","mes","mien","mien","tien","tiens",
|
"tout","toute","toutes",
|
"a","b","c","d","e","f","g","h","i","j","l","m","n","o","p","q",
|
"r","s","t","u","v","w","x","y","z",
|
"le","la","les","nos",
|
"alors","au","aucuns","aussi","autre","avant","avec","avoir","bon","car","ce",
|
"cela","ces","ceux","chaque","ci","comme","comment","dans","des","du","dedans",
|
"dehors","depuis","deux","devrait","doit","donc","dos","droite","début","elle",
|
"elles","en","encore","essai","est","et","eu","fait","faites","fois","font",
|
"force","haut","hors","ici","il","ils","je juste","la","le","les","leur","là ",
|
"ma","maintenant","mais","mes","mine","moins","mon","mot","même","ni","nommés"
|
,
|
"notre","nous","nouveaux","ou","où","par","parce","parole","pas","personnes",
|
"peut","peu","pièce","plupart","pour","pourquoi","quand","que","quel","quelle",
|
"quelles","quels","qui","sa","sans","ses","seulement","si","sien","son",
|
"sont","sous","soyez sujet","sur","ta","tandis","tellement","tels","tes","ton",
|
"tous","tout","trop","très","tu","valeur","voie","voient","vont","votre","vous"
|
,
|
"vu","ça","étaient","état","étions","été","être",
|
"un","deux","trois","quatre","cinq","six","sept","huit","neuf","dix",
|
"0","1","2","3","4","5","6","7","8","9","10",
|
"avec","chez","par","dans","des","en","de","une","votre","meilleurs","entre",
|
"entres","depuis","alors","ne","pas","du","meme",
|
"ou","nom","seuls","acceptes","ayant",
|
"vos","votre","mes","mien","mien","tien","tiens","tout","toute","toutes",
|
"que","quoi","qui","comment","peu","peut","pis","puis","pas",
|
"chaque","chacun","chacune",
|
"son","ses","au","aux","se","sur","ce","ceux","cette","ca","ci","ceci","cela",
|
"aussi","pour","petit","grand","moyen","large","haut","bas","milieu","droite",
|
"gauche","centre","dit","etre","leur","leurs","plus","moin","moins",
|
"es","est","sont","son","va","suis","ai","viens"
|
);
|
/*******************************************************************************
|
* Fonction enleve les slashs
|
* Enleve les accents
|
***************************************************************************/
|
|
function AuStripSlashes($chaine) {
|
return(get_magic_quotes_gpc() == 1 ? StripSlashes($chaine) : $chaine);}
|
|
function TexteSansAccent($texte){
|
$accent=
|
'ÀÃÂà ÄÅà áâà äåÒÓÔÕÖØòóôõöøÈÉÊËéèêëÇçÌÃÃŽÃ' .
|
'ìÃîïÙÚÛÜùúûüÿÑñ';
|
$noaccent='AAAAAAaaaaaaOOOOOOooooooEEEEeeeeCcIIIIiiiiUUUUuuuuyNn';
|
$texte = strtr($texte,$accent,$noaccent);
|
return $texte; }
|
|
/*******************************************************************************
|
* gestion de la chaine et placement de la chaine dans une table
|
***************************************************************************/
|
|
// enleve les slashs
|
$texte = AuStripSlashes($texte);
|
// enleve les accent
|
$texte = TexteSansAccent($texte);// enleve les accent
|
// enleve les apostrophes
|
$texte = str_replace("'"," ",$texte);
|
// passe le texte en minuscule
|
$texte = strtolower($texte); // passe minuscule
|
// Place tous les mots d'une chaine dans un tableau
|
$regs1 = split("[^[:alpha:]]+", $texte);
|
$tab_copie = $regs1; // copie de la table
|
|
/*******************************************************************************
|
* gestion du tableau
|
***************************************************************************/
|
|
// enleve les mots bannis en faisant le difference des 2 tableaux
|
$regs = array_diff($regs1,$tab_banni);
|
// On groupe les Mots-clés identiques et on les compte
|
$stats = array_count_values($regs);
|
// On trie par ordre croissant la liste
|
array_multisort($stats, SORT_DESC);
|
// On crée un tableau avec les clés du tableau correpondants aux mots clés
|
$tabKey = array_keys($stats);
|
|
/********************************/
|
/* CREATION TABLEAU */
|
/*******************************************************************************
|
* Création du tableau contenant les resultats
|
***************************************************************************/
|
|
$i=0;
|
$compteur = 0;
|
while ( $i < sizeof($tabKey))
|
|
{
|
$champ = $tabKey[$i];
|
$taille = strlen($champ);
|
if ($taille <= $taille_des_mots) {
|
$tag[$compteur] = $tabKey[$i];
|
$compteur++;
|
}
|
$i++;
|
if ($compteur==($nbre_elements+1)) break;
|
}
|
|
/********************************/
|
/* CREATION DU TAGS CLOUD */
|
/*******************************************************************************
|
* 3 tableaux pour faire un aléatoire sur chacun
|
***************************************************************************/
|
|
|
|
// PREMIERE PARTIE
|
|
$i=0;
|
$temp1 = -1;
|
$temp2 = 0;
|
$temp3 = 0;
|
|
while ($i<sizeof($tag))
|
{
|
if ($i <= $y) {
|
if ($option) {$nb = ($temp1++ & 1) ? '3' : '1';} else {$temp1++; $nb=1;}
|
$tab_1[$temp1]='<a class="cloud'.$nb.'" href="file.php?w='.$tag[$i].'">'.$tag[$i
|
].'</a> ';
|
}
|
|
if ($i > $y and $i <= ($y*2)) {
|
$tab_2[$temp2] = '<a class="cloud2" href="file.php?w='.$tag[$i].'">'.$tag[$i].
|
'</a> ';
|
$temp2++;
|
}
|
if ($i > ($y*2) ) {
|
$tab_3[$temp3] = '<a class="cloud3" href="file.php?w='.$tag[$i].'">'.$tag[$i].
|
'</a> ';
|
$temp3++;
|
}
|
|
$i++;
|
}
|
|
$i=0;
|
while ($i<$y)
|
{
|
$tchaine = array();
|
$new_chaine = '';
|
$tchaine[] = $tab_1[$i];
|
$tchaine[] = $tab_2[$i];
|
$tchaine[] = $tab_3[$i];
|
srand((float)microtime()*1000000);
|
shuffle($tchaine);
|
$j=0;
|
while ($j<sizeof($tchaine)) { $new_chaine .= $tchaine[$j]; $j++; }
|
$tab_final[] = $new_chaine;
|
$i++;
|
}
|
|
/**************************************/
|
/* CREATION FINAL DU TAGS CLOUD */
|
/*******************************************************************************
|
* c'est ici que vous pouvez ajuster l'affichage du tag cloud
|
***************************************************************************/
|
|
$i=0;
|
$tag_clouds =
|
'<table style="width:240px;border: 1px dotted #999;margin:2px;">';
|
while ($i<sizeof($tab_final))
|
{
|
if($i%$nbcol_tableau==0)
|
$tag_clouds .= '<tr><td colspan="'.$nbcol_tableau.'">';
|
$tag_clouds .= ''.$tab_final[$i].'';
|
|
if($i%$nbcol_tableau==($nbcol_tableau-1))
|
$tag_clouds .= "</td></tr>";
|
$i++;
|
}
|
$tag_clouds .= "</table>";
|
|
/********************************/
|
/* CONNECTION FICHIER */
|
/*******************************************************************************
|
* Ouverture du fichier et insertion du tag cloud
|
***************************************************************************/
|
|
$f = 'tag_clouds.txt';
|
$handle = fopen($f,"w+");
|
|
// regarde si le fichier est accessible en écriture
|
if (is_writable($f)) {
|
// Ecriture
|
if (fwrite($handle, $tag_clouds) === FALSE) {
|
echo 'Impossible d\'écrire dans le fichier '.$f.'';
|
exit;
|
}
|
fclose($handle);
|
|
}
|
else { echo 'Impossible d\'écrire dans le fichier '.$f.'';
|
}
|
|
/********************************/
|
/* TEMPS D'EXECUTION */
|
/*******************************************************************************
|
* Calcul et affichage du temps d'execution du script
|
***************************************************************************/
|
|
$mtime = microtime();
|
$mtime = explode(" ",$mtime);
|
$mtime = $mtime[1] + $mtime[0];
|
$endtime = $mtime;
|
$totaltime = ($endtime - $starttime);
|
echo'<br /><br />';
|
echo '<font style="font-size:11px;font-family:Verdana;color:#111111; ">';
|
echo 'Tag Cloud généré en ',number_format($totaltime,4,',',''),' s</font>'
|
;
|
echo '</td></tr></table>';
|
echo'<br /><br />';
|
|
|
/***********************************/
|
/* AFFICHAGE LE NUAGE DE TAG ;) */
|
/*******************************************************************************
|
* Vous pouvez prendre cette ligne et la placez ou vous voulez sur votre
|
site
|
***************************************************************************/
|
|
// Affiche le tag clouds
|
|
include 'tag_clouds.txt';
|
|
|
Invité
18 Fév 2011 à 09:26Je trouve que la démarche est intéressante, à nous de créer le script qui va avec.