HTMLGenerator.pm 81 KB

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