Old stuff/Perl/xchat/func.pl
(Deskargatu)
#!/usr/bin/perl -w
use Image::Magick;
use DBI;
my $list=0;
sub affichage($)
{
$list=0;
$code=0;
$contenu = shift;
@contenu = split("\n+",$contenu);
for($i=0;$i<@contenu;$i++)
{
$contenu[$i] =~ s/&(?!.{1,3};)/&/g;
$contenu[$i] =~ s/__(.+?)__/<span class="underline">$1<\/span>/g;
if ($contenu[$i] =~ /^\-(.{1,})/)
{
if ($list==0) { $contenu[$i] =~ s/^\-(.{1,})/<ul><li>$1<\/li>/g; }
else { $contenu[$i] =~ s/^\-(.{1,})/<li>$1<\/li>/g; }
$list=1;
}
elsif($list) { $contenu[$i] =~ s/^(.+)$/<\/ul><p>$1 $list<\/p>/g; $list=0;}
elsif( $contenu[$i] =~ /\[code]/)
{
$contenu[$i] =~ s/\[code\]/<pre>/;
$code = 1;
}
elsif( $contenu[$i] =~ /\[\/code\]/)
{
$contenu[$i] =~ s/\[\/code\]/<\/pre>/;
$code = 0;
}
elsif(!$code) { $contenu[$i] =~ s/(.+)/<p>$1<\/p>/g;
}
}
if ($list) { push(@contenu,"</ul>"); }
return join("\n",@contenu);
}
sub miniature($)
{
$_ = shift;
if (! -f $_) { print "$_ introuvable\n"; }
else
{
$image = Image::Magick->new;
$x = $image->Read("$_");
return 0 if "$x";
$newfile = $_;
$newfile =~ s/(.*\/)(.+)/$1.min_$2/;
$x = $image->Resize(geometry=>'75x75');
warn "$x" if "$x";
$x = $image->Write("$newfile");
warn "$x" if "$x";
}
}
sub connect_db()
{
$dbh = DBI->connect("dbi:Pg:dbname=web;host=localhost;port=5432","tfe","prout123") or die $dbh->errstr();
return $dbh;
}
sub highlight($)
{
$_ = shift;
s/&/&/g;
s/\</</g;
s/\</>/g;
my @contenu = split //,$_;
my @ouverts=();
my %var = ( "[" => "]" , "{" => "}" );
my $ouverture;
my $precedant = "";
my $recherche = "";
my $temp;
for $i(0..$#contenu)
{
$temp =$contenu[$i];
$contenu[$i] =~ s/\n/\\n/g;
if ($contenu[$i] =~ /[\n]/ && $ouverture eq "com")
{
$contenu[$i] .= "</span>";
$ouverture= undef;
}
elsif ($contenu[$i] eq "#" && $precedant ne "\\" && $precedant ne "\$" && !$ouverte)
{
$contenu[$i] =~ s/(.)/<span class=\"com\">$1/;
$ouverture = "com";
}
elsif (($contenu[$i] eq "\"" || $contenu[$i] eq "\'") && !$ouverture)
{
$ouverture = "quote";
$recherche = $contenu[$i];
$contenu[$i] =~ s/(.)/<span class=\"quote\">$1/;
}
elsif($contenu[$i] eq "$recherche" && $precedant ne "\\" && $ouverture ne "com" ) {
$ouverture = undef;
$contenu[$i] .= "</span>";
}
$precedant = $temp;
}
return join("",@contenu);
}
return 1;