HTMLGenerator.pm 69 KB

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