HTMLGenerator.pm 83 KB

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