View Single Post
  #1  
Old 09-17-2013, 05:38 AM
HnathBST
Sarnak
 
Join Date: Feb 2007
Location: Sunset Home
Posts: 71
Default Slight modification to plugin::PWAutoCenter

I modified PWAutoCenter to not count html & bbcode tags when centering

Code:
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
Reply With Quote