HTMLGenerator.pm 70 KB

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