fixed tag exploit
git-svn-id: http://yolanda.mister-muffin.de/svn@272 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
parent
b9baadf6fd
commit
fa1b8fb203
1 changed files with 19 additions and 1 deletions
|
@ -11,24 +11,42 @@ $dbh = DBI->connect("DBI:mysql:$database:$dbhost", $dbuser, $dbpass);
|
||||||
|
|
||||||
$sth = $dbh->prepare("select subject from videos");
|
$sth = $dbh->prepare("select subject from videos");
|
||||||
$sth->execute();
|
$sth->execute();
|
||||||
|
#cycle through all video subjects
|
||||||
while(($subject) = $sth->fetchrow_array())
|
while(($subject) = $sth->fetchrow_array())
|
||||||
{
|
{
|
||||||
@subject = split(' ', $subject);
|
@subject = split(' ', $subject);
|
||||||
|
#cycle through all tags of video
|
||||||
foreach my $val (@subject)
|
foreach my $val (@subject)
|
||||||
{
|
{
|
||||||
|
#strip whitespaces
|
||||||
$val =~ s/^\s*(.*?)\s*$/$1/;
|
$val =~ s/^\s*(.*?)\s*$/$1/;
|
||||||
if(length($val) >= 4)
|
if(length($val) >= 4)
|
||||||
{
|
{
|
||||||
%hash->{$val}++;
|
#check if some clever guy has written a tag multiple times
|
||||||
|
$found = 0;
|
||||||
|
foreach my $tmpval (@subject)
|
||||||
|
{
|
||||||
|
if($val eq $tmpval)
|
||||||
|
{
|
||||||
|
$found = 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
#only add tag if it is not been entered twice or more
|
||||||
|
if(!$found)
|
||||||
|
{
|
||||||
|
%hash->{$val}++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
$sth->finish();
|
$sth->finish();
|
||||||
|
|
||||||
|
#sort by count
|
||||||
@sorted = sort {$hash{$b} cmp $hash{$a}} keys %hash;
|
@sorted = sort {$hash{$b} cmp $hash{$a}} keys %hash;
|
||||||
|
|
||||||
$dbh->do("delete from tagcloud");
|
$dbh->do("delete from tagcloud");
|
||||||
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
|
$sth = $dbh->prepare("insert into tagcloud (text, count) values (?, ?)");
|
||||||
|
#insert first 20 tags into tagcloud table
|
||||||
for($i=0;$i<20 and $i<=$#sorted;$i++)
|
for($i=0;$i<20 and $i<=$#sorted;$i++)
|
||||||
{
|
{
|
||||||
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
|
$sth->execute( $sorted[$i], %hash->{$sorted[$i]} );
|
||||||
|
|
Loading…
Reference in a new issue