HTMLGenerator.pm 81 KB

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