7 use Onis::Config qw/get_config/;
8 use Onis::Language qw/translate/;
9 use Onis::Data::Core qw#get_channel get_total_lines#;
11 @Onis::Html::EXPORT_OK = qw/open_file close_file get_filehandle html_escape/;
12 @Onis::Html::ISA = ('Exporter');
15 our $time_start = time ();
20 if (get_config ('color_codes'))
22 my $temp = get_config ('color_codes');
23 if (($temp eq 'print') or ($temp eq 'true')
30 if (get_config ('public_page'))
32 my $temp = get_config ('public_page');
34 if ($temp =~ m/false|off|no/i)
40 # `orange' is not a plain html name.
41 # The color we want is #FFA500
42 our @mirc_colors = qw/white black navy green red maroon purple orange
43 yellow lime teal aqua blue fuchsia gray silver/;
45 my $VERSION = '$Id: Html.pm,v 1.20 2004/09/16 10:30:20 octo Exp $';
46 print STDERR $/, __FILE__, ": $VERSION" if ($::DEBUG);
61 print STDERR $/, __FILE__, ": Not opening file ``$file'': Another file is already open!";
65 unless (open ($fh, "> $file"))
67 print STDERR $/, __FILE__, ": Unable to open file ``$file'': $!";
71 unless (flock ($fh, LOCK_EX))
73 print STDERR $/, __FILE__, ": Unable to exclusive lock file ``$file'': $!";
83 # Generates the HTML header including the CSS information.
84 # Doesn't take any arguments
87 my $generated_time = scalar (localtime ($time_start));
90 my $stylesheet = 'style.css';
91 if (get_config ('stylesheet'))
93 $stylesheet = get_config ('stylesheet');
96 my $encoding = 'iso-8859-1';
97 if (get_config ('encoding'))
99 $encoding = get_config ('encoding');
103 if (get_config ('user'))
105 $user = get_config ('user');
107 elsif (defined ($ENV{'USER'}))
109 $user = $ENV{'USER'};
112 my $channel = get_channel ();
114 my @images = get_config ('horizontal_images');
117 @images = qw#images/hor0n.png images/hor1n.png images/hor2n.png images/hor3n.png#;
120 $trans = translate ('%s statistics created by %s');
121 my $title = sprintf ($trans, $channel, $user);
125 <?xml version="1.0" encoding="$encoding"?>
126 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
127 "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
129 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
131 <title>$title</title>
132 <meta http-equiv="Cache-Control" content="public, must-revalidiate" />
133 <link rel="stylesheet" type="text/css" href="$stylesheet" />
138 <div class="msie_hack">
141 $trans = translate ('%s stats by %s');
142 $title = sprintf ($trans, $channel, $user);
144 $trans = translate ('Statistics generated on %s');
145 my $time_msg = sprintf ($trans, $generated_time);
147 $trans = translate ('Hours');
153 <table class="legend">
155 <td><img src="$images[0]" alt="Red" /><br />$trans 0-5</td>
156 <td><img src="$images[1]" alt="Green" /><br />$trans 6-11</td>
157 <td><img src="$images[2]" alt="Blue" /><br />$trans 12-17</td>
158 <td><img src="$images[3]" alt="Red" /><br />$trans 18-24</td>
165 # this routine adds a box to the end of the html-
166 # page with onis' homepage URL, the author's name
167 # and email-address. Feel free to uncomment the
168 # creation of this box if it's appereance nags
172 my $runtime = time () - $time_start;
173 my $now = scalar (localtime ());
174 my $total_lines = get_total_lines () || 0;
175 my $lines_per_sec = 'infinite';
177 my $hp = translate ("onis' homepage");
178 my $gen = translate ('This page was generated <span>on %s</span> <span>with %s</span>');
179 my $stats = translate ('%u lines processed in %u seconds (%s lines per second)');
180 my $by = translate ('onis is written %s <span>by %s</span>');
181 my $link = translate ('Get the latest version from %s');
183 my $lps = translate ('infinite');
186 $lps = sprintf ("%.1f", ($total_lines / $runtime));
190 </div> <!-- class="msie_hack" -->
191 <!-- This script is under GPL (GNU public license). You may copy and modify it. -->
196 print $fh ' <td class="left">';
197 printf $fh ($gen, $now, "onis $::VERSION ("onis not irc stats")");
198 print $fh "<br />\n ";
199 printf $fh ($stats, $total_lines, $runtime, $lps);
200 print $fh qq#\n </td>\n <td class="right">\n #;
201 printf $fh ($by, '2000-2004', '<a href="http://verplant.org/">Florian octo Forster</a></span> <span><octo@<span class="spam">nospam.</span>verplant.org>');
202 print $fh qq#<img id="smalllogo" src="http://images.verplant.org/onis-small.png" /># if ($PUBLIC_PAGE);
203 print $fh "<br />\n ";
204 printf $fh ($link, sprintf (qq#<a href="http://verplant.org/onis/">%s</a>#, $hp));
223 my $esc = escape_uris ($_);
224 push (@retval, $esc);
233 return join ("\n", @retval);
242 return ('') if (!defined ($text));
244 #if ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%/-~]+)?(?=\W|$)#i)
245 if ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%\/\-\~]*(?:\?[\+\w\&\%\=]+)?)?(?=\W|$)#i)
251 my $match = $orig_match;
252 if ($match =~ /^www/i) { $match = 'http://' . $match; }
253 if ($match !~ m#://.+/#) { $match .= '/'; }
255 if ((length ($orig_match) > 50) and ($orig_match =~ m#^http://#))
257 $orig_match =~ s#^http://##;
259 if (length ($orig_match) > 50)
261 my $len = length ($orig_match) - 47;
262 substr ($orig_match, 47, $len, '...');
265 $retval = escape_normal ($prematch);
266 $retval .= qq(<a href="$match">$orig_match</a>);
267 $retval .= escape_uris ($postmatch);
271 $retval = escape_normal ($text);
281 return ('') if (!defined ($text));
283 $text =~ s/\&/\&/g;
284 $text =~ s/"/\"/g;
285 $text =~ s/</\</g;
286 $text =~ s/>/\>/g;
289 $text =~ s/ä/\ä/g;
290 $text =~ s/ö/\ö/g;
291 $text =~ s/ü/\ü/g;
292 $text =~ s/Ä/\Ä/g;
293 $text =~ s/Ü/\Ö/g;
294 $text =~ s/Ö/\Ü/g;
295 $text =~ s/ß/\ß/g;
299 $text = find_colors ($text);
303 $text =~ s/[\cB\c_\cV\cO]|\cC(?:\d+(?:,\d+)?)?//g;
326 while ($string =~ m/([\cB\c_\cV\cO])|(\cC)(?:(\d+)(?:,(\d+))?)?/g)
328 my $controlchar = $1 ? $1 : $2;
329 my $fg = defined ($3) ? $3 : -1;
330 my $bg = defined ($4) ? $4 : -1;
337 # Close open spans first
338 if ($flags{'span_open'})
340 $newspan .= "</span>";
341 $flags{'span_open'} = 0;
344 # To catch `\cC' without anything following..
345 if (($controlchar eq "\cC") and ($fg == -1) and ($bg == -1))
347 $flags{'fg_color'} = -1;
348 $flags{'bg_color'} = -1;
350 elsif ($controlchar eq "\cC")
354 $flags{'fg_color'} = $fg % scalar (@mirc_colors);
358 $flags{'bg_color'} = $bg % scalar (@mirc_colors);
361 elsif ($controlchar eq "\cB")
363 $flags{'bold'} = 1 - $flags{'bold'};
365 elsif ($controlchar eq "\c_")
367 $flags{'underline'} = 1 - $flags{'underline'};
369 elsif ($controlchar eq "\cV")
371 $flags{'reverse'} = 1 - $flags{'reverse'};
374 elsif ($controlchar eq "\cO")
376 $flags{'fg_color'} = -1;
377 $flags{'bg_color'} = -1;
379 $flags{'underline'} = 0;
380 $flags{'reverse'} = 0;
383 # build the new span-tag
384 if (($flags{'fg_color'} != -1) || ($flags{'bg_color'} != -1)
385 || $flags{'bold'} || $flags{'underline'})
387 my $fg = $flags{'fg_color'};
388 my $bg = $flags{'bg_color'};
391 if ($flags{'reverse'} and ($bg != -1))
393 $fg = $flags{'bg_color'};
394 $bg = $flags{'fg_color'};
399 push (@style, 'color: ' . $mirc_colors[$fg] . ';');
403 push (@style, 'background-color: ' . $mirc_colors[$bg] . ';');
407 push (@style, 'font-weight: bold;');
409 if ($flags{'underline'})
411 push (@style, 'text-decoration: underline;');
414 $newspan .= '<span style="' . join (' ', @style) . '">';
415 $flags{'span_open'} = 1;
418 $string = $prematch . $newspan . $postmatch;
421 if ($flags{'span_open'})
423 $string .= "</span>";
424 $flags{'span_open'} = 0;