HTMLGenerator.pm 77 KB

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