HTMLGenerator.pm 81 KB

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