Re: nube de keywords como hacerla?
| From: | Mariano Guezuraga | Date: | Fri, 30 Nov 2007 13:23:29 +0000 |
| Subject: | Re: nube de keywords como hacerla? | ||
| References: | 1 2 | Groups: | php.general.es |
| Request: | Send a blank email to general-es+get-61895@lists.php.net to get a copy of this message | ||
El 30/11/07, Fernando Cassia <fcassia@sdf.lonestar.org> escribió:
> Gerardo Benitez wrote:
> > Hola gente!
> >
> > Tengo una duda, partiendo de un array de palabras claves, como puedo armar
> > una nube de keywords como la que se puede ver en cualquier blog, por ejemplo
> > o sitios a lo web 2.0
> >
> > Gracias de antemano.
> >
> Es como una nube de pedos, pero en formato grafico.
...cuac
Asi la armo yo: (en CakePhp)
El findAll es una consulta, en tu caso la tendrias que hacer como de
costumbre...
Espero que te sirva.
function generateTags() {
$data = $this->FindAll("active = 1 AND approved = 1 AND tags <>
''","tags","hits",50);
$mots = array();
foreach ($data as $_tag)
{
$tag = $_tag['Classified']['tags'];
if ($tag):
if (stristr($tag, chr(44))) {
$tags = explode(chr(44), $tag);
foreach($tags as $__tag):
if(array_key_exists($__tag, $mots)) $mots[$__tag]++;
else $mots[$__tag] = '1';
endforeach;
}
else {
if(array_key_exists($tag, $mots)) $mots[$tag]++;
else $mots[$tag] = '1';
}
endif;
}
$max_size = 15; $max_weight = 900; //max font size and max font weight
$min_size = 10; $min_weight = 100; //min font size and min font weight
if (!empty($mots)) {
$max_qty = max(array_values($mots)); //the maximum data
$min_qty = min(array_values($mots)); //the minimum data
} else {
$max_qty = 1;
$min_qty = 0;
}
$spread = $max_qty - $min_qty;
if (0 == $spread) {
$spread = 1;
}
$step = ($max_size - $min_size)/($spread);
$bold = ($max_weight - $min_weight)/($spread);
$links = array();
foreach ($mots as $key => $value)
{
$size = round($min_size + (($value - $min_qty) * $step),0);
$weight = round($min_weight + (($value - $min_qty) * $bold),0);
array_push($links,array('nombre' => trim($key),
'weight' => $weight,
'size' => $size,
'title' => $value.' clasificado/s en el tag '..$key));
}
return $links;
}
Repito, no te va a andar de una, pero vas a tener una idea de como hacerlo