PDA

View Full Version : Slight modification to plugin::PWAutoCenter


HnathBST
09-17-2013, 05:38 AM
I modified PWAutoCenter to not count html & bbcode tags when centering


sub PWAutoCenter{
$Cent = $_[0];
$len = $_[0];
$len =~ s!<(?:[^>]+)>([^<]+)</(?:[^>]+)>!$1!gi;
$len =~ s!\[(?:[\]]+)\]([^\[]+)\[/(?:[\]]+)\]!$1!gi;
$SendCharLength = $_[1];
if($SendCharLength != 2){
$CentLength = length($len);
$IC = (53 - ($CentLength * .80) - 4);
}
else{
$IC = $Cent;
}
my $n = 0;
my $Result = "";
while ($n < $IC){
$Result .= "&nbsp;";
$n++;
}
if(!$SendCharLength){
return "$Result $Cent";
my $CentLength = 0;
}
elsif($SendCharLength == 2){
return "$Result";
}
else{
return "There are $IC characters in this phrase, use this arguement for Option 2 in Arguement 2";
}
my $SendCharLenghth = undef;
my $CentLenght = undef;
}


if you don't need the BBCode [..]..[/..] remove the third $len. This will center links.

hope this helps someone :)