HTMLGenerator.pm 78 KB

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