HTMLGenerator.pm 66 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113
  1. package Pisg::HTMLGenerator;
  2. # Copyright and license, as well as documentation(POD) for this module is
  3. # found at the end of the file.
  4. use strict;
  5. $^W = 1;
  6. sub new
  7. {
  8. my $type = shift;
  9. my %args = @_;
  10. my $self = {
  11. cfg => $args{cfg},
  12. stats => $args{stats},
  13. users => $args{users},
  14. tmps => $args{tmps},
  15. topactive => {},
  16. };
  17. # Import common functions in Pisg::Common
  18. require Pisg::Common;
  19. Pisg::Common->import();
  20. bless($self, $type);
  21. return $self;
  22. }
  23. sub create_html
  24. {
  25. # This subroutine calls all the subroutines which create their
  26. # individual stats. The name of the functions is somewhat saying - if
  27. # you don't understand it, most subs have a better explanation in the
  28. # sub itself.
  29. my $self = shift;
  30. $self->_topactive();
  31. print "Now generating HTML($self->{cfg}->{outputfile})...\n"
  32. unless ($self->{cfg}->{silent});
  33. open (OUTPUT, "> $self->{cfg}->{outputfile}") or
  34. die("$0: Unable to open outputfile($self->{cfg}->{outputfile}): $!\n");
  35. if ($self->{cfg}->{showtime}) {
  36. $self->{cfg}->{tablewidth} += 40;
  37. }
  38. if ($self->{cfg}->{showlinetime}) {
  39. $self->{cfg}->{tablewidth} += 100;
  40. }
  41. if ($self->{cfg}->{showwordtime}) {
  42. $self->{cfg}->{tablewidth} += 100;
  43. }
  44. if ($self->{cfg}->{showwords}) {
  45. $self->{cfg}->{tablewidth} += 40;
  46. }
  47. if ($self->{cfg}->{showwpl}) {
  48. $self->{cfg}->{tablewidth} += 40;
  49. }
  50. if ($self->{cfg}->{showcpl}) {
  51. $self->{cfg}->{tablewidth} += 40;
  52. }
  53. $self->{cfg}->{headwidth} = $self->{cfg}->{tablewidth} - 4;
  54. $self->_htmlheader();
  55. $self->_pageheader()
  56. if ($self->{cfg}->{pagehead} ne 'none');
  57. if ($self->{cfg}->{showactivetimes}) {
  58. $self->_activetimes();
  59. }
  60. $self->_activenicks();
  61. if ($self->{cfg}->{showmostactivebyhour}) {
  62. $self->_mostactivebyhour();
  63. }
  64. if ($self->{cfg}->{showbignumbers}) {
  65. $self->_headline($self->_template_text('bignumtopic'));
  66. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  67. $self->_questions();
  68. $self->_shoutpeople();
  69. $self->_capspeople();
  70. $self->_violent();
  71. $self->_mostsmiles();
  72. $self->_mostsad();
  73. $self->_linelengths();
  74. $self->_mostwords();
  75. $self->_mostwordsperline();
  76. _html("</table>"); # Needed for sections
  77. }
  78. if ($self->{cfg}->{showmostnicks}) {
  79. $self->_mostnicks();
  80. }
  81. if ($self->{cfg}->{showmuw}) {
  82. $self->_mostusedword();
  83. }
  84. if ($self->{cfg}->{showmrn}) {
  85. $self->_mostreferencednicks();
  86. }
  87. if ($self->{cfg}->{showmru}) {
  88. $self->_mosturls();
  89. }
  90. if ($self->{cfg}->{showbignumbers}) {
  91. $self->_headline($self->_template_text('othernumtopic'));
  92. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  93. $self->_gotkicks();
  94. $self->_mostkicks();
  95. $self->_mostop() if $self->{cfg}->{showops};
  96. $self->_mosthalfop() if $self->{cfg}->{showhalfops};
  97. $self->_mostvoice() if $self->{cfg}->{showvoices};
  98. $self->_mostactions();
  99. $self->_mostmonologues();
  100. $self->_mostjoins();
  101. $self->_mostfoul();
  102. _html("</table>"); # Needed for sections
  103. }
  104. if ($self->{cfg}->{showtopics}) {
  105. $self->_headline($self->_template_text('latesttopic'));
  106. _html("<table width=\"$self->{cfg}->{tablewidth}\">\n"); # Needed for sections
  107. $self->_lasttopics();
  108. _html("</table>"); # Needed for sections
  109. }
  110. my %hash = ( lines => $self->{stats}->{parsedlines} );
  111. _html($self->_template_text('totallines', %hash) . "<br /><br />");
  112. $self->_pagefooter()
  113. if ($self->{cfg}->{pagefoot} ne 'none');
  114. $self->_htmlfooter();
  115. close(OUTPUT);
  116. }
  117. sub _htmlheader
  118. {
  119. my $self = shift;
  120. my %hash = (
  121. network => $self->{cfg}->{network},
  122. maintainer => $self->{cfg}->{maintainer},
  123. days => $self->{stats}->{days},
  124. nicks => scalar keys %{ $self->{stats}->{lines} }
  125. );
  126. my $css_file = $self->{cfg}->{cssdir} . $self->{cfg}->{colorscheme} . ".css";
  127. # Get the chosen CSS file
  128. open(FILE, $css_file) or open (FILE, $self->{cfg}->{search_path} . "/$css_file") or die("$0: Unable to open stylesheet($css_file): $!\n");
  129. my @CSS = <FILE>;
  130. my $title = $self->_template_text('pagetitle1', %hash);
  131. print OUTPUT <<HTML;
  132. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  133. <html>
  134. <head>
  135. <meta http-equiv="Content-Type" content="text/html; charset=$self->{cfg}->{charset}" />
  136. <title>$title</title>
  137. <style type="text/css">
  138. @CSS
  139. </style></head>
  140. <body>
  141. <div align="center">
  142. HTML
  143. _html("<span class=\"title\">$title</span><br />");
  144. _html("<br />");
  145. _html($self->_template_text('pagetitle2', %hash) . " " . $self->get_time());
  146. _html("<br />" . $self->_template_text('pagetitle3', %hash) . "<br /><br />");
  147. }
  148. sub get_time
  149. {
  150. my $self = shift;
  151. my ($tday, %hash);
  152. my $month = $self->_template_text('month', %hash);
  153. my $day = $self->_template_text('day', %hash);
  154. my @month = split(" ", $month);
  155. my @day = split(" ", $day);
  156. # Get the Date from the users computer
  157. my $timezone = $self->{cfg}->{timeoffset} * 3600;
  158. my ($sec,$min,$hour,$mday,$mon,$year,$wday) = localtime(time+$timezone);
  159. $year += 1900; # Y2K Patch
  160. $min =~ s/^(.)$/0$1/; # Fixes the display of mins/secs below
  161. $sec =~ s/^(.)$/0$1/; # it displays 03 instead of 3
  162. if ($hour > '23') { # Checks to see if it Midnight
  163. $hour = 12; # Makes it display the hour 12
  164. $tday = "AM"; # Display AM
  165. } elsif($hour > '12') { # Get rid of the Military time and
  166. $hour -= 12; # put it into normal time
  167. $tday = "PM"; # If past Noon and before Midnight set
  168. } else {
  169. $tday = "AM"; # If it's past Midnight and before Noon
  170. } # set the time as AM
  171. # Use 24 hours pr. day
  172. if ($tday eq "PM" && $hour < '12') {
  173. $hour += 12;
  174. }
  175. return "$day[$wday] $mday $month[$mon] $year - $hour:$min:$sec";
  176. }
  177. sub _htmlfooter
  178. {
  179. my $self = shift;
  180. my %hash;
  181. my $pisg_hp = $self->_template_text('pisghomepage');
  182. $hash{pisg_url} = "<a href=\"http://pisg.sourceforge.net/\" title=\"$pisg_hp\" class=\"background\">pisg</a>";
  183. my $author_hp = $self->_template_text('authorhomepage');
  184. $hash{author_url} = "<a href=\"http://mbrix.dk/\" title=\"$author_hp\" class=\"background\">Morten Brix Pedersen</a>";
  185. $hash{version} = $self->{cfg}->{version};
  186. my $hours = $self->_template_text('hours');
  187. my $mins = $self->_template_text('minutes');
  188. my $secs = $self->_template_text('seconds');
  189. my $and = $self->_template_text('and');
  190. my $h = $self->{stats}->{processtime}{hours};
  191. my $m = $self->{stats}->{processtime}{mins};
  192. my $s = $self->{stats}->{processtime}{secs};
  193. $hash{time} = "$h $hours $m $mins $and $s $secs";
  194. my $stats_gen = $self->_template_text('stats_gen_by', %hash);
  195. my $author_text = $self->_template_text('author', %hash);
  196. my $stats_text = $self->_template_text('stats_gen_in', %hash);
  197. print OUTPUT <<HTML;
  198. <span class="small">
  199. $stats_gen<br />
  200. $author_text<br />
  201. $stats_text
  202. </span>
  203. </div>
  204. </body>
  205. </html>
  206. HTML
  207. }
  208. sub _headline
  209. {
  210. my $self = shift;
  211. my ($title) = (@_);
  212. print OUTPUT <<HTML;
  213. <br />
  214. <table width="$self->{cfg}->{headwidth}" cellpadding="1" cellspacing="0" border="0">
  215. <tr>
  216. <td class="headlinebg">
  217. <table width="100%" cellpadding="2" cellspacing="0" border="0">
  218. <tr>
  219. <td class="headtext">$title</td>
  220. </tr>
  221. </table>
  222. </td>
  223. </tr>
  224. </table>
  225. HTML
  226. }
  227. sub _pageheader
  228. {
  229. my $self = shift;
  230. open(PAGEHEAD, $self->{cfg}->{pagehead}) or die("$0: Unable to open $self->{cfg}->{pagehead} for reading: $!\n");
  231. while (<PAGEHEAD>) {
  232. _html($_);
  233. }
  234. close(PAGEHEAD);
  235. }
  236. sub _pagefooter
  237. {
  238. my $self = shift;
  239. open(PAGEFOOT, $self->{cfg}->{pagefoot}) or die("$0: Unable to open $self->{cfg}->{pagefoot} for reading: $!\n");
  240. while (<PAGEFOOT>) {
  241. _html($_);
  242. }
  243. close(PAGEFOOT);
  244. }
  245. sub _activetimes
  246. {
  247. # The most actives times on the channel
  248. my $self = shift;
  249. my (%output, $class);
  250. $self->_headline($self->_template_text('activetimestopic'));
  251. my @toptime = sort { $self->{stats}->{times}{$b} <=> $self->{stats}->{times}{$a} } keys %{ $self->{stats}->{times} };
  252. my $highest_value = $self->{stats}->{times}{$toptime[0]};
  253. my @now = localtime($self->{cfg}->{timestamp});
  254. my $image;
  255. for my $hour (sort keys %{ $self->{stats}->{times} }) {
  256. my $size = ($self->{stats}->{times}{$hour} / $highest_value) * 100;
  257. my $percent = ($self->{stats}->{times}{$hour} / $self->{stats}->{parsedlines}) * 100;
  258. $percent =~ s/(\.\d)\d+/$1/;
  259. if ($size < 1 && $size != 0) {
  260. # Opera doesn't understand '0.xxxx' in the height="xx" attr,
  261. # so we simply round up to 1.0 here.
  262. $size = 1.0;
  263. }
  264. $image = "pic_v_".(int($hour/6)*6);
  265. $image = $self->{cfg}->{$image};
  266. $output{$hour} = "<td align=\"center\" valign=\"bottom\" class=\"asmall\">$percent%<br /><img src=\"$self->{cfg}->{piclocation}/$image\" width=\"15\" height=\"$size\" alt=\"$percent\" /></td>\n";
  267. }
  268. _html("<table border=\"0\"><tr>\n");
  269. for ($b = 0; $b < 24; $b++) {
  270. $a = sprintf("%02d", $b);
  271. if (!defined($output{$a}) || $output{$a} eq "") {
  272. _html("<td align=\"center\" valign=\"bottom\" class=\"asmall\">0%</td>");
  273. } else {
  274. _html($output{$a});
  275. }
  276. }
  277. _html("</tr><tr>");
  278. # Remove leading zero
  279. $toptime[0] =~ s/0(\d)/$1/;
  280. for ($b = 0; $b < 24; $b++) {
  281. if ($toptime[0] == $b) {
  282. # Highlight the top time
  283. $class = 'hirankc10center';
  284. } else {
  285. $class = 'rankc10center';
  286. }
  287. _html("<td class=\"$class\" align=\"center\">$b</td>");
  288. }
  289. _html("</tr></table>");
  290. if($self->{cfg}->{showlegend} == 1) {
  291. $self->_legend();
  292. }
  293. }
  294. sub _activenicks
  295. {
  296. # The most active nicks (those who wrote most lines)
  297. my $self = shift;
  298. $self->_headline($self->_template_text('activenickstopic'));
  299. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  300. _html("<td>&nbsp;</td>"
  301. . "<td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>"
  302. . "<td class=\"tdtop\"><b>" . $self->_template_text('numberlines') . "</b></td>"
  303. . ($self->{cfg}->{showtime} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_time')."</b></td>" : "")
  304. . ($self->{cfg}->{showwords} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_words')."</b></td>" : "")
  305. . ($self->{cfg}->{showwpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_wpl')."</b></td>" : "")
  306. . ($self->{cfg}->{showcpl} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_cpl')."</b></td>" : "")
  307. . ($self->{cfg}->{showlastseen} ? "<td class=\"tdtop\"><b>".$self->_template_text('show_lastseen')."</b></td>" : "")
  308. . ($self->{cfg}->{showrandquote} ? "<td class=\"tdtop\"><b>".$self->_template_text('randquote')."</b></td>" : "")
  309. );
  310. my @active;
  311. my $nicks;
  312. if ($self->{cfg}->{sortbywords}) {
  313. @active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} } keys %{ $self->{stats}->{words} };
  314. $nicks = scalar keys %{ $self->{stats}->{words} };
  315. } else {
  316. @active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} } keys %{ $self->{stats}->{lines} };
  317. $nicks = scalar keys %{ $self->{stats}->{lines} };
  318. }
  319. if ($self->{cfg}->{activenicks} > $nicks) { $self->{cfg}->{activenicks} = $nicks; }
  320. my $have_userpics;
  321. for (my $c = 0; $c < $self->{cfg}->{activenicks}; $c++) {
  322. my $nick = $active[$c];
  323. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  324. $have_userpics = 1;
  325. _html("<td class=\"tdtop\"><b>" . $self->_template_text('userpic') ."</b></td>");
  326. last;
  327. }
  328. }
  329. _html("</tr>");
  330. for (my $i = 0; $i < $self->{cfg}->{activenicks}; $i++) {
  331. my $c = $i + 1;
  332. my $nick = $active[$i];
  333. my $visiblenick = $active[$i];
  334. my $randomline;
  335. if (not defined $self->{stats}->{sayings}{$nick}) {
  336. if ($self->{stats}->{actions}{$nick}) {
  337. $randomline = $self->{stats}->{actionlines}{$nick};
  338. } else {
  339. $randomline = "";
  340. }
  341. } else {
  342. $randomline = $self->{stats}->{sayings}{$nick};
  343. }
  344. if ($randomline) {
  345. $randomline = $self->_format_line($randomline);
  346. }
  347. # Add a link to the nick if there is any
  348. if ($self->{users}->{userlinks}{$nick}) {
  349. $visiblenick = $self->_replace_links($self->{users}->{userlinks}{$nick}, $nick);
  350. }
  351. my $color = $self->generate_colors($c);
  352. my $class = 'rankc';
  353. if ($c == 1) {
  354. $class = 'hirankc';
  355. }
  356. my $lastseen;
  357. if ($self->{cfg}->{showlastseen}) {
  358. $lastseen = $self->{stats}->{days} - $self->{stats}->{lastvisited}{$nick};
  359. if ($lastseen == 0) {
  360. $lastseen = $self->_template_text('today');
  361. } elsif ($lastseen == 1) {
  362. $lastseen = "$lastseen " .$self->_template_text('lastseen1');
  363. } else {
  364. $lastseen = "$lastseen " .$self->_template_text('lastseen2');
  365. }
  366. }
  367. _html("<tr><td class=\"$class\" align=\"left\">$c</td>");
  368. my $line = $self->{stats}->{lines}{$nick};
  369. my $w = $self->{stats}->{words}{$nick} ? $self->{stats}->{words}{$nick} : 0;
  370. my $ch = $self->{stats}->{lengths}{$nick};
  371. my $sex = $self->{users}->{sex}{$nick};
  372. _html("<td style=\"background-color: $color\""
  373. . ($sex ? ($sex eq 'm' ? " class=\"male\">"
  374. : ($sex eq 'f' ? " class=\"female\">" : " class=\"bot\">")) : ">")
  375. ."$visiblenick</td>"
  376. . ($self->{cfg}->{showlinetime} ?
  377. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_linetimes($nick,$active[0])."</td>"
  378. : "<td style=\"background-color: $color\">$line</td>")
  379. . ($self->{cfg}->{showtime} ?
  380. "<td style=\"background-color: $color\">".$self->_user_times($nick)."</td>"
  381. : "")
  382. . ($self->{cfg}->{showwords} ?
  383. ($self->{cfg}->{showwordtime} ?
  384. "<td style=\"background-color: $color\" nowrap=\"nowrap\">".$self->_user_wordtimes($nick,$active[0])."</td>"
  385. : "<td style=\"background-color: $color\">$w</td>")
  386. : "")
  387. . ($self->{cfg}->{showwpl} ?
  388. "<td style=\"background-color: $color\">".sprintf("%.1f",$w/$line)."</td>"
  389. : "")
  390. . ($self->{cfg}->{showcpl} ?
  391. "<td style=\"background-color: $color\">".sprintf("%.1f",$ch/$line)."</td>"
  392. : "")
  393. . ($self->{cfg}->{showlastseen} ?
  394. "<td style=\"background-color: $color\">$lastseen</td>"
  395. : "")
  396. . ($self->{cfg}->{showrandquote} ?
  397. "<td style=\"background-color: $color\">\"$randomline\"</td>"
  398. : "")
  399. );
  400. my $height = $self->{cfg}->{picheight};
  401. my $width = $self->{cfg}->{picwidth};
  402. if ($width ne '') {
  403. $width = "width=\"$width\"";
  404. }
  405. if ($height ne '') {
  406. $height = "height=\"$height\"";
  407. }
  408. if ($self->{users}->{userpics}{$nick} && $self->{cfg}->{userpics} !~ /n/i) {
  409. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\">");
  410. if (defined $self->{users}->{biguserpics}{$nick}) {
  411. if ($self->{users}->{biguserpics}{$nick} =~ /^http:\/\//i) {
  412. _html("<a href=\"$self->{users}->{biguserpics}{$nick}\">");
  413. } else {
  414. _html("<a href=\"$self->{cfg}->{imagepath}$self->{users}->{biguserpics}{$nick}\">");
  415. }
  416. }
  417. if ($self->{users}->{userpics}{$nick} =~ /^http:\/\//i) {
  418. _html("<img src=\"$self->{users}->{userpics}{$nick}\" $width $height alt=\"$nick\" />");
  419. } else {
  420. _html("<img src=\"$self->{cfg}->{imagepath}$self->{users}->{userpics}{$nick}\" $width $height alt=\"$nick\" />");
  421. }
  422. if (defined $self->{users}->{biguserpics}{$nick}) {
  423. _html("</a>");
  424. }
  425. _html("</td>");
  426. } elsif ($self->{cfg}->{defaultpic} ne '' && $self->{cfg}->{userpics} !~ /n/i) {
  427. if ($self->{cfg}->{defaultpic} =~ /^http:\/\//i) {
  428. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\"><img src=\"$self->{cfg}->{defaultpic}\" $width $height alt=\"\" /></td>");
  429. } else {
  430. _html("<td style=\"background-color: $color\" align=\"center\" valign=\"middle\"><img src=\"$self->{cfg}->{imagepath}$self->{cfg}->{defaultpic}\" $width $height alt=\"\" /></td>");
  431. }
  432. }
  433. _html("</tr>");
  434. }
  435. _html("</table><br />");
  436. # Almost as active nicks ('These didn't make it to the top..')
  437. my $toshow = $self->{cfg}->{activenicks2} - $self->{cfg}->{activenicks};
  438. my $remain = $self->{cfg}->{activenicks} + $toshow;
  439. unless ($toshow > $nicks) {
  440. $remain = $self->{cfg}->{activenicks} + $self->{cfg}->{activenicks2};
  441. if ($remain > $nicks) {
  442. $remain = $nicks;
  443. }
  444. if ($self->{cfg}->{activenicks} < $remain) {
  445. _html("<br /><b><i>" . $self->_template_text('nottop') . "</i></b><table><tr>");
  446. for (my $i = $self->{cfg}->{activenicks}; $i < $remain; $i++) {
  447. unless ($i % 5) { if ($i != $self->{cfg}->{activenicks}) { _html("</tr><tr>"); } }
  448. my $items;
  449. if ($self->{cfg}->{sortbywords}) {
  450. $items = $self->{stats}->{words}{$active[$i]};
  451. } else {
  452. $items = $self->{stats}->{lines}{$active[$i]};
  453. }
  454. my $sex = $self->{users}->{sex}{$active[$i]};
  455. _html("<td class=\"rankc10\">"
  456. . ($sex ? ($sex eq 'm' ? "<span class=\"male\">"
  457. : ($sex eq 'f' ? "<span class=\"female\">" : "<span class=\"bot\">")) : "")
  458. ."$active[$i] ($items)"
  459. . ($sex ? "</span>" : "")
  460. ."</td>");
  461. }
  462. _html("</tr></table>");
  463. }
  464. }
  465. my %hash;
  466. $hash{totalnicks} = $nicks - $remain;
  467. if ($hash{totalnicks} > 0) {
  468. _html("<br /><b>" . $self->_template_text('totalnicks', %hash) . "</b><br />");
  469. }
  470. }
  471. sub generate_colors
  472. {
  473. my $self = shift;
  474. my $c = shift;
  475. my $h = $self->{cfg}->{hicell};
  476. $h =~ s/^#//;
  477. $h = hex $h;
  478. my $h2 = $self->{cfg}->{hicell2};
  479. $h2 =~ s/^#//;
  480. $h2 = hex $h2;
  481. my $f_b = $h & 0xff;
  482. my $f_g = ($h & 0xff00) >> 8;
  483. my $f_r = ($h & 0xff0000) >> 16;
  484. my $t_b = $h2 & 0xff;
  485. my $t_g = ($h2 & 0xff00) >> 8;
  486. my $t_r = ($h2 & 0xff0000) >> 16;
  487. my $blue = sprintf "%0.2x", abs int(((($t_b - $f_b) / $self->{cfg}->{activenicks}) * +$c) + $f_b);
  488. my $green = sprintf "%0.2x", abs int(((($t_g - $f_g) / $self->{cfg}->{activenicks}) * +$c) + $f_g);
  489. my $red = sprintf "%0.2x", abs int(((($t_r - $f_r) / $self->{cfg}->{activenicks}) * +$c) + $f_r);
  490. return "#$red$green$blue";
  491. }
  492. sub _html
  493. {
  494. my $html = shift;
  495. print OUTPUT "$html\n";
  496. }
  497. sub _questions
  498. {
  499. # Persons who asked the most questions
  500. my $self = shift;
  501. my %qpercent;
  502. foreach my $nick (sort keys %{ $self->{stats}->{questions} }) {
  503. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  504. if ($self->{stats}->{lines}{$nick} > 100) {
  505. $qpercent{$nick} = ($self->{stats}->{questions}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  506. $qpercent{$nick} =~ s/(\.\d)\d+/$1/;
  507. }
  508. }
  509. }
  510. my @question = sort { $qpercent{$b} <=> $qpercent{$a} } keys %qpercent;
  511. if (@question) {
  512. my %hash = (
  513. nick => $question[0],
  514. per => $qpercent{$question[0]}
  515. );
  516. my $text = $self->_template_text('question1', %hash);
  517. _html("<tr><td class=\"hicell\">$text");
  518. if (@question >= 2) {
  519. my %hash = (
  520. nick => $question[1],
  521. per => $qpercent{$question[1]}
  522. );
  523. my $text = $self->_template_text('question2', %hash);
  524. _html("<br /><span class=\"small\">$text</span>");
  525. }
  526. _html("</td></tr>");
  527. } else {
  528. _html("<tr><td class=\"hicell\">" . $self->_template_text('question3') . "</td></tr>");
  529. }
  530. }
  531. sub _shoutpeople
  532. {
  533. # The ones who speak with exclamation marks!
  534. my $self = shift;
  535. my %spercent;
  536. foreach my $nick (sort keys %{ $self->{stats}->{shouts} }) {
  537. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  538. if ($self->{stats}->{lines}{$nick} > 100) {
  539. $spercent{$nick} = ($self->{stats}->{shouts}{$nick} / $self->{stats}->{lines}{$nick}) * 100;
  540. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  541. }
  542. }
  543. }
  544. my @shout = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  545. if (@shout) {
  546. my %hash = (
  547. nick => $shout[0],
  548. per => $spercent{$shout[0]}
  549. );
  550. my $text = $self->_template_text('shout1', %hash);
  551. _html("<tr><td class=\"hicell\">$text");
  552. if (@shout >= 2) {
  553. my %hash = (
  554. nick => $shout[1],
  555. per => $spercent{$shout[1]}
  556. );
  557. my $text = $self->_template_text('shout2', %hash);
  558. _html("<br /><span class=\"small\">$text</span>");
  559. }
  560. _html("</td></tr>");
  561. } else {
  562. my $text = $self->_template_text('shout3');
  563. _html("<tr><td class=\"hicell\">$text</td></tr>");
  564. }
  565. }
  566. sub _capspeople
  567. {
  568. # The ones who speak ALL CAPS.
  569. my $self = shift;
  570. my %cpercent;
  571. foreach my $nick (sort keys %{ $self->{stats}->{allcaps} }) {
  572. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  573. if ($self->{stats}->{lines}{$nick} > 100) {
  574. $cpercent{$nick} = $self->{stats}->{allcaps}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  575. $cpercent{$nick} =~ s/(\.\d)\d+/$1/;
  576. }
  577. }
  578. }
  579. my @caps = sort { $cpercent{$b} <=> $cpercent{$a} } keys %cpercent;
  580. if (@caps) {
  581. my %hash = (
  582. nick => $caps[0],
  583. per => $cpercent{$caps[0]},
  584. line => $self->_format_line($self->{stats}->{allcaplines}{$caps[0]})
  585. );
  586. my $text = $self->_template_text('allcaps1', %hash);
  587. if($self->{cfg}->{showshoutline}) {
  588. my $exttext = $self->_template_text('allcapstext', %hash);
  589. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  590. } else {
  591. _html("<tr><td class=\"hicell\">$text");
  592. }
  593. if (@caps >= 2) {
  594. my %hash = (
  595. nick => $caps[1],
  596. per => $cpercent{$caps[1]}
  597. );
  598. my $text = $self->_template_text('allcaps2', %hash);
  599. _html("<br /><span class=\"small\">$text</span>");
  600. }
  601. _html("</td></tr>");
  602. } else {
  603. my $text = $self->_template_text('allcaps3');
  604. _html("<tr><td class=\"hicell\">$text</td></tr>");
  605. }
  606. }
  607. sub _violent
  608. {
  609. # They attacked others (words defined by $self->{cfg}->{violent})
  610. my $self = shift;
  611. my @aggressors = sort { $self->{stats}->{violence}{$b} <=> $self->{stats}->{violence}{$a} }
  612. keys %{ $self->{stats}->{violence} };
  613. @aggressors = $self->_istoponly(@aggressors);
  614. if(@aggressors) {
  615. my %hash = (
  616. nick => $aggressors[0],
  617. attacks => $self->{stats}->{violence}{$aggressors[0]},
  618. line => $self->_format_line($self->{stats}->{violencelines}{$aggressors[0]})
  619. );
  620. my $text = $self->_template_text('violent1', %hash);
  621. if($self->{cfg}->{showviolentlines}) {
  622. my $exttext = $self->_template_text('violenttext', %hash);
  623. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  624. } else {
  625. _html("<tr><td class=\"hicell\">$text");
  626. }
  627. if (@aggressors >= 2) {
  628. my %hash = (
  629. nick => $aggressors[1],
  630. attacks => $self->{stats}->{violence}{$aggressors[1]}
  631. );
  632. my $text = $self->_template_text('violent2', %hash);
  633. _html("<br /><span class=\"small\">$text</span>");
  634. }
  635. _html("</td></tr>");
  636. } else {
  637. my $text = $self->_template_text('violent3');
  638. _html("<tr><td class=\"hicell\">$text</td></tr>");
  639. }
  640. # They got attacked
  641. my @victims = sort { $self->{stats}->{attacked}{$b} <=> $self->{stats}->{attacked}{$a} }
  642. keys %{ $self->{stats}->{attacked} };
  643. @victims = $self->_istoponly(@victims);
  644. if(@victims) {
  645. my %hash = (
  646. nick => $victims[0],
  647. attacks => $self->{stats}->{attacked}{$victims[0]},
  648. line => $self->_format_line($self->{stats}->{attackedlines}{$victims[0]})
  649. );
  650. my $text = $self->_template_text('attacked1', %hash);
  651. if($self->{cfg}->{showviolentlines}) {
  652. my $exttext = $self->_template_text('attackedtext', %hash);
  653. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  654. } else {
  655. _html("<tr><td class=\"hicell\">$text");
  656. }
  657. if (@victims >= 2) {
  658. my %hash = (
  659. nick => $victims[1],
  660. attacks => $self->{stats}->{attacked}{$victims[1]}
  661. );
  662. my $text = $self->_template_text('attacked2', %hash);
  663. _html("<br /><span class=\"small\">$text</span>");
  664. }
  665. _html("</td></tr>");
  666. }
  667. }
  668. sub _gotkicks
  669. {
  670. # The persons who got kicked the most
  671. my $self = shift;
  672. my @gotkick = sort { $self->{stats}->{gotkicked}{$b} <=> $self->{stats}->{gotkicked}{$a} }
  673. keys %{ $self->{stats}->{gotkicked} };
  674. @gotkick = $self->_istoponly(@gotkick);
  675. if (@gotkick) {
  676. my %hash = (
  677. nick => $gotkick[0],
  678. kicks => $self->{stats}->{gotkicked}{$gotkick[0]},
  679. line => $self->_format_line($self->{stats}->{kicklines}{$gotkick[0]})
  680. );
  681. my $text = $self->_template_text('gotkick1', %hash);
  682. if ($self->{cfg}->{showkickline}) {
  683. my $exttext = $self->_template_text('kicktext', %hash);
  684. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  685. } else {
  686. _html("<tr><td class=\"hicell\">$text");
  687. }
  688. if (@gotkick >= 2) {
  689. my %hash = (
  690. nick => $gotkick[1],
  691. kicks => $self->{stats}->{gotkicked}{$gotkick[1]}
  692. );
  693. my $text = $self->_template_text('gotkick2', %hash);
  694. _html("<br /><span class=\"small\">$text</span>");
  695. }
  696. _html("</td></tr>");
  697. }
  698. }
  699. sub _mostjoins
  700. {
  701. my $self = shift;
  702. my @joins = sort { $self->{stats}->{joins}{$b} <=> $self->{stats}->{joins}{$a} }
  703. keys %{ $self->{stats}->{joins} };
  704. @joins = $self->_istoponly(@joins);
  705. if (@joins) {
  706. my %hash = (
  707. nick => $joins[0],
  708. joins => $self->{stats}->{joins}{$joins[0]}
  709. );
  710. my $text = $self->_template_text('joins', %hash);
  711. _html("<tr><td class=\"hicell\">$text</td></tr>");
  712. }
  713. }
  714. sub _mostwords
  715. {
  716. # The person who got words the most
  717. my $self = shift;
  718. my @words = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  719. keys %{ $self->{stats}->{words} };
  720. @words = $self->_istoponly(@words);
  721. if (@words) {
  722. my %hash = (
  723. nick => $words[0],
  724. words => $self->{stats}->{words}{$words[0]}
  725. );
  726. my $text = $self->_template_text('words1', %hash);
  727. _html("<tr><td class=\"hicell\">$text");
  728. if (@words >= 2) {
  729. my %hash = (
  730. oldnick => $words[0],
  731. nick => $words[1],
  732. words => $self->{stats}->{words}{$words[1]}
  733. );
  734. my $text = $self->_template_text('words2', %hash);
  735. _html("<br /><span class=\"small\">$text</span>");
  736. }
  737. _html("</td></tr>");
  738. } else {
  739. my $text = $self->_template_text('kick3');
  740. _html("<tr><td class=\"hicell\">$text</td></tr>");
  741. }
  742. }
  743. sub _mostkicks
  744. {
  745. # The person who kicked the most
  746. my $self = shift;
  747. my @kicked = sort { $self->{stats}->{kicked}{$b} <=> $self->{stats}->{kicked}{$a} }
  748. keys %{ $self->{stats}->{kicked} };
  749. @kicked = $self->_istoponly(@kicked);
  750. if (@kicked) {
  751. my %hash = (
  752. nick => $kicked[0],
  753. kicked => $self->{stats}->{kicked}{$kicked[0]}
  754. );
  755. my $text = $self->_template_text('kick1', %hash);
  756. _html("<tr><td class=\"hicell\">$text");
  757. if (@kicked >= 2) {
  758. my %hash = (
  759. oldnick => $kicked[0],
  760. nick => $kicked[1],
  761. kicked => $self->{stats}->{kicked}{$kicked[1]}
  762. );
  763. my $text = $self->_template_text('kick2', %hash);
  764. _html("<br /><span class=\"small\">$text</span>");
  765. }
  766. _html("</td></tr>");
  767. } else {
  768. my $text = $self->_template_text('kick3');
  769. _html("<tr><td class=\"hicell\">$text</td></tr>");
  770. }
  771. }
  772. sub _mostmonologues
  773. {
  774. # The person who had the most monologues (speaking to himself)
  775. my $self = shift;
  776. my @monologue = sort { $self->{stats}->{monologues}{$b} <=> $self->{stats}->{monologues}{$a} }
  777. keys %{ $self->{stats}->{monologues} };
  778. @monologue = $self->_istoponly(@monologue);
  779. if (@monologue) {
  780. my %hash = (
  781. nick => $monologue[0],
  782. monos => $self->{stats}->{monologues}{$monologue[0]}
  783. );
  784. my $text = $self->_template_text('mono1', %hash);
  785. _html("<tr><td class=\"hicell\">$text");
  786. if (@monologue >= 2) {
  787. my %hash = (
  788. nick => $monologue[1],
  789. monos => $self->{stats}->{monologues}{$monologue[1]}
  790. );
  791. my $text = $self->_template_text('mono2', %hash);
  792. _html("<br /><span class=\"small\">$text</span>");
  793. }
  794. _html("</td></tr>");
  795. }
  796. }
  797. sub _linelengths
  798. {
  799. # The person(s) who wrote the longest lines
  800. my $self = shift;
  801. my %len;
  802. foreach my $nick (sort keys %{ $self->{stats}->{lengths} }) {
  803. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  804. if ($self->{stats}->{lines}{$nick} > 100) {
  805. $len{$nick} = $self->{stats}->{lengths}{$nick} / $self->{stats}->{lines}{$nick};
  806. $len{$nick} =~ s/(\.\d)\d+/$1/;
  807. }
  808. }
  809. }
  810. my @len = sort { $len{$b} <=> $len{$a} } keys %len;
  811. my $all_lines = 0;
  812. my $totallength;
  813. foreach my $nick (keys %{ $self->{stats}->{lines} }) {
  814. $all_lines += $self->{stats}->{lines}{$nick};
  815. $totallength += $self->{stats}->{lengths}{$nick};
  816. }
  817. my $totalaverage;
  818. if ($all_lines > 0) {
  819. $totalaverage = $totallength / $all_lines;
  820. $totalaverage =~ s/(\.\d)\d+/$1/;
  821. }
  822. if (@len) {
  823. my %hash = (
  824. nick => $len[0],
  825. letters => $len{$len[0]}
  826. );
  827. my $text = $self->_template_text('long1', %hash);
  828. _html("<tr><td class=\"hicell\">$text<br />");
  829. if (@len >= 2) {
  830. %hash = (
  831. avg => $totalaverage
  832. );
  833. $text = $self->_template_text('long2', %hash);
  834. _html("<span class=\"small\">$text</span></td></tr>");
  835. } else {
  836. _html("</td></tr>");
  837. }
  838. }
  839. # The person(s) who wrote the shortest lines
  840. if (@len) {
  841. my %hash = (
  842. nick => $len[$#len],
  843. letters => $len{$len[$#len]}
  844. );
  845. my $text = $self->_template_text('short1', %hash);
  846. _html("<tr><td class=\"hicell\">$text<br />");
  847. if (@len >= 2) {
  848. %hash = (
  849. nick => $len[$#len - 1],
  850. letters => $len{$len[$#len - 1]}
  851. );
  852. $text = $self->_template_text('short2', %hash);
  853. _html("<span class=\"small\">$text</span></td></tr>");
  854. } else {
  855. _html("</td></tr>");
  856. }
  857. }
  858. }
  859. sub _mostfoul
  860. {
  861. my $self = shift;
  862. my %spercent;
  863. foreach my $nick (sort keys %{ $self->{stats}->{foul} }) {
  864. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  865. if ($self->{stats}->{lines}{$nick} > 15) {
  866. $spercent{$nick} = $self->{stats}->{foul}{$nick} / $self->{stats}->{words}{$nick} * 100;
  867. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  868. }
  869. }
  870. }
  871. my @foul = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  872. if (@foul) {
  873. my %hash = (
  874. nick => $foul[0],
  875. per => $spercent{$foul[0]},
  876. line => $self->_format_line($self->{stats}{foullines}{$foul[0]}),
  877. );
  878. my $text = $self->_template_text('foul1', %hash);
  879. if($self->{cfg}->{showfoulline}) {
  880. my $exttext = $self->_template_text('foultext', %hash);
  881. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  882. } else {
  883. _html("<tr><td class=\"hicell\">$text");
  884. }
  885. if (@foul >= 2) {
  886. my %hash = (
  887. nick => $foul[1],
  888. per => $spercent{$foul[1]}
  889. );
  890. my $text = $self->_template_text('foul2', %hash);
  891. _html("<br /><span class=\"small\">$text</span>");
  892. }
  893. _html("</td></tr>");
  894. } else {
  895. my $text = $self->_template_text('foul3');
  896. _html("<tr><td class=\"hicell\">$text</td></tr>");
  897. }
  898. }
  899. sub _mostsad
  900. {
  901. my $self = shift;
  902. my %spercent;
  903. foreach my $nick (sort keys %{ $self->{stats}->{frowns} }) {
  904. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  905. if ($self->{stats}->{lines}{$nick} > 100) {
  906. $spercent{$nick} = $self->{stats}->{frowns}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  907. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  908. }
  909. }
  910. }
  911. my @sadface = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  912. if (@sadface) {
  913. my %hash = (
  914. nick => $sadface[0],
  915. per => $spercent{$sadface[0]}
  916. );
  917. my $text = $self->_template_text('sad1', %hash);
  918. _html("<tr><td class=\"hicell\">$text");
  919. if (@sadface >= 2) {
  920. my %hash = (
  921. nick => $sadface[1],
  922. per => $spercent{$sadface[1]}
  923. );
  924. my $text = $self->_template_text('sad2', %hash);
  925. _html("<br /><span class=\"small\">$text</span>");
  926. }
  927. _html("</td></tr>");
  928. } else {
  929. my $text = $self->_template_text('sad3');
  930. _html("<tr><td class=\"hicell\">$text</td></tr>");
  931. }
  932. }
  933. sub _mostop
  934. {
  935. my $self = shift;
  936. my @ops = sort { $self->{stats}->{gaveops}{$b} <=> $self->{stats}->{gaveops}{$a} }
  937. keys %{ $self->{stats}->{gaveops} };
  938. @ops = $self->_istoponly(@ops);
  939. my @deops = sort { $self->{stats}->{tookops}{$b} <=> $self->{stats}->{tookops}{$a} }
  940. keys %{ $self->{stats}->{tookops} };
  941. @deops = $self->_istoponly(@deops);
  942. if (@ops) {
  943. my %hash = (
  944. nick => $ops[0],
  945. ops => $self->{stats}->{gaveops}{$ops[0]}
  946. );
  947. my $text = $self->_template_text('mostop1', %hash);
  948. _html("<tr><td class=\"hicell\">$text");
  949. if (@ops >= 2) {
  950. my %hash = (
  951. nick => $ops[1],
  952. ops => $self->{stats}->{gaveops}{$ops[1]}
  953. );
  954. my $text = $self->_template_text('mostop2', %hash);
  955. _html("<br /><span class=\"small\">$text</span>");
  956. }
  957. _html("</td></tr>");
  958. } else {
  959. my $text = $self->_template_text('mostop3');
  960. _html("<tr><td class=\"hicell\">$text</td></tr>");
  961. }
  962. if (@deops) {
  963. my %hash = (
  964. nick => $deops[0],
  965. deops => $self->{stats}->{tookops}{$deops[0]}
  966. );
  967. my $text = $self->_template_text('mostdeop1', %hash);
  968. _html("<tr><td class=\"hicell\">$text");
  969. if (@deops >= 2) {
  970. my %hash = (
  971. nick => $deops[1],
  972. deops => $self->{stats}->{tookops}{$deops[1]}
  973. );
  974. my $text = $self->_template_text('mostdeop2', %hash);
  975. _html("<br /><span class=\"small\">$text</span>");
  976. }
  977. _html("</td></tr>");
  978. } else {
  979. my $text = $self->_template_text('mostdeop3');
  980. _html("<tr><td class=\"hicell\">$text</td></tr>");
  981. }
  982. }
  983. sub _mostvoice
  984. {
  985. my $self = shift;
  986. my @voice = sort { $self->{stats}->{gavevoice}{$b} <=> $self->{stats}->{gavevoice}{$a} }
  987. keys %{ $self->{stats}->{gavevoice} };
  988. @voice = $self->_istoponly(@voice);
  989. my @devoice = sort { $self->{stats}->{tookvoice}{$b} <=> $self->{stats}->{tookvoice}{$a} }
  990. keys %{ $self->{stats}->{tookvoice} };
  991. @devoice = $self->_istoponly(@devoice);
  992. if (@voice) {
  993. my %hash = (
  994. nick => $voice[0],
  995. voices => $self->{stats}->{gavevoice}{$voice[0]}
  996. );
  997. my $text = $self->_template_text('mostvoice1', %hash);
  998. _html("<tr><td class=\"hicell\">$text");
  999. if (@voice >= 2) {
  1000. my %hash = (
  1001. nick => $voice[1],
  1002. voices => $self->{stats}->{gavevoice}{$voice[1]}
  1003. );
  1004. my $text = $self->_template_text('mostvoice2', %hash);
  1005. _html("<br /><span class=\"small\">$text</span>");
  1006. }
  1007. _html("</td></tr>");
  1008. } else {
  1009. my $text = $self->_template_text('mostvoice3');
  1010. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1011. }
  1012. if (@devoice) {
  1013. my %hash = (
  1014. nick => $devoice[0],
  1015. devoices => $self->{stats}->{tookvoice}{$devoice[0]}
  1016. );
  1017. my $text = $self->_template_text('mostdevoice1', %hash);
  1018. _html("<tr><td class=\"hicell\">$text");
  1019. if (@devoice >= 2) {
  1020. my %hash = (
  1021. nick => $devoice[1],
  1022. devoices => $self->{stats}->{tookvoice}{$devoice[1]}
  1023. );
  1024. my $text = $self->_template_text('mostdevoice2', %hash);
  1025. _html("<br /><span class=\"small\">$text</span>");
  1026. }
  1027. _html("</td></tr>");
  1028. } else {
  1029. my $text = $self->_template_text('mostdevoice3');
  1030. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1031. }
  1032. }
  1033. sub _mosthalfop
  1034. {
  1035. my $self = shift;
  1036. my @halfops = sort { $self->{stats}->{gavehalfops}{$b} <=> $self->{stats}->{gavehalfops}{$a} }
  1037. keys %{ $self->{stats}->{gavehalfops} };
  1038. @halfops = $self->_istoponly(@halfops);
  1039. my @dehalfops = sort { $self->{stats}->{tookhalfops}{$b} <=> $self->{stats}->{tookhalfops}{$a} }
  1040. keys %{ $self->{stats}->{tookhalfops} };
  1041. @dehalfops = $self->_istoponly(@dehalfops);
  1042. if (@halfops) {
  1043. my %hash = (
  1044. nick => $halfops[0],
  1045. halfops => $self->{stats}->{gavehalfops}{$halfops[0]}
  1046. );
  1047. my $text = $self->_template_text('mosthalfop1', %hash);
  1048. _html("<tr><td class=\"hicell\">$text");
  1049. if (@halfops >= 2) {
  1050. my %hash = (
  1051. nick => $halfops[1],
  1052. halfops => $self->{stats}->{gavehalfops}{$halfops[1]}
  1053. );
  1054. my $text = $self->_template_text('mosthalfop2', %hash);
  1055. _html("<br /><span class=\"small\">$text</span>");
  1056. }
  1057. _html("</td></tr>");
  1058. } else {
  1059. my $text = $self->_template_text('mosthalfop3');
  1060. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1061. }
  1062. if (@dehalfops) {
  1063. my %hash = (
  1064. nick => $dehalfops[0],
  1065. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[0]}
  1066. );
  1067. my $text = $self->_template_text('mostdehalfop1', %hash);
  1068. _html("<tr><td class=\"hicell\">$text");
  1069. if (@dehalfops >= 2) {
  1070. my %hash = (
  1071. nick => $dehalfops[1],
  1072. dehalfops => $self->{stats}->{tookhalfops}{$dehalfops[1]}
  1073. );
  1074. my $text = $self->_template_text('mostdehalfop2', %hash);
  1075. _html("<br /><span class=\"small\">$text</span>");
  1076. }
  1077. _html("</td></tr>");
  1078. } else {
  1079. my $text = $self->_template_text('mostdehalfop3');
  1080. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1081. }
  1082. }
  1083. sub _mostactions
  1084. {
  1085. # The person who did the most /me's
  1086. my $self = shift;
  1087. my @actions = sort { $self->{stats}->{actions}{$b} <=> $self->{stats}->{actions}{$a} }
  1088. keys %{ $self->{stats}->{actions} };
  1089. @actions = $self->_istoponly(@actions);
  1090. if (@actions) {
  1091. my %linehash =
  1092. my %hash = (
  1093. nick => $actions[0],
  1094. actions => $self->{stats}->{actions}{$actions[0]},
  1095. line => $self->_format_line($self->{stats}->{actionlines}{$actions[0]})
  1096. );
  1097. my $text = $self->_template_text('action1', %hash);
  1098. if($self->{cfg}->{showactionline}) {
  1099. my $exttext = $self->_template_text('actiontext', %hash);
  1100. _html("<tr><td class=\"hicell\">$text<br /><span class=\"small\">$exttext</span><br />");
  1101. } else {
  1102. _html("<tr><td class=\"hicell\">$text");
  1103. }
  1104. if (@actions >= 2) {
  1105. my %hash = (
  1106. nick => $actions[1],
  1107. actions => $self->{stats}->{actions}{$actions[1]}
  1108. );
  1109. my $text = $self->_template_text('action2', %hash);
  1110. _html("<br /><span class=\"small\">$text</span>");
  1111. }
  1112. _html("</td></tr>");
  1113. } else {
  1114. my $text = $self->_template_text('action3');
  1115. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1116. }
  1117. }
  1118. sub _mostsmiles
  1119. {
  1120. # The person(s) who smiled the most :-)
  1121. my $self = shift;
  1122. my %spercent;
  1123. foreach my $nick (sort keys %{ $self->{stats}->{smiles} }) {
  1124. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1125. if ($self->{stats}->{lines}{$nick} > 100) {
  1126. $spercent{$nick} = $self->{stats}->{smiles}{$nick} / $self->{stats}->{lines}{$nick} * 100;
  1127. $spercent{$nick} =~ s/(\.\d)\d+/$1/;
  1128. }
  1129. }
  1130. }
  1131. my @smiles = sort { $spercent{$b} <=> $spercent{$a} } keys %spercent;
  1132. if (@smiles) {
  1133. my %hash = (
  1134. nick => $smiles[0],
  1135. per => $spercent{$smiles[0]}
  1136. );
  1137. my $text = $self->_template_text('smiles1', %hash);
  1138. _html("<tr><td class=\"hicell\">$text");
  1139. if (@smiles >= 2) {
  1140. my %hash = (
  1141. nick => $smiles[1],
  1142. per => $spercent{$smiles[1]}
  1143. );
  1144. my $text = $self->_template_text('smiles2', %hash);
  1145. _html("<br /><span class=\"small\">$text</span>");
  1146. }
  1147. _html("</td></tr>");
  1148. } else {
  1149. my $text = $self->_template_text('smiles3');
  1150. _html("<tr><td class=\"hicell\">$text</td></tr>");
  1151. }
  1152. }
  1153. sub _lasttopics
  1154. {
  1155. my $self = shift;
  1156. if ($self->{stats}->{topics}) {
  1157. my %topic_seen;
  1158. my %hash = (
  1159. total => scalar @{ $self->{stats}->{topics} }
  1160. );
  1161. my $ltopic = $#{ $self->{stats}->{topics} };
  1162. my $tlimit = 0;
  1163. $self->{cfg}->{topichistory} -= 1;
  1164. if ($ltopic > $self->{cfg}->{topichistory}) {
  1165. $tlimit = $ltopic - $self->{cfg}->{topichistory};
  1166. }
  1167. for (my $i = $ltopic; $i >= $tlimit; $i--) {
  1168. my $topic = $self->{stats}->{topics}[$i]{topic};
  1169. # This code makes sure that we don't see the same topic twice
  1170. next if ($topic_seen{$topic});
  1171. $topic_seen{$topic} = 1;
  1172. # Strip off the quotes (')
  1173. $topic =~ s/^\'(.*)\'$/$1/;
  1174. my $nick = $self->{stats}->{topics}[$i]{nick};
  1175. my $hour = $self->{stats}->{topics}[$i]{hour};
  1176. my $min = $self->{stats}->{topics}[$i]{min};
  1177. $hash{nick} = $self->_format_word($nick);
  1178. $hash{time} = "$hour:$min";
  1179. _html('<tr><td class="hicell"><i>' . $self->_format_line($topic) . '</i></td>');
  1180. _html('<td class="hicell"><b>' . $self->_template_text('bylinetopic', %hash) . '</b></td></tr>');
  1181. }
  1182. _html("<tr><td align=\"center\" colspan=\"2\" class=\"asmall\">" . $self->_template_text('totaltopic', %hash) . "</td></tr>");
  1183. } else {
  1184. _html("<tr><td class=\"hicell\">" . $self->_template_text('notopic') ."</td></tr>");
  1185. }
  1186. }
  1187. sub _template_text
  1188. {
  1189. # This function is for the homemade template system. It receives a name
  1190. # of a template and a hash with the fields in the template to update to
  1191. # its corresponding value
  1192. my $self = shift;
  1193. my $template = shift;
  1194. my %hash = @_;
  1195. my $text;
  1196. unless ($text = $self->{tmps}->{lc($self->{cfg}->{lang})}{$template}) {
  1197. # Fall back to English if the language template doesn't exist
  1198. if ($text = $self->{tmps}->{en}{$template}) {
  1199. print "Note: No translation in '$self->{cfg}->{lang}' for '$template' - falling back to English..\n"
  1200. unless ($self->{cfg}->{silent});
  1201. } else {
  1202. die("No such template '$template' in language file.\n");
  1203. }
  1204. }
  1205. $hash{channel} = $self->{cfg}->{channel};
  1206. foreach my $key (sort keys %hash) {
  1207. $text =~ s/\[:$key\]/$hash{$key}/;
  1208. if ($self->{cfg}->{charset} =~ /iso-8859-1/i) {
  1209. $text =~ s/ü/&uuml;/go;
  1210. $text =~ s/ö/&ouml;/go;
  1211. $text =~ s/ä/&auml;/go;
  1212. $text =~ s/ß/&szlig;/go;
  1213. $text =~ s/å/&aring;/go;
  1214. $text =~ s/æ/&aelig;/go;
  1215. $text =~ s/ø/&oslash;/go;
  1216. $text =~ s/Å/&Aring;/go;
  1217. $text =~ s/Æ/&AElig;/go;
  1218. $text =~ s/Ø/&Oslash;/go;
  1219. }
  1220. }
  1221. if ($text =~ /\[:[^:]*?:[^:]*?:[^:]*?:\]/o) {
  1222. $text =~ s/\[:([^:]*?):([^:]*?):([^:]*?):\]/$self->_get_subst($1,$2,$3,\%hash)/geo;
  1223. }
  1224. if ($text =~ /\[:[^:]*?:[^:]*?:]/o) {
  1225. $text =~ s/\[:([^:]*?):([^:]*?):]/$self->_get_subst($1,$2,undef,\%hash)/geo;
  1226. }
  1227. return $text;
  1228. }
  1229. sub _format_word
  1230. {
  1231. # This function formats a word -- should ONLY be called on words used alone (EG: not whole line printed)
  1232. my ($self, $word) = @_;
  1233. $word = htmlentities($word, $self->{cfg}->{charset});
  1234. $word = $self->_replace_links($word);
  1235. return $word;
  1236. }
  1237. sub _format_line
  1238. {
  1239. # This function formats a action/normal line to be more readable, and calls any other function
  1240. # that should be executed on every line.
  1241. my ($self, $line) = @_;
  1242. my $hashref;
  1243. if ($hashref = $self->{cfg}->{analyzer}->{parser}->normalline($line)) {
  1244. $line = '<' . $hashref->{nick} . '> ' . $hashref->{saying};
  1245. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->actionline($line)) {
  1246. $line = '* ' . $hashref->{nick} . ' ' . $hashref->{saying};
  1247. } elsif ($hashref = $self->{cfg}->{analyzer}->{parser}->thirdline($line)) {
  1248. if (defined($hashref->{kicker})) {
  1249. $line = '*** ' . $hashref->{nick} . ' was kicked by ' . $hashref->{kicker};
  1250. $line .= ' (' . $hashref->{kicktext} . ')'
  1251. if (defined($hashref->{kicktext}));
  1252. } elsif (defined($hashref->{newtopic})) {
  1253. $line = '*** ' . $hashref->{nick} . ' changes topic to \'' . $hashref->{newtopic} . '\'';
  1254. } elsif (defined($hashref->{newmode})) {
  1255. $line = '*** ' . $hashref->{nick} . ' sets mode ' . $hashref->{newmode};
  1256. $line .= ' ' . $hashref->{modechanges}
  1257. if (defined($hashref->{kicktext}));
  1258. } elsif (defined($hashref->{newjoin})) {
  1259. $line = '*** Joins: ' . $hashref->{nick};
  1260. } elsif (defined($hashref->{newnick})) {
  1261. $line = '*** ' . $hashref->{nick} . ' is now known as ' . $hashref->{newnick};
  1262. } elsif (defined($hashref->{newtopic})) {
  1263. $line = '*** ' . $hashref->{nick} . ' changes topic to: ' . $hashref->{newtopic};
  1264. }
  1265. }
  1266. $line = htmlentities($line, $self->{cfg}->{charset});
  1267. $line = $self->_replace_links($line);
  1268. return $line;
  1269. }
  1270. sub _get_subst
  1271. {
  1272. # This function looks at the user definition and see if there is sex
  1273. # defined. If yes, return the appropriate value. If no, just return the
  1274. # default he/she value.
  1275. my $self = shift;
  1276. my ($m,$f,$d,$hash) = @_;
  1277. if ($hash->{nick} && $self->{users}->{sex}{$hash->{nick}}) {
  1278. if ($self->{users}->{sex}{$hash->{nick}} eq 'm') {
  1279. return $m;
  1280. } elsif ($self->{users}->{sex}{$hash->{nick}} eq 'f') {
  1281. return $f;
  1282. }
  1283. }
  1284. return defined($d) ? $d : "$m/$f";
  1285. }
  1286. sub _mostusedword
  1287. {
  1288. # Word usage statistics
  1289. my $self = shift;
  1290. my %usages;
  1291. foreach my $word (keys %{ $self->{stats}->{wordcounts} }) {
  1292. # Skip people's nicks.
  1293. next if is_nick($word);
  1294. next if (length($word) < $self->{cfg}->{wordlength});
  1295. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1296. }
  1297. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1298. if (@popular) {
  1299. $self->_headline($self->_template_text('mostwordstopic'));
  1300. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1301. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('word') . "</b></td>");
  1302. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1303. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1304. my $count = 0;
  1305. for(my $i = 0; $count < $self->{cfg}->{wordhistory}; $i++) {
  1306. last unless $i < $#popular;
  1307. # Skip nicks. It's far more efficient to do this here than when
  1308. # @popular is created.
  1309. next if is_ignored($popular[$i]);
  1310. my $a = $count + 1;
  1311. my $popular = $self->_format_word($popular[$i]);
  1312. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1313. my $lastused = $self->_format_word($self->{stats}->{wordnicks}{$popular[$i]});
  1314. my $class;
  1315. if ($a == 1) {
  1316. $class = 'hirankc';
  1317. } else {
  1318. $class = 'rankc';
  1319. }
  1320. _html("<tr><td class=\"$class\">$a</td>");
  1321. _html("<td class=\"hicell\">$popular</td>");
  1322. _html("<td class=\"hicell\">$wordcount</td>");
  1323. _html("<td class=\"hicell\">$lastused</td>");
  1324. _html("</tr>");
  1325. $count++;
  1326. }
  1327. _html("</table>");
  1328. }
  1329. }
  1330. sub _mostwordsperline
  1331. {
  1332. # The person who got the most words per line
  1333. my $self = shift;
  1334. my %wpl = ();
  1335. my $numlines = 0;
  1336. my ($avg, $numwords);
  1337. foreach my $nick (keys %{ $self->{stats}->{words} }) {
  1338. if ($self->{topactive}{$nick} || !$self->{cfg}->{showonlytop}) {
  1339. $wpl{$nick} = sprintf("%.2f", $self->{stats}->{words}{$nick}/$self->{stats}->{lines}{$nick});
  1340. $numlines += $self->{stats}->{lines}{$nick};
  1341. $numwords += $self->{stats}->{words}{$nick};
  1342. }
  1343. }
  1344. if ($numlines > 0) {
  1345. $avg = sprintf("%.2f", $numwords/$numlines);
  1346. }
  1347. my @wpl = sort { $wpl{$b} <=> $wpl{$a} } keys %wpl;
  1348. if (@wpl) {
  1349. my %hash = (
  1350. nick => $wpl[0],
  1351. wpl => $wpl{$wpl[0]}
  1352. );
  1353. my $text = $self->_template_text('wpl1', %hash);
  1354. _html("<tr><td class=\"hicell\">$text");
  1355. $hash{avg} = $avg;
  1356. $text = $self->_template_text('wpl2', %hash);
  1357. _html("<br /><span class=\"small\">$text</span>");
  1358. _html("</td></tr>");
  1359. }
  1360. }
  1361. sub _mostreferencednicks
  1362. {
  1363. # List showing the most referenced nicks
  1364. my $self = shift;
  1365. my %usages;
  1366. foreach my $word (sort keys %{ $self->{stats}->{wordcounts} }) {
  1367. next if !exists $self->{stats}->{lines}{$word};
  1368. next if is_ignored($word);
  1369. $usages{$word} = $self->{stats}->{wordcounts}{$word};
  1370. }
  1371. my @popular = sort { $usages{$b} <=> $usages{$a} } keys %usages;
  1372. if (@popular) {
  1373. $self->_headline($self->_template_text('referencetopic'));
  1374. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1375. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('nick') . "</b></td>");
  1376. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1377. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1378. for(my $i = 0; $i < $self->{cfg}->{nickhistory}; $i++) {
  1379. last unless $i < $#popular;
  1380. my $a = $i + 1;
  1381. my $popular = $popular[$i];
  1382. my $wordcount = $self->{stats}->{wordcounts}{$popular[$i]};
  1383. my $lastused = $self->{stats}->{wordnicks}{$popular[$i]};
  1384. my $class;
  1385. if ($a == 1) {
  1386. $class = 'hirankc';
  1387. } else {
  1388. $class = 'rankc';
  1389. }
  1390. _html("<tr><td class=\"$class\">$a</td>");
  1391. _html("<td class=\"hicell\">$popular</td>");
  1392. _html("<td class=\"hicell\">$wordcount</td>");
  1393. _html("<td class=\"hicell\">$lastused</td>");
  1394. _html("</tr>");
  1395. }
  1396. _html("</table>");
  1397. }
  1398. }
  1399. sub _mosturls
  1400. {
  1401. # List showing the most referenced URLs
  1402. my $self = shift;
  1403. my @sorturls = sort { $self->{stats}->{urlcounts}{$b} <=> $self->{stats}->{urlcounts}{$a} }
  1404. keys %{ $self->{stats}->{urlcounts} };
  1405. if (@sorturls) {
  1406. $self->_headline($self->_template_text('urlstopic'));
  1407. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1408. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>" . $self->_template_text('url') . "</b></td>");
  1409. _html("<td class=\"tdtop\"><b>" . $self->_template_text('numberuses') . "</b></td>");
  1410. _html("<td class=\"tdtop\"><b>" . $self->_template_text('lastused') . "</b></td></tr>");
  1411. for(my $i = 0; $i < $self->{cfg}->{urlhistory}; $i++) {
  1412. last unless $i < @sorturls;
  1413. my $a = $i + 1;
  1414. my $sorturl = $sorturls[$i];
  1415. my $urlcount = $self->{stats}->{urlcounts}{$sorturls[$i]};
  1416. my $lastused = $self->{stats}->{urlnicks}{$sorturls[$i]};
  1417. if (length($sorturl) > 60) {
  1418. $sorturl = substr($sorturl, 0, 60);
  1419. }
  1420. my $class;
  1421. if ($a == 1) {
  1422. $class = 'hirankc';
  1423. } else {
  1424. $class = 'rankc';
  1425. }
  1426. _html("<tr><td class=\"$class\">$a</td>");
  1427. _html("<td class=\"hicell\"><a href=\"$sorturls[$i]\">$sorturl</a></td>");
  1428. _html("<td class=\"hicell\">$urlcount</td>");
  1429. _html("<td class=\"hicell\">$lastused</td>");
  1430. _html("</tr>");
  1431. }
  1432. _html("</table>");
  1433. }
  1434. }
  1435. sub _legend
  1436. {
  1437. # A legend showing the timebars and their associated time.
  1438. my $self = shift;
  1439. _html("<table align=\"center\" border=\"0\" width=\"520\"><tr>");
  1440. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_0}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"0-5\" /> = 0-5</td>");
  1441. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_6}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"6-11\" /> = 6-11</td>");
  1442. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_12}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"12-17\" /> = 12-17</td>");
  1443. _html("<td align=\"center\" class=\"asmall\"><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{pic_h_18}\" width=\"40\" height=\"15\" align=\"middle\" alt=\"18-23\" /> = 18-23</td>");
  1444. _html("</tr></table>\n");
  1445. }
  1446. sub _replace_links
  1447. {
  1448. # Sub to replace urls and e-mail addys to links
  1449. my ($self, $str, $nick) = @_;
  1450. # Regular expressions are taken from match_urls() and match_email() in
  1451. # Common.pm
  1452. my $texturl = $self->_template_text("newwindow");
  1453. my $textmail = $self->_template_text("mailto");
  1454. my (@str) = split(/ /,$str);
  1455. foreach (@str) {
  1456. if (m/(http|https|ftp|telnet|news)(:\/\/[-a-zA-Z0-9_\/~:@]+\.[-a-zA-Z0-9.,_~=:&amp;@%?#\/+]+)/o) {
  1457. my $nick = $nick || $1 . $2;
  1458. $_ = "<a href=\"$1$2\" target=\"_blank\" title=\"$texturl $1$2\">" . $self->_split_long_text($nick) . '</a>';
  1459. } elsif (m/(^|[^:])\b([-a-zA-Z0-9._]+@[-a-zA-Z0-9_]+\.[-a-zA-Z0-9._]+)/o) {
  1460. my $nick = $nick || $1 . $2;
  1461. $_ = "$1<a href=\"mailto:$2\" title=\"$textmail $nick\">" . $self->_split_long_text($nick) . "<\/a>";
  1462. } else {
  1463. $_ = $self->_split_long_text($_);
  1464. }
  1465. }
  1466. return join(' ', @str);
  1467. }
  1468. sub _split_long_text
  1469. {
  1470. my ($self, $str) = @_;
  1471. $str =~ s/(\S{$self->{cfg}->{quotewidth}})(?!\s)/$1-<br \/>/og;
  1472. return($str);
  1473. }
  1474. sub _user_linetimes
  1475. {
  1476. my $self = shift;
  1477. my $nick = shift;
  1478. my $top = shift;
  1479. my $bar = "";
  1480. my $len = ($self->{stats}->{lines}{$nick} / $self->{stats}->{lines}{$top}) * 100;
  1481. for (my $i = 0; $i <= 3; $i++) {
  1482. next if not defined $self->{stats}->{line_times}{$nick}[$i];
  1483. my $w = int(($self->{stats}->{line_times}{$nick}[$i] / $self->{stats}->{lines}{$nick}) * $len);
  1484. if ($w) {
  1485. my $pic = 'pic_h_'.(6*$i);
  1486. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1487. }
  1488. }
  1489. return "$bar&nbsp;$self->{stats}->{lines}{$nick}";
  1490. }
  1491. sub _user_wordtimes
  1492. {
  1493. my $self = shift;
  1494. my $nick = shift;
  1495. my $top = shift;
  1496. my $bar = "";
  1497. my $len = ($self->{stats}->{words}{$nick} / $self->{stats}->{words}{$top}) * 100;
  1498. for (my $i = 0; $i <= 3; $i++) {
  1499. next if not defined $self->{stats}->{word_times}{$nick}[$i];
  1500. my $w = int(($self->{stats}->{word_times}{$nick}[$i] / $self->{stats}->{words}{$nick}) * $len);
  1501. if ($w) {
  1502. my $pic = 'pic_h_'.(6*$i);
  1503. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />";
  1504. }
  1505. }
  1506. return "$bar&nbsp;$self->{stats}->{words}{$nick}";
  1507. }
  1508. sub _user_times
  1509. {
  1510. my $self = shift;
  1511. my ($nick) = @_;
  1512. my $bar = "";
  1513. my $itemstat = ($self->{cfg}->{sortbywords} ? 'words' : 'lines');
  1514. my $timestat = ($self->{cfg}->{sortbywords} ? 'word_times' : 'line_times');
  1515. for (my $i = 0; $i <= 3; $i++) {
  1516. next if not defined $self->{stats}->{$timestat}{$nick}[$i];
  1517. my $w = int(($self->{stats}->{$timestat}{$nick}[$i] / $self->{stats}->{$itemstat}{$nick}) * 40);
  1518. if ($w) {
  1519. my $pic = 'pic_h_'.(6*$i);
  1520. $bar .= "<img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" alt=\"\" />";
  1521. }
  1522. }
  1523. return $bar;
  1524. }
  1525. sub _mostnicks
  1526. {
  1527. # List showing the user with most used nicks
  1528. my $self = shift;
  1529. my @sortnicks = sort { keys %{ $self->{stats}->{nicks}->{$b} } <=> keys %{ $self->{stats}->{nicks}->{$a} } }
  1530. keys %{ $self->{stats}->{nicks} };
  1531. if (keys %{ $self->{stats}->{nicks}->{$sortnicks[0]} } > 1) {
  1532. $self->_headline($self->_template_text('mostnickstopic'));
  1533. my $names1 = $self->_template_text('names1');
  1534. my $names2 = $self->_template_text('names2');
  1535. my $nick_txt = $self->_template_text('nick');
  1536. my $names_txt = $self->_template_text('names');
  1537. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1538. _html("<td>&nbsp;</td><td class=\"tdtop\"><b>$nick_txt</b></td>");
  1539. _html("<td class=\"tdtop\"><b>$names_txt</b></td></tr>");
  1540. for(my $i = 0; $i < $self->{cfg}->{mostnickshistory}; $i++) {
  1541. next if is_ignored($sortnicks[$i]);
  1542. last unless $i < @sortnicks;
  1543. my $nickcount = keys %{ $self->{stats}->{nicks}->{$sortnicks[$i]} };
  1544. my $nickused = join(", ", values %{ $self->{stats}->{nicks}->{$sortnicks[$i]} });
  1545. next unless ($nickcount > 1);
  1546. my $a = $i + 1;
  1547. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1548. my $n = $nickcount > 1 ? $names1 : $names2;
  1549. _html("<tr><td class=\"$class\">$a</td>");
  1550. if ($self->{cfg}->{mostnicksverbose}) {
  1551. _html("<td class=\"hicell10\">$sortnicks[$i]<br />($nickcount $n)</td>");
  1552. _html("<td class=\"hicell10\" valign='top'>$nickused</td>");
  1553. } else {
  1554. _html("<td class=\"hicell10\">$sortnicks[$i]</td>");
  1555. _html("<td class=\"hicell10\" valign='top'>$nickcount $n</td>");
  1556. }
  1557. _html("</tr>");
  1558. }
  1559. _html("</table>");
  1560. }
  1561. }
  1562. sub _mostactivebyhour
  1563. {
  1564. # Charts for most active nicks by hour (0-5, 6-11, 12-17, 18-23)
  1565. my $self = shift;
  1566. my $sortnicks;
  1567. my $lastline=-1;
  1568. my $maxlines=0;
  1569. foreach my $period (0,1,2,3) {
  1570. my @sortnicks =
  1571. sort
  1572. {
  1573. (defined $self->{stats}->{line_times}{$b}[$period]?$self->{stats}->{line_times}{$b}[$period]:0)
  1574. <=>
  1575. (defined $self->{stats}->{line_times}{$a}[$period]?$self->{stats}->{line_times}{$a}[$period]:0)
  1576. }
  1577. keys %{ $self->{stats}->{line_times} } ;
  1578. for(my $i = 0; $i < $self->{cfg}->{activenicksbyhour}; $i++) {
  1579. next if ! $sortnicks[$i];
  1580. next if is_ignored($sortnicks[$i]);
  1581. last unless $i < @sortnicks;
  1582. my $nick=$sortnicks[$i];
  1583. my $count=$self->{stats}->{line_times}{$nick}[$period] || 0;
  1584. last unless $nick;
  1585. last unless $count;
  1586. $sortnicks->[$period][$i]=$nick;
  1587. if ($lastline<$i) {
  1588. $lastline=$i;
  1589. }
  1590. if ($maxlines<$count) {
  1591. $maxlines=$count;
  1592. }
  1593. }
  1594. }
  1595. if ($lastline>=0) {
  1596. $self->_headline($self->_template_text('activenickbyhourtopic'));
  1597. _html("<table border=\"0\" width=\"$self->{cfg}->{tablewidth}\"><tr>");
  1598. _html("<td>&nbsp;</td>");
  1599. _html("<td class=\"tdtop\"><b>0-5</b></td>");
  1600. _html("<td class=\"tdtop\"><b>6-11</b></td>");
  1601. _html("<td class=\"tdtop\"><b>12-17</b></td>");
  1602. _html("<td class=\"tdtop\"><b>18-23</b></td>");
  1603. _html("</tr>");
  1604. for(my $i = 0; $i <= $lastline; $i++) {
  1605. my $a = $i + 1;
  1606. my $class = $a == 1 ? 'hirankc' : 'rankc';
  1607. _html("<tr><td class=\"$class\">$a</td>");
  1608. foreach my $period (0,1,2,3) {
  1609. my $nick=$sortnicks->[$period][$i];
  1610. if ($nick) {
  1611. my $count=$self->{stats}->{line_times}{$nick}[$period];
  1612. if ($count) {
  1613. _html("<td class=\"hicell\">".$nick." - ".$count);
  1614. if ($self->{cfg}->{showmostactivebyhourgraph}) {
  1615. my $pic = 'pic_h_'.(6*$period);
  1616. my $w = int(($count / $maxlines) * 100);
  1617. _html("<br /><img src=\"$self->{cfg}->{piclocation}/$self->{cfg}->{$pic}\" border=\"0\" width=\"$w\" height=\"15\" align=\"middle\" alt=\"\" />");
  1618. }
  1619. _html("</td>");
  1620. } else {
  1621. _html("<td class=\"hicell\">&nbsp;</td>");
  1622. }
  1623. } else {
  1624. _html("<td class=\"hicell\">&nbsp;</td>");
  1625. }
  1626. }
  1627. _html("</tr>");
  1628. }
  1629. _html("</table>");
  1630. }
  1631. }
  1632. sub _topactive {
  1633. my $self = shift;
  1634. my @top_active;
  1635. my $top_nicks;
  1636. if ($self->{cfg}->{sortbywords}) {
  1637. @top_active = sort { $self->{stats}->{words}{$b} <=> $self->{stats}->{words}{$a} }
  1638. keys %{ $self->{stats}->{words} };
  1639. $top_nicks = scalar keys %{ $self->{stats}->{words} };
  1640. } else {
  1641. @top_active = sort { $self->{stats}->{lines}{$b} <=> $self->{stats}->{lines}{$a} }
  1642. keys %{ $self->{stats}->{lines} };
  1643. $top_nicks = scalar keys %{ $self->{stats}->{lines} };
  1644. }
  1645. if ($self->{cfg}->{activenicks} > $top_nicks) {
  1646. $self->{cfg}->{activenicks} = $top_nicks;
  1647. }
  1648. if (($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}) > $top_nicks) {
  1649. $self->{cfg}->{activenicks2} = $top_nicks-$self->{cfg}->{activenicks};
  1650. }
  1651. (@top_active) = @top_active[0..($self->{cfg}->{activenicks}+$self->{cfg}->{activenicks2}-1)];
  1652. foreach (@top_active) {
  1653. $self->{topactive}{$_} = 1;
  1654. }
  1655. }
  1656. sub _istoponly {
  1657. my $self = shift;
  1658. my (@nicks_tmp) = @_;
  1659. my @nicks;
  1660. my $cnt=0;
  1661. if ($self->{cfg}->{showonlytop}) {
  1662. foreach my $nick (@nicks_tmp) {
  1663. if ($self->{topactive}{$nick}) {
  1664. push(@nicks, $nick);
  1665. }
  1666. }
  1667. return(@nicks);
  1668. } else {
  1669. return(@nicks_tmp);
  1670. }
  1671. }
  1672. 1;
  1673. __END__
  1674. =head1 NAME
  1675. Pisg::HTMLGenerator - class to create a static HTML page out of data parsed
  1676. =head1 DESCRIPTION
  1677. C<Pisg::HTMLGenerator> uses the hash returned by Pisg::Parser::Logfile and turns it into a static HTML page.
  1678. =head1 SYNOPSIS
  1679. use Pisg::HTMLGenerator;
  1680. $generator = new Pisg::HTMLGenerator(
  1681. cfg => $cfg,
  1682. stats => $stats,
  1683. users => $users,
  1684. tmps => $tmps
  1685. );
  1686. =head1 CONSTRUCTOR
  1687. =over 4
  1688. =item new ( [ OPTIONS ] )
  1689. This is the constructor for a new Pisg::HTMLGenerator object. C<OPTIONS> are passed in a hash like fashion using key and value pairs.
  1690. Possible options are:
  1691. B<cfg> - hashref containing configuration variables, created by the Pisg module.
  1692. B<stats> - reference to the hash returned by Pisg::Parser::Logfile containing all stats.
  1693. B<users> - reference to a hash containg user information
  1694. B<tmps> - reference to a hash containing the language templates.
  1695. =back
  1696. =head1 AUTHOR
  1697. Morten Brix Pedersen <morten@wtf.dk>
  1698. =head1 COPYRIGHT
  1699. Copyright (C) 2001-2002 Morten Brix Pedersen. All rights reserved.
  1700. This program is free software; you can redistribute it and/or modify it
  1701. under the terms of the GPL, license is included with the distribution of
  1702. this file.
  1703. =cut