HTMLGenerator.pm 80 KB

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