blib/lib/AUBBC.pm | |||
---|---|---|---|
Criterion | Covered | Total | % |
statement | 100 | 305 | 32.7 |
branch | 38 | 248 | 15.3 |
condition | 11 | 100 | 11.0 |
subroutine | 15 | 38 | 39.4 |
pod | 5 | 28 | 17.8 |
total | 169 | 719 | 23.5 |
line | stmt | bran | cond | sub | pod | time | code |
---|---|---|---|---|---|---|---|
1 | package AUBBC; | ||||||
2 | 1 | 1 | 956 | use strict; | |||
1 | 2 | ||||||
1 | 59 | ||||||
3 | 1 | 1 | 6 | use warnings; | |||
1 | 2 | ||||||
1 | 8808 | ||||||
4 | |||||||
5 | our $VERSION = '4.06'; | ||||||
6 | our $BAD_MESSAGE = 'Unathorized'; | ||||||
7 | our $DEBUG_AUBBC = 0; | ||||||
8 | our $MEMOIZE = 1; | ||||||
9 | my $msg = ''; | ||||||
10 | my $aubbc_error = ''; | ||||||
11 | my $long_regex = '[\w\.\/\-\~\@\:\;\=]+(?:\?[\w\~\.\;\:\,\$\-\+\!\*\?\/\=\&\@\#\%]+?)?'; | ||||||
12 | my @do_f = (1,1,1,1,1,0,0,0,time.$$.'000','',1); | ||||||
13 | my @key64 = ('A'..'Z','a'..'z',0..9,'+','/'); | ||||||
14 | my %SMILEYS = (); | ||||||
15 | my %Build_AUBBC = (); | ||||||
16 | my %AUBBC = ( | ||||||
17 | aubbc => 1, | ||||||
18 | utf => 1, | ||||||
19 | smileys => 1, | ||||||
20 | highlight => 1, | ||||||
21 | highlight_function => \&code_highlight, | ||||||
22 | no_bypass => 0, | ||||||
23 | for_links => 0, | ||||||
24 | aubbc_escape => 1, | ||||||
25 | no_img => 0, | ||||||
26 | icon_image => 1, | ||||||
27 | image_hight => '60', | ||||||
28 | image_width => '90', | ||||||
29 | image_border => '0', | ||||||
30 | image_wrap => ' ', | ||||||
31 | href_target => ' target="_blank"', | ||||||
32 | images_url => '', | ||||||
33 | html_type => ' /', | ||||||
34 | fix_amp => 1, | ||||||
35 | line_break => '1', | ||||||
36 | code_class => '', | ||||||
37 | code_extra => '', | ||||||
38 | code_download => '^Download above code^', | ||||||
39 | href_class => '', | ||||||
40 | quote_class => '', | ||||||
41 | quote_extra => '', | ||||||
42 | script_escape => 1, | ||||||
43 | protect_email => '0', | ||||||
44 | email_message => 'Contact Email', | ||||||
45 | highlight_class1 => '', | ||||||
46 | highlight_class2 => '', | ||||||
47 | highlight_class3 => '', | ||||||
48 | highlight_class4 => '', | ||||||
49 | highlight_class5 => '', | ||||||
50 | highlight_class6 => '', | ||||||
51 | highlight_class7 => '', | ||||||
52 | highlight_class8 => '', | ||||||
53 | highlight_class9 => '', | ||||||
54 | ); | ||||||
55 | my @security_levels = ('Guest', 'User', 'Moderator','Administrator'); | ||||||
56 | my ($user_level, $high_level, $user_key) = ('Guest', 3, 0); | ||||||
57 | my %Tag_SecLVL = ( | ||||||
58 | code => { level => 0, text => $BAD_MESSAGE, }, | ||||||
59 | img => { level => 0, text => $BAD_MESSAGE, }, | ||||||
60 | url => { level => 0, text => $BAD_MESSAGE, }, | ||||||
61 | ); | ||||||
62 | |||||||
63 | sub security_levels { | ||||||
64 | 0 | 0 | 0 | 0 | my ($self,@s_levels) = @_; | ||
65 | 0 | 0 | $do_f[10] = 0; | ||||
66 | @s_levels | ||||||
67 | 0 | 0 | 0 | ? @security_levels = @s_levels | |||
68 | : return @security_levels; | ||||||
69 | } | ||||||
70 | |||||||
71 | sub user_level { | ||||||
72 | 0 | 0 | 0 | 0 | my ($self,$u_level) = @_; | ||
73 | 0 | 0 | $do_f[10] = 0; | ||||
74 | 0 | 0 | 0 | defined $u_level | |||
75 | ? $user_level = $u_level | ||||||
76 | : return $user_level; | ||||||
77 | } | ||||||
78 | |||||||
79 | sub tag_security { | ||||||
80 | 0 | 0 | 0 | 0 | my ($self,%s_tags) = @_; | ||
81 | 0 | 0 | 0 | %s_tags | |||
82 | ? %Tag_SecLVL = %s_tags | ||||||
83 | : return %Tag_SecLVL; | ||||||
84 | } | ||||||
85 | |||||||
86 | sub check_access { | ||||||
87 | 1 | 1 | 0 | 2 | my $tag = shift; | ||
88 | 1 | 50 | 3 | unless ($do_f[10]) { | |||
89 | 0 | 0 | $do_f[10] = 1; | ||||
90 | 0 | 0 | ($high_level, $user_key) = (scalar(@security_levels), 0); | ||||
91 | |||||||
92 | 0 | 0 | for(my $i = 0; $i < $high_level;) { | ||||
93 | 0 | 0 | 0 | if ($security_levels[$i] eq $user_level) { | |||
94 | 0 | 0 | $user_key = $i; | ||||
95 | 0 | 0 | last; | ||||
96 | } | ||||||
97 | 0 | 0 | $i++; | ||||
98 | } | ||||||
99 | } | ||||||
100 | |||||||
101 | 1 | 0 | 33 | 6 | if (defined $tag && $do_f[10]) { | ||
102 | 0 | 0 | 0 | $user_key >= $Tag_SecLVL{$tag}{level} | |||
103 | ? return 1 | ||||||
104 | : return ''; | ||||||
105 | } | ||||||
106 | } | ||||||
107 | |||||||
108 | sub new { | ||||||
109 | 1 | 50 | 1 | 0 | 19 | warn 'CREATING AUBBC '.$VERSION if $DEBUG_AUBBC; | |
110 | 1 | 50 | 33 | 8 | if ($MEMOIZE && ! $do_f[7]) { | ||
111 | 1 | 3 | $do_f[7] = 1; | ||||
112 | 1 | 50 | 1 | 1309 | eval 'use Memoize' if ! defined $Memoize::VERSION; | ||
1 | 2771 | ||||||
1 | 42 | ||||||
1 | 74 | ||||||
113 | 1 | 50 | 33 | 11 | unless ($@ || ! defined $Memoize::VERSION) { | ||
114 | 1 | 4 | Memoize::memoize('AUBBC::settings'); | ||||
115 | 1 | 4086 | Memoize::memoize('AUBBC::smiley_hash'); | ||||
116 | 1 | 169 | Memoize::memoize('AUBBC::add_build_tag'); | ||||
117 | 1 | 151 | Memoize::memoize('AUBBC::do_all_ubbc'); | ||||
118 | 1 | 146 | Memoize::memoize('AUBBC::script_escape'); | ||||
119 | 1 | 144 | Memoize::memoize('AUBBC::html_to_text'); | ||||
120 | } | ||||||
121 | 1 | 50 | 146 | $aubbc_error .= $@."\n" if $@; | |||
122 | } | ||||||
123 | 1 | 5 | return bless {}; | ||||
124 | } | ||||||
125 | |||||||
126 | sub DESTROY { | ||||||
127 | 1 | 50 | 1 | 156 | warn 'DESTROY AUBBC '.$VERSION if $DEBUG_AUBBC; | ||
128 | } | ||||||
129 | |||||||
130 | sub settings_prep { | ||||||
131 | 1 | 50 | 1 | 0 | 5 | $AUBBC{href_target} = $AUBBC{href_target} ? ' target="_blank"' : ''; | |
132 | 1 | 50 | 6 | $AUBBC{image_wrap} = $AUBBC{image_wrap} ? ' ' : ''; | |||
133 | 1 | 50 | 4 | $AUBBC{image_border} = $AUBBC{image_border} ? '1' : '0'; | |||
134 | 1 | 50 | 33 | 9 | $AUBBC{html_type} = $AUBBC{html_type} eq 'xhtml' || $AUBBC{html_type} eq ' /' ? ' /' : ''; | ||
135 | } | ||||||
136 | |||||||
137 | sub settings { | ||||||
138 | 1 | 1 | 92 | my ($self,%s_hash) = @_; | |||
139 | 1 | 5 | foreach (keys %s_hash) { | ||||
140 | 1 | 50 | 4 | if ('highlight_function' eq $_) { | |||
141 | 0 | 0 | $AUBBC{highlight} = 0; | ||||
142 | 0 | 0 | $s_hash{$_} = check_subroutine($s_hash{$_},''); | ||||
143 | 0 | 0 | 0 | $AUBBC{highlight_function} = $s_hash{$_} unless ! $s_hash{$_}; | |||
144 | } else { | ||||||
145 | 1 | 5 | $AUBBC{$_} = $s_hash{$_}; | ||||
146 | } | ||||||
147 | } | ||||||
148 | 1 | 5 | &settings_prep; | ||||
149 | 1 | 50 | 6 | if ($DEBUG_AUBBC) { | |||
150 | 0 | 0 | my $uabbc_settings = ''; | ||||
151 | 0 | 0 | $uabbc_settings .= $_ . ' =>' . $AUBBC{$_} . ', ' foreach keys %AUBBC; | ||||
152 | 0 | 0 | warn 'AUBBC Settings Change: '.$uabbc_settings; | ||||
153 | } | ||||||
154 | } | ||||||
155 | |||||||
156 | sub get_setting { | ||||||
157 | 1 | 1 | 0 | 17 | my ($self,$name) = @_; | ||
158 | 1 | 50 | 6 | return $AUBBC{$name} if exists $AUBBC{$name}; | |||
159 | } | ||||||
160 | |||||||
161 | sub code_highlight { | ||||||
162 | 0 | 0 | 0 | 0 | my $txt = shift; | ||
163 | 0 | 0 | 0 | warn 'ENTER code_highlight' if $DEBUG_AUBBC; | |||
164 | 0 | 0 | $txt =~ s/:/:/g; | ||||
165 | 0 | 0 | $txt =~ s/\[/[/g; | ||||
166 | 0 | 0 | $txt =~ s/\]/]/g; | ||||
167 | 0 | 0 | $txt =~ s/\000[/[[/g; | ||||
168 | 0 | 0 | $txt =~ s/\000]/]]/g; | ||||
169 | 0 | 0 | $txt =~ s/\{/{/g; | ||||
170 | 0 | 0 | $txt =~ s/\}/}/g; | ||||
171 | 0 | 0 | $txt =~ s/%/%/g; | ||||
172 | 0 | 0 | $txt =~ s/(?)\n/ \n/g; |
||||
173 | 0 | 0 | 0 | if ($AUBBC{highlight}) { | |||
174 | 0 | 0 | 0 | warn 'ENTER block highlight' if $DEBUG_AUBBC; | |||
175 | 0 | 0 | 0 | $txt =~ s/\z/ / if $txt !~ m/ \z/; |
|||
176 | 0 | 0 | $txt =~ s/(<<(?:')?(\w+)(?:')?;(?s)[^\2]+\b\2\b)/$1<\/span>/g; | ||||
177 | 0 | 0 | $txt =~ s/(?))/$1<\/span>/g; | ||||
178 | 0 | 0 | $txt =~ s/(\bsub\b(?:\s+))(\w+)/$1$2<\/span>/g; | ||||
179 | 0 | 0 | $txt =~ s/(\w+(?:\->)?(?:\w+)?((?:.+?)?)(?:;)?)/$1<\/span>/g; | ||||
180 | 0 | 0 | $txt =~ s/((?:&)\w+;)/$1<\/span>/g; | ||||
181 | 0 | 0 | $txt =~ s/('(?s).*?(?$1<\/span>/g; | ||||
182 | 0 | 0 | $txt =~ s/("(?s).*?(?$1<\/span>/g; | ||||
183 | 0 | 0 | $txt =~ s/(?$1<\/span>/g; | ||||
184 | 0 | 0 | $txt =~ | ||||
185 | s/(|||&&|\b(?:strict|package|return|require|for|my|sub|if|eq|ne|lt|ge|le|gt|or|xor|use|while|foreach|next|last|unless|elsif|else|not|and|until|continue|do|goto)\b)/$1<\/span>/g; | ||||||
186 | 0 | 0 | $txt =~ s/(?$1<\/span>/g; | ||||
187 | } | ||||||
188 | 0 | 0 | return $txt; | ||||
189 | } | ||||||
190 | |||||||
191 | sub code_download { | ||||||
192 | 0 | 0 | 0 | 1 | 0 | if ($AUBBC{code_download}) { | |
193 | 0 | 0 | $do_f[8]++; | ||||
194 | 0 | 0 | $do_f[9] = | ||||
195 | make_link('javascript:void(0)',$AUBBC{code_download}, "javascript:MyCodePrint('aubbcode$do_f[8]');",''); | ||||||
196 | 0 | 0 | return " id=\"aubbcode$do_f[8]\""; | ||||
197 | 0 | 0 | } else { return ''; } | ||||
198 | } | ||||||
199 | |||||||
200 | sub code_tag { | ||||||
201 | 0 | 0 | 0 | 0 | my ($code,$name) = @_; | ||
202 | 0 | 0 | 0 | if (check_access('code')) { | |||
203 | 0 | 0 | 0 | $name = "# $name: \n" if $name; |
|||
204 | 0 | 0 | return "$name\n".
|
||||
205 | $AUBBC{highlight_function}->($code). | ||||||
206 | "\n".$AUBBC{code_extra}.$do_f[9]; | ||||||
207 | } | ||||||
208 | else { | ||||||
209 | 0 | 0 | return $Tag_SecLVL{code}{text}; | ||||
210 | } | ||||||
211 | } | ||||||
212 | |||||||
213 | sub make_image { | ||||||
214 | 0 | 0 | 0 | 0 | my ($align,$src,$width,$height,$alt) = @_; | ||
215 | 0 | 0 | my $img = " | ||||
216 | 0 | 0 | 0 | $img .= " width=\"$width\"" if $width; | |||
217 | 0 | 0 | 0 | $img .= " height=\"$height\"" if $height; | |||
218 | 0 | 0 | return $img." alt=\"$alt\" border=\"$AUBBC{image_border}\"$AUBBC{html_type}>"; | ||||
219 | } | ||||||
220 | |||||||
221 | sub make_link { | ||||||
222 | 0 | 0 | 0 | 0 | my ($link,$name,$javas,$targ) = @_; | ||
223 | 0 | 0 | my $linkd = " | ||||
224 | 0 | 0 | 0 | $linkd .= " onclick=\"$javas\"" if $javas; | |||
225 | 0 | 0 | 0 | $linkd .= $AUBBC{href_target} if $targ; | |||
226 | 0 | 0 | $linkd .= $AUBBC{href_class}.'>'; | ||||
227 | 0 | 0 | 0 | $linkd .= $name ? $name : $link; | |||
228 | 0 | 0 | return $linkd.''; | ||||
229 | } | ||||||
230 | |||||||
231 | sub do_ubbc { | ||||||
232 | 1 | 50 | 1 | 0 | 3 | warn 'ENTER do_ubbc' if $DEBUG_AUBBC; | |
233 | 1 | 3 | $msg =~ s/\[(?:c|code)\](?s)(.+?)\[\/(?:c|code)\]/code_tag($1, '')/ge; | ||||
0 | 0 | ||||||
234 | 1 | 2 | $msg =~ s/\[(?:c|code)=(.+?)\](?s)(.+?)\[\/(?:c|code)\]/code_tag($2, $1)/ge; | ||||
0 | 0 | ||||||
235 | 1 | 50 | 3 | $do_f[9] = '' if $do_f[9]; | |||
236 | |||||||
237 | 1 | 50 | 6 | $msg =~ s/\[(img|right_img|left_img)\](.+?)\[\/img\]/fix_image($1, $2)/ge if ! $AUBBC{no_img}; | |||
0 | 0 | ||||||
238 | |||||||
239 | 1 | 3 | $msg =~ s/\[email\](?![\w\.\-\&\+]+\@[\w\.\-]+).+?\[\/email\]/\[$BAD_MESSAGE<\/font>\]email/g; | ||||
240 | 1 | 50 | 6 | $AUBBC{protect_email} | |||
241 | 0 | 0 | ? $msg =~ s/\[email\]([\w\.\-\&\+]+\@[\w\.\-]+)\[\/email\]/protect_email($1)/ge | ||||
242 | 0 | 0 | : $msg =~ s/\[email\]([\w\.\-\&\+]+\@[\w\.\-]+)\[\/email\]/link_check("mailto:$1",$1,'','')/ge; | ||||
243 | |||||||
244 | 1 | 2 | $msg =~ s/\[color=([\w#]+)\](?s)(.+?)\[\/color\]/$2<\/span>/g; | ||||
245 | |||||||
246 | 1 | 3 | 1 while $msg =~ | ||||
247 | s/\[quote=([\w\s]+)\](?s)(.+?)\[\/quote\]/ $1:<\/strong><\/small> |
||||||
248 | $2<\/div>$AUBBC{quote_extra}/g; | ||||||
249 | 1 | 15 | 1 while $msg =~ | ||||
250 | s/\[quote\](?s)(.+?)\[\/quote\]/ $1<\/div>$AUBBC{quote_extra}/g;
|
||||||
251 | |||||||
252 | 1 | 3 | $msg =~ s/\[(left|right|center)\](?s)(.+?)\[\/\1\]/ $2<\/div>/g;
|
||||
253 | 1 | 2 | $msg =~ s/\[li=(\d+)\](?s)(.+?)\[\/li\]/ |
||||
254 | 1 | 3 | $msg =~ s/\[u\](?s)(.+?)\[\/u\]/$1<\/span>/g; | ||||
255 | 1 | 1 | $msg =~ s/\[strike\](?s)(.+?)\[\/strike\]/$1<\/span>/g; | ||||
256 | 1 | 10 | $msg =~ s/\[([bh]r)\]/<$1$AUBBC{html_type}>/g; | ||||
257 | 1 | 3 | $msg =~ s/\[list\](?s)(.+?)\[\/list\]/fix_list($1)/ge; | ||||
0 | 0 | ||||||
258 | |||||||
259 | 1 | 4 | 1 while $msg =~ | ||||
260 | s/\[(blockquote|big|h[123456]|[ou]l|li|em|pre|s(?:mall|trong|u[bp])|[bip])\](?s)(.+?)\[\/\1\]/<$1>$2<\/$1>/g; | ||||||
261 | |||||||
262 | 1 | 3 | $msg =~ s/(<\/?(?:ol|ul|li|hr)\s?\/?>)\r?\n? /$1/g; |
||||
263 | |||||||
264 | 1 | 139 | $msg =~ s/\[url=(\w+\:\/\/$long_regex)\](.+?)\[\/url\]/link_check($1,fix_message($2),'',1)/ge; | ||||
0 | 0 | ||||||
265 | 1 | 179 | $msg =~ s/(? | ||||
0 | 0 | ||||||
266 | } | ||||||
267 | |||||||
268 | sub link_check { | ||||||
269 | 0 | 0 | 0 | 0 | my ($link,$name,$javas,$targ) = @_; | ||
270 | 0 | 0 | 0 | check_access('url') | |||
271 | ? make_link($link,$name,$javas,$targ) | ||||||
272 | : return $Tag_SecLVL{url}{text}; | ||||||
273 | } | ||||||
274 | |||||||
275 | sub fix_list { | ||||||
276 | 0 | 0 | 0 | 0 | my $list = shift; | ||
277 | 0 | 0 | 0 | if ($list =~ m/\[\*/) { | |||
278 | 0 | 0 | $list =~ s/ //g; |
||||
279 | 0 | 0 | my $type = 'ul'; | ||||
280 | 0 | 0 | 0 | $type = 'ol' if $list =~ s/\[\*=(\d+)\]/\[\*\]$1\|/g; | |||
281 | 0 | 0 | my @clean = split('\[\*\]', $list); | ||||
282 | 0 | 0 | $list = "<$type>\n"; | ||||
283 | 0 | 0 | foreach (@clean) { | ||||
284 | 0 | 0 | 0 | 0 | if ($_ && $_ =~ s/\A(\d+)\|(?s)(.+?)/$2/) { | ||
0 | 0 | ||||||
285 | 0 | 0 | 0 | $list .= " |
|||
286 | } elsif ($_ && $_ !~ m/\A\s+|\d+\|\r?\n?\z/) { | ||||||
287 | 0 | 0 | $list .= " |
||||
288 | } | ||||||
289 | } | ||||||
290 | 0 | 0 | $list .= "<\/$type>"; | ||||
291 | } | ||||||
292 | 0 | 0 | return $list; | ||||
293 | } | ||||||
294 | |||||||
295 | sub fix_image { | ||||||
296 | 0 | 0 | 0 | 0 | my ($tmp2, $tmp) = @_; | ||
297 | 0 | 0 | 0 | if (check_access('img')) { | |||
298 | 0 | 0 | 0 | 0 | if ($tmp !~ m/\A\w+:\/\/|\// || $tmp =~ m/\?|\#|\.\bjs\b\z/i) { | ||
299 | 0 | 0 | $tmp = "[$BAD_MESSAGE]$tmp2"; | ||||
300 | } | ||||||
301 | else { | ||||||
302 | 0 | 0 | 0 | $tmp2 = '' if $tmp2 eq 'img'; | |||
303 | 0 | 0 | 0 | $tmp2 = ' align="right"' if $tmp2 eq 'right_img'; | |||
304 | 0 | 0 | 0 | $tmp2 = ' align="left"' if $tmp2 eq 'left_img'; | |||
305 | 0 | 0 | 0 | $tmp = $AUBBC{icon_image} | |||
306 | ? make_link($tmp,make_image($tmp2,$tmp,$AUBBC{image_width}, | ||||||
307 | $AUBBC{image_hight},''),'',1).$AUBBC{image_wrap} | ||||||
308 | : make_image($tmp2,$tmp,'','','').$AUBBC{image_wrap}; | ||||||
309 | } | ||||||
310 | 0 | 0 | return $tmp; | ||||
311 | } | ||||||
312 | else { | ||||||
313 | 0 | 0 | return $Tag_SecLVL{img}{text}; | ||||
314 | } | ||||||
315 | } | ||||||
316 | |||||||
317 | sub protect_email { | ||||||
318 | 0 | 0 | 1 | 0 | my $em = shift; | ||
319 | 0 | 0 | 0 | if (check_access('url')) { | |||
320 | 0 | 0 | my ($email1, $email2, $ran_num, $protect_email, @letters) = | ||||
321 | ('', '', '', '', split (//, $em)); | ||||||
322 | 0 | 0 | 0 | 0 | $protect_email = '[' if $AUBBC{protect_email} eq 3 || $AUBBC{protect_email} eq 4; | ||
323 | |||||||
324 | 0 | 0 | foreach my $character (@letters) { | ||||
325 | 0 | 0 | 0 | 0 | $protect_email .= '' . ord($character) . ';' if $AUBBC{protect_email} eq 1 || $AUBBC{protect_email} eq 2; | ||
326 | 0 | 0 | 0 | $protect_email .= ord($character) . ',' if $AUBBC{protect_email} eq 3; | |||
327 | 0 | 0 | 0 | 0 | $ran_num = int(rand(64)) || 0 if $AUBBC{protect_email} eq 4; | ||
328 | 0 | 0 | 0 | $protect_email .= '\'' . (ord($key64[$ran_num]) ^ ord($character)) . '\',\'' . $key64[$ran_num] . '\',' | |||
329 | if $AUBBC{protect_email} eq 4; | ||||||
330 | } | ||||||
331 | |||||||
332 | 0 | 0 | 0 | return make_link("mailto:$protect_email",$protect_email,'','') | |||
333 | if $AUBBC{protect_email} eq 1; | ||||||
334 | |||||||
335 | 0 | 0 | 0 | ($email1, $email2) = split ("@", $protect_email) if $AUBBC{protect_email} eq 2; | |||
336 | 0 | 0 | 0 | $protect_email = "'$email1' + '@' + '$email2'" if $AUBBC{protect_email} eq 2; | |||
337 | 0 | 0 | 0 | 0 | $protect_email =~ s/\,\z/]/g if $AUBBC{protect_email} eq 3 || $AUBBC{protect_email} eq 4; | ||
338 | |||||||
339 | 0 | 0 | 0 | 0 | return make_link('javascript:void(0)',$AUBBC{email_message},"javascript:MyEmCode('$AUBBC{protect_email}',$protect_email);",'') | ||
0 | |||||||
340 | if $AUBBC{protect_email} eq '2' || $AUBBC{protect_email} eq '3' || $AUBBC{protect_email} eq '4'; | ||||||
341 | } | ||||||
342 | else { | ||||||
343 | 0 | 0 | return $Tag_SecLVL{url}{text}; | ||||
344 | } | ||||||
345 | } | ||||||
346 | |||||||
347 | sub js_print { | ||||||
348 | 0 | 0 | 0 | 0 | my $self = shift; | ||
349 | 0 | 0 | print < | ||||
350 | Content-type: text/javascript | ||||||
351 | |||||||
352 | /* | ||||||
353 | AUBBC v$VERSION | ||||||
354 | JS | ||||||
355 | |||||||
356 | 0 | 0 | print <<'JS'; | ||||
357 | Fully supports dynamic view in XHTML. | ||||||
358 | */ | ||||||
359 | function MyEmCode (type, content) { | ||||||
360 | var returner = false; | ||||||
361 | if (type == 4) { | ||||||
362 | var farray= new Array(content.length,1); | ||||||
363 | for(farray[1];farray[1] | ||||||
364 | } else if (type == 3) { | ||||||
365 | for (i = 0; i < content.length; i++) { returner+=String.fromCharCode(content[i]); } | ||||||
366 | } else if (type == 2) { returner=content; } | ||||||
367 | if (returner) { window.location='mailto:'+returner; } | ||||||
368 | } | ||||||
369 | |||||||
370 | function MyCodePrint (input) { | ||||||
371 | if (input && document.getElementById(input)) { | ||||||
372 | var TheCode = document.getElementById(input).innerHTML; | ||||||
373 | TheCode = TheCode.replace(/<([^br<]+|\/?[puib])>/ig, ""); | ||||||
374 | codewin = window.open("", input, "width=800,height=600,resizable=yes,menubar=yes,scrollbars=yes"); | ||||||
375 | top.codewin.document.write("\n"+ | ||||||
376 | "\n\n |
||||||
377 | "\n"+ | ||||||
378 | "\n\n"+TheCode+" \n\n\n");
|
||||||
379 | top.codewin.document.close(); | ||||||
380 | } | ||||||
381 | } | ||||||
382 | JS | ||||||
383 | 0 | 0 | exit(0); | ||||
384 | } | ||||||
385 | |||||||
386 | sub do_build_tag { | ||||||
387 | 0 | 0 | 0 | 0 | 0 | warn 'ENTER do_build_tag' if $DEBUG_AUBBC; | |
388 | |||||||
389 | 0 | 0 | foreach (keys %Build_AUBBC) { | ||||
390 | 0 | 0 | 0 | warn 'ENTER foreach do_build_tag' if $DEBUG_AUBBC; | |||
391 | 0 | 0 | 0 | $msg =~ s/(\[$_\:\/\/([$Build_AUBBC{$_}[0]]+)\])/ | |||
392 | 0 | 0 | 0 | do_sub( $_, $2 , $Build_AUBBC{$_}[2] ) || $1; | |||
393 | /eg if $Build_AUBBC{$_}[1] eq '1'; | ||||||
394 | |||||||
395 | 0 | 0 | 0 | $msg =~ s/(\[$_\](?s)([$Build_AUBBC{$_}[0]]+)\[\/$_\])/ | |||
396 | 0 | 0 | 0 | do_sub( $_, $2 , $Build_AUBBC{$_}[2] ) || $1; | |||
397 | /eg if $Build_AUBBC{$_}[1] eq '2'; | ||||||
398 | |||||||
399 | 0 | 0 | 0 | $msg =~ s/(\[$_\])/ | |||
400 | 0 | 0 | 0 | do_sub( $_, '' , $Build_AUBBC{$_}[2] ) || $1; | |||
401 | /eg if $Build_AUBBC{$_}[1] eq '3'; | ||||||
402 | |||||||
403 | 0 | 0 | 0 | $msg =~ s/\[$_\]/ | |||
404 | 0 | 0 | 0 | check_access($_) ? $Build_AUBBC{$_}[2] : $Tag_SecLVL{$_}{text}; | |||
405 | /eg if $Build_AUBBC{$_}[1] eq '4'; | ||||||
406 | } | ||||||
407 | } | ||||||
408 | |||||||
409 | sub do_sub { | ||||||
410 | 0 | 0 | 0 | 0 | my ($key, $term, $fun) = @_; | ||
411 | 0 | 0 | 0 | warn 'ENTER do_sub' if $DEBUG_AUBBC; | |||
412 | 0 | 0 | 0 | 0 | check_access($key) | ||
413 | ? return $fun->($key, $term) || '' | ||||||
414 | : return $Tag_SecLVL{$key}{text}; | ||||||
415 | } | ||||||
416 | |||||||
417 | sub check_subroutine { | ||||||
418 | 0 | 0 | 0 | 0 | my $name = shift; | ||
419 | 0 | 0 | defined $name && exists &{$name} && (ref $name eq 'CODE' || ref $name eq '') | ||||
420 | 0 | 0 | 0 | 0 | ? return \&{$name} | ||
421 | : return ''; | ||||||
422 | } | ||||||
423 | |||||||
424 | sub add_build_tag { | ||||||
425 | 0 | 0 | 0 | my ($self,%NewTag) = @_; | |||
426 | 0 | 0 | 0 | warn 'ENTER add_build_tag' if $DEBUG_AUBBC; | |||
427 | |||||||
428 | 0 | 0 | 0 | $NewTag{function2} = $NewTag{function} || 'undefined!'; | |||
429 | 0 | 0 | 0 | $NewTag{function} = check_subroutine($NewTag{function},'') | |||
430 | if $NewTag{type} ne '4'; | ||||||
431 | |||||||
432 | 0 | 0 | 0 | $self->aubbc_error("Usage: add_build_tag - function 'Undefined subroutine' => $NewTag{function2}") | |||
433 | if ! $NewTag{function}; | ||||||
434 | |||||||
435 | 0 | 0 | 0 | if ($NewTag{function}) { | |||
436 | 0 | 0 | 0 | 0 | $NewTag{pattern} = 'l' if $NewTag{type} eq '3' || $NewTag{type} eq '4'; | ||
437 | 0 | 0 | 0 | 0 | if ($NewTag{type} && $NewTag{name} =~ m/\A[\w\-]+\z/ && $NewTag{pattern} =~ m/\A[lns_:\-,]+|all\z/) { | ||
0 | |||||||
438 | |||||||
439 | 0 | 0 | 0 | if ($NewTag{pattern} eq 'all') { | |||
440 | 0 | 0 | $NewTag{pattern} = '^\[|\]'; | ||||
441 | } | ||||||
442 | else { | ||||||
443 | 0 | 0 | my @pat_split = (); | ||||
444 | 0 | 0 | my %is_pat = ('l' => 'a-z', 'n' => '\d', '_' => '\_', ':' => '\:', 's' => '\s', '-' => '\-'); | ||||
445 | 0 | 0 | @pat_split = split /\,/, $NewTag{pattern}; | ||||
446 | 0 | 0 | $NewTag{pattern} = ''; | ||||
447 | 0 | 0 | 0 | $NewTag{pattern} .= $is_pat{$_} || '' foreach @pat_split; | |||
448 | } | ||||||
449 | |||||||
450 | 0 | 0 | $Build_AUBBC{$NewTag{name}} = [$NewTag{pattern}, $NewTag{type}, $NewTag{function}]; | ||||
451 | 0 | 0 | 0 | $NewTag{level} ||= 0; | |||
452 | 0 | 0 | 0 | $NewTag{error} ||= $BAD_MESSAGE; | |||
453 | 0 | 0 | $Tag_SecLVL{$NewTag{name}} = {level => $NewTag{level}, text => $NewTag{error},}; | ||||
454 | 0 | 0 | 0 | $do_f[5] = 1 if !$do_f[5]; | |||
455 | 0 | 0 | 0 | 0 | warn 'Added Build_AUBBC Tag '.$Build_AUBBC{$NewTag{name}} if $DEBUG_AUBBC && $Build_AUBBC{$NewTag{name}}; | ||
456 | } | ||||||
457 | else { | ||||||
458 | 0 | 0 | $self->aubbc_error('Usage: add_build_tag - Bad name or pattern format'); | ||||
459 | } | ||||||
460 | } | ||||||
461 | } | ||||||
462 | |||||||
463 | sub remove_build_tag { | ||||||
464 | 0 | 0 | 1 | 0 | my ($self,$name,$type) = @_; | ||
465 | 0 | 0 | 0 | warn 'ENTER remove_build_tag' if $DEBUG_AUBBC; | |||
466 | 0 | 0 | 0 | 0 | delete $Build_AUBBC{$name} if exists $Build_AUBBC{$name} && !$type; # clear one | ||
467 | 0 | 0 | 0 | 0 | %Build_AUBBC = () if $type && !$name; # clear all | ||
468 | } | ||||||
469 | |||||||
470 | sub do_unicode{ | ||||||
471 | 1 | 50 | 1 | 0 | 4 | warn 'ENTER do_unicode' if $DEBUG_AUBBC; | |
472 | 1 | 10 | $msg =~ s/\[utf:\/\/(\#?\w+)\]/&$1;/g; | ||||
473 | } | ||||||
474 | |||||||
475 | sub do_smileys { | ||||||
476 | 0 | 0 | 0 | 0 | 0 | warn 'ENTER do_smileys' if $DEBUG_AUBBC; | |
477 | $msg =~ | ||||||
478 | 0 | 0 | s/\[$_\]/make_image('',"$AUBBC{images_url}\/smilies\/$SMILEYS{$_}",'','',$_).$AUBBC{image_wrap}/ge | ||||
479 | 0 | 0 | foreach keys %SMILEYS; | ||||
480 | } | ||||||
481 | |||||||
482 | sub smiley_hash { | ||||||
483 | 0 | 0 | 0 | my ($self,%s_hash) = @_; | |||
484 | 0 | 0 | 0 | warn 'ENTER smiley_hash' if $DEBUG_AUBBC; | |||
485 | 0 | 0 | 0 | if (keys %s_hash) { | |||
486 | 0 | 0 | %SMILEYS = %s_hash; | ||||
487 | 0 | 0 | $do_f[6] = 1; | ||||
488 | } | ||||||
489 | } | ||||||
490 | |||||||
491 | sub do_all_ubbc { | ||||||
492 | 1 | 1 | 47 | my ($self,$message) = @_; | |||
493 | 1 | 50 | 4 | warn 'ENTER do_all_ubbc' if $DEBUG_AUBBC; | |||
494 | 1 | 50 | 4 | $msg = defined $message ? $message : ''; | |||
495 | 1 | 50 | 3 | if ($msg) { | |||
496 | 1 | 3 | check_access(); | ||||
497 | 1 | 50 | 22 | $msg = $self->script_escape($msg,'') if $AUBBC{script_escape}; | |||
498 | 1 | 50 | 11 | $msg =~ s/&(?!\#?\w+;)/&/g if $AUBBC{fix_amp}; | |||
499 | 1 | 50 | 33 | 10 | if (!$AUBBC{no_bypass} && $msg =~ m/\A\#no/) { | ||
500 | 0 | 0 | 0 | $do_f[4] = 0 if $msg =~ s/\A\#none//; | |||
501 | 0 | 0 | 0 | if ($do_f[4]) { | |||
502 | 0 | 0 | 0 | $do_f[0] = 0 if $msg =~ s/\A\#noubbc//; | |||
503 | 0 | 0 | 0 | $do_f[1] = 0 if $msg =~ s/\A\#nobuild//; | |||
504 | 0 | 0 | 0 | $do_f[2] = 0 if $msg =~ s/\A\#noutf//; | |||
505 | 0 | 0 | 0 | $do_f[3] = 0 if $msg =~ s/\A\#nosmileys//; | |||
506 | } | ||||||
507 | 0 | 0 | 0 | 0 | warn 'START no_bypass' if $DEBUG_AUBBC && !$do_f[4]; | ||
508 | } | ||||||
509 | 1 | 50 | 5 | if ($do_f[4]) { | |||
510 | 1 | 50 | 6 | escape_aubbc() if $AUBBC{aubbc_escape}; | |||
511 | 1 | 50 | 4 | if (!$AUBBC{for_links}) { | |||
512 | 1 | 50 | 33 | 10 | do_ubbc($msg) if $do_f[0] && $AUBBC{aubbc}; | ||
513 | 1 | 0 | 33 | 6 | do_build_tag() if $do_f[5] && $do_f[1]; | ||
514 | } | ||||||
515 | 1 | 50 | 33 | 13 | do_unicode() if $do_f[2] && $AUBBC{utf}; | ||
516 | 1 | 0 | 33 | 5 | do_smileys() if $do_f[6] && $do_f[3] && $AUBBC{smileys}; | ||
0 | |||||||
517 | } | ||||||
518 | } | ||||||
519 | 1 | 50 | 7 | $msg =~ tr/\000//d if $AUBBC{aubbc_escape}; | |||
520 | 1 | 4 | return $msg; | ||||
521 | } | ||||||
522 | |||||||
523 | sub fix_message { | ||||||
524 | 0 | 0 | 0 | 0 | my $txt = shift; | ||
525 | 0 | 0 | $txt =~ s/\././g; | ||||
526 | 0 | 0 | $txt =~ s/\:/:/g; | ||||
527 | 0 | 0 | return $txt; | ||||
528 | } | ||||||
529 | sub escape_aubbc { | ||||||
530 | 1 | 50 | 1 | 0 | 2 | warn 'ENTER escape_aubbc' if $DEBUG_AUBBC; | |
531 | 1 | 2 | $msg =~ s/\[\[/\000[/g; | ||||
532 | 1 | 2 | $msg =~ s/\]\]/\000]/g; | ||||
533 | } | ||||||
534 | |||||||
535 | sub script_escape { | ||||||
536 | 1 | 1 | 25 | my ($self, $text, $option) = @_; | |||
537 | 1 | 50 | 3 | warn 'ENTER html_escape' if $DEBUG_AUBBC; | |||
538 | 1 | 50 | 3 | $text = '' unless defined $text; | |||
539 | 1 | 50 | 5 | if ($text) { | |||
540 | 1 | 0 | 4 | $text =~ s/(&|;)/$1 eq '&' ? '&' : ';'/ge; | |||
0 | 0 | ||||||
541 | 1 | 50 | 4 | if (!$option) { | |||
542 | 1 | 2 | $text =~ s/\t/ \ \ \ /g; | ||||
543 | 1 | 2 | $text =~ s/ / \ /g; | ||||
544 | } | ||||||
545 | 1 | 2 | $text =~ s/"/"/g; | ||||
546 | 1 | 4 | $text =~ s/</g; | ||||
547 | 1 | 2 | $text =~ s/>/>/g; | ||||
548 | 1 | 3 | $text =~ s/'/'/g; | ||||
549 | 1 | 2 | $text =~ s/\)/)/g; | ||||
550 | 1 | 17 | $text =~ s/\(/(/g; | ||||
551 | 1 | 3 | $text =~ s/\\/\/g; | ||||
552 | 1 | 2 | $text =~ s/\|/|/g; | ||||
553 | 1 | 50 | 33 | 16 | ! $option && $AUBBC{line_break} eq '2' | ||
50 | 33 | ||||||
554 | ? $text =~ s/\n/ /g |
||||||
555 | : $text =~ s/\n/ \n/g if !$option && $AUBBC{line_break} eq '1'; |
||||||
556 | 1 | 3 | return $text; | ||||
557 | } | ||||||
558 | } | ||||||
559 | |||||||
560 | sub html_to_text { | ||||||
561 | 0 | 0 | 0 | my ($self, $html, $option) = @_; | |||
562 | 0 | 0 | 0 | warn 'ENTER html_to_text' if $DEBUG_AUBBC; | |||
563 | 0 | 0 | 0 | $html = '' unless defined $html; | |||
564 | 0 | 0 | 0 | if ($html) { | |||
565 | 0 | 0 | $html =~ s/&/&/g; | ||||
566 | 0 | 0 | $html =~ s/;/;/g; | ||||
567 | 0 | 0 | 0 | if (!$option) { | |||
568 | 0 | 0 | $html =~ s/ \ \ \ /\t/g; | ||||
569 | 0 | 0 | $html =~ s/ \ / /g; | ||||
570 | } | ||||||
571 | 0 | 0 | $html =~ s/"/"/g; | ||||
572 | 0 | 0 | $html =~ s/</ | ||||
573 | 0 | 0 | $html =~ s/>/>/g; | ||||
574 | 0 | 0 | $html =~ s/'/'/g; | ||||
575 | 0 | 0 | $html =~ s/)/\)/g; | ||||
576 | 0 | 0 | $html =~ s/(/\(/g; | ||||
577 | 0 | 0 | $html =~ s/\/\\/g; | ||||
578 | 0 | 0 | $html =~ s/|/\|/g; | ||||
579 | 0 | 0 | 0 | $html =~ s/ \n?/\n/g if $AUBBC{line_break}; |
|||
580 | 0 | 0 | return $html; | ||||
581 | } | ||||||
582 | } | ||||||
583 | |||||||
584 | sub version { | ||||||
585 | 1 | 1 | 1 | 6 | my $self = shift; | ||
586 | 1 | 3 | return $VERSION; | ||||
587 | } | ||||||
588 | |||||||
589 | sub aubbc_error { | ||||||
590 | 0 | 0 | 1 | my ($self, $error) = @_; | |||
591 | 0 | 0 | 0 | defined $error && $error | |||
592 | ? $aubbc_error .= $error . "\n" | ||||||
593 | : return $aubbc_error; | ||||||
594 | } | ||||||
595 | |||||||
596 | 1; | ||||||
597 | |||||||
598 | __END__ |