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, $lines_this_time) = get_total_lines ();
175 my $lines_per_sec = 'infinite';
178 $lines_this_time ||= 0;
180 my $hp = translate ("onis' homepage");
181 my $gen = translate ('This page was generated <span>on %s</span> <span>with %s</span>');
182 my $stats = translate ('%u lines processed in %u seconds (%s lines per second, %u lines total)');
183 my $by = translate ('onis is written %s <span>by %s</span>');
184 my $link = translate ('Get the latest version from %s');
186 my $lps = translate ('infinite');
189 $lps = sprintf ("%.1f", ($lines_this_time / $runtime));
193 </div> <!-- class="msie_hack" -->
194 <!-- This script is under GPL (GNU public license). You may copy and modify it. -->
199 print $fh ' <td class="left">';
200 printf $fh ($gen, $now, "onis $::VERSION ("onis not irc stats")");
201 print $fh "<br />\n ";
202 printf $fh ($stats, $lines_this_time, $runtime, $lps, $total_lines);
203 print $fh qq#\n </td>\n <td class="right">\n #;
204 printf $fh ($by, '2000-2005', '<a href="http://verplant.org/">Florian octo Forster</a></span> <span><octo@<span class="spam">nospam.</span>verplant.org>');
205 print $fh qq#<img id="smalllogo" src="http://images.verplant.org/onis-small.png" /># if ($PUBLIC_PAGE);
206 print $fh "<br />\n ";
207 printf $fh ($link, sprintf (qq#<a href="http://verplant.org/onis/">%s</a>#, $hp));
226 my $esc = escape_uris ($_);
227 push (@retval, $esc);
236 return join ("\n", @retval);
245 return ('') if (!defined ($text));
247 #if ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%/-~]+)?(?=\W|$)#i)
248 if ($text =~ m#(?:(?:ftp|https?)://|www\.)[\w\.-]+\.[A-Za-z]{2,4}(?::\d+)?(?:/[\w\d\.\%\/\-\~]*(?:\?[\+\w\&\%\=]+)?)?(?=\W|$)#i)
254 my $match = $orig_match;
255 if ($match =~ /^www/i) { $match = 'http://' . $match; }
256 if ($match !~ m#://.+/#) { $match .= '/'; }
258 if ((length ($orig_match) > 50) and ($orig_match =~ m#^http://#))
260 $orig_match =~ s#^http://##;
262 if (length ($orig_match) > 50)
264 my $len = length ($orig_match) - 47;
265 substr ($orig_match, 47, $len, '...');
268 $retval = escape_normal ($prematch);
269 $retval .= qq(<a href="$match">$orig_match</a>);
270 $retval .= escape_uris ($postmatch);
274 $retval = escape_normal ($text);
284 return ('') if (!defined ($text));
286 $text =~ s/\&/\&/g;
287 $text =~ s/"/\"/g;
288 $text =~ s/</\</g;
289 $text =~ s/>/\>/g;
292 $text =~ s/ä/\ä/g;
293 $text =~ s/ö/\ö/g;
294 $text =~ s/ü/\ü/g;
295 $text =~ s/Ä/\Ä/g;
296 $text =~ s/Ü/\Ö/g;
297 $text =~ s/Ö/\Ü/g;
298 $text =~ s/ß/\ß/g;
302 $text = find_colors ($text);
306 $text =~ s/[\cB\c_\cV\cO]|\cC(?:\d+(?:,\d+)?)?//g;
329 while ($string =~ m/([\cB\c_\cV\cO])|(\cC)(?:(\d+)(?:,(\d+))?)?/g)
331 my $controlchar = $1 ? $1 : $2;
332 my $fg = defined ($3) ? $3 : -1;
333 my $bg = defined ($4) ? $4 : -1;
340 # Close open spans first
341 if ($flags{'span_open'})
343 $newspan .= "</span>";
344 $flags{'span_open'} = 0;
347 # To catch `\cC' without anything following..
348 if (($controlchar eq "\cC") and ($fg == -1) and ($bg == -1))
350 $flags{'fg_color'} = -1;
351 $flags{'bg_color'} = -1;
353 elsif ($controlchar eq "\cC")
357 $flags{'fg_color'} = $fg % scalar (@mirc_colors);
361 $flags{'bg_color'} = $bg % scalar (@mirc_colors);
364 elsif ($controlchar eq "\cB")
366 $flags{'bold'} = 1 - $flags{'bold'};
368 elsif ($controlchar eq "\c_")
370 $flags{'underline'} = 1 - $flags{'underline'};
372 elsif ($controlchar eq "\cV")
374 $flags{'reverse'} = 1 - $flags{'reverse'};
377 elsif ($controlchar eq "\cO")
379 $flags{'fg_color'} = -1;
380 $flags{'bg_color'} = -1;
382 $flags{'underline'} = 0;
383 $flags{'reverse'} = 0;
386 # build the new span-tag
387 if (($flags{'fg_color'} != -1) || ($flags{'bg_color'} != -1)
388 || $flags{'bold'} || $flags{'underline'})
390 my $fg = $flags{'fg_color'};
391 my $bg = $flags{'bg_color'};
394 if ($flags{'reverse'} and ($bg != -1))
396 $fg = $flags{'bg_color'};
397 $bg = $flags{'fg_color'};
402 push (@style, 'color: ' . $mirc_colors[$fg] . ';');
406 push (@style, 'background-color: ' . $mirc_colors[$bg] . ';');
410 push (@style, 'font-weight: bold;');
412 if ($flags{'underline'})
414 push (@style, 'text-decoration: underline;');
417 $newspan .= '<span style="' . join (' ', @style) . '">';
418 $flags{'span_open'} = 1;
421 $string = $prematch . $newspan . $postmatch;
424 if ($flags{'span_open'})
426 $string .= "</span>";
427 $flags{'span_open'} = 0;