4
0

HTMLGenerator.pm 78 KB

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