HTMLGenerator.pm 83 KB

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